1 /*
2  * Copyright (c) 2022-2024 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 "core/components_ng/pattern/canvas/canvas_pattern.h"
17 
18 #include "interfaces/inner_api/ace/ai/image_analyzer.h"
19 
20 #include "base/log/dump_log.h"
21 #include "base/utils/utils.h"
22 #include "core/common/ace_application_info.h"
23 #include "core/common/ai/image_analyzer_manager.h"
24 #include "core/common/container.h"
25 #include "core/components_ng/pattern/canvas/canvas_modifier.h"
26 #include "core/components_ng/pattern/canvas/canvas_paint_method.h"
27 #include "core/components_ng/pattern/canvas/canvas_paint_op.h"
28 #include "core/components_ng/pattern/canvas/offscreen_canvas_pattern.h"
29 
30 namespace OHOS::Ace::NG {
~CanvasPattern()31 CanvasPattern::~CanvasPattern()
32 {
33     if (IsSupportImageAnalyzerFeature()) {
34         ReleaseImageAnalyzer();
35     }
36 }
37 
OnDetachFromFrameNode(FrameNode * frameNode)38 void CanvasPattern::OnDetachFromFrameNode(FrameNode* frameNode)
39 {
40     DetachRenderContext();
41 }
42 
AttachRenderContext()43 void CanvasPattern::AttachRenderContext()
44 {
45     if (!isAttached_) {
46         isAttached_ = true;
47         FireOnContext2DAttach();
48     }
49 }
50 
DetachRenderContext()51 void CanvasPattern::DetachRenderContext()
52 {
53     if (isAttached_) {
54         isAttached_ = false;
55         FireOnContext2DDetach();
56     }
57 }
58 
OnAttachToMainTree()59 void CanvasPattern::OnAttachToMainTree()
60 {
61     if (paintMethod_) {
62         paintMethod_->SetHostCustomNodeName();
63     }
64 }
65 
SetOnContext2DAttach(std::function<void ()> && callback)66 void CanvasPattern::SetOnContext2DAttach(std::function<void()>&& callback)
67 {
68     onContext2DAttach_ = std::move(callback);
69 }
70 
SetOnContext2DDetach(std::function<void ()> && callback)71 void CanvasPattern::SetOnContext2DDetach(std::function<void()>&& callback)
72 {
73     onContext2DDetach_ = std::move(callback);
74 }
75 
FireOnContext2DAttach()76 void CanvasPattern::FireOnContext2DAttach()
77 {
78     if (onContext2DAttach_) {
79         onContext2DAttach_();
80     }
81 }
82 
FireOnContext2DDetach()83 void CanvasPattern::FireOnContext2DDetach()
84 {
85     if (onContext2DDetach_) {
86         onContext2DDetach_();
87     }
88 }
89 
OnAttachToFrameNode()90 void CanvasPattern::OnAttachToFrameNode()
91 {
92 #ifndef ACE_UNITTEST
93     auto host = GetHost();
94     CHECK_NULL_VOID(host);
95     auto renderCtx = host->GetRenderContext();
96     renderCtx->SetClipToBounds(false);
97     renderCtx->SetUsingContentRectForRenderFrame(true);
98     renderCtx->SetFrameGravity(Rosen::Gravity::RESIZE_ASPECT_FILL);
99     if (!contentModifier_) {
100         contentModifier_ = AceType::MakeRefPtr<CanvasModifier>();
101     }
102     paintMethod_ = MakeRefPtr<CanvasPaintMethod>(contentModifier_, host);
103 #endif
104 }
105 
CreateNodePaintMethod()106 RefPtr<NodePaintMethod> CanvasPattern::CreateNodePaintMethod()
107 {
108     return paintMethod_;
109 }
110 
OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper> & dirty,const DirtySwapConfig & config)111 bool CanvasPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config)
112 {
113     ACE_SCOPED_TRACE("CanvasPattern::OnDirtyLayoutWrapperSwap");
114     bool needReset = !(config.skipMeasure || dirty->SkipMeasureContent());
115     auto host = GetHost();
116     CHECK_NULL_RETURN(host, false);
117     auto context = host->GetContext();
118     CHECK_NULL_RETURN(context, false);
119     context->AddAfterLayoutTask([weak = WeakClaim(this), config, needReset]() {
120         auto pattern = weak.Upgrade();
121         CHECK_NULL_VOID(pattern);
122         pattern->OnSizeChanged(config, needReset);
123     });
124     return true;
125 }
126 
OnSizeChanged(const DirtySwapConfig & config,bool needReset)127 void CanvasPattern::OnSizeChanged(const DirtySwapConfig& config, bool needReset)
128 {
129     auto host = GetHost();
130     CHECK_NULL_VOID(host);
131     auto geometryNode = host->GetGeometryNode();
132     CHECK_NULL_VOID(geometryNode);
133     SizeF currentPixelGridRoundSize = geometryNode->GetPixelGridRoundSize();
134     bool pixelGridRoundSizeChange = currentPixelGridRoundSize != dirtyPixelGridRoundSize_;
135     lastDirtyPixelGridRoundSize_ = dirtyPixelGridRoundSize_;
136     dirtyPixelGridRoundSize_ = currentPixelGridRoundSize;
137 
138     // Canvas is first time onReady && Visibility is None
139     if (!needReset && (currentPixelGridRoundSize == SizeF { 0, 0 }) &&
140         (lastDirtyPixelGridRoundSize_ == SizeF { -1, -1 })) {
141         return;
142     }
143     // Visibility is None
144     if (!needReset && (currentPixelGridRoundSize == SizeF { 0, 0 })) {
145         CHECK_NULL_VOID(paintMethod_);
146         paintMethod_->UpdateRecordingCanvas(currentPixelGridRoundSize.Width(), currentPixelGridRoundSize.Height());
147         return;
148     }
149     // constraint is unchanged
150     if (!needReset) {
151         return;
152     }
153 
154     needReset = config.frameSizeChange || config.contentSizeChange;
155     if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TEN)) {
156         needReset = needReset && pixelGridRoundSizeChange;
157     } else {
158         needReset = needReset || config.frameOffsetChange || config.contentOffsetChange;
159     }
160 
161     if (needReset) {
162         if (IsSupportImageAnalyzerFeature()) {
163             imageAnalyzerManager_->UpdateAnalyzerUIConfig(geometryNode);
164         }
165         auto renderContext = host->GetRenderContext();
166         CHECK_NULL_VOID(renderContext);
167         CHECK_NULL_VOID(contentModifier_);
168         contentModifier_->SetNeedResetSurface();
169         contentModifier_->SetRenderContext(renderContext);
170         CHECK_NULL_VOID(paintMethod_);
171         paintMethod_->UpdateRecordingCanvas(currentPixelGridRoundSize.Width(), currentPixelGridRoundSize.Height());
172         auto canvasEventHub = GetEventHub<CanvasEventHub>();
173         CHECK_NULL_VOID(canvasEventHub);
174         canvasEventHub->FireReadyEvent();
175     }
176 }
177 
SetAntiAlias(bool isEnabled)178 void CanvasPattern::SetAntiAlias(bool isEnabled)
179 {
180     CHECK_NULL_VOID(paintMethod_);
181 #ifndef USE_FAST_TASKPOOL
182     auto task = [isEnabled](CanvasPaintMethod& paintMethod) {
183         paintMethod.SetAntiAlias(isEnabled);
184     };
185     paintMethod_->PushTask(task);
186 #else
187     paintMethod_->PushTask<SetAntiAliasOp>(isEnabled);
188 #endif
189 }
190 
FillRect(const Rect & rect)191 void CanvasPattern::FillRect(const Rect& rect)
192 {
193 #ifndef USE_FAST_TASKPOOL
194     auto task = [rect](CanvasPaintMethod& paintMethod) {
195         paintMethod.FillRect(rect);
196     };
197     paintMethod_->PushTask(task);
198 #else
199     paintMethod_->PushTask<FillRectOp>(rect);
200 #endif
201 }
202 
StrokeRect(const Rect & rect)203 void CanvasPattern::StrokeRect(const Rect& rect)
204 {
205 #ifndef USE_FAST_TASKPOOL
206     auto task = [rect](CanvasPaintMethod& paintMethod) {
207         paintMethod.StrokeRect(rect);
208     };
209     paintMethod_->PushTask(task);
210 #else
211     paintMethod_->PushTask<StrokeRectOp>(rect);
212 #endif
213 }
214 
ClearRect(const Rect & rect)215 void CanvasPattern::ClearRect(const Rect& rect)
216 {
217 #ifndef USE_FAST_TASKPOOL
218     auto task = [rect](CanvasPaintMethod& paintMethod) {
219         paintMethod.ClearRect(rect);
220     };
221     paintMethod_->PushTask(task);
222 #else
223     paintMethod_->PushTask<ClearRectOp>(rect);
224 #endif
225 }
226 
Fill()227 void CanvasPattern::Fill()
228 {
229 #ifndef USE_FAST_TASKPOOL
230     auto task = [](CanvasPaintMethod& paintMethod) {
231         paintMethod.Fill();
232     };
233     paintMethod_->PushTask(task);
234 #else
235     paintMethod_->PushTask<FillOp>();
236 #endif
237 }
238 
Fill(const RefPtr<CanvasPath2D> & path)239 void CanvasPattern::Fill(const RefPtr<CanvasPath2D>& path)
240 {
241 #ifndef USE_FAST_TASKPOOL
242     auto task = [path](CanvasPaintMethod& paintMethod) {
243         paintMethod.Fill(path);
244     };
245     paintMethod_->PushTask(task);
246 #else
247     paintMethod_->PushTask<Fill2DOp>(path);
248 #endif
249 }
250 
Stroke()251 void CanvasPattern::Stroke()
252 {
253 #ifndef USE_FAST_TASKPOOL
254     auto task = [](CanvasPaintMethod& paintMethod) {
255         paintMethod.Stroke();
256     };
257     paintMethod_->PushTask(task);
258 #else
259     paintMethod_->PushTask<StrokeOp>();
260 #endif
261 }
262 
Stroke(const RefPtr<CanvasPath2D> & path)263 void CanvasPattern::Stroke(const RefPtr<CanvasPath2D>& path)
264 {
265 #ifndef USE_FAST_TASKPOOL
266     auto task = [path](CanvasPaintMethod& paintMethod) {
267         paintMethod.Stroke(path);
268     };
269     paintMethod_->PushTask(task);
270 #else
271     paintMethod_->PushTask<Stroke2DOp>(path);
272 #endif
273 }
274 
Clip()275 void CanvasPattern::Clip()
276 {
277 #ifndef USE_FAST_TASKPOOL
278     auto task = [](CanvasPaintMethod& paintMethod) {
279         paintMethod.Clip();
280     };
281     paintMethod_->PushTask(task);
282 #else
283     paintMethod_->PushTask<ClipOp>();
284 #endif
285 }
286 
Clip(const RefPtr<CanvasPath2D> & path)287 void CanvasPattern::Clip(const RefPtr<CanvasPath2D>& path)
288 {
289 #ifndef USE_FAST_TASKPOOL
290     auto task = [path](CanvasPaintMethod& paintMethod) {
291         paintMethod.Clip(path);
292     };
293     paintMethod_->PushTask(task);
294 #else
295     paintMethod_->PushTask<Clip2DOp>(path);
296 #endif
297 }
298 
BeginPath()299 void CanvasPattern::BeginPath()
300 {
301 #ifndef USE_FAST_TASKPOOL
302     auto task = [](CanvasPaintMethod& paintMethod) {
303         paintMethod.BeginPath();
304     };
305     paintMethod_->PushTask(task);
306 #else
307     paintMethod_->PushTask<BeginPathOp>();
308 #endif
309 }
310 
ClosePath()311 void CanvasPattern::ClosePath()
312 {
313 #ifndef USE_FAST_TASKPOOL
314     auto task = [](CanvasPaintMethod& paintMethod) {
315         paintMethod.ClosePath();
316     };
317     paintMethod_->PushTask(task);
318 #else
319     paintMethod_->PushTask<ClosePathOp>();
320 #endif
321 }
322 
MoveTo(double x,double y)323 void CanvasPattern::MoveTo(double x, double y)
324 {
325 #ifndef USE_FAST_TASKPOOL
326     auto task = [x, y](CanvasPaintMethod& paintMethod) {
327         paintMethod.MoveTo(x, y);
328     };
329     paintMethod_->PushTask(task);
330 #else
331     paintMethod_->PushTask<MoveToOp>(x, y);
332 #endif
333 }
334 
LineTo(double x,double y)335 void CanvasPattern::LineTo(double x, double y)
336 {
337 #ifndef USE_FAST_TASKPOOL
338     auto task = [x, y](CanvasPaintMethod& paintMethod) {
339         paintMethod.LineTo(x, y);
340     };
341     paintMethod_->PushTask(task);
342 #else
343     paintMethod_->PushTask<LineToOp>(x, y);
344 #endif
345 }
346 
Arc(const ArcParam & param)347 void CanvasPattern::Arc(const ArcParam& param)
348 {
349 #ifndef USE_FAST_TASKPOOL
350     auto task = [param](CanvasPaintMethod& paintMethod) {
351         paintMethod.Arc(param);
352     };
353     paintMethod_->PushTask(task);
354 #else
355     paintMethod_->PushTask<ArcOp>(param);
356 #endif
357 }
358 
ArcTo(const ArcToParam & param)359 void CanvasPattern::ArcTo(const ArcToParam& param)
360 {
361 #ifndef USE_FAST_TASKPOOL
362     auto task = [param](CanvasPaintMethod& paintMethod) {
363         paintMethod.ArcTo(param);
364     };
365     paintMethod_->PushTask(task);
366 #else
367     paintMethod_->PushTask<ArcToOp>(param);
368 #endif
369 }
370 
AddRect(const Rect & rect)371 void CanvasPattern::AddRect(const Rect& rect)
372 {
373 #ifndef USE_FAST_TASKPOOL
374     auto task = [rect](CanvasPaintMethod& paintMethod) {
375         paintMethod.AddRect(rect);
376     };
377     paintMethod_->PushTask(task);
378 #else
379     paintMethod_->PushTask<AddRectOp>(rect);
380 #endif
381 }
382 
Ellipse(const EllipseParam & param)383 void CanvasPattern::Ellipse(const EllipseParam& param)
384 {
385 #ifndef USE_FAST_TASKPOOL
386     auto task = [param](CanvasPaintMethod& paintMethod) {
387         paintMethod.Ellipse(param);
388     };
389     paintMethod_->PushTask(task);
390 #else
391     paintMethod_->PushTask<EllipseOp>(param);
392 #endif
393 }
394 
BezierCurveTo(const BezierCurveParam & param)395 void CanvasPattern::BezierCurveTo(const BezierCurveParam& param)
396 {
397 #ifndef USE_FAST_TASKPOOL
398     auto task = [param](CanvasPaintMethod& paintMethod) {
399         paintMethod.BezierCurveTo(param);
400     };
401     paintMethod_->PushTask(task);
402 #else
403     paintMethod_->PushTask<BezierCurveToOp>(param);
404 #endif
405 }
406 
QuadraticCurveTo(const QuadraticCurveParam & param)407 void CanvasPattern::QuadraticCurveTo(const QuadraticCurveParam& param)
408 {
409 #ifndef USE_FAST_TASKPOOL
410     auto task = [param](CanvasPaintMethod& paintMethod) {
411         paintMethod.QuadraticCurveTo(param);
412     };
413     paintMethod_->PushTask(task);
414 #else
415     paintMethod_->PushTask<QuadraticCurveToOp>(param);
416 #endif
417 }
418 
FillText(const std::string & text,double x,double y,std::optional<double> maxWidth)419 void CanvasPattern::FillText(const std::string& text, double x, double y, std::optional<double> maxWidth)
420 {
421 #ifndef USE_FAST_TASKPOOL
422     auto task = [text, x, y, maxWidth](CanvasPaintMethod& paintMethod) {
423         paintMethod.FillText(text, x, y, maxWidth);
424     };
425     paintMethod_->PushTask(task);
426 #else
427     paintMethod_->PushTask<FillTextOp>(text, x, y, maxWidth);
428 #endif
429 }
430 
StrokeText(const std::string & text,double x,double y,std::optional<double> maxWidth)431 void CanvasPattern::StrokeText(const std::string& text, double x, double y, std::optional<double> maxWidth)
432 {
433 #ifndef USE_FAST_TASKPOOL
434     auto task = [text, x, y, maxWidth](CanvasPaintMethod& paintMethod) {
435         paintMethod.StrokeText(text, x, y, maxWidth);
436     };
437     paintMethod_->PushTask(task);
438 #else
439     paintMethod_->PushTask<StrokeTextOp>(text, x, y, maxWidth);
440 #endif
441 }
442 
MeasureTextMetrics(const std::string & text,const PaintState & state)443 TextMetrics CanvasPattern::MeasureTextMetrics(const std::string& text, const PaintState& state)
444 {
445     return paintMethod_->MeasureTextMetrics(text, state);
446 }
447 
DrawImage(const Ace::CanvasImage & image,double width,double height)448 void CanvasPattern::DrawImage(const Ace::CanvasImage& image, double width, double height)
449 {
450 #ifndef USE_FAST_TASKPOOL
451     auto task = [image, width, height](CanvasPaintMethod& paintMethod) {
452         paintMethod.DrawImage(image, width, height);
453     };
454     paintMethod_->PushTask(task);
455 #else
456     paintMethod_->PushTask<DrawImageOp>(image, width, height);
457 #endif
458 }
459 
DrawSvgImage(RefPtr<SvgDomBase> svgDom,const Ace::CanvasImage & image,const ImageFit & imageFit)460 void CanvasPattern::DrawSvgImage(
461     RefPtr<SvgDomBase> svgDom, const Ace::CanvasImage& image, const ImageFit& imageFit)
462 {
463 #ifndef USE_FAST_TASKPOOL
464     auto task = [svgDom, image, imageFit](CanvasPaintMethod& paintMethod) {
465         paintMethod.DrawSvgImage(svgDom, image, imageFit);
466     };
467     paintMethod_->PushTask(task);
468 #else
469     paintMethod_->PushTask<DrawSvgImageOp>(svgDom, image, imageFit);
470 #endif
471 }
472 
DrawPixelMap(RefPtr<PixelMap> pixelMap,const Ace::CanvasImage & image)473 void CanvasPattern::DrawPixelMap(RefPtr<PixelMap> pixelMap, const Ace::CanvasImage& image)
474 {
475 #ifndef USE_FAST_TASKPOOL
476     auto task = [pixelMap, image](CanvasPaintMethod& paintMethod) {
477         paintMethod.DrawPixelMap(pixelMap, image);
478     };
479     paintMethod_->PushTask(task);
480 #else
481     paintMethod_->PushTask<DrawPixelMapOp>(pixelMap, image);
482 #endif
483 }
484 
GetImageData(double left,double top,double width,double height)485 std::unique_ptr<Ace::ImageData> CanvasPattern::GetImageData(double left, double top, double width, double height)
486 {
487     if (!paintMethod_) {
488         std::unique_ptr<Ace::ImageData> data = std::make_unique<Ace::ImageData>();
489         data->dirtyWidth = width;
490         data->dirtyHeight = height;
491         return data;
492     }
493     // Rely on the single-threaded model. Should guarantee the timing between Render Task of pipeline and GetImageData
494     paintMethod_->FlushUITasks();
495     return paintMethod_->GetImageData(left, top, width, height);
496 }
497 
GetImageData(const std::shared_ptr<Ace::ImageData> & imageData)498 void CanvasPattern::GetImageData(const std::shared_ptr<Ace::ImageData>& imageData)
499 {
500     CHECK_NULL_VOID(paintMethod_);
501     paintMethod_->FlushUITasks();
502     paintMethod_->GetImageData(imageData);
503 }
504 
PutImageData(const Ace::ImageData & imageData)505 void CanvasPattern::PutImageData(const Ace::ImageData& imageData)
506 {
507 #ifndef USE_FAST_TASKPOOL
508     auto task = [imageData](CanvasPaintMethod& paintMethod) {
509         paintMethod.PutImageData(imageData);
510     };
511     paintMethod_->PushTask(task);
512 #else
513     paintMethod_->PushTask<PutImageDataOp>(imageData);
514 #endif
515 }
516 
517 #ifdef PIXEL_MAP_SUPPORTED
TransferFromImageBitmap(const RefPtr<PixelMap> & pixelMap)518 void CanvasPattern::TransferFromImageBitmap(const RefPtr<PixelMap>& pixelMap)
519 {
520 #ifndef USE_FAST_TASKPOOL
521     auto task = [pixelMap](CanvasPaintMethod& paintMethod) {
522         paintMethod.TransferFromImageBitmap(pixelMap);
523     };
524     paintMethod_->PushTask(task);
525 #else
526     paintMethod_->PushTask<TransferFromImageBitmapOp>(pixelMap);
527 #endif
528 }
529 #else
TransferFromImageBitmap(const Ace::ImageData & imageData)530 void CanvasPattern::TransferFromImageBitmap(const Ace::ImageData& imageData)
531 {
532 #ifndef ACE_UNITTEST
533 #ifndef USE_FAST_TASKPOOL
534     auto task = [imageData](CanvasPaintMethod& paintMethod) {
535         paintMethod.PutImageData(imageData);
536     };
537     paintMethod_->PushTask(task);
538 #else
539     paintMethod_->PushTask<PutImageDataOp>(imageData);
540 #endif
541 #endif
542 }
543 #endif
544 
CloseImageBitmap(const std::string & src)545 void CanvasPattern::CloseImageBitmap(const std::string& src)
546 {
547     paintMethod_->CloseImageBitmap(src);
548 }
549 
UpdateGlobalAlpha(double alpha)550 void CanvasPattern::UpdateGlobalAlpha(double alpha)
551 {
552 #ifndef USE_FAST_TASKPOOL
553     auto task = [alpha](CanvasPaintMethod& paintMethod) {
554         paintMethod.SetAlpha(alpha);
555     };
556     paintMethod_->PushTask(task);
557 #else
558     paintMethod_->PushTask<SetAlphaOp>(alpha);
559 #endif
560 }
561 
UpdateCompositeOperation(CompositeOperation type)562 void CanvasPattern::UpdateCompositeOperation(CompositeOperation type)
563 {
564 #ifndef USE_FAST_TASKPOOL
565     auto task = [type](CanvasPaintMethod& paintMethod) {
566         paintMethod.SetCompositeType(type);
567     };
568     paintMethod_->PushTask(task);
569 #else
570     paintMethod_->PushTask<SetCompositeTypeOp>(type);
571 #endif
572 }
573 
UpdateSmoothingEnabled(bool enabled)574 void CanvasPattern::UpdateSmoothingEnabled(bool enabled)
575 {
576 #ifndef USE_FAST_TASKPOOL
577     auto task = [enabled](CanvasPaintMethod& paintMethod) {
578         paintMethod.SetSmoothingEnabled(enabled);
579     };
580     paintMethod_->PushTask(task);
581 #else
582     paintMethod_->PushTask<SetSmoothingEnabledOp>(enabled);
583 #endif
584 }
585 
UpdateSmoothingQuality(const std::string & quality)586 void CanvasPattern::UpdateSmoothingQuality(const std::string& quality)
587 {
588 #ifndef USE_FAST_TASKPOOL
589     auto task = [quality](CanvasPaintMethod& paintMethod) {
590         paintMethod.SetSmoothingQuality(quality);
591     };
592     paintMethod_->PushTask(task);
593 #else
594     paintMethod_->PushTask<SetSmoothingQualityOp>(quality);
595 #endif
596 }
597 
UpdateLineCap(LineCapStyle cap)598 void CanvasPattern::UpdateLineCap(LineCapStyle cap)
599 {
600 #ifndef USE_FAST_TASKPOOL
601     auto task = [cap](CanvasPaintMethod& paintMethod) {
602         paintMethod.SetLineCap(cap);
603     };
604     paintMethod_->PushTask(task);
605 #else
606     paintMethod_->PushTask<SetLineCapOp>(cap);
607 #endif
608 }
609 
UpdateLineDashOffset(double dash)610 void CanvasPattern::UpdateLineDashOffset(double dash)
611 {
612 #ifndef USE_FAST_TASKPOOL
613     auto task = [dash](CanvasPaintMethod& paintMethod) {
614         paintMethod.SetLineDashOffset(dash);
615     };
616     paintMethod_->PushTask(task);
617 #else
618     paintMethod_->PushTask<SetLineDashOffsetOp>(dash);
619 #endif
620 }
621 
UpdateLineJoin(LineJoinStyle join)622 void CanvasPattern::UpdateLineJoin(LineJoinStyle join)
623 {
624 #ifndef USE_FAST_TASKPOOL
625     auto task = [join](CanvasPaintMethod& paintMethod) {
626         paintMethod.SetLineJoin(join);
627     };
628     paintMethod_->PushTask(task);
629 #else
630     paintMethod_->PushTask<SetLineJoinOp>(join);
631 #endif
632 }
633 
UpdateLineWidth(double width)634 void CanvasPattern::UpdateLineWidth(double width)
635 {
636 #ifndef USE_FAST_TASKPOOL
637     auto task = [width](CanvasPaintMethod& paintMethod) {
638         paintMethod.SetLineWidth(width);
639     };
640     paintMethod_->PushTask(task);
641 #else
642     paintMethod_->PushTask<SetLineWidthOp>(width);
643 #endif
644 }
645 
UpdateMiterLimit(double limit)646 void CanvasPattern::UpdateMiterLimit(double limit)
647 {
648 #ifndef USE_FAST_TASKPOOL
649     auto task = [limit](CanvasPaintMethod& paintMethod) {
650         paintMethod.SetMiterLimit(limit);
651     };
652     paintMethod_->PushTask(task);
653 #else
654     paintMethod_->PushTask<SetMiterLimitOp>(limit);
655 #endif
656 }
657 
UpdateShadowBlur(double blur)658 void CanvasPattern::UpdateShadowBlur(double blur)
659 {
660 #ifndef USE_FAST_TASKPOOL
661     auto task = [blur](CanvasPaintMethod& paintMethod) {
662         paintMethod.SetShadowBlur(blur);
663     };
664     paintMethod_->PushTask(task);
665 #else
666     paintMethod_->PushTask<SetShadowBlurOp>(blur);
667 #endif
668 }
669 
UpdateShadowColor(const Color & color)670 void CanvasPattern::UpdateShadowColor(const Color& color)
671 {
672     CHECK_NULL_VOID(paintMethod_);
673 #ifndef USE_FAST_TASKPOOL
674     auto task = [color](CanvasPaintMethod& paintMethod) {
675         paintMethod.SetShadowColor(color);
676     };
677     paintMethod_->PushTask(task);
678 #else
679     paintMethod_->PushTask<SetShadowColorOp>(color);
680 #endif
681 }
682 
UpdateShadowOffsetX(double offsetX)683 void CanvasPattern::UpdateShadowOffsetX(double offsetX)
684 {
685 #ifndef USE_FAST_TASKPOOL
686     auto task = [offsetX](CanvasPaintMethod& paintMethod) {
687         paintMethod.SetShadowOffsetX(offsetX);
688     };
689     paintMethod_->PushTask(task);
690 #else
691     paintMethod_->PushTask<SetShadowOffsetXOp>(offsetX);
692 #endif
693 }
694 
UpdateShadowOffsetY(double offsetY)695 void CanvasPattern::UpdateShadowOffsetY(double offsetY)
696 {
697 #ifndef USE_FAST_TASKPOOL
698     auto task = [offsetY](CanvasPaintMethod& paintMethod) {
699         paintMethod.SetShadowOffsetY(offsetY);
700     };
701     paintMethod_->PushTask(task);
702 #else
703     paintMethod_->PushTask<SetShadowOffsetYOp>(offsetY);
704 #endif
705 }
706 
UpdateTextAlign(TextAlign align)707 void CanvasPattern::UpdateTextAlign(TextAlign align)
708 {
709 #ifndef USE_FAST_TASKPOOL
710     auto task = [align](CanvasPaintMethod& paintMethod) {
711         paintMethod.SetTextAlign(align);
712     };
713     paintMethod_->PushTask(task);
714 #else
715     paintMethod_->PushTask<SetTextAlignOp>(align);
716 #endif
717 }
718 
UpdateTextBaseline(TextBaseline baseline)719 void CanvasPattern::UpdateTextBaseline(TextBaseline baseline)
720 {
721 #ifndef USE_FAST_TASKPOOL
722     auto task = [baseline](CanvasPaintMethod& paintMethod) {
723         paintMethod.SetTextBaseline(baseline);
724     };
725     paintMethod_->PushTask(task);
726 #else
727     paintMethod_->PushTask<SetTextBaselineOp>(baseline);
728 #endif
729 }
730 
UpdateStrokePattern(const std::weak_ptr<Ace::Pattern> & pattern)731 void CanvasPattern::UpdateStrokePattern(const std::weak_ptr<Ace::Pattern>& pattern)
732 {
733 #ifndef USE_FAST_TASKPOOL
734     auto task = [pattern](CanvasPaintMethod& paintMethod) {
735         paintMethod.SetStrokePatternNG(pattern);
736     };
737     paintMethod_->PushTask(task);
738 #else
739     paintMethod_->PushTask<SetStrokePatternNGOp>(pattern);
740 #endif
741 }
742 
UpdateStrokeColor(const Color & color)743 void CanvasPattern::UpdateStrokeColor(const Color& color)
744 {
745 #ifndef USE_FAST_TASKPOOL
746     auto task = [color](CanvasPaintMethod& paintMethod) {
747         paintMethod.SetStrokeColor(color);
748     };
749     paintMethod_->PushTask(task);
750 #else
751     paintMethod_->PushTask<SetStrokeColorOp>(color);
752 #endif
753 }
754 
SetStrokeGradient(const std::shared_ptr<Ace::Gradient> & gradient)755 void CanvasPattern::SetStrokeGradient(const std::shared_ptr<Ace::Gradient>& gradient)
756 {
757 #ifndef USE_FAST_TASKPOOL
758     auto task = [gradientObj = *gradient](CanvasPaintMethod& paintMethod) {
759         paintMethod.SetStrokeGradient(gradientObj);
760     };
761     paintMethod_->PushTask(task);
762 #else
763     paintMethod_->PushTask<SetStrokeGradientOp>(gradient);
764 #endif
765 }
766 
UpdateFontWeight(FontWeight weight)767 void CanvasPattern::UpdateFontWeight(FontWeight weight)
768 {
769 #ifndef USE_FAST_TASKPOOL
770     auto task = [weight](CanvasPaintMethod& paintMethod) {
771         paintMethod.SetFontWeight(weight);
772     };
773     paintMethod_->PushTask(task);
774 #else
775     paintMethod_->PushTask<SetFontWeightOp>(weight);
776 #endif
777 }
778 
UpdateFontStyle(FontStyle style)779 void CanvasPattern::UpdateFontStyle(FontStyle style)
780 {
781 #ifndef USE_FAST_TASKPOOL
782     auto task = [style](CanvasPaintMethod& paintMethod) {
783         paintMethod.SetFontStyle(style);
784     };
785     paintMethod_->PushTask(task);
786 #else
787     paintMethod_->PushTask<SetFontStyleOp>(style);
788 #endif
789 }
790 
UpdateFontFamilies(const std::vector<std::string> & families)791 void CanvasPattern::UpdateFontFamilies(const std::vector<std::string>& families)
792 {
793 #ifndef USE_FAST_TASKPOOL
794     auto task = [families](CanvasPaintMethod& paintMethod) {
795         paintMethod.SetFontFamilies(families);
796     };
797     paintMethod_->PushTask(task);
798 #else
799     paintMethod_->PushTask<SetFontFamiliesOp>(families);
800 #endif
801 }
802 
UpdateFontSize(const Dimension & size)803 void CanvasPattern::UpdateFontSize(const Dimension& size)
804 {
805 #ifndef USE_FAST_TASKPOOL
806     auto task = [size](CanvasPaintMethod& paintMethod) {
807         paintMethod.SetFontSize(size);
808     };
809     paintMethod_->PushTask(task);
810 #else
811     paintMethod_->PushTask<SetFontSizeOp>(size);
812 #endif
813 }
814 
UpdateFillColor(const Color & color)815 void CanvasPattern::UpdateFillColor(const Color& color)
816 {
817 #ifndef USE_FAST_TASKPOOL
818     auto task = [color](CanvasPaintMethod& paintMethod) {
819         paintMethod.SetFillColor(color);
820     };
821     paintMethod_->PushTask(task);
822 #else
823     paintMethod_->PushTask<SetFillColorOp>(color);
824 #endif
825 }
826 
SetFillGradient(const std::shared_ptr<Ace::Gradient> & gradient)827 void CanvasPattern::SetFillGradient(const std::shared_ptr<Ace::Gradient>& gradient)
828 {
829 #ifndef USE_FAST_TASKPOOL
830     auto task = [gradientObj = *gradient](CanvasPaintMethod& paintMethod) {
831         paintMethod.SetFillGradient(gradientObj);
832     };
833     paintMethod_->PushTask(task);
834 #else
835     paintMethod_->PushTask<SetFillGradientOp>(gradient);
836 #endif
837 }
838 
UpdateFillPattern(const std::weak_ptr<Ace::Pattern> & pattern)839 void CanvasPattern::UpdateFillPattern(const std::weak_ptr<Ace::Pattern>& pattern)
840 {
841 #ifndef USE_FAST_TASKPOOL
842     auto task = [pattern](CanvasPaintMethod& paintMethod) {
843         paintMethod.SetFillPatternNG(pattern);
844     };
845     paintMethod_->PushTask(task);
846 #else
847     paintMethod_->PushTask<SetFillPatternNGOp>(pattern);
848 #endif
849 }
850 
UpdateFillRuleForPath(const CanvasFillRule rule)851 void CanvasPattern::UpdateFillRuleForPath(const CanvasFillRule rule)
852 {
853 #ifndef USE_FAST_TASKPOOL
854     auto task = [rule](CanvasPaintMethod& paintMethod) {
855         paintMethod.SetFillRuleForPath(rule);
856     };
857     paintMethod_->PushTask(task);
858 #else
859     paintMethod_->PushTask<SetFillRuleForPathOp>(rule);
860 #endif
861 }
862 
UpdateFillRuleForPath2D(const CanvasFillRule rule)863 void CanvasPattern::UpdateFillRuleForPath2D(const CanvasFillRule rule)
864 {
865 #ifndef USE_FAST_TASKPOOL
866     auto task = [rule](CanvasPaintMethod& paintMethod) {
867         paintMethod.SetFillRuleForPath2D(rule);
868     };
869     paintMethod_->PushTask(task);
870 #else
871     paintMethod_->PushTask<SetFillRuleForPath2DOp>(rule);
872 #endif
873 }
874 
GetLineDash() const875 LineDashParam CanvasPattern::GetLineDash() const
876 {
877     return paintMethod_->GetLineDash();
878 }
879 
UpdateLineDash(const std::vector<double> & segments)880 void CanvasPattern::UpdateLineDash(const std::vector<double>& segments)
881 {
882 #ifndef USE_FAST_TASKPOOL
883     auto task = [segments](CanvasPaintMethod& paintMethod) {
884         paintMethod.SetLineDash(segments);
885     };
886     paintMethod_->PushTask(task);
887 #else
888     paintMethod_->PushTask<SetLineDashOp>(segments);
889 #endif
890     paintMethod_->SetLineDashParam(segments);
891 }
892 
Save()893 void CanvasPattern::Save()
894 {
895 #ifndef USE_FAST_TASKPOOL
896     auto task = [](CanvasPaintMethod& paintMethod) {
897         paintMethod.Save();
898     };
899     paintMethod_->PushTask(task);
900 #else
901     paintMethod_->PushTask<SaveOp>();
902 #endif
903     paintMethod_->SaveProperties();
904 }
905 
Restore()906 void CanvasPattern::Restore()
907 {
908 #ifndef USE_FAST_TASKPOOL
909     auto task = [](CanvasPaintMethod& paintMethod) {
910         paintMethod.Restore();
911     };
912     paintMethod_->PushTask(task);
913 #else
914     paintMethod_->PushTask<RestoreOp>();
915 #endif
916     paintMethod_->RestoreProperties();
917 }
918 
Scale(double x,double y)919 void CanvasPattern::Scale(double x, double y)
920 {
921 #ifndef USE_FAST_TASKPOOL
922     auto task = [x, y](CanvasPaintMethod& paintMethod) {
923         paintMethod.Scale(x, y);
924     };
925     paintMethod_->PushTask(task);
926 #else
927     paintMethod_->PushTask<ScaleOp>(x, y);
928 #endif
929     paintMethod_->ScaleMatrix(x, y);
930 }
931 
Rotate(double angle)932 void CanvasPattern::Rotate(double angle)
933 {
934 #ifndef USE_FAST_TASKPOOL
935     auto task = [angle](CanvasPaintMethod& paintMethod) {
936         paintMethod.Rotate(angle);
937     };
938     paintMethod_->PushTask(task);
939 #else
940     paintMethod_->PushTask<RotateOp>(angle);
941 #endif
942     paintMethod_->RotateMatrix(angle);
943 }
944 
SetTransform(const TransformParam & param)945 void CanvasPattern::SetTransform(const TransformParam& param)
946 {
947 #ifndef USE_FAST_TASKPOOL
948     auto task = [param](CanvasPaintMethod& paintMethod) {
949         paintMethod.SetTransform(param);
950     };
951     paintMethod_->PushTask(task);
952 #else
953     paintMethod_->PushTask<SetTransformOp>(param);
954 #endif
955     paintMethod_->SetTransformMatrix(param);
956 }
957 
ResetTransform()958 void CanvasPattern::ResetTransform()
959 {
960 #ifndef USE_FAST_TASKPOOL
961     auto task = [](CanvasPaintMethod& paintMethod) {
962         paintMethod.ResetTransform();
963     };
964     paintMethod_->PushTask(task);
965 #else
966     paintMethod_->PushTask<ResetTransformOp>();
967 #endif
968     paintMethod_->ResetTransformMatrix();
969 }
970 
Transform(const TransformParam & param)971 void CanvasPattern::Transform(const TransformParam& param)
972 {
973 #ifndef USE_FAST_TASKPOOL
974     auto task = [param](CanvasPaintMethod& paintMethod) {
975         paintMethod.Transform(param);
976     };
977     paintMethod_->PushTask(task);
978 #else
979     paintMethod_->PushTask<TransformOp>(param);
980 #endif
981     paintMethod_->TransformMatrix(param);
982 }
983 
Translate(double x,double y)984 void CanvasPattern::Translate(double x, double y)
985 {
986 #ifndef USE_FAST_TASKPOOL
987     auto task = [x, y](CanvasPaintMethod& paintMethod) {
988         paintMethod.Translate(x, y);
989     };
990     paintMethod_->PushTask(task);
991 #else
992     paintMethod_->PushTask<TranslateOp>(x, y);
993 #endif
994     paintMethod_->TranslateMatrix(x, y);
995 }
996 
ToDataURL(const std::string & type,double quality)997 std::string CanvasPattern::ToDataURL(const std::string& type, double quality)
998 {
999     // Rely on the single-threaded model. Should guarantee the timing between Render Task of pipeline and ToDataURL
1000     paintMethod_->FlushUITasks();
1001     return paintMethod_->ToDataURL(type, quality);
1002 }
1003 
GetJsonData(const std::string & path)1004 std::string CanvasPattern::GetJsonData(const std::string& path)
1005 {
1006     return paintMethod_->GetJsonData(path);
1007 }
1008 
GetWidth()1009 double CanvasPattern::GetWidth()
1010 {
1011     CHECK_NULL_RETURN(canvasSize_, 0.0);
1012     return canvasSize_->Width();
1013 }
1014 
GetHeight()1015 double CanvasPattern::GetHeight()
1016 {
1017     CHECK_NULL_RETURN(canvasSize_, 0.0);
1018     return canvasSize_->Height();
1019 }
1020 
SetRSCanvasCallback(std::function<void (RSCanvas *,double,double)> & callback)1021 void CanvasPattern::SetRSCanvasCallback(std::function<void(RSCanvas*, double, double)>& callback)
1022 {
1023     paintMethod_->SetRSCanvasCallback(callback);
1024 }
1025 
SetInvalidate()1026 void CanvasPattern::SetInvalidate()
1027 {
1028 #ifndef USE_FAST_TASKPOOL
1029     auto task = [](CanvasPaintMethod& paintMethod) {};
1030     paintMethod_->PushTask(task);
1031 #else
1032     paintMethod_->PushTask<SetInvalidateOp>();
1033 #endif
1034 }
1035 
SetTextDirection(TextDirection direction)1036 void CanvasPattern::SetTextDirection(TextDirection direction)
1037 {
1038     currentSetTextDirection_ = direction;
1039     auto host = GetHost();
1040     CHECK_NULL_VOID(host);
1041     auto layoutProperty = host->GetLayoutProperty<LayoutProperty>();
1042     auto directionCommon = layoutProperty->GetLayoutDirection();
1043     if (directionCommon == TextDirection::AUTO) {
1044         directionCommon = AceApplicationInfo::GetInstance().IsRightToLeft() ? TextDirection::RTL : TextDirection::LTR;
1045     }
1046     if (direction == TextDirection::INHERIT) {
1047         direction = directionCommon;
1048     }
1049     CHECK_NULL_VOID(paintMethod_);
1050 #ifndef USE_FAST_TASKPOOL
1051     auto task = [direction](CanvasPaintMethod& paintMethod) {
1052         paintMethod.SetTextDirection(direction);
1053     };
1054     paintMethod_->PushTask(task);
1055 #else
1056     paintMethod_->PushTask<SetTextDirectionOp>(direction);
1057 #endif
1058 }
1059 
SetFilterParam(const std::string & filterStr)1060 void CanvasPattern::SetFilterParam(const std::string& filterStr)
1061 {
1062 #ifndef USE_FAST_TASKPOOL
1063     auto task = [filterStr](CanvasPaintMethod& paintMethod) {
1064         paintMethod.SetFilterParam(filterStr);
1065     };
1066     paintMethod_->PushTask(task);
1067 #else
1068     paintMethod_->PushTask<SetFilterParamOp>(filterStr);
1069 #endif
1070 }
1071 
GetTransform() const1072 TransformParam CanvasPattern::GetTransform() const
1073 {
1074     return paintMethod_->GetTransform();
1075 }
1076 
SaveLayer()1077 void CanvasPattern::SaveLayer()
1078 {
1079 #ifndef USE_FAST_TASKPOOL
1080     auto task = [](CanvasPaintMethod& paintMethod) {
1081         paintMethod.SaveLayer();
1082     };
1083     paintMethod_->PushTask(task);
1084 #else
1085     paintMethod_->PushTask<SaveLayerOp>();
1086 #endif
1087 }
1088 
RestoreLayer()1089 void CanvasPattern::RestoreLayer()
1090 {
1091 #ifndef USE_FAST_TASKPOOL
1092     auto task = [](CanvasPaintMethod& paintMethod) {
1093         paintMethod.RestoreLayer();
1094     };
1095     paintMethod_->PushTask(task);
1096 #else
1097     paintMethod_->PushTask<RestoreLayerOp>();
1098 #endif
1099 }
1100 
EnableAnalyzer(bool enable)1101 void CanvasPattern::EnableAnalyzer(bool enable)
1102 {
1103     isEnableAnalyzer_ = enable;
1104     if (!isEnableAnalyzer_) {
1105         DestroyAnalyzerOverlay();
1106         return;
1107     }
1108 
1109     CHECK_NULL_VOID(!imageAnalyzerManager_);
1110     auto host = GetHost();
1111     CHECK_NULL_VOID(host);
1112     imageAnalyzerManager_ = std::make_shared<ImageAnalyzerManager>(host, ImageAnalyzerHolder::CANVAS);
1113     CHECK_NULL_VOID(imageAnalyzerManager_);
1114 
1115     CHECK_NULL_VOID(paintMethod_);
1116     paintMethod_->SetOnModifierUpdateFunc([weak = WeakClaim(this)] () -> void {
1117         auto pattern = weak.Upgrade();
1118         CHECK_NULL_VOID(pattern);
1119         pattern->DestroyAnalyzerOverlay();
1120     });
1121 }
1122 
SetImageAIOptions(void * options)1123 void CanvasPattern::SetImageAIOptions(void* options)
1124 {
1125     if (!imageAnalyzerManager_) {
1126         imageAnalyzerManager_ = std::make_shared<ImageAnalyzerManager>(GetHost(), ImageAnalyzerHolder::CANVAS);
1127     }
1128     CHECK_NULL_VOID(imageAnalyzerManager_);
1129     imageAnalyzerManager_->SetImageAIOptions(options);
1130 }
1131 
StartImageAnalyzer(void * config,OnAnalyzedCallback & onAnalyzed)1132 void CanvasPattern::StartImageAnalyzer(void* config, OnAnalyzedCallback& onAnalyzed)
1133 {
1134     if (!IsSupportImageAnalyzerFeature()) {
1135         CHECK_NULL_VOID(onAnalyzed);
1136         (onAnalyzed.value())(ImageAnalyzerState::UNSUPPORTED);
1137         return;
1138     }
1139 
1140     CHECK_NULL_VOID(imageAnalyzerManager_);
1141     imageAnalyzerManager_->SetImageAnalyzerConfig(config);
1142     imageAnalyzerManager_->SetImageAnalyzerCallback(onAnalyzed);
1143 
1144     auto host = GetHost();
1145     CHECK_NULL_VOID(host);
1146     auto context = host->GetContext();
1147     CHECK_NULL_VOID(context);
1148     auto uiTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::UI);
1149     uiTaskExecutor.PostTask([weak = WeakClaim(this)] {
1150         auto pattern = weak.Upgrade();
1151         CHECK_NULL_VOID(pattern);
1152         pattern->CreateAnalyzerOverlay();
1153     }, "ArkUICanvasStartImageAnalyzer");
1154 }
1155 
StopImageAnalyzer()1156 void CanvasPattern::StopImageAnalyzer()
1157 {
1158     DestroyAnalyzerOverlay();
1159 }
1160 
IsSupportImageAnalyzerFeature()1161 bool CanvasPattern::IsSupportImageAnalyzerFeature()
1162 {
1163     return isEnableAnalyzer_ && imageAnalyzerManager_ && imageAnalyzerManager_->IsSupportImageAnalyzerFeature();
1164 }
1165 
CreateAnalyzerOverlay()1166 void CanvasPattern::CreateAnalyzerOverlay()
1167 {
1168     auto host = GetHost();
1169     CHECK_NULL_VOID(host);
1170     host->SetOverlayNode(nullptr);
1171     auto context = host->GetRenderContext();
1172     CHECK_NULL_VOID(context);
1173     auto pixelMap = context->GetThumbnailPixelMap();
1174     CHECK_NULL_VOID(pixelMap);
1175     if (IsSupportImageAnalyzerFeature()) {
1176         CHECK_NULL_VOID(imageAnalyzerManager_);
1177         imageAnalyzerManager_->CreateAnalyzerOverlay(pixelMap);
1178     }
1179 }
1180 
UpdateAnalyzerOverlay()1181 void CanvasPattern::UpdateAnalyzerOverlay()
1182 {
1183     auto host = GetHost();
1184     CHECK_NULL_VOID(host);
1185     auto context = host->GetRenderContext();
1186     CHECK_NULL_VOID(context);
1187     auto pixelMap = context->GetThumbnailPixelMap();
1188     CHECK_NULL_VOID(pixelMap);
1189     CHECK_NULL_VOID(imageAnalyzerManager_);
1190     imageAnalyzerManager_->UpdateAnalyzerOverlay(pixelMap);
1191 }
1192 
DestroyAnalyzerOverlay()1193 void CanvasPattern::DestroyAnalyzerOverlay()
1194 {
1195     CHECK_NULL_VOID(imageAnalyzerManager_);
1196     imageAnalyzerManager_->DestroyAnalyzerOverlay();
1197 }
1198 
ReleaseImageAnalyzer()1199 void CanvasPattern::ReleaseImageAnalyzer()
1200 {
1201     CHECK_NULL_VOID(imageAnalyzerManager_);
1202     imageAnalyzerManager_->ReleaseImageAnalyzer();
1203 }
1204 
DumpInfo()1205 void CanvasPattern::DumpInfo()
1206 {
1207     CHECK_NULL_VOID(paintMethod_);
1208     DumpLog::GetInstance().AddDesc(paintMethod_->GetDumpInfo());
1209     CHECK_NULL_VOID(contentModifier_);
1210     DumpLog::GetInstance().AddDesc(contentModifier_->GetDumpInfo());
1211 }
1212 
Reset()1213 void CanvasPattern::Reset()
1214 {
1215 #ifndef USE_FAST_TASKPOOL
1216     auto task = [](CanvasPaintMethod& paintMethod) {
1217         paintMethod.Reset();
1218     };
1219     paintMethod_->PushTask(task);
1220 #else
1221     paintMethod_->PushTask<ResetCanvasOp>();
1222 #endif
1223     paintMethod_->ResetTransformMatrix();
1224     paintMethod_->ResetLineDash();
1225     SetTextDirection(TextDirection::INHERIT);
1226 }
1227 
OnLanguageConfigurationUpdate()1228 void CanvasPattern::OnLanguageConfigurationUpdate()
1229 {
1230     UpdateTextDefaultDirection();
1231 }
1232 
OnModifyDone()1233 void CanvasPattern::OnModifyDone()
1234 {
1235     Pattern::CheckLocalized();
1236     UpdateTextDefaultDirection();
1237 }
1238 
UpdateTextDefaultDirection()1239 void CanvasPattern::UpdateTextDefaultDirection()
1240 {
1241     if (currentSetTextDirection_ != TextDirection::INHERIT) {
1242         return;
1243     }
1244     SetTextDirection(TextDirection::INHERIT);
1245 }
1246 
SetDensity(double density)1247 void CanvasPattern::SetDensity(double density)
1248 {
1249     paintMethod_->SetDensity(density);
1250 }
1251 
GetId()1252 int32_t CanvasPattern::GetId()
1253 {
1254     auto host = GetHost();
1255     CHECK_NULL_RETURN(host, -1);
1256     return host->GetId();
1257 }
1258 
DumpSimplifyInfo(std::unique_ptr<JsonValue> & json)1259 void CanvasPattern::DumpSimplifyInfo(std::unique_ptr<JsonValue>& json)
1260 {
1261     CHECK_NULL_VOID(paintMethod_);
1262     auto jsonMethod = JsonUtil::Create();
1263     paintMethod_->GetSimplifyDumpInfo(jsonMethod);
1264     json->PutRef("CanvasPaint", std::move(jsonMethod));
1265     CHECK_NULL_VOID(contentModifier_);
1266     auto arrayModifier = JsonUtil::Create();
1267     contentModifier_->GetSimplifyDumpInfo(arrayModifier);
1268     json->PutRef("CanvasModifier", std::move(arrayModifier));
1269 }
1270 } // namespace OHOS::Ace::NG
1271