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 "recording/draw_cmd.h"
17 
18 #include <cstdint>
19 
20 #include "recording/cmd_list_helper.h"
21 #include "recording/draw_cmd_list.h"
22 #include "recording/mem_allocator.h"
23 #include "recording/op_item.h"
24 
25 #include "draw/brush.h"
26 #include "draw/path.h"
27 #include "draw/surface.h"
28 #include "effect/color_filter.h"
29 #include "effect/color_space.h"
30 #include "effect/image_filter.h"
31 #include "effect/mask_filter.h"
32 #include "effect/path_effect.h"
33 #include "effect/shader_effect.h"
34 #include "utils/log.h"
35 #include "utils/scalar.h"
36 #include "utils/system_properties.h"
37 #include "sandbox_utils.h"
38 
39 namespace OHOS {
40 namespace Rosen {
41 namespace Drawing {
42 std::unordered_map<uint32_t, std::string> typeOpDes = {
43     { DrawOpItem::OPITEM_HEAD,              "OPITEM_HEAD"},
44     { DrawOpItem::POINT_OPITEM,             "POINT_OPITEM" },
45     { DrawOpItem::POINTS_OPITEM,            "POINTS_OPITEM" },
46     { DrawOpItem::LINE_OPITEM,              "LINE_OPITEM" },
47     { DrawOpItem::RECT_OPITEM,              "RECT_OPITEM" },
48     { DrawOpItem::ROUND_RECT_OPITEM,        "ROUND_RECT_OPITEM" },
49     { DrawOpItem::NESTED_ROUND_RECT_OPITEM, "NESTED_ROUND_RECT_OPITEM" },
50     { DrawOpItem::ARC_OPITEM,               "ARC_OPITEM" },
51     { DrawOpItem::PIE_OPITEM,               "PIE_OPITEM" },
52     { DrawOpItem::OVAL_OPITEM,              "OVAL_OPITEM" },
53     { DrawOpItem::CIRCLE_OPITEM,            "CIRCLE_OPITEM" },
54     { DrawOpItem::PATH_OPITEM,              "PATH_OPITEM" },
55     { DrawOpItem::BACKGROUND_OPITEM,        "BACKGROUND_OPITEM" },
56     { DrawOpItem::SHADOW_OPITEM,            "SHADOW_OPITEM" },
57     { DrawOpItem::SHADOW_STYLE_OPITEM,      "SHADOW_STYLE_OPITEM" },
58     { DrawOpItem::COLOR_OPITEM,             "COLOR_OPITEM" },
59     { DrawOpItem::IMAGE_NINE_OPITEM,        "IMAGE_NINE_OPITEM" },
60     { DrawOpItem::IMAGE_LATTICE_OPITEM,     "IMAGE_LATTICE_OPITEM" },
61     { DrawOpItem::ATLAS_OPITEM,             "ATLAS_OPITEM" },
62     { DrawOpItem::BITMAP_OPITEM,            "BITMAP_OPITEM" },
63     { DrawOpItem::IMAGE_OPITEM,             "IMAGE_OPITEM" },
64     { DrawOpItem::IMAGE_RECT_OPITEM,        "IMAGE_RECT_OPITEM" },
65     { DrawOpItem::PICTURE_OPITEM,           "PICTURE_OPITEM" },
66     { DrawOpItem::TEXT_BLOB_OPITEM,         "TEXT_BLOB_OPITEM" },
67     { DrawOpItem::SYMBOL_OPITEM,            "SYMBOL_OPITEM" },
68     { DrawOpItem::CLIP_RECT_OPITEM,         "CLIP_RECT_OPITEM" },
69     { DrawOpItem::CLIP_IRECT_OPITEM,        "CLIP_IRECT_OPITEM" },
70     { DrawOpItem::CLIP_ROUND_RECT_OPITEM,   "CLIP_ROUND_RECT_OPITEM" },
71     { DrawOpItem::CLIP_PATH_OPITEM,         "CLIP_PATH_OPITEM" },
72     { DrawOpItem::CLIP_REGION_OPITEM,       "CLIP_REGION_OPITEM" },
73     { DrawOpItem::SET_MATRIX_OPITEM,        "SET_MATRIX_OPITEM" },
74     { DrawOpItem::RESET_MATRIX_OPITEM,      "RESET_MATRIX_OPITEM" },
75     { DrawOpItem::CONCAT_MATRIX_OPITEM,     "CONCAT_MATRIX_OPITEM" },
76     { DrawOpItem::TRANSLATE_OPITEM,         "TRANSLATE_OPITEM" },
77     { DrawOpItem::SCALE_OPITEM,             "SCALE_OPITEM" },
78     { DrawOpItem::ROTATE_OPITEM,            "ROTATE_OPITEM" },
79     { DrawOpItem::SHEAR_OPITEM,             "SHEAR_OPITEM" },
80     { DrawOpItem::FLUSH_OPITEM,             "FLUSH_OPITEM" },
81     { DrawOpItem::CLEAR_OPITEM,             "CLEAR_OPITEM" },
82     { DrawOpItem::SAVE_OPITEM,              "SAVE_OPITEM" },
83     { DrawOpItem::SAVE_LAYER_OPITEM,        "SAVE_LAYER_OPITEM" },
84     { DrawOpItem::RESTORE_OPITEM,           "RESTORE_OPITEM" },
85     { DrawOpItem::DISCARD_OPITEM,           "DISCARD_OPITEM" },
86     { DrawOpItem::CLIP_ADAPTIVE_ROUND_RECT_OPITEM,  "CLIP_ADAPTIVE_ROUND_RECT_OPITEM" },
87     { DrawOpItem::IMAGE_WITH_PARM_OPITEM,   "IMAGE_WITH_PARM_OPITEM" },
88     { DrawOpItem::PIXELMAP_WITH_PARM_OPITEM, "PIXELMAP_WITH_PARM_OPITEM" },
89     { DrawOpItem::PIXELMAP_RECT_OPITEM,     "PIXELMAP_RECT_OPITEM" },
90     { DrawOpItem::REGION_OPITEM,            "REGION_OPITEM" },
91     { DrawOpItem::PATCH_OPITEM,             "PATCH_OPITEM" },
92     { DrawOpItem::EDGEAAQUAD_OPITEM,        "EDGEAAQUAD_OPITEM" },
93     { DrawOpItem::VERTICES_OPITEM,          "VERTICES_OPITEM" },
94     { DrawOpItem::IMAGE_SNAPSHOT_OPITEM,    "IMAGE_SNAPSHOT_OPITEM" },
95     { DrawOpItem::SURFACEBUFFER_OPITEM,     "SURFACEBUFFER_OPITEM"},
96     { DrawOpItem::DRAW_FUNC_OPITEM,         "DRAW_FUNC_OPITEM"},
97 };
98 
99 namespace {
100 constexpr int TEXT_BLOB_CACHE_MARGIN = 10;
101 constexpr float HIGH_CONTRAST_OFFSCREEN_THREASHOLD = 0.99f;
102 }
103 
104 std::function<void (std::shared_ptr<Drawing::Image> image)> DrawOpItem::holdDrawingImagefunc_ = nullptr;
SetBaseCallback(std::function<void (std::shared_ptr<Drawing::Image> image)> holdDrawingImagefunc)105 void DrawOpItem::SetBaseCallback(
106     std::function<void (std::shared_ptr<Drawing::Image> image)> holdDrawingImagefunc)
107 {
108     holdDrawingImagefunc_ = holdDrawingImagefunc;
109 }
110 
111 std::function<std::shared_ptr<Drawing::Typeface>(uint64_t)> DrawOpItem::customTypefaceQueryfunc_ = nullptr;
SetTypefaceQueryCallBack(std::function<std::shared_ptr<Drawing::Typeface> (uint64_t)> customTypefaceQueryfunc)112 void DrawOpItem::SetTypefaceQueryCallBack(
113     std::function<std::shared_ptr<Drawing::Typeface>(uint64_t)> customTypefaceQueryfunc)
114 {
115     customTypefaceQueryfunc_ = customTypefaceQueryfunc;
116 }
117 
BrushHandleToBrush(const BrushHandle & brushHandle,const DrawCmdList & cmdList,Brush & brush)118 void DrawOpItem::BrushHandleToBrush(const BrushHandle& brushHandle, const DrawCmdList& cmdList, Brush& brush)
119 {
120     brush.SetBlendMode(brushHandle.mode);
121     brush.SetAntiAlias(brushHandle.isAntiAlias);
122     brush.SetBlenderEnabled(brushHandle.blenderEnabled);
123 
124     if (brushHandle.colorSpaceHandle.size) {
125         auto colorSpace = CmdListHelper::GetColorSpaceFromCmdList(cmdList, brushHandle.colorSpaceHandle);
126         const Color4f color4f = { brushHandle.color.GetRedF(), brushHandle.color.GetGreenF(),
127                                   brushHandle.color.GetBlueF(), brushHandle.color.GetAlphaF() };
128         brush.SetColor(color4f, colorSpace);
129     } else {
130         brush.SetColor(brushHandle.color);
131     }
132 
133     if (brushHandle.shaderEffectHandle.size) {
134         auto shaderEffect = CmdListHelper::GetShaderEffectFromCmdList(cmdList, brushHandle.shaderEffectHandle);
135         brush.SetShaderEffect(shaderEffect);
136     }
137 
138     Filter filter;
139     bool hasFilter = false;
140     if (brushHandle.colorFilterHandle.size) {
141         auto colorFilter = CmdListHelper::GetColorFilterFromCmdList(cmdList, brushHandle.colorFilterHandle);
142         filter.SetColorFilter(colorFilter);
143         hasFilter = true;
144     }
145     if (brushHandle.imageFilterHandle.size) {
146         auto imageFilter = CmdListHelper::GetImageFilterFromCmdList(cmdList, brushHandle.imageFilterHandle);
147         filter.SetImageFilter(imageFilter);
148         hasFilter = true;
149     }
150     if (brushHandle.maskFilterHandle.size) {
151         auto maskFilter = CmdListHelper::GetMaskFilterFromCmdList(cmdList, brushHandle.maskFilterHandle);
152         filter.SetMaskFilter(maskFilter);
153         hasFilter = true;
154     }
155 
156     if (hasFilter) {
157         filter.SetFilterQuality(brushHandle.filterQuality);
158         brush.SetFilter(filter);
159     }
160 }
161 
BrushToBrushHandle(const Brush & brush,DrawCmdList & cmdList,BrushHandle & brushHandle)162 void DrawOpItem::BrushToBrushHandle(const Brush& brush, DrawCmdList& cmdList, BrushHandle& brushHandle)
163 {
164     const Filter& filter = brush.GetFilter();
165     brushHandle.color = brush.GetColor();
166     brushHandle.mode = brush.GetBlendMode();
167     brushHandle.isAntiAlias = brush.IsAntiAlias();
168     brushHandle.blenderEnabled = brush.GetBlenderEnabled();
169     brushHandle.filterQuality = filter.GetFilterQuality();
170     brushHandle.colorSpaceHandle = CmdListHelper::AddColorSpaceToCmdList(cmdList, brush.GetColorSpace());
171     brushHandle.shaderEffectHandle = CmdListHelper::AddShaderEffectToCmdList(cmdList, brush.GetShaderEffect());
172     brushHandle.colorFilterHandle = CmdListHelper::AddColorFilterToCmdList(cmdList, filter.GetColorFilter());
173     brushHandle.imageFilterHandle = CmdListHelper::AddImageFilterToCmdList(cmdList, filter.GetImageFilter());
174     brushHandle.maskFilterHandle = CmdListHelper::AddMaskFilterToCmdList(cmdList, filter.GetMaskFilter());
175 }
176 
GeneratePaintFromHandle(const PaintHandle & paintHandle,const DrawCmdList & cmdList,Paint & paint)177 void DrawOpItem::GeneratePaintFromHandle(const PaintHandle& paintHandle, const DrawCmdList& cmdList, Paint& paint)
178 {
179     paint.SetBlendMode(paintHandle.mode);
180     paint.SetAntiAlias(paintHandle.isAntiAlias);
181     paint.SetBlenderEnabled(paintHandle.blenderEnabled);
182     paint.SetStyle(paintHandle.style);
183 
184     if (paintHandle.colorSpaceHandle.size) {
185         auto colorSpace = CmdListHelper::GetColorSpaceFromCmdList(cmdList, paintHandle.colorSpaceHandle);
186         const Color4f color4f = { paintHandle.color.GetRedF(), paintHandle.color.GetGreenF(),
187                                   paintHandle.color.GetBlueF(), paintHandle.color.GetAlphaF() };
188         paint.SetColor(color4f, colorSpace);
189     } else {
190         paint.SetColor(paintHandle.color);
191     }
192 
193     if (paintHandle.shaderEffectHandle.size) {
194         auto shaderEffect = CmdListHelper::GetShaderEffectFromCmdList(cmdList, paintHandle.shaderEffectHandle);
195         paint.SetShaderEffect(shaderEffect);
196     }
197 
198     Filter filter;
199     bool hasFilter = false;
200     if (paintHandle.colorFilterHandle.size) {
201         auto colorFilter = CmdListHelper::GetColorFilterFromCmdList(cmdList, paintHandle.colorFilterHandle);
202         filter.SetColorFilter(colorFilter);
203         hasFilter = true;
204     }
205     if (paintHandle.imageFilterHandle.size) {
206         auto imageFilter = CmdListHelper::GetImageFilterFromCmdList(cmdList, paintHandle.imageFilterHandle);
207         filter.SetImageFilter(imageFilter);
208         hasFilter = true;
209     }
210     if (paintHandle.maskFilterHandle.size) {
211         auto maskFilter = CmdListHelper::GetMaskFilterFromCmdList(cmdList, paintHandle.maskFilterHandle);
212         filter.SetMaskFilter(maskFilter);
213         hasFilter = true;
214     }
215 
216     if (hasFilter) {
217         filter.SetFilterQuality(paintHandle.filterQuality);
218         paint.SetFilter(filter);
219     }
220 
221     if (paintHandle.blurDrawLooperHandle.size) {
222         auto blurDrawLooper = CmdListHelper::GetBlurDrawLooperFromCmdList(cmdList,
223             paintHandle.blurDrawLooperHandle);
224         paint.SetLooper(blurDrawLooper);
225     }
226 
227     if (!paint.HasStrokeStyle()) {
228         return;
229     }
230 
231     paint.SetWidth(paintHandle.width);
232     paint.SetMiterLimit(paintHandle.miterLimit);
233     paint.SetCapStyle(paintHandle.capStyle);
234     paint.SetJoinStyle(paintHandle.joinStyle);
235     if (paintHandle.pathEffectHandle.size) {
236         auto pathEffect = CmdListHelper::GetPathEffectFromCmdList(cmdList, paintHandle.pathEffectHandle);
237         paint.SetPathEffect(pathEffect);
238     }
239 }
240 
GenerateHandleFromPaint(CmdList & cmdList,const Paint & paint,PaintHandle & paintHandle)241 void DrawOpItem::GenerateHandleFromPaint(CmdList& cmdList, const Paint& paint, PaintHandle& paintHandle)
242 {
243     paintHandle.isAntiAlias = paint.IsAntiAlias();
244     paintHandle.blenderEnabled = paint.GetBlenderEnabled();
245     paintHandle.style = paint.GetStyle();
246     paintHandle.color = paint.GetColor();
247     paintHandle.mode = paint.GetBlendMode();
248 
249     if (paint.HasFilter()) {
250         const Filter& filter = paint.GetFilter();
251         paintHandle.filterQuality = filter.GetFilterQuality();
252         paintHandle.colorFilterHandle = CmdListHelper::AddColorFilterToCmdList(cmdList, filter.GetColorFilter());
253         paintHandle.imageFilterHandle = CmdListHelper::AddImageFilterToCmdList(cmdList, filter.GetImageFilter());
254         paintHandle.maskFilterHandle = CmdListHelper::AddMaskFilterToCmdList(cmdList, filter.GetMaskFilter());
255     }
256 
257     if (paint.GetColorSpace()) {
258         paintHandle.colorSpaceHandle = CmdListHelper::AddColorSpaceToCmdList(cmdList, paint.GetColorSpace());
259     }
260 
261     if (paint.GetShaderEffect()) {
262         paintHandle.shaderEffectHandle = CmdListHelper::AddShaderEffectToCmdList(cmdList, paint.GetShaderEffect());
263     }
264 
265     if (paint.GetLooper()) {
266         paintHandle.blurDrawLooperHandle = CmdListHelper::AddBlurDrawLooperToCmdList(cmdList,
267             paint.GetLooper());
268     }
269 
270     if (!paint.HasStrokeStyle()) {
271         return;
272     }
273 
274     paintHandle.width = paint.GetWidth();
275     paintHandle.miterLimit = paint.GetMiterLimit();
276     paintHandle.capStyle = paint.GetCapStyle();
277     paintHandle.joinStyle = paint.GetJoinStyle();
278     if (paint.GetPathEffect()) {
279         paintHandle.pathEffectHandle = CmdListHelper::AddPathEffectToCmdList(cmdList, paint.GetPathEffect());
280     }
281 }
282 
GetOpDesc()283 std::string DrawOpItem::GetOpDesc()
284 {
285     return typeOpDes[GetType()];
286 }
287 
Dump(std::string & out)288 void DrawOpItem::Dump(std::string& out)
289 {
290     out += typeOpDes[GetType()];
291 }
292 
GenerateCachedOpItemPlayer(DrawCmdList & cmdList,Canvas * canvas,const Rect * rect)293 GenerateCachedOpItemPlayer::GenerateCachedOpItemPlayer(DrawCmdList &cmdList, Canvas* canvas, const Rect* rect)
294     : canvas_(canvas), rect_(rect), cmdList_(cmdList) {}
295 
GenerateCachedOpItem(uint32_t type,void * handle,size_t avaliableSize)296 bool GenerateCachedOpItemPlayer::GenerateCachedOpItem(uint32_t type, void* handle, size_t avaliableSize)
297 {
298     if (handle == nullptr) {
299         return false;
300     }
301 
302     if (type == DrawOpItem::TEXT_BLOB_OPITEM && avaliableSize >= sizeof(DrawTextBlobOpItem::ConstructorHandle)) {
303         auto* op = static_cast<DrawTextBlobOpItem::ConstructorHandle*>(handle);
304         return op->GenerateCachedOpItem(cmdList_, canvas_);
305     }
306     return false;
307 }
308 
309 /* UnmarshallingPlayer */
Instance()310 UnmarshallingHelper& UnmarshallingHelper::Instance()
311 {
312     static UnmarshallingHelper instance;
313     return instance;
314 }
315 
Register(uint32_t type,UnmarshallingHelper::UnmarshallingFunc func,size_t unmarshallingSize)316 bool UnmarshallingHelper::Register(uint32_t type, UnmarshallingHelper::UnmarshallingFunc func, size_t unmarshallingSize)
317 {
318     std::unique_lock lck(mtx_);
319     opUnmarshallingFuncLUT_.emplace(type, func);
320     opUnmarshallingSize_.emplace(type, unmarshallingSize);
321     return true;
322 }
323 
GetFuncAndSize(uint32_t type)324 std::pair<UnmarshallingHelper::UnmarshallingFunc, size_t> UnmarshallingHelper::GetFuncAndSize(uint32_t type)
325 {
326     std::shared_lock lck(mtx_);
327     auto funcIt = opUnmarshallingFuncLUT_.find(type);
328     auto sizeIt = opUnmarshallingSize_.find(type);
329     if (funcIt == opUnmarshallingFuncLUT_.end() || sizeIt == opUnmarshallingSize_.end()) {
330         return { nullptr, 0 };
331     }
332     /* unmarshalling func, desirable size for unmarshalling*/
333     return { funcIt->second, sizeIt->second };
334 }
335 
UnmarshallingPlayer(const DrawCmdList & cmdList)336 UnmarshallingPlayer::UnmarshallingPlayer(const DrawCmdList& cmdList) : cmdList_(cmdList) {}
337 
Unmarshalling(uint32_t type,void * handle,size_t avaliableSize)338 std::shared_ptr<DrawOpItem> UnmarshallingPlayer::Unmarshalling(uint32_t type, void* handle, size_t avaliableSize)
339 {
340     if (type == DrawOpItem::OPITEM_HEAD) {
341         return nullptr;
342     }
343 
344     const auto unmarshallingPair = UnmarshallingHelper::Instance().GetFuncAndSize(type);
345     /* if unmarshalling func is null or avaliable size < desirable unmarshalling size, then return nullptr*/
346     if (unmarshallingPair.first == nullptr || unmarshallingPair.second > avaliableSize) {
347         return nullptr;
348     }
349     return (*unmarshallingPair.first)(this->cmdList_, handle);
350 }
351 
352 /* DrawWithPaintOpItem */
DrawWithPaintOpItem(const DrawCmdList & cmdList,const PaintHandle & paintHandle,uint32_t type)353 DrawWithPaintOpItem::DrawWithPaintOpItem(const DrawCmdList& cmdList, const PaintHandle& paintHandle, uint32_t type)
354     : DrawOpItem(type)
355 {
356     GeneratePaintFromHandle(paintHandle, cmdList, paint_);
357 }
358 
359 /* DrawPointOpItem */
360 UNMARSHALLING_REGISTER(DrawPoint, DrawOpItem::POINT_OPITEM,
361     DrawPointOpItem::Unmarshalling, sizeof(DrawPointOpItem::ConstructorHandle));
362 
DrawPointOpItem(const DrawCmdList & cmdList,DrawPointOpItem::ConstructorHandle * handle)363 DrawPointOpItem::DrawPointOpItem(const DrawCmdList& cmdList, DrawPointOpItem::ConstructorHandle* handle)
364     : DrawWithPaintOpItem(cmdList, handle->paintHandle, POINT_OPITEM), point_(handle->point) {}
365 
Unmarshalling(const DrawCmdList & cmdList,void * handle)366 std::shared_ptr<DrawOpItem> DrawPointOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
367 {
368     return std::make_shared<DrawPointOpItem>(cmdList, static_cast<DrawPointOpItem::ConstructorHandle*>(handle));
369 }
370 
Marshalling(DrawCmdList & cmdList)371 void DrawPointOpItem::Marshalling(DrawCmdList& cmdList)
372 {
373     PaintHandle paintHandle;
374     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
375     cmdList.AddOp<ConstructorHandle>(point_, paintHandle);
376 }
377 
Playback(Canvas * canvas,const Rect * rect)378 void DrawPointOpItem::Playback(Canvas* canvas, const Rect* rect)
379 {
380     canvas->AttachPaint(paint_);
381     canvas->DrawPoint(point_);
382 }
383 
384 /* DrawPointsOpItem */
385 UNMARSHALLING_REGISTER(DrawPoints, DrawOpItem::POINTS_OPITEM,
386     DrawPointsOpItem::Unmarshalling, sizeof(DrawPointsOpItem::ConstructorHandle));
387 
DrawPointsOpItem(const DrawCmdList & cmdList,DrawPointsOpItem::ConstructorHandle * handle)388 DrawPointsOpItem::DrawPointsOpItem(const DrawCmdList& cmdList, DrawPointsOpItem::ConstructorHandle* handle)
389     : DrawWithPaintOpItem(cmdList, handle->paintHandle, POINTS_OPITEM), mode_(handle->mode)
390 {
391     pts_ = CmdListHelper::GetVectorFromCmdList<Point>(cmdList, handle->pts);
392 }
393 
Unmarshalling(const DrawCmdList & cmdList,void * handle)394 std::shared_ptr<DrawOpItem> DrawPointsOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
395 {
396     return std::make_shared<DrawPointsOpItem>(cmdList, static_cast<DrawPointsOpItem::ConstructorHandle*>(handle));
397 }
398 
Marshalling(DrawCmdList & cmdList)399 void DrawPointsOpItem::Marshalling(DrawCmdList& cmdList)
400 {
401     PaintHandle paintHandle;
402     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
403     auto pointsData = CmdListHelper::AddVectorToCmdList<Point>(cmdList, pts_);
404     cmdList.AddOp<ConstructorHandle>(mode_, pointsData, paintHandle);
405 }
406 
Playback(Canvas * canvas,const Rect * rect)407 void DrawPointsOpItem::Playback(Canvas* canvas, const Rect* rect)
408 {
409     canvas->AttachPaint(paint_);
410     canvas->DrawPoints(mode_, pts_.size(), pts_.data());
411 }
412 
413 /* DrawLineOpItem */
414 UNMARSHALLING_REGISTER(DrawLine, DrawOpItem::LINE_OPITEM,
415     DrawLineOpItem::Unmarshalling, sizeof(DrawLineOpItem::ConstructorHandle));
416 
DrawLineOpItem(const DrawCmdList & cmdList,DrawLineOpItem::ConstructorHandle * handle)417 DrawLineOpItem::DrawLineOpItem(const DrawCmdList& cmdList, DrawLineOpItem::ConstructorHandle* handle)
418     : DrawWithPaintOpItem(cmdList, handle->paintHandle, LINE_OPITEM),
419       startPt_(handle->startPt), endPt_(handle->endPt) {}
420 
Unmarshalling(const DrawCmdList & cmdList,void * handle)421 std::shared_ptr<DrawOpItem> DrawLineOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
422 {
423     return std::make_shared<DrawLineOpItem>(cmdList, static_cast<DrawLineOpItem::ConstructorHandle*>(handle));
424 }
425 
Marshalling(DrawCmdList & cmdList)426 void DrawLineOpItem::Marshalling(DrawCmdList& cmdList)
427 {
428     PaintHandle paintHandle;
429     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
430     cmdList.AddOp<ConstructorHandle>(startPt_, endPt_, paintHandle);
431 }
432 
Playback(Canvas * canvas,const Rect * rect)433 void DrawLineOpItem::Playback(Canvas* canvas, const Rect* rect)
434 {
435     canvas->AttachPaint(paint_);
436     canvas->DrawLine(startPt_, endPt_);
437 }
438 
439 /* DrawRectOpItem */
440 UNMARSHALLING_REGISTER(DrawRect, DrawOpItem::RECT_OPITEM,
441     DrawRectOpItem::Unmarshalling, sizeof(DrawRectOpItem::ConstructorHandle));
442 
DrawRectOpItem(const DrawCmdList & cmdList,DrawRectOpItem::ConstructorHandle * handle)443 DrawRectOpItem::DrawRectOpItem(const DrawCmdList& cmdList, DrawRectOpItem::ConstructorHandle* handle)
444     : DrawWithPaintOpItem(cmdList, handle->paintHandle, RECT_OPITEM), rect_(handle->rect) {}
445 
Unmarshalling(const DrawCmdList & cmdList,void * handle)446 std::shared_ptr<DrawOpItem> DrawRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
447 {
448     return std::make_shared<DrawRectOpItem>(cmdList, static_cast<DrawRectOpItem::ConstructorHandle*>(handle));
449 }
450 
Marshalling(DrawCmdList & cmdList)451 void DrawRectOpItem::Marshalling(DrawCmdList& cmdList)
452 {
453     PaintHandle paintHandle;
454     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
455     cmdList.AddOp<ConstructorHandle>(rect_, paintHandle);
456 }
457 
Playback(Canvas * canvas,const Rect * rect)458 void DrawRectOpItem::Playback(Canvas* canvas, const Rect* rect)
459 {
460     canvas->AttachPaint(paint_);
461     canvas->DrawRect(rect_);
462 }
463 
464 /* DrawRoundRectOpItem */
465 UNMARSHALLING_REGISTER(DrawRoundRect, DrawOpItem::ROUND_RECT_OPITEM,
466     DrawRoundRectOpItem::Unmarshalling, sizeof(DrawRoundRectOpItem::ConstructorHandle));
467 
DrawRoundRectOpItem(const DrawCmdList & cmdList,DrawRoundRectOpItem::ConstructorHandle * handle)468 DrawRoundRectOpItem::DrawRoundRectOpItem(const DrawCmdList& cmdList, DrawRoundRectOpItem::ConstructorHandle* handle)
469     : DrawWithPaintOpItem(cmdList, handle->paintHandle, ROUND_RECT_OPITEM), rrect_(handle->rrect) {}
470 
Unmarshalling(const DrawCmdList & cmdList,void * handle)471 std::shared_ptr<DrawOpItem> DrawRoundRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
472 {
473     return std::make_shared<DrawRoundRectOpItem>(cmdList, static_cast<DrawRoundRectOpItem::ConstructorHandle*>(handle));
474 }
475 
Marshalling(DrawCmdList & cmdList)476 void DrawRoundRectOpItem::Marshalling(DrawCmdList& cmdList)
477 {
478     PaintHandle paintHandle;
479     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
480     cmdList.AddOp<ConstructorHandle>(rrect_, paintHandle);
481 }
482 
Playback(Canvas * canvas,const Rect * rect)483 void DrawRoundRectOpItem::Playback(Canvas* canvas, const Rect* rect)
484 {
485     canvas->AttachPaint(paint_);
486     canvas->DrawRoundRect(rrect_);
487 }
488 
489 /* DrawNestedRoundRectOpItem */
490 UNMARSHALLING_REGISTER(DrawNestedRoundRect, DrawOpItem::NESTED_ROUND_RECT_OPITEM,
491     DrawNestedRoundRectOpItem::Unmarshalling, sizeof(DrawNestedRoundRectOpItem::ConstructorHandle));
492 
DrawNestedRoundRectOpItem(const DrawCmdList & cmdList,DrawNestedRoundRectOpItem::ConstructorHandle * handle)493 DrawNestedRoundRectOpItem::DrawNestedRoundRectOpItem(
494     const DrawCmdList& cmdList, DrawNestedRoundRectOpItem::ConstructorHandle* handle)
495     : DrawWithPaintOpItem(cmdList, handle->paintHandle, NESTED_ROUND_RECT_OPITEM),
496       outerRRect_(handle->outerRRect), innerRRect_(handle->innerRRect) {}
497 
Unmarshalling(const DrawCmdList & cmdList,void * handle)498 std::shared_ptr<DrawOpItem> DrawNestedRoundRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
499 {
500     return std::make_shared<DrawNestedRoundRectOpItem>(
501         cmdList, static_cast<DrawNestedRoundRectOpItem::ConstructorHandle*>(handle));
502 }
503 
Marshalling(DrawCmdList & cmdList)504 void DrawNestedRoundRectOpItem::Marshalling(DrawCmdList& cmdList)
505 {
506     PaintHandle paintHandle;
507     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
508     cmdList.AddOp<ConstructorHandle>(outerRRect_, innerRRect_, paintHandle);
509 }
510 
Playback(Canvas * canvas,const Rect * rect)511 void DrawNestedRoundRectOpItem::Playback(Canvas* canvas, const Rect* rect)
512 {
513     canvas->AttachPaint(paint_);
514     canvas->DrawNestedRoundRect(outerRRect_, innerRRect_);
515 }
516 
517 /* DrawArcOpItem */
518 UNMARSHALLING_REGISTER(DrawArc, DrawOpItem::ARC_OPITEM,
519     DrawArcOpItem::Unmarshalling, sizeof(DrawArcOpItem::ConstructorHandle));
520 
DrawArcOpItem(const DrawCmdList & cmdList,DrawArcOpItem::ConstructorHandle * handle)521 DrawArcOpItem::DrawArcOpItem(const DrawCmdList& cmdList, DrawArcOpItem::ConstructorHandle* handle)
522     : DrawWithPaintOpItem(cmdList, handle->paintHandle, ARC_OPITEM), rect_(handle->rect),
523       startAngle_(handle->startAngle), sweepAngle_(handle->sweepAngle) {}
524 
Unmarshalling(const DrawCmdList & cmdList,void * handle)525 std::shared_ptr<DrawOpItem> DrawArcOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
526 {
527     return std::make_shared<DrawArcOpItem>(cmdList, static_cast<DrawArcOpItem::ConstructorHandle*>(handle));
528 }
529 
Marshalling(DrawCmdList & cmdList)530 void DrawArcOpItem::Marshalling(DrawCmdList& cmdList)
531 {
532     PaintHandle paintHandle;
533     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
534     cmdList.AddOp<ConstructorHandle>(rect_, startAngle_, sweepAngle_, paintHandle);
535 }
536 
Playback(Canvas * canvas,const Rect * rect)537 void DrawArcOpItem::Playback(Canvas* canvas, const Rect* rect)
538 {
539     canvas->AttachPaint(paint_);
540     canvas->DrawArc(rect_, startAngle_, sweepAngle_);
541 }
542 
543 /* DrawPieOpItem */
544 UNMARSHALLING_REGISTER(DrawPie, DrawOpItem::PIE_OPITEM,
545     DrawPieOpItem::Unmarshalling, sizeof(DrawPieOpItem::ConstructorHandle));
546 
DrawPieOpItem(const DrawCmdList & cmdList,DrawPieOpItem::ConstructorHandle * handle)547 DrawPieOpItem::DrawPieOpItem(const DrawCmdList& cmdList, DrawPieOpItem::ConstructorHandle* handle)
548     : DrawWithPaintOpItem(cmdList, handle->paintHandle, PIE_OPITEM), rect_(handle->rect),
549       startAngle_(handle->startAngle), sweepAngle_(handle->sweepAngle) {}
550 
Unmarshalling(const DrawCmdList & cmdList,void * handle)551 std::shared_ptr<DrawOpItem> DrawPieOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
552 {
553     return std::make_shared<DrawPieOpItem>(cmdList, static_cast<DrawPieOpItem::ConstructorHandle*>(handle));
554 }
555 
Marshalling(DrawCmdList & cmdList)556 void DrawPieOpItem::Marshalling(DrawCmdList& cmdList)
557 {
558     PaintHandle paintHandle;
559     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
560     cmdList.AddOp<ConstructorHandle>(rect_, startAngle_, sweepAngle_, paintHandle);
561 }
562 
Playback(Canvas * canvas,const Rect * rect)563 void DrawPieOpItem::Playback(Canvas* canvas, const Rect* rect)
564 {
565     canvas->AttachPaint(paint_);
566     canvas->DrawPie(rect_, startAngle_, sweepAngle_);
567 }
568 
569 /* DrawOvalOpItem */
570 UNMARSHALLING_REGISTER(DrawOval, DrawOpItem::OVAL_OPITEM,
571     DrawOvalOpItem::Unmarshalling, sizeof(DrawOvalOpItem::ConstructorHandle));
572 
DrawOvalOpItem(const DrawCmdList & cmdList,DrawOvalOpItem::ConstructorHandle * handle)573 DrawOvalOpItem::DrawOvalOpItem(const DrawCmdList& cmdList, DrawOvalOpItem::ConstructorHandle* handle)
574     : DrawWithPaintOpItem(cmdList, handle->paintHandle, OVAL_OPITEM), rect_(handle->rect) {}
575 
Unmarshalling(const DrawCmdList & cmdList,void * handle)576 std::shared_ptr<DrawOpItem> DrawOvalOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
577 {
578     return std::make_shared<DrawOvalOpItem>(cmdList, static_cast<DrawOvalOpItem::ConstructorHandle*>(handle));
579 }
580 
Marshalling(DrawCmdList & cmdList)581 void DrawOvalOpItem::Marshalling(DrawCmdList& cmdList)
582 {
583     PaintHandle paintHandle;
584     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
585     cmdList.AddOp<ConstructorHandle>(rect_, paintHandle);
586 }
587 
Playback(Canvas * canvas,const Rect * rect)588 void DrawOvalOpItem::Playback(Canvas* canvas, const Rect* rect)
589 {
590     canvas->AttachPaint(paint_);
591     canvas->DrawOval(rect_);
592 }
593 
594 /* DrawCircleOpItem */
595 UNMARSHALLING_REGISTER(DrawCircle, DrawOpItem::CIRCLE_OPITEM,
596     DrawCircleOpItem::Unmarshalling, sizeof(DrawCircleOpItem::ConstructorHandle));
597 
DrawCircleOpItem(const DrawCmdList & cmdList,DrawCircleOpItem::ConstructorHandle * handle)598 DrawCircleOpItem::DrawCircleOpItem(const DrawCmdList& cmdList, DrawCircleOpItem::ConstructorHandle* handle)
599     : DrawWithPaintOpItem(cmdList, handle->paintHandle, CIRCLE_OPITEM),
600       centerPt_(handle->centerPt), radius_(handle->radius) {}
601 
Unmarshalling(const DrawCmdList & cmdList,void * handle)602 std::shared_ptr<DrawOpItem> DrawCircleOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
603 {
604     return std::make_shared<DrawCircleOpItem>(cmdList, static_cast<DrawCircleOpItem::ConstructorHandle*>(handle));
605 }
606 
Marshalling(DrawCmdList & cmdList)607 void DrawCircleOpItem::Marshalling(DrawCmdList& cmdList)
608 {
609     PaintHandle paintHandle;
610     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
611     cmdList.AddOp<ConstructorHandle>(centerPt_, radius_, paintHandle);
612 }
613 
Playback(Canvas * canvas,const Rect * rect)614 void DrawCircleOpItem::Playback(Canvas* canvas, const Rect* rect)
615 {
616     canvas->AttachPaint(paint_);
617     canvas->DrawCircle(centerPt_, radius_);
618 }
619 
620 /* DrawPathOpItem */
621 UNMARSHALLING_REGISTER(DrawPath, DrawOpItem::PATH_OPITEM,
622     DrawPathOpItem::Unmarshalling, sizeof(DrawPathOpItem::ConstructorHandle));
623 
DrawPathOpItem(const DrawCmdList & cmdList,DrawPathOpItem::ConstructorHandle * handle)624 DrawPathOpItem::DrawPathOpItem(const DrawCmdList& cmdList, DrawPathOpItem::ConstructorHandle* handle)
625     : DrawWithPaintOpItem(cmdList, handle->paintHandle, PATH_OPITEM)
626 {
627     path_ = CmdListHelper::GetPathFromCmdList(cmdList, handle->path);
628 }
629 
Unmarshalling(const DrawCmdList & cmdList,void * handle)630 std::shared_ptr<DrawOpItem> DrawPathOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
631 {
632     return std::make_shared<DrawPathOpItem>(cmdList, static_cast<DrawPathOpItem::ConstructorHandle*>(handle));
633 }
634 
Marshalling(DrawCmdList & cmdList)635 void DrawPathOpItem::Marshalling(DrawCmdList& cmdList)
636 {
637     PaintHandle paintHandle;
638     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
639     OpDataHandle pathHandle;
640     if (path_) {
641         pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
642     }
643     cmdList.AddOp<ConstructorHandle>(pathHandle, paintHandle);
644 }
645 
Playback(Canvas * canvas,const Rect * rect)646 void DrawPathOpItem::Playback(Canvas* canvas, const Rect* rect)
647 {
648     if (path_ == nullptr) {
649         LOGD("DrawPathOpItem path is null!");
650         return;
651     }
652     canvas->AttachPaint(paint_);
653     canvas->DrawPath(*path_);
654 }
655 
656 /* DrawBackgroundOpItem */
657 UNMARSHALLING_REGISTER(DrawBackground, DrawOpItem::BACKGROUND_OPITEM,
658     DrawBackgroundOpItem::Unmarshalling, sizeof(DrawBackgroundOpItem::ConstructorHandle));
659 
DrawBackgroundOpItem(const DrawCmdList & cmdList,DrawBackgroundOpItem::ConstructorHandle * handle)660 DrawBackgroundOpItem::DrawBackgroundOpItem(const DrawCmdList& cmdList, DrawBackgroundOpItem::ConstructorHandle* handle)
661     : DrawOpItem(BACKGROUND_OPITEM)
662 {
663     BrushHandleToBrush(handle->brushHandle, cmdList, brush_);
664 }
665 
Unmarshalling(const DrawCmdList & cmdList,void * handle)666 std::shared_ptr<DrawOpItem> DrawBackgroundOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
667 {
668     return std::make_shared<DrawBackgroundOpItem>(
669         cmdList, static_cast<DrawBackgroundOpItem::ConstructorHandle*>(handle));
670 }
671 
Marshalling(DrawCmdList & cmdList)672 void DrawBackgroundOpItem::Marshalling(DrawCmdList& cmdList)
673 {
674     BrushHandle brushHandle;
675     BrushToBrushHandle(brush_, cmdList, brushHandle);
676     cmdList.AddOp<ConstructorHandle>(brushHandle);
677 }
678 
Playback(Canvas * canvas,const Rect * rect)679 void DrawBackgroundOpItem::Playback(Canvas* canvas, const Rect* rect)
680 {
681     canvas->DrawBackground(brush_);
682 }
683 
684 /* DrawShadowStyleOpItem */
685 UNMARSHALLING_REGISTER(DrawShadowStyle, DrawOpItem::SHADOW_STYLE_OPITEM,
686     DrawShadowStyleOpItem::Unmarshalling, sizeof(DrawShadowStyleOpItem::ConstructorHandle));
687 
DrawShadowStyleOpItem(const DrawCmdList & cmdList,DrawShadowStyleOpItem::ConstructorHandle * handle)688 DrawShadowStyleOpItem::DrawShadowStyleOpItem(
689     const DrawCmdList& cmdList, DrawShadowStyleOpItem::ConstructorHandle* handle)
690     : DrawOpItem(SHADOW_STYLE_OPITEM),
691       planeParams_(handle->planeParams),
692       devLightPos_(handle->devLightPos),
693       lightRadius_(handle->lightRadius),
694       ambientColor_(handle->ambientColor),
695       spotColor_(handle->spotColor),
696       flag_(handle->flag),
697       isLimitElevation_(handle->isLimitElevation)
698 {
699     path_ = CmdListHelper::GetPathFromCmdList(cmdList, handle->path);
700 }
701 
Unmarshalling(const DrawCmdList & cmdList,void * handle)702 std::shared_ptr<DrawOpItem> DrawShadowStyleOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
703 {
704     return std::make_shared<DrawShadowStyleOpItem>(
705         cmdList, static_cast<DrawShadowStyleOpItem::ConstructorHandle*>(handle));
706 }
707 
Marshalling(DrawCmdList & cmdList)708 void DrawShadowStyleOpItem::Marshalling(DrawCmdList& cmdList)
709 {
710     OpDataHandle pathHandle;
711     if (path_) {
712         pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
713     }
714     cmdList.AddOp<ConstructorHandle>(
715         pathHandle, planeParams_, devLightPos_, lightRadius_, ambientColor_, spotColor_, flag_, isLimitElevation_);
716 }
717 
Playback(Canvas * canvas,const Rect * rect)718 void DrawShadowStyleOpItem::Playback(Canvas* canvas, const Rect* rect)
719 {
720     if (path_ == nullptr) {
721         LOGD("DrawShadowStyleOpItem path is null!");
722         return;
723     }
724     canvas->DrawShadowStyle(
725         *path_, planeParams_, devLightPos_, lightRadius_, ambientColor_, spotColor_, flag_, isLimitElevation_);
726 }
727 
728 /* DrawShadowOpItem */
729 UNMARSHALLING_REGISTER(DrawShadow, DrawOpItem::SHADOW_OPITEM,
730     DrawShadowOpItem::Unmarshalling, sizeof(DrawShadowOpItem::ConstructorHandle));
731 
DrawShadowOpItem(const DrawCmdList & cmdList,DrawShadowOpItem::ConstructorHandle * handle)732 DrawShadowOpItem::DrawShadowOpItem(const DrawCmdList& cmdList, DrawShadowOpItem::ConstructorHandle* handle)
733     : DrawOpItem(SHADOW_OPITEM), planeParams_(handle->planeParams), devLightPos_(handle->devLightPos),
734     lightRadius_(handle->lightRadius), ambientColor_(handle->ambientColor),
735     spotColor_(handle->spotColor), flag_(handle->flag)
736 {
737     path_ = CmdListHelper::GetPathFromCmdList(cmdList, handle->path);
738 }
739 
Unmarshalling(const DrawCmdList & cmdList,void * handle)740 std::shared_ptr<DrawOpItem> DrawShadowOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
741 {
742     return std::make_shared<DrawShadowOpItem>(cmdList, static_cast<DrawShadowOpItem::ConstructorHandle*>(handle));
743 }
744 
Marshalling(DrawCmdList & cmdList)745 void DrawShadowOpItem::Marshalling(DrawCmdList& cmdList)
746 {
747     OpDataHandle pathHandle;
748     if (path_) {
749         pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
750     }
751     cmdList.AddOp<ConstructorHandle>(
752         pathHandle, planeParams_, devLightPos_, lightRadius_, ambientColor_, spotColor_, flag_);
753 }
754 
Playback(Canvas * canvas,const Rect * rect)755 void DrawShadowOpItem::Playback(Canvas* canvas, const Rect* rect)
756 {
757     if (path_ == nullptr) {
758         LOGD("DrawShadowOpItem path is null!");
759         return;
760     }
761     canvas->DrawShadow(*path_, planeParams_, devLightPos_, lightRadius_,
762                        ambientColor_, spotColor_, flag_);
763 }
764 
765 /* DrawRegionOpItem */
766 UNMARSHALLING_REGISTER(DrawRegion, DrawOpItem::REGION_OPITEM,
767     DrawRegionOpItem::Unmarshalling, sizeof(DrawRegionOpItem::ConstructorHandle));
768 
DrawRegionOpItem(const DrawCmdList & cmdList,DrawRegionOpItem::ConstructorHandle * handle)769 DrawRegionOpItem::DrawRegionOpItem(const DrawCmdList& cmdList, DrawRegionOpItem::ConstructorHandle* handle)
770     : DrawWithPaintOpItem(cmdList, handle->paintHandle, REGION_OPITEM)
771 {
772     region_ = CmdListHelper::GetRegionFromCmdList(cmdList, handle->region);
773 }
774 
Unmarshalling(const DrawCmdList & cmdList,void * handle)775 std::shared_ptr<DrawOpItem> DrawRegionOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
776 {
777     return std::make_shared<DrawRegionOpItem>(cmdList, static_cast<DrawRegionOpItem::ConstructorHandle*>(handle));
778 }
779 
Marshalling(DrawCmdList & cmdList)780 void DrawRegionOpItem::Marshalling(DrawCmdList& cmdList)
781 {
782     PaintHandle paintHandle;
783     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
784     OpDataHandle regionHandle;
785     if (region_) {
786         regionHandle = CmdListHelper::AddRegionToCmdList(cmdList, *region_);
787     }
788     cmdList.AddOp<ConstructorHandle>(regionHandle, paintHandle);
789 }
790 
Playback(Canvas * canvas,const Rect * rect)791 void DrawRegionOpItem::Playback(Canvas* canvas, const Rect* rect)
792 {
793     if (region_ == nullptr) {
794         LOGD("DrawRegionOpItem region is nullptr!");
795         return;
796     }
797     canvas->AttachPaint(paint_);
798     canvas->DrawRegion(*region_);
799 }
800 
801 /* DrawVerticesOpItem */
802 UNMARSHALLING_REGISTER(DrawVertices, DrawOpItem::VERTICES_OPITEM,
803     DrawVerticesOpItem::Unmarshalling, sizeof(DrawVerticesOpItem::ConstructorHandle));
804 
DrawVerticesOpItem(const DrawCmdList & cmdList,DrawVerticesOpItem::ConstructorHandle * handle)805 DrawVerticesOpItem::DrawVerticesOpItem(const DrawCmdList& cmdList, DrawVerticesOpItem::ConstructorHandle* handle)
806     : DrawWithPaintOpItem(cmdList, handle->paintHandle, VERTICES_OPITEM), mode_(handle->mode)
807 {
808     vertices_ = CmdListHelper::GetVerticesFromCmdList(cmdList, handle->vertices);
809 }
810 
Unmarshalling(const DrawCmdList & cmdList,void * handle)811 std::shared_ptr<DrawOpItem> DrawVerticesOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
812 {
813     return std::make_shared<DrawVerticesOpItem>(cmdList, static_cast<DrawVerticesOpItem::ConstructorHandle*>(handle));
814 }
815 
Marshalling(DrawCmdList & cmdList)816 void DrawVerticesOpItem::Marshalling(DrawCmdList& cmdList)
817 {
818     PaintHandle paintHandle;
819     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
820     OpDataHandle opDataHandle;
821     if (vertices_) {
822         opDataHandle = CmdListHelper::AddVerticesToCmdList(cmdList, *vertices_);
823     }
824     cmdList.AddOp<ConstructorHandle>(opDataHandle, mode_, paintHandle);
825 }
826 
Playback(Canvas * canvas,const Rect * rect)827 void DrawVerticesOpItem::Playback(Canvas* canvas, const Rect* rect)
828 {
829     if (vertices_ == nullptr) {
830         LOGD("DrawVerticesOpItem vertices is null");
831         return;
832     }
833     canvas->AttachPaint(paint_);
834     canvas->DrawVertices(*vertices_, mode_);
835 }
836 
837 /* DrawColorOpItem */
838 UNMARSHALLING_REGISTER(DrawColor, DrawOpItem::COLOR_OPITEM,
839     DrawColorOpItem::Unmarshalling, sizeof(DrawColorOpItem::ConstructorHandle));
840 
DrawColorOpItem(DrawColorOpItem::ConstructorHandle * handle)841 DrawColorOpItem::DrawColorOpItem(DrawColorOpItem::ConstructorHandle* handle)
842     : DrawOpItem(COLOR_OPITEM), color_(handle->color), mode_(handle->mode) {}
843 
Unmarshalling(const DrawCmdList & cmdList,void * handle)844 std::shared_ptr<DrawOpItem> DrawColorOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
845 {
846     return std::make_shared<DrawColorOpItem>(static_cast<DrawColorOpItem::ConstructorHandle*>(handle));
847 }
848 
Marshalling(DrawCmdList & cmdList)849 void DrawColorOpItem::Marshalling(DrawCmdList& cmdList)
850 {
851     cmdList.AddOp<ConstructorHandle>(color_, mode_);
852 }
853 
Playback(Canvas * canvas,const Rect * rect)854 void DrawColorOpItem::Playback(Canvas* canvas, const Rect* rect)
855 {
856     canvas->DrawColor(color_, mode_);
857 }
858 
859 /* DrawImageNineOpItem */
860 UNMARSHALLING_REGISTER(DrawImageNine, DrawOpItem::IMAGE_NINE_OPITEM,
861     DrawImageNineOpItem::Unmarshalling, sizeof(DrawImageNineOpItem::ConstructorHandle));
862 
DrawImageNineOpItem(const DrawCmdList & cmdList,DrawImageNineOpItem::ConstructorHandle * handle)863 DrawImageNineOpItem::DrawImageNineOpItem(const DrawCmdList& cmdList, DrawImageNineOpItem::ConstructorHandle* handle)
864     : DrawOpItem(IMAGE_NINE_OPITEM), center_(handle->center), dst_(handle->dst), filter_(handle->filter),
865     hasBrush_(handle->hasBrush)
866 {
867     image_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->image);
868     if (DrawOpItem::holdDrawingImagefunc_) {
869         DrawOpItem::holdDrawingImagefunc_(image_);
870     }
871     if (hasBrush_) {
872         BrushHandleToBrush(handle->brushHandle, cmdList, brush_);
873     }
874 }
875 
Unmarshalling(const DrawCmdList & cmdList,void * handle)876 std::shared_ptr<DrawOpItem> DrawImageNineOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
877 {
878     return std::make_shared<DrawImageNineOpItem>(cmdList, static_cast<DrawImageNineOpItem::ConstructorHandle*>(handle));
879 }
880 
Marshalling(DrawCmdList & cmdList)881 void DrawImageNineOpItem::Marshalling(DrawCmdList& cmdList)
882 {
883     OpDataHandle imageHandle;
884     if (image_) {
885         imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
886     }
887     BrushHandle brushHandle;
888     if (hasBrush_) {
889         BrushToBrushHandle(brush_, cmdList, brushHandle);
890     }
891 
892     cmdList.AddOp<ConstructorHandle>(imageHandle, center_, dst_, filter_, brushHandle, hasBrush_);
893 }
894 
Playback(Canvas * canvas,const Rect * rect)895 void DrawImageNineOpItem::Playback(Canvas* canvas, const Rect* rect)
896 {
897     if (image_ == nullptr) {
898         LOGD("DrawImageNineOpItem image is null");
899         return;
900     }
901     Brush* brushPtr = hasBrush_ ? &brush_ : nullptr;
902     canvas->DrawImageNine(image_.get(), center_, dst_, filter_, brushPtr);
903 }
904 
905 /* DrawImageLatticeOpItem */
906 UNMARSHALLING_REGISTER(DrawImageLattice, DrawOpItem::IMAGE_LATTICE_OPITEM,
907     DrawImageLatticeOpItem::Unmarshalling, sizeof(DrawImageLatticeOpItem::ConstructorHandle));
908 
DrawImageLatticeOpItem(const DrawCmdList & cmdList,DrawImageLatticeOpItem::ConstructorHandle * handle)909 DrawImageLatticeOpItem::DrawImageLatticeOpItem(
910     const DrawCmdList& cmdList, DrawImageLatticeOpItem::ConstructorHandle* handle)
911     : DrawWithPaintOpItem(cmdList, handle->paintHandle, IMAGE_LATTICE_OPITEM),
912     dst_(handle->dst), filter_(handle->filter)
913 {
914     image_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->image);
915     if (DrawOpItem::holdDrawingImagefunc_) {
916         DrawOpItem::holdDrawingImagefunc_(image_);
917     }
918     lattice_ = CmdListHelper::GetLatticeFromCmdList(cmdList, handle->latticeHandle);
919 }
920 
Unmarshalling(const DrawCmdList & cmdList,void * handle)921 std::shared_ptr<DrawOpItem> DrawImageLatticeOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
922 {
923     return std::make_shared<DrawImageLatticeOpItem>(
924         cmdList, static_cast<DrawImageLatticeOpItem::ConstructorHandle*>(handle));
925 }
926 
Marshalling(DrawCmdList & cmdList)927 void DrawImageLatticeOpItem::Marshalling(DrawCmdList& cmdList)
928 {
929     PaintHandle paintHandle;
930     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
931     OpDataHandle imageHandle;
932     if (image_) {
933         imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
934     }
935     auto latticeHandle =  CmdListHelper::AddLatticeToCmdList(cmdList, lattice_);
936     cmdList.AddOp<ConstructorHandle>(imageHandle, latticeHandle, dst_, filter_, paintHandle);
937 }
938 
Playback(Canvas * canvas,const Rect * rect)939 void DrawImageLatticeOpItem::Playback(Canvas* canvas, const Rect* rect)
940 {
941     if (image_ == nullptr) {
942         LOGD("DrawImageNineOpItem image is null");
943         return;
944     }
945     canvas->AttachPaint(paint_);
946     canvas->DrawImageLattice(image_.get(), lattice_, dst_, filter_);
947 }
948 
949 /* DrawAtlasOpItem */
950 UNMARSHALLING_REGISTER(DrawAtlas, DrawOpItem::ATLAS_OPITEM,
951     DrawAtlasOpItem::Unmarshalling, sizeof(DrawAtlasOpItem::ConstructorHandle));
952 
DrawAtlasOpItem(const DrawCmdList & cmdList,DrawAtlasOpItem::ConstructorHandle * handle)953 DrawAtlasOpItem::DrawAtlasOpItem(const DrawCmdList& cmdList, DrawAtlasOpItem::ConstructorHandle* handle)
954     : DrawWithPaintOpItem(cmdList, handle->paintHandle, ATLAS_OPITEM), mode_(handle->mode),
955       samplingOptions_(handle->samplingOptions), hasCullRect_(handle->hasCullRect), cullRect_(handle->cullRect)
956 {
957     atlas_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->atlas);
958     if (DrawOpItem::holdDrawingImagefunc_) {
959         DrawOpItem::holdDrawingImagefunc_(atlas_);
960     }
961     xform_ = CmdListHelper::GetVectorFromCmdList<RSXform>(cmdList, handle->xform);
962     tex_ = CmdListHelper::GetVectorFromCmdList<Rect>(cmdList, handle->tex);
963     colors_ = CmdListHelper::GetVectorFromCmdList<ColorQuad>(cmdList, handle->colors);
964 }
965 
Unmarshalling(const DrawCmdList & cmdList,void * handle)966 std::shared_ptr<DrawOpItem> DrawAtlasOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
967 {
968     return std::make_shared<DrawAtlasOpItem>(cmdList, static_cast<DrawAtlasOpItem::ConstructorHandle*>(handle));
969 }
970 
Marshalling(DrawCmdList & cmdList)971 void DrawAtlasOpItem::Marshalling(DrawCmdList& cmdList)
972 {
973     PaintHandle paintHandle;
974     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
975     OpDataHandle imageHandle;
976     if (atlas_) {
977         imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *atlas_);
978     }
979     auto xformData = CmdListHelper::AddVectorToCmdList<RSXform>(cmdList, xform_);
980     auto texData = CmdListHelper::AddVectorToCmdList<Rect>(cmdList, tex_);
981     auto colorData = CmdListHelper::AddVectorToCmdList<ColorQuad>(cmdList, colors_);
982     cmdList.AddOp<ConstructorHandle>(imageHandle, xformData, texData, colorData, mode_, samplingOptions_,
983         hasCullRect_, cullRect_, paintHandle);
984 }
985 
Playback(Canvas * canvas,const Rect * rect)986 void DrawAtlasOpItem::Playback(Canvas* canvas, const Rect* rect)
987 {
988     if (atlas_ == nullptr) {
989         LOGD("DrawAtlasOpItem atlas is null");
990         return;
991     }
992     canvas->AttachPaint(paint_);
993     Rect* rectPtr = hasCullRect_ ? &cullRect_ : nullptr;
994     canvas->DrawAtlas(atlas_.get(), xform_.data(), tex_.data(), colors_.data(), xform_.size(), mode_,
995         samplingOptions_, rectPtr);
996 }
997 
998 /* DrawBitmapOpItem */
999 UNMARSHALLING_REGISTER(DrawBitmap, DrawOpItem::BITMAP_OPITEM,
1000     DrawBitmapOpItem::Unmarshalling, sizeof(DrawBitmapOpItem::ConstructorHandle));
1001 
DrawBitmapOpItem(const DrawCmdList & cmdList,DrawBitmapOpItem::ConstructorHandle * handle)1002 DrawBitmapOpItem::DrawBitmapOpItem(const DrawCmdList& cmdList, DrawBitmapOpItem::ConstructorHandle* handle)
1003     : DrawWithPaintOpItem(cmdList, handle->paintHandle, BITMAP_OPITEM), px_(handle->px), py_(handle->py)
1004 {
1005     bitmap_ = CmdListHelper::GetBitmapFromCmdList(cmdList, handle->bitmap);
1006 }
1007 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1008 std::shared_ptr<DrawOpItem> DrawBitmapOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1009 {
1010     return std::make_shared<DrawBitmapOpItem>(cmdList, static_cast<DrawBitmapOpItem::ConstructorHandle*>(handle));
1011 }
1012 
Marshalling(DrawCmdList & cmdList)1013 void DrawBitmapOpItem::Marshalling(DrawCmdList& cmdList)
1014 {
1015     PaintHandle paintHandle;
1016     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1017     ImageHandle bitmapHandle;
1018     if (bitmap_) {
1019         bitmapHandle = CmdListHelper::AddBitmapToCmdList(cmdList, *bitmap_);
1020     }
1021     cmdList.AddOp<ConstructorHandle>(bitmapHandle, px_, py_, paintHandle);
1022 }
1023 
Playback(Canvas * canvas,const Rect * rect)1024 void DrawBitmapOpItem::Playback(Canvas* canvas, const Rect* rect)
1025 {
1026     if (bitmap_ == nullptr) {
1027         LOGD("DrawBitmapOpItem bitmap is null");
1028         return;
1029     }
1030     canvas->AttachPaint(paint_);
1031     canvas->DrawBitmap(*bitmap_, px_, py_);
1032 }
1033 
1034 /* DrawImageOpItem */
1035 UNMARSHALLING_REGISTER(DrawImage, DrawOpItem::IMAGE_OPITEM,
1036     DrawImageOpItem::Unmarshalling, sizeof(DrawImageOpItem::ConstructorHandle));
1037 
DrawImageOpItem(const DrawCmdList & cmdList,DrawImageOpItem::ConstructorHandle * handle)1038 DrawImageOpItem::DrawImageOpItem(const DrawCmdList& cmdList, DrawImageOpItem::ConstructorHandle* handle)
1039     : DrawWithPaintOpItem(cmdList, handle->paintHandle, IMAGE_OPITEM), px_(handle->px), py_(handle->py),
1040       samplingOptions_(handle->samplingOptions)
1041 {
1042     image_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->image);
1043     if (DrawOpItem::holdDrawingImagefunc_) {
1044         DrawOpItem::holdDrawingImagefunc_(image_);
1045     }
1046 }
1047 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1048 std::shared_ptr<DrawOpItem> DrawImageOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1049 {
1050     return std::make_shared<DrawImageOpItem>(cmdList, static_cast<DrawImageOpItem::ConstructorHandle*>(handle));
1051 }
1052 
Marshalling(DrawCmdList & cmdList)1053 void DrawImageOpItem::Marshalling(DrawCmdList& cmdList)
1054 {
1055     PaintHandle paintHandle;
1056     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1057     OpDataHandle imageHandle;
1058     if (image_) {
1059         imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
1060     }
1061     cmdList.AddOp<ConstructorHandle>(imageHandle, px_, py_, samplingOptions_, paintHandle);
1062 }
1063 
Playback(Canvas * canvas,const Rect * rect)1064 void DrawImageOpItem::Playback(Canvas* canvas, const Rect* rect)
1065 {
1066     if (image_ == nullptr) {
1067         LOGD("DrawImageOpItem image is null");
1068         return;
1069     }
1070     canvas->AttachPaint(paint_);
1071     canvas->DrawImage(*image_, px_, py_, samplingOptions_);
1072 }
1073 
1074 /* DrawImageRectOpItem */
1075 UNMARSHALLING_REGISTER(DrawImageRect, DrawOpItem::IMAGE_RECT_OPITEM,
1076     DrawImageRectOpItem::Unmarshalling, sizeof(DrawImageRectOpItem::ConstructorHandle));
1077 
DrawImageRectOpItem(const DrawCmdList & cmdList,DrawImageRectOpItem::ConstructorHandle * handle)1078 DrawImageRectOpItem::DrawImageRectOpItem(const DrawCmdList& cmdList, DrawImageRectOpItem::ConstructorHandle* handle)
1079     : DrawWithPaintOpItem(cmdList, handle->paintHandle, IMAGE_RECT_OPITEM), src_(handle->src), dst_(handle->dst),
1080       sampling_(handle->sampling), constraint_(handle->constraint), isForeground_(handle->isForeground)
1081 {
1082     image_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->image);
1083     if (DrawOpItem::holdDrawingImagefunc_) {
1084         DrawOpItem::holdDrawingImagefunc_(image_);
1085     }
1086 }
1087 
DrawImageRectOpItem(const Image & image,const Rect & src,const Rect & dst,const SamplingOptions & sampling,SrcRectConstraint constraint,const Paint & paint,bool isForeground)1088 DrawImageRectOpItem::DrawImageRectOpItem(const Image& image, const Rect& src,
1089     const Rect& dst, const SamplingOptions& sampling,
1090     SrcRectConstraint constraint, const Paint& paint, bool isForeground)
1091     : DrawWithPaintOpItem(paint, DrawOpItem::IMAGE_RECT_OPITEM), src_(src), dst_(dst), sampling_(sampling),
1092     constraint_(constraint), image_(std::make_shared<Image>(image)), isForeground_(isForeground)
1093 {
1094     if (DrawOpItem::holdDrawingImagefunc_) {
1095         DrawOpItem::holdDrawingImagefunc_(image_);
1096     }
1097 }
1098 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1099 std::shared_ptr<DrawOpItem> DrawImageRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1100 {
1101     return std::make_shared<DrawImageRectOpItem>(cmdList, static_cast<DrawImageRectOpItem::ConstructorHandle*>(handle));
1102 }
1103 
Marshalling(DrawCmdList & cmdList)1104 void DrawImageRectOpItem::Marshalling(DrawCmdList& cmdList)
1105 {
1106     PaintHandle paintHandle;
1107     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1108     OpDataHandle imageHandle;
1109     if (image_) {
1110         imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
1111     }
1112     cmdList.AddOp<ConstructorHandle>(imageHandle, src_, dst_, sampling_, constraint_, paintHandle);
1113 }
1114 
Playback(Canvas * canvas,const Rect * rect)1115 void DrawImageRectOpItem::Playback(Canvas* canvas, const Rect* rect)
1116 {
1117     if (image_ == nullptr) {
1118         LOGD("DrawImageRectOpItem image is null");
1119         return;
1120     }
1121     if (isForeground_) {
1122         AutoCanvasRestore acr(*canvas, false);
1123         SaveLayerOps ops;
1124         canvas->SaveLayer(ops);
1125         canvas->AttachPaint(paint_);
1126         canvas->DrawImageRect(*image_, src_, dst_, sampling_, constraint_);
1127         Brush brush;
1128         brush.SetColor(canvas->GetEnvForegroundColor());
1129         brush.SetBlendMode(Drawing::BlendMode::SRC_IN);
1130         canvas->DrawBackground(brush);
1131         return;
1132     }
1133     canvas->AttachPaint(paint_);
1134     canvas->DrawImageRect(*image_, src_, dst_, sampling_, constraint_);
1135 }
1136 
1137 /* DrawRecordCmdOpItem */
1138 UNMARSHALLING_REGISTER(DrawRecordCmd, DrawOpItem::RECORD_CMD_OPITEM,
1139     DrawRecordCmdOpItem::Unmarshalling, sizeof(DrawRecordCmdOpItem::ConstructorHandle));
1140 
DrawRecordCmdOpItem(const DrawCmdList & cmdList,DrawRecordCmdOpItem::ConstructorHandle * handle)1141 DrawRecordCmdOpItem::DrawRecordCmdOpItem(
1142     const DrawCmdList& cmdList, DrawRecordCmdOpItem::ConstructorHandle* handle)
1143     : DrawOpItem(RECORD_CMD_OPITEM), hasBrush_(handle->hasBrush)
1144 {
1145     recordCmd_ = CmdListHelper::GetRecordCmdFromCmdList(cmdList, handle->recordCmdHandle);
1146     matrix_.SetAll(handle->matrixBuffer);
1147     if (hasBrush_) {
1148         BrushHandleToBrush(handle->brushHandle, cmdList, brush_);
1149     }
1150 }
1151 
DrawRecordCmdOpItem(const std::shared_ptr<RecordCmd> & recordCmd,const Matrix * matrix,const Brush * brush)1152 DrawRecordCmdOpItem::DrawRecordCmdOpItem(const std::shared_ptr<RecordCmd>& recordCmd,
1153     const Matrix* matrix, const Brush* brush)
1154     : DrawOpItem(RECORD_CMD_OPITEM), recordCmd_(recordCmd)
1155 {
1156     if (matrix != nullptr) {
1157         matrix_ = *matrix;
1158     }
1159     if (brush != nullptr) {
1160         hasBrush_ = true;
1161         brush_ = *brush;
1162     }
1163 }
1164 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1165 std::shared_ptr<DrawOpItem> DrawRecordCmdOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1166 {
1167     return std::make_shared<DrawRecordCmdOpItem>(
1168         cmdList, static_cast<DrawRecordCmdOpItem::ConstructorHandle*>(handle));
1169 }
1170 
Marshalling(DrawCmdList & cmdList)1171 void DrawRecordCmdOpItem::Marshalling(DrawCmdList& cmdList)
1172 {
1173     auto recordCmdHandle = CmdListHelper::AddRecordCmdToCmdList(cmdList, recordCmd_);
1174     Matrix::Buffer matrixBuffer;
1175     matrix_.GetAll(matrixBuffer);
1176     BrushHandle brushHandle;
1177     if (hasBrush_) {
1178         BrushToBrushHandle(brush_, cmdList, brushHandle);
1179     }
1180     cmdList.AddOp<ConstructorHandle>(recordCmdHandle,
1181         matrixBuffer, hasBrush_, brushHandle);
1182 }
1183 
Playback(Canvas * canvas,const Rect * rect)1184 void DrawRecordCmdOpItem::Playback(Canvas* canvas, const Rect* rect)
1185 {
1186     Brush* brushPtr = hasBrush_ ? &brush_ : nullptr;
1187     canvas->DrawRecordCmd(recordCmd_, &matrix_, brushPtr);
1188 }
1189 
1190 /* DrawPictureOpItem */
1191 UNMARSHALLING_REGISTER(DrawPicture, DrawOpItem::PICTURE_OPITEM,
1192     DrawPictureOpItem::Unmarshalling, sizeof(DrawPictureOpItem::ConstructorHandle));
1193 
DrawPictureOpItem(const DrawCmdList & cmdList,DrawPictureOpItem::ConstructorHandle * handle)1194 DrawPictureOpItem::DrawPictureOpItem(const DrawCmdList& cmdList, DrawPictureOpItem::ConstructorHandle* handle)
1195     : DrawOpItem(PICTURE_OPITEM)
1196 {
1197     picture_ = CmdListHelper::GetPictureFromCmdList(cmdList, handle->picture);
1198 }
1199 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1200 std::shared_ptr<DrawOpItem> DrawPictureOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1201 {
1202     return std::make_shared<DrawPictureOpItem>(cmdList, static_cast<DrawPictureOpItem::ConstructorHandle*>(handle));
1203 }
1204 
Marshalling(DrawCmdList & cmdList)1205 void DrawPictureOpItem::Marshalling(DrawCmdList& cmdList)
1206 {
1207     OpDataHandle pictureHandle;
1208     if (picture_) {
1209         pictureHandle = CmdListHelper::AddPictureToCmdList(cmdList, *picture_);
1210     }
1211     cmdList.AddOp<ConstructorHandle>(pictureHandle);
1212 }
1213 
Playback(Canvas * canvas,const Rect * rect)1214 void DrawPictureOpItem::Playback(Canvas* canvas, const Rect* rect)
1215 {
1216     if (picture_ == nullptr) {
1217         LOGD("DrawPictureOpItem picture is null");
1218         return;
1219     }
1220     canvas->DrawPicture(*picture_);
1221 }
1222 
1223 /* DrawTextBlobOpItem */
1224 UNMARSHALLING_REGISTER(DrawTextBlob, DrawOpItem::TEXT_BLOB_OPITEM,
1225     DrawTextBlobOpItem::Unmarshalling, sizeof(DrawTextBlobOpItem::ConstructorHandle));
1226 
SimplifyPaint(ColorQuad colorQuad,Paint & paint)1227 void SimplifyPaint(ColorQuad colorQuad, Paint& paint)
1228 {
1229     Color color{colorQuad};
1230     paint.SetColor(color);
1231     paint.SetShaderEffect(nullptr);
1232     if (paint.HasFilter()) {
1233         Filter filter = paint.GetFilter();
1234         if (filter.GetColorFilter() != nullptr) {
1235             filter.SetColorFilter(nullptr);
1236             paint.SetFilter(filter);
1237         }
1238     }
1239     paint.SetWidth(1.04); // 1.04 is empirical value
1240     paint.SetJoinStyle(Pen::JoinStyle::ROUND_JOIN);
1241 }
1242 
DrawTextBlobOpItem(const DrawCmdList & cmdList,DrawTextBlobOpItem::ConstructorHandle * handle)1243 DrawTextBlobOpItem::DrawTextBlobOpItem(const DrawCmdList& cmdList, DrawTextBlobOpItem::ConstructorHandle* handle)
1244     : DrawWithPaintOpItem(cmdList, handle->paintHandle, TEXT_BLOB_OPITEM), x_(handle->x), y_(handle->y)
1245 {
1246     textBlob_ = CmdListHelper::GetTextBlobFromCmdList(cmdList, handle->textBlob, handle->globalUniqueId);
1247 }
1248 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1249 std::shared_ptr<DrawOpItem> DrawTextBlobOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1250 {
1251     return std::make_shared<DrawTextBlobOpItem>(cmdList, static_cast<DrawTextBlobOpItem::ConstructorHandle*>(handle));
1252 }
1253 
Marshalling(DrawCmdList & cmdList)1254 void DrawTextBlobOpItem::Marshalling(DrawCmdList& cmdList)
1255 {
1256     static uint64_t shiftedPid = static_cast<uint64_t>(GetRealPid()) << 32; // 32 for 64-bit unsignd number shift
1257     PaintHandle paintHandle;
1258     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1259     TextBlob::Context ctx {nullptr, false};
1260     auto textBlobHandle = CmdListHelper::AddTextBlobToCmdList(cmdList, textBlob_.get(), &ctx);
1261     uint64_t globalUniqueId = 0;
1262     if (ctx.GetTypeface() != nullptr) {
1263         uint32_t typefaceId = ctx.GetTypeface()->GetUniqueID();
1264         globalUniqueId = (shiftedPid | typefaceId);
1265     }
1266 
1267     cmdList.AddOp<ConstructorHandle>(textBlobHandle, globalUniqueId, x_, y_, paintHandle);
1268 }
1269 
Playback(Canvas * canvas,const Rect * rect)1270 void DrawTextBlobOpItem::Playback(Canvas* canvas, const Rect* rect)
1271 {
1272     if (textBlob_ == nullptr) {
1273         LOGD("DrawTextBlobOpItem textBlob is null");
1274         return;
1275     }
1276     RectI globalClipBounds = canvas->GetDeviceClipBounds();
1277     bool saveFlag = false;
1278     if (globalClipBounds.GetWidth() == 1 || globalClipBounds.GetHeight() == 1) {
1279         // In this case, the clip area for textblob must have AA.
1280         Matrix m = canvas->GetTotalMatrix();
1281         canvas->Save();
1282         canvas->SetMatrix(m);
1283         auto bounds = textBlob_->Bounds();
1284         if (bounds && bounds->IsValid()) {
1285             canvas->ClipRect(*bounds, ClipOp::INTERSECT, true);
1286         }
1287         saveFlag = true;
1288     }
1289     if (canvas->isHighContrastEnabled()) {
1290         LOGD("DrawTextBlobOpItem::Playback highContrastEnabled, %{public}s, %{public}d", __FUNCTION__, __LINE__);
1291         DrawHighContrastEnabled(canvas);
1292     } else {
1293         canvas->AttachPaint(paint_);
1294         canvas->DrawTextBlob(textBlob_.get(), x_, y_);
1295     }
1296     if (saveFlag) {
1297         canvas->Restore();
1298     }
1299 }
1300 
GetOffScreenSurfaceAndCanvas(const Canvas & canvas,std::shared_ptr<Drawing::Surface> & offScreenSurface,std::shared_ptr<Canvas> & offScreenCanvas) const1301 bool DrawTextBlobOpItem::GetOffScreenSurfaceAndCanvas(const Canvas& canvas,
1302     std::shared_ptr<Drawing::Surface>& offScreenSurface, std::shared_ptr<Canvas>& offScreenCanvas) const
1303 {
1304     auto surface = canvas.GetSurface();
1305     auto textBlobBounds = textBlob_->Bounds();
1306     if (!surface || !textBlobBounds) {
1307         return false;
1308     }
1309     offScreenSurface = surface->MakeSurface(textBlobBounds->GetWidth(), textBlobBounds->GetHeight());
1310     if (!offScreenSurface) {
1311         return false;
1312     }
1313     offScreenCanvas = offScreenSurface->GetCanvas();
1314     if (!offScreenCanvas) {
1315         return false;
1316     }
1317     offScreenCanvas->Translate(-textBlobBounds->GetLeft(), -textBlobBounds->GetTop());
1318     return true;
1319 }
1320 
DrawHighContrastEnabled(Canvas * canvas) const1321 void DrawTextBlobOpItem::DrawHighContrastEnabled(Canvas* canvas) const
1322 {
1323     ColorQuad colorQuad = paint_.GetColor().CastToColorQuad();
1324     if (Color::ColorQuadGetA(colorQuad) == 0 || paint_.HasFilter()) {
1325         canvas->AttachPaint(paint_);
1326         canvas->DrawTextBlob(textBlob_.get(), x_, y_);
1327         return;
1328     }
1329     // in case of perceptible transparent, text should be drawn offscreen to avoid stroke and content overlap.
1330     if (canvas->GetAlphaSaveCount() > 0 && canvas->GetAlpha() < HIGH_CONTRAST_OFFSCREEN_THREASHOLD) {
1331         std::shared_ptr<Drawing::Surface> offScreenSurface;
1332         std::shared_ptr<Canvas> offScreenCanvas;
1333         if (GetOffScreenSurfaceAndCanvas(*canvas, offScreenSurface, offScreenCanvas)) {
1334             DrawHighContrast(offScreenCanvas.get(), true);
1335             offScreenCanvas->Flush();
1336             auto image = offScreenSurface->GetImageSnapshot();
1337             if (image == nullptr) {
1338                 return;
1339             }
1340             Drawing::Brush paint;
1341             paint.SetAntiAlias(true);
1342             canvas->AttachBrush(paint);
1343             Drawing::SamplingOptions sampling =
1344                 Drawing::SamplingOptions(Drawing::FilterMode::NEAREST, Drawing::MipmapMode::NEAREST);
1345             canvas->DrawImage(*image, x_ + textBlob_->Bounds()->GetLeft(),
1346                 y_ + textBlob_->Bounds()->GetTop(), sampling);
1347             canvas->DetachBrush();
1348             return;
1349         }
1350     }
1351     DrawHighContrast(canvas);
1352 }
1353 
DrawHighContrast(Canvas * canvas,bool offScreen) const1354 void DrawTextBlobOpItem::DrawHighContrast(Canvas* canvas, bool offScreen) const
1355 {
1356     ColorQuad colorQuad = paint_.GetColor().CastToColorQuad();
1357     uint32_t channelSum = Color::ColorQuadGetR(colorQuad) + Color::ColorQuadGetG(colorQuad) +
1358         Color::ColorQuadGetB(colorQuad);
1359     bool flag = channelSum < 594; // 594 is empirical value
1360 
1361     // draw outline stroke with pen
1362     Drawing::Pen outlinePen;
1363     outlinePen.SetColor(flag ? Color::COLOR_WHITE : Color::COLOR_BLACK);
1364     outlinePen.SetAntiAlias(true);
1365     outlinePen.SetBlenderEnabled(false);
1366     canvas->AttachPen(outlinePen);
1367     offScreen ? canvas->DrawTextBlob(textBlob_.get(), 0, 0) : canvas->DrawTextBlob(textBlob_.get(), x_, y_);
1368 
1369     // draw inner content with brush
1370     Drawing::Brush innerBrush;
1371     innerBrush.SetColor(flag ? Color::COLOR_BLACK : Color::COLOR_WHITE);
1372     canvas->DetachPen();
1373     canvas->AttachBrush(innerBrush);
1374     offScreen ? canvas->DrawTextBlob(textBlob_.get(), 0, 0) : canvas->DrawTextBlob(textBlob_.get(), x_, y_);
1375 }
1376 
GenerateCachedOpItem(DrawCmdList & cmdList,const TextBlob * textBlob,scalar x,scalar y,Paint & p)1377 bool DrawTextBlobOpItem::ConstructorHandle::GenerateCachedOpItem(
1378     DrawCmdList& cmdList, const TextBlob* textBlob, scalar x, scalar y, Paint& p)
1379 {
1380     if (!textBlob) {
1381         LOGD("textBlob nullptr, %{public}s, %{public}d", __FUNCTION__, __LINE__);
1382         return false;
1383     }
1384 
1385     auto bounds = textBlob->Bounds();
1386     if (!bounds || !bounds->IsValid()) {
1387         return false;
1388     }
1389     bounds->Offset(x, y);
1390     bounds->MakeOutset(TEXT_BLOB_CACHE_MARGIN, TEXT_BLOB_CACHE_MARGIN);
1391     // create CPU raster surface
1392     Drawing::ImageInfo offscreenInfo { bounds->GetWidth(), bounds->GetHeight(),
1393         Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL, nullptr};
1394     std::shared_ptr<Surface> offscreenSurface = Surface::MakeRaster(offscreenInfo);
1395     if (offscreenSurface == nullptr) {
1396         return false;
1397     }
1398     auto offscreenCanvas = offscreenSurface->GetCanvas();
1399     if (offscreenCanvas == nullptr) {
1400         return false;
1401     }
1402     if (bounds->GetLeft() != 0 || bounds->GetTop() != 0) {
1403         offscreenCanvas->Translate(-bounds->GetLeft(), -bounds->GetTop());
1404     }
1405 
1406     //OffscreenCanvas used once, detach is unnecessary, FakeBrush/Pen avoid affecting ImageRectOp, attach is necessary.
1407     bool isForeground = false;
1408     if (p.GetColor() == Drawing::Color::COLOR_FOREGROUND) {
1409         isForeground = true;
1410         p.SetColor(Drawing::Color::COLOR_BLACK);
1411     }
1412     offscreenCanvas->AttachPaint(p);
1413     offscreenCanvas->DrawTextBlob(textBlob, x, y);
1414 
1415     std::shared_ptr<Image> image = offscreenSurface->GetImageSnapshot();
1416     if (image == nullptr) {
1417         return false;
1418     }
1419     Drawing::Rect src(0, 0, image->GetWidth(), image->GetHeight());
1420     Drawing::Rect dst(bounds->GetLeft(), bounds->GetTop(),
1421         bounds->GetLeft() + image->GetWidth(), bounds->GetTop() + image->GetHeight());
1422     SamplingOptions sampling(FilterMode::LINEAR, MipmapMode::LINEAR);
1423     auto imageHandle = CmdListHelper::AddImageToCmdList(cmdList, image);
1424     PaintHandle fakePaintHandle;
1425     fakePaintHandle.isAntiAlias = true;
1426     fakePaintHandle.style = Paint::PaintStyle::PAINT_FILL;
1427     cmdList.AddOp<DrawImageRectOpItem::ConstructorHandle>(
1428         imageHandle, src, dst, sampling, SrcRectConstraint::STRICT_SRC_RECT_CONSTRAINT, fakePaintHandle, isForeground);
1429     return true;
1430 }
1431 
GenerateCachedOpItem(DrawCmdList & cmdList,Canvas * canvas)1432 bool DrawTextBlobOpItem::ConstructorHandle::GenerateCachedOpItem(DrawCmdList& cmdList, Canvas* canvas)
1433 {
1434     std::shared_ptr<TextBlob> textBlob_ = CmdListHelper::GetTextBlobFromCmdList(cmdList, textBlob, globalUniqueId);
1435     if (!textBlob_) {
1436         LOGD("textBlob nullptr, %{public}s, %{public}d", __FUNCTION__, __LINE__);
1437         return false;
1438     }
1439 
1440     auto bounds = textBlob_->Bounds();
1441     if (!bounds || !bounds->IsValid()) {
1442         return false;
1443     }
1444     bounds->Offset(x, y);
1445 
1446     std::shared_ptr<Surface> offscreenSurface = nullptr;
1447 
1448     if (auto surface = canvas != nullptr ? canvas->GetSurface() : nullptr) {
1449         // create GPU accelerated surface if possible
1450         offscreenSurface = surface->MakeSurface(bounds->GetWidth(), bounds->GetHeight());
1451     } else {
1452         // create CPU raster surface
1453         Drawing::ImageInfo offscreenInfo { bounds->GetWidth(), bounds->GetHeight(),
1454             Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL, nullptr};
1455         offscreenSurface = Surface::MakeRaster(offscreenInfo);
1456     }
1457     if (offscreenSurface == nullptr) {
1458         return false;
1459     }
1460 
1461     Canvas* offscreenCanvas = offscreenSurface->GetCanvas().get();
1462     if (!offscreenCanvas) {
1463         return false;
1464     }
1465 
1466     // align draw op to [0, 0]
1467     if (bounds->GetLeft() != 0 || bounds->GetTop() != 0) {
1468         offscreenCanvas->Translate(-bounds->GetLeft(), -bounds->GetTop());
1469     }
1470 
1471     Paint p;
1472     GeneratePaintFromHandle(paintHandle, cmdList, p);
1473     offscreenCanvas->AttachPaint(p);
1474     offscreenCanvas->DrawTextBlob(textBlob_.get(), x, y);
1475 
1476     std::shared_ptr<Image> image = offscreenSurface->GetImageSnapshot();
1477     if (image == nullptr) {
1478         return false;
1479     }
1480     Drawing::Rect src(0, 0, image->GetWidth(), image->GetHeight());
1481     Drawing::Rect dst(bounds->GetLeft(), bounds->GetTop(),
1482         bounds->GetLeft() + image->GetWidth(), bounds->GetTop() + image->GetHeight());
1483     SamplingOptions sampling;
1484     auto imageHandle = CmdListHelper::AddImageToCmdList(cmdList, image);
1485     PaintHandle fakePaintHandle;
1486     fakePaintHandle.isAntiAlias = true;
1487     fakePaintHandle.style = Paint::PaintStyle::PAINT_FILL;
1488     cmdList.AddOp<DrawImageRectOpItem::ConstructorHandle>(imageHandle, src, dst, sampling,
1489         SrcRectConstraint::FAST_SRC_RECT_CONSTRAINT, fakePaintHandle);
1490     return true;
1491 }
1492 
GenerateCachedOpItem(Canvas * canvas)1493 std::shared_ptr<DrawImageRectOpItem> DrawTextBlobOpItem::GenerateCachedOpItem(Canvas* canvas)
1494 {
1495     if (!textBlob_) {
1496         LOGD("textBlob nullptr, %{public}s, %{public}d", __FUNCTION__, __LINE__);
1497         return nullptr;
1498     }
1499 
1500     auto bounds = textBlob_->Bounds();
1501     if (!bounds || !bounds->IsValid()) {
1502         return nullptr;
1503     }
1504     bounds->Offset(x_, y_);
1505 
1506     std::shared_ptr<Surface> offscreenSurface = nullptr;
1507 
1508     if (auto surface = canvas != nullptr ? canvas->GetSurface() : nullptr) {
1509         // create GPU accelerated surface if possible
1510         offscreenSurface = surface->MakeSurface(bounds->GetWidth(), bounds->GetHeight());
1511     } else {
1512         // create CPU raster surface
1513         Drawing::ImageInfo offscreenInfo { bounds->GetWidth(), bounds->GetHeight(),
1514             Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL, nullptr};
1515         offscreenSurface = Surface::MakeRaster(offscreenInfo);
1516     }
1517     if (offscreenSurface == nullptr) {
1518         return nullptr;
1519     }
1520 
1521     Canvas* offscreenCanvas = offscreenSurface->GetCanvas().get();
1522     if (!offscreenCanvas) {
1523         return nullptr;
1524     }
1525 
1526     // align draw op to [0, 0]
1527     if (bounds->GetLeft() != 0 || bounds->GetTop() != 0) {
1528         offscreenCanvas->Translate(-bounds->GetLeft(), -bounds->GetTop());
1529     }
1530 
1531     Playback(offscreenCanvas, nullptr);
1532 
1533     std::shared_ptr<Image> image = offscreenSurface->GetImageSnapshot();
1534     if (image == nullptr) {
1535         return nullptr;
1536     }
1537     Drawing::Rect src(0, 0, image->GetWidth(), image->GetHeight());
1538     Drawing::Rect dst(bounds->GetLeft(), bounds->GetTop(), bounds->GetRight(), bounds->GetBottom());
1539     Paint fakePaint;
1540     fakePaint.SetStyle(Paint::PaintStyle::PAINT_FILL);
1541     fakePaint.SetAntiAlias(true);
1542     return std::make_shared<DrawImageRectOpItem>(*image, src, dst, SamplingOptions(),
1543         SrcRectConstraint::FAST_SRC_RECT_CONSTRAINT, fakePaint);
1544 }
1545 
1546 /* DrawSymbolOpItem */
1547 UNMARSHALLING_REGISTER(DrawSymbol, DrawOpItem::SYMBOL_OPITEM,
1548     DrawSymbolOpItem::Unmarshalling, sizeof(DrawSymbolOpItem::ConstructorHandle));
1549 
DrawSymbolOpItem(const DrawCmdList & cmdList,DrawSymbolOpItem::ConstructorHandle * handle)1550 DrawSymbolOpItem::DrawSymbolOpItem(const DrawCmdList& cmdList, DrawSymbolOpItem::ConstructorHandle* handle)
1551     : DrawWithPaintOpItem(cmdList, handle->paintHandle, SYMBOL_OPITEM), locate_(handle->locate)
1552 {
1553     symbol_ = CmdListHelper::GetSymbolFromCmdList(cmdList, handle->symbolHandle);
1554 }
1555 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1556 std::shared_ptr<DrawOpItem> DrawSymbolOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1557 {
1558     return std::make_shared<DrawSymbolOpItem>(cmdList, static_cast<DrawSymbolOpItem::ConstructorHandle*>(handle));
1559 }
1560 
Marshalling(DrawCmdList & cmdList)1561 void DrawSymbolOpItem::Marshalling(DrawCmdList& cmdList)
1562 {
1563     PaintHandle paintHandle;
1564     GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1565     auto symbolHandle = CmdListHelper::AddSymbolToCmdList(cmdList, symbol_);
1566     cmdList.AddOp<ConstructorHandle>(symbolHandle, locate_, paintHandle);
1567 }
1568 
Playback(Canvas * canvas,const Rect * rect)1569 void DrawSymbolOpItem::Playback(Canvas* canvas, const Rect* rect)
1570 {
1571     if (!canvas) {
1572         LOGD("SymbolOpItem::Playback failed cause by canvas is nullptr");
1573         return;
1574     }
1575     Path path(symbol_.path_);
1576 
1577     // 1.0 move path
1578     path.Offset(locate_.GetX(), locate_.GetY());
1579 
1580     // 2.0 split path
1581     std::vector<Path> paths;
1582     DrawingHMSymbol::PathOutlineDecompose(path, paths);
1583     std::vector<Path> pathLayers;
1584     DrawingHMSymbol::MultilayerPath(symbol_.symbolInfo_.layers, paths, pathLayers);
1585 
1586     // 3.0 set paint
1587     Paint paintCopy = paint_;
1588     paintCopy.SetAntiAlias(true);
1589     paintCopy.SetStyle(Paint::PaintStyle::PAINT_FILL_STROKE);
1590     paintCopy.SetWidth(0.0f);
1591     paintCopy.SetJoinStyle(Pen::JoinStyle::ROUND_JOIN);
1592 
1593     // draw path
1594     std::vector<DrawingRenderGroup> groups = symbol_.symbolInfo_.renderGroups;
1595     LOGD("SymbolOpItem::Draw RenderGroup size %{public}d", static_cast<int>(groups.size()));
1596     if (groups.size() == 0) {
1597         canvas->AttachPaint(paintCopy);
1598         canvas->DrawPath(path);
1599     }
1600     for (auto group : groups) {
1601         Path multPath;
1602         MergeDrawingPath(multPath, group, pathLayers);
1603         // color
1604         paintCopy.SetColor(Color::ColorQuadSetARGB(0xFF, group.color.r, group.color.g, group.color.b));
1605         paintCopy.SetAlphaF(group.color.a);
1606         canvas->AttachPaint(paintCopy);
1607         canvas->DrawPath(multPath);
1608     }
1609 }
1610 
MergeDrawingPath(Drawing::Path & multPath,Drawing::DrawingRenderGroup & group,std::vector<Drawing::Path> & pathLayers)1611 void DrawSymbolOpItem::MergeDrawingPath(
1612     Drawing::Path& multPath, Drawing::DrawingRenderGroup& group, std::vector<Drawing::Path>& pathLayers)
1613 {
1614     for (auto groupInfo : group.groupInfos) {
1615         Drawing::Path pathTemp;
1616         for (auto k : groupInfo.layerIndexes) {
1617             if (k >= pathLayers.size()) {
1618                 continue;
1619             }
1620             pathTemp.AddPath(pathLayers[k]);
1621         }
1622         for (size_t h : groupInfo.maskIndexes) {
1623             if (h >= pathLayers.size()) {
1624                 continue;
1625             }
1626             Drawing::Path outPath;
1627             auto isOk = outPath.Op(pathTemp, pathLayers[h], Drawing::PathOp::DIFFERENCE);
1628             if (isOk) {
1629                 pathTemp = outPath;
1630             }
1631         }
1632         multPath.AddPath(pathTemp);
1633     }
1634 }
1635 
1636 /* ClipRectOpItem */
1637 UNMARSHALLING_REGISTER(ClipRect, DrawOpItem::CLIP_RECT_OPITEM,
1638     ClipRectOpItem::Unmarshalling, sizeof(ClipRectOpItem::ConstructorHandle));
1639 
ClipRectOpItem(ClipRectOpItem::ConstructorHandle * handle)1640 ClipRectOpItem::ClipRectOpItem(ClipRectOpItem::ConstructorHandle* handle)
1641     : DrawOpItem(CLIP_RECT_OPITEM), rect_(handle->rect), clipOp_(handle->clipOp), doAntiAlias_(handle->doAntiAlias) {}
1642 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1643 std::shared_ptr<DrawOpItem> ClipRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1644 {
1645     return std::make_shared<ClipRectOpItem>(static_cast<ClipRectOpItem::ConstructorHandle*>(handle));
1646 }
1647 
Marshalling(DrawCmdList & cmdList)1648 void ClipRectOpItem::Marshalling(DrawCmdList& cmdList)
1649 {
1650     cmdList.AddOp<ConstructorHandle>(rect_, clipOp_, doAntiAlias_);
1651 }
1652 
Playback(Canvas * canvas,const Rect * rect)1653 void ClipRectOpItem::Playback(Canvas* canvas, const Rect* rect)
1654 {
1655     canvas->ClipRect(rect_, clipOp_, doAntiAlias_);
1656 }
1657 
1658 /* ClipIRectOpItem */
1659 UNMARSHALLING_REGISTER(ClipIRect, DrawOpItem::CLIP_IRECT_OPITEM,
1660     ClipIRectOpItem::Unmarshalling, sizeof(ClipIRectOpItem::ConstructorHandle));
1661 
ClipIRectOpItem(ClipIRectOpItem::ConstructorHandle * handle)1662 ClipIRectOpItem::ClipIRectOpItem(ClipIRectOpItem::ConstructorHandle* handle)
1663     : DrawOpItem(CLIP_IRECT_OPITEM), rect_(handle->rect), clipOp_(handle->clipOp) {}
1664 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1665 std::shared_ptr<DrawOpItem> ClipIRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1666 {
1667     return std::make_shared<ClipIRectOpItem>(static_cast<ClipIRectOpItem::ConstructorHandle*>(handle));
1668 }
1669 
Marshalling(DrawCmdList & cmdList)1670 void ClipIRectOpItem::Marshalling(DrawCmdList& cmdList)
1671 {
1672     cmdList.AddOp<ConstructorHandle>(rect_, clipOp_);
1673 }
1674 
Playback(Canvas * canvas,const Rect * rect)1675 void ClipIRectOpItem::Playback(Canvas* canvas, const Rect* rect)
1676 {
1677     canvas->ClipIRect(rect_, clipOp_);
1678 }
1679 
1680 /* ClipRoundRectOpItem */
1681 UNMARSHALLING_REGISTER(ClipRoundRect, DrawOpItem::CLIP_ROUND_RECT_OPITEM,
1682     ClipRoundRectOpItem::Unmarshalling, sizeof(ClipRoundRectOpItem::ConstructorHandle));
1683 
ClipRoundRectOpItem(ClipRoundRectOpItem::ConstructorHandle * handle)1684 ClipRoundRectOpItem::ClipRoundRectOpItem(ClipRoundRectOpItem::ConstructorHandle* handle)
1685     : DrawOpItem(CLIP_ROUND_RECT_OPITEM), rrect_(handle->rrect), clipOp_(handle->clipOp),
1686     doAntiAlias_(handle->doAntiAlias) {}
1687 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1688 std::shared_ptr<DrawOpItem> ClipRoundRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1689 {
1690     return std::make_shared<ClipRoundRectOpItem>(static_cast<ClipRoundRectOpItem::ConstructorHandle*>(handle));
1691 }
1692 
Marshalling(DrawCmdList & cmdList)1693 void ClipRoundRectOpItem::Marshalling(DrawCmdList& cmdList)
1694 {
1695     cmdList.AddOp<ConstructorHandle>(rrect_, clipOp_, doAntiAlias_);
1696 }
1697 
Playback(Canvas * canvas,const Rect * rect)1698 void ClipRoundRectOpItem::Playback(Canvas* canvas, const Rect* rect)
1699 {
1700     canvas->ClipRoundRect(rrect_, clipOp_, doAntiAlias_);
1701 }
1702 
1703 /* ClipPathOpItem */
1704 UNMARSHALLING_REGISTER(ClipPath, DrawOpItem::CLIP_PATH_OPITEM,
1705     ClipPathOpItem::Unmarshalling, sizeof(ClipPathOpItem::ConstructorHandle));
1706 
ClipPathOpItem(const DrawCmdList & cmdList,ClipPathOpItem::ConstructorHandle * handle)1707 ClipPathOpItem::ClipPathOpItem(const DrawCmdList& cmdList, ClipPathOpItem::ConstructorHandle* handle)
1708     : DrawOpItem(CLIP_PATH_OPITEM), clipOp_(handle->clipOp), doAntiAlias_(handle->doAntiAlias)
1709 {
1710     path_ = CmdListHelper::GetPathFromCmdList(cmdList, handle->path);
1711 }
1712 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1713 std::shared_ptr<DrawOpItem> ClipPathOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1714 {
1715     return std::make_shared<ClipPathOpItem>(cmdList, static_cast<ClipPathOpItem::ConstructorHandle*>(handle));
1716 }
1717 
Marshalling(DrawCmdList & cmdList)1718 void ClipPathOpItem::Marshalling(DrawCmdList& cmdList)
1719 {
1720     OpDataHandle pathHandle;
1721     if (path_) {
1722         pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
1723     }
1724     cmdList.AddOp<ConstructorHandle>(pathHandle, clipOp_, doAntiAlias_);
1725 }
1726 
Playback(Canvas * canvas,const Rect * rect)1727 void ClipPathOpItem::Playback(Canvas* canvas, const Rect* rect)
1728 {
1729     if (path_ == nullptr) {
1730         LOGD("ClipPathOpItem path is null!");
1731         return;
1732     }
1733     canvas->ClipPath(*path_, clipOp_, doAntiAlias_);
1734 }
1735 
1736 /* ClipRegionOpItem */
1737 UNMARSHALLING_REGISTER(ClipRegion, DrawOpItem::CLIP_REGION_OPITEM,
1738     ClipRegionOpItem::Unmarshalling, sizeof(ClipRegionOpItem::ConstructorHandle));
1739 
ClipRegionOpItem(const DrawCmdList & cmdList,ClipRegionOpItem::ConstructorHandle * handle)1740 ClipRegionOpItem::ClipRegionOpItem(const DrawCmdList& cmdList, ClipRegionOpItem::ConstructorHandle* handle)
1741     : DrawOpItem(CLIP_REGION_OPITEM), clipOp_(handle->clipOp)
1742 {
1743     region_ = CmdListHelper::GetRegionFromCmdList(cmdList, handle->region);
1744 }
1745 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1746 std::shared_ptr<DrawOpItem> ClipRegionOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1747 {
1748     return std::make_shared<ClipRegionOpItem>(cmdList, static_cast<ClipRegionOpItem::ConstructorHandle*>(handle));
1749 }
1750 
Marshalling(DrawCmdList & cmdList)1751 void ClipRegionOpItem::Marshalling(DrawCmdList& cmdList)
1752 {
1753     OpDataHandle regionHandle;
1754     if (region_) {
1755         regionHandle = CmdListHelper::AddRegionToCmdList(cmdList, *region_);
1756     }
1757     cmdList.AddOp<ConstructorHandle>(regionHandle, clipOp_);
1758 }
1759 
Playback(Canvas * canvas,const Rect * rect)1760 void ClipRegionOpItem::Playback(Canvas* canvas, const Rect* rect)
1761 {
1762     if (region_ == nullptr) {
1763         LOGD("ClipRegionOpItem region is null!");
1764         return;
1765     }
1766     canvas->ClipRegion(*region_, clipOp_);
1767 }
1768 
1769 /* SetMatrixOpItem */
1770 UNMARSHALLING_REGISTER(SetMatrix, DrawOpItem::SET_MATRIX_OPITEM,
1771     SetMatrixOpItem::Unmarshalling, sizeof(SetMatrixOpItem::ConstructorHandle));
1772 
SetMatrixOpItem(SetMatrixOpItem::ConstructorHandle * handle)1773 SetMatrixOpItem::SetMatrixOpItem(SetMatrixOpItem::ConstructorHandle* handle) : DrawOpItem(SET_MATRIX_OPITEM)
1774 {
1775     matrix_.SetAll(handle->matrixBuffer);
1776 }
1777 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1778 std::shared_ptr<DrawOpItem> SetMatrixOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1779 {
1780     return std::make_shared<SetMatrixOpItem>(static_cast<SetMatrixOpItem::ConstructorHandle*>(handle));
1781 }
1782 
Marshalling(DrawCmdList & cmdList)1783 void SetMatrixOpItem::Marshalling(DrawCmdList& cmdList)
1784 {
1785     Matrix::Buffer matrixBuffer;
1786     matrix_.GetAll(matrixBuffer);
1787     cmdList.AddOp<ConstructorHandle>(matrixBuffer);
1788 }
1789 
Playback(Canvas * canvas,const Rect * rect)1790 void SetMatrixOpItem::Playback(Canvas* canvas, const Rect* rect)
1791 {
1792     canvas->SetMatrix(matrix_);
1793 }
1794 
1795 /* ResetMatrixOpItem */
1796 UNMARSHALLING_REGISTER(ResetMatrix, DrawOpItem::RESET_MATRIX_OPITEM,
1797     ResetMatrixOpItem::Unmarshalling, sizeof(ResetMatrixOpItem::ConstructorHandle));
1798 
ResetMatrixOpItem()1799 ResetMatrixOpItem::ResetMatrixOpItem() : DrawOpItem(RESET_MATRIX_OPITEM) {}
1800 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1801 std::shared_ptr<DrawOpItem> ResetMatrixOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1802 {
1803     return std::make_shared<ResetMatrixOpItem>();
1804 }
1805 
Marshalling(DrawCmdList & cmdList)1806 void ResetMatrixOpItem::Marshalling(DrawCmdList& cmdList)
1807 {
1808     cmdList.AddOp<ConstructorHandle>();
1809 }
1810 
Playback(Canvas * canvas,const Rect * rect)1811 void ResetMatrixOpItem::Playback(Canvas* canvas, const Rect* rect)
1812 {
1813     canvas->ResetMatrix();
1814 }
1815 
1816 /* ConcatMatrixOpItem */
1817 UNMARSHALLING_REGISTER(ConcatMatrix, DrawOpItem::CONCAT_MATRIX_OPITEM,
1818     ConcatMatrixOpItem::Unmarshalling, sizeof(ConcatMatrixOpItem::ConstructorHandle));
1819 
ConcatMatrixOpItem(ConcatMatrixOpItem::ConstructorHandle * handle)1820 ConcatMatrixOpItem::ConcatMatrixOpItem(ConcatMatrixOpItem::ConstructorHandle* handle) : DrawOpItem(CONCAT_MATRIX_OPITEM)
1821 {
1822     matrix_.SetAll(handle->matrixBuffer);
1823 }
1824 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1825 std::shared_ptr<DrawOpItem> ConcatMatrixOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1826 {
1827     return std::make_shared<ConcatMatrixOpItem>(static_cast<ConcatMatrixOpItem::ConstructorHandle*>(handle));
1828 }
1829 
Marshalling(DrawCmdList & cmdList)1830 void ConcatMatrixOpItem::Marshalling(DrawCmdList& cmdList)
1831 {
1832     Matrix::Buffer matrixBuffer;
1833     matrix_.GetAll(matrixBuffer);
1834     cmdList.AddOp<ConstructorHandle>(matrixBuffer);
1835 }
1836 
Playback(Canvas * canvas,const Rect * rect)1837 void ConcatMatrixOpItem::Playback(Canvas* canvas, const Rect* rect)
1838 {
1839     canvas->ConcatMatrix(matrix_);
1840 }
1841 
1842 /* TranslateOpItem */
1843 UNMARSHALLING_REGISTER(Translate, DrawOpItem::TRANSLATE_OPITEM,
1844     TranslateOpItem::Unmarshalling, sizeof(TranslateOpItem::ConstructorHandle));
1845 
TranslateOpItem(TranslateOpItem::ConstructorHandle * handle)1846 TranslateOpItem::TranslateOpItem(TranslateOpItem::ConstructorHandle* handle)
1847     : DrawOpItem(TRANSLATE_OPITEM), dx_(handle->dx), dy_(handle->dy) {}
1848 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1849 std::shared_ptr<DrawOpItem> TranslateOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1850 {
1851     return std::make_shared<TranslateOpItem>(static_cast<TranslateOpItem::ConstructorHandle*>(handle));
1852 }
1853 
Marshalling(DrawCmdList & cmdList)1854 void TranslateOpItem::Marshalling(DrawCmdList& cmdList)
1855 {
1856     cmdList.AddOp<ConstructorHandle>(dx_, dy_);
1857 }
1858 
Playback(Canvas * canvas,const Rect * rect)1859 void TranslateOpItem::Playback(Canvas* canvas, const Rect* rect)
1860 {
1861     canvas->Translate(dx_, dy_);
1862 }
1863 
1864 /* ScaleOpItem */
1865 UNMARSHALLING_REGISTER(Scale, DrawOpItem::SCALE_OPITEM,
1866     ScaleOpItem::Unmarshalling, sizeof(ScaleOpItem::ConstructorHandle));
1867 
ScaleOpItem(ScaleOpItem::ConstructorHandle * handle)1868 ScaleOpItem::ScaleOpItem(ScaleOpItem::ConstructorHandle* handle)
1869     : DrawOpItem(SCALE_OPITEM), sx_(handle->sx), sy_(handle->sy) {}
1870 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1871 std::shared_ptr<DrawOpItem> ScaleOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1872 {
1873     return std::make_shared<ScaleOpItem>(static_cast<ScaleOpItem::ConstructorHandle*>(handle));
1874 }
1875 
Marshalling(DrawCmdList & cmdList)1876 void ScaleOpItem::Marshalling(DrawCmdList& cmdList)
1877 {
1878     cmdList.AddOp<ConstructorHandle>(sx_, sy_);
1879 }
1880 
Playback(Canvas * canvas,const Rect * rect)1881 void ScaleOpItem::Playback(Canvas* canvas, const Rect* rect)
1882 {
1883     canvas->Scale(sx_, sy_);
1884 }
1885 
1886 /* RotateOpItem */
1887 UNMARSHALLING_REGISTER(Rotate, DrawOpItem::ROTATE_OPITEM,
1888     RotateOpItem::Unmarshalling, sizeof(RotateOpItem::ConstructorHandle));
1889 
RotateOpItem(RotateOpItem::ConstructorHandle * handle)1890 RotateOpItem::RotateOpItem(RotateOpItem::ConstructorHandle* handle)
1891     : DrawOpItem(ROTATE_OPITEM), deg_(handle->deg), sx_(handle->sx), sy_(handle->sy) {}
1892 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1893 std::shared_ptr<DrawOpItem> RotateOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1894 {
1895     return std::make_shared<RotateOpItem>(static_cast<RotateOpItem::ConstructorHandle*>(handle));
1896 }
1897 
Marshalling(DrawCmdList & cmdList)1898 void RotateOpItem::Marshalling(DrawCmdList& cmdList)
1899 {
1900     cmdList.AddOp<ConstructorHandle>(deg_, sx_, sy_);
1901 }
1902 
Playback(Canvas * canvas,const Rect * rect)1903 void RotateOpItem::Playback(Canvas* canvas, const Rect* rect)
1904 {
1905     canvas->Rotate(deg_, sx_, sy_);
1906 }
1907 
1908 /* ShearOpItem */
1909 UNMARSHALLING_REGISTER(Shear, DrawOpItem::SHEAR_OPITEM,
1910     ShearOpItem::Unmarshalling, sizeof(ShearOpItem::ConstructorHandle));
1911 
ShearOpItem(ShearOpItem::ConstructorHandle * handle)1912 ShearOpItem::ShearOpItem(ShearOpItem::ConstructorHandle* handle)
1913     : DrawOpItem(SHEAR_OPITEM), sx_(handle->sx), sy_(handle->sy) {}
1914 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1915 std::shared_ptr<DrawOpItem> ShearOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1916 {
1917     return std::make_shared<ShearOpItem>(static_cast<ShearOpItem::ConstructorHandle*>(handle));
1918 }
1919 
Marshalling(DrawCmdList & cmdList)1920 void ShearOpItem::Marshalling(DrawCmdList& cmdList)
1921 {
1922     cmdList.AddOp<ConstructorHandle>(sx_, sy_);
1923 }
1924 
Playback(Canvas * canvas,const Rect * rect)1925 void ShearOpItem::Playback(Canvas* canvas, const Rect* rect)
1926 {
1927     canvas->Shear(sx_, sy_);
1928 }
1929 
1930 /* FlushOpItem */
1931 UNMARSHALLING_REGISTER(Flush, DrawOpItem::FLUSH_OPITEM,
1932     FlushOpItem::Unmarshalling, sizeof(FlushOpItem::ConstructorHandle));
1933 
FlushOpItem()1934 FlushOpItem::FlushOpItem() : DrawOpItem(FLUSH_OPITEM) {}
1935 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1936 std::shared_ptr<DrawOpItem> FlushOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1937 {
1938     return std::make_shared<FlushOpItem>();
1939 }
1940 
Marshalling(DrawCmdList & cmdList)1941 void FlushOpItem::Marshalling(DrawCmdList& cmdList)
1942 {
1943     cmdList.AddOp<ConstructorHandle>();
1944 }
1945 
Playback(Canvas * canvas,const Rect * rect)1946 void FlushOpItem::Playback(Canvas* canvas, const Rect* rect)
1947 {
1948     canvas->Flush();
1949 }
1950 
1951 /* ClearOpItem */
1952 UNMARSHALLING_REGISTER(Clear, DrawOpItem::CLEAR_OPITEM,
1953     ClearOpItem::Unmarshalling, sizeof(ClearOpItem::ConstructorHandle));
1954 
ClearOpItem(ClearOpItem::ConstructorHandle * handle)1955 ClearOpItem::ClearOpItem(ClearOpItem::ConstructorHandle* handle)
1956     : DrawOpItem(CLEAR_OPITEM), color_(handle->color) {}
1957 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1958 std::shared_ptr<DrawOpItem> ClearOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1959 {
1960     return std::make_shared<ClearOpItem>(static_cast<ClearOpItem::ConstructorHandle*>(handle));
1961 }
1962 
Marshalling(DrawCmdList & cmdList)1963 void ClearOpItem::Marshalling(DrawCmdList& cmdList)
1964 {
1965     cmdList.AddOp<ConstructorHandle>(color_);
1966 }
1967 
Playback(Canvas * canvas,const Rect * rect)1968 void ClearOpItem::Playback(Canvas* canvas, const Rect* rect)
1969 {
1970     canvas->Clear(color_);
1971 }
1972 
1973 /* SaveOpItem */
1974 UNMARSHALLING_REGISTER(Save, DrawOpItem::SAVE_OPITEM,
1975     SaveOpItem::Unmarshalling, sizeof(SaveOpItem::ConstructorHandle));
1976 
SaveOpItem()1977 SaveOpItem::SaveOpItem() : DrawOpItem(SAVE_OPITEM) {}
1978 
Unmarshalling(const DrawCmdList & cmdList,void * handle)1979 std::shared_ptr<DrawOpItem> SaveOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1980 {
1981     return std::make_shared<SaveOpItem>();
1982 }
1983 
Marshalling(DrawCmdList & cmdList)1984 void SaveOpItem::Marshalling(DrawCmdList& cmdList)
1985 {
1986     cmdList.AddOp<ConstructorHandle>();
1987 }
1988 
Playback(Canvas * canvas,const Rect * rect)1989 void SaveOpItem::Playback(Canvas* canvas, const Rect* rect)
1990 {
1991     canvas->Save();
1992 }
1993 
1994 /* SaveLayerOpItem */
1995 UNMARSHALLING_REGISTER(SaveLayer, DrawOpItem::SAVE_LAYER_OPITEM,
1996     SaveLayerOpItem::Unmarshalling, sizeof(SaveLayerOpItem::ConstructorHandle));
1997 
SaveLayerOpItem(const DrawCmdList & cmdList,SaveLayerOpItem::ConstructorHandle * handle)1998 SaveLayerOpItem::SaveLayerOpItem(const DrawCmdList& cmdList, SaveLayerOpItem::ConstructorHandle* handle)
1999     : DrawOpItem(SAVE_LAYER_OPITEM), saveLayerFlags_(handle->saveLayerFlags), rect_(handle->rect),
2000     hasBrush_(handle->hasBrush)
2001 {
2002     if (hasBrush_) {
2003         BrushHandleToBrush(handle->brushHandle, cmdList, brush_);
2004     }
2005 }
2006 
Unmarshalling(const DrawCmdList & cmdList,void * handle)2007 std::shared_ptr<DrawOpItem> SaveLayerOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2008 {
2009     return std::make_shared<SaveLayerOpItem>(cmdList, static_cast<SaveLayerOpItem::ConstructorHandle*>(handle));
2010 }
2011 
Marshalling(DrawCmdList & cmdList)2012 void SaveLayerOpItem::Marshalling(DrawCmdList& cmdList)
2013 {
2014     BrushHandle brushHandle;
2015     if (hasBrush_) {
2016         BrushToBrushHandle(brush_, cmdList, brushHandle);
2017     }
2018     cmdList.AddOp<ConstructorHandle>(rect_, hasBrush_, brushHandle, saveLayerFlags_);
2019 }
2020 
Playback(Canvas * canvas,const Rect * rect)2021 void SaveLayerOpItem::Playback(Canvas* canvas, const Rect* rect)
2022 {
2023     const Rect* rectPtr = nullptr;
2024     if (rect_.IsValid()) {
2025         rectPtr = &rect_;
2026     }
2027     Brush* brushPtr = hasBrush_ ? &brush_ : nullptr;
2028     SaveLayerOps slo(rectPtr, brushPtr, saveLayerFlags_);
2029     canvas->SaveLayer(slo);
2030 }
2031 
2032 /* RestoreOpItem */
2033 UNMARSHALLING_REGISTER(Restore, DrawOpItem::RESTORE_OPITEM,
2034     RestoreOpItem::Unmarshalling, sizeof(RestoreOpItem::ConstructorHandle));
2035 
RestoreOpItem()2036 RestoreOpItem::RestoreOpItem() : DrawOpItem(RESTORE_OPITEM) {}
2037 
Unmarshalling(const DrawCmdList & cmdList,void * handle)2038 std::shared_ptr<DrawOpItem> RestoreOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2039 {
2040     return std::make_shared<RestoreOpItem>();
2041 }
2042 
Marshalling(DrawCmdList & cmdList)2043 void RestoreOpItem::Marshalling(DrawCmdList& cmdList)
2044 {
2045     cmdList.AddOp<ConstructorHandle>();
2046 }
2047 
Playback(Canvas * canvas,const Rect * rect)2048 void RestoreOpItem::Playback(Canvas* canvas, const Rect* rect)
2049 {
2050     canvas->Restore();
2051 }
2052 
2053 /* DiscardOpItem */
2054 UNMARSHALLING_REGISTER(Discard, DrawOpItem::DISCARD_OPITEM,
2055     DiscardOpItem::Unmarshalling, sizeof(DiscardOpItem::ConstructorHandle));
2056 
DiscardOpItem()2057 DiscardOpItem::DiscardOpItem() : DrawOpItem(DISCARD_OPITEM) {}
2058 
Unmarshalling(const DrawCmdList & cmdList,void * handle)2059 std::shared_ptr<DrawOpItem> DiscardOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2060 {
2061     return std::make_shared<DiscardOpItem>();
2062 }
2063 
Marshalling(DrawCmdList & cmdList)2064 void DiscardOpItem::Marshalling(DrawCmdList& cmdList)
2065 {
2066     cmdList.AddOp<ConstructorHandle>();
2067 }
2068 
Playback(Canvas * canvas,const Rect * rect)2069 void DiscardOpItem::Playback(Canvas* canvas, const Rect* rect)
2070 {
2071     canvas->Discard();
2072 }
2073 
2074 /* ClipAdaptiveRoundRectOpItem */
2075 UNMARSHALLING_REGISTER(ClipAdaptiveRoundRect, DrawOpItem::CLIP_ADAPTIVE_ROUND_RECT_OPITEM,
2076     ClipAdaptiveRoundRectOpItem::Unmarshalling, sizeof(ClipAdaptiveRoundRectOpItem::ConstructorHandle));
2077 
ClipAdaptiveRoundRectOpItem(const DrawCmdList & cmdList,ClipAdaptiveRoundRectOpItem::ConstructorHandle * handle)2078 ClipAdaptiveRoundRectOpItem::ClipAdaptiveRoundRectOpItem(
2079     const DrawCmdList& cmdList, ClipAdaptiveRoundRectOpItem::ConstructorHandle* handle)
2080     : DrawOpItem(CLIP_ADAPTIVE_ROUND_RECT_OPITEM)
2081 {
2082     radiusData_ = CmdListHelper::GetVectorFromCmdList<Point>(cmdList, handle->radiusData);
2083 }
2084 
Unmarshalling(const DrawCmdList & cmdList,void * handle)2085 std::shared_ptr<DrawOpItem> ClipAdaptiveRoundRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2086 {
2087     return std::make_shared<ClipAdaptiveRoundRectOpItem>(
2088         cmdList, static_cast<ClipAdaptiveRoundRectOpItem::ConstructorHandle*>(handle));
2089 }
2090 
Marshalling(DrawCmdList & cmdList)2091 void ClipAdaptiveRoundRectOpItem::Marshalling(DrawCmdList& cmdList)
2092 {
2093     auto radiusData = CmdListHelper::AddVectorToCmdList<Point>(cmdList, radiusData_);
2094     cmdList.AddOp<ConstructorHandle>(radiusData);
2095 }
2096 
Playback(Canvas * canvas,const Rect * rect)2097 void ClipAdaptiveRoundRectOpItem::Playback(Canvas* canvas, const Rect* rect)
2098 {
2099     canvas->ClipRoundRect(*rect, radiusData_, true);
2100 }
2101 } // namespace Drawing
2102 } // namespace Rosen
2103 } // namespace OHOS
2104