From bf2d631bc246a89392c674ce61973833db9fa901 Mon Sep 17 00:00:00 2001 From: zhangchao Date: Fri, 5 Jan 2024 10:47:32 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E8=AE=BF=E9=97=AE=E7=9A=84crash=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangchao --- .../render_service_base/src/render/rs_image_cache.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/rosen/modules/render_service_base/src/render/rs_image_cache.cpp b/rosen/modules/render_service_base/src/render/rs_image_cache.cpp index 0a6d84aad..3e798f5af 100644 --- a/rosen/modules/render_service_base/src/render/rs_image_cache.cpp +++ b/rosen/modules/render_service_base/src/render/rs_image_cache.cpp @@ -161,15 +161,9 @@ void RSImageCache::ReleasePixelMapCache(uint64_t uniqueId) } } #ifndef USE_ROSEN_DRAWING - auto itr = pixelMapIdRelatedSkiaImageCache_.find(uniqueId); - if (itr != pixelMapIdRelatedSkiaImageCache_.end()) { - pixelMapIdRelatedSkiaImageCache_.erase(itr); - } + ReleaseSkiaImageCacheByPixelMapId(uniqueId); #else - auto itr = pixelMapIdRelatedDrawingImageCache_.find(uniqueId); - if (itr != pixelMapIdRelatedDrawingImageCache_.end()) { - pixelMapIdRelatedDrawingImageCache_.erase(itr); - } + ReleaseDrawingImageCacheByPixelMapId(uniqueId); #endif } } -- Gitee From e130f715795fea8e68ae2899b2d3ae575b23befc Mon Sep 17 00:00:00 2001 From: c00607827 Date: Fri, 5 Jan 2024 11:12:01 +0800 Subject: [PATCH 02/12] add wind mode Signed-off-by: c00607827 --- .../modules/render_service_base/include/common/rs_common_def.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rosen/modules/render_service_base/include/common/rs_common_def.h b/rosen/modules/render_service_base/include/common/rs_common_def.h index 23557f3af..b0ef70c77 100644 --- a/rosen/modules/render_service_base/include/common/rs_common_def.h +++ b/rosen/modules/render_service_base/include/common/rs_common_def.h @@ -151,6 +151,8 @@ enum class SystemAnimatedScenes : uint32_t { ENTER_APP_CENTER, // Enter the app center EXIT_APP_CENTER, // Exit the app center APPEAR_MISSION_CENTER, // A special case scenario that displays the mission center + ENTER_WIND_CLEAR, // Enter win+D in clear screen mode + ENTER_WIND_RECOVER, // Enter win+D in recover mode OTHERS, // 1.Default state 2.The state in which the animation ends }; -- Gitee From 8ae10408b025a8551b31d8fd1ebaad43a1bf79f1 Mon Sep 17 00:00:00 2001 From: c00607827 Date: Fri, 5 Jan 2024 14:38:32 +0800 Subject: [PATCH 03/12] add wind mode Signed-off-by: c00607827 --- rosen/modules/render_service/core/pipeline/rs_main_thread.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp index 6b34d7296..97674ed22 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp @@ -2677,7 +2677,9 @@ bool RSMainThread::SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedSc --systemAnimatedScenesCnt_; } else { if (systemAnimatedScenes == SystemAnimatedScenes::ENTER_TFS_WINDOW || - systemAnimatedScenes == SystemAnimatedScenes::EXIT_TFU_WINDOW) { + systemAnimatedScenes == SystemAnimatedScenes::EXIT_TFU_WINDOW || + systemAnimatedScenes == SystemAnimatedScenes::ENTER_WIND_CLEAR || + systemAnimatedScenes == SystemAnimatedScenes::ENTER_WIND_RECOVER) { ++threeFingerCnt_; } if (systemAnimatedScenes != SystemAnimatedScenes::APPEAR_MISSION_CENTER) { -- Gitee From bf1348381b5af72a0b6d27658df5975df0c085b8 Mon Sep 17 00:00:00 2001 From: BruceXuXu Date: Thu, 4 Jan 2024 16:06:15 +0000 Subject: [PATCH 04/12] fix vk cancelbuffer crash Signed-off-by: BruceXuXu Change-Id: I87f071de90e65ebeac144879e54a6ed01370cbd3 --- .../src/platform/ohos/backend/native_buffer_utils.cpp | 2 ++ .../src/platform/ohos/backend/native_buffer_utils.h | 3 ++- .../platform/ohos/backend/rs_surface_ohos_vulkan.cpp | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.cpp b/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.cpp index 151c15099..cf0437b99 100755 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.cpp @@ -264,6 +264,8 @@ bool MakeFromNativeWindowBuffer(std::shared_ptr skContext, #endif nativeSurface.image = image; + NativeObjectUnreference(nativeSurface.nativeWindowBuffer); + NativeObjectReference(nativeWindowBuffer); nativeSurface.nativeWindowBuffer = nativeWindowBuffer; return true; diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.h b/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.h index 28c94694f..0c07ac1f8 100755 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.h +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.h @@ -95,7 +95,8 @@ struct NativeSurfaceInfo { #else drawingSurface = nullptr; #endif - NativeWindowCancelBuffer(window, nativeWindowBuffer); + NativeObjectUnreference(window); + NativeObjectUnreference(nativeWindowBuffer); } }; diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_vulkan.cpp b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_vulkan.cpp index 70d778930..6062480f9 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_vulkan.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_vulkan.cpp @@ -45,8 +45,8 @@ RSSurfaceOhosVulkan::RSSurfaceOhosVulkan(const sptr& producer) : RSSurf RSSurfaceOhosVulkan::~RSSurfaceOhosVulkan() { #ifdef ENABLE_NATIVEBUFFER - mSurfaceList.clear(); mSurfaceMap.clear(); + mSurfaceList.clear(); #endif // ENABLE_NATIVEBUFFER DestoryNativeWindow(mNativeWindow); mNativeWindow = nullptr; @@ -60,6 +60,9 @@ RSSurfaceOhosVulkan::~RSSurfaceOhosVulkan() void RSSurfaceOhosVulkan::SetNativeWindowInfo(int32_t width, int32_t height, bool useAFBC) { if (width != mWidth || height != mHeight) { + for (auto &[key, val] : mSurfaceMap) { + NativeWindowCancelBuffer(mNativeWindow, key); + } mSurfaceMap.clear(); } NativeWindowHandleOpt(mNativeWindow, SET_FORMAT, pixelFormat_); @@ -145,6 +148,7 @@ std::unique_ptr RSSurfaceOhosVulkan::RequestFrame( #else if (nativeSurface.drawingSurface == nullptr) { #endif + NativeObjectReference(mNativeWindow); nativeSurface.window = mNativeWindow; if (!NativeBufferUtils::MakeFromNativeWindowBuffer( mSkContext, nativeWindowBuffer, nativeSurface, width, height)) { @@ -160,6 +164,7 @@ std::unique_ptr RSSurfaceOhosVulkan::RequestFrame( #endif ROSEN_LOGE("RSSurfaceOhosVulkan: skSurface is null, return"); mSurfaceList.pop_back(); + NativeWindowCancelBuffer(mNativeWindow, nativeWindowBuffer); mSurfaceMap.erase(nativeWindowBuffer); return nullptr; } else { @@ -342,6 +347,9 @@ void RSSurfaceOhosVulkan::SetColorSpace(GraphicColorGamut colorSpace) { if (colorSpace != colorSpace_) { colorSpace_ = colorSpace; + for (auto &[key, val] : mSurfaceMap) { + NativeWindowCancelBuffer(mNativeWindow, key); + } mSurfaceMap.clear(); } } -- Gitee From 2ef448a0605e2ad9acd9c515c0c86801c607650b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E5=B8=B8=E5=BE=B7?= Date: Fri, 29 Dec 2023 15:15:47 +0800 Subject: [PATCH 05/12] Fixed the wrong rotation position of the casting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 钱常德 Change-Id: I706d2383d8776cd9cd4bcf8652dbe031d2debece --- .../rs_uni_render_virtual_processor.cpp | 189 ++++++++---------- .../rs_uni_render_virtual_processor.h | 4 + 2 files changed, 86 insertions(+), 107 deletions(-) diff --git a/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.cpp b/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.cpp index fe1f6b51e..92fb74de9 100644 --- a/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.cpp @@ -137,6 +137,77 @@ void RSUniRenderVirtualProcessor::CanvasRotation(ScreenRotation screenRotation, #endif } +void RSUniRenderVirtualProcessor::RotateMirrorCanvasIfNeed(RSDisplayRenderNode& node) +{ + auto rotation = node.GetScreenRotation(); + if (RSSystemProperties::IsFoldScreenFlag() && node.GetScreenId() == 0) { + if (rotation == ScreenRotation::ROTATION_270) { + rotation = ScreenRotation::ROTATION_0; + } else { + rotation = static_cast(static_cast(rotation) + 1); + } + } +#ifndef USE_ROSEN_DRAWING + if (rotation != ScreenRotation::ROTATION_0) { + auto screenManager = CreateOrGetScreenManager(); + auto mainScreenInfo = screenManager->QueryScreenInfo(node.GetScreenId()); + if (rotation == ScreenRotation::ROTATION_90) { + canvas_->rotate(90); // 90 degrees + canvas_->translate(0, -(static_cast(mainScreenInfo.height))); + } else if (rotation == ScreenRotation::ROTATION_180) { + canvas_->rotate(180, static_cast(mainScreenInfo.width) / 2, // 180 degrees, 2 is centre + static_cast(mainScreenInfo.height) / 2); // 2 is centre + } else if (rotation == ScreenRotation::ROTATION_270) { + canvas_->rotate(270); // 270 degrees + canvas_->translate(-(static_cast(mainScreenInfo.width)), 0); + } + } +#else + if (rotation != ScreenRotation::ROTATION_0) { + auto screenManager = CreateOrGetScreenManager(); + auto mainScreenInfo = screenManager->QueryScreenInfo(node.GetScreenId()); + if (rotation == ScreenRotation::ROTATION_90) { + canvas_->Rotate(90, 0, 0); // 90 degrees + canvas_->Translate(0, -(static_cast(mainScreenInfo.height))); + } else if (rotation == ScreenRotation::ROTATION_180) { + canvas_->Rotate(180, static_cast(mainScreenInfo.width) / 2, // 180 degrees, 2 is centre + static_cast(mainScreenInfo.height) / 2); // 2 is centre + } else if (rotation == ScreenRotation::ROTATION_270) { + canvas_->Rotate(270, 0, 0); // 270 degrees + canvas_->Translate(-(static_cast(mainScreenInfo.width)), 0); + } + } +#endif +} + +void RSUniRenderVirtualProcessor::ScaleMirrorIfNeed(RSDisplayRenderNode& node) +{ + if (mainWidth_ != mirrorWidth_ || mainHeight_ != mirrorHeight_) { +#ifndef USE_ROSEN_DRAWING + canvas_->clear(SK_ColorBLACK); +#else + canvas_->Clear(SK_ColorBLACK); +#endif + float mirrorScale = 1.0f; // 1 for init scale + float startX = 0.0f; + float startY = 0.0f; + if ((mirrorHeight_ / mirrorWidth_) < (mainHeight_ / mainWidth_)) { + mirrorScale = mirrorHeight_ / mainHeight_; + startX = (mirrorWidth_ - (mirrorScale * mainWidth_)) / 2; // 2 for calc X + } else if ((mirrorHeight_ / mirrorWidth_) > (mainHeight_ / mainWidth_)) { + mirrorScale = mirrorWidth_ / mainWidth_; + startY = (mirrorHeight_ - (mirrorScale * mainHeight_)) / 2; // 2 for calc Y + } +#ifndef USE_ROSEN_DRAWING + canvas_->translate(startX, startY); + canvas_->scale(mirrorScale, mirrorScale); +#else + canvas_->Translate(startX, startY); + canvas_->Scale(mirrorScale, mirrorScale); +#endif + } +} + void RSUniRenderVirtualProcessor::PostProcess(RSDisplayRenderNode* node) { if (producerSurface_ == nullptr) { @@ -194,116 +265,20 @@ void RSUniRenderVirtualProcessor::ProcessDisplaySurface(RSDisplayRenderNode& nod auto params = RSUniRenderUtil::CreateBufferDrawParam(node, forceCPU_); auto screenManager = CreateOrGetScreenManager(); auto mainScreenInfo = screenManager->QueryScreenInfo(node.GetScreenId()); - float mainWidth = static_cast(mainScreenInfo.width); - float mainHeight = static_cast(mainScreenInfo.height); - auto screenCorrection = screenManager->GetScreenCorrection(node.GetScreenId()); - if ((RSSystemProperties::IsFoldScreenFlag() && node.GetScreenId() == 0) || canvasRotation_) { - std::swap(mainWidth, mainHeight); - if (screenCorrection == ScreenRotation::ROTATION_270) { -#ifndef USE_ROSEN_DRAWING - canvas_->rotate(-270, mirrorWidth_ / 2.0f, mirrorHeight_ / 2.0f); -#else - canvas_->Rotate(-270, mirrorWidth_ / 2.0f, mirrorHeight_ / 2.0f); -#endif - } - if (mainScreenRotation_ == ScreenRotation::ROTATION_180) { - std::swap(mainWidth, mainHeight); - } - if (canvasRotation_) { - CanvasRotation(mainScreenRotation_, mirrorWidth_, mirrorHeight_); - } + mainWidth_ = static_cast(mainScreenInfo.width); + mainHeight_ = static_cast(mainScreenInfo.height); + if ((RSSystemProperties::IsFoldScreenFlag() && node.GetScreenId() == 0)) { + std::swap(mainWidth_, mainHeight_); + } + if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || + mainScreenRotation_ == ScreenRotation::ROTATION_270) { + std::swap(mainWidth_, mainHeight_); } - // If the width and height not match the main screen, calculate the dstRect. - if (mainWidth != mirrorWidth_ || mainHeight != mirrorHeight_) { -#ifndef USE_ROSEN_DRAWING - SkRect mirrorDstRect; - if ((mirrorHeight_ / mirrorWidth_) < (mainHeight / mainWidth)) { - float mirrorScale = mirrorHeight_ / mainHeight; - float mainScale = mainHeight / mainWidth; - if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || - mainScreenRotation_ == ScreenRotation::ROTATION_270) { - if (screenCorrection == ScreenRotation::ROTATION_270) { - mirrorDstRect = SkRect::MakeXYWH(-(mirrorHeight_ / 2.0f), - -(mirrorScale * mainWidth * mainScale) / 2.0f, - mirrorHeight_, mirrorScale * mainWidth * mainScale); - } else { - mirrorDstRect = SkRect::MakeXYWH(-(mirrorHeight_ / 2.0f), - -(mirrorScale * mainWidth) / 2.0f, - mirrorHeight_, mirrorScale * mainWidth); - } - } else { - if (screenCorrection == ScreenRotation::ROTATION_270) { - mirrorDstRect = SkRect::MakeXYWH((mirrorWidth_ - (mirrorScale * mainScale * mainWidth)) / 2.0f, - 0, mirrorScale * mainScale * mainWidth, mirrorHeight_); - } else { - mirrorDstRect = SkRect::MakeXYWH((mirrorWidth_ - (mirrorScale * mainWidth)) / 2.0f, 0, - mirrorScale * mainWidth, mirrorHeight_); - } - } - } else if ((mirrorHeight_ / mirrorWidth_) > (mainHeight / mainWidth)) { - float mirrorScale = mirrorWidth_ / mainWidth; - if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || - mainScreenRotation_ == ScreenRotation::ROTATION_270) { - mirrorDstRect = SkRect::MakeXYWH((mirrorHeight_ / 2.0f) - - ((mirrorScale * mainHeight) / 2.0f), -(mirrorWidth_ / 2.0f), - mirrorScale * mainHeight, mirrorWidth_); - } else { - mirrorDstRect = SkRect::MakeXYWH(0, - (mirrorHeight_ - (mirrorScale * mainHeight)) / 2.0f, - mirrorWidth_, mirrorScale * mainHeight); - } - } - params.dstRect = mirrorDstRect; -#else - Drawing::Rect mirrorDstRect; - if ((mirrorHeight_ / mirrorWidth_) < (mainHeight / mainWidth)) { - float mirrorScale = mirrorHeight_ / mainHeight; - float mainScale = mainHeight / mainWidth; - if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || - mainScreenRotation_ == ScreenRotation::ROTATION_270) { - if (screenCorrection == ScreenRotation::ROTATION_270) { - mirrorDstRect = Drawing::Rect(-(mirrorHeight_ / 2.0f), - -(mirrorScale * mainWidth * mainScale) / 2.0f, mirrorHeight_ / 2.0f, - (mirrorScale * mainWidth * mainScale) / 2.0f); - } else { - mirrorDstRect = Drawing::Rect(-(mirrorHeight_ / 2.0f), -(mirrorScale * mainWidth) / 2.0f, - mirrorHeight_ / 2.0f, (mirrorScale * mainWidth) / 2.0f); - } - } else { - if (screenCorrection == ScreenRotation::ROTATION_270) { - mirrorDstRect = Drawing::Rect((mirrorWidth_ - (mirrorScale * mainScale * mainWidth)) / 2.0f, 0, - (mirrorWidth_ + (mirrorScale * mainScale * mainWidth)) / 2.0f, mirrorHeight_); - } else { - mirrorDstRect = Drawing::Rect((mirrorWidth_ - (mirrorScale * mainWidth)) / 2.0f, 0, - (mirrorWidth_ + (mirrorScale * mainWidth)) / 2.0f, mirrorHeight_); - } - } - } else if ((mirrorHeight_ / mirrorWidth_) > (mainHeight / mainWidth)) { - float mirrorScale = mirrorWidth_ / mainWidth; - if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || - mainScreenRotation_ == ScreenRotation::ROTATION_270) { - mirrorDstRect = Drawing::Rect((mirrorHeight_ / 2.0f) - ((mirrorScale * mainHeight) / 2.0f), - -(mirrorWidth_ / 2.0f), (mirrorHeight_ / 2.0f) + ((mirrorScale * mainHeight) / 2.0f), - (mirrorWidth_ / 2.0f)); - } else { - mirrorDstRect = Drawing::Rect(0, (mirrorHeight_ - (mirrorScale * mainHeight)) / 2.0f, - mirrorWidth_, (mirrorHeight_ + (mirrorScale * mainHeight)) / 2.0); - } - } - params.dstRect = mirrorDstRect; -#endif - } else { - if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || - mainScreenRotation_ == ScreenRotation::ROTATION_270) { -#ifndef USE_ROSEN_DRAWING - canvas_->translate(-(mirrorHeight_ / 2.0f), -(mirrorWidth_ / 2.0f)); -#else - canvas_->Translate(-(mirrorHeight_ / 2.0f), -(mirrorWidth_ / 2.0f)); -#endif - } + ScaleMirrorIfNeed(node); + if ((RSSystemProperties::IsFoldScreenFlag() && node.GetScreenId() == 0) || canvasRotation_) { + RotateMirrorCanvasIfNeed(node); } - renderEngine_->DrawDisplayNodeWithParams(*canvas_, node, params); #ifndef USE_ROSEN_DRAWING canvas_->restore(); diff --git a/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.h b/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.h index 996fb5f18..60baa7a0f 100644 --- a/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.h +++ b/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.h @@ -39,6 +39,8 @@ public: } private: void CanvasRotation(ScreenRotation screenRotation, float width, float height); + void ScaleMirrorIfNeed(RSDisplayRenderNode& node); + void RotateMirrorCanvasIfNeed(RSDisplayRenderNode& node); sptr producerSurface_; std::unique_ptr renderFrame_; std::unique_ptr canvas_; @@ -47,6 +49,8 @@ private: bool isPhone_ = false; float mirrorWidth_ = 0.f; float mirrorHeight_ = 0.f; + float mainWidth_ = 0.f; + float mainHeight_ = 0.f; bool canvasRotation_ = false; ScreenRotation mainScreenRotation_ = ScreenRotation::ROTATION_0; }; -- Gitee From 2413eb2008d127606348ae03f2e80846a4153945 Mon Sep 17 00:00:00 2001 From: sunshipan Date: Thu, 4 Jan 2024 19:20:37 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E6=A8=A1=E7=B3=8A=E5=B9=B6=E8=A1=8C?= =?UTF-8?q?=E5=8C=96=E5=A2=9E=E5=8A=A0=E5=BA=94=E7=94=A8=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunshipan --- .../parallel_render/rs_filter_sub_thread.cpp | 107 ++++- .../parallel_render/rs_filter_sub_thread.h | 10 +- .../parallel_render/rs_sub_thread_manager.cpp | 14 + .../parallel_render/rs_sub_thread_manager.h | 2 + .../core/pipeline/rs_main_thread.cpp | 2 + .../core/pipeline/rs_uni_render_visitor.cpp | 4 + .../property/rs_filter_cache_manager.h | 117 ++++-- .../include/render/rs_filter.h | 6 + .../platform/ohos/rs_system_properties.cpp | 6 +- .../src/property/rs_filter_cache_manager.cpp | 377 +++++++++++------- .../src/render/rs_blur_filter.cpp | 2 +- .../src/render/rs_filter.cpp | 2 + .../src/render/rs_material_filter.cpp | 2 +- 13 files changed, 443 insertions(+), 208 deletions(-) diff --git a/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.cpp b/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.cpp index 94166cba6..6c0a19886 100644 --- a/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.cpp @@ -24,6 +24,7 @@ #include "memory/rs_tag_tracker.h" #include "rs_trace.h" +#include "common/rs_optional_trace.h" #include "pipeline/parallel_render/rs_sub_thread_manager.h" #include "pipeline/rs_main_thread.h" #include "pipeline/rs_surface_render_node.h" @@ -75,7 +76,21 @@ void RSFilterSubThread::Start() grContext_ = CreateShareGrContext(); }); RSFilter::postTask = [this](std::weak_ptr task) { - PostTask([this, task]() { RenderCache(task); }); + filterTaskList_.emplace_back(task); + RS_TRACE_NAME_FMT("postTask:%zu", filterTaskList_.size()); + }; + + RSFilter::clearGpuContext = [this]() { ResetGrContext(); }; + + RSFilter::setRelease = [this](std::weak_ptr task) { + PostTask([this, task]() { + auto workTask = task.lock(); + if (!workTask) { + RS_LOGE("Color picker task is null"); + return; + } + workTask->SetTaskRelease(); + }); }; } @@ -175,28 +190,92 @@ void RSFilterSubThread::DestroyShareEglContext() #endif } -void RSFilterSubThread::RenderCache(std::weak_ptr filterTask) +void RSFilterSubThread::RenderCache(std::vector>& filterTaskList) { - RS_TRACE_NAME("RenderCache"); - auto task = filterTask.lock(); - if (!task) { - RS_LOGE("task is null"); - return; - } + RS_TRACE_NAME_FMT("RSFilterSubThread::RenderCache:%zu", filterTaskList.size()); if (grContext_ == nullptr) { grContext_ = CreateShareGrContext(); } + if (fence_->Wait(SYNC_TIME_OUT) < 0) { + RS_LOGE("RSFilterSubThread::RenderCache: fence time out"); + filterTaskList.clear(); + isWorking_.store(false); + return; + } if (grContext_ == nullptr) { - RS_LOGE("grContext is null"); + RS_LOGE("RSFilterSubThread::RenderCache: grContext is null"); + filterTaskList.clear(); + isWorking_.store(false); return; } - if (!task->InitSurface(grContext_.get())) { - RS_LOGE("InitSurface failed"); + for (auto& task : filterTaskList) { + auto workTask = task.lock(); + if (!workTask) { + RS_LOGE("RSFilterSubThread::RenderCache: Render task is null"); + continue; + } + if (!workTask->InitSurface(grContext_.get())) { + RS_LOGE("RSFilterSubThread::RenderCache: InitSurface failed"); + continue; + } + if (!workTask->Render()) { + RS_LOGE("RSFilterSubThread::RenderCache: Render failed"); + continue; + } + } +#ifndef USE_ROSEN_DRAWING + grContext_->flushAndSubmit(true); +#else + grContext_->FlushAndSubmit(true); +#endif + for (auto& task : filterTaskList) { + auto workTask = task.lock(); + if (!workTask) { + RS_LOGE("RSFilterSubThread::RenderCache, SaveFilteredImage task is null"); + continue; + } + if (!workTask->SaveFilteredImage()) { + RS_LOGE("RSFilterSubThread::RenderCache, SaveFilteredImage failed"); + continue; + } + if (!workTask->SetDone()) { + RS_LOGE("RSFilterSubThread::RenderCache, SetDone failed"); + continue; + } + } + filterTaskList.clear(); + isWorking_.store(false); +} + +void RSFilterSubThread::FlushAndSubmit() +{ + RS_TRACE_NAME_FMT("RSFilterSubThread::FlushAndSubmit():isWorking_:%d TaskList size:%zu", + isWorking_.load(), filterReadyTaskList_.size()); + + if (filterTaskList_.empty()) { return; } - if (!task->Render()) { - RS_LOGE("Render failed"); + + if (isWorking_.load()) { + return; + } + + filterTaskList_.swap(filterReadyTaskList_); + for (auto& task : filterReadyTaskList_) { + auto initTask = task.lock(); + if (!initTask) { + RS_LOGE("RSFilterSubThread::FlushAndSubmit:SwapInit task is null"); + continue; + } + initTask->SwapInit(); } + isWorking_.store(true); + PostTask([this]() { RenderCache(filterReadyTaskList_); }); +} + +void RSFilterSubThread::SetFence(sptr fence) +{ + fence_ = fence; } void RSFilterSubThread::ColorPickerRenderCache(std::weak_ptr colorPickerTask) @@ -326,8 +405,10 @@ void RSFilterSubThread::ResetGrContext() return; } #ifndef USE_ROSEN_DRAWING + grContext_->flushAndSubmit(true); grContext_->freeGpuResources(); #else + grContext_->FlushAndSubmit(true); grContext_->FreeGpuResources(); #endif } diff --git a/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.h b/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.h index e8c571a2f..fce9594be 100644 --- a/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.h +++ b/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.h @@ -42,7 +42,9 @@ public: void StartColorPicker(); void PostTask(const std::function& task); void PostSyncTask(const std::function& task); - void RenderCache(std::weak_ptr filterTask); + void RenderCache(std::vector>& filterTaskList); + void FlushAndSubmit(); + void SetFence(sptr fence); void ColorPickerRenderCache(std::weak_ptr colorPickerTask); void ResetGrContext(); @@ -50,6 +52,7 @@ public: float GetAppGpuMemoryInMB(); private: + const uint32_t SYNC_TIME_OUT = 1000; void CreateShareEglContext(); void DestroyShareEglContext(); #ifndef USE_ROSEN_DRAWING @@ -61,7 +64,10 @@ private: #else std::shared_ptr CreateShareGrContext(); #endif - + std::atomic isWorking_ = false; + sptr fence_ = nullptr; + std::vector> filterTaskList_; + std::vector> filterReadyTaskList_; uint32_t threadIndex_ = 0; std::shared_ptr runner_ = nullptr; std::shared_ptr handler_ = nullptr; diff --git a/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.cpp b/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.cpp index 618e6f79f..8d6c6e5f3 100644 --- a/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.cpp +++ b/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.cpp @@ -171,6 +171,20 @@ float RSSubThreadManager::GetAppGpuMemoryInMB() return total; } +void RSSubThreadManager::SubmitFilterSubThreadTask() +{ + if (filterThread) { + filterThread->FlushAndSubmit(); + } +} + +void RSSubThreadManager::SetFenceSubThread(sptr fence) +{ + if (filterThread) { + filterThread->SetFence(fence); + } +} + void RSSubThreadManager::SubmitSubThreadTask(const std::shared_ptr& node, const std::list>& subThreadNodes) { diff --git a/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.h b/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.h index 682d49391..b27e464bb 100644 --- a/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.h +++ b/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.h @@ -42,6 +42,8 @@ public: void PostTask(const std::function& task, uint32_t threadIndex, bool isSyncTask = false); void WaitNodeTask(uint64_t nodeId); void NodeTaskNotify(uint64_t nodeId); + void SubmitFilterSubThreadTask(); + void SetFenceSubThread(sptr fence); void SubmitSubThreadTask(const std::shared_ptr& node, const std::list>& subThreadNodes); void ResetSubThreadGrContext(); diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp index 52d068283..b0537a5ac 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp @@ -272,6 +272,8 @@ void RSMainThread::Init() Render(); InformHgmNodeInfo(); ReleaseAllNodesBuffer(); + auto subThreadManager = RSSubThreadManager::Instance(); + subThreadManager->SubmitFilterSubThreadTask(); SendCommands(); context_->activeNodesInRoot_.clear(); ROSEN_TRACE_END(HITRACE_TAG_GRAPHIC_AGP); diff --git a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp index e78ad4727..ebd73abca 100644 --- a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp @@ -3067,6 +3067,10 @@ void RSUniRenderVisitor::ProcessDisplayRenderNode(RSDisplayRenderNode& node) AssignGlobalZOrderAndCreateLayer(appWindowNodesInZOrder_); node.SetGlobalZOrder(globalZOrder_++); processor_->ProcessDisplaySurface(node); + auto& surfaceHandler = static_cast(node); + auto& fence = surfaceHandler.GetAcquireFence(); + auto subThreadManager = RSSubThreadManager::Instance(); + subThreadManager->SetFenceSubThread(fence); AssignGlobalZOrderAndCreateLayer(hardwareEnabledTopNodes_); } diff --git a/rosen/modules/render_service_base/include/property/rs_filter_cache_manager.h b/rosen/modules/render_service_base/include/property/rs_filter_cache_manager.h index 63d52d6cb..85e16fca6 100644 --- a/rosen/modules/render_service_base/include/property/rs_filter_cache_manager.h +++ b/rosen/modules/render_service_base/include/property/rs_filter_cache_manager.h @@ -28,6 +28,7 @@ #include "include/core/SkSurface.h" #include "include/gpu/GrBackendSurface.h" #else +#include "draw/canvas.h" #include "draw/surface.h" #include "utils/rect.h" #endif @@ -81,7 +82,10 @@ public: const std::shared_ptr& filter, const std::optional& srcRect = std::nullopt, const std::optional& dstRect = std::nullopt); - void PostPartialFilterRenderTask(const std::shared_ptr& filter); + static bool IsNearlyFullScreen(SkISize imageSize, int32_t canvasWidth, int32_t canvasHeight); + void PostPartialFilterRenderTask(const std::shared_ptr& filter, const SkIRect& dstRect); + void PostPartialFilterRenderInit(const std::shared_ptr& filter, const SkIRect& dstRect, + int32_t canvasWidth, int32_t canvasHeight); #else // Call this function during the process phase to apply the filter. Depending on the cache state, it may either // regenerate the cache or reuse the existing cache. @@ -96,7 +100,10 @@ public: const std::shared_ptr& filter, const std::optional& srcRect = std::nullopt, const std::optional& dstRect = std::nullopt); - void PostPartialFilterRenderTask(const std::shared_ptr& filter); + static bool IsNearlyFullScreen(Drawing::RectI imageSize, int32_t canvasWidth, int32_t canvasHeight); + void PostPartialFilterRenderTask(const std::shared_ptr& filter, const Drawing::RectI& dstRect); + void PostPartialFilterRenderInit(const std::shared_ptr& filter, const Drawing::RectI& dstRect, + int32_t canvasWidth, int32_t canvasHeight); #endif enum CacheType : uint8_t { CACHE_TYPE_NONE = 0, @@ -119,7 +126,10 @@ private: class RSFilterCacheTask : public RSFilter::RSFilterTask { public: static const bool FilterPartialRenderEnabled; - bool isTaskTooLong = false; + bool isFirstInit_ = true; + bool needClearSurface_ = false; + std::atomic isTaskRelease_ = false; + std::shared_ptr cachedFirstFilter_ = nullptr; RSFilterCacheTask() = default; virtual ~RSFilterCacheTask() = default; #ifndef USE_ROSEN_DRAWING @@ -128,7 +138,10 @@ private: bool InitSurface(Drawing::GPUContext* grContext) override; #endif bool Render() override; - + bool SaveFilteredImage() override; + void SwapInit() override; + bool SetDone() override; + void SetTaskRelease() override; CacheProcessStatus GetStatus() const { return cacheProcessStatus_.load(); @@ -141,57 +154,66 @@ private: #ifndef USE_ROSEN_DRAWING void InitTask(std::shared_ptr filter, - std::shared_ptr cachedSnapshot, SkISize size) + std::shared_ptr cachedSnapshot, const SkIRect& dstRect) { - filter_ = filter; - cachedSnapshot_ = cachedSnapshot; - cacheBackendTexture_ = cachedSnapshot_->cachedImage_->getBackendTexture(false); - surfaceSize_ = size; + needClearSurface_ = (dstRectBefore_.width() != dstRect.width() || + dstRectBefore_.height() != dstRect.height()); + filterBefore_ = filter; + cachedSnapshotBefore_ = cachedSnapshot; + snapshotSizeBefore_ = cachedSnapshot->cachedRect_.size(); + dstRectBefore_ = dstRect; } GrBackendTexture GetResultTexture() const { return cacheCompletedBackendTexture_; } + + SkIRect GetDstRect() const + { + return dstRect_; + } #else void InitTask(std::shared_ptr filter, - std::shared_ptr cachedSnapshot, Drawing::RectI size) + std::shared_ptr cachedSnapshot, const Drawing::RectI& dstRect) { - filter_ = filter; - cachedSnapshot_ = cachedSnapshot; - cacheBackendTexture_ = cachedSnapshot_->cachedImage_->GetBackendTexture(false, nullptr); - surfaceSize_ = size; + needClearSurface_ = (dstRectBefore_.GetWidth() != dstRect.GetWidth() || + dstRectBefore_.GetHeight() != dstRect.GetHeight()); + filterBefore_ = filter; + cachedSnapshotBefore_ = cachedSnapshot; + snapshotSizeBefore_ = cachedSnapshot->cachedRect_; + dstRectBefore_ = dstRect; } Drawing::BackendTexture GetResultTexture() const { return cacheCompletedBackendTexture_; } + + Drawing::RectI GetDstRect() const + { + return dstRect_; + } #endif void Reset() { - cachedSnapshot_.reset(); + cachedSnapshotBefore_.reset(); } - void ResetGrContext() + void ResetInTask() { -#ifndef USE_ROSEN_DRAWING - if (cacheSurface_ != nullptr) { - GrDirectContext* grContext_ = cacheSurface_->recordingContext()->asDirectContext(); - cacheSurface_ = nullptr; - grContext_->freeGpuResources(); - } -#else - if (cacheSurface_ != nullptr) { - std::shared_ptr gpuContext_ = cacheSurface_->GetCanvas()->GetGPUContext(); - cacheSurface_ = nullptr; - gpuContext_->FreeGpuResources(); - } -#endif + cachedSnapshotInTask_.reset(); + dstRectBefore_ = { 0, 0, 0, 0 }; + dstRect_ = { 0, 0, 0, 0 }; } - bool WaitTaskFinished(); + void ResetGrContext() + { + cacheSurface_ = nullptr; + cacheCompletedSurface_ = nullptr; + RSFilter::clearGpuContext(); + } void Notify() { @@ -213,31 +235,41 @@ private: isCompleted_ = val; } - void SawpTexture() + void SwapTexture() { - std::unique_lock lock(grBackendTextureMutex_); std::swap(resultBackendTexture_, cacheCompletedBackendTexture_); + std::swap(cacheSurface_, cacheCompletedSurface_); } private: #ifndef USE_ROSEN_DRAWING - sk_sp cacheSurface_ = nullptr; GrBackendTexture cacheBackendTexture_; GrBackendTexture resultBackendTexture_; - SkISize surfaceSize_; - std::weak_ptr filter_; GrBackendTexture cacheCompletedBackendTexture_; + sk_sp cacheSurface_ = nullptr; + sk_sp cacheCompletedSurface_ = nullptr; + SkISize snapshotSize_; + SkISize snapshotSizeBefore_; + SkIRect dstRect_; + SkIRect dstRectBefore_; + std::shared_ptr filter_ = nullptr; + std::shared_ptr filterBefore_ = nullptr; #else - std::shared_ptr cacheSurface_ = nullptr; Drawing::BackendTexture cacheBackendTexture_; Drawing::BackendTexture resultBackendTexture_; - Drawing::RectI surfaceSize_; - std::weak_ptr filter_; Drawing::BackendTexture cacheCompletedBackendTexture_; + std::shared_ptr cacheSurface_ = nullptr; + std::shared_ptr cacheCompletedSurface_ = nullptr; + Drawing::RectI snapshotSize_; + Drawing::RectI snapshotSizeBefore_; + Drawing::RectI dstRect_; + Drawing::RectI dstRectBefore_; + std::shared_ptr filter_ = nullptr; + std::shared_ptr filterBefore_ = nullptr; #endif std::atomic cacheProcessStatus_ = CacheProcessStatus::WAITING; - std::shared_ptr cachedSnapshot_ = nullptr; - std::mutex grBackendTextureMutex_; + std::shared_ptr cachedSnapshotInTask_ = nullptr; + std::shared_ptr cachedSnapshotBefore_ = nullptr; std::condition_variable cvParallelRender_; std::shared_ptr handler_ = nullptr; bool isCompleted_ = false; @@ -248,6 +280,8 @@ private: const SkIRect& srcRect, const bool needSnapshotOutset = true); void GenerateFilteredSnapshot( RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& dstRect); + void FilterPartialRender( + RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& dstRect); void DrawCachedFilteredSnapshot(RSPaintFilterCanvas& canvas, const SkIRect& dstRect) const; // Validate the input srcRect and dstRect, and return the validated rects. std::tuple ValidateParams(RSPaintFilterCanvas& canvas, @@ -257,6 +291,8 @@ private: const Drawing::RectI& srcRect, const bool needSnapshotOutset = true); void GenerateFilteredSnapshot( RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const Drawing::RectI& dstRect); + void FilterPartialRender( + RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const Drawing::RectI& dstRect); void DrawCachedFilteredSnapshot(RSPaintFilterCanvas& canvas, const Drawing::RectI& dstRect) const; // Validate the input srcRect and dstRect, and return the validated rects. std::tuple ValidateParams(RSPaintFilterCanvas& canvas, @@ -275,6 +311,7 @@ private: // Note: rect in cachedSnapshot_ and cachedFilteredSnapshot_ is in device coordinate. std::shared_ptr cachedSnapshot_ = nullptr; std::shared_ptr cachedFilteredSnapshot_ = nullptr; + bool newCache_ = true; // Hash of previous filter, used to determine if we need to invalidate cachedFilteredSnapshot_. uint32_t cachedFilterHash_ = 0; diff --git a/rosen/modules/render_service_base/include/render/rs_filter.h b/rosen/modules/render_service_base/include/render/rs_filter.h index 1d484086f..6d83e775e 100644 --- a/rosen/modules/render_service_base/include/render/rs_filter.h +++ b/rosen/modules/render_service_base/include/render/rs_filter.h @@ -46,8 +46,14 @@ public: virtual bool InitSurface(Drawing::GPUContext* grContext); #endif virtual bool Render(); + virtual bool SaveFilteredImage(); + virtual void SwapInit(); + virtual bool SetDone(); + virtual void SetTaskRelease(); }; static std::function)> postTask; + static std::function)> setRelease; + static std::function clearGpuContext; virtual ~RSFilter(); RSFilter(const RSFilter&) = delete; diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp index d866a2da5..2699e8139 100755 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp @@ -26,8 +26,8 @@ namespace OHOS { namespace Rosen { -constexpr int DEFAULT_CACHE_WIDTH = 1344; -constexpr int DEFAULT_CACHE_HEIGHT = 2772; +constexpr int DEFAULT_CACHE_WIDTH = 1250; +constexpr int DEFAULT_CACHE_HEIGHT = 2710; constexpr int DEFAULT_PARTIAL_RENDER_ENABLED_VALUE = 2; constexpr int DEFAULT_UNI_PARTIAL_RENDER_ENABLED_VALUE = 4; constexpr int DEFAULT_CORRECTION_MODE_VALUE = 999; @@ -436,7 +436,7 @@ bool RSSystemProperties::GetFilterPartialRenderEnabled() // Determine whether the filter partial render should be enabled. The default value is 0, // which means that it is unenabled. static bool enabled = - std::atoi((system::GetParameter("persist.sys.graphic.filterPartialRenderEnabled", "0")).c_str()) != 0; + std::atoi((system::GetParameter("persist.sys.graphic.filterPartialRenderEnabled", "1")).c_str()) != 0; return enabled; } diff --git a/rosen/modules/render_service_base/src/property/rs_filter_cache_manager.cpp b/rosen/modules/render_service_base/src/property/rs_filter_cache_manager.cpp index f71052386..1128e94f3 100644 --- a/rosen/modules/render_service_base/src/property/rs_filter_cache_manager.cpp +++ b/rosen/modules/render_service_base/src/property/rs_filter_cache_manager.cpp @@ -26,6 +26,7 @@ namespace OHOS { namespace Rosen { +constexpr float PARALLEL_FILTER_RATIO_THRESHOLD = 0.8f; const char* RSFilterCacheManager::GetCacheState() const { if (cachedFilteredSnapshot_ != nullptr) { @@ -37,11 +38,11 @@ const char* RSFilterCacheManager::GetCacheState() const } } -#define CHECK_CACHE_PROCESS_STATUS \ - do { \ - if (cacheProcessStatus_.load() == CacheProcessStatus::WAITING) { \ - return false; \ - } \ +#define CHECK_CACHE_PROCESS_STATUS \ + do { \ + if (GetStatus() != CacheProcessStatus::DOING) { \ + return false; \ + } \ } while (false) #ifndef ROSEN_ARKUI_X const bool RSFilterCacheManager::RSFilterCacheTask::FilterPartialRenderEnabled = @@ -75,30 +76,55 @@ inline static bool isEqualRect(const Drawing::RectI& src, const RectI& dst) void RSFilterCacheManager::UpdateCacheStateWithFilterHash(const std::shared_ptr& filter) { + RS_OPTIONAL_TRACE_FUNC(); auto filterHash = filter->Hash(); - if (task_->GetStatus() == CacheProcessStatus::DONE) { - task_->Reset(); - } - if (RSFilterCacheTask::FilterPartialRenderEnabled && cachedSnapshot_ != nullptr && - cachedFilterHash_ != filterHash && cachedSnapshot_->cachedImage_ != nullptr) { -#ifndef USE_ROSEN_DRAWING - auto rsFilter = std::static_pointer_cast(filter); -#else - auto rsFilter = std::static_pointer_cast(filter); -#endif - PostPartialFilterRenderTask(rsFilter); - } if (cachedFilteredSnapshot_ == nullptr || cachedFilterHash_ == filterHash) { return; } - RS_OPTIONAL_TRACE_FUNC(); - // filter changed, clear the filtered snapshot. ROSEN_LOGD("RSFilterCacheManager::UpdateCacheStateWithFilterHash Cache expired. Reason: Cached filtered hash " "%{public}X does not match new hash %{public}X.", cachedFilterHash_, filterHash); cachedFilteredSnapshot_.reset(); } +#ifndef USE_ROSEN_DRAWING +void RSFilterCacheManager::PostPartialFilterRenderInit( + const std::shared_ptr& filter, const SkIRect& dstRect, int32_t canvasWidth, int32_t canvasHeight) +#else +void RSFilterCacheManager::PostPartialFilterRenderInit(const std::shared_ptr& filter, + const Drawing::RectI& dstRect, int32_t canvasWidth, int32_t canvasHeight) +#endif +{ + RS_OPTIONAL_TRACE_FUNC(); + task_->SetCompleted(task_->GetStatus() == CacheProcessStatus::DONE); + if (task_->GetStatus() == CacheProcessStatus::DOING) { + task_->SetCompleted(!task_->isFirstInit_); + } + if (task_->GetStatus() == CacheProcessStatus::DONE) { + task_->Reset(); + task_->isFirstInit_ = false; + task_->SwapTexture(); + task_->SetStatus(CacheProcessStatus::WAITING); + } + if (task_->isTaskRelease_.load()) { + return; + } + if (task_->cachedFirstFilter_ != nullptr && task_->isFirstInit_) { + cachedFilteredSnapshot_ = task_->cachedFirstFilter_; + } else { + task_->cachedFirstFilter_ = nullptr; + } + if (RSFilterCacheTask::FilterPartialRenderEnabled && + (cachedSnapshot_ != nullptr && cachedSnapshot_->cachedImage_ != nullptr) && + (cachedFilteredSnapshot_ == nullptr || cachedFilteredSnapshot_->cachedImage_ == nullptr) && +#ifndef USE_ROSEN_DRAWING + IsNearlyFullScreen(cachedSnapshot_->cachedRect_.size(), canvasWidth, canvasHeight)) { +#else + IsNearlyFullScreen(cachedSnapshot_->cachedRect_, canvasWidth, canvasHeight)) { +#endif + PostPartialFilterRenderTask(filter, dstRect); + } +} void RSFilterCacheManager::UpdateCacheStateWithFilterRegion() { @@ -137,17 +163,19 @@ bool RSFilterCacheManager::RSFilterCacheTask::InitSurface(GrRecordingContext* gr bool RSFilterCacheManager::RSFilterCacheTask::InitSurface(Drawing::GPUContext* grContext) #endif { - RS_TRACE_NAME("InitSurface"); - if (cacheSurface_ != nullptr) { + RS_OPTIONAL_TRACE_FUNC(); + if (!needClearSurface_) { return true; } + cacheSurface_ = nullptr; + auto runner = AppExecFwk::EventRunner::Current(); handler_ = std::make_shared(runner); #ifndef USE_ROSEN_DRAWING - SkImageInfo info = SkImageInfo::MakeN32Premul(surfaceSize_.width(), surfaceSize_.height()); + SkImageInfo info = SkImageInfo::MakeN32Premul(dstRect_.width(), dstRect_.height()); cacheSurface_ = SkSurface::MakeRenderTarget(grContext, SkBudgeted::kYes, info); #else - Drawing::ImageInfo info = Drawing::ImageInfo::MakeN32Premul(surfaceSize_.GetWidth(), surfaceSize_.GetHeight()); + Drawing::ImageInfo info = Drawing::ImageInfo::MakeN32Premul(dstRect_.GetWidth(), dstRect_.GetHeight()); cacheSurface_ = Drawing::Surface::MakeRenderTarget(grContext, true, info); #endif return cacheSurface_ != nullptr; @@ -179,12 +207,17 @@ bool RSFilterCacheManager::RSFilterCacheTask::Render() } #else surfaceOrigin = kBottomLeft_GrSurfaceOrigin; -#endif - auto threadImage = SkImage::MakeFromTexture(cacheCanvas->recordingContext(), cacheBackendTexture_, - surfaceOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); - auto src = SkRect::MakeSize(SkSize::Make(surfaceSize_)); - auto dst = SkRect::MakeSize(SkSize::Make(surfaceSize_)); -#else +#endif // RS_ENABLE_VK + auto threadImage = SkImage::MakeFromTexture(cacheCanvas->recordingContext(), cacheBackendTexture_, surfaceOrigin, + kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); + if (!threadImage) { + SetStatus(CacheProcessStatus::WAITING); + ROSEN_LOGE("RSFilterCacheManager::Render: threadImage is null"); + return false; + } + auto src = SkRect::MakeSize(SkSize::Make(snapshotSize_)); + auto dst = SkRect::MakeSize(SkSize::Make(dstRect_.size())); +#else // USE_ROSEN_DRAWING Drawing::TextureOrigin surfaceOrigin = Drawing::TextureOrigin::TOP_LEFT; #ifdef RS_ENABLE_VK if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || @@ -195,102 +228,100 @@ bool RSFilterCacheManager::RSFilterCacheTask::Render() } #else surfaceOrigin = Drawing::TextureOrigin::BOTTOM_LEFT; -#endif +#endif // RS_ENABLE_VK Drawing::BitmapFormat bitmapFormat = { Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_PREMUL }; auto threadImage = std::make_shared(); if (!threadImage->BuildFromTexture(*cacheCanvas->GetGPUContext(), cacheBackendTexture_.GetTextureInfo(), - surfaceOrigin, bitmapFormat, nullptr)) { + surfaceOrigin, bitmapFormat, nullptr)) { + SetStatus(CacheProcessStatus::WAITING); ROSEN_LOGE("RSFilterCacheManager::Render: cacheCanvas is null"); return false; } - auto src = Drawing::Rect(0, 0, surfaceSize_.GetWidth(), surfaceSize_.GetHeight()); - auto dst = Drawing::Rect(0, 0, surfaceSize_.GetWidth(), surfaceSize_.GetHeight()); -#endif + auto src = Drawing::Rect(0, 0, snapshotSize_.GetWidth(), snapshotSize_.GetHeight()); + auto dst = Drawing::Rect(0, 0, dstRect_.GetWidth(), dstRect_.GetHeight()); +#endif // USE_ROSEN_DRAWING CHECK_CACHE_PROCESS_STATUS; - { - auto filterTemp = filter_.lock(); - if (!filterTemp) { - SetStatus(CacheProcessStatus::WAITING); - ROSEN_LOGE("RSFilterCacheManager::Render: filterTemp is null"); - return false; - } - filterTemp->DrawImageRect(*cacheCanvas, threadImage, src, dst); - filterTemp->PostProcess(*cacheCanvas); - } + filter_->DrawImageRect(*cacheCanvas, threadImage, src, dst); + filter_->PostProcess(*cacheCanvas); + CHECK_CACHE_PROCESS_STATUS; + return true; +} + +bool RSFilterCacheManager::RSFilterCacheTask::SaveFilteredImage() +{ CHECK_CACHE_PROCESS_STATUS; #ifndef USE_ROSEN_DRAWING - cacheSurface_->flushAndSubmit(true); + resultBackendTexture_ = + cacheSurface_->getBackendTexture(SkSurface::BackendHandleAccess::kFlushRead_BackendHandleAccess); #else - cacheSurface_->FlushAndSubmit(true); + resultBackendTexture_ = cacheSurface_->GetBackendTexture(); #endif CHECK_CACHE_PROCESS_STATUS; - { - std::unique_lock lock(grBackendTextureMutex_); + return true; +} + +void RSFilterCacheManager::RSFilterCacheTask::SwapInit() +{ + RS_OPTIONAL_TRACE_FUNC(); + std::swap(filter_, filterBefore_); + std::swap(cachedSnapshotInTask_, cachedSnapshotBefore_); + std::swap(snapshotSize_, snapshotSizeBefore_); + std::swap(dstRect_, dstRectBefore_); + if (cachedSnapshotInTask_ != nullptr) { #ifndef USE_ROSEN_DRAWING - resultBackendTexture_ = - cacheSurface_->getBackendTexture(SkSurface::BackendHandleAccess::kFlushRead_BackendHandleAccess); + cacheBackendTexture_ = cachedSnapshotInTask_->cachedImage_->getBackendTexture(false); #else - resultBackendTexture_ = cacheSurface_->GetBackendTexture(); + cacheBackendTexture_ = cachedSnapshotInTask_->cachedImage_->GetBackendTexture(false, nullptr); #endif } - CHECK_CACHE_PROCESS_STATUS; - cacheProcessStatus_.store(CacheProcessStatus::DONE); - Notify(); - return true; } -bool RSFilterCacheManager::RSFilterCacheTask::WaitTaskFinished() +void RSFilterCacheManager::RSFilterCacheTask::SetTaskRelease() { - std::unique_lock lock(grBackendTextureMutex_); - if (GetStatus() != CacheProcessStatus::DOING) { - return GetStatus() == CacheProcessStatus::DONE; - } - const long TIME_OUT = 1; // 1 milliseconds - if (!cvParallelRender_.wait_for(lock, std::chrono::milliseconds(TIME_OUT), - [this] { return cacheProcessStatus_ == CacheProcessStatus::DONE; })) { - RS_OPTIONAL_TRACE_NAME("WaitTaskFinished, wait failed, CacheProcessStatus_:" + - std::to_string(static_cast(cacheProcessStatus_.load()))); - return false; + isTaskRelease_.store(false); +} + +bool RSFilterCacheManager::RSFilterCacheTask::SetDone() +{ + RS_OPTIONAL_TRACE_FUNC(); + CHECK_CACHE_PROCESS_STATUS; + if (isTaskRelease_.load()) { + SetStatus(CacheProcessStatus::WAITING); + } else { + SetStatus(CacheProcessStatus::DONE); } - RS_OPTIONAL_TRACE_NAME("WaitTaskFinished, wait success, CacheProcessStatus_:" + - std::to_string(static_cast(cacheProcessStatus_.load()))); return true; } - #ifndef USE_ROSEN_DRAWING -void RSFilterCacheManager::PostPartialFilterRenderTask(const std::shared_ptr& filter) +bool RSFilterCacheManager::IsNearlyFullScreen(SkISize imageSize, int32_t canvasWidth, int32_t canvasHeight) #else -void RSFilterCacheManager::PostPartialFilterRenderTask(const std::shared_ptr& filter) +bool RSFilterCacheManager::IsNearlyFullScreen(Drawing::RectI imageSize, int32_t canvasWidth, int32_t canvasHeight) #endif { RS_OPTIONAL_TRACE_FUNC(); - task_->SetCompleted(task_->GetStatus() == CacheProcessStatus::DONE); - if (task_->GetStatus() == CacheProcessStatus::DOING && !task_->isTaskTooLong && !task_->WaitTaskFinished()) { - task_->isTaskTooLong = true; - } - if (task_->GetStatus() == CacheProcessStatus::DONE) { - task_->SawpTexture(); - task_->SetStatus(CacheProcessStatus::WAITING); - task_->isTaskTooLong = false; - } - if (SoloTaskPrepare) { - SoloTaskPrepare = false; - } else { - task_->SetCompleted(false); - return; - } - // Prepare a backup of common resources for threads - if (RSFilter::postTask != nullptr && task_->GetStatus() == CacheProcessStatus::WAITING) { - // Because the screenshot is zoomed out, here you need to zoom in + auto widthThreshold = static_cast(canvasWidth * PARALLEL_FILTER_RATIO_THRESHOLD); + auto heightThreshold = static_cast(canvasHeight * PARALLEL_FILTER_RATIO_THRESHOLD); #ifndef USE_ROSEN_DRAWING - auto dstCopy = cachedSnapshot_->cachedRect_.makeOutset(1, 1); - task_->InitTask(filter, cachedSnapshot_, dstCopy.size()); + return imageSize.width() >= widthThreshold && imageSize.height() >= heightThreshold; #else - auto dstCopy = cachedSnapshot_->cachedRect_; - dstCopy.MakeOutset(1, 1); - task_->InitTask(filter, cachedSnapshot_, dstCopy); + return imageSize.GetWidth() >= widthThreshold && imageSize.GetHeight() >= heightThreshold; #endif +} + +#ifndef USE_ROSEN_DRAWING +void RSFilterCacheManager::PostPartialFilterRenderTask( + const std::shared_ptr& filter, const SkIRect& dstRect) +#else +void RSFilterCacheManager::PostPartialFilterRenderTask( + const std::shared_ptr& filter, const Drawing::RectI& dstRect) +#endif +{ + RS_OPTIONAL_TRACE_FUNC(); + // Prepare a backup of common resources for threads + if (RSFilter::postTask != nullptr && (task_->GetStatus() == CacheProcessStatus::WAITING)) { + // Because the screenshot is zoomed out, here you need to zoom in + task_->InitTask(filter, cachedSnapshot_, dstRect); task_->SetStatus(CacheProcessStatus::DOING); RSFilter::postTask(task_); } else { @@ -330,50 +361,39 @@ void RSFilterCacheManager::DrawFilter(RSPaintFilterCanvas& canvas, const std::sh } else { --cacheUpdateInterval_; } - +#ifndef USE_ROSEN_DRAWING + auto surface = canvas.getSurface(); + auto width = surface->width(); + auto height = surface->height(); +#else + auto surface = canvas.GetSurface(); + auto width = surface->Width(); + auto height = surface->Height(); +#endif + PostPartialFilterRenderInit(filter, dst, width, height); bool shouldClearFilteredCache = false; if (cachedFilteredSnapshot_ == nullptr || cachedFilteredSnapshot_->cachedImage_ == nullptr) { auto previousFilterHash = cachedFilterHash_; if (RSFilterCacheTask::FilterPartialRenderEnabled && task_->IsCompleted()) { -#ifndef USE_ROSEN_DRAWING - auto filteredSnapshot = SkImage::MakeFromTexture(canvas.recordingContext(), task_->GetResultTexture(), - kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); -#else - auto filteredSnapshot = std::make_shared(); - Drawing::BitmapFormat bitmapFormat = { Drawing::ColorType::COLORTYPE_RGBA_8888, - Drawing::AlphaType::ALPHATYPE_PREMUL }; - filteredSnapshot->BuildFromTexture(*canvas.GetGPUContext(), - task_->GetResultTexture().GetTextureInfo(), - Drawing::TextureOrigin::BOTTOM_LEFT, bitmapFormat, nullptr); -#endif - auto filteredRect = dst; -#ifndef USE_ROSEN_DRAWING - if (RSSystemProperties::GetImageGpuResourceCacheEnable( - filteredSnapshot->width(), filteredSnapshot->height())) { - ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", - filteredSnapshot->width(), filteredSnapshot->height()); - as_IB(filteredSnapshot)->hintCacheGpuResource(); - } -#else - if (RSSystemProperties::GetImageGpuResourceCacheEnable( - filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight())) { - ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", - filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight()); - as_IB(filteredSnapshot->ExportSkImage().get())->hintCacheGpuResource(); - } -#endif - cachedFilteredSnapshot_ = - std::make_shared(std::move(filteredSnapshot), filteredRect); - cachedFilterHash_ = filter->Hash(); + FilterPartialRender(canvas, filter, dst); } else { GenerateFilteredSnapshot(canvas, filter, dst); } - SoloTaskPrepare = true; + newCache_ = true; // If 1. the filter hash matches, 2. the filter region is whole snapshot region, we can safely clear original // snapshot, else we need to clear the filtered snapshot. shouldClearFilteredCache = previousFilterHash != cachedFilterHash_ || !isEqualRect(dst, snapshotRegion_); + } else if (RSFilterCacheTask::FilterPartialRenderEnabled && task_->IsCompleted()) { + FilterPartialRender(canvas, filter, dst); + } else { + newCache_ = false; + } + if (task_->GetStatus() == CacheProcessStatus::DOING && task_->isFirstInit_ && + task_->cachedFirstFilter_ == nullptr) { + task_->cachedFirstFilter_ = cachedFilteredSnapshot_; } DrawCachedFilteredSnapshot(canvas, dst); + task_->SetCompleted(false); // To reduce the memory consumption, we only keep either the cached snapshot or the filtered image. CompactCache(shouldClearFilteredCache); } @@ -428,9 +448,8 @@ const std::shared_ptr RSFilterCacheManage } #ifndef USE_ROSEN_DRAWING -void RSFilterCacheManager::TakeSnapshot( - RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& srcRect, - const bool needSnapshotOutset) +void RSFilterCacheManager::TakeSnapshot(RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, + const SkIRect& srcRect, const bool needSnapshotOutset) { auto skSurface = canvas.GetSurface(); if (skSurface == nullptr) { @@ -474,9 +493,8 @@ void RSFilterCacheManager::TakeSnapshot( pendingPurge_ = false; } #else -void RSFilterCacheManager::TakeSnapshot( - RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const Drawing::RectI& srcRect, - const bool needSnapshotOutset) +void RSFilterCacheManager::TakeSnapshot(RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, + const Drawing::RectI& srcRect, const bool needSnapshotOutset) { auto drawingSurface = canvas.GetSurface(); if (drawingSurface == nullptr) { @@ -520,6 +538,51 @@ void RSFilterCacheManager::TakeSnapshot( } #endif +#ifndef USE_ROSEN_DRAWING +void RSFilterCacheManager::FilterPartialRender( + RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& dstRect) +#else +void RSFilterCacheManager::FilterPartialRender( + RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const Drawing::RectI& dstRect) +#endif +{ + RS_OPTIONAL_TRACE_FUNC(); +#ifndef USE_ROSEN_DRAWING + auto filteredSnapshot = SkImage::MakeFromTexture(canvas.recordingContext(), task_->GetResultTexture(), + kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); +#else + auto filteredSnapshot = std::make_shared(); + Drawing::BitmapFormat bitmapFormat = { Drawing::ColorType::COLORTYPE_RGBA_8888, + Drawing::AlphaType::ALPHATYPE_PREMUL }; + filteredSnapshot->BuildFromTexture(*canvas.GetGPUContext(), task_->GetResultTexture().GetTextureInfo(), + Drawing::TextureOrigin::BOTTOM_LEFT, bitmapFormat, nullptr); +#endif + if (filteredSnapshot == nullptr) { + GenerateFilteredSnapshot(canvas, filter, dstRect); + } else { +#ifndef USE_ROSEN_DRAWING + auto filteredRect = SkIRect::MakeWH(filteredSnapshot->width(), filteredSnapshot->height()); + if (RSSystemProperties::GetImageGpuResourceCacheEnable(filteredSnapshot->width(), filteredSnapshot->height())) { + ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", + filteredSnapshot->width(), filteredSnapshot->height()); + as_IB(filteredSnapshot)->hintCacheGpuResource(); + } +#else + auto filteredRect = Drawing::RectI(0, 0, filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight()); + if (RSSystemProperties::GetImageGpuResourceCacheEnable( + filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight())) { + ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", + filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight()); + as_IB(filteredSnapshot->ExportSkImage().get())->hintCacheGpuResource(); + } +#endif + cachedFilteredSnapshot_.reset(); + cachedFilteredSnapshot_ = + std::make_shared(std::move(filteredSnapshot), task_->GetDstRect()); + cachedFilterHash_ = filter->Hash(); + } +} + #ifndef USE_ROSEN_DRAWING void RSFilterCacheManager::GenerateFilteredSnapshot( RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& dstRect) @@ -574,8 +637,8 @@ void RSFilterCacheManager::GenerateFilteredSnapshot( } #else auto filteredSnapshot = offscreenSurface->GetImageSnapshot(); - if (RSSystemProperties::GetImageGpuResourceCacheEnable(filteredSnapshot->GetWidth(), - filteredSnapshot->GetHeight())) { + if (RSSystemProperties::GetImageGpuResourceCacheEnable( + filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight())) { ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight()); as_IB(filteredSnapshot->ExportSkImage().get())->hintCacheGpuResource(); @@ -608,8 +671,14 @@ void RSFilterCacheManager::DrawCachedFilteredSnapshot(RSPaintFilterCanvas& canva ClipVisibleRect(canvas); // The cache type and parameters has been validated, dstRect must be subset of cachedFilteredSnapshot_->cachedRect_. - auto dst = SkRect::Make(dstRect); - auto src = SkRect::Make(dstRect.makeOffset(-cachedFilteredSnapshot_->cachedRect_.topLeft())); + SkRect dst = SkRect::Make(dstRect); + SkRect src; + if (newCache_) { + src = SkRect::MakeSize(SkSize::Make(cachedFilteredSnapshot_->cachedImage_->dimensions())); + } else { + src = SkRect::Make(dstRect.makeOffset(-cachedFilteredSnapshot_->cachedRect_.topLeft())); + src.intersect(SkRect::Make(cachedFilteredSnapshot_->cachedImage_->bounds())); + } SkPaint paint; paint.setAntiAlias(true); @@ -632,9 +701,17 @@ void RSFilterCacheManager::DrawCachedFilteredSnapshot(RSPaintFilterCanvas& canva ClipVisibleRect(canvas); // The cache type and parameters has been validated, dstRect must be subset of cachedFilteredSnapshot_->cachedRect_. - Drawing::Rect dst = {dstRect.GetLeft(), dstRect.GetTop(), dstRect.GetRight(), dstRect.GetBottom()}; - Drawing::Rect src = {dstRect.GetLeft(), dstRect.GetTop(), dstRect.GetRight(), dstRect.GetBottom()}; - src.Offset(-cachedFilteredSnapshot_->cachedRect_.GetLeft(), -cachedFilteredSnapshot_->cachedRect_.GetTop()); + Drawing::Rect dst(dstRect.GetLeft(), dstRect.GetTop(), dstRect.GetRight(), dstRect.GetBottom()); + Drawing::Rect src; + if (newCache_) { + src = { 0, 0, cachedFilteredSnapshot_->cachedImage_->GetWidth(), + cachedFilteredSnapshot_->cachedImage_->GetHeight() }; + } else { + src = { dstRect.GetLeft(), dstRect.GetTop(), dstRect.GetRight(), dstRect.GetBottom() }; + src.Offset(-cachedFilteredSnapshot_->cachedRect_.GetLeft(), -cachedFilteredSnapshot_->cachedRect_.GetTop()); + src.Intersect(Drawing::Rect(0, 0, cachedFilteredSnapshot_->cachedImage_->GetWidth(), + cachedFilteredSnapshot_->cachedImage_->GetHeight())); + } Drawing::Brush brush; brush.SetAntiAlias(true); @@ -654,18 +731,20 @@ void RSFilterCacheManager::InvalidateCache(CacheType cacheType) if (cacheType & CacheType::CACHE_TYPE_FILTERED_SNAPSHOT) { cachedFilteredSnapshot_.reset(); } - task_->SetStatus(CacheProcessStatus::WAITING); - task_->SetCompleted(false); - task_->Reset(); } void RSFilterCacheManager::ReleaseCacheOffTree() { - RS_OPTIONAL_TRACE_NAME("WaitTaskFinished, wait failed, CacheProcessStatus_:"); + RS_OPTIONAL_TRACE_FUNC(); ROSEN_LOGD("RSFilterCacheManager::ReleaseCacheOffTree task_:%{public}p", task_.get()); cachedSnapshot_.reset(); cachedFilteredSnapshot_.reset(); + newCache_ = false; + task_->isTaskRelease_.store(true); + task_->cachedFirstFilter_ = nullptr; + task_->ResetInTask(); task_->SetCompleted(false); + task_->isFirstInit_ = true; task_->SetStatus(CacheProcessStatus::WAITING); task_->Reset(); if (task_->GetHandler() != nullptr) { @@ -673,6 +752,9 @@ void RSFilterCacheManager::ReleaseCacheOffTree() task_->GetHandler()->PostTask( [task_tmp]() { task_tmp->ResetGrContext(); }, AppExecFwk::EventQueue::Priority::IMMEDIATE); } + if (RSFilter::setRelease != nullptr) { + RSFilter::setRelease(task_); + } } #ifndef USE_ROSEN_DRAWING @@ -689,8 +771,8 @@ inline void RSFilterCacheManager::ClipVisibleRect(RSPaintFilterCanvas& canvas) { auto visibleRectF = canvas.GetVisibleRect(); visibleRectF.Round(); - Drawing::RectI visibleIRect = {(int)visibleRectF.GetLeft(), (int)visibleRectF.GetTop(), - (int)visibleRectF.GetRight(), (int)visibleRectF.GetBottom()}; + Drawing::RectI visibleIRect = { (int)visibleRectF.GetLeft(), (int)visibleRectF.GetTop(), + (int)visibleRectF.GetRight(), (int)visibleRectF.GetBottom() }; auto deviceClipRect = canvas.GetDeviceClipBounds(); if (!visibleIRect.IsEmpty() && deviceClipRect.Intersect(visibleIRect)) { canvas.ClipIRect(visibleIRect, Drawing::ClipOp::INTERSECT); @@ -753,9 +835,8 @@ std::tuple RSFilterCacheManager::ValidateParams( return { src, dst }; } #else -std::tuple RSFilterCacheManager::ValidateParams( - RSPaintFilterCanvas& canvas, const std::optional& srcRect, - const std::optional& dstRect) +std::tuple RSFilterCacheManager::ValidateParams(RSPaintFilterCanvas& canvas, + const std::optional& srcRect, const std::optional& dstRect) { Drawing::RectI src; Drawing::RectI dst; diff --git a/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp b/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp index fddb0e047..96a284977 100644 --- a/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp +++ b/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp @@ -91,7 +91,7 @@ std::string RSBlurFilter::GetDescription() bool RSBlurFilter::IsValid() const { - constexpr float epsilon = 0.05f; + constexpr float epsilon = 0.999f; return blurRadiusX_ > epsilon || blurRadiusY_ > epsilon; } diff --git a/rosen/modules/render_service_base/src/render/rs_filter.cpp b/rosen/modules/render_service_base/src/render/rs_filter.cpp index d85f0ed8d..84c3fe7b3 100644 --- a/rosen/modules/render_service_base/src/render/rs_filter.cpp +++ b/rosen/modules/render_service_base/src/render/rs_filter.cpp @@ -29,6 +29,8 @@ RSFilter::RSFilter() RSFilter::~RSFilter() {} std::function)> RSFilter::postTask = nullptr; +std::function)> RSFilter::setRelease = nullptr; +std::function RSFilter::clearGpuContext = nullptr; std::string RSFilter::GetDescription() { diff --git a/rosen/modules/render_service_base/src/render/rs_material_filter.cpp b/rosen/modules/render_service_base/src/render/rs_material_filter.cpp index 95571ac0a..3a1297b02 100644 --- a/rosen/modules/render_service_base/src/render/rs_material_filter.cpp +++ b/rosen/modules/render_service_base/src/render/rs_material_filter.cpp @@ -285,7 +285,7 @@ std::shared_ptr RSMaterialFilter::TransformFilter(float fraction) cons bool RSMaterialFilter::IsValid() const { - constexpr float epsilon = 0.05f; + constexpr float epsilon = 0.999f; return radius_ > epsilon; } -- Gitee From ee7a19de603767dd0fa51f9e785d65c5d67f65b7 Mon Sep 17 00:00:00 2001 From: shiyueeee Date: Fri, 5 Jan 2024 22:08:53 +0800 Subject: [PATCH 07/12] specify limited contentdirty case within surface assigned to subthread Signed-off-by: shiyueeee Change-Id: I3dd8036738499025e32b319cd3c811b292e113f4 --- .../core/pipeline/rs_main_thread.cpp | 25 +++---- .../core/pipeline/rs_main_thread.h | 2 +- .../core/pipeline/rs_uni_render_visitor.cpp | 71 +++++++++++-------- .../core/pipeline/rs_uni_render_visitor.h | 7 +- .../core/system/rs_system_parameters.cpp | 2 +- .../core/system/rs_system_parameters.h | 1 + .../include/pipeline/rs_surface_render_node.h | 12 +++- .../src/pipeline/rs_surface_render_node.cpp | 27 +++++++ .../unittest/pipeline/rs_main_thread_test.cpp | 19 ++--- .../pipeline/rs_uni_render_visitor_test.cpp | 16 ++--- 10 files changed, 112 insertions(+), 70 deletions(-) diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp index 6b34d7296..09eda4c78 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp @@ -2730,27 +2730,18 @@ bool RSMainThread::IsDrawingGroupChanged(RSRenderNode& cacheRootNode) const return false; } -bool RSMainThread::CheckIfInstanceOnlySurfaceBasicGeoTransform(NodeId instanceNodeId) const +void RSMainThread::CheckAndUpdateInstanceContentStaticStatus(std::shared_ptr instanceNode) const { - if (instanceNodeId == INVALID_NODEID) { - RS_LOGE("CheckIfInstanceOnlySurfaceBasicGeoTransform instanceNodeId invalid."); - return false; + if (instanceNode == nullptr) { + RS_LOGE("CheckAndUpdateInstanceContentStaticStatus instanceNode invalid."); + return ; } - auto iter = context_->activeNodesInRoot_.find(instanceNodeId); + auto iter = context_->activeNodesInRoot_.find(instanceNode->GetId()); if (iter != context_->activeNodesInRoot_.end()) { - const auto& activeNodeIds = iter->second; - for (auto [id, subNode] : activeNodeIds) { - auto node = subNode.lock(); - if (node == nullptr) { - continue; - } - // filter active nodes except instance surface itself - if (id != instanceNodeId || !node->IsOnlyBasicGeoTransform()) { - return false; - } - } + instanceNode->UpdateSurfaceCacheContentStatic(iter->second); + } else { + instanceNode->UpdateSurfaceCacheContentStatic({}); } - return true; } FrameRateRange RSMainThread::CalcAnimateFrameRateRange(std::shared_ptr node) diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.h b/rosen/modules/render_service/core/pipeline/rs_main_thread.h index 810fe798c..f379fd241 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.h +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.h @@ -137,7 +137,7 @@ public: bool IsDrawingGroupChanged(RSRenderNode& cacheRootNode) const; // check if active instance only move or scale it's main window surface without rearrangement // instanceNodeId should be MainWindowType, or it cannot grep correct app's info - bool CheckIfInstanceOnlySurfaceBasicGeoTransform(NodeId instanceNodeId) const; + void CheckAndUpdateInstanceContentStaticStatus(std::shared_ptr instanceNode) const; void RegisterApplicationAgent(uint32_t pid, sptr app); void UnRegisterApplicationAgent(sptr app); diff --git a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp index 5aeea9438..2c4cca932 100644 --- a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp @@ -296,15 +296,17 @@ void RSUniRenderVisitor::CopyPropertyForParallelVisitor(RSUniRenderVisitor *main isSubThread_ = true; } -void RSUniRenderVisitor::UpdateStaticCacheSubTree(const std::shared_ptr& cacheRootNode, +void RSUniRenderVisitor::UpdateSubTreeInCache(const std::shared_ptr& cacheRootNode, const std::list& children) { for (auto& child : children) { if (child == nullptr) { continue; } - if (child->GetDrawingCacheType() != RSDrawingCacheType::DISABLED_CACHE) { - child->SetDrawingCacheChanged(false); + if (child->IsDirty()) { + curDirty_ = child->IsDirty(); + child->Prepare(shared_from_this()); + continue; } // set flag for surface node whose children contain shared transition node if (child->GetSharedTransitionParam().has_value() && curSurfaceNode_) { @@ -312,7 +314,7 @@ void RSUniRenderVisitor::UpdateStaticCacheSubTree(const std::shared_ptrReinterpretCastTo()) { - // fully prepare hwcLayer and its subnodes + // fully prepare hwcLayer Layer and its subnodes if (surfaceNode->IsHardwareEnabledType()) { PrepareSurfaceRenderNode(*surfaceNode); return; @@ -337,7 +339,7 @@ void RSUniRenderVisitor::UpdateStaticCacheSubTree(const std::shared_ptrIsBackgroundFilterCacheValid()); } } - UpdateStaticCacheSubTree(child, child->GetSortedChildren()); + UpdateSubTreeInCache(child, child->GetSortedChildren()); } } @@ -350,7 +352,7 @@ void RSUniRenderVisitor::PrepareEffectNodeIfCacheReuse(const std::shared_ptrInitializeEffectRegion(); effectNode->Update(*curSurfaceDirtyManager_, cacheRootNode, dirtyFlag_, prepareClipRect_); - UpdateStaticCacheSubTree(effectNode, effectNode->GetSortedChildren()); + UpdateSubTreeInCache(effectNode, effectNode->GetSortedChildren()); effectNode->SetEffectRegion(effectRegion_); if (effectNode->GetRenderProperties().NeedFilter()) { UpdateForegroundFilterCacheWithDirty(*effectNode, *curSurfaceDirtyManager_); @@ -393,10 +395,10 @@ void RSUniRenderVisitor::PrepareChildren(RSRenderNode& node) if (curSurfaceDirtyManager_ != nullptr && isCachedSurfaceReuse_ && !node.HasMustRenewedInfo()) { RS_OPTIONAL_TRACE_NAME_FMT("CachedSurfaceReuse node %llu quickSkip subtree", node.GetId()); } else if (curSurfaceDirtyManager_ != nullptr && curDisplayNode_ != nullptr && - (isCachedSurfaceReuse_ || !UpdateCacheChangeStatus(node))) { - RS_OPTIONAL_TRACE_NAME_FMT("UpdateCacheChangeStatus node %llu simply update subtree, isCachedSurfaceReuse_ %d", - node.GetId(), isCachedSurfaceReuse_); - UpdateStaticCacheSubTree(node.ReinterpretCastTo(), children); + (isCachedSurfaceReuse_ || isSurfaceDirtyNodeLimited_ || !UpdateCacheChangeStatus(node))) { + RS_OPTIONAL_TRACE_NAME_FMT("UpdateCacheChangeStatus node %llu simply update subtree, isCachedSurfaceReuse_ %d," + " isSurfaceDirtyNodeLimited_ %d", node.GetId(), isCachedSurfaceReuse_, isSurfaceDirtyNodeLimited_); + UpdateSubTreeInCache(node.ReinterpretCastTo(), children); } else { // Get delay flag to restore geo changes if (node.GetCacheGeoPreparationDelay()) { @@ -890,7 +892,7 @@ bool RSUniRenderVisitor::CheckIfSurfaceRenderNodeStatic(RSSurfaceRenderNode& nod if (result) { return false; } - node.SetSurfaceCacheContentStatic(true); + node.UpdateSurfaceCacheContentStatic({}); RS_OPTIONAL_TRACE_NAME("Skip static surface " + node.GetName() + " nodeid - pid: " + std::to_string(node.GetId()) + " - " + std::to_string(ExtractPid(node.GetId()))); // static node's dirty region is empty @@ -1040,11 +1042,10 @@ void RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeBeforeUpdate(RSSurfaceRe node.ResetFilterNodes(); effectNodeNum_ = 0; node.SetUseEffectNodes(0); - node.SetSurfaceCacheContentStatic( - RSMainThread::Instance()->CheckIfInstanceOnlySurfaceBasicGeoTransform(node.GetId())); // [planning] check if it is not reset recursively firstVisitedCache_ = INVALID_NODEID; curSurfaceNode_ = node.ReinterpretCastTo(); + RSMainThread::Instance()->CheckAndUpdateInstanceContentStaticStatus(curSurfaceNode_); curSurfaceDirtyManager_ = node.GetDirtyManager(); if (curSurfaceDirtyManager_ == nullptr) { RS_LOGE("RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeBeforeUpdate %{public}s has no" @@ -1059,14 +1060,7 @@ void RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeBeforeUpdate(RSSurfaceRe if (isTargetDirtyRegionDfxEnabled_ && CheckIfSurfaceTargetedForDFX(node.GetName())) { curSurfaceDirtyManager_->MarkAsTargetForDfx(); } - } - if (node.IsMainWindowType()) { - isCachedSurfaceReuse_ = (quickSkipPrepareType_ == QuickSkipPrepareType::STATIC_CACHE_SURFACE) && - (RSMainThread::Instance()->GetDeviceType() == DeviceType::PC) && - CheckIfUIFirstSurfaceContentReusable(curSurfaceNode_); - if (isCachedSurfaceReuse_) { - node.SetCacheGeoPreparationDelay(dirtyFlag_); - } + ClassifyUIFirstSurfaceDirtyStatus(node); } // collect app window node's child hardware enabled node @@ -1076,7 +1070,22 @@ void RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeBeforeUpdate(RSSurfaceRe } } -bool RSUniRenderVisitor::CheckIfUIFirstSurfaceContentReusable(std::shared_ptr& node) +void RSUniRenderVisitor::ClassifyUIFirstSurfaceDirtyStatus(RSSurfaceRenderNode& node) +{ + if (node.IsMainWindowType()) { + isCachedSurfaceReuse_ = (quickSkipPrepareType_ >= QuickSkipPrepareType::STATIC_CACHE_SURFACE) && + (RSMainThread::Instance()->GetDeviceType() == DeviceType::PC) && + CheckIfUIFirstSurfaceContentReusable(curSurfaceNode_, isSurfaceDirtyNodeLimited_); + isSurfaceDirtyNodeLimited_ = (quickSkipPrepareType_ == QuickSkipPrepareType::CONTENT_DIRTY_CACHE_SURFACE) && + isSurfaceDirtyNodeLimited_ && node.IsOnlyBasicGeoTransform() && node.IsContentDirtyNodeLimited(); + if (isCachedSurfaceReuse_) { + node.SetCacheGeoPreparationDelay(dirtyFlag_); + } + } +} + +bool RSUniRenderVisitor::CheckIfUIFirstSurfaceContentReusable(std::shared_ptr& node, + bool& isAssigned) { if (!isUIFirst_ || node == nullptr) { return false; @@ -1086,17 +1095,18 @@ bool RSUniRenderVisitor::CheckIfUIFirstSurfaceContentReusable(std::shared_ptrGetInstanceRootNode()) { auto surfaceParent = parentInstance->ReinterpretCastTo(); if (surfaceParent && surfaceParent->IsLeashWindow()) { - RS_OPTIONAL_TRACE_NAME(surfaceParent->GetName() + " CheckIfUIFirstSurfaceContentReusable(leash): " + - std::to_string(surfaceParent->IsUIFirstCacheReusable(deviceType))); - return RSUniRenderUtil::IsNodeAssignSubThread(surfaceParent, curDisplayNode_->IsRotationChanged()) && - surfaceParent->IsUIFirstCacheReusable(deviceType); + isAssigned = + RSUniRenderUtil::IsNodeAssignSubThread(surfaceParent, curDisplayNode_->IsRotationChanged()); + RS_OPTIONAL_TRACE_NAME_FMT("%s CheckIfUIFirstSurfaceContentReusable(leash): %d, isAssigned %d", + surfaceParent->GetName().c_str(), surfaceParent->IsUIFirstCacheReusable(deviceType), isAssigned); + return isAssigned && surfaceParent->IsUIFirstCacheReusable(deviceType); } } } - RS_OPTIONAL_TRACE_NAME(node->GetName() + " CheckIfUIFirstSurfaceContentReusable(mainwindow): " + - std::to_string(node->IsUIFirstCacheReusable(deviceType))); - return RSUniRenderUtil::IsNodeAssignSubThread(node, curDisplayNode_->IsRotationChanged()) && - node->IsUIFirstCacheReusable(deviceType); + isAssigned = RSUniRenderUtil::IsNodeAssignSubThread(node, curDisplayNode_->IsRotationChanged()); + RS_OPTIONAL_TRACE_NAME_FMT("%s CheckIfUIFirstSurfaceContentReusable(mainwindow): %d, isAssigned %d", + node->GetName().c_str(), node->IsUIFirstCacheReusable(deviceType), isAssigned); + return isAssigned && node->IsUIFirstCacheReusable(deviceType); } void RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeAfterUpdate(RSSurfaceRenderNode& node) @@ -1116,6 +1126,7 @@ void RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeAfterUpdate(RSSurfaceRen } if (node.IsMainWindowType()) { isCachedSurfaceReuse_ = false; + isSurfaceDirtyNodeLimited_ = false; node.SetUseEffectNodes(effectNodeNum_); bool hasFilter = node.IsTransparent() && properties.NeedFilter(); bool hasHardwareNode = !node.GetChildHardwareEnabledNodes().empty(); diff --git a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.h b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.h index bd91d9b12..e32c5c903 100644 --- a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.h +++ b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.h @@ -277,7 +277,9 @@ private: * mainwindow check if it has leashwindow parent * If so, check parent or check itself */ - bool CheckIfUIFirstSurfaceContentReusable(std::shared_ptr& node); + bool CheckIfUIFirstSurfaceContentReusable(std::shared_ptr& node, bool& isAssigned); + // currently classify surface assigned subthread specific dirty case for preparation + void ClassifyUIFirstSurfaceDirtyStatus(RSSurfaceRenderNode& node); void PrepareTypesOfSurfaceRenderNodeBeforeUpdate(RSSurfaceRenderNode& node); void PrepareTypesOfSurfaceRenderNodeAfterUpdate(RSSurfaceRenderNode& node); @@ -287,7 +289,7 @@ private: bool IsDrawingCacheStatic(RSRenderNode& node); // if cache root reuses, update its subtree // [attention] check curSurfaceDirtyManager_ before function calls - void UpdateStaticCacheSubTree(const std::shared_ptr& cacheRootNode, + void UpdateSubTreeInCache(const std::shared_ptr& cacheRootNode, const std::list& children); // set node cacheable animation after checking whold child tree void SetNodeCacheChangeStatus(RSRenderNode& node); @@ -430,6 +432,7 @@ private: // currently available to uiFirst bool isCachedSurfaceReuse_ = false; uint32_t effectNodeNum_ = 0; + bool isSurfaceDirtyNodeLimited_ = false; bool isDirtyRegionAlignedEnable_ = false; std::shared_ptr surfaceNodePrepareMutex_; diff --git a/rosen/modules/render_service/core/system/rs_system_parameters.cpp b/rosen/modules/render_service/core/system/rs_system_parameters.cpp index 7714e6441..272f988da 100644 --- a/rosen/modules/render_service/core/system/rs_system_parameters.cpp +++ b/rosen/modules/render_service/core/system/rs_system_parameters.cpp @@ -62,7 +62,7 @@ bool RSSystemParameters::GetShowRefreshRateEnabled() QuickSkipPrepareType RSSystemParameters::GetQuickSkipPrepareType() { - static CachedHandle g_Handle = CachedParameterCreate("rosen.quickskipprepare.enabled", "4"); + static CachedHandle g_Handle = CachedParameterCreate("rosen.quickskipprepare.enabled", "5"); int changed = 0; const char *type = CachedParameterGetChanged(g_Handle, &changed); return static_cast(ConvertToInt(type, DEFAULT_QUICK_SKIP_PREPARE_TYPE_VALUE)); diff --git a/rosen/modules/render_service/core/system/rs_system_parameters.h b/rosen/modules/render_service/core/system/rs_system_parameters.h index 320118c1a..24cfba24f 100644 --- a/rosen/modules/render_service/core/system/rs_system_parameters.h +++ b/rosen/modules/render_service/core/system/rs_system_parameters.h @@ -31,6 +31,7 @@ enum class QuickSkipPrepareType { STATIC_APP_INSTANCE, // 2, in case of dirty process, skip static app instance's preparation STATIC_CACHE, // 3, in case of dirty instance, simplify static (drawing)cache's preparation STATIC_CACHE_SURFACE, // 4, in case of dirty instance, simplify surface's static cache's preparation + CONTENT_DIRTY_CACHE_SURFACE, // 5, simplify dirty cache surface's subtree preparation }; class RSB_EXPORT RSSystemParameters final { diff --git a/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h b/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h index df8b80c31..f203a236e 100644 --- a/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h +++ b/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h @@ -876,9 +876,14 @@ public: return surfaceCacheContentStatic_; } - void SetSurfaceCacheContentStatic(bool contentStatic) + void UpdateSurfaceCacheContentStatic( + const std::unordered_map>& activeNodeIds); + // temperory limit situation: + // subtree no drawingcache and geodirty + // contentdirty 1 specifically for buffer update + bool IsContentDirtyNodeLimited() const { - surfaceCacheContentStatic_ = contentStatic; + return drawingCacheNodes_.empty() && dirtyGeoNodeNum_ == 0 && dirtyContentNodeNum_ <= 1; } size_t GetLastFrameChildrenCnt() @@ -1046,6 +1051,9 @@ private: std::vector childrenFilterRectsCacheValid_; std::vector> childrenFilterNodes_; std::unordered_set abilityNodeIds_; + size_t dirtyContentNodeNum_ = 0; + size_t dirtyGeoNodeNum_ = 0; + size_t dirtynodeNum_ = 0; // transparent region of the surface, floating window's container window is always treated as transparent Occlusion::Region transparentRegion_; diff --git a/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp index 3980188f9..cf48b0597 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp @@ -1457,6 +1457,33 @@ void RSSurfaceRenderNode::ResetAbilityNodeIds() abilityNodeIds_.clear(); } +void RSSurfaceRenderNode::UpdateSurfaceCacheContentStatic( + const std::unordered_map>& activeNodeIds) +{ + dirtyContentNodeNum_ = 0; + dirtyGeoNodeNum_ = 0; + dirtynodeNum_ = activeNodeIds.size(); + surfaceCacheContentStatic_ = IsOnlyBasicGeoTransform(); + if (dirtynodeNum_ == 0) { + RS_LOGD("Clear surface %{public}" PRIu64 " dirtynodes surfaceCacheContentStatic_:%{public}d", + GetId(), surfaceCacheContentStatic_); + return; + } + for (auto [id, subNode] : activeNodeIds) { + auto node = subNode.lock(); + if (node == nullptr || (id == GetId() && surfaceCacheContentStatic_)) { + continue; + } + // classify active nodes except instance surface itself + if (node->IsContentDirty()) { + dirtyContentNodeNum_++; + } else { + dirtyGeoNodeNum_++; + } + } + surfaceCacheContentStatic_ = surfaceCacheContentStatic_ && !(dirtyContentNodeNum_ == 0 || dirtyGeoNodeNum_ == 0); +} + const std::unordered_set& RSSurfaceRenderNode::GetAbilityNodeIds() const { return abilityNodeIds_; diff --git a/rosen/test/render_service/render_service/unittest/pipeline/rs_main_thread_test.cpp b/rosen/test/render_service/render_service/unittest/pipeline/rs_main_thread_test.cpp index c9a44532d..e5e12695d 100644 --- a/rosen/test/render_service/render_service/unittest/pipeline/rs_main_thread_test.cpp +++ b/rosen/test/render_service/render_service/unittest/pipeline/rs_main_thread_test.cpp @@ -553,42 +553,43 @@ HWTEST_F(RSMainThreadTest, AddActiveNode, TestSize.Level1) } /** - * @tc.name: CheckIfInstanceOnlySurfaceBasicGeoTransform01 + * @tc.name: CheckAndUpdateInstanceContentStaticStatus01 * @tc.desc: Test static instance(no dirty) would be classify as only basic geo transform * @tc.type: FUNC * @tc.require: issueI8IXTX */ -HWTEST_F(RSMainThreadTest, CheckIfInstanceOnlySurfaceBasicGeoTransform01, TestSize.Level1) +HWTEST_F(RSMainThreadTest, CheckAndUpdateInstanceContentStaticStatus01, TestSize.Level1) { auto mainThread = RSMainThread::Instance(); mainThread->context_->activeNodesInRoot_.clear(); // valid nodeid NodeId id = 1; - auto node = std::make_shared(id, mainThread->context_); + auto node = std::make_shared(id, mainThread->context_); ASSERT_NE(node, nullptr); - ASSERT_EQ(mainThread->CheckIfInstanceOnlySurfaceBasicGeoTransform(id), true); + mainThread->CheckAndUpdateInstanceContentStaticStatus(node); + ASSERT_EQ(node->GetSurfaceCacheContentStatic(), true); } /** - * @tc.name: CheckIfInstanceOnlySurfaceBasicGeoTransform02 + * @tc.name: CheckAndUpdateInstanceContentStaticStatus02 * @tc.desc: Test new instance would not be classify as only basic geo transform * @tc.type: FUNC * @tc.require: issueI8IXTX */ -HWTEST_F(RSMainThreadTest, CheckIfInstanceOnlySurfaceBasicGeoTransform02, TestSize.Level1) +HWTEST_F(RSMainThreadTest, CheckAndUpdateInstanceContentStaticStatus02, TestSize.Level1) { auto mainThread = RSMainThread::Instance(); mainThread->context_->activeNodesInRoot_.clear(); // valid nodeid NodeId id = 1; - auto node = std::make_shared(id, mainThread->context_); + auto node = std::make_shared(id, mainThread->context_); ASSERT_NE(node, nullptr); node->SetIsOnTheTree(true, id, id); node->SetContentDirty(); mainThread->context_->AddActiveNode(node); ASSERT_EQ(static_cast(mainThread->context_->activeNodesInRoot_.size()), 1); - - ASSERT_EQ(mainThread->CheckIfInstanceOnlySurfaceBasicGeoTransform(id), false); + mainThread->CheckAndUpdateInstanceContentStaticStatus(node); + ASSERT_EQ(node->GetSurfaceCacheContentStatic(), false); } /** diff --git a/rosen/test/render_service/render_service/unittest/pipeline/rs_uni_render_visitor_test.cpp b/rosen/test/render_service/render_service/unittest/pipeline/rs_uni_render_visitor_test.cpp index 770a8daea..dd6e6b346 100644 --- a/rosen/test/render_service/render_service/unittest/pipeline/rs_uni_render_visitor_test.cpp +++ b/rosen/test/render_service/render_service/unittest/pipeline/rs_uni_render_visitor_test.cpp @@ -2555,13 +2555,13 @@ HWTEST_F(RSUniRenderVisitorTest, ProcessSharedTransitionNode003, TestSize.Level2 } /** - * @tc.name: UpdateStaticCacheSubTree001 - * @tc.desc: Test RSUniRenderVisitorTest.UpdateStaticCacheSubTree while + * @tc.name: UpdateSubTreeInCache001 + * @tc.desc: Test RSUniRenderVisitorTest.UpdateSubTreeInCache while * node doesn't have Child * @tc.type: FUNC * @tc.require: issueI7UGLR */ -HWTEST_F(RSUniRenderVisitorTest, UpdateStaticCacheSubTree001, TestSize.Level2) +HWTEST_F(RSUniRenderVisitorTest, UpdateSubTreeInCache001, TestSize.Level2) { NodeId id = 0; auto node = std::make_shared(id); @@ -2569,18 +2569,18 @@ HWTEST_F(RSUniRenderVisitorTest, UpdateStaticCacheSubTree001, TestSize.Level2) ASSERT_NE(node, nullptr); auto rsUniRenderVisitor = std::make_shared(); ASSERT_NE(rsUniRenderVisitor, nullptr); - rsUniRenderVisitor->UpdateStaticCacheSubTree(node, node->GetSortedChildren()); + rsUniRenderVisitor->UpdateSubTreeInCache(node, node->GetSortedChildren()); ASSERT_EQ(node->GetDrawingCacheChanged(), false); } /** - * @tc.name: UpdateStaticCacheSubTree002 - * @tc.desc: Test RSUniRenderVisitorTest.UpdateStaticCacheSubTree while + * @tc.name: UpdateSubTreeInCache002 + * @tc.desc: Test RSUniRenderVisitorTest.UpdateSubTreeInCache while * node has Child * @tc.type: FUNC * @tc.require: issueI7UGLR */ -HWTEST_F(RSUniRenderVisitorTest, UpdateStaticCacheSubTree002, TestSize.Level2) +HWTEST_F(RSUniRenderVisitorTest, UpdateSubTreeInCache002, TestSize.Level2) { NodeId id = 0; auto node = std::make_shared(id); @@ -2592,7 +2592,7 @@ HWTEST_F(RSUniRenderVisitorTest, UpdateStaticCacheSubTree002, TestSize.Level2) node->AddChild(child); auto rsUniRenderVisitor = std::make_shared(); ASSERT_NE(rsUniRenderVisitor, nullptr); - rsUniRenderVisitor->UpdateStaticCacheSubTree(node, node->GetSortedChildren()); + rsUniRenderVisitor->UpdateSubTreeInCache(node, node->GetSortedChildren()); ASSERT_EQ(node->GetDrawingCacheChanged(), false); } -- Gitee From bfd300983dcbd5414dca049207100b72e1d6479a Mon Sep 17 00:00:00 2001 From: yanghua Date: Sat, 6 Jan 2024 15:25:35 +0800 Subject: [PATCH 08/12] syncTransactionWaitDelay change to 1500 Signed-off-by: yanghua --- .../src/platform/ohos/rs_system_properties.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp index d866a2da5..7ce3e3965 100755 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp @@ -658,7 +658,7 @@ bool RSSystemProperties::GetSyncTransactionEnabled() int RSSystemProperties::GetSyncTransactionWaitDelay() { static int syncTransactionWaitDelay = - std::atoi((system::GetParameter("persist.sys.graphic.syncTransactionWaitDelay", "500")).c_str()); + std::atoi((system::GetParameter("persist.sys.graphic.syncTransactionWaitDelay", "1500")).c_str()); return syncTransactionWaitDelay; } -- Gitee From abd2613e970712970fea39ef3e6bc2cf326c5f8f Mon Sep 17 00:00:00 2001 From: zhangdunxu Date: Sat, 6 Jan 2024 19:54:49 +0800 Subject: [PATCH 09/12] add attach cancelbuffer test Change-Id: Ief26c97358fcf04982897f8ead2d06ea88f898d7 --- .../include/producer_surface_delegator.h | 2 ++ .../src/producer_surface_delegator.cpp | 10 ++++++ .../producer_surface_delegator_test.cpp | 31 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/frameworks/surface/include/producer_surface_delegator.h b/frameworks/surface/include/producer_surface_delegator.h index 456c6064f..f5986f310 100644 --- a/frameworks/surface/include/producer_surface_delegator.h +++ b/frameworks/surface/include/producer_surface_delegator.h @@ -33,6 +33,8 @@ public: GSError QueueBuffer(int32_t slot, int32_t acquireFence); GSError ReleaseBuffer(const sptr &buffer, const sptr &fence); GSError ClearBufferSlot(int32_t slot); + GSError CancelBuffer(int32_t slot, int32_t fenceFd); + GSError DetachBuffer(int32_t slot); int OnDequeueBuffer(MessageParcel &data, MessageParcel &reply); int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; diff --git a/frameworks/surface/src/producer_surface_delegator.cpp b/frameworks/surface/src/producer_surface_delegator.cpp index edf715927..93308d915 100644 --- a/frameworks/surface/src/producer_surface_delegator.cpp +++ b/frameworks/surface/src/producer_surface_delegator.cpp @@ -39,6 +39,16 @@ GSError ProducerSurfaceDelegator::ClearBufferSlot(int32_t slot) return GSERROR_OK; } +GSError ProducerSurfaceDelegator::CancelBuffer(int32_t slot, int32_t fenceFd) +{ + return GSERROR_OK; +} + +GSError ProducerSurfaceDelegator::DetachBuffer(int32_t slot) +{ + return GSERROR_OK; +} + int ProducerSurfaceDelegator::OnDequeueBuffer(MessageParcel &data, MessageParcel &reply) { return ERR_NONE; diff --git a/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp b/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp index 7fc9f68cf..227731289 100644 --- a/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp +++ b/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp @@ -223,6 +223,37 @@ HWTEST_F(ProducerSurfaceDelegatorTest, ReleaseBuffer002, Function | MediumTest | ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS); } +/* +* Function: DetachBuffer +* Type: Function +* Rank: Important(2) +* EnvConditions: N/A +* CaseDescription: 1. call DetachBuffer +* 2. check ret + */ +HWTEST_F(ProducerSurfaceDelegatorTest, DetachBuffer001, Function | MediumTest | Level2) +{ + int32_t slot = -1; + GSError ret = qwe->DetachBuffer(slot); + ASSERT_EQ(ret, GSERROR_OK); +} + +/* +* Function: CancelBuffer +* Type: Function +* Rank: Important(2) +* EnvConditions: N/A +* CaseDescription: 1. call CancelBuffer +* 2. check ret + */ +HWTEST_F(ProducerSurfaceDelegatorTest, CancelBuffer001, Function | MediumTest | Level2) +{ + int32_t slot = -1; + int32_t fenceFd = -1; + GSError ret = qwe->CancelBuffer(slot, fenceFd); + ASSERT_EQ(ret, GSERROR_OK); +} + /* * Function: OnRemoteRequest * Type: Function -- Gitee From 530db5cc70742a0eba5ef50b0b2ba6a810ce01bd Mon Sep 17 00:00:00 2001 From: katuya_chaos Date: Sat, 6 Jan 2024 12:02:22 +0000 Subject: [PATCH 10/12] Revert "add attach cancelbuffer test" This reverts commit abd2613e970712970fea39ef3e6bc2cf326c5f8f. --- .../include/producer_surface_delegator.h | 2 -- .../src/producer_surface_delegator.cpp | 10 ------ .../producer_surface_delegator_test.cpp | 31 ------------------- 3 files changed, 43 deletions(-) diff --git a/frameworks/surface/include/producer_surface_delegator.h b/frameworks/surface/include/producer_surface_delegator.h index f5986f310..456c6064f 100644 --- a/frameworks/surface/include/producer_surface_delegator.h +++ b/frameworks/surface/include/producer_surface_delegator.h @@ -33,8 +33,6 @@ public: GSError QueueBuffer(int32_t slot, int32_t acquireFence); GSError ReleaseBuffer(const sptr &buffer, const sptr &fence); GSError ClearBufferSlot(int32_t slot); - GSError CancelBuffer(int32_t slot, int32_t fenceFd); - GSError DetachBuffer(int32_t slot); int OnDequeueBuffer(MessageParcel &data, MessageParcel &reply); int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; diff --git a/frameworks/surface/src/producer_surface_delegator.cpp b/frameworks/surface/src/producer_surface_delegator.cpp index 93308d915..edf715927 100644 --- a/frameworks/surface/src/producer_surface_delegator.cpp +++ b/frameworks/surface/src/producer_surface_delegator.cpp @@ -39,16 +39,6 @@ GSError ProducerSurfaceDelegator::ClearBufferSlot(int32_t slot) return GSERROR_OK; } -GSError ProducerSurfaceDelegator::CancelBuffer(int32_t slot, int32_t fenceFd) -{ - return GSERROR_OK; -} - -GSError ProducerSurfaceDelegator::DetachBuffer(int32_t slot) -{ - return GSERROR_OK; -} - int ProducerSurfaceDelegator::OnDequeueBuffer(MessageParcel &data, MessageParcel &reply) { return ERR_NONE; diff --git a/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp b/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp index 227731289..7fc9f68cf 100644 --- a/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp +++ b/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp @@ -223,37 +223,6 @@ HWTEST_F(ProducerSurfaceDelegatorTest, ReleaseBuffer002, Function | MediumTest | ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS); } -/* -* Function: DetachBuffer -* Type: Function -* Rank: Important(2) -* EnvConditions: N/A -* CaseDescription: 1. call DetachBuffer -* 2. check ret - */ -HWTEST_F(ProducerSurfaceDelegatorTest, DetachBuffer001, Function | MediumTest | Level2) -{ - int32_t slot = -1; - GSError ret = qwe->DetachBuffer(slot); - ASSERT_EQ(ret, GSERROR_OK); -} - -/* -* Function: CancelBuffer -* Type: Function -* Rank: Important(2) -* EnvConditions: N/A -* CaseDescription: 1. call CancelBuffer -* 2. check ret - */ -HWTEST_F(ProducerSurfaceDelegatorTest, CancelBuffer001, Function | MediumTest | Level2) -{ - int32_t slot = -1; - int32_t fenceFd = -1; - GSError ret = qwe->CancelBuffer(slot, fenceFd); - ASSERT_EQ(ret, GSERROR_OK); -} - /* * Function: OnRemoteRequest * Type: Function -- Gitee From 95c5259c0b26037200f57d1215650e4c4ff47a0c Mon Sep 17 00:00:00 2001 From: zhangdunxu Date: Sat, 6 Jan 2024 20:07:14 +0800 Subject: [PATCH 11/12] add attach cancelbuffer test Change-Id: Ic8d4cc9210a8e2dda1b1823fc1402429f999fd8f --- .../include/producer_surface_delegator.h | 2 + .../src/producer_surface_delegator.cpp | 10 ++++ .../producer_surface_delegator_test.cpp | 46 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/frameworks/surface/include/producer_surface_delegator.h b/frameworks/surface/include/producer_surface_delegator.h index 456c6064f..f5986f310 100644 --- a/frameworks/surface/include/producer_surface_delegator.h +++ b/frameworks/surface/include/producer_surface_delegator.h @@ -33,6 +33,8 @@ public: GSError QueueBuffer(int32_t slot, int32_t acquireFence); GSError ReleaseBuffer(const sptr &buffer, const sptr &fence); GSError ClearBufferSlot(int32_t slot); + GSError CancelBuffer(int32_t slot, int32_t fenceFd); + GSError DetachBuffer(int32_t slot); int OnDequeueBuffer(MessageParcel &data, MessageParcel &reply); int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; diff --git a/frameworks/surface/src/producer_surface_delegator.cpp b/frameworks/surface/src/producer_surface_delegator.cpp index edf715927..93308d915 100644 --- a/frameworks/surface/src/producer_surface_delegator.cpp +++ b/frameworks/surface/src/producer_surface_delegator.cpp @@ -39,6 +39,16 @@ GSError ProducerSurfaceDelegator::ClearBufferSlot(int32_t slot) return GSERROR_OK; } +GSError ProducerSurfaceDelegator::CancelBuffer(int32_t slot, int32_t fenceFd) +{ + return GSERROR_OK; +} + +GSError ProducerSurfaceDelegator::DetachBuffer(int32_t slot) +{ + return GSERROR_OK; +} + int ProducerSurfaceDelegator::OnDequeueBuffer(MessageParcel &data, MessageParcel &reply) { return ERR_NONE; diff --git a/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp b/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp index 7fc9f68cf..164f88287 100644 --- a/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp +++ b/frameworks/surface/test/unittest/producer_surface_delegator_test.cpp @@ -223,6 +223,52 @@ HWTEST_F(ProducerSurfaceDelegatorTest, ReleaseBuffer002, Function | MediumTest | ASSERT_EQ(ret, GSERROR_INVALID_ARGUMENTS); } +/* +* Function: DetachBuffer +* Type: Function +* Rank: Important(2) +* EnvConditions: N/A +* CaseDescription: 1. call DetachBuffer +* 2. check ret + */ +HWTEST_F(ProducerSurfaceDelegatorTest, DetachBuffer001, Function | MediumTest | Level2) +{ + int32_t slot = -1; + GSError ret = qwe->DetachBuffer(slot); + ASSERT_EQ(ret, GSERROR_OK); +} + +/* +* Function: CancelBuffer +* Type: Function +* Rank: Important(2) +* EnvConditions: N/A +* CaseDescription: 1. call CancelBuffer +* 2. check ret + */ +HWTEST_F(ProducerSurfaceDelegatorTest, CancelBuffer001, Function | MediumTest | Level2) +{ + int32_t slot = -1; + int32_t fenceFd = -1; + GSError ret = qwe->CancelBuffer(slot, fenceFd); + ASSERT_EQ(ret, GSERROR_OK); +} + +/* +* Function: ClearBufferSlot +* Type: Function +* Rank: Important(2) +* EnvConditions: N/A +* CaseDescription: 1. call ClearBufferSlot +* 2. check ret + */ +HWTEST_F(ProducerSurfaceDelegatorTest, ClearBufferSlot001, Function | MediumTest | Level2) +{ + int32_t slot = -1; + GSError ret = qwe->ClearBufferSlot(slot); + ASSERT_EQ(ret, GSERROR_OK); +} + /* * Function: OnRemoteRequest * Type: Function -- Gitee From 036049e551ef36f91dbfe1c8b6ebddc11b46346a Mon Sep 17 00:00:00 2001 From: katuya_chaos Date: Sat, 6 Jan 2024 12:21:21 +0000 Subject: [PATCH 12/12] Revert "Merge branch 'master' of gitee.com:openharmony/graphic_graphic_2d into ouo" This reverts commit 824cbc4a3b3b2c4a802d8a85577cbcffc1a95f05. --- .../parallel_render/rs_filter_sub_thread.cpp | 107 +---- .../parallel_render/rs_filter_sub_thread.h | 10 +- .../parallel_render/rs_sub_thread_manager.cpp | 14 - .../parallel_render/rs_sub_thread_manager.h | 2 - .../core/pipeline/rs_main_thread.cpp | 31 +- .../core/pipeline/rs_main_thread.h | 2 +- .../rs_uni_render_virtual_processor.cpp | 189 +++++---- .../rs_uni_render_virtual_processor.h | 4 - .../core/pipeline/rs_uni_render_visitor.cpp | 75 ++-- .../core/pipeline/rs_uni_render_visitor.h | 7 +- .../core/system/rs_system_parameters.cpp | 2 +- .../core/system/rs_system_parameters.h | 1 - .../include/common/rs_common_def.h | 2 - .../include/pipeline/rs_surface_render_node.h | 12 +- .../property/rs_filter_cache_manager.h | 117 ++---- .../include/render/rs_filter.h | 6 - .../src/pipeline/rs_surface_render_node.cpp | 27 -- .../ohos/backend/native_buffer_utils.cpp | 2 - .../ohos/backend/native_buffer_utils.h | 3 +- .../ohos/backend/rs_surface_ohos_vulkan.cpp | 10 +- .../platform/ohos/rs_system_properties.cpp | 8 +- .../src/property/rs_filter_cache_manager.cpp | 377 +++++++----------- .../src/render/rs_blur_filter.cpp | 2 +- .../src/render/rs_filter.cpp | 2 - .../src/render/rs_image_cache.cpp | 10 +- .../src/render/rs_material_filter.cpp | 2 +- .../unittest/pipeline/rs_main_thread_test.cpp | 19 +- .../pipeline/rs_uni_render_visitor_test.cpp | 16 +- 28 files changed, 397 insertions(+), 662 deletions(-) diff --git a/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.cpp b/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.cpp index 6c0a19886..94166cba6 100644 --- a/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.cpp @@ -24,7 +24,6 @@ #include "memory/rs_tag_tracker.h" #include "rs_trace.h" -#include "common/rs_optional_trace.h" #include "pipeline/parallel_render/rs_sub_thread_manager.h" #include "pipeline/rs_main_thread.h" #include "pipeline/rs_surface_render_node.h" @@ -76,21 +75,7 @@ void RSFilterSubThread::Start() grContext_ = CreateShareGrContext(); }); RSFilter::postTask = [this](std::weak_ptr task) { - filterTaskList_.emplace_back(task); - RS_TRACE_NAME_FMT("postTask:%zu", filterTaskList_.size()); - }; - - RSFilter::clearGpuContext = [this]() { ResetGrContext(); }; - - RSFilter::setRelease = [this](std::weak_ptr task) { - PostTask([this, task]() { - auto workTask = task.lock(); - if (!workTask) { - RS_LOGE("Color picker task is null"); - return; - } - workTask->SetTaskRelease(); - }); + PostTask([this, task]() { RenderCache(task); }); }; } @@ -190,92 +175,28 @@ void RSFilterSubThread::DestroyShareEglContext() #endif } -void RSFilterSubThread::RenderCache(std::vector>& filterTaskList) +void RSFilterSubThread::RenderCache(std::weak_ptr filterTask) { - RS_TRACE_NAME_FMT("RSFilterSubThread::RenderCache:%zu", filterTaskList.size()); - if (grContext_ == nullptr) { - grContext_ = CreateShareGrContext(); - } - if (fence_->Wait(SYNC_TIME_OUT) < 0) { - RS_LOGE("RSFilterSubThread::RenderCache: fence time out"); - filterTaskList.clear(); - isWorking_.store(false); + RS_TRACE_NAME("RenderCache"); + auto task = filterTask.lock(); + if (!task) { + RS_LOGE("task is null"); return; } if (grContext_ == nullptr) { - RS_LOGE("RSFilterSubThread::RenderCache: grContext is null"); - filterTaskList.clear(); - isWorking_.store(false); - return; - } - for (auto& task : filterTaskList) { - auto workTask = task.lock(); - if (!workTask) { - RS_LOGE("RSFilterSubThread::RenderCache: Render task is null"); - continue; - } - if (!workTask->InitSurface(grContext_.get())) { - RS_LOGE("RSFilterSubThread::RenderCache: InitSurface failed"); - continue; - } - if (!workTask->Render()) { - RS_LOGE("RSFilterSubThread::RenderCache: Render failed"); - continue; - } - } -#ifndef USE_ROSEN_DRAWING - grContext_->flushAndSubmit(true); -#else - grContext_->FlushAndSubmit(true); -#endif - for (auto& task : filterTaskList) { - auto workTask = task.lock(); - if (!workTask) { - RS_LOGE("RSFilterSubThread::RenderCache, SaveFilteredImage task is null"); - continue; - } - if (!workTask->SaveFilteredImage()) { - RS_LOGE("RSFilterSubThread::RenderCache, SaveFilteredImage failed"); - continue; - } - if (!workTask->SetDone()) { - RS_LOGE("RSFilterSubThread::RenderCache, SetDone failed"); - continue; - } + grContext_ = CreateShareGrContext(); } - filterTaskList.clear(); - isWorking_.store(false); -} - -void RSFilterSubThread::FlushAndSubmit() -{ - RS_TRACE_NAME_FMT("RSFilterSubThread::FlushAndSubmit():isWorking_:%d TaskList size:%zu", - isWorking_.load(), filterReadyTaskList_.size()); - - if (filterTaskList_.empty()) { + if (grContext_ == nullptr) { + RS_LOGE("grContext is null"); return; } - - if (isWorking_.load()) { + if (!task->InitSurface(grContext_.get())) { + RS_LOGE("InitSurface failed"); return; } - - filterTaskList_.swap(filterReadyTaskList_); - for (auto& task : filterReadyTaskList_) { - auto initTask = task.lock(); - if (!initTask) { - RS_LOGE("RSFilterSubThread::FlushAndSubmit:SwapInit task is null"); - continue; - } - initTask->SwapInit(); + if (!task->Render()) { + RS_LOGE("Render failed"); } - isWorking_.store(true); - PostTask([this]() { RenderCache(filterReadyTaskList_); }); -} - -void RSFilterSubThread::SetFence(sptr fence) -{ - fence_ = fence; } void RSFilterSubThread::ColorPickerRenderCache(std::weak_ptr colorPickerTask) @@ -405,10 +326,8 @@ void RSFilterSubThread::ResetGrContext() return; } #ifndef USE_ROSEN_DRAWING - grContext_->flushAndSubmit(true); grContext_->freeGpuResources(); #else - grContext_->FlushAndSubmit(true); grContext_->FreeGpuResources(); #endif } diff --git a/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.h b/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.h index fce9594be..e8c571a2f 100644 --- a/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.h +++ b/rosen/modules/render_service/core/pipeline/parallel_render/rs_filter_sub_thread.h @@ -42,9 +42,7 @@ public: void StartColorPicker(); void PostTask(const std::function& task); void PostSyncTask(const std::function& task); - void RenderCache(std::vector>& filterTaskList); - void FlushAndSubmit(); - void SetFence(sptr fence); + void RenderCache(std::weak_ptr filterTask); void ColorPickerRenderCache(std::weak_ptr colorPickerTask); void ResetGrContext(); @@ -52,7 +50,6 @@ public: float GetAppGpuMemoryInMB(); private: - const uint32_t SYNC_TIME_OUT = 1000; void CreateShareEglContext(); void DestroyShareEglContext(); #ifndef USE_ROSEN_DRAWING @@ -64,10 +61,7 @@ private: #else std::shared_ptr CreateShareGrContext(); #endif - std::atomic isWorking_ = false; - sptr fence_ = nullptr; - std::vector> filterTaskList_; - std::vector> filterReadyTaskList_; + uint32_t threadIndex_ = 0; std::shared_ptr runner_ = nullptr; std::shared_ptr handler_ = nullptr; diff --git a/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.cpp b/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.cpp index 8d6c6e5f3..618e6f79f 100644 --- a/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.cpp +++ b/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.cpp @@ -171,20 +171,6 @@ float RSSubThreadManager::GetAppGpuMemoryInMB() return total; } -void RSSubThreadManager::SubmitFilterSubThreadTask() -{ - if (filterThread) { - filterThread->FlushAndSubmit(); - } -} - -void RSSubThreadManager::SetFenceSubThread(sptr fence) -{ - if (filterThread) { - filterThread->SetFence(fence); - } -} - void RSSubThreadManager::SubmitSubThreadTask(const std::shared_ptr& node, const std::list>& subThreadNodes) { diff --git a/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.h b/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.h index b27e464bb..682d49391 100644 --- a/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.h +++ b/rosen/modules/render_service/core/pipeline/parallel_render/rs_sub_thread_manager.h @@ -42,8 +42,6 @@ public: void PostTask(const std::function& task, uint32_t threadIndex, bool isSyncTask = false); void WaitNodeTask(uint64_t nodeId); void NodeTaskNotify(uint64_t nodeId); - void SubmitFilterSubThreadTask(); - void SetFenceSubThread(sptr fence); void SubmitSubThreadTask(const std::shared_ptr& node, const std::list>& subThreadNodes); void ResetSubThreadGrContext(); diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp index 587bd2aea..6b34d7296 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp @@ -273,8 +273,6 @@ void RSMainThread::Init() Render(); InformHgmNodeInfo(); ReleaseAllNodesBuffer(); - auto subThreadManager = RSSubThreadManager::Instance(); - subThreadManager->SubmitFilterSubThreadTask(); SendCommands(); context_->activeNodesInRoot_.clear(); ROSEN_TRACE_END(HITRACE_TAG_GRAPHIC_AGP); @@ -2679,9 +2677,7 @@ bool RSMainThread::SetSystemAnimatedScenes(SystemAnimatedScenes systemAnimatedSc --systemAnimatedScenesCnt_; } else { if (systemAnimatedScenes == SystemAnimatedScenes::ENTER_TFS_WINDOW || - systemAnimatedScenes == SystemAnimatedScenes::EXIT_TFU_WINDOW || - systemAnimatedScenes == SystemAnimatedScenes::ENTER_WIND_CLEAR || - systemAnimatedScenes == SystemAnimatedScenes::ENTER_WIND_RECOVER) { + systemAnimatedScenes == SystemAnimatedScenes::EXIT_TFU_WINDOW) { ++threeFingerCnt_; } if (systemAnimatedScenes != SystemAnimatedScenes::APPEAR_MISSION_CENTER) { @@ -2734,18 +2730,27 @@ bool RSMainThread::IsDrawingGroupChanged(RSRenderNode& cacheRootNode) const return false; } -void RSMainThread::CheckAndUpdateInstanceContentStaticStatus(std::shared_ptr instanceNode) const +bool RSMainThread::CheckIfInstanceOnlySurfaceBasicGeoTransform(NodeId instanceNodeId) const { - if (instanceNode == nullptr) { - RS_LOGE("CheckAndUpdateInstanceContentStaticStatus instanceNode invalid."); - return ; + if (instanceNodeId == INVALID_NODEID) { + RS_LOGE("CheckIfInstanceOnlySurfaceBasicGeoTransform instanceNodeId invalid."); + return false; } - auto iter = context_->activeNodesInRoot_.find(instanceNode->GetId()); + auto iter = context_->activeNodesInRoot_.find(instanceNodeId); if (iter != context_->activeNodesInRoot_.end()) { - instanceNode->UpdateSurfaceCacheContentStatic(iter->second); - } else { - instanceNode->UpdateSurfaceCacheContentStatic({}); + const auto& activeNodeIds = iter->second; + for (auto [id, subNode] : activeNodeIds) { + auto node = subNode.lock(); + if (node == nullptr) { + continue; + } + // filter active nodes except instance surface itself + if (id != instanceNodeId || !node->IsOnlyBasicGeoTransform()) { + return false; + } + } } + return true; } FrameRateRange RSMainThread::CalcAnimateFrameRateRange(std::shared_ptr node) diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.h b/rosen/modules/render_service/core/pipeline/rs_main_thread.h index f379fd241..810fe798c 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.h +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.h @@ -137,7 +137,7 @@ public: bool IsDrawingGroupChanged(RSRenderNode& cacheRootNode) const; // check if active instance only move or scale it's main window surface without rearrangement // instanceNodeId should be MainWindowType, or it cannot grep correct app's info - void CheckAndUpdateInstanceContentStaticStatus(std::shared_ptr instanceNode) const; + bool CheckIfInstanceOnlySurfaceBasicGeoTransform(NodeId instanceNodeId) const; void RegisterApplicationAgent(uint32_t pid, sptr app); void UnRegisterApplicationAgent(sptr app); diff --git a/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.cpp b/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.cpp index 92fb74de9..fe1f6b51e 100644 --- a/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.cpp @@ -137,77 +137,6 @@ void RSUniRenderVirtualProcessor::CanvasRotation(ScreenRotation screenRotation, #endif } -void RSUniRenderVirtualProcessor::RotateMirrorCanvasIfNeed(RSDisplayRenderNode& node) -{ - auto rotation = node.GetScreenRotation(); - if (RSSystemProperties::IsFoldScreenFlag() && node.GetScreenId() == 0) { - if (rotation == ScreenRotation::ROTATION_270) { - rotation = ScreenRotation::ROTATION_0; - } else { - rotation = static_cast(static_cast(rotation) + 1); - } - } -#ifndef USE_ROSEN_DRAWING - if (rotation != ScreenRotation::ROTATION_0) { - auto screenManager = CreateOrGetScreenManager(); - auto mainScreenInfo = screenManager->QueryScreenInfo(node.GetScreenId()); - if (rotation == ScreenRotation::ROTATION_90) { - canvas_->rotate(90); // 90 degrees - canvas_->translate(0, -(static_cast(mainScreenInfo.height))); - } else if (rotation == ScreenRotation::ROTATION_180) { - canvas_->rotate(180, static_cast(mainScreenInfo.width) / 2, // 180 degrees, 2 is centre - static_cast(mainScreenInfo.height) / 2); // 2 is centre - } else if (rotation == ScreenRotation::ROTATION_270) { - canvas_->rotate(270); // 270 degrees - canvas_->translate(-(static_cast(mainScreenInfo.width)), 0); - } - } -#else - if (rotation != ScreenRotation::ROTATION_0) { - auto screenManager = CreateOrGetScreenManager(); - auto mainScreenInfo = screenManager->QueryScreenInfo(node.GetScreenId()); - if (rotation == ScreenRotation::ROTATION_90) { - canvas_->Rotate(90, 0, 0); // 90 degrees - canvas_->Translate(0, -(static_cast(mainScreenInfo.height))); - } else if (rotation == ScreenRotation::ROTATION_180) { - canvas_->Rotate(180, static_cast(mainScreenInfo.width) / 2, // 180 degrees, 2 is centre - static_cast(mainScreenInfo.height) / 2); // 2 is centre - } else if (rotation == ScreenRotation::ROTATION_270) { - canvas_->Rotate(270, 0, 0); // 270 degrees - canvas_->Translate(-(static_cast(mainScreenInfo.width)), 0); - } - } -#endif -} - -void RSUniRenderVirtualProcessor::ScaleMirrorIfNeed(RSDisplayRenderNode& node) -{ - if (mainWidth_ != mirrorWidth_ || mainHeight_ != mirrorHeight_) { -#ifndef USE_ROSEN_DRAWING - canvas_->clear(SK_ColorBLACK); -#else - canvas_->Clear(SK_ColorBLACK); -#endif - float mirrorScale = 1.0f; // 1 for init scale - float startX = 0.0f; - float startY = 0.0f; - if ((mirrorHeight_ / mirrorWidth_) < (mainHeight_ / mainWidth_)) { - mirrorScale = mirrorHeight_ / mainHeight_; - startX = (mirrorWidth_ - (mirrorScale * mainWidth_)) / 2; // 2 for calc X - } else if ((mirrorHeight_ / mirrorWidth_) > (mainHeight_ / mainWidth_)) { - mirrorScale = mirrorWidth_ / mainWidth_; - startY = (mirrorHeight_ - (mirrorScale * mainHeight_)) / 2; // 2 for calc Y - } -#ifndef USE_ROSEN_DRAWING - canvas_->translate(startX, startY); - canvas_->scale(mirrorScale, mirrorScale); -#else - canvas_->Translate(startX, startY); - canvas_->Scale(mirrorScale, mirrorScale); -#endif - } -} - void RSUniRenderVirtualProcessor::PostProcess(RSDisplayRenderNode* node) { if (producerSurface_ == nullptr) { @@ -265,20 +194,116 @@ void RSUniRenderVirtualProcessor::ProcessDisplaySurface(RSDisplayRenderNode& nod auto params = RSUniRenderUtil::CreateBufferDrawParam(node, forceCPU_); auto screenManager = CreateOrGetScreenManager(); auto mainScreenInfo = screenManager->QueryScreenInfo(node.GetScreenId()); - mainWidth_ = static_cast(mainScreenInfo.width); - mainHeight_ = static_cast(mainScreenInfo.height); - if ((RSSystemProperties::IsFoldScreenFlag() && node.GetScreenId() == 0)) { - std::swap(mainWidth_, mainHeight_); - } - if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || - mainScreenRotation_ == ScreenRotation::ROTATION_270) { - std::swap(mainWidth_, mainHeight_); + float mainWidth = static_cast(mainScreenInfo.width); + float mainHeight = static_cast(mainScreenInfo.height); + auto screenCorrection = screenManager->GetScreenCorrection(node.GetScreenId()); + if ((RSSystemProperties::IsFoldScreenFlag() && node.GetScreenId() == 0) || canvasRotation_) { + std::swap(mainWidth, mainHeight); + if (screenCorrection == ScreenRotation::ROTATION_270) { +#ifndef USE_ROSEN_DRAWING + canvas_->rotate(-270, mirrorWidth_ / 2.0f, mirrorHeight_ / 2.0f); +#else + canvas_->Rotate(-270, mirrorWidth_ / 2.0f, mirrorHeight_ / 2.0f); +#endif + } + if (mainScreenRotation_ == ScreenRotation::ROTATION_180) { + std::swap(mainWidth, mainHeight); + } + if (canvasRotation_) { + CanvasRotation(mainScreenRotation_, mirrorWidth_, mirrorHeight_); + } } - ScaleMirrorIfNeed(node); - if ((RSSystemProperties::IsFoldScreenFlag() && node.GetScreenId() == 0) || canvasRotation_) { - RotateMirrorCanvasIfNeed(node); + // If the width and height not match the main screen, calculate the dstRect. + if (mainWidth != mirrorWidth_ || mainHeight != mirrorHeight_) { +#ifndef USE_ROSEN_DRAWING + SkRect mirrorDstRect; + if ((mirrorHeight_ / mirrorWidth_) < (mainHeight / mainWidth)) { + float mirrorScale = mirrorHeight_ / mainHeight; + float mainScale = mainHeight / mainWidth; + if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || + mainScreenRotation_ == ScreenRotation::ROTATION_270) { + if (screenCorrection == ScreenRotation::ROTATION_270) { + mirrorDstRect = SkRect::MakeXYWH(-(mirrorHeight_ / 2.0f), + -(mirrorScale * mainWidth * mainScale) / 2.0f, + mirrorHeight_, mirrorScale * mainWidth * mainScale); + } else { + mirrorDstRect = SkRect::MakeXYWH(-(mirrorHeight_ / 2.0f), + -(mirrorScale * mainWidth) / 2.0f, + mirrorHeight_, mirrorScale * mainWidth); + } + } else { + if (screenCorrection == ScreenRotation::ROTATION_270) { + mirrorDstRect = SkRect::MakeXYWH((mirrorWidth_ - (mirrorScale * mainScale * mainWidth)) / 2.0f, + 0, mirrorScale * mainScale * mainWidth, mirrorHeight_); + } else { + mirrorDstRect = SkRect::MakeXYWH((mirrorWidth_ - (mirrorScale * mainWidth)) / 2.0f, 0, + mirrorScale * mainWidth, mirrorHeight_); + } + } + } else if ((mirrorHeight_ / mirrorWidth_) > (mainHeight / mainWidth)) { + float mirrorScale = mirrorWidth_ / mainWidth; + if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || + mainScreenRotation_ == ScreenRotation::ROTATION_270) { + mirrorDstRect = SkRect::MakeXYWH((mirrorHeight_ / 2.0f) - + ((mirrorScale * mainHeight) / 2.0f), -(mirrorWidth_ / 2.0f), + mirrorScale * mainHeight, mirrorWidth_); + } else { + mirrorDstRect = SkRect::MakeXYWH(0, + (mirrorHeight_ - (mirrorScale * mainHeight)) / 2.0f, + mirrorWidth_, mirrorScale * mainHeight); + } + } + params.dstRect = mirrorDstRect; +#else + Drawing::Rect mirrorDstRect; + if ((mirrorHeight_ / mirrorWidth_) < (mainHeight / mainWidth)) { + float mirrorScale = mirrorHeight_ / mainHeight; + float mainScale = mainHeight / mainWidth; + if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || + mainScreenRotation_ == ScreenRotation::ROTATION_270) { + if (screenCorrection == ScreenRotation::ROTATION_270) { + mirrorDstRect = Drawing::Rect(-(mirrorHeight_ / 2.0f), + -(mirrorScale * mainWidth * mainScale) / 2.0f, mirrorHeight_ / 2.0f, + (mirrorScale * mainWidth * mainScale) / 2.0f); + } else { + mirrorDstRect = Drawing::Rect(-(mirrorHeight_ / 2.0f), -(mirrorScale * mainWidth) / 2.0f, + mirrorHeight_ / 2.0f, (mirrorScale * mainWidth) / 2.0f); + } + } else { + if (screenCorrection == ScreenRotation::ROTATION_270) { + mirrorDstRect = Drawing::Rect((mirrorWidth_ - (mirrorScale * mainScale * mainWidth)) / 2.0f, 0, + (mirrorWidth_ + (mirrorScale * mainScale * mainWidth)) / 2.0f, mirrorHeight_); + } else { + mirrorDstRect = Drawing::Rect((mirrorWidth_ - (mirrorScale * mainWidth)) / 2.0f, 0, + (mirrorWidth_ + (mirrorScale * mainWidth)) / 2.0f, mirrorHeight_); + } + } + } else if ((mirrorHeight_ / mirrorWidth_) > (mainHeight / mainWidth)) { + float mirrorScale = mirrorWidth_ / mainWidth; + if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || + mainScreenRotation_ == ScreenRotation::ROTATION_270) { + mirrorDstRect = Drawing::Rect((mirrorHeight_ / 2.0f) - ((mirrorScale * mainHeight) / 2.0f), + -(mirrorWidth_ / 2.0f), (mirrorHeight_ / 2.0f) + ((mirrorScale * mainHeight) / 2.0f), + (mirrorWidth_ / 2.0f)); + } else { + mirrorDstRect = Drawing::Rect(0, (mirrorHeight_ - (mirrorScale * mainHeight)) / 2.0f, + mirrorWidth_, (mirrorHeight_ + (mirrorScale * mainHeight)) / 2.0); + } + } + params.dstRect = mirrorDstRect; +#endif + } else { + if (mainScreenRotation_ == ScreenRotation::ROTATION_90 || + mainScreenRotation_ == ScreenRotation::ROTATION_270) { +#ifndef USE_ROSEN_DRAWING + canvas_->translate(-(mirrorHeight_ / 2.0f), -(mirrorWidth_ / 2.0f)); +#else + canvas_->Translate(-(mirrorHeight_ / 2.0f), -(mirrorWidth_ / 2.0f)); +#endif + } } + renderEngine_->DrawDisplayNodeWithParams(*canvas_, node, params); #ifndef USE_ROSEN_DRAWING canvas_->restore(); diff --git a/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.h b/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.h index 60baa7a0f..996fb5f18 100644 --- a/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.h +++ b/rosen/modules/render_service/core/pipeline/rs_uni_render_virtual_processor.h @@ -39,8 +39,6 @@ public: } private: void CanvasRotation(ScreenRotation screenRotation, float width, float height); - void ScaleMirrorIfNeed(RSDisplayRenderNode& node); - void RotateMirrorCanvasIfNeed(RSDisplayRenderNode& node); sptr producerSurface_; std::unique_ptr renderFrame_; std::unique_ptr canvas_; @@ -49,8 +47,6 @@ private: bool isPhone_ = false; float mirrorWidth_ = 0.f; float mirrorHeight_ = 0.f; - float mainWidth_ = 0.f; - float mainHeight_ = 0.f; bool canvasRotation_ = false; ScreenRotation mainScreenRotation_ = ScreenRotation::ROTATION_0; }; diff --git a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp index dd50f82eb..c390a4fb0 100644 --- a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.cpp @@ -296,17 +296,15 @@ void RSUniRenderVisitor::CopyPropertyForParallelVisitor(RSUniRenderVisitor *main isSubThread_ = true; } -void RSUniRenderVisitor::UpdateSubTreeInCache(const std::shared_ptr& cacheRootNode, +void RSUniRenderVisitor::UpdateStaticCacheSubTree(const std::shared_ptr& cacheRootNode, const std::list& children) { for (auto& child : children) { if (child == nullptr) { continue; } - if (child->IsDirty()) { - curDirty_ = child->IsDirty(); - child->Prepare(shared_from_this()); - continue; + if (child->GetDrawingCacheType() != RSDrawingCacheType::DISABLED_CACHE) { + child->SetDrawingCacheChanged(false); } // set flag for surface node whose children contain shared transition node if (child->GetSharedTransitionParam().has_value() && curSurfaceNode_) { @@ -314,7 +312,7 @@ void RSUniRenderVisitor::UpdateSubTreeInCache(const std::shared_ptrReinterpretCastTo()) { - // fully prepare hwcLayer Layer and its subnodes + // fully prepare hwcLayer and its subnodes if (surfaceNode->IsHardwareEnabledType()) { PrepareSurfaceRenderNode(*surfaceNode); return; @@ -339,7 +337,7 @@ void RSUniRenderVisitor::UpdateSubTreeInCache(const std::shared_ptrIsBackgroundFilterCacheValid()); } } - UpdateSubTreeInCache(child, child->GetSortedChildren()); + UpdateStaticCacheSubTree(child, child->GetSortedChildren()); } } @@ -352,7 +350,7 @@ void RSUniRenderVisitor::PrepareEffectNodeIfCacheReuse(const std::shared_ptrInitializeEffectRegion(); effectNode->Update(*curSurfaceDirtyManager_, cacheRootNode, dirtyFlag_, prepareClipRect_); - UpdateSubTreeInCache(effectNode, effectNode->GetSortedChildren()); + UpdateStaticCacheSubTree(effectNode, effectNode->GetSortedChildren()); effectNode->SetEffectRegion(effectRegion_); if (effectNode->GetRenderProperties().NeedFilter()) { UpdateForegroundFilterCacheWithDirty(*effectNode, *curSurfaceDirtyManager_); @@ -395,10 +393,10 @@ void RSUniRenderVisitor::PrepareChildren(RSRenderNode& node) if (curSurfaceDirtyManager_ != nullptr && isCachedSurfaceReuse_ && !node.HasMustRenewedInfo()) { RS_OPTIONAL_TRACE_NAME_FMT("CachedSurfaceReuse node %llu quickSkip subtree", node.GetId()); } else if (curSurfaceDirtyManager_ != nullptr && curDisplayNode_ != nullptr && - (isCachedSurfaceReuse_ || isSurfaceDirtyNodeLimited_ || !UpdateCacheChangeStatus(node))) { - RS_OPTIONAL_TRACE_NAME_FMT("UpdateCacheChangeStatus node %llu simply update subtree, isCachedSurfaceReuse_ %d," - " isSurfaceDirtyNodeLimited_ %d", node.GetId(), isCachedSurfaceReuse_, isSurfaceDirtyNodeLimited_); - UpdateSubTreeInCache(node.ReinterpretCastTo(), children); + (isCachedSurfaceReuse_ || !UpdateCacheChangeStatus(node))) { + RS_OPTIONAL_TRACE_NAME_FMT("UpdateCacheChangeStatus node %llu simply update subtree, isCachedSurfaceReuse_ %d", + node.GetId(), isCachedSurfaceReuse_); + UpdateStaticCacheSubTree(node.ReinterpretCastTo(), children); } else { // Get delay flag to restore geo changes if (node.GetCacheGeoPreparationDelay()) { @@ -892,7 +890,7 @@ bool RSUniRenderVisitor::CheckIfSurfaceRenderNodeStatic(RSSurfaceRenderNode& nod if (result) { return false; } - node.UpdateSurfaceCacheContentStatic({}); + node.SetSurfaceCacheContentStatic(true); RS_OPTIONAL_TRACE_NAME("Skip static surface " + node.GetName() + " nodeid - pid: " + std::to_string(node.GetId()) + " - " + std::to_string(ExtractPid(node.GetId()))); // static node's dirty region is empty @@ -1042,10 +1040,11 @@ void RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeBeforeUpdate(RSSurfaceRe node.ResetFilterNodes(); effectNodeNum_ = 0; node.SetUseEffectNodes(0); + node.SetSurfaceCacheContentStatic( + RSMainThread::Instance()->CheckIfInstanceOnlySurfaceBasicGeoTransform(node.GetId())); // [planning] check if it is not reset recursively firstVisitedCache_ = INVALID_NODEID; curSurfaceNode_ = node.ReinterpretCastTo(); - RSMainThread::Instance()->CheckAndUpdateInstanceContentStaticStatus(curSurfaceNode_); curSurfaceDirtyManager_ = node.GetDirtyManager(); if (curSurfaceDirtyManager_ == nullptr) { RS_LOGE("RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeBeforeUpdate %{public}s has no" @@ -1060,32 +1059,24 @@ void RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeBeforeUpdate(RSSurfaceRe if (isTargetDirtyRegionDfxEnabled_ && CheckIfSurfaceTargetedForDFX(node.GetName())) { curSurfaceDirtyManager_->MarkAsTargetForDfx(); } - ClassifyUIFirstSurfaceDirtyStatus(node); - } - - // collect app window node's child hardware enabled node - if (node.IsHardwareEnabledType() && curSurfaceNode_) { - curSurfaceNode_->AddChildHardwareEnabledNode(node.ReinterpretCastTo()); - node.SetLocalZOrder(localZOrder_++); } -} - -void RSUniRenderVisitor::ClassifyUIFirstSurfaceDirtyStatus(RSSurfaceRenderNode& node) -{ if (node.IsMainWindowType()) { - isCachedSurfaceReuse_ = (quickSkipPrepareType_ >= QuickSkipPrepareType::STATIC_CACHE_SURFACE) && + isCachedSurfaceReuse_ = (quickSkipPrepareType_ == QuickSkipPrepareType::STATIC_CACHE_SURFACE) && (RSMainThread::Instance()->GetDeviceType() == DeviceType::PC) && - CheckIfUIFirstSurfaceContentReusable(curSurfaceNode_, isSurfaceDirtyNodeLimited_); - isSurfaceDirtyNodeLimited_ = (quickSkipPrepareType_ == QuickSkipPrepareType::CONTENT_DIRTY_CACHE_SURFACE) && - isSurfaceDirtyNodeLimited_ && node.IsOnlyBasicGeoTransform() && node.IsContentDirtyNodeLimited(); + CheckIfUIFirstSurfaceContentReusable(curSurfaceNode_); if (isCachedSurfaceReuse_) { node.SetCacheGeoPreparationDelay(dirtyFlag_); } } + + // collect app window node's child hardware enabled node + if (node.IsHardwareEnabledType() && curSurfaceNode_) { + curSurfaceNode_->AddChildHardwareEnabledNode(node.ReinterpretCastTo()); + node.SetLocalZOrder(localZOrder_++); + } } -bool RSUniRenderVisitor::CheckIfUIFirstSurfaceContentReusable(std::shared_ptr& node, - bool& isAssigned) +bool RSUniRenderVisitor::CheckIfUIFirstSurfaceContentReusable(std::shared_ptr& node) { if (!isUIFirst_ || node == nullptr) { return false; @@ -1095,18 +1086,17 @@ bool RSUniRenderVisitor::CheckIfUIFirstSurfaceContentReusable(std::shared_ptrGetInstanceRootNode()) { auto surfaceParent = parentInstance->ReinterpretCastTo(); if (surfaceParent && surfaceParent->IsLeashWindow()) { - isAssigned = - RSUniRenderUtil::IsNodeAssignSubThread(surfaceParent, curDisplayNode_->IsRotationChanged()); - RS_OPTIONAL_TRACE_NAME_FMT("%s CheckIfUIFirstSurfaceContentReusable(leash): %d, isAssigned %d", - surfaceParent->GetName().c_str(), surfaceParent->IsUIFirstCacheReusable(deviceType), isAssigned); - return isAssigned && surfaceParent->IsUIFirstCacheReusable(deviceType); + RS_OPTIONAL_TRACE_NAME(surfaceParent->GetName() + " CheckIfUIFirstSurfaceContentReusable(leash): " + + std::to_string(surfaceParent->IsUIFirstCacheReusable(deviceType))); + return RSUniRenderUtil::IsNodeAssignSubThread(surfaceParent, curDisplayNode_->IsRotationChanged()) && + surfaceParent->IsUIFirstCacheReusable(deviceType); } } } - isAssigned = RSUniRenderUtil::IsNodeAssignSubThread(node, curDisplayNode_->IsRotationChanged()); - RS_OPTIONAL_TRACE_NAME_FMT("%s CheckIfUIFirstSurfaceContentReusable(mainwindow): %d, isAssigned %d", - node->GetName().c_str(), node->IsUIFirstCacheReusable(deviceType), isAssigned); - return isAssigned && node->IsUIFirstCacheReusable(deviceType); + RS_OPTIONAL_TRACE_NAME(node->GetName() + " CheckIfUIFirstSurfaceContentReusable(mainwindow): " + + std::to_string(node->IsUIFirstCacheReusable(deviceType))); + return RSUniRenderUtil::IsNodeAssignSubThread(node, curDisplayNode_->IsRotationChanged()) && + node->IsUIFirstCacheReusable(deviceType); } void RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeAfterUpdate(RSSurfaceRenderNode& node) @@ -1126,7 +1116,6 @@ void RSUniRenderVisitor::PrepareTypesOfSurfaceRenderNodeAfterUpdate(RSSurfaceRen } if (node.IsMainWindowType()) { isCachedSurfaceReuse_ = false; - isSurfaceDirtyNodeLimited_ = false; node.SetUseEffectNodes(effectNodeNum_); bool hasFilter = node.IsTransparent() && properties.NeedFilter(); bool hasHardwareNode = !node.GetChildHardwareEnabledNodes().empty(); @@ -3084,10 +3073,6 @@ void RSUniRenderVisitor::ProcessDisplayRenderNode(RSDisplayRenderNode& node) AssignGlobalZOrderAndCreateLayer(appWindowNodesInZOrder_); node.SetGlobalZOrder(globalZOrder_++); processor_->ProcessDisplaySurface(node); - auto& surfaceHandler = static_cast(node); - auto& fence = surfaceHandler.GetAcquireFence(); - auto subThreadManager = RSSubThreadManager::Instance(); - subThreadManager->SetFenceSubThread(fence); AssignGlobalZOrderAndCreateLayer(hardwareEnabledTopNodes_); } diff --git a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.h b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.h index e32c5c903..bd91d9b12 100644 --- a/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.h +++ b/rosen/modules/render_service/core/pipeline/rs_uni_render_visitor.h @@ -277,9 +277,7 @@ private: * mainwindow check if it has leashwindow parent * If so, check parent or check itself */ - bool CheckIfUIFirstSurfaceContentReusable(std::shared_ptr& node, bool& isAssigned); - // currently classify surface assigned subthread specific dirty case for preparation - void ClassifyUIFirstSurfaceDirtyStatus(RSSurfaceRenderNode& node); + bool CheckIfUIFirstSurfaceContentReusable(std::shared_ptr& node); void PrepareTypesOfSurfaceRenderNodeBeforeUpdate(RSSurfaceRenderNode& node); void PrepareTypesOfSurfaceRenderNodeAfterUpdate(RSSurfaceRenderNode& node); @@ -289,7 +287,7 @@ private: bool IsDrawingCacheStatic(RSRenderNode& node); // if cache root reuses, update its subtree // [attention] check curSurfaceDirtyManager_ before function calls - void UpdateSubTreeInCache(const std::shared_ptr& cacheRootNode, + void UpdateStaticCacheSubTree(const std::shared_ptr& cacheRootNode, const std::list& children); // set node cacheable animation after checking whold child tree void SetNodeCacheChangeStatus(RSRenderNode& node); @@ -432,7 +430,6 @@ private: // currently available to uiFirst bool isCachedSurfaceReuse_ = false; uint32_t effectNodeNum_ = 0; - bool isSurfaceDirtyNodeLimited_ = false; bool isDirtyRegionAlignedEnable_ = false; std::shared_ptr surfaceNodePrepareMutex_; diff --git a/rosen/modules/render_service/core/system/rs_system_parameters.cpp b/rosen/modules/render_service/core/system/rs_system_parameters.cpp index 272f988da..7714e6441 100644 --- a/rosen/modules/render_service/core/system/rs_system_parameters.cpp +++ b/rosen/modules/render_service/core/system/rs_system_parameters.cpp @@ -62,7 +62,7 @@ bool RSSystemParameters::GetShowRefreshRateEnabled() QuickSkipPrepareType RSSystemParameters::GetQuickSkipPrepareType() { - static CachedHandle g_Handle = CachedParameterCreate("rosen.quickskipprepare.enabled", "5"); + static CachedHandle g_Handle = CachedParameterCreate("rosen.quickskipprepare.enabled", "4"); int changed = 0; const char *type = CachedParameterGetChanged(g_Handle, &changed); return static_cast(ConvertToInt(type, DEFAULT_QUICK_SKIP_PREPARE_TYPE_VALUE)); diff --git a/rosen/modules/render_service/core/system/rs_system_parameters.h b/rosen/modules/render_service/core/system/rs_system_parameters.h index 24cfba24f..320118c1a 100644 --- a/rosen/modules/render_service/core/system/rs_system_parameters.h +++ b/rosen/modules/render_service/core/system/rs_system_parameters.h @@ -31,7 +31,6 @@ enum class QuickSkipPrepareType { STATIC_APP_INSTANCE, // 2, in case of dirty process, skip static app instance's preparation STATIC_CACHE, // 3, in case of dirty instance, simplify static (drawing)cache's preparation STATIC_CACHE_SURFACE, // 4, in case of dirty instance, simplify surface's static cache's preparation - CONTENT_DIRTY_CACHE_SURFACE, // 5, simplify dirty cache surface's subtree preparation }; class RSB_EXPORT RSSystemParameters final { diff --git a/rosen/modules/render_service_base/include/common/rs_common_def.h b/rosen/modules/render_service_base/include/common/rs_common_def.h index b0ef70c77..23557f3af 100644 --- a/rosen/modules/render_service_base/include/common/rs_common_def.h +++ b/rosen/modules/render_service_base/include/common/rs_common_def.h @@ -151,8 +151,6 @@ enum class SystemAnimatedScenes : uint32_t { ENTER_APP_CENTER, // Enter the app center EXIT_APP_CENTER, // Exit the app center APPEAR_MISSION_CENTER, // A special case scenario that displays the mission center - ENTER_WIND_CLEAR, // Enter win+D in clear screen mode - ENTER_WIND_RECOVER, // Enter win+D in recover mode OTHERS, // 1.Default state 2.The state in which the animation ends }; diff --git a/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h b/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h index 7e7f938be..c9a34becf 100644 --- a/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h +++ b/rosen/modules/render_service_base/include/pipeline/rs_surface_render_node.h @@ -876,14 +876,9 @@ public: return surfaceCacheContentStatic_; } - void UpdateSurfaceCacheContentStatic( - const std::unordered_map>& activeNodeIds); - // temperory limit situation: - // subtree no drawingcache and geodirty - // contentdirty 1 specifically for buffer update - bool IsContentDirtyNodeLimited() const + void SetSurfaceCacheContentStatic(bool contentStatic) { - return drawingCacheNodes_.empty() && dirtyGeoNodeNum_ == 0 && dirtyContentNodeNum_ <= 1; + surfaceCacheContentStatic_ = contentStatic; } size_t GetLastFrameChildrenCnt() @@ -1051,9 +1046,6 @@ private: std::vector childrenFilterRectsCacheValid_; std::vector> childrenFilterNodes_; std::unordered_set abilityNodeIds_; - size_t dirtyContentNodeNum_ = 0; - size_t dirtyGeoNodeNum_ = 0; - size_t dirtynodeNum_ = 0; // transparent region of the surface, floating window's container window is always treated as transparent Occlusion::Region transparentRegion_; diff --git a/rosen/modules/render_service_base/include/property/rs_filter_cache_manager.h b/rosen/modules/render_service_base/include/property/rs_filter_cache_manager.h index 85e16fca6..63d52d6cb 100644 --- a/rosen/modules/render_service_base/include/property/rs_filter_cache_manager.h +++ b/rosen/modules/render_service_base/include/property/rs_filter_cache_manager.h @@ -28,7 +28,6 @@ #include "include/core/SkSurface.h" #include "include/gpu/GrBackendSurface.h" #else -#include "draw/canvas.h" #include "draw/surface.h" #include "utils/rect.h" #endif @@ -82,10 +81,7 @@ public: const std::shared_ptr& filter, const std::optional& srcRect = std::nullopt, const std::optional& dstRect = std::nullopt); - static bool IsNearlyFullScreen(SkISize imageSize, int32_t canvasWidth, int32_t canvasHeight); - void PostPartialFilterRenderTask(const std::shared_ptr& filter, const SkIRect& dstRect); - void PostPartialFilterRenderInit(const std::shared_ptr& filter, const SkIRect& dstRect, - int32_t canvasWidth, int32_t canvasHeight); + void PostPartialFilterRenderTask(const std::shared_ptr& filter); #else // Call this function during the process phase to apply the filter. Depending on the cache state, it may either // regenerate the cache or reuse the existing cache. @@ -100,10 +96,7 @@ public: const std::shared_ptr& filter, const std::optional& srcRect = std::nullopt, const std::optional& dstRect = std::nullopt); - static bool IsNearlyFullScreen(Drawing::RectI imageSize, int32_t canvasWidth, int32_t canvasHeight); - void PostPartialFilterRenderTask(const std::shared_ptr& filter, const Drawing::RectI& dstRect); - void PostPartialFilterRenderInit(const std::shared_ptr& filter, const Drawing::RectI& dstRect, - int32_t canvasWidth, int32_t canvasHeight); + void PostPartialFilterRenderTask(const std::shared_ptr& filter); #endif enum CacheType : uint8_t { CACHE_TYPE_NONE = 0, @@ -126,10 +119,7 @@ private: class RSFilterCacheTask : public RSFilter::RSFilterTask { public: static const bool FilterPartialRenderEnabled; - bool isFirstInit_ = true; - bool needClearSurface_ = false; - std::atomic isTaskRelease_ = false; - std::shared_ptr cachedFirstFilter_ = nullptr; + bool isTaskTooLong = false; RSFilterCacheTask() = default; virtual ~RSFilterCacheTask() = default; #ifndef USE_ROSEN_DRAWING @@ -138,10 +128,7 @@ private: bool InitSurface(Drawing::GPUContext* grContext) override; #endif bool Render() override; - bool SaveFilteredImage() override; - void SwapInit() override; - bool SetDone() override; - void SetTaskRelease() override; + CacheProcessStatus GetStatus() const { return cacheProcessStatus_.load(); @@ -154,67 +141,58 @@ private: #ifndef USE_ROSEN_DRAWING void InitTask(std::shared_ptr filter, - std::shared_ptr cachedSnapshot, const SkIRect& dstRect) + std::shared_ptr cachedSnapshot, SkISize size) { - needClearSurface_ = (dstRectBefore_.width() != dstRect.width() || - dstRectBefore_.height() != dstRect.height()); - filterBefore_ = filter; - cachedSnapshotBefore_ = cachedSnapshot; - snapshotSizeBefore_ = cachedSnapshot->cachedRect_.size(); - dstRectBefore_ = dstRect; + filter_ = filter; + cachedSnapshot_ = cachedSnapshot; + cacheBackendTexture_ = cachedSnapshot_->cachedImage_->getBackendTexture(false); + surfaceSize_ = size; } GrBackendTexture GetResultTexture() const { return cacheCompletedBackendTexture_; } - - SkIRect GetDstRect() const - { - return dstRect_; - } #else void InitTask(std::shared_ptr filter, - std::shared_ptr cachedSnapshot, const Drawing::RectI& dstRect) + std::shared_ptr cachedSnapshot, Drawing::RectI size) { - needClearSurface_ = (dstRectBefore_.GetWidth() != dstRect.GetWidth() || - dstRectBefore_.GetHeight() != dstRect.GetHeight()); - filterBefore_ = filter; - cachedSnapshotBefore_ = cachedSnapshot; - snapshotSizeBefore_ = cachedSnapshot->cachedRect_; - dstRectBefore_ = dstRect; + filter_ = filter; + cachedSnapshot_ = cachedSnapshot; + cacheBackendTexture_ = cachedSnapshot_->cachedImage_->GetBackendTexture(false, nullptr); + surfaceSize_ = size; } Drawing::BackendTexture GetResultTexture() const { return cacheCompletedBackendTexture_; } - - Drawing::RectI GetDstRect() const - { - return dstRect_; - } #endif void Reset() { - cachedSnapshotBefore_.reset(); - } - - void ResetInTask() - { - cachedSnapshotInTask_.reset(); - dstRectBefore_ = { 0, 0, 0, 0 }; - dstRect_ = { 0, 0, 0, 0 }; + cachedSnapshot_.reset(); } void ResetGrContext() { - cacheSurface_ = nullptr; - cacheCompletedSurface_ = nullptr; - RSFilter::clearGpuContext(); +#ifndef USE_ROSEN_DRAWING + if (cacheSurface_ != nullptr) { + GrDirectContext* grContext_ = cacheSurface_->recordingContext()->asDirectContext(); + cacheSurface_ = nullptr; + grContext_->freeGpuResources(); + } +#else + if (cacheSurface_ != nullptr) { + std::shared_ptr gpuContext_ = cacheSurface_->GetCanvas()->GetGPUContext(); + cacheSurface_ = nullptr; + gpuContext_->FreeGpuResources(); + } +#endif } + bool WaitTaskFinished(); + void Notify() { cvParallelRender_.notify_one(); @@ -235,41 +213,31 @@ private: isCompleted_ = val; } - void SwapTexture() + void SawpTexture() { + std::unique_lock lock(grBackendTextureMutex_); std::swap(resultBackendTexture_, cacheCompletedBackendTexture_); - std::swap(cacheSurface_, cacheCompletedSurface_); } private: #ifndef USE_ROSEN_DRAWING + sk_sp cacheSurface_ = nullptr; GrBackendTexture cacheBackendTexture_; GrBackendTexture resultBackendTexture_; + SkISize surfaceSize_; + std::weak_ptr filter_; GrBackendTexture cacheCompletedBackendTexture_; - sk_sp cacheSurface_ = nullptr; - sk_sp cacheCompletedSurface_ = nullptr; - SkISize snapshotSize_; - SkISize snapshotSizeBefore_; - SkIRect dstRect_; - SkIRect dstRectBefore_; - std::shared_ptr filter_ = nullptr; - std::shared_ptr filterBefore_ = nullptr; #else + std::shared_ptr cacheSurface_ = nullptr; Drawing::BackendTexture cacheBackendTexture_; Drawing::BackendTexture resultBackendTexture_; + Drawing::RectI surfaceSize_; + std::weak_ptr filter_; Drawing::BackendTexture cacheCompletedBackendTexture_; - std::shared_ptr cacheSurface_ = nullptr; - std::shared_ptr cacheCompletedSurface_ = nullptr; - Drawing::RectI snapshotSize_; - Drawing::RectI snapshotSizeBefore_; - Drawing::RectI dstRect_; - Drawing::RectI dstRectBefore_; - std::shared_ptr filter_ = nullptr; - std::shared_ptr filterBefore_ = nullptr; #endif std::atomic cacheProcessStatus_ = CacheProcessStatus::WAITING; - std::shared_ptr cachedSnapshotInTask_ = nullptr; - std::shared_ptr cachedSnapshotBefore_ = nullptr; + std::shared_ptr cachedSnapshot_ = nullptr; + std::mutex grBackendTextureMutex_; std::condition_variable cvParallelRender_; std::shared_ptr handler_ = nullptr; bool isCompleted_ = false; @@ -280,8 +248,6 @@ private: const SkIRect& srcRect, const bool needSnapshotOutset = true); void GenerateFilteredSnapshot( RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& dstRect); - void FilterPartialRender( - RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& dstRect); void DrawCachedFilteredSnapshot(RSPaintFilterCanvas& canvas, const SkIRect& dstRect) const; // Validate the input srcRect and dstRect, and return the validated rects. std::tuple ValidateParams(RSPaintFilterCanvas& canvas, @@ -291,8 +257,6 @@ private: const Drawing::RectI& srcRect, const bool needSnapshotOutset = true); void GenerateFilteredSnapshot( RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const Drawing::RectI& dstRect); - void FilterPartialRender( - RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const Drawing::RectI& dstRect); void DrawCachedFilteredSnapshot(RSPaintFilterCanvas& canvas, const Drawing::RectI& dstRect) const; // Validate the input srcRect and dstRect, and return the validated rects. std::tuple ValidateParams(RSPaintFilterCanvas& canvas, @@ -311,7 +275,6 @@ private: // Note: rect in cachedSnapshot_ and cachedFilteredSnapshot_ is in device coordinate. std::shared_ptr cachedSnapshot_ = nullptr; std::shared_ptr cachedFilteredSnapshot_ = nullptr; - bool newCache_ = true; // Hash of previous filter, used to determine if we need to invalidate cachedFilteredSnapshot_. uint32_t cachedFilterHash_ = 0; diff --git a/rosen/modules/render_service_base/include/render/rs_filter.h b/rosen/modules/render_service_base/include/render/rs_filter.h index 6d83e775e..1d484086f 100644 --- a/rosen/modules/render_service_base/include/render/rs_filter.h +++ b/rosen/modules/render_service_base/include/render/rs_filter.h @@ -46,14 +46,8 @@ public: virtual bool InitSurface(Drawing::GPUContext* grContext); #endif virtual bool Render(); - virtual bool SaveFilteredImage(); - virtual void SwapInit(); - virtual bool SetDone(); - virtual void SetTaskRelease(); }; static std::function)> postTask; - static std::function)> setRelease; - static std::function clearGpuContext; virtual ~RSFilter(); RSFilter(const RSFilter&) = delete; diff --git a/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp index 3c4f6a964..480c88fc7 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_surface_render_node.cpp @@ -1455,33 +1455,6 @@ void RSSurfaceRenderNode::ResetAbilityNodeIds() abilityNodeIds_.clear(); } -void RSSurfaceRenderNode::UpdateSurfaceCacheContentStatic( - const std::unordered_map>& activeNodeIds) -{ - dirtyContentNodeNum_ = 0; - dirtyGeoNodeNum_ = 0; - dirtynodeNum_ = activeNodeIds.size(); - surfaceCacheContentStatic_ = IsOnlyBasicGeoTransform(); - if (dirtynodeNum_ == 0) { - RS_LOGD("Clear surface %{public}" PRIu64 " dirtynodes surfaceCacheContentStatic_:%{public}d", - GetId(), surfaceCacheContentStatic_); - return; - } - for (auto [id, subNode] : activeNodeIds) { - auto node = subNode.lock(); - if (node == nullptr || (id == GetId() && surfaceCacheContentStatic_)) { - continue; - } - // classify active nodes except instance surface itself - if (node->IsContentDirty()) { - dirtyContentNodeNum_++; - } else { - dirtyGeoNodeNum_++; - } - } - surfaceCacheContentStatic_ = surfaceCacheContentStatic_ && !(dirtyContentNodeNum_ == 0 || dirtyGeoNodeNum_ == 0); -} - const std::unordered_set& RSSurfaceRenderNode::GetAbilityNodeIds() const { return abilityNodeIds_; diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.cpp b/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.cpp index cf0437b99..151c15099 100755 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.cpp @@ -264,8 +264,6 @@ bool MakeFromNativeWindowBuffer(std::shared_ptr skContext, #endif nativeSurface.image = image; - NativeObjectUnreference(nativeSurface.nativeWindowBuffer); - NativeObjectReference(nativeWindowBuffer); nativeSurface.nativeWindowBuffer = nativeWindowBuffer; return true; diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.h b/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.h index 0c07ac1f8..28c94694f 100755 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.h +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/native_buffer_utils.h @@ -95,8 +95,7 @@ struct NativeSurfaceInfo { #else drawingSurface = nullptr; #endif - NativeObjectUnreference(window); - NativeObjectUnreference(nativeWindowBuffer); + NativeWindowCancelBuffer(window, nativeWindowBuffer); } }; diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_vulkan.cpp b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_vulkan.cpp index 6062480f9..70d778930 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_vulkan.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_vulkan.cpp @@ -45,8 +45,8 @@ RSSurfaceOhosVulkan::RSSurfaceOhosVulkan(const sptr& producer) : RSSurf RSSurfaceOhosVulkan::~RSSurfaceOhosVulkan() { #ifdef ENABLE_NATIVEBUFFER - mSurfaceMap.clear(); mSurfaceList.clear(); + mSurfaceMap.clear(); #endif // ENABLE_NATIVEBUFFER DestoryNativeWindow(mNativeWindow); mNativeWindow = nullptr; @@ -60,9 +60,6 @@ RSSurfaceOhosVulkan::~RSSurfaceOhosVulkan() void RSSurfaceOhosVulkan::SetNativeWindowInfo(int32_t width, int32_t height, bool useAFBC) { if (width != mWidth || height != mHeight) { - for (auto &[key, val] : mSurfaceMap) { - NativeWindowCancelBuffer(mNativeWindow, key); - } mSurfaceMap.clear(); } NativeWindowHandleOpt(mNativeWindow, SET_FORMAT, pixelFormat_); @@ -148,7 +145,6 @@ std::unique_ptr RSSurfaceOhosVulkan::RequestFrame( #else if (nativeSurface.drawingSurface == nullptr) { #endif - NativeObjectReference(mNativeWindow); nativeSurface.window = mNativeWindow; if (!NativeBufferUtils::MakeFromNativeWindowBuffer( mSkContext, nativeWindowBuffer, nativeSurface, width, height)) { @@ -164,7 +160,6 @@ std::unique_ptr RSSurfaceOhosVulkan::RequestFrame( #endif ROSEN_LOGE("RSSurfaceOhosVulkan: skSurface is null, return"); mSurfaceList.pop_back(); - NativeWindowCancelBuffer(mNativeWindow, nativeWindowBuffer); mSurfaceMap.erase(nativeWindowBuffer); return nullptr; } else { @@ -347,9 +342,6 @@ void RSSurfaceOhosVulkan::SetColorSpace(GraphicColorGamut colorSpace) { if (colorSpace != colorSpace_) { colorSpace_ = colorSpace; - for (auto &[key, val] : mSurfaceMap) { - NativeWindowCancelBuffer(mNativeWindow, key); - } mSurfaceMap.clear(); } } diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp index a3c636f87..d866a2da5 100755 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_system_properties.cpp @@ -26,8 +26,8 @@ namespace OHOS { namespace Rosen { -constexpr int DEFAULT_CACHE_WIDTH = 1250; -constexpr int DEFAULT_CACHE_HEIGHT = 2710; +constexpr int DEFAULT_CACHE_WIDTH = 1344; +constexpr int DEFAULT_CACHE_HEIGHT = 2772; constexpr int DEFAULT_PARTIAL_RENDER_ENABLED_VALUE = 2; constexpr int DEFAULT_UNI_PARTIAL_RENDER_ENABLED_VALUE = 4; constexpr int DEFAULT_CORRECTION_MODE_VALUE = 999; @@ -436,7 +436,7 @@ bool RSSystemProperties::GetFilterPartialRenderEnabled() // Determine whether the filter partial render should be enabled. The default value is 0, // which means that it is unenabled. static bool enabled = - std::atoi((system::GetParameter("persist.sys.graphic.filterPartialRenderEnabled", "1")).c_str()) != 0; + std::atoi((system::GetParameter("persist.sys.graphic.filterPartialRenderEnabled", "0")).c_str()) != 0; return enabled; } @@ -658,7 +658,7 @@ bool RSSystemProperties::GetSyncTransactionEnabled() int RSSystemProperties::GetSyncTransactionWaitDelay() { static int syncTransactionWaitDelay = - std::atoi((system::GetParameter("persist.sys.graphic.syncTransactionWaitDelay", "1500")).c_str()); + std::atoi((system::GetParameter("persist.sys.graphic.syncTransactionWaitDelay", "500")).c_str()); return syncTransactionWaitDelay; } diff --git a/rosen/modules/render_service_base/src/property/rs_filter_cache_manager.cpp b/rosen/modules/render_service_base/src/property/rs_filter_cache_manager.cpp index 1128e94f3..f71052386 100644 --- a/rosen/modules/render_service_base/src/property/rs_filter_cache_manager.cpp +++ b/rosen/modules/render_service_base/src/property/rs_filter_cache_manager.cpp @@ -26,7 +26,6 @@ namespace OHOS { namespace Rosen { -constexpr float PARALLEL_FILTER_RATIO_THRESHOLD = 0.8f; const char* RSFilterCacheManager::GetCacheState() const { if (cachedFilteredSnapshot_ != nullptr) { @@ -38,11 +37,11 @@ const char* RSFilterCacheManager::GetCacheState() const } } -#define CHECK_CACHE_PROCESS_STATUS \ - do { \ - if (GetStatus() != CacheProcessStatus::DOING) { \ - return false; \ - } \ +#define CHECK_CACHE_PROCESS_STATUS \ + do { \ + if (cacheProcessStatus_.load() == CacheProcessStatus::WAITING) { \ + return false; \ + } \ } while (false) #ifndef ROSEN_ARKUI_X const bool RSFilterCacheManager::RSFilterCacheTask::FilterPartialRenderEnabled = @@ -76,55 +75,30 @@ inline static bool isEqualRect(const Drawing::RectI& src, const RectI& dst) void RSFilterCacheManager::UpdateCacheStateWithFilterHash(const std::shared_ptr& filter) { - RS_OPTIONAL_TRACE_FUNC(); auto filterHash = filter->Hash(); + if (task_->GetStatus() == CacheProcessStatus::DONE) { + task_->Reset(); + } + if (RSFilterCacheTask::FilterPartialRenderEnabled && cachedSnapshot_ != nullptr && + cachedFilterHash_ != filterHash && cachedSnapshot_->cachedImage_ != nullptr) { +#ifndef USE_ROSEN_DRAWING + auto rsFilter = std::static_pointer_cast(filter); +#else + auto rsFilter = std::static_pointer_cast(filter); +#endif + PostPartialFilterRenderTask(rsFilter); + } if (cachedFilteredSnapshot_ == nullptr || cachedFilterHash_ == filterHash) { return; } + RS_OPTIONAL_TRACE_FUNC(); + // filter changed, clear the filtered snapshot. ROSEN_LOGD("RSFilterCacheManager::UpdateCacheStateWithFilterHash Cache expired. Reason: Cached filtered hash " "%{public}X does not match new hash %{public}X.", cachedFilterHash_, filterHash); cachedFilteredSnapshot_.reset(); } -#ifndef USE_ROSEN_DRAWING -void RSFilterCacheManager::PostPartialFilterRenderInit( - const std::shared_ptr& filter, const SkIRect& dstRect, int32_t canvasWidth, int32_t canvasHeight) -#else -void RSFilterCacheManager::PostPartialFilterRenderInit(const std::shared_ptr& filter, - const Drawing::RectI& dstRect, int32_t canvasWidth, int32_t canvasHeight) -#endif -{ - RS_OPTIONAL_TRACE_FUNC(); - task_->SetCompleted(task_->GetStatus() == CacheProcessStatus::DONE); - if (task_->GetStatus() == CacheProcessStatus::DOING) { - task_->SetCompleted(!task_->isFirstInit_); - } - if (task_->GetStatus() == CacheProcessStatus::DONE) { - task_->Reset(); - task_->isFirstInit_ = false; - task_->SwapTexture(); - task_->SetStatus(CacheProcessStatus::WAITING); - } - if (task_->isTaskRelease_.load()) { - return; - } - if (task_->cachedFirstFilter_ != nullptr && task_->isFirstInit_) { - cachedFilteredSnapshot_ = task_->cachedFirstFilter_; - } else { - task_->cachedFirstFilter_ = nullptr; - } - if (RSFilterCacheTask::FilterPartialRenderEnabled && - (cachedSnapshot_ != nullptr && cachedSnapshot_->cachedImage_ != nullptr) && - (cachedFilteredSnapshot_ == nullptr || cachedFilteredSnapshot_->cachedImage_ == nullptr) && -#ifndef USE_ROSEN_DRAWING - IsNearlyFullScreen(cachedSnapshot_->cachedRect_.size(), canvasWidth, canvasHeight)) { -#else - IsNearlyFullScreen(cachedSnapshot_->cachedRect_, canvasWidth, canvasHeight)) { -#endif - PostPartialFilterRenderTask(filter, dstRect); - } -} void RSFilterCacheManager::UpdateCacheStateWithFilterRegion() { @@ -163,19 +137,17 @@ bool RSFilterCacheManager::RSFilterCacheTask::InitSurface(GrRecordingContext* gr bool RSFilterCacheManager::RSFilterCacheTask::InitSurface(Drawing::GPUContext* grContext) #endif { - RS_OPTIONAL_TRACE_FUNC(); - if (!needClearSurface_) { + RS_TRACE_NAME("InitSurface"); + if (cacheSurface_ != nullptr) { return true; } - cacheSurface_ = nullptr; - auto runner = AppExecFwk::EventRunner::Current(); handler_ = std::make_shared(runner); #ifndef USE_ROSEN_DRAWING - SkImageInfo info = SkImageInfo::MakeN32Premul(dstRect_.width(), dstRect_.height()); + SkImageInfo info = SkImageInfo::MakeN32Premul(surfaceSize_.width(), surfaceSize_.height()); cacheSurface_ = SkSurface::MakeRenderTarget(grContext, SkBudgeted::kYes, info); #else - Drawing::ImageInfo info = Drawing::ImageInfo::MakeN32Premul(dstRect_.GetWidth(), dstRect_.GetHeight()); + Drawing::ImageInfo info = Drawing::ImageInfo::MakeN32Premul(surfaceSize_.GetWidth(), surfaceSize_.GetHeight()); cacheSurface_ = Drawing::Surface::MakeRenderTarget(grContext, true, info); #endif return cacheSurface_ != nullptr; @@ -207,17 +179,12 @@ bool RSFilterCacheManager::RSFilterCacheTask::Render() } #else surfaceOrigin = kBottomLeft_GrSurfaceOrigin; -#endif // RS_ENABLE_VK - auto threadImage = SkImage::MakeFromTexture(cacheCanvas->recordingContext(), cacheBackendTexture_, surfaceOrigin, - kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); - if (!threadImage) { - SetStatus(CacheProcessStatus::WAITING); - ROSEN_LOGE("RSFilterCacheManager::Render: threadImage is null"); - return false; - } - auto src = SkRect::MakeSize(SkSize::Make(snapshotSize_)); - auto dst = SkRect::MakeSize(SkSize::Make(dstRect_.size())); -#else // USE_ROSEN_DRAWING +#endif + auto threadImage = SkImage::MakeFromTexture(cacheCanvas->recordingContext(), cacheBackendTexture_, + surfaceOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); + auto src = SkRect::MakeSize(SkSize::Make(surfaceSize_)); + auto dst = SkRect::MakeSize(SkSize::Make(surfaceSize_)); +#else Drawing::TextureOrigin surfaceOrigin = Drawing::TextureOrigin::TOP_LEFT; #ifdef RS_ENABLE_VK if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || @@ -228,100 +195,102 @@ bool RSFilterCacheManager::RSFilterCacheTask::Render() } #else surfaceOrigin = Drawing::TextureOrigin::BOTTOM_LEFT; -#endif // RS_ENABLE_VK +#endif Drawing::BitmapFormat bitmapFormat = { Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_PREMUL }; auto threadImage = std::make_shared(); if (!threadImage->BuildFromTexture(*cacheCanvas->GetGPUContext(), cacheBackendTexture_.GetTextureInfo(), - surfaceOrigin, bitmapFormat, nullptr)) { - SetStatus(CacheProcessStatus::WAITING); + surfaceOrigin, bitmapFormat, nullptr)) { ROSEN_LOGE("RSFilterCacheManager::Render: cacheCanvas is null"); return false; } - auto src = Drawing::Rect(0, 0, snapshotSize_.GetWidth(), snapshotSize_.GetHeight()); - auto dst = Drawing::Rect(0, 0, dstRect_.GetWidth(), dstRect_.GetHeight()); -#endif // USE_ROSEN_DRAWING - CHECK_CACHE_PROCESS_STATUS; - filter_->DrawImageRect(*cacheCanvas, threadImage, src, dst); - filter_->PostProcess(*cacheCanvas); + auto src = Drawing::Rect(0, 0, surfaceSize_.GetWidth(), surfaceSize_.GetHeight()); + auto dst = Drawing::Rect(0, 0, surfaceSize_.GetWidth(), surfaceSize_.GetHeight()); +#endif CHECK_CACHE_PROCESS_STATUS; - return true; -} - -bool RSFilterCacheManager::RSFilterCacheTask::SaveFilteredImage() -{ + { + auto filterTemp = filter_.lock(); + if (!filterTemp) { + SetStatus(CacheProcessStatus::WAITING); + ROSEN_LOGE("RSFilterCacheManager::Render: filterTemp is null"); + return false; + } + filterTemp->DrawImageRect(*cacheCanvas, threadImage, src, dst); + filterTemp->PostProcess(*cacheCanvas); + } CHECK_CACHE_PROCESS_STATUS; #ifndef USE_ROSEN_DRAWING - resultBackendTexture_ = - cacheSurface_->getBackendTexture(SkSurface::BackendHandleAccess::kFlushRead_BackendHandleAccess); + cacheSurface_->flushAndSubmit(true); #else - resultBackendTexture_ = cacheSurface_->GetBackendTexture(); + cacheSurface_->FlushAndSubmit(true); #endif CHECK_CACHE_PROCESS_STATUS; - return true; -} - -void RSFilterCacheManager::RSFilterCacheTask::SwapInit() -{ - RS_OPTIONAL_TRACE_FUNC(); - std::swap(filter_, filterBefore_); - std::swap(cachedSnapshotInTask_, cachedSnapshotBefore_); - std::swap(snapshotSize_, snapshotSizeBefore_); - std::swap(dstRect_, dstRectBefore_); - if (cachedSnapshotInTask_ != nullptr) { + { + std::unique_lock lock(grBackendTextureMutex_); #ifndef USE_ROSEN_DRAWING - cacheBackendTexture_ = cachedSnapshotInTask_->cachedImage_->getBackendTexture(false); + resultBackendTexture_ = + cacheSurface_->getBackendTexture(SkSurface::BackendHandleAccess::kFlushRead_BackendHandleAccess); #else - cacheBackendTexture_ = cachedSnapshotInTask_->cachedImage_->GetBackendTexture(false, nullptr); + resultBackendTexture_ = cacheSurface_->GetBackendTexture(); #endif } + CHECK_CACHE_PROCESS_STATUS; + cacheProcessStatus_.store(CacheProcessStatus::DONE); + Notify(); + return true; } -void RSFilterCacheManager::RSFilterCacheTask::SetTaskRelease() -{ - isTaskRelease_.store(false); -} - -bool RSFilterCacheManager::RSFilterCacheTask::SetDone() +bool RSFilterCacheManager::RSFilterCacheTask::WaitTaskFinished() { - RS_OPTIONAL_TRACE_FUNC(); - CHECK_CACHE_PROCESS_STATUS; - if (isTaskRelease_.load()) { - SetStatus(CacheProcessStatus::WAITING); - } else { - SetStatus(CacheProcessStatus::DONE); + std::unique_lock lock(grBackendTextureMutex_); + if (GetStatus() != CacheProcessStatus::DOING) { + return GetStatus() == CacheProcessStatus::DONE; } + const long TIME_OUT = 1; // 1 milliseconds + if (!cvParallelRender_.wait_for(lock, std::chrono::milliseconds(TIME_OUT), + [this] { return cacheProcessStatus_ == CacheProcessStatus::DONE; })) { + RS_OPTIONAL_TRACE_NAME("WaitTaskFinished, wait failed, CacheProcessStatus_:" + + std::to_string(static_cast(cacheProcessStatus_.load()))); + return false; + } + RS_OPTIONAL_TRACE_NAME("WaitTaskFinished, wait success, CacheProcessStatus_:" + + std::to_string(static_cast(cacheProcessStatus_.load()))); return true; } -#ifndef USE_ROSEN_DRAWING -bool RSFilterCacheManager::IsNearlyFullScreen(SkISize imageSize, int32_t canvasWidth, int32_t canvasHeight) -#else -bool RSFilterCacheManager::IsNearlyFullScreen(Drawing::RectI imageSize, int32_t canvasWidth, int32_t canvasHeight) -#endif -{ - RS_OPTIONAL_TRACE_FUNC(); - auto widthThreshold = static_cast(canvasWidth * PARALLEL_FILTER_RATIO_THRESHOLD); - auto heightThreshold = static_cast(canvasHeight * PARALLEL_FILTER_RATIO_THRESHOLD); -#ifndef USE_ROSEN_DRAWING - return imageSize.width() >= widthThreshold && imageSize.height() >= heightThreshold; -#else - return imageSize.GetWidth() >= widthThreshold && imageSize.GetHeight() >= heightThreshold; -#endif -} #ifndef USE_ROSEN_DRAWING -void RSFilterCacheManager::PostPartialFilterRenderTask( - const std::shared_ptr& filter, const SkIRect& dstRect) +void RSFilterCacheManager::PostPartialFilterRenderTask(const std::shared_ptr& filter) #else -void RSFilterCacheManager::PostPartialFilterRenderTask( - const std::shared_ptr& filter, const Drawing::RectI& dstRect) +void RSFilterCacheManager::PostPartialFilterRenderTask(const std::shared_ptr& filter) #endif { RS_OPTIONAL_TRACE_FUNC(); + task_->SetCompleted(task_->GetStatus() == CacheProcessStatus::DONE); + if (task_->GetStatus() == CacheProcessStatus::DOING && !task_->isTaskTooLong && !task_->WaitTaskFinished()) { + task_->isTaskTooLong = true; + } + if (task_->GetStatus() == CacheProcessStatus::DONE) { + task_->SawpTexture(); + task_->SetStatus(CacheProcessStatus::WAITING); + task_->isTaskTooLong = false; + } + if (SoloTaskPrepare) { + SoloTaskPrepare = false; + } else { + task_->SetCompleted(false); + return; + } // Prepare a backup of common resources for threads - if (RSFilter::postTask != nullptr && (task_->GetStatus() == CacheProcessStatus::WAITING)) { + if (RSFilter::postTask != nullptr && task_->GetStatus() == CacheProcessStatus::WAITING) { // Because the screenshot is zoomed out, here you need to zoom in - task_->InitTask(filter, cachedSnapshot_, dstRect); +#ifndef USE_ROSEN_DRAWING + auto dstCopy = cachedSnapshot_->cachedRect_.makeOutset(1, 1); + task_->InitTask(filter, cachedSnapshot_, dstCopy.size()); +#else + auto dstCopy = cachedSnapshot_->cachedRect_; + dstCopy.MakeOutset(1, 1); + task_->InitTask(filter, cachedSnapshot_, dstCopy); +#endif task_->SetStatus(CacheProcessStatus::DOING); RSFilter::postTask(task_); } else { @@ -361,39 +330,50 @@ void RSFilterCacheManager::DrawFilter(RSPaintFilterCanvas& canvas, const std::sh } else { --cacheUpdateInterval_; } -#ifndef USE_ROSEN_DRAWING - auto surface = canvas.getSurface(); - auto width = surface->width(); - auto height = surface->height(); -#else - auto surface = canvas.GetSurface(); - auto width = surface->Width(); - auto height = surface->Height(); -#endif - PostPartialFilterRenderInit(filter, dst, width, height); + bool shouldClearFilteredCache = false; if (cachedFilteredSnapshot_ == nullptr || cachedFilteredSnapshot_->cachedImage_ == nullptr) { auto previousFilterHash = cachedFilterHash_; if (RSFilterCacheTask::FilterPartialRenderEnabled && task_->IsCompleted()) { - FilterPartialRender(canvas, filter, dst); +#ifndef USE_ROSEN_DRAWING + auto filteredSnapshot = SkImage::MakeFromTexture(canvas.recordingContext(), task_->GetResultTexture(), + kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); +#else + auto filteredSnapshot = std::make_shared(); + Drawing::BitmapFormat bitmapFormat = { Drawing::ColorType::COLORTYPE_RGBA_8888, + Drawing::AlphaType::ALPHATYPE_PREMUL }; + filteredSnapshot->BuildFromTexture(*canvas.GetGPUContext(), + task_->GetResultTexture().GetTextureInfo(), + Drawing::TextureOrigin::BOTTOM_LEFT, bitmapFormat, nullptr); +#endif + auto filteredRect = dst; +#ifndef USE_ROSEN_DRAWING + if (RSSystemProperties::GetImageGpuResourceCacheEnable( + filteredSnapshot->width(), filteredSnapshot->height())) { + ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", + filteredSnapshot->width(), filteredSnapshot->height()); + as_IB(filteredSnapshot)->hintCacheGpuResource(); + } +#else + if (RSSystemProperties::GetImageGpuResourceCacheEnable( + filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight())) { + ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", + filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight()); + as_IB(filteredSnapshot->ExportSkImage().get())->hintCacheGpuResource(); + } +#endif + cachedFilteredSnapshot_ = + std::make_shared(std::move(filteredSnapshot), filteredRect); + cachedFilterHash_ = filter->Hash(); } else { GenerateFilteredSnapshot(canvas, filter, dst); } - newCache_ = true; + SoloTaskPrepare = true; // If 1. the filter hash matches, 2. the filter region is whole snapshot region, we can safely clear original // snapshot, else we need to clear the filtered snapshot. shouldClearFilteredCache = previousFilterHash != cachedFilterHash_ || !isEqualRect(dst, snapshotRegion_); - } else if (RSFilterCacheTask::FilterPartialRenderEnabled && task_->IsCompleted()) { - FilterPartialRender(canvas, filter, dst); - } else { - newCache_ = false; - } - if (task_->GetStatus() == CacheProcessStatus::DOING && task_->isFirstInit_ && - task_->cachedFirstFilter_ == nullptr) { - task_->cachedFirstFilter_ = cachedFilteredSnapshot_; } DrawCachedFilteredSnapshot(canvas, dst); - task_->SetCompleted(false); // To reduce the memory consumption, we only keep either the cached snapshot or the filtered image. CompactCache(shouldClearFilteredCache); } @@ -448,8 +428,9 @@ const std::shared_ptr RSFilterCacheManage } #ifndef USE_ROSEN_DRAWING -void RSFilterCacheManager::TakeSnapshot(RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, - const SkIRect& srcRect, const bool needSnapshotOutset) +void RSFilterCacheManager::TakeSnapshot( + RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& srcRect, + const bool needSnapshotOutset) { auto skSurface = canvas.GetSurface(); if (skSurface == nullptr) { @@ -493,8 +474,9 @@ void RSFilterCacheManager::TakeSnapshot(RSPaintFilterCanvas& canvas, const std:: pendingPurge_ = false; } #else -void RSFilterCacheManager::TakeSnapshot(RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, - const Drawing::RectI& srcRect, const bool needSnapshotOutset) +void RSFilterCacheManager::TakeSnapshot( + RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const Drawing::RectI& srcRect, + const bool needSnapshotOutset) { auto drawingSurface = canvas.GetSurface(); if (drawingSurface == nullptr) { @@ -538,51 +520,6 @@ void RSFilterCacheManager::TakeSnapshot(RSPaintFilterCanvas& canvas, const std:: } #endif -#ifndef USE_ROSEN_DRAWING -void RSFilterCacheManager::FilterPartialRender( - RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& dstRect) -#else -void RSFilterCacheManager::FilterPartialRender( - RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const Drawing::RectI& dstRect) -#endif -{ - RS_OPTIONAL_TRACE_FUNC(); -#ifndef USE_ROSEN_DRAWING - auto filteredSnapshot = SkImage::MakeFromTexture(canvas.recordingContext(), task_->GetResultTexture(), - kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); -#else - auto filteredSnapshot = std::make_shared(); - Drawing::BitmapFormat bitmapFormat = { Drawing::ColorType::COLORTYPE_RGBA_8888, - Drawing::AlphaType::ALPHATYPE_PREMUL }; - filteredSnapshot->BuildFromTexture(*canvas.GetGPUContext(), task_->GetResultTexture().GetTextureInfo(), - Drawing::TextureOrigin::BOTTOM_LEFT, bitmapFormat, nullptr); -#endif - if (filteredSnapshot == nullptr) { - GenerateFilteredSnapshot(canvas, filter, dstRect); - } else { -#ifndef USE_ROSEN_DRAWING - auto filteredRect = SkIRect::MakeWH(filteredSnapshot->width(), filteredSnapshot->height()); - if (RSSystemProperties::GetImageGpuResourceCacheEnable(filteredSnapshot->width(), filteredSnapshot->height())) { - ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", - filteredSnapshot->width(), filteredSnapshot->height()); - as_IB(filteredSnapshot)->hintCacheGpuResource(); - } -#else - auto filteredRect = Drawing::RectI(0, 0, filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight()); - if (RSSystemProperties::GetImageGpuResourceCacheEnable( - filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight())) { - ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", - filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight()); - as_IB(filteredSnapshot->ExportSkImage().get())->hintCacheGpuResource(); - } -#endif - cachedFilteredSnapshot_.reset(); - cachedFilteredSnapshot_ = - std::make_shared(std::move(filteredSnapshot), task_->GetDstRect()); - cachedFilterHash_ = filter->Hash(); - } -} - #ifndef USE_ROSEN_DRAWING void RSFilterCacheManager::GenerateFilteredSnapshot( RSPaintFilterCanvas& canvas, const std::shared_ptr& filter, const SkIRect& dstRect) @@ -637,8 +574,8 @@ void RSFilterCacheManager::GenerateFilteredSnapshot( } #else auto filteredSnapshot = offscreenSurface->GetImageSnapshot(); - if (RSSystemProperties::GetImageGpuResourceCacheEnable( - filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight())) { + if (RSSystemProperties::GetImageGpuResourceCacheEnable(filteredSnapshot->GetWidth(), + filteredSnapshot->GetHeight())) { ROSEN_LOGD("GenerateFilteredSnapshot cache image resource(width:%{public}d, height:%{public}d).", filteredSnapshot->GetWidth(), filteredSnapshot->GetHeight()); as_IB(filteredSnapshot->ExportSkImage().get())->hintCacheGpuResource(); @@ -671,14 +608,8 @@ void RSFilterCacheManager::DrawCachedFilteredSnapshot(RSPaintFilterCanvas& canva ClipVisibleRect(canvas); // The cache type and parameters has been validated, dstRect must be subset of cachedFilteredSnapshot_->cachedRect_. - SkRect dst = SkRect::Make(dstRect); - SkRect src; - if (newCache_) { - src = SkRect::MakeSize(SkSize::Make(cachedFilteredSnapshot_->cachedImage_->dimensions())); - } else { - src = SkRect::Make(dstRect.makeOffset(-cachedFilteredSnapshot_->cachedRect_.topLeft())); - src.intersect(SkRect::Make(cachedFilteredSnapshot_->cachedImage_->bounds())); - } + auto dst = SkRect::Make(dstRect); + auto src = SkRect::Make(dstRect.makeOffset(-cachedFilteredSnapshot_->cachedRect_.topLeft())); SkPaint paint; paint.setAntiAlias(true); @@ -701,17 +632,9 @@ void RSFilterCacheManager::DrawCachedFilteredSnapshot(RSPaintFilterCanvas& canva ClipVisibleRect(canvas); // The cache type and parameters has been validated, dstRect must be subset of cachedFilteredSnapshot_->cachedRect_. - Drawing::Rect dst(dstRect.GetLeft(), dstRect.GetTop(), dstRect.GetRight(), dstRect.GetBottom()); - Drawing::Rect src; - if (newCache_) { - src = { 0, 0, cachedFilteredSnapshot_->cachedImage_->GetWidth(), - cachedFilteredSnapshot_->cachedImage_->GetHeight() }; - } else { - src = { dstRect.GetLeft(), dstRect.GetTop(), dstRect.GetRight(), dstRect.GetBottom() }; - src.Offset(-cachedFilteredSnapshot_->cachedRect_.GetLeft(), -cachedFilteredSnapshot_->cachedRect_.GetTop()); - src.Intersect(Drawing::Rect(0, 0, cachedFilteredSnapshot_->cachedImage_->GetWidth(), - cachedFilteredSnapshot_->cachedImage_->GetHeight())); - } + Drawing::Rect dst = {dstRect.GetLeft(), dstRect.GetTop(), dstRect.GetRight(), dstRect.GetBottom()}; + Drawing::Rect src = {dstRect.GetLeft(), dstRect.GetTop(), dstRect.GetRight(), dstRect.GetBottom()}; + src.Offset(-cachedFilteredSnapshot_->cachedRect_.GetLeft(), -cachedFilteredSnapshot_->cachedRect_.GetTop()); Drawing::Brush brush; brush.SetAntiAlias(true); @@ -731,20 +654,18 @@ void RSFilterCacheManager::InvalidateCache(CacheType cacheType) if (cacheType & CacheType::CACHE_TYPE_FILTERED_SNAPSHOT) { cachedFilteredSnapshot_.reset(); } + task_->SetStatus(CacheProcessStatus::WAITING); + task_->SetCompleted(false); + task_->Reset(); } void RSFilterCacheManager::ReleaseCacheOffTree() { - RS_OPTIONAL_TRACE_FUNC(); + RS_OPTIONAL_TRACE_NAME("WaitTaskFinished, wait failed, CacheProcessStatus_:"); ROSEN_LOGD("RSFilterCacheManager::ReleaseCacheOffTree task_:%{public}p", task_.get()); cachedSnapshot_.reset(); cachedFilteredSnapshot_.reset(); - newCache_ = false; - task_->isTaskRelease_.store(true); - task_->cachedFirstFilter_ = nullptr; - task_->ResetInTask(); task_->SetCompleted(false); - task_->isFirstInit_ = true; task_->SetStatus(CacheProcessStatus::WAITING); task_->Reset(); if (task_->GetHandler() != nullptr) { @@ -752,9 +673,6 @@ void RSFilterCacheManager::ReleaseCacheOffTree() task_->GetHandler()->PostTask( [task_tmp]() { task_tmp->ResetGrContext(); }, AppExecFwk::EventQueue::Priority::IMMEDIATE); } - if (RSFilter::setRelease != nullptr) { - RSFilter::setRelease(task_); - } } #ifndef USE_ROSEN_DRAWING @@ -771,8 +689,8 @@ inline void RSFilterCacheManager::ClipVisibleRect(RSPaintFilterCanvas& canvas) { auto visibleRectF = canvas.GetVisibleRect(); visibleRectF.Round(); - Drawing::RectI visibleIRect = { (int)visibleRectF.GetLeft(), (int)visibleRectF.GetTop(), - (int)visibleRectF.GetRight(), (int)visibleRectF.GetBottom() }; + Drawing::RectI visibleIRect = {(int)visibleRectF.GetLeft(), (int)visibleRectF.GetTop(), + (int)visibleRectF.GetRight(), (int)visibleRectF.GetBottom()}; auto deviceClipRect = canvas.GetDeviceClipBounds(); if (!visibleIRect.IsEmpty() && deviceClipRect.Intersect(visibleIRect)) { canvas.ClipIRect(visibleIRect, Drawing::ClipOp::INTERSECT); @@ -835,8 +753,9 @@ std::tuple RSFilterCacheManager::ValidateParams( return { src, dst }; } #else -std::tuple RSFilterCacheManager::ValidateParams(RSPaintFilterCanvas& canvas, - const std::optional& srcRect, const std::optional& dstRect) +std::tuple RSFilterCacheManager::ValidateParams( + RSPaintFilterCanvas& canvas, const std::optional& srcRect, + const std::optional& dstRect) { Drawing::RectI src; Drawing::RectI dst; diff --git a/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp b/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp index 96a284977..fddb0e047 100644 --- a/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp +++ b/rosen/modules/render_service_base/src/render/rs_blur_filter.cpp @@ -91,7 +91,7 @@ std::string RSBlurFilter::GetDescription() bool RSBlurFilter::IsValid() const { - constexpr float epsilon = 0.999f; + constexpr float epsilon = 0.05f; return blurRadiusX_ > epsilon || blurRadiusY_ > epsilon; } diff --git a/rosen/modules/render_service_base/src/render/rs_filter.cpp b/rosen/modules/render_service_base/src/render/rs_filter.cpp index 84c3fe7b3..d85f0ed8d 100644 --- a/rosen/modules/render_service_base/src/render/rs_filter.cpp +++ b/rosen/modules/render_service_base/src/render/rs_filter.cpp @@ -29,8 +29,6 @@ RSFilter::RSFilter() RSFilter::~RSFilter() {} std::function)> RSFilter::postTask = nullptr; -std::function)> RSFilter::setRelease = nullptr; -std::function RSFilter::clearGpuContext = nullptr; std::string RSFilter::GetDescription() { diff --git a/rosen/modules/render_service_base/src/render/rs_image_cache.cpp b/rosen/modules/render_service_base/src/render/rs_image_cache.cpp index 3e798f5af..0a6d84aad 100644 --- a/rosen/modules/render_service_base/src/render/rs_image_cache.cpp +++ b/rosen/modules/render_service_base/src/render/rs_image_cache.cpp @@ -161,9 +161,15 @@ void RSImageCache::ReleasePixelMapCache(uint64_t uniqueId) } } #ifndef USE_ROSEN_DRAWING - ReleaseSkiaImageCacheByPixelMapId(uniqueId); + auto itr = pixelMapIdRelatedSkiaImageCache_.find(uniqueId); + if (itr != pixelMapIdRelatedSkiaImageCache_.end()) { + pixelMapIdRelatedSkiaImageCache_.erase(itr); + } #else - ReleaseDrawingImageCacheByPixelMapId(uniqueId); + auto itr = pixelMapIdRelatedDrawingImageCache_.find(uniqueId); + if (itr != pixelMapIdRelatedDrawingImageCache_.end()) { + pixelMapIdRelatedDrawingImageCache_.erase(itr); + } #endif } } diff --git a/rosen/modules/render_service_base/src/render/rs_material_filter.cpp b/rosen/modules/render_service_base/src/render/rs_material_filter.cpp index 3a1297b02..95571ac0a 100644 --- a/rosen/modules/render_service_base/src/render/rs_material_filter.cpp +++ b/rosen/modules/render_service_base/src/render/rs_material_filter.cpp @@ -285,7 +285,7 @@ std::shared_ptr RSMaterialFilter::TransformFilter(float fraction) cons bool RSMaterialFilter::IsValid() const { - constexpr float epsilon = 0.999f; + constexpr float epsilon = 0.05f; return radius_ > epsilon; } diff --git a/rosen/test/render_service/render_service/unittest/pipeline/rs_main_thread_test.cpp b/rosen/test/render_service/render_service/unittest/pipeline/rs_main_thread_test.cpp index e5e12695d..c9a44532d 100644 --- a/rosen/test/render_service/render_service/unittest/pipeline/rs_main_thread_test.cpp +++ b/rosen/test/render_service/render_service/unittest/pipeline/rs_main_thread_test.cpp @@ -553,43 +553,42 @@ HWTEST_F(RSMainThreadTest, AddActiveNode, TestSize.Level1) } /** - * @tc.name: CheckAndUpdateInstanceContentStaticStatus01 + * @tc.name: CheckIfInstanceOnlySurfaceBasicGeoTransform01 * @tc.desc: Test static instance(no dirty) would be classify as only basic geo transform * @tc.type: FUNC * @tc.require: issueI8IXTX */ -HWTEST_F(RSMainThreadTest, CheckAndUpdateInstanceContentStaticStatus01, TestSize.Level1) +HWTEST_F(RSMainThreadTest, CheckIfInstanceOnlySurfaceBasicGeoTransform01, TestSize.Level1) { auto mainThread = RSMainThread::Instance(); mainThread->context_->activeNodesInRoot_.clear(); // valid nodeid NodeId id = 1; - auto node = std::make_shared(id, mainThread->context_); + auto node = std::make_shared(id, mainThread->context_); ASSERT_NE(node, nullptr); - mainThread->CheckAndUpdateInstanceContentStaticStatus(node); - ASSERT_EQ(node->GetSurfaceCacheContentStatic(), true); + ASSERT_EQ(mainThread->CheckIfInstanceOnlySurfaceBasicGeoTransform(id), true); } /** - * @tc.name: CheckAndUpdateInstanceContentStaticStatus02 + * @tc.name: CheckIfInstanceOnlySurfaceBasicGeoTransform02 * @tc.desc: Test new instance would not be classify as only basic geo transform * @tc.type: FUNC * @tc.require: issueI8IXTX */ -HWTEST_F(RSMainThreadTest, CheckAndUpdateInstanceContentStaticStatus02, TestSize.Level1) +HWTEST_F(RSMainThreadTest, CheckIfInstanceOnlySurfaceBasicGeoTransform02, TestSize.Level1) { auto mainThread = RSMainThread::Instance(); mainThread->context_->activeNodesInRoot_.clear(); // valid nodeid NodeId id = 1; - auto node = std::make_shared(id, mainThread->context_); + auto node = std::make_shared(id, mainThread->context_); ASSERT_NE(node, nullptr); node->SetIsOnTheTree(true, id, id); node->SetContentDirty(); mainThread->context_->AddActiveNode(node); ASSERT_EQ(static_cast(mainThread->context_->activeNodesInRoot_.size()), 1); - mainThread->CheckAndUpdateInstanceContentStaticStatus(node); - ASSERT_EQ(node->GetSurfaceCacheContentStatic(), false); + + ASSERT_EQ(mainThread->CheckIfInstanceOnlySurfaceBasicGeoTransform(id), false); } /** diff --git a/rosen/test/render_service/render_service/unittest/pipeline/rs_uni_render_visitor_test.cpp b/rosen/test/render_service/render_service/unittest/pipeline/rs_uni_render_visitor_test.cpp index dd6e6b346..770a8daea 100644 --- a/rosen/test/render_service/render_service/unittest/pipeline/rs_uni_render_visitor_test.cpp +++ b/rosen/test/render_service/render_service/unittest/pipeline/rs_uni_render_visitor_test.cpp @@ -2555,13 +2555,13 @@ HWTEST_F(RSUniRenderVisitorTest, ProcessSharedTransitionNode003, TestSize.Level2 } /** - * @tc.name: UpdateSubTreeInCache001 - * @tc.desc: Test RSUniRenderVisitorTest.UpdateSubTreeInCache while + * @tc.name: UpdateStaticCacheSubTree001 + * @tc.desc: Test RSUniRenderVisitorTest.UpdateStaticCacheSubTree while * node doesn't have Child * @tc.type: FUNC * @tc.require: issueI7UGLR */ -HWTEST_F(RSUniRenderVisitorTest, UpdateSubTreeInCache001, TestSize.Level2) +HWTEST_F(RSUniRenderVisitorTest, UpdateStaticCacheSubTree001, TestSize.Level2) { NodeId id = 0; auto node = std::make_shared(id); @@ -2569,18 +2569,18 @@ HWTEST_F(RSUniRenderVisitorTest, UpdateSubTreeInCache001, TestSize.Level2) ASSERT_NE(node, nullptr); auto rsUniRenderVisitor = std::make_shared(); ASSERT_NE(rsUniRenderVisitor, nullptr); - rsUniRenderVisitor->UpdateSubTreeInCache(node, node->GetSortedChildren()); + rsUniRenderVisitor->UpdateStaticCacheSubTree(node, node->GetSortedChildren()); ASSERT_EQ(node->GetDrawingCacheChanged(), false); } /** - * @tc.name: UpdateSubTreeInCache002 - * @tc.desc: Test RSUniRenderVisitorTest.UpdateSubTreeInCache while + * @tc.name: UpdateStaticCacheSubTree002 + * @tc.desc: Test RSUniRenderVisitorTest.UpdateStaticCacheSubTree while * node has Child * @tc.type: FUNC * @tc.require: issueI7UGLR */ -HWTEST_F(RSUniRenderVisitorTest, UpdateSubTreeInCache002, TestSize.Level2) +HWTEST_F(RSUniRenderVisitorTest, UpdateStaticCacheSubTree002, TestSize.Level2) { NodeId id = 0; auto node = std::make_shared(id); @@ -2592,7 +2592,7 @@ HWTEST_F(RSUniRenderVisitorTest, UpdateSubTreeInCache002, TestSize.Level2) node->AddChild(child); auto rsUniRenderVisitor = std::make_shared(); ASSERT_NE(rsUniRenderVisitor, nullptr); - rsUniRenderVisitor->UpdateSubTreeInCache(node, node->GetSortedChildren()); + rsUniRenderVisitor->UpdateStaticCacheSubTree(node, node->GetSortedChildren()); ASSERT_EQ(node->GetDrawingCacheChanged(), false); } -- Gitee