From 8da1842c95b24e2ca4dae8a0a9cf112c2fbd1ed0 Mon Sep 17 00:00:00 2001 From: redermens Date: Mon, 18 Nov 2024 16:53:08 +0800 Subject: [PATCH 1/2] Canvas PostPlayback for dirtyArea Signed-off-by: redermens --- ...rs_canvas_drawing_render_node_drawable.cpp | 159 +++++++++--------- .../rs_canvas_drawing_render_node_drawable.h | 7 +- .../core/pipeline/rs_main_thread.cpp | 2 +- .../pipeline/rs_canvas_drawing_render_node.h | 1 - .../rs_canvas_drawing_render_node.cpp | 46 +++-- .../src/pipeline/rs_render_node.cpp | 4 +- .../unittest/pipeline/rs_main_thread_test.cpp | 51 ++---- 7 files changed, 137 insertions(+), 133 deletions(-) diff --git a/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.cpp b/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.cpp index ab368295c9..fcebea2ccc 100755 --- a/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.cpp +++ b/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.cpp @@ -17,6 +17,7 @@ #include "common/rs_background_thread.h" #include "common/rs_common_def.h" +#include "common/rs_optional_trace.h" #include "offscreen_render/rs_offscreen_render_thread.h" #include "params/rs_canvas_drawing_render_params.h" #include "pipeline/rs_main_thread.h" @@ -228,6 +229,9 @@ void RSCanvasDrawingRenderNodeDrawable::Purge() isPurgeMatrix_ = true; curThreadInfo_.second(std::move(surface_)); surface_ = nullptr; + recordingCanvas_ = nullptr; + image_ = nullptr; + canvas_ = nullptr; } #endif RSRenderNodeDrawableAdapter::Purge(); @@ -252,30 +256,42 @@ void RSCanvasDrawingRenderNodeDrawable::PostPlaybackInCorrespondThread() { auto canvasDrawingPtr = shared_from_this(); pid_t threadId = threadId_; + RS_OPTIONAL_TRACE_NAME_FMT("post playback task node[%llu]", GetId()); auto task = [this, canvasDrawingPtr, threadId]() { std::unique_lock lock(drawableMutex_); // default in unirenderthread - if (!renderParams_ || renderParams_->GetCanvasDrawingSurfaceChanged()) { + if (!IsNeedDraw()) { + return; + } + + if (!renderParams_) { + RS_LOGE("PostPlaybackInCorrespondThread NodeId[%{public}" PRIu64 "] renderParams null", GetId()); return; } if (threadId != threadId_) { - RS_LOGE("RSCanvasDrawingRenderNodeDrawable::PostPlayback ThreadId Error NodeId[%{public}" PRIu64 "]," + RS_LOGE("PostPlaybackInCorrespondThread ThreadId Error NodeId[%{public}" PRIu64 "]," "threadId[%{public}d], threadId_[%{public}d]", GetId(), threadId, threadId_.load()); return; } auto surfaceParams = renderParams_->GetCanvasDrawingSurfaceParams(); if (surfaceParams.width == 0 || surfaceParams.height == 0) { - RS_LOGE("RSCanvasDrawingRenderNodeDrawable::PostPlayback Area Error NodeId[%{public}" PRIu64 "]," + RS_LOGE("PostPlaybackInCorrespondThread Area Error NodeId[%{public}" PRIu64 "]," "width[%{public}d], height[%{public}d]", GetId(), surfaceParams.width, surfaceParams.height); SetNeedDraw(false); return; } + if (renderParams_->GetCanvasDrawingSurfaceChanged()) { + ResetSurface(); + RS_LOGI("PostPlaybackInCorrespondThread NodeId[%{public}" PRIu64 "] SurfaceChanged Reset Surface", GetId()); + renderParams_->SetCanvasDrawingSurfaceChanged(false); + } + if (!surface_ || !canvas_) { if (!ResetSurfaceforPlayback(surfaceParams.width, surfaceParams.height)) { - RS_LOGE("RSCanvasDrawingRenderNodeDrawable::PostPlayback Reset Surface Error NodeId[%{public}" PRIu64 + RS_LOGE("PostPlaybackInCorrespondThread Reset Surface Error NodeId[%{public}" PRIu64 "], width[%{public}d], height[%{public}d]", GetId(), surfaceParams.width, surfaceParams.height); return; } @@ -288,6 +304,8 @@ void RSCanvasDrawingRenderNodeDrawable::PostPlaybackInCorrespondThread() }; SetSurfaceClearFunc({ threadIdx, clearFunc }, threadId); } + RS_OPTIONAL_TRACE_NAME_FMT("PostPlaybackInCorrespondThread NodeId[%llu]", GetId()); + RS_LOGI("CanvasDrawing PostPlayback NodeId[%{public}" PRIu64 "] finish draw", GetId()); auto rect = GetRenderParams()->GetBounds(); DrawContent(*canvas_, rect); SetNeedDraw(false); @@ -465,8 +483,9 @@ void RSCanvasDrawingRenderNodeDrawable::ProcessCPURenderInBackgroundThread(std:: void RSCanvasDrawingRenderNodeDrawable::ResetSurface() { + RS_LOGI("RSCanvasDrawingRenderNodeDrawable::ResetSurface NodeId[%{public}" PRIu64 "] ResetSurface", GetId()); if (surface_ && surface_->GetImageInfo().GetWidth() > EDGE_WIDTH_LIMIT) { - RS_LOGE("RSCanvasDrawingRenderNodeDrawable::ResetSurface id:%{public}" PRIu64 "", nodeId_); + RS_LOGE("RSCanvasDrawingRenderNodeDrawable::ResetSurface id:%{public}" PRIu64 "]", nodeId_); } #ifdef RS_ENABLE_VK if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || @@ -660,6 +679,36 @@ void RSCanvasDrawingRenderNodeDrawable::DrawCaptureImage(RSPaintFilterCanvas& ca #endif } +#ifdef RS_ENABLE_VK +bool RSCanvasDrawingRenderNodeDrawable::ReleaseSurfaceVk(int width, int height) +{ + if (!backendTexture_.IsValid() || !backendTexture_.GetTextureInfo().GetVKTextureInfo()) { + backendTexture_ = RSUniRenderUtil::MakeBackendTexture(width, height); + if (!backendTexture_.IsValid()) { + if ((RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || + RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) && + (vulkanCleanupHelper_ && isPurge_)) { + vulkanCleanupHelper_->UnRef(); + isPurge_ = false; + } + surface_ = nullptr; + recordingCanvas_ = nullptr; + image_ = nullptr; + canvas_ = nullptr; + backendTexture_ = {}; + if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || + RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) { + vulkanCleanupHelper_ = nullptr; + } + RS_LOGE("RSCanvasDrawingRenderNodeDrawable::ResetSurfaceForVK size too big [%{public}d, %{public}d] failed", + width, height); + return false; + } + } + return true; +} +#endif + bool RSCanvasDrawingRenderNodeDrawable::ResetSurfaceForVK(int width, int height, RSPaintFilterCanvas& canvas) { Drawing::ImageInfo info = @@ -674,30 +723,8 @@ bool RSCanvasDrawingRenderNodeDrawable::ResetSurfaceForVK(int width, int height, isGpuSurface_ = false; surface_ = Drawing::Surface::MakeRaster(info); } else { - if (!backendTexture_.IsValid() || !backendTexture_.GetTextureInfo().GetVKTextureInfo()) { - backendTexture_ = RSUniRenderUtil::MakeBackendTexture(width, height); - if (!backendTexture_.IsValid()) { - if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || - RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) { - if (vulkanCleanupHelper_ && isPurge_) { - vulkanCleanupHelper_->UnRef(); - isPurge_ = false; - } - } - surface_ = nullptr; - recordingCanvas_ = nullptr; - image_ = nullptr; - canvas_ = nullptr; - backendTexture_ = {}; - if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || - RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) { - vulkanCleanupHelper_ = nullptr; - } - RS_LOGE( - "RSCanvasDrawingRenderNodeDrawable::ResetSurfaceForVK size too big [%{public}d, %{public}d] failed", - width, height); - return false; - } + if (!ReleaseSurfaceVk(width, height)) { + return false; } auto vkTextureInfo = backendTexture_.GetTextureInfo().GetVKTextureInfo(); if (vulkanCleanupHelper_ == nullptr) { @@ -798,12 +825,12 @@ bool RSCanvasDrawingRenderNodeDrawable::GetCurrentContext(std::shared_ptr& gpuContext) { Drawing::ImageInfo info = Drawing::ImageInfo { width, height, Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL }; +#if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)) surface_ = Drawing::Surface::MakeRenderTarget(gpuContext.get(), false, info); if (!surface_) { isGpuSurface_ = false; @@ -816,41 +843,22 @@ bool RSCanvasDrawingRenderNodeDrawable::GpuContextResetGL( canvas_ = std::make_unique(recordingCanvas_.get()); return true; } +#else + surface_ = Drawing::Surface::MakeRaster(info); +#endif return true; } -#endif -#if defined(RS_ENABLE_VK) -bool RSCanvasDrawingRenderNodeDrawable::GpuContextResetVk( +bool RSCanvasDrawingRenderNodeDrawable::GpuContextResetVK( int width, int height, std::shared_ptr& gpuContext) { Drawing::ImageInfo info = Drawing::ImageInfo { width, height, Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL }; bool isNewCreate = false; - if (!backendTexture_.IsValid() || !backendTexture_.GetTextureInfo().GetVKTextureInfo()) { - backendTexture_ = RSUniRenderUtil::MakeBackendTexture(width, height); - if (!backendTexture_.IsValid()) { - if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || - RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) { - if (vulkanCleanupHelper_ && isPurge_) { - vulkanCleanupHelper_->UnRef(); - isPurge_ = false; - } - } - surface_ = nullptr; - recordingCanvas_ = nullptr; - image_ = nullptr; - canvas_ = nullptr; - backendTexture_ = {}; - if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || - RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) { - vulkanCleanupHelper_ = nullptr; - } - RS_LOGE("RSCanvasDrawingRenderNodeDrawable::VK backendTexture invalid, nodeId[%{public}" PRIu64 "]", - GetId()); - return false; - } +#if defined(RS_ENABLE_VK) + if (!ReleaseSurfaceVk(width, height)) { + return false; } auto vkTextureInfo = backendTexture_.GetTextureInfo().GetVKTextureInfo(); if (vulkanCleanupHelper_ == nullptr) { @@ -874,14 +882,17 @@ bool RSCanvasDrawingRenderNodeDrawable::GpuContextResetVk( return true; } return true; -} +#else + surface_ = Drawing::Surface::MakeRaster(info); #endif + return true; +} bool RSCanvasDrawingRenderNodeDrawable::ResetSurfaceforPlayback(int width, int height) { Drawing::ImageInfo info = Drawing::ImageInfo { width, height, Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL }; - + RS_LOGI("RSCanvasDrawingRenderNodeDrawable::ResetSurfaceforPlayback NodeId[%{public}" PRIu64 "]", GetId()); std::shared_ptr gpuContext; if (canvas_ == nullptr) { if (!GetCurrentContext(gpuContext)) { @@ -897,25 +908,23 @@ bool RSCanvasDrawingRenderNodeDrawable::ResetSurfaceforPlayback(int width, int h isGpuSurface_ = false; surface_ = Drawing::Surface::MakeRaster(info); } else { -#if defined(RS_ENABLE_GL) - if (!GpuContextResetGL(width, height, gpuContext)) { - return false; + if (RSSystemProperties::GetGpuApiType() == GpuApiType::OPENGL) { + if (!GpuContextResetGL(width, height, gpuContext)) { + return false; + } + if (canvas_) { + return true; + } } - if (canvas_) { - return true; + if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN || + RSSystemProperties::GetGpuApiType() == GpuApiType::DDGR) { + if (!GpuContextResetVK(width, height, gpuContext)) { + return false; + } + if (canvas_) { + return true; + } } -#else -#if defined(RS_ENABLE_VK) - if (!GpuContextResetVk(width, height, gpuContext)) { - return false; - } - if (canvas_) { - return true; - } -#else - surface_ = Drawing::Surface::MakeRaster(info); -#endif -#endif } if (!surface_) { diff --git a/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.h b/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.h index 58ae207753..e3aa09f425 100755 --- a/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.h +++ b/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.h @@ -72,11 +72,10 @@ private: void DrawRenderContent(Drawing::Canvas& canvas, const Drawing::Rect& rect); bool ResetSurfaceForGL(int width, int height, RSPaintFilterCanvas& canvas); bool ResetSurfaceForVK(int width, int height, RSPaintFilterCanvas& canvas); -#if defined(RS_ENABLE_GL) bool GpuContextResetGL(int width, int height, std::shared_ptr& gpuContext); -#endif -#if defined(RS_ENABLE_VK) - bool GpuContextResetVk(int width, int height, std::shared_ptr& gpuContext); + bool GpuContextResetVK(int width, int height, std::shared_ptr& gpuContext); +#ifdef RS_ENABLE_VK + bool ReleaseSurfaceVk(int width, int height); #endif bool ResetSurfaceforPlayback(int width, int height); bool GetCurrentContext(std::shared_ptr& grContext); 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 6366b7438c..14d1dc8998 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp @@ -1187,7 +1187,7 @@ void RSMainThread::ProcessCommandForUniRender() if (canvasDrawingNode == nullptr) { return; } - if (canvasDrawingNode->IsNeedProcess() && !canvasDrawingNode->IsOnTheTree()) { + if (canvasDrawingNode->IsNeedProcess()) { auto drawableNode = DrawableV2::RSRenderNodeDrawableAdapter::OnGenerate(canvasDrawingNode); if (!drawableNode) { RS_LOGE("RSMainThread::ProcessCommandForUniRender GetCanvasDrawable Failed NodeId[%{public}" PRIu64 "]", diff --git a/rosen/modules/render_service_base/include/pipeline/rs_canvas_drawing_render_node.h b/rosen/modules/render_service_base/include/pipeline/rs_canvas_drawing_render_node.h index d9def01856..641089ae2a 100644 --- a/rosen/modules/render_service_base/include/pipeline/rs_canvas_drawing_render_node.h +++ b/rosen/modules/render_service_base/include/pipeline/rs_canvas_drawing_render_node.h @@ -109,7 +109,6 @@ private: // Used in uni render thread. uint32_t drawingNodeRenderID = UNI_MAIN_THREAD_INDEX; - uint32_t playbackNotOnTreeCmdSize_ = 0; friend class RSCanvasDrawingNodeCommandHelper; }; diff --git a/rosen/modules/render_service_base/src/pipeline/rs_canvas_drawing_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_canvas_drawing_render_node.cpp index 6bd565b9f1..8c7fa08877 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_canvas_drawing_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_canvas_drawing_render_node.cpp @@ -208,9 +208,11 @@ bool RSCanvasDrawingRenderNode::IsNeedProcess() const void RSCanvasDrawingRenderNode::ContentStyleSlotUpdate() { - //update content_style when node not on tree, need check (waitSync_ false, not on tree, surface not changed) + // update content_style when node not on tree, need check (waitSync_ false, not on tree, never on tree + // not texture exportnode, unirender mode) + // if canvas drawing node never on tree, should not update, it will lost renderParams->localDrawRect_ if (IsWaitSync() || IsOnTheTree() || isNeverOnTree_ || !stagingRenderParams_ || - stagingRenderParams_->GetCanvasDrawingSurfaceChanged() || RSUniRenderJudgement::IsUniRender()) { + !RSUniRenderJudgement::IsUniRender() || GetIsTextureExportNode()) { return; } @@ -225,15 +227,31 @@ void RSCanvasDrawingRenderNode::ContentStyleSlotUpdate() return; } - playbackNotOnTreeCmdSize_ += drawCmdLists_[RSModifierType::CONTENT_STYLE].size(); - RS_OPTIONAL_TRACE_NAME_FMT("node[%llu], NotOnTreeDraw Cmdlist Size[%lu]", GetId(), playbackNotOnTreeCmdSize_); + //only update content_style dirtyType + auto savedirtyTypes = dirtyTypes_; + dirtyTypes_.reset(); + dirtyTypes_.set(static_cast(RSModifierType::CONTENT_STYLE), true); UpdateDrawableVecV2(); - // Clear node some resource - ClearResource(); - // update state - dirtyTypes_.reset(); + if (!IsWaitSync()) { + RS_LOGE("RSCanvasDrawingRenderNode::ContentStyleSlotUpdate NodeId[%{public}" PRIu64 + "] UpdateDrawableVecV2 failed, dirtySlots empty", GetId()); + return; + } + + RS_LOGI("RSCanvasDrawingRenderNode::ContentStyleSlotUpdate NodeId[%{public}" PRIu64 "]", GetId()); + RS_OPTIONAL_TRACE_NAME_FMT("canvas drawing node[%llu] ContentStyleSlotUpdate", GetId()); + + // clear content_style drawcmdlist + std::lock_guard lock(drawCmdListsMutex_); + auto contentCmdList = drawCmdLists_.find(RSModifierType::CONTENT_STYLE); + if (contentCmdList != drawCmdLists_.end()) { + contentCmdList->second.clear(); + } + savedirtyTypes.set(static_cast(RSModifierType::CONTENT_STYLE), false); + dirtyTypes_ = savedirtyTypes; + AddToPendingSyncList(); } @@ -495,10 +513,12 @@ void RSCanvasDrawingRenderNode::CheckDrawCmdListSize(RSModifierType type) { bool overflow = drawCmdLists_[type].size() > DRAWCMDLIST_COUNT_LIMIT; if (overflow) { + RS_OPTIONAL_TRACE_NAME_FMT("AddDitryType id:[%llu] StateOnTheTree[%d] ModifierType[%d] ModifierCmdSize[%d]", + GetId(), type, drawCmdLists_[type].size(), IsOnTheTree()); if (overflow != lastOverflowStatus_) { RS_LOGE("AddDirtyType Out of Cmdlist Limit, This Node[%{public}" PRIu64 "] with Modifier[%{public}hd]" - " have drawcmdlist:%{public}zu", - GetId(), type, drawCmdLists_[type].size()); + " have drawcmdlist:%{public}zu, StateOnTheTree[%{public}d]", + GetId(), type, drawCmdLists_[type].size(), IsOnTheTree()); } // If such nodes are not drawn, The drawcmdlists don't clearOp during recording, As a result, there are // too many drawOp, so we need to add the limit of drawcmdlists. @@ -508,8 +528,8 @@ void RSCanvasDrawingRenderNode::CheckDrawCmdListSize(RSModifierType type) } if (drawCmdLists_[type].size() > DRAWCMDLIST_COUNT_LIMIT) { RS_LOGE("AddDirtyType Cmdlist Protect Error, This Node[%{public}" PRIu64 "] with Modifier[%{public}hd]" - " have drawcmdlist:%{public}zu", - GetId(), type, drawCmdLists_[type].size()); + " have drawcmdlist:%{public}zu, StateOnTheTree[%{public}d]", + GetId(), type, drawCmdLists_[type].size(), IsOnTheTree()); } } lastOverflowStatus_ = overflow; @@ -571,7 +591,7 @@ const std::map>& RSCanvasDraw void RSCanvasDrawingRenderNode::ClearResource() { - if (RSUniRenderJudgement::IsUniRender()) { + if (RSUniRenderJudgement::IsUniRender() && !GetIsTextureExportNode()) { std::lock_guard lock(drawCmdListsMutex_); drawCmdLists_.clear(); } diff --git a/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp index 1df1d9400e..e59956695d 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_render_node.cpp @@ -4270,7 +4270,9 @@ void RSRenderNode::OnSync() foregroundFilterInteractWithDirty_ = false; // Reset Sync Flag - renderDrawable_->SetNeedDraw(true); + if (waitSync_) { + renderDrawable_->SetNeedDraw(true); + } waitSync_ = false; lastFrameSynced_ = !isLeashWindowPartialSkip; 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 9bd3850920..2ce88114e9 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 @@ -27,6 +27,7 @@ #include "pipeline/rs_render_engine.h" #include "pipeline/rs_root_render_node.h" #include "pipeline/rs_uni_render_engine.h" +#include "pipeline/rs_canvas_drawing_render_node.h" #include "platform/common/rs_innovation.h" #include "platform/common/rs_system_properties.h" #if defined(ACCESSIBILITY_ENABLE) @@ -781,6 +782,13 @@ HWTEST_F(RSMainThreadTest, ProcessCommandForUniRender, TestSize.Level1) mainThread->effectiveTransactionDataIndexMap_[0].second.emplace_back(std::move(data)); // empty data mainThread->effectiveTransactionDataIndexMap_[0].second.emplace_back(nullptr); + + NodeId nodeId =1; + std::weak_ptr context = {}; + auto rsCanvasDrawingRenderNode = std::make_shared(nodeId, context); + auto drawableNode = DrawableV2::RSRenderNodeDrawableAdapter::OnGenerate(rsCanvasDrawingRenderNode); + drawableNode->SetNeedDraw(true); + mainThread_->context_->nodeMap.RegisterRenderNode(rsCanvasDrawingRenderNode); mainThread->ProcessCommandForUniRender(); } @@ -4003,48 +4011,15 @@ HWTEST_F(RSMainThreadTest, OnCommitDumpClientNodeTree, TestSize.Level2) } /** - * @tc.name: CheckIsAihdrSurface - * @tc.desc: Test CheckIsAihdrSurface + * @tc.name: TraverseCanvasDrawingNodesNotOnTree + * @tc.desc: test TraverseCanvasDrawingNodesNotOnTree * @tc.type: FUNC - * @tc.require: + * @tc.require: issueIB56EL */ -#ifdef USE_VIDEO_PROCESSING_ENGINE -HWTEST_F(RSMainThreadTest, CheckIsAihdrSurface, TestSize.Level1) -{ - auto mainThread = RSMainThread::Instance(); - mainThread->context_->activeNodesInRoot_.clear(); - // valid nodeid - NodeId id = 1; - auto node = std::make_shared(id, mainThread->context_); - ASSERT_NE(node, nullptr); - const auto& surfaceBuffer = node->GetRSSurfaceHandler()->GetBuffer(); - if (surfaceBuffer == nullptr) { - return; - } - uint32_t hdrType = HDI::Display::Graphic::Common::V2_1::CM_VIDEO_AI_HDR; - std::vector metadataType; - metadataType.resize(sizeof(hdrType)); - memcpy_s(metadataType.data(), metadataType.size(), &hdrType, sizeof(hdrType)); - surfaceBuffer->SetMetadata(Media::VideoProcessingEngine::ATTRKEY_HDR_METADATA_TYPE, - metadataType); - ASSERT_EQ(mainThread->CheckIsAihdrSurface(*node), true); -} -#endif - -/** - * @tc.name: RenderServiceAllNodeDump01 - * @tc.desc: RenderServiceAllNodeDump Test - * @tc.type: FUNC - * @tc.require: issueIB57QP - */ -HWTEST_F(RSMainThreadTest, RenderServiceAllNodeDump01, TestSize.Level1) +HWTEST_F(RSMainThreadTest, TraverseCanvasDrawingNodesNotOnTree, TestSize.Level2) { auto mainThread = RSMainThread::Instance(); ASSERT_NE(mainThread, nullptr); - NodeId id = 1; - MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE}; - MemoryTrack::Instance().AddNodeRecord(id, info); - DfxString log; - mainThread->RenderServiceAllNodeDump(log); + mainThread->TraverseCanvasDrawingNodesNotOnTree(); } } // namespace OHOS::Rosen From 380187059dd0ed1d8edbd66f4c8f8210596eb3b5 Mon Sep 17 00:00:00 2001 From: redermens Date: Thu, 21 Nov 2024 10:55:24 +0800 Subject: [PATCH 2/2] check contentStyle condition Signed-off-by: redermens --- ...rs_canvas_drawing_render_node_drawable.cpp | 15 ++---- .../rs_canvas_drawing_render_node_drawable.h | 2 +- .../pipeline/rs_canvas_drawing_render_node.h | 2 +- .../rs_canvas_drawing_render_node.cpp | 7 ++- .../unittest/pipeline/rs_main_thread_test.cpp | 48 ++++++++++++++++++- 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.cpp b/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.cpp index fcebea2ccc..798b381207 100755 --- a/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.cpp +++ b/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.cpp @@ -275,20 +275,13 @@ void RSCanvasDrawingRenderNodeDrawable::PostPlaybackInCorrespondThread() return; } - auto surfaceParams = renderParams_->GetCanvasDrawingSurfaceParams(); - if (surfaceParams.width == 0 || surfaceParams.height == 0) { - RS_LOGE("PostPlaybackInCorrespondThread Area Error NodeId[%{public}" PRIu64 "]," - "width[%{public}d], height[%{public}d]", GetId(), surfaceParams.width, surfaceParams.height); - SetNeedDraw(false); - return; - } - if (renderParams_->GetCanvasDrawingSurfaceChanged()) { ResetSurface(); RS_LOGI("PostPlaybackInCorrespondThread NodeId[%{public}" PRIu64 "] SurfaceChanged Reset Surface", GetId()); renderParams_->SetCanvasDrawingSurfaceChanged(false); } + auto surfaceParams = renderParams_->GetCanvasDrawingSurfaceParams(); if (!surface_ || !canvas_) { if (!ResetSurfaceforPlayback(surfaceParams.width, surfaceParams.height)) { RS_LOGE("PostPlaybackInCorrespondThread Reset Surface Error NodeId[%{public}" PRIu64 @@ -680,7 +673,7 @@ void RSCanvasDrawingRenderNodeDrawable::DrawCaptureImage(RSPaintFilterCanvas& ca } #ifdef RS_ENABLE_VK -bool RSCanvasDrawingRenderNodeDrawable::ReleaseSurfaceVk(int width, int height) +bool RSCanvasDrawingRenderNodeDrawable::ReleaseSurfaceVK(int width, int height) { if (!backendTexture_.IsValid() || !backendTexture_.GetTextureInfo().GetVKTextureInfo()) { backendTexture_ = RSUniRenderUtil::MakeBackendTexture(width, height); @@ -723,7 +716,7 @@ bool RSCanvasDrawingRenderNodeDrawable::ResetSurfaceForVK(int width, int height, isGpuSurface_ = false; surface_ = Drawing::Surface::MakeRaster(info); } else { - if (!ReleaseSurfaceVk(width, height)) { + if (!ReleaseSurfaceVK(width, height)) { return false; } auto vkTextureInfo = backendTexture_.GetTextureInfo().GetVKTextureInfo(); @@ -857,7 +850,7 @@ bool RSCanvasDrawingRenderNodeDrawable::GpuContextResetVK( bool isNewCreate = false; #if defined(RS_ENABLE_VK) - if (!ReleaseSurfaceVk(width, height)) { + if (!ReleaseSurfaceVK(width, height)) { return false; } auto vkTextureInfo = backendTexture_.GetTextureInfo().GetVKTextureInfo(); diff --git a/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.h b/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.h index e3aa09f425..4e971b4bdf 100755 --- a/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.h +++ b/rosen/modules/render_service/core/drawable/rs_canvas_drawing_render_node_drawable.h @@ -75,7 +75,7 @@ private: bool GpuContextResetGL(int width, int height, std::shared_ptr& gpuContext); bool GpuContextResetVK(int width, int height, std::shared_ptr& gpuContext); #ifdef RS_ENABLE_VK - bool ReleaseSurfaceVk(int width, int height); + bool ReleaseSurfaceVK(int width, int height); #endif bool ResetSurfaceforPlayback(int width, int height); bool GetCurrentContext(std::shared_ptr& grContext); diff --git a/rosen/modules/render_service_base/include/pipeline/rs_canvas_drawing_render_node.h b/rosen/modules/render_service_base/include/pipeline/rs_canvas_drawing_render_node.h index 641089ae2a..e7c77f0316 100644 --- a/rosen/modules/render_service_base/include/pipeline/rs_canvas_drawing_render_node.h +++ b/rosen/modules/render_service_base/include/pipeline/rs_canvas_drawing_render_node.h @@ -80,7 +80,7 @@ private: explicit RSCanvasDrawingRenderNode( NodeId id, const std::weak_ptr& context = {}, bool isTextureExportNode = false); void ApplyDrawCmdModifier(RSModifierContext& context, RSModifierType type); - void CheckDrawCmdListSize(RSModifierType type); + void CheckDrawCmdListSize(RSModifierType type); bool ResetSurface(int width, int height, RSPaintFilterCanvas& canvas); bool GetSizeFromDrawCmdModifiers(int& width, int& height); bool IsNeedResetSurface() const; diff --git a/rosen/modules/render_service_base/src/pipeline/rs_canvas_drawing_render_node.cpp b/rosen/modules/render_service_base/src/pipeline/rs_canvas_drawing_render_node.cpp index 4b43f7cc7a..933da3b03e 100644 --- a/rosen/modules/render_service_base/src/pipeline/rs_canvas_drawing_render_node.cpp +++ b/rosen/modules/render_service_base/src/pipeline/rs_canvas_drawing_render_node.cpp @@ -213,7 +213,12 @@ void RSCanvasDrawingRenderNode::ContentStyleSlotUpdate() // if canvas drawing node never on tree, should not update, it will lost renderParams->localDrawRect_ #ifdef RS_ENABLE_GPU if (IsWaitSync() || IsOnTheTree() || isNeverOnTree_ || !stagingRenderParams_ || - RSUniRenderJudgement::IsUniRender()) { + !RSUniRenderJudgement::IsUniRender() || GetIsTextureExportNode()) { + return; + } +#else + if (IsWaitSync() || IsOnTheTree() || isNeverOnTree_ || !stagingRenderParams_ || + !RSUniRenderJudgement::IsUniRender() || GetIsTextureExportNode()) { return; } #endif 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 4d24b3e880..920daedc85 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 @@ -788,7 +788,7 @@ HWTEST_F(RSMainThreadTest, ProcessCommandForUniRender, TestSize.Level1) auto rsCanvasDrawingRenderNode = std::make_shared(nodeId, context); auto drawableNode = DrawableV2::RSRenderNodeDrawableAdapter::OnGenerate(rsCanvasDrawingRenderNode); drawableNode->SetNeedDraw(true); - mainThread_->context_->nodeMap.RegisterRenderNode(rsCanvasDrawingRenderNode); + mainThread->context_->nodeMap.RegisterRenderNode(rsCanvasDrawingRenderNode); mainThread->ProcessCommandForUniRender(); } @@ -4023,6 +4023,52 @@ HWTEST_F(RSMainThreadTest, TraverseCanvasDrawingNodesNotOnTree, TestSize.Level2) mainThread->TraverseCanvasDrawingNodesNotOnTree(); } +/** + * @tc.name: CheckIsAihdrSurface + * @tc.desc: Test CheckIsAihdrSurface + * @tc.type: FUNC + * @tc.require: + */ +#ifdef USE_VIDEO_PROCESSING_ENGINE +HWTEST_F(RSMainThreadTest, CheckIsAihdrSurface, TestSize.Level1) +{ + auto mainThread = RSMainThread::Instance(); + mainThread->context_->activeNodesInRoot_.clear(); + // valid nodeid + NodeId id = 1; + auto node = std::make_shared(id, mainThread->context_); + ASSERT_NE(node, nullptr); + const auto& surfaceBuffer = node->GetRSSurfaceHandler()->GetBuffer(); + if (surfaceBuffer == nullptr) { + return; + } + uint32_t hdrType = HDI::Display::Graphic::Common::V2_1::CM_VIDEO_AI_HDR; + std::vector metadataType; + metadataType.resize(sizeof(hdrType)); + memcpy_s(metadataType.data(), metadataType.size(), &hdrType, sizeof(hdrType)); + surfaceBuffer->SetMetadata(Media::VideoProcessingEngine::ATTRKEY_HDR_METADATA_TYPE, + metadataType); + ASSERT_EQ(mainThread->CheckIsAihdrSurface(*node), true); +} +#endif + +/** + * @tc.name: RenderServiceAllNodeDump01 + * @tc.desc: RenderServiceAllNodeDump Test + * @tc.type: FUNC + * @tc.require: issueIB57QP + */ +HWTEST_F(RSMainThreadTest, RenderServiceAllNodeDump01, TestSize.Level1) +{ + auto mainThread = RSMainThread::Instance(); + ASSERT_NE(mainThread, nullptr); + NodeId id = 1; + MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE}; + MemoryTrack::Instance().AddNodeRecord(id, info); + DfxString log; + mainThread->RenderServiceAllNodeDump(log); +} + /** * @tc.name: IsOcclusionNodesNeedSync001 * @tc.desc: test IsOcclusionNodesNeedSync001