• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "pipeline/rs_canvas_drawing_render_node.h"
17 
18 #include <memory>
19 
20 #include "include/core/SkCanvas.h"
21 #include "src/image/SkImage_Base.h"
22 #ifdef NEW_SKIA
23 #include "include/gpu/GrBackendSurface.h"
24 #include "include/gpu/GrDirectContext.h"
25 #endif
26 
27 #include "rs_trace.h"
28 
29 #include "common/rs_background_thread.h"
30 #include "common/rs_common_def.h"
31 #include "common/rs_obj_abs_geometry.h"
32 #include "params/rs_canvas_drawing_render_params.h"
33 #include "pipeline/rs_context.h"
34 #include "pipeline/rs_paint_filter_canvas.h"
35 #include "pipeline/rs_recording_canvas.h"
36 #include "pipeline/rs_task_dispatcher.h"
37 #include "pipeline/sk_resource_manager.h"
38 #include "platform/common/rs_log.h"
39 #include "property/rs_properties_painter.h"
40 #include "visitor/rs_node_visitor.h"
41 
42 namespace OHOS {
43 namespace Rosen {
44 static std::mutex drawingMutex_;
45 namespace {
46 constexpr uint32_t DRAWCMDLIST_COUNT_LIMIT = 50;
47 constexpr uint32_t DRAWCMDLIST_OPSIZE_COUNT_LIMIT = 50000;
48 }
RSCanvasDrawingRenderNode(NodeId id,const std::weak_ptr<RSContext> & context,bool isTextureExportNode)49 RSCanvasDrawingRenderNode::RSCanvasDrawingRenderNode(
50     NodeId id, const std::weak_ptr<RSContext>& context, bool isTextureExportNode)
51     : RSCanvasRenderNode(id, context, isTextureExportNode)
52 {
53     MemorySnapshot::Instance().AddCpuMemory(ExtractPid(id), sizeof(*this) - sizeof(RSCanvasRenderNode));
54 }
55 
~RSCanvasDrawingRenderNode()56 RSCanvasDrawingRenderNode::~RSCanvasDrawingRenderNode()
57 {
58 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
59     if (preThreadInfo_.second && surface_) {
60         preThreadInfo_.second(std::move(surface_));
61     }
62 #endif
63     MemorySnapshot::Instance().RemoveCpuMemory(ExtractPid(GetId()), sizeof(*this) - sizeof(RSCanvasRenderNode));
64 }
65 
InitRenderContent()66 void RSCanvasDrawingRenderNode::InitRenderContent()
67 {
68     drawingNodeRenderID = UNI_RENDER_THREAD_INDEX;
69 }
70 
71 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
ResetSurfaceWithTexture(int width,int height,RSPaintFilterCanvas & canvas)72 bool RSCanvasDrawingRenderNode::ResetSurfaceWithTexture(int width, int height, RSPaintFilterCanvas& canvas)
73 {
74     if (canvas_ == nullptr) {
75         RS_LOGE("canvas_ is nullptr");
76         return false;
77     }
78     auto preMatrix = canvas_->GetTotalMatrix();
79     auto preSurface = surface_;
80     if (!ResetSurface(width, height, canvas)) {
81         return false;
82     }
83     auto image = preSurface->GetImageSnapshot();
84     if (!image) {
85         return false;
86     }
87     Drawing::TextureOrigin origin = RSSystemProperties::GetGpuApiType() == GpuApiType::OPENGL
88         ? Drawing::TextureOrigin::BOTTOM_LEFT : Drawing::TextureOrigin::TOP_LEFT;
89     auto sharedBackendTexture = image->GetBackendTexture(false, &origin);
90     if (!sharedBackendTexture.IsValid()) {
91         RS_LOGE("RSCanvasDrawingRenderNode::ResetSurfaceWithTexture sharedBackendTexture is nullptr");
92         return false;
93     }
94     Drawing::BitmapFormat bitmapFormat = { image->GetColorType(), image->GetAlphaType() };
95     auto sharedTexture = std::make_shared<Drawing::Image>();
96     auto context = canvas.GetGPUContext();
97     if (!context || !sharedTexture->BuildFromTexture(*context, sharedBackendTexture.GetTextureInfo(),
98         origin, bitmapFormat, nullptr, SKResourceManager::DeleteSharedTextureContext,
99         new SharedTextureContext(image))) {
100         RS_LOGE("RSCanvasDrawingRenderNode::ResetSurfaceWithTexture sharedTexture is nullptr");
101         return false;
102     }
103     if (RSSystemProperties::GetRecordingEnabled()) {
104         if (sharedTexture->IsTextureBacked()) {
105             RS_LOGI("RSCanvasDrawingRenderNode::ResetSurfaceWithTexture sharedTexture from texture to raster image");
106             sharedTexture = sharedTexture->MakeRasterImage();
107             if (!sharedTexture) {
108                 RS_LOGE("RSCanvasDrawingRenderNode::ResetSurfaceWithTexture: MakeRasterImage failed");
109                 return false;
110             }
111         }
112     }
113     canvas_->DrawImage(*sharedTexture, 0.f, 0.f, Drawing::SamplingOptions());
114     if (preThreadInfo_.second && preSurface) {
115         preThreadInfo_.second(std::move(preSurface));
116     }
117     preThreadInfo_ = curThreadInfo_;
118     canvas_->SetMatrix(preMatrix);
119     canvas_->Flush();
120     return true;
121 }
122 #endif
123 
ProcessRenderContents(RSPaintFilterCanvas & canvas)124 void RSCanvasDrawingRenderNode::ProcessRenderContents(RSPaintFilterCanvas& canvas)
125 {
126     int width = 0;
127     int height = 0;
128     std::lock_guard<std::mutex> lockTask(taskMutex_);
129     if (!GetSizeFromDrawCmdModifiers(width, height)) {
130         return;
131     }
132 
133     if (IsNeedResetSurface()) {
134 #if defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)
135         if (preThreadInfo_.second && surface_) {
136             preThreadInfo_.second(std::move(surface_));
137         }
138         preThreadInfo_ = curThreadInfo_;
139 #endif
140         if (!ResetSurface(width, height, canvas)) {
141             return;
142         }
143 #if defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)
144     } else if ((isGpuSurface_) && (preThreadInfo_.first != curThreadInfo_.first)) {
145         if (!ResetSurfaceWithTexture(width, height, canvas)) {
146             return;
147         }
148     }
149 #else
150     }
151 #endif
152     if (!surface_) {
153         return;
154     }
155 
156     RSModifierContext context = { GetMutableRenderProperties(), canvas_.get() };
157     ApplyDrawCmdModifier(context, RSModifierType::CONTENT_STYLE);
158     isNeedProcess_ = false;
159 
160     Rosen::Drawing::Matrix mat;
161     if (RSPropertiesPainter::GetGravityMatrix(
162             GetRenderProperties().GetFrameGravity(), GetRenderProperties().GetFrameRect(), width, height, mat)) {
163         canvas.ConcatMatrix(mat);
164     }
165     if (!recordingCanvas_) {
166         image_ = surface_->GetImageSnapshot();
167         if (image_) {
168             SKResourceManager::Instance().HoldResource(image_);
169         }
170     } else {
171         auto cmds = recordingCanvas_->GetDrawCmdList();
172         if (cmds && !cmds->IsEmpty()) {
173             recordingCanvas_ = std::make_shared<ExtendRecordingCanvas>(width, height, false);
174             canvas_ = std::make_unique<RSPaintFilterCanvas>(recordingCanvas_.get());
175         }
176     }
177     std::lock_guard<std::mutex> lock(imageMutex_);
178     if (!image_) {
179         return;
180     }
181     auto samplingOptions = Drawing::SamplingOptions(Drawing::FilterMode::LINEAR, Drawing::MipmapMode::LINEAR);
182     Drawing::Paint paint;
183     paint.SetStyle(Drawing::Paint::PaintStyle::PAINT_FILL);
184     canvas.AttachPaint(paint);
185     if (canvas.GetRecordingState()) {
186         auto cpuImage = image_->MakeRasterImage();
187         if (!cpuImage) {
188             RS_LOGE("RSCanvasDrawingRenderNode::ProcessRenderContents: MakeRasterImage failed");
189             canvas.DetachPaint();
190             return;
191         }
192         canvas.DrawImage(*cpuImage, 0.f, 0.f, samplingOptions);
193     } else {
194         canvas.DrawImage(*image_, 0.f, 0.f, samplingOptions);
195     }
196     canvas.DetachPaint();
197 }
198 
IsNeedProcess() const199 bool RSCanvasDrawingRenderNode::IsNeedProcess() const
200 {
201     if (!renderDrawable_ || !(renderDrawable_->GetRenderParams())) {
202         return false;
203     }
204     return renderDrawable_->GetRenderParams()->IsNeedProcess();
205 }
206 
SetNeedProcess(bool needProcess)207 void RSCanvasDrawingRenderNode::SetNeedProcess(bool needProcess)
208 {
209     auto stagingCanvasDrawingParams = static_cast<RSCanvasDrawingRenderParams*>(stagingRenderParams_.get());
210     if (stagingCanvasDrawingParams) {
211         stagingCanvasDrawingParams->SetNeedProcess(needProcess);
212         if (stagingRenderParams_->NeedSync()) {
213             AddToPendingSyncList();
214         }
215     }
216     isNeedProcess_ = needProcess;
217 }
218 
PlaybackInCorrespondThread()219 void RSCanvasDrawingRenderNode::PlaybackInCorrespondThread()
220 {
221     auto nodeId = GetId();
222     auto ctx = GetContext().lock();
223     if (ctx == nullptr) {
224         return;
225     }
226     auto task = [nodeId, ctx, this]() {
227         std::lock_guard<std::mutex> lockTask(taskMutex_);
228         auto node = ctx->GetNodeMap().GetRenderNode<RSCanvasDrawingRenderNode>(nodeId);
229         if (!node || !surface_ || !canvas_) {
230             return;
231         }
232         RSModifierContext context = { GetMutableRenderProperties(), canvas_.get() };
233         ApplyDrawCmdModifier(context, RSModifierType::CONTENT_STYLE);
234         isNeedProcess_ = false;
235     };
236     RSTaskDispatcher::GetInstance().PostTask(threadId_, task, false);
237 }
238 
ResetSurface(int width,int height,RSPaintFilterCanvas & canvas)239 bool RSCanvasDrawingRenderNode::ResetSurface(int width, int height, RSPaintFilterCanvas& canvas)
240 {
241     Drawing::ImageInfo info =
242         Drawing::ImageInfo { width, height, Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL };
243 
244 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
245 #if (defined(ROSEN_IOS))
246     surface_ = Drawing::Surface::MakeRaster(info);
247 #else
248     auto gpuContext = canvas.GetGPUContext();
249     isGpuSurface_ = true;
250     if (gpuContext == nullptr) {
251         RS_LOGD("RSCanvasDrawingRenderNode::ResetSurface: gpuContext is nullptr");
252         isGpuSurface_ = false;
253         surface_ = Drawing::Surface::MakeRaster(info);
254     } else {
255         surface_ = Drawing::Surface::MakeRenderTarget(gpuContext.get(), false, info);
256         if (!surface_) {
257             isGpuSurface_ = false;
258             surface_ = Drawing::Surface::MakeRaster(info);
259             RS_LOGW("RSCanvasDrawingRenderNode::ResetSurface [%{public}d, %{public}d] %{public}" PRIu64 "",
260                 width, height, GetId());
261             if (!surface_) {
262                 RS_LOGE("RSCanvasDrawingRenderNode::ResetSurface surface is nullptr");
263                 return false;
264             }
265             recordingCanvas_ = std::make_shared<ExtendRecordingCanvas>(width, height, false);
266             canvas_ = std::make_unique<RSPaintFilterCanvas>(recordingCanvas_.get());
267             return true;
268         }
269     }
270 #endif
271 #else
272     surface_ = Drawing::Surface::MakeRaster(info);
273 #endif
274     if (!surface_) {
275         RS_LOGE("RSCanvasDrawingRenderNode::ResetSurface surface is nullptr");
276         return false;
277     }
278     canvas_ = std::make_unique<RSPaintFilterCanvas>(surface_.get());
279     return true;
280 }
281 
ApplyDrawCmdModifier(RSModifierContext & context,RSModifierType type)282 void RSCanvasDrawingRenderNode::ApplyDrawCmdModifier(RSModifierContext& context, RSModifierType type)
283 {
284     std::lock_guard<std::mutex> lock(drawCmdListsMutex_);
285     auto it = drawCmdLists_.find(type);
286     if (it == drawCmdLists_.end() || it->second.empty()) {
287         return;
288     }
289     for (const auto& drawCmdList : it->second) {
290         drawCmdList->Playback(*context.canvas_);
291         drawCmdList->ClearOp();
292     }
293     context.canvas_->Flush();
294     it->second.clear();
295 }
296 
GetTid() const297 uint32_t RSCanvasDrawingRenderNode::GetTid() const
298 {
299     if (UNI_RENDER_THREAD_INDEX == drawingNodeRenderID) {
300         return drawingNodeRenderID;
301     }
302     return curThreadInfo_.first;
303 }
304 
GetBitmap()305 Drawing::Bitmap RSCanvasDrawingRenderNode::GetBitmap()
306 {
307     return GetBitmap(UNI_MAIN_THREAD_INDEX);
308 }
309 
WriteSkImageToPixelmap(std::shared_ptr<Drawing::Image> image,Drawing::ImageInfo info,std::shared_ptr<Media::PixelMap> pixelmap,const Drawing::Rect * rect)310 bool WriteSkImageToPixelmap(std::shared_ptr<Drawing::Image> image, Drawing::ImageInfo info,
311     std::shared_ptr<Media::PixelMap> pixelmap, const Drawing::Rect* rect)
312 {
313     return image->ReadPixels(
314         info, pixelmap->GetWritablePixels(), pixelmap->GetRowStride(), rect->GetLeft(), rect->GetTop());
315 }
316 
GetImage(const uint64_t tid)317 std::shared_ptr<Drawing::Image> RSCanvasDrawingRenderNode::GetImage(const uint64_t tid)
318 {
319     if (GetTid() != tid) {
320         RS_LOGE("RSCanvasDrawingRenderNode::GetImage: image_ used by multi threads");
321         return nullptr;
322     }
323     if (!image_) {
324         RS_LOGE("RSCanvasDrawingRenderNode::GetImage: image_ is nullptr");
325     }
326     return image_;
327 }
328 
GetBitmap(const uint64_t tid)329 Drawing::Bitmap RSCanvasDrawingRenderNode::GetBitmap(const uint64_t tid)
330 {
331     Drawing::Bitmap bitmap;
332     std::lock_guard<std::mutex> lock(drawingMutex_);
333     if (!image_) {
334         RS_LOGE("RSCanvasDrawingRenderNode::GetBitmap: image_ is nullptr");
335         return bitmap;
336     }
337     if (GetTid() != tid) {
338         RS_LOGE("RSCanvasDrawingRenderNode::GetBitmap: image_ used by multi threads");
339         return bitmap;
340     }
341     if (!image_->AsLegacyBitmap(bitmap)) {
342         RS_LOGE("RSCanvasDrawingRenderNode::GetBitmap: asLegacyBitmap failed");
343     }
344     return bitmap;
345 }
346 
GetPixelmap(std::shared_ptr<Media::PixelMap> pixelmap,const Drawing::Rect * rect,const uint64_t tid,std::shared_ptr<Drawing::DrawCmdList> drawCmdList)347 bool RSCanvasDrawingRenderNode::GetPixelmap(std::shared_ptr<Media::PixelMap> pixelmap, const Drawing::Rect* rect,
348     const uint64_t tid, std::shared_ptr<Drawing::DrawCmdList> drawCmdList)
349 {
350     std::lock_guard<std::mutex> lock(drawingMutex_);
351     if (!pixelmap || !rect) {
352         RS_LOGE("RSCanvasDrawingRenderNode::GetPixelmap: pixelmap is nullptr");
353         return false;
354     }
355 
356     if (!surface_) {
357         RS_LOGE("RSCanvasDrawingRenderNode::GetPixelmap: surface is nullptr");
358         return false;
359     }
360 
361     auto image = surface_->GetImageSnapshot();
362     if (image == nullptr) {
363         RS_LOGE("RSCanvasDrawingRenderNode::GetPixelmap: GetImageSnapshot failed");
364         return false;
365     }
366 
367     if (GetTid() != tid) {
368         RS_LOGE("RSCanvasDrawingRenderNode::GetPixelmap: surface used by multi threads");
369         return false;
370     }
371 
372     Drawing::ImageInfo info = Drawing::ImageInfo { pixelmap->GetWidth(), pixelmap->GetHeight(),
373         Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL };
374     if (!drawCmdList) {
375         if (!WriteSkImageToPixelmap(image, info, pixelmap, rect)) {
376             RS_LOGE("RSCanvasDrawingRenderNode::GetPixelmap: readPixels failed");
377             return false;
378         }
379         return true;
380     }
381     std::shared_ptr<Drawing::Surface> surface;
382     std::unique_ptr<RSPaintFilterCanvas> canvas;
383 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
384     if (!canvas_) {
385         return false;
386     }
387     auto gpuContext = canvas_->GetGPUContext();
388     if (gpuContext == nullptr) {
389         if (!WriteSkImageToPixelmap(image, info, pixelmap, rect)) {
390             RS_LOGE("RSCanvasDrawingRenderNode::GetPixelmap: readPixels failed");
391         }
392         return false;
393     } else {
394         Drawing::ImageInfo newInfo = Drawing::ImageInfo{ image->GetWidth(), image->GetHeight(),
395             Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL };
396         surface = Drawing::Surface::MakeRenderTarget(gpuContext.get(), false, newInfo);
397         if (!surface) {
398             if (!WriteSkImageToPixelmap(image, info, pixelmap, rect)) {
399                 RS_LOGE("RSCanvasDrawingRenderNode::GetPixelmap: readPixels failed");
400             }
401             return false;
402         }
403         canvas = std::make_unique<RSPaintFilterCanvas>(surface.get());
404     }
405 #else
406     if (!WriteSkImageToPixelmap(image, info, pixelmap, rect)) {
407         RS_LOGE("RSCanvasDrawingRenderNode::GetPixelmap: readPixels failed");
408     }
409     return false;
410 #endif
411     canvas->DrawImage(*image, 0, 0, Drawing::SamplingOptions());
412     drawCmdList->Playback(*canvas, rect);
413     auto pixelmapImage = surface->GetImageSnapshot();
414     if (!pixelmapImage) {
415         return false;
416     }
417     if (!WriteSkImageToPixelmap(pixelmapImage, info, pixelmap, rect)) {
418         RS_LOGE("RSCanvasDrawingRenderNode::GetPixelmap: readPixels failed");
419         return false;
420     }
421     return true;
422 }
423 
GetSizeFromDrawCmdModifiers(int & width,int & height)424 bool RSCanvasDrawingRenderNode::GetSizeFromDrawCmdModifiers(int& width, int& height)
425 {
426     auto it = GetDrawCmdModifiers().find(RSModifierType::CONTENT_STYLE);
427     if (it == GetDrawCmdModifiers().end() || it->second.empty()) {
428         return false;
429     }
430     for (const auto& modifier : it->second) {
431         auto prop = modifier->GetProperty();
432         if (auto cmd = std::static_pointer_cast<RSRenderProperty<Drawing::DrawCmdListPtr>>(prop)->Get()) {
433             width = std::max(width, cmd->GetWidth());
434             height = std::max(height, cmd->GetHeight());
435         }
436     }
437     if (width <= 0 || height <= 0) {
438         RS_LOGE("RSCanvasDrawingRenderNode::GetSizeFromDrawCmdModifiers: The width or height of the canvas is less "
439                 "than or equal to 0");
440         return false;
441     }
442     return true;
443 }
444 
IsNeedResetSurface() const445 bool RSCanvasDrawingRenderNode::IsNeedResetSurface() const
446 {
447     if (!surface_ || !surface_->GetCanvas()) {
448         return true;
449     }
450     return false;
451 }
452 
InitRenderParams()453 void RSCanvasDrawingRenderNode::InitRenderParams()
454 {
455     stagingRenderParams_ = std::make_unique<RSCanvasDrawingRenderParams>(GetId());
456     DrawableV2::RSRenderNodeDrawableAdapter::OnGenerate(shared_from_this());
457     if (renderDrawable_ == nullptr) {
458         RS_LOGE("RSCanvasDrawingRenderNode::InitRenderParams failed");
459         return;
460     }
461 }
462 
AddDirtyType(RSModifierType modifierType)463 void RSCanvasDrawingRenderNode::AddDirtyType(RSModifierType modifierType)
464 {
465     dirtyTypes_.set(static_cast<int>(modifierType), true);
466     std::lock_guard<std::mutex> lock(drawCmdListsMutex_);
467     for (auto& [type, list]: GetDrawCmdModifiers()) {
468         if (modifierType != type || list.empty()) {
469             continue;
470         }
471         for (const auto& modifier : list) {
472             if (modifier == nullptr) {
473                 continue;
474             }
475             auto prop = modifier->GetProperty();
476             if (prop == nullptr) {
477                 continue;
478             }
479             auto cmd = std::static_pointer_cast<RSRenderProperty<Drawing::DrawCmdListPtr>>(prop)->Get();
480             if (cmd == nullptr) {
481                 continue;
482             }
483 
484             if (cmd->GetOpItemSize() > DRAWCMDLIST_OPSIZE_COUNT_LIMIT) {
485                 RS_LOGE("CanvasDrawingNode AddDirtyType NodeId[%{public}" PRIu64 "] Cmd oversize"
486                     " Add DrawOpSize [%{public}zu]", GetId(), cmd->GetOpItemSize());
487                 continue;
488             }
489 
490             //only content_style allowed multi-drawcmdlist, others modifier same as canvas_node
491             if (type != RSModifierType::CONTENT_STYLE) {
492                 drawCmdLists_[type].clear();
493             }
494             drawCmdLists_[type].emplace_back(cmd);
495             SetNeedProcess(true);
496         }
497         bool overflow = drawCmdLists_[type].size() > DRAWCMDLIST_COUNT_LIMIT;
498         if (overflow && lastOverflowStatus_ != overflow) {
499             RS_LOGE("drawcmdlist overflow, This Node[%{public}" PRIu64 "] with Modifier[%{public}hd]"
500                     " have drawcmdlist:%{public}zu", GetId(), type, drawCmdLists_[type].size());
501         }
502         lastOverflowStatus_ = overflow;
503         // If such nodes are not drawn, The drawcmdlists don't clearOp during recording, As a result, there are
504         // too many drawOp, so we need to add the limit of drawcmdlists.
505         while ((GetOldDirtyInSurface().IsEmpty() || !IsDirty() || renderDrawable_) &&
506             drawCmdLists_[type].size() > DRAWCMDLIST_COUNT_LIMIT) {
507             drawCmdLists_[type].pop_front();
508         }
509         if (drawCmdLists_[type].size() > DRAWCMDLIST_COUNT_LIMIT) {
510             RS_LOGE("drawcmdlist Error, This Node[%{public}" PRIu64 "] with Modifier[%{public}hd]"
511                     " have drawcmdlist:%{public}zu", GetId(), type, drawCmdLists_[type].size());
512         }
513     }
514 }
515 
ClearOp()516 void RSCanvasDrawingRenderNode::ClearOp()
517 {
518     std::lock_guard<std::mutex> lock(drawCmdListsMutex_);
519     drawCmdLists_.clear();
520 }
521 
ResetSurface(int width,int height)522 void RSCanvasDrawingRenderNode::ResetSurface(int width, int height)
523 {
524     std::lock_guard<std::mutex> lockTask(taskMutex_);
525     if (preThreadInfo_.second && surface_) {
526         preThreadInfo_.second(std::move(surface_));
527     }
528     surface_ = nullptr;
529     recordingCanvas_ = nullptr;
530     stagingRenderParams_->SetCanvasDrawingSurfaceChanged(true);
531     stagingRenderParams_->SetCanvasDrawingSurfaceParams(width, height);
532 }
533 
GetDrawCmdLists() const534 const std::map<RSModifierType, std::list<Drawing::DrawCmdListPtr>>& RSCanvasDrawingRenderNode::GetDrawCmdLists() const
535 {
536     return drawCmdLists_;
537 }
538 
ClearResource()539 void RSCanvasDrawingRenderNode::ClearResource()
540 {
541     if (renderDrawable_ && renderDrawable_->IsDrawCmdListsVisited()) {
542         std::lock_guard<std::mutex> lock(drawCmdListsMutex_);
543         drawCmdLists_.clear();
544         renderDrawable_->SetDrawCmdListsVisited(false);
545     }
546 }
547 
548 } // namespace Rosen
549 } // namespace OHOS