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 #include <sstream>
20
21 #include "recording/cmd_list_helper.h"
22 #include "recording/draw_cmd_list.h"
23 #include "recording/mem_allocator.h"
24 #include "recording/op_item.h"
25
26 #include "draw/brush.h"
27 #include "draw/color.h"
28 #include "draw/path.h"
29 #include "draw/surface.h"
30 #include "effect/color_filter.h"
31 #include "effect/color_space.h"
32 #include "effect/image_filter.h"
33 #include "effect/mask_filter.h"
34 #include "effect/path_effect.h"
35 #include "effect/shader_effect.h"
36 #include "utils/log.h"
37 #include "utils/scalar.h"
38 #include "utils/system_properties.h"
39 #include "sandbox_utils.h"
40 #include "securec.h"
41
42 namespace OHOS {
43 namespace Rosen {
44 namespace Drawing {
45 std::unordered_map<uint32_t, std::string> typeOpDes = {
46 { DrawOpItem::OPITEM_HEAD, "OPITEM_HEAD"},
47 { DrawOpItem::POINT_OPITEM, "POINT_OPITEM" },
48 { DrawOpItem::POINTS_OPITEM, "POINTS_OPITEM" },
49 { DrawOpItem::LINE_OPITEM, "LINE_OPITEM" },
50 { DrawOpItem::RECT_OPITEM, "RECT_OPITEM" },
51 { DrawOpItem::ROUND_RECT_OPITEM, "ROUND_RECT_OPITEM" },
52 { DrawOpItem::NESTED_ROUND_RECT_OPITEM, "NESTED_ROUND_RECT_OPITEM" },
53 { DrawOpItem::ARC_OPITEM, "ARC_OPITEM" },
54 { DrawOpItem::PIE_OPITEM, "PIE_OPITEM" },
55 { DrawOpItem::OVAL_OPITEM, "OVAL_OPITEM" },
56 { DrawOpItem::CIRCLE_OPITEM, "CIRCLE_OPITEM" },
57 { DrawOpItem::PATH_OPITEM, "PATH_OPITEM" },
58 { DrawOpItem::BACKGROUND_OPITEM, "BACKGROUND_OPITEM" },
59 { DrawOpItem::SHADOW_OPITEM, "SHADOW_OPITEM" },
60 { DrawOpItem::SHADOW_STYLE_OPITEM, "SHADOW_STYLE_OPITEM" },
61 { DrawOpItem::COLOR_OPITEM, "COLOR_OPITEM" },
62 { DrawOpItem::IMAGE_NINE_OPITEM, "IMAGE_NINE_OPITEM" },
63 { DrawOpItem::IMAGE_LATTICE_OPITEM, "IMAGE_LATTICE_OPITEM" },
64 { DrawOpItem::ATLAS_OPITEM, "ATLAS_OPITEM" },
65 { DrawOpItem::BITMAP_OPITEM, "BITMAP_OPITEM" },
66 { DrawOpItem::IMAGE_OPITEM, "IMAGE_OPITEM" },
67 { DrawOpItem::IMAGE_RECT_OPITEM, "IMAGE_RECT_OPITEM" },
68 { DrawOpItem::PICTURE_OPITEM, "PICTURE_OPITEM" },
69 { DrawOpItem::TEXT_BLOB_OPITEM, "TEXT_BLOB_OPITEM" },
70 { DrawOpItem::SYMBOL_OPITEM, "SYMBOL_OPITEM" },
71 { DrawOpItem::CLIP_RECT_OPITEM, "CLIP_RECT_OPITEM" },
72 { DrawOpItem::CLIP_IRECT_OPITEM, "CLIP_IRECT_OPITEM" },
73 { DrawOpItem::CLIP_ROUND_RECT_OPITEM, "CLIP_ROUND_RECT_OPITEM" },
74 { DrawOpItem::CLIP_PATH_OPITEM, "CLIP_PATH_OPITEM" },
75 { DrawOpItem::CLIP_REGION_OPITEM, "CLIP_REGION_OPITEM" },
76 { DrawOpItem::SET_MATRIX_OPITEM, "SET_MATRIX_OPITEM" },
77 { DrawOpItem::RESET_MATRIX_OPITEM, "RESET_MATRIX_OPITEM" },
78 { DrawOpItem::CONCAT_MATRIX_OPITEM, "CONCAT_MATRIX_OPITEM" },
79 { DrawOpItem::TRANSLATE_OPITEM, "TRANSLATE_OPITEM" },
80 { DrawOpItem::SCALE_OPITEM, "SCALE_OPITEM" },
81 { DrawOpItem::ROTATE_OPITEM, "ROTATE_OPITEM" },
82 { DrawOpItem::SHEAR_OPITEM, "SHEAR_OPITEM" },
83 { DrawOpItem::FLUSH_OPITEM, "FLUSH_OPITEM" },
84 { DrawOpItem::CLEAR_OPITEM, "CLEAR_OPITEM" },
85 { DrawOpItem::SAVE_OPITEM, "SAVE_OPITEM" },
86 { DrawOpItem::SAVE_LAYER_OPITEM, "SAVE_LAYER_OPITEM" },
87 { DrawOpItem::RESTORE_OPITEM, "RESTORE_OPITEM" },
88 { DrawOpItem::DISCARD_OPITEM, "DISCARD_OPITEM" },
89 { DrawOpItem::CLIP_ADAPTIVE_ROUND_RECT_OPITEM, "CLIP_ADAPTIVE_ROUND_RECT_OPITEM" },
90 { DrawOpItem::IMAGE_WITH_PARM_OPITEM, "IMAGE_WITH_PARM_OPITEM" },
91 { DrawOpItem::PIXELMAP_WITH_PARM_OPITEM, "PIXELMAP_WITH_PARM_OPITEM" },
92 { DrawOpItem::PIXELMAP_RECT_OPITEM, "PIXELMAP_RECT_OPITEM" },
93 { DrawOpItem::PIXELMAP_NINE_OPITEM, "PIXELMAP_NINE_OPITEM" },
94 { DrawOpItem::PIXELMAP_LATTICE_OPITEM, "PIXELMAP_LATTICE_OPITEM" },
95 { DrawOpItem::REGION_OPITEM, "REGION_OPITEM" },
96 { DrawOpItem::PATCH_OPITEM, "PATCH_OPITEM" },
97 { DrawOpItem::EDGEAAQUAD_OPITEM, "EDGEAAQUAD_OPITEM" },
98 { DrawOpItem::VERTICES_OPITEM, "VERTICES_OPITEM" },
99 { DrawOpItem::IMAGE_SNAPSHOT_OPITEM, "IMAGE_SNAPSHOT_OPITEM" },
100 { DrawOpItem::SURFACEBUFFER_OPITEM, "SURFACEBUFFER_OPITEM"},
101 { DrawOpItem::DRAW_FUNC_OPITEM, "DRAW_FUNC_OPITEM"},
102 { DrawOpItem::HYBRID_RENDER_PIXELMAP_OPITEM, "HYBRID_RENDER_PIXELMAP_OPITEM"},
103 { DrawOpItem::HYBRID_RENDER_PIXELMAP_SIZE_OPITEM, "HYBRID_RENDER_PIXELMAP_SIZE_OPITEM"},
104 };
105
106 namespace {
107 constexpr int TEXT_BLOB_CACHE_MARGIN = 10;
108 constexpr float HIGH_CONTRAST_OFFSCREEN_THREASHOLD = 0.99f;
109 constexpr size_t MAX_GLYPH_ID_COUNT = 20;
110
111 template<class A, class F>
DumpArray(std::string & out,const A & array,F func)112 void DumpArray(std::string& out, const A& array, F func)
113 {
114 out += "[";
115 auto end = std::end(array);
116 for (auto begin = std::begin(array); begin != end; begin++) {
117 func(out, *begin);
118 out += " ";
119 }
120 if (std::begin(array) != end) {
121 out.pop_back();
122 }
123 out += "]";
124 }
125 }
126
127 std::function<void (std::shared_ptr<Drawing::Image> image)> DrawOpItem::holdDrawingImagefunc_ = nullptr;
SetBaseCallback(std::function<void (std::shared_ptr<Drawing::Image> image)> holdDrawingImagefunc)128 void DrawOpItem::SetBaseCallback(
129 std::function<void (std::shared_ptr<Drawing::Image> image)> holdDrawingImagefunc)
130 {
131 holdDrawingImagefunc_ = holdDrawingImagefunc;
132 }
133
134 std::function<std::shared_ptr<Drawing::Typeface>(uint64_t)> DrawOpItem::customTypefaceQueryfunc_ = nullptr;
SetTypefaceQueryCallBack(std::function<std::shared_ptr<Drawing::Typeface> (uint64_t)> customTypefaceQueryfunc)135 void DrawOpItem::SetTypefaceQueryCallBack(
136 std::function<std::shared_ptr<Drawing::Typeface>(uint64_t)> customTypefaceQueryfunc)
137 {
138 customTypefaceQueryfunc_ = customTypefaceQueryfunc;
139 }
140
BrushHandleToBrush(const BrushHandle & brushHandle,const DrawCmdList & cmdList,Brush & brush)141 void DrawOpItem::BrushHandleToBrush(const BrushHandle& brushHandle, const DrawCmdList& cmdList, Brush& brush)
142 {
143 brush.SetBlendMode(brushHandle.mode);
144 brush.SetAntiAlias(brushHandle.isAntiAlias);
145 brush.SetBlenderEnabled(brushHandle.blenderEnabled);
146
147 if (brushHandle.colorSpaceHandle.size) {
148 auto colorSpace = CmdListHelper::GetColorSpaceFromCmdList(cmdList, brushHandle.colorSpaceHandle);
149 const Color4f color4f = { brushHandle.color.GetRedF(), brushHandle.color.GetGreenF(),
150 brushHandle.color.GetBlueF(), brushHandle.color.GetAlphaF() };
151 brush.SetColor(color4f, colorSpace);
152 } else {
153 brush.SetColor(brushHandle.color);
154 }
155
156 if (brushHandle.shaderEffectHandle.size) {
157 auto shaderEffect = CmdListHelper::GetShaderEffectFromCmdList(cmdList, brushHandle.shaderEffectHandle);
158 brush.SetShaderEffect(shaderEffect);
159 }
160
161 if (brushHandle.blenderHandle.size) {
162 auto blender = CmdListHelper::GetBlenderFromCmdList(cmdList, brushHandle.blenderHandle);
163 brush.SetBlender(blender);
164 }
165
166 Filter filter;
167 bool hasFilter = false;
168 if (brushHandle.colorFilterHandle.size) {
169 auto colorFilter = CmdListHelper::GetColorFilterFromCmdList(cmdList, brushHandle.colorFilterHandle);
170 filter.SetColorFilter(colorFilter);
171 hasFilter = true;
172 }
173 if (brushHandle.imageFilterHandle.size) {
174 auto imageFilter = CmdListHelper::GetImageFilterFromCmdList(cmdList, brushHandle.imageFilterHandle);
175 filter.SetImageFilter(imageFilter);
176 hasFilter = true;
177 }
178 if (brushHandle.maskFilterHandle.size) {
179 auto maskFilter = CmdListHelper::GetMaskFilterFromCmdList(cmdList, brushHandle.maskFilterHandle);
180 filter.SetMaskFilter(maskFilter);
181 hasFilter = true;
182 }
183
184 if (hasFilter) {
185 filter.SetFilterQuality(brushHandle.filterQuality);
186 brush.SetFilter(filter);
187 }
188 }
189
BrushToBrushHandle(const Brush & brush,DrawCmdList & cmdList,BrushHandle & brushHandle)190 void DrawOpItem::BrushToBrushHandle(const Brush& brush, DrawCmdList& cmdList, BrushHandle& brushHandle)
191 {
192 const Filter& filter = brush.GetFilter();
193 brushHandle.color = brush.GetColor();
194 brushHandle.mode = brush.GetBlendMode();
195 brushHandle.isAntiAlias = brush.IsAntiAlias();
196 brushHandle.blenderEnabled = brush.GetBlenderEnabled();
197 brushHandle.filterQuality = filter.GetFilterQuality();
198 brushHandle.colorSpaceHandle = CmdListHelper::AddColorSpaceToCmdList(cmdList, brush.GetColorSpace());
199 brushHandle.shaderEffectHandle = CmdListHelper::AddShaderEffectToCmdList(cmdList, brush.GetShaderEffect());
200 brushHandle.colorFilterHandle = CmdListHelper::AddColorFilterToCmdList(cmdList, filter.GetColorFilter());
201 brushHandle.imageFilterHandle = CmdListHelper::AddImageFilterToCmdList(cmdList, filter.GetImageFilter());
202 brushHandle.maskFilterHandle = CmdListHelper::AddMaskFilterToCmdList(cmdList, filter.GetMaskFilter());
203 }
204
GeneratePaintFromHandle(const PaintHandle & paintHandle,const DrawCmdList & cmdList,Paint & paint)205 void DrawOpItem::GeneratePaintFromHandle(const PaintHandle& paintHandle, const DrawCmdList& cmdList, Paint& paint)
206 {
207 paint.SetBlendMode(paintHandle.mode);
208 paint.SetAntiAlias(paintHandle.isAntiAlias);
209 paint.SetBlenderEnabled(paintHandle.blenderEnabled);
210 paint.SetStyle(paintHandle.style);
211
212 if (paintHandle.colorSpaceHandle.size) {
213 auto colorSpace = CmdListHelper::GetColorSpaceFromCmdList(cmdList, paintHandle.colorSpaceHandle);
214 const Color4f color4f = { paintHandle.color.GetRedF(), paintHandle.color.GetGreenF(),
215 paintHandle.color.GetBlueF(), paintHandle.color.GetAlphaF() };
216 paint.SetColor(color4f, colorSpace);
217 } else {
218 paint.SetColor(paintHandle.color);
219 }
220
221 if (paintHandle.shaderEffectHandle.size) {
222 auto shaderEffect = CmdListHelper::GetShaderEffectFromCmdList(cmdList, paintHandle.shaderEffectHandle);
223 paint.SetShaderEffect(shaderEffect);
224 }
225
226 if (paintHandle.blenderHandle.size) {
227 auto blender = CmdListHelper::GetBlenderFromCmdList(cmdList, paintHandle.blenderHandle);
228 paint.SetBlender(blender);
229 }
230
231 Filter filter;
232 bool hasFilter = false;
233 if (paintHandle.colorFilterHandle.size) {
234 auto colorFilter = CmdListHelper::GetColorFilterFromCmdList(cmdList, paintHandle.colorFilterHandle);
235 filter.SetColorFilter(colorFilter);
236 hasFilter = true;
237 }
238 if (paintHandle.imageFilterHandle.size) {
239 auto imageFilter = CmdListHelper::GetImageFilterFromCmdList(cmdList, paintHandle.imageFilterHandle);
240 filter.SetImageFilter(imageFilter);
241 hasFilter = true;
242 }
243 if (paintHandle.maskFilterHandle.size) {
244 auto maskFilter = CmdListHelper::GetMaskFilterFromCmdList(cmdList, paintHandle.maskFilterHandle);
245 filter.SetMaskFilter(maskFilter);
246 hasFilter = true;
247 }
248
249 if (hasFilter) {
250 filter.SetFilterQuality(paintHandle.filterQuality);
251 paint.SetFilter(filter);
252 }
253
254 if (paintHandle.blurDrawLooperHandle.size) {
255 auto blurDrawLooper = CmdListHelper::GetBlurDrawLooperFromCmdList(cmdList,
256 paintHandle.blurDrawLooperHandle);
257 paint.SetLooper(blurDrawLooper);
258 }
259
260 if (!paint.HasStrokeStyle()) {
261 return;
262 }
263
264 paint.SetWidth(paintHandle.width);
265 paint.SetMiterLimit(paintHandle.miterLimit);
266 paint.SetCapStyle(paintHandle.capStyle);
267 paint.SetJoinStyle(paintHandle.joinStyle);
268 if (paintHandle.pathEffectHandle.size) {
269 auto pathEffect = CmdListHelper::GetPathEffectFromCmdList(cmdList, paintHandle.pathEffectHandle);
270 paint.SetPathEffect(pathEffect);
271 }
272 }
273
GenerateHandleFromPaint(CmdList & cmdList,const Paint & paint,PaintHandle & paintHandle)274 void DrawOpItem::GenerateHandleFromPaint(CmdList& cmdList, const Paint& paint, PaintHandle& paintHandle)
275 {
276 paintHandle.isAntiAlias = paint.IsAntiAlias();
277 paintHandle.blenderEnabled = paint.GetBlenderEnabled();
278 paintHandle.style = paint.GetStyle();
279 paintHandle.color = paint.GetColor();
280 paintHandle.mode = paint.GetBlendMode();
281
282 if (paint.HasFilter()) {
283 const Filter& filter = paint.GetFilter();
284 paintHandle.filterQuality = filter.GetFilterQuality();
285 paintHandle.colorFilterHandle = CmdListHelper::AddColorFilterToCmdList(cmdList, filter.GetColorFilter());
286 paintHandle.imageFilterHandle = CmdListHelper::AddImageFilterToCmdList(cmdList, filter.GetImageFilter());
287 paintHandle.maskFilterHandle = CmdListHelper::AddMaskFilterToCmdList(cmdList, filter.GetMaskFilter());
288 }
289
290 if (paint.GetColorSpace()) {
291 paintHandle.colorSpaceHandle = CmdListHelper::AddColorSpaceToCmdList(cmdList, paint.GetColorSpace());
292 }
293
294 if (paint.GetShaderEffect()) {
295 paintHandle.shaderEffectHandle = CmdListHelper::AddShaderEffectToCmdList(cmdList, paint.GetShaderEffect());
296 }
297
298 if (paint.GetBlender()) {
299 paintHandle.blenderHandle = CmdListHelper::AddBlenderToCmdList(cmdList, paint.GetBlender());
300 }
301
302 if (paint.GetLooper()) {
303 paintHandle.blurDrawLooperHandle = CmdListHelper::AddBlurDrawLooperToCmdList(cmdList,
304 paint.GetLooper());
305 }
306
307 if (!paint.HasStrokeStyle()) {
308 return;
309 }
310
311 paintHandle.width = paint.GetWidth();
312 paintHandle.miterLimit = paint.GetMiterLimit();
313 paintHandle.capStyle = paint.GetCapStyle();
314 paintHandle.joinStyle = paint.GetJoinStyle();
315 if (paint.GetPathEffect()) {
316 paintHandle.pathEffectHandle = CmdListHelper::AddPathEffectToCmdList(cmdList, paint.GetPathEffect());
317 }
318 }
319
GetOpDesc() const320 std::string DrawOpItem::GetOpDesc() const
321 {
322 return typeOpDes[GetType()];
323 }
324
Dump(std::string & out) const325 void DrawOpItem::Dump(std::string& out) const
326 {
327 out += typeOpDes[GetType()];
328 }
329
GetOpSize()330 size_t DrawOpItem::GetOpSize()
331 {
332 size_t totoalSize = sizeof(*this);
333 const auto unmarshallingPair = UnmarshallingHelper::Instance().GetFuncAndSize(GetType());
334 totoalSize += unmarshallingPair.second;
335 return totoalSize;
336 }
337
GenerateCachedOpItemPlayer(DrawCmdList & cmdList,Canvas * canvas,const Rect * rect)338 GenerateCachedOpItemPlayer::GenerateCachedOpItemPlayer(DrawCmdList &cmdList, Canvas* canvas, const Rect* rect)
339 : canvas_(canvas), rect_(rect), cmdList_(cmdList) {}
340
GenerateCachedOpItem(uint32_t type,void * handle,size_t availableSize)341 bool GenerateCachedOpItemPlayer::GenerateCachedOpItem(uint32_t type, void* handle, size_t availableSize)
342 {
343 if (handle == nullptr) {
344 return false;
345 }
346
347 if (type == DrawOpItem::TEXT_BLOB_OPITEM && availableSize >= sizeof(DrawTextBlobOpItem::ConstructorHandle)) {
348 auto* op = static_cast<DrawTextBlobOpItem::ConstructorHandle*>(handle);
349 return op->GenerateCachedOpItem(cmdList_, canvas_);
350 }
351 return false;
352 }
353
354 /* UnmarshallingPlayer */
Instance()355 UnmarshallingHelper& UnmarshallingHelper::Instance()
356 {
357 static UnmarshallingHelper instance;
358 return instance;
359 }
360
Register(uint32_t type,UnmarshallingHelper::UnmarshallingFunc func,size_t unmarshallingSize)361 bool UnmarshallingHelper::Register(uint32_t type, UnmarshallingHelper::UnmarshallingFunc func, size_t unmarshallingSize)
362 {
363 std::unique_lock lck(mtx_);
364 opUnmarshallingFuncLUT_.emplace(type, func);
365 opUnmarshallingSize_.emplace(type, unmarshallingSize);
366 return true;
367 }
368
GetFuncAndSize(uint32_t type)369 std::pair<UnmarshallingHelper::UnmarshallingFunc, size_t> UnmarshallingHelper::GetFuncAndSize(uint32_t type)
370 {
371 std::shared_lock lck(mtx_);
372 auto funcIt = opUnmarshallingFuncLUT_.find(type);
373 auto sizeIt = opUnmarshallingSize_.find(type);
374 if (funcIt == opUnmarshallingFuncLUT_.end() || sizeIt == opUnmarshallingSize_.end()) {
375 return { nullptr, 0 };
376 }
377 /* unmarshalling func, desirable size for unmarshalling*/
378 return { funcIt->second, sizeIt->second };
379 }
380
UnmarshallingPlayer(const DrawCmdList & cmdList)381 UnmarshallingPlayer::UnmarshallingPlayer(const DrawCmdList& cmdList) : cmdList_(cmdList) {}
382
Unmarshalling(uint32_t type,void * handle,size_t avaliableSize,bool isReplayMode)383 std::shared_ptr<DrawOpItem> UnmarshallingPlayer::Unmarshalling(uint32_t type, void* handle, size_t avaliableSize,
384 bool isReplayMode)
385 {
386 if (type == DrawOpItem::OPITEM_HEAD) {
387 return nullptr;
388 }
389
390 const auto unmarshallingPair = UnmarshallingHelper::Instance().GetFuncAndSize(type);
391 /* if unmarshalling func is null or avaliable size < desirable unmarshalling size, then return nullptr*/
392 if (unmarshallingPair.first == nullptr) {
393 return nullptr;
394 }
395 if (unmarshallingPair.second > avaliableSize) {
396 if (isReplayMode) {
397 auto data = malloc(unmarshallingPair.second);
398 if (!data) {
399 return nullptr;
400 }
401 auto ret = memset_s(data, sizeof(data), 0, unmarshallingPair.second);
402 if (ret != EOK) {
403 free(data);
404 return nullptr;
405 }
406 ret = memmove_s(data, sizeof(data), handle, avaliableSize);
407 if (ret != EOK) {
408 free(data);
409 return nullptr;
410 }
411
412 auto result = (*unmarshallingPair.first)(this->cmdList_, data);
413 free(data);
414
415 return result;
416 }
417 return nullptr;
418 }
419 return (*unmarshallingPair.first)(this->cmdList_, handle);
420 }
421
422 /* DrawWithPaintOpItem */
DrawWithPaintOpItem(const DrawCmdList & cmdList,const PaintHandle & paintHandle,uint32_t type)423 DrawWithPaintOpItem::DrawWithPaintOpItem(const DrawCmdList& cmdList, const PaintHandle& paintHandle, uint32_t type)
424 : DrawOpItem(type)
425 {
426 GeneratePaintFromHandle(paintHandle, cmdList, paint_);
427 }
428
Dump(std::string & out) const429 void DrawWithPaintOpItem::Dump(std::string& out) const
430 {
431 DrawOpItem::Dump(out);
432 out += "[paint";
433 paint_.Dump(out);
434 DumpItems(out);
435 out += ']';
436 }
437
438 /* DrawPointOpItem */
439 UNMARSHALLING_REGISTER(DrawPoint, DrawOpItem::POINT_OPITEM,
440 DrawPointOpItem::Unmarshalling, sizeof(DrawPointOpItem::ConstructorHandle));
441
DrawPointOpItem(const DrawCmdList & cmdList,DrawPointOpItem::ConstructorHandle * handle)442 DrawPointOpItem::DrawPointOpItem(const DrawCmdList& cmdList, DrawPointOpItem::ConstructorHandle* handle)
443 : DrawWithPaintOpItem(cmdList, handle->paintHandle, POINT_OPITEM), point_(handle->point) {}
444
Unmarshalling(const DrawCmdList & cmdList,void * handle)445 std::shared_ptr<DrawOpItem> DrawPointOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
446 {
447 return std::make_shared<DrawPointOpItem>(cmdList, static_cast<DrawPointOpItem::ConstructorHandle*>(handle));
448 }
449
Marshalling(DrawCmdList & cmdList)450 void DrawPointOpItem::Marshalling(DrawCmdList& cmdList)
451 {
452 PaintHandle paintHandle;
453 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
454 cmdList.AddOp<ConstructorHandle>(point_, paintHandle);
455 }
456
Playback(Canvas * canvas,const Rect * rect)457 void DrawPointOpItem::Playback(Canvas* canvas, const Rect* rect)
458 {
459 canvas->AttachPaint(paint_);
460 canvas->DrawPoint(point_);
461 }
462
DumpItems(std::string & out) const463 void DrawPointOpItem::DumpItems(std::string& out) const
464 {
465 out += " point";
466 point_.Dump(out);
467 }
468
469 /* DrawPointsOpItem */
470 UNMARSHALLING_REGISTER(DrawPoints, DrawOpItem::POINTS_OPITEM,
471 DrawPointsOpItem::Unmarshalling, sizeof(DrawPointsOpItem::ConstructorHandle));
472
DrawPointsOpItem(const DrawCmdList & cmdList,DrawPointsOpItem::ConstructorHandle * handle)473 DrawPointsOpItem::DrawPointsOpItem(const DrawCmdList& cmdList, DrawPointsOpItem::ConstructorHandle* handle)
474 : DrawWithPaintOpItem(cmdList, handle->paintHandle, POINTS_OPITEM), mode_(handle->mode)
475 {
476 pts_ = CmdListHelper::GetVectorFromCmdList<Point>(cmdList, handle->pts);
477 }
478
Unmarshalling(const DrawCmdList & cmdList,void * handle)479 std::shared_ptr<DrawOpItem> DrawPointsOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
480 {
481 return std::make_shared<DrawPointsOpItem>(cmdList, static_cast<DrawPointsOpItem::ConstructorHandle*>(handle));
482 }
483
Marshalling(DrawCmdList & cmdList)484 void DrawPointsOpItem::Marshalling(DrawCmdList& cmdList)
485 {
486 PaintHandle paintHandle;
487 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
488 auto pointsData = CmdListHelper::AddVectorToCmdList<Point>(cmdList, pts_);
489 cmdList.AddOp<ConstructorHandle>(mode_, pointsData, paintHandle);
490 }
491
Playback(Canvas * canvas,const Rect * rect)492 void DrawPointsOpItem::Playback(Canvas* canvas, const Rect* rect)
493 {
494 canvas->AttachPaint(paint_);
495 canvas->DrawPoints(mode_, pts_.size(), pts_.data());
496 }
497
498 /* DrawLineOpItem */
499 UNMARSHALLING_REGISTER(DrawLine, DrawOpItem::LINE_OPITEM,
500 DrawLineOpItem::Unmarshalling, sizeof(DrawLineOpItem::ConstructorHandle));
501
DrawLineOpItem(const DrawCmdList & cmdList,DrawLineOpItem::ConstructorHandle * handle)502 DrawLineOpItem::DrawLineOpItem(const DrawCmdList& cmdList, DrawLineOpItem::ConstructorHandle* handle)
503 : DrawWithPaintOpItem(cmdList, handle->paintHandle, LINE_OPITEM),
504 startPt_(handle->startPt), endPt_(handle->endPt) {}
505
Unmarshalling(const DrawCmdList & cmdList,void * handle)506 std::shared_ptr<DrawOpItem> DrawLineOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
507 {
508 return std::make_shared<DrawLineOpItem>(cmdList, static_cast<DrawLineOpItem::ConstructorHandle*>(handle));
509 }
510
Marshalling(DrawCmdList & cmdList)511 void DrawLineOpItem::Marshalling(DrawCmdList& cmdList)
512 {
513 PaintHandle paintHandle;
514 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
515 cmdList.AddOp<ConstructorHandle>(startPt_, endPt_, paintHandle);
516 }
517
Playback(Canvas * canvas,const Rect * rect)518 void DrawLineOpItem::Playback(Canvas* canvas, const Rect* rect)
519 {
520 canvas->AttachPaint(paint_);
521 canvas->DrawLine(startPt_, endPt_);
522 }
523
DumpItems(std::string & out) const524 void DrawLineOpItem::DumpItems(std::string& out) const
525 {
526 out += " startPt";
527 startPt_.Dump(out);
528 out += " endPt";
529 endPt_.Dump(out);
530 }
531
532 /* DrawRectOpItem */
533 UNMARSHALLING_REGISTER(DrawRect, DrawOpItem::RECT_OPITEM,
534 DrawRectOpItem::Unmarshalling, sizeof(DrawRectOpItem::ConstructorHandle));
535
DrawRectOpItem(const DrawCmdList & cmdList,DrawRectOpItem::ConstructorHandle * handle)536 DrawRectOpItem::DrawRectOpItem(const DrawCmdList& cmdList, DrawRectOpItem::ConstructorHandle* handle)
537 : DrawWithPaintOpItem(cmdList, handle->paintHandle, RECT_OPITEM), rect_(handle->rect) {}
538
Unmarshalling(const DrawCmdList & cmdList,void * handle)539 std::shared_ptr<DrawOpItem> DrawRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
540 {
541 return std::make_shared<DrawRectOpItem>(cmdList, static_cast<DrawRectOpItem::ConstructorHandle*>(handle));
542 }
543
Marshalling(DrawCmdList & cmdList)544 void DrawRectOpItem::Marshalling(DrawCmdList& cmdList)
545 {
546 PaintHandle paintHandle;
547 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
548 cmdList.AddOp<ConstructorHandle>(rect_, paintHandle);
549 }
550
Playback(Canvas * canvas,const Rect * rect)551 void DrawRectOpItem::Playback(Canvas* canvas, const Rect* rect)
552 {
553 canvas->AttachPaint(paint_);
554 canvas->DrawRect(rect_);
555 }
556
DumpItems(std::string & out) const557 void DrawRectOpItem::DumpItems(std::string& out) const
558 {
559 out += " rect";
560 rect_.Dump(out);
561 }
562
GetOpItemCmdlistDrawRegion()563 Rect DrawRectOpItem::GetOpItemCmdlistDrawRegion()
564 {
565 if (rect_.IsEmpty()) {
566 LOGD("GetOpItemCmdlistDrawRegion rect opItem's bounds is empty");
567 return { 0, 0, 0, 0 };
568 }
569 return rect_;
570 }
571
572 /* DrawRoundRectOpItem */
573 UNMARSHALLING_REGISTER(DrawRoundRect, DrawOpItem::ROUND_RECT_OPITEM,
574 DrawRoundRectOpItem::Unmarshalling, sizeof(DrawRoundRectOpItem::ConstructorHandle));
575
DrawRoundRectOpItem(const DrawCmdList & cmdList,DrawRoundRectOpItem::ConstructorHandle * handle)576 DrawRoundRectOpItem::DrawRoundRectOpItem(const DrawCmdList& cmdList, DrawRoundRectOpItem::ConstructorHandle* handle)
577 : DrawWithPaintOpItem(cmdList, handle->paintHandle, ROUND_RECT_OPITEM), rrect_(handle->rrect) {}
578
Unmarshalling(const DrawCmdList & cmdList,void * handle)579 std::shared_ptr<DrawOpItem> DrawRoundRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
580 {
581 return std::make_shared<DrawRoundRectOpItem>(cmdList, static_cast<DrawRoundRectOpItem::ConstructorHandle*>(handle));
582 }
583
Marshalling(DrawCmdList & cmdList)584 void DrawRoundRectOpItem::Marshalling(DrawCmdList& cmdList)
585 {
586 PaintHandle paintHandle;
587 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
588 cmdList.AddOp<ConstructorHandle>(rrect_, paintHandle);
589 }
590
Playback(Canvas * canvas,const Rect * rect)591 void DrawRoundRectOpItem::Playback(Canvas* canvas, const Rect* rect)
592 {
593 canvas->AttachPaint(paint_);
594 canvas->DrawRoundRect(rrect_);
595 }
596
DumpItems(std::string & out) const597 void DrawRoundRectOpItem::DumpItems(std::string& out) const
598 {
599 out += " rrect";
600 rrect_.Dump(out);
601 }
602
603 /* DrawNestedRoundRectOpItem */
604 UNMARSHALLING_REGISTER(DrawNestedRoundRect, DrawOpItem::NESTED_ROUND_RECT_OPITEM,
605 DrawNestedRoundRectOpItem::Unmarshalling, sizeof(DrawNestedRoundRectOpItem::ConstructorHandle));
606
DrawNestedRoundRectOpItem(const DrawCmdList & cmdList,DrawNestedRoundRectOpItem::ConstructorHandle * handle)607 DrawNestedRoundRectOpItem::DrawNestedRoundRectOpItem(
608 const DrawCmdList& cmdList, DrawNestedRoundRectOpItem::ConstructorHandle* handle)
609 : DrawWithPaintOpItem(cmdList, handle->paintHandle, NESTED_ROUND_RECT_OPITEM),
610 outerRRect_(handle->outerRRect), innerRRect_(handle->innerRRect) {}
611
Unmarshalling(const DrawCmdList & cmdList,void * handle)612 std::shared_ptr<DrawOpItem> DrawNestedRoundRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
613 {
614 return std::make_shared<DrawNestedRoundRectOpItem>(
615 cmdList, static_cast<DrawNestedRoundRectOpItem::ConstructorHandle*>(handle));
616 }
617
Marshalling(DrawCmdList & cmdList)618 void DrawNestedRoundRectOpItem::Marshalling(DrawCmdList& cmdList)
619 {
620 PaintHandle paintHandle;
621 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
622 cmdList.AddOp<ConstructorHandle>(outerRRect_, innerRRect_, paintHandle);
623 }
624
Playback(Canvas * canvas,const Rect * rect)625 void DrawNestedRoundRectOpItem::Playback(Canvas* canvas, const Rect* rect)
626 {
627 canvas->AttachPaint(paint_);
628 canvas->DrawNestedRoundRect(outerRRect_, innerRRect_);
629 }
630
DumpItems(std::string & out) const631 void DrawNestedRoundRectOpItem::DumpItems(std::string& out) const
632 {
633 out += " outerRRect";
634 outerRRect_.Dump(out);
635 out += " innerRRect";
636 innerRRect_.Dump(out);
637 }
638
639 /* DrawArcOpItem */
640 UNMARSHALLING_REGISTER(DrawArc, DrawOpItem::ARC_OPITEM,
641 DrawArcOpItem::Unmarshalling, sizeof(DrawArcOpItem::ConstructorHandle));
642
DrawArcOpItem(const DrawCmdList & cmdList,DrawArcOpItem::ConstructorHandle * handle)643 DrawArcOpItem::DrawArcOpItem(const DrawCmdList& cmdList, DrawArcOpItem::ConstructorHandle* handle)
644 : DrawWithPaintOpItem(cmdList, handle->paintHandle, ARC_OPITEM), rect_(handle->rect),
645 startAngle_(handle->startAngle), sweepAngle_(handle->sweepAngle) {}
646
Unmarshalling(const DrawCmdList & cmdList,void * handle)647 std::shared_ptr<DrawOpItem> DrawArcOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
648 {
649 return std::make_shared<DrawArcOpItem>(cmdList, static_cast<DrawArcOpItem::ConstructorHandle*>(handle));
650 }
651
Marshalling(DrawCmdList & cmdList)652 void DrawArcOpItem::Marshalling(DrawCmdList& cmdList)
653 {
654 PaintHandle paintHandle;
655 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
656 cmdList.AddOp<ConstructorHandle>(rect_, startAngle_, sweepAngle_, paintHandle);
657 }
658
Playback(Canvas * canvas,const Rect * rect)659 void DrawArcOpItem::Playback(Canvas* canvas, const Rect* rect)
660 {
661 canvas->AttachPaint(paint_);
662 canvas->DrawArc(rect_, startAngle_, sweepAngle_);
663 }
664
DumpItems(std::string & out) const665 void DrawArcOpItem::DumpItems(std::string& out) const
666 {
667 out += " rect";
668 rect_.Dump(out);
669 out += " startAngle:" + std::to_string(startAngle_);
670 out += " sweepAngle:" + std::to_string(sweepAngle_);
671 }
672
673 /* DrawPieOpItem */
674 UNMARSHALLING_REGISTER(DrawPie, DrawOpItem::PIE_OPITEM,
675 DrawPieOpItem::Unmarshalling, sizeof(DrawPieOpItem::ConstructorHandle));
676
DrawPieOpItem(const DrawCmdList & cmdList,DrawPieOpItem::ConstructorHandle * handle)677 DrawPieOpItem::DrawPieOpItem(const DrawCmdList& cmdList, DrawPieOpItem::ConstructorHandle* handle)
678 : DrawWithPaintOpItem(cmdList, handle->paintHandle, PIE_OPITEM), rect_(handle->rect),
679 startAngle_(handle->startAngle), sweepAngle_(handle->sweepAngle) {}
680
Unmarshalling(const DrawCmdList & cmdList,void * handle)681 std::shared_ptr<DrawOpItem> DrawPieOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
682 {
683 return std::make_shared<DrawPieOpItem>(cmdList, static_cast<DrawPieOpItem::ConstructorHandle*>(handle));
684 }
685
Marshalling(DrawCmdList & cmdList)686 void DrawPieOpItem::Marshalling(DrawCmdList& cmdList)
687 {
688 PaintHandle paintHandle;
689 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
690 cmdList.AddOp<ConstructorHandle>(rect_, startAngle_, sweepAngle_, paintHandle);
691 }
692
Playback(Canvas * canvas,const Rect * rect)693 void DrawPieOpItem::Playback(Canvas* canvas, const Rect* rect)
694 {
695 canvas->AttachPaint(paint_);
696 canvas->DrawPie(rect_, startAngle_, sweepAngle_);
697 }
698
DumpItems(std::string & out) const699 void DrawPieOpItem::DumpItems(std::string& out) const
700 {
701 out += " rect";
702 rect_.Dump(out);
703 out += " startAngle:" + std::to_string(startAngle_);
704 out += " sweepAngle:" + std::to_string(sweepAngle_);
705 }
706
707 /* DrawOvalOpItem */
708 UNMARSHALLING_REGISTER(DrawOval, DrawOpItem::OVAL_OPITEM,
709 DrawOvalOpItem::Unmarshalling, sizeof(DrawOvalOpItem::ConstructorHandle));
710
DrawOvalOpItem(const DrawCmdList & cmdList,DrawOvalOpItem::ConstructorHandle * handle)711 DrawOvalOpItem::DrawOvalOpItem(const DrawCmdList& cmdList, DrawOvalOpItem::ConstructorHandle* handle)
712 : DrawWithPaintOpItem(cmdList, handle->paintHandle, OVAL_OPITEM), rect_(handle->rect) {}
713
Unmarshalling(const DrawCmdList & cmdList,void * handle)714 std::shared_ptr<DrawOpItem> DrawOvalOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
715 {
716 return std::make_shared<DrawOvalOpItem>(cmdList, static_cast<DrawOvalOpItem::ConstructorHandle*>(handle));
717 }
718
Marshalling(DrawCmdList & cmdList)719 void DrawOvalOpItem::Marshalling(DrawCmdList& cmdList)
720 {
721 PaintHandle paintHandle;
722 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
723 cmdList.AddOp<ConstructorHandle>(rect_, paintHandle);
724 }
725
Playback(Canvas * canvas,const Rect * rect)726 void DrawOvalOpItem::Playback(Canvas* canvas, const Rect* rect)
727 {
728 canvas->AttachPaint(paint_);
729 canvas->DrawOval(rect_);
730 }
731
DumpItems(std::string & out) const732 void DrawOvalOpItem::DumpItems(std::string& out) const
733 {
734 out += " rect";
735 rect_.Dump(out);
736 }
737
738 /* DrawCircleOpItem */
739 UNMARSHALLING_REGISTER(DrawCircle, DrawOpItem::CIRCLE_OPITEM,
740 DrawCircleOpItem::Unmarshalling, sizeof(DrawCircleOpItem::ConstructorHandle));
741
DrawCircleOpItem(const DrawCmdList & cmdList,DrawCircleOpItem::ConstructorHandle * handle)742 DrawCircleOpItem::DrawCircleOpItem(const DrawCmdList& cmdList, DrawCircleOpItem::ConstructorHandle* handle)
743 : DrawWithPaintOpItem(cmdList, handle->paintHandle, CIRCLE_OPITEM),
744 centerPt_(handle->centerPt), radius_(handle->radius) {}
745
Unmarshalling(const DrawCmdList & cmdList,void * handle)746 std::shared_ptr<DrawOpItem> DrawCircleOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
747 {
748 return std::make_shared<DrawCircleOpItem>(cmdList, static_cast<DrawCircleOpItem::ConstructorHandle*>(handle));
749 }
750
Marshalling(DrawCmdList & cmdList)751 void DrawCircleOpItem::Marshalling(DrawCmdList& cmdList)
752 {
753 PaintHandle paintHandle;
754 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
755 cmdList.AddOp<ConstructorHandle>(centerPt_, radius_, paintHandle);
756 }
757
Playback(Canvas * canvas,const Rect * rect)758 void DrawCircleOpItem::Playback(Canvas* canvas, const Rect* rect)
759 {
760 canvas->AttachPaint(paint_);
761 canvas->DrawCircle(centerPt_, radius_);
762 }
763
DumpItems(std::string & out) const764 void DrawCircleOpItem::DumpItems(std::string& out) const
765 {
766 out += " centerPt";
767 centerPt_.Dump(out);
768 out += " radius:" + std::to_string(radius_);
769 }
770
771 /* DrawPathOpItem */
772 UNMARSHALLING_REGISTER(DrawPath, DrawOpItem::PATH_OPITEM,
773 DrawPathOpItem::Unmarshalling, sizeof(DrawPathOpItem::ConstructorHandle));
774
DrawPathOpItem(const DrawCmdList & cmdList,DrawPathOpItem::ConstructorHandle * handle)775 DrawPathOpItem::DrawPathOpItem(const DrawCmdList& cmdList, DrawPathOpItem::ConstructorHandle* handle)
776 : DrawWithPaintOpItem(cmdList, handle->paintHandle, PATH_OPITEM)
777 {
778 path_ = CmdListHelper::GetPathFromCmdList(cmdList, handle->path);
779 }
780
Unmarshalling(const DrawCmdList & cmdList,void * handle)781 std::shared_ptr<DrawOpItem> DrawPathOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
782 {
783 return std::make_shared<DrawPathOpItem>(cmdList, static_cast<DrawPathOpItem::ConstructorHandle*>(handle));
784 }
785
Marshalling(DrawCmdList & cmdList)786 void DrawPathOpItem::Marshalling(DrawCmdList& cmdList)
787 {
788 PaintHandle paintHandle;
789 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
790 OpDataHandle pathHandle;
791 if (path_) {
792 pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
793 }
794 cmdList.AddOp<ConstructorHandle>(pathHandle, paintHandle);
795 }
796
Playback(Canvas * canvas,const Rect * rect)797 void DrawPathOpItem::Playback(Canvas* canvas, const Rect* rect)
798 {
799 if (path_ == nullptr) {
800 LOGD("DrawPathOpItem path is null!");
801 return;
802 }
803 canvas->AttachPaint(paint_);
804 canvas->DrawPath(*path_);
805 }
806
DumpItems(std::string & out) const807 void DrawPathOpItem::DumpItems(std::string& out) const
808 {
809 if (path_ != nullptr) {
810 out += " Path";
811 path_->Dump(out);
812 }
813 }
814
GetOpItemCmdlistDrawRegion()815 Rect DrawPathOpItem::GetOpItemCmdlistDrawRegion()
816 {
817 if (path_ == nullptr) {
818 LOGD("GetOpItemCmdlistDrawRegion path opItem is nullptr");
819 return { 0, 0, 0, 0 };
820 }
821
822 const auto& bounds = path_->GetBounds();
823 if (bounds.IsEmpty()) {
824 LOGD("GetOpItemCmdlistDrawRegion path opItem's bounds is empty");
825 return { 0, 0, 0, 0 };
826 }
827 return bounds;
828 }
829
830 /* DrawBackgroundOpItem */
831 UNMARSHALLING_REGISTER(DrawBackground, DrawOpItem::BACKGROUND_OPITEM,
832 DrawBackgroundOpItem::Unmarshalling, sizeof(DrawBackgroundOpItem::ConstructorHandle));
833
DrawBackgroundOpItem(const DrawCmdList & cmdList,DrawBackgroundOpItem::ConstructorHandle * handle)834 DrawBackgroundOpItem::DrawBackgroundOpItem(const DrawCmdList& cmdList, DrawBackgroundOpItem::ConstructorHandle* handle)
835 : DrawOpItem(BACKGROUND_OPITEM)
836 {
837 BrushHandleToBrush(handle->brushHandle, cmdList, brush_);
838 }
839
Unmarshalling(const DrawCmdList & cmdList,void * handle)840 std::shared_ptr<DrawOpItem> DrawBackgroundOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
841 {
842 return std::make_shared<DrawBackgroundOpItem>(
843 cmdList, static_cast<DrawBackgroundOpItem::ConstructorHandle*>(handle));
844 }
845
Marshalling(DrawCmdList & cmdList)846 void DrawBackgroundOpItem::Marshalling(DrawCmdList& cmdList)
847 {
848 BrushHandle brushHandle;
849 BrushToBrushHandle(brush_, cmdList, brushHandle);
850 cmdList.AddOp<ConstructorHandle>(brushHandle);
851 }
852
Playback(Canvas * canvas,const Rect * rect)853 void DrawBackgroundOpItem::Playback(Canvas* canvas, const Rect* rect)
854 {
855 canvas->DrawBackground(brush_);
856 }
857
858 /* DrawShadowStyleOpItem */
859 UNMARSHALLING_REGISTER(DrawShadowStyle, DrawOpItem::SHADOW_STYLE_OPITEM,
860 DrawShadowStyleOpItem::Unmarshalling, sizeof(DrawShadowStyleOpItem::ConstructorHandle));
861
DrawShadowStyleOpItem(const DrawCmdList & cmdList,DrawShadowStyleOpItem::ConstructorHandle * handle)862 DrawShadowStyleOpItem::DrawShadowStyleOpItem(
863 const DrawCmdList& cmdList, DrawShadowStyleOpItem::ConstructorHandle* handle)
864 : DrawOpItem(SHADOW_STYLE_OPITEM),
865 planeParams_(handle->planeParams),
866 devLightPos_(handle->devLightPos),
867 lightRadius_(handle->lightRadius),
868 ambientColor_(handle->ambientColor),
869 spotColor_(handle->spotColor),
870 flag_(handle->flag),
871 isLimitElevation_(handle->isLimitElevation)
872 {
873 path_ = CmdListHelper::GetPathFromCmdList(cmdList, handle->path);
874 }
875
Unmarshalling(const DrawCmdList & cmdList,void * handle)876 std::shared_ptr<DrawOpItem> DrawShadowStyleOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
877 {
878 return std::make_shared<DrawShadowStyleOpItem>(
879 cmdList, static_cast<DrawShadowStyleOpItem::ConstructorHandle*>(handle));
880 }
881
Marshalling(DrawCmdList & cmdList)882 void DrawShadowStyleOpItem::Marshalling(DrawCmdList& cmdList)
883 {
884 OpDataHandle pathHandle;
885 if (path_) {
886 pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
887 }
888 cmdList.AddOp<ConstructorHandle>(
889 pathHandle, planeParams_, devLightPos_, lightRadius_, ambientColor_, spotColor_, flag_, isLimitElevation_);
890 }
891
Playback(Canvas * canvas,const Rect * rect)892 void DrawShadowStyleOpItem::Playback(Canvas* canvas, const Rect* rect)
893 {
894 if (path_ == nullptr) {
895 LOGD("DrawShadowStyleOpItem path is null!");
896 return;
897 }
898 canvas->DrawShadowStyle(
899 *path_, planeParams_, devLightPos_, lightRadius_, ambientColor_, spotColor_, flag_, isLimitElevation_);
900 }
901
Dump(std::string & out) const902 void DrawShadowStyleOpItem::Dump(std::string& out) const
903 {
904 out += GetOpDesc() + "[plane";
905 planeParams_.Dump(out);
906 out += " lightPos";
907 devLightPos_.Dump(out);
908 out += " lightRadius:" + std::to_string(lightRadius_);
909 out += " ambientColor";
910 ambientColor_.Dump(out);
911 out += " spotColor_";
912 spotColor_.Dump(out);
913 out += " shadowFlags:" + std::to_string(static_cast<int>(flag_));
914 out += " isLimitElevation:" + std::string(isLimitElevation_ ? "true" : "false");
915 out += "]";
916 }
917
918 /* DrawShadowOpItem */
919 UNMARSHALLING_REGISTER(DrawShadow, DrawOpItem::SHADOW_OPITEM,
920 DrawShadowOpItem::Unmarshalling, sizeof(DrawShadowOpItem::ConstructorHandle));
921
DrawShadowOpItem(const DrawCmdList & cmdList,DrawShadowOpItem::ConstructorHandle * handle)922 DrawShadowOpItem::DrawShadowOpItem(const DrawCmdList& cmdList, DrawShadowOpItem::ConstructorHandle* handle)
923 : DrawOpItem(SHADOW_OPITEM), planeParams_(handle->planeParams), devLightPos_(handle->devLightPos),
924 lightRadius_(handle->lightRadius), ambientColor_(handle->ambientColor),
925 spotColor_(handle->spotColor), flag_(handle->flag)
926 {
927 path_ = CmdListHelper::GetPathFromCmdList(cmdList, handle->path);
928 }
929
Unmarshalling(const DrawCmdList & cmdList,void * handle)930 std::shared_ptr<DrawOpItem> DrawShadowOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
931 {
932 return std::make_shared<DrawShadowOpItem>(cmdList, static_cast<DrawShadowOpItem::ConstructorHandle*>(handle));
933 }
934
Marshalling(DrawCmdList & cmdList)935 void DrawShadowOpItem::Marshalling(DrawCmdList& cmdList)
936 {
937 OpDataHandle pathHandle;
938 if (path_) {
939 pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
940 }
941 cmdList.AddOp<ConstructorHandle>(
942 pathHandle, planeParams_, devLightPos_, lightRadius_, ambientColor_, spotColor_, flag_);
943 }
944
Playback(Canvas * canvas,const Rect * rect)945 void DrawShadowOpItem::Playback(Canvas* canvas, const Rect* rect)
946 {
947 if (path_ == nullptr) {
948 LOGD("DrawShadowOpItem path is null!");
949 return;
950 }
951 canvas->DrawShadow(*path_, planeParams_, devLightPos_, lightRadius_,
952 ambientColor_, spotColor_, flag_);
953 }
954
Dump(std::string & out) const955 void DrawShadowOpItem::Dump(std::string& out) const
956 {
957 out += GetOpDesc() + "[plane";
958 planeParams_.Dump(out);
959 out += " lightPos";
960 devLightPos_.Dump(out);
961 out += " lightRadius:" + std::to_string(lightRadius_);
962 out += " ambientColor";
963 ambientColor_.Dump(out);
964 out += " spotColor_";
965 spotColor_.Dump(out);
966 out += " shadowFlags:" + std::to_string(static_cast<int>(flag_));
967 out += " path";
968 if (path_) {
969 path_->Dump(out);
970 } else {
971 out += "[null]";
972 }
973 out += "]";
974 }
975
976 /* DrawRegionOpItem */
977 UNMARSHALLING_REGISTER(DrawRegion, DrawOpItem::REGION_OPITEM,
978 DrawRegionOpItem::Unmarshalling, sizeof(DrawRegionOpItem::ConstructorHandle));
979
DrawRegionOpItem(const DrawCmdList & cmdList,DrawRegionOpItem::ConstructorHandle * handle)980 DrawRegionOpItem::DrawRegionOpItem(const DrawCmdList& cmdList, DrawRegionOpItem::ConstructorHandle* handle)
981 : DrawWithPaintOpItem(cmdList, handle->paintHandle, REGION_OPITEM)
982 {
983 region_ = CmdListHelper::GetRegionFromCmdList(cmdList, handle->region);
984 }
985
Unmarshalling(const DrawCmdList & cmdList,void * handle)986 std::shared_ptr<DrawOpItem> DrawRegionOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
987 {
988 return std::make_shared<DrawRegionOpItem>(cmdList, static_cast<DrawRegionOpItem::ConstructorHandle*>(handle));
989 }
990
Marshalling(DrawCmdList & cmdList)991 void DrawRegionOpItem::Marshalling(DrawCmdList& cmdList)
992 {
993 PaintHandle paintHandle;
994 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
995 OpDataHandle regionHandle;
996 if (region_) {
997 regionHandle = CmdListHelper::AddRegionToCmdList(cmdList, *region_);
998 }
999 cmdList.AddOp<ConstructorHandle>(regionHandle, paintHandle);
1000 }
1001
Playback(Canvas * canvas,const Rect * rect)1002 void DrawRegionOpItem::Playback(Canvas* canvas, const Rect* rect)
1003 {
1004 if (region_ == nullptr) {
1005 LOGD("DrawRegionOpItem region is nullptr!");
1006 return;
1007 }
1008 canvas->AttachPaint(paint_);
1009 canvas->DrawRegion(*region_);
1010 }
1011
DumpItems(std::string & out) const1012 void DrawRegionOpItem::DumpItems(std::string& out) const
1013 {
1014 if (region_ != nullptr) {
1015 out += " Region";
1016 region_->Dump(out);
1017 }
1018 }
1019
1020 /* DrawVerticesOpItem */
1021 UNMARSHALLING_REGISTER(DrawVertices, DrawOpItem::VERTICES_OPITEM,
1022 DrawVerticesOpItem::Unmarshalling, sizeof(DrawVerticesOpItem::ConstructorHandle));
1023
DrawVerticesOpItem(const DrawCmdList & cmdList,DrawVerticesOpItem::ConstructorHandle * handle)1024 DrawVerticesOpItem::DrawVerticesOpItem(const DrawCmdList& cmdList, DrawVerticesOpItem::ConstructorHandle* handle)
1025 : DrawWithPaintOpItem(cmdList, handle->paintHandle, VERTICES_OPITEM), mode_(handle->mode)
1026 {
1027 vertices_ = CmdListHelper::GetVerticesFromCmdList(cmdList, handle->vertices);
1028 }
1029
Unmarshalling(const DrawCmdList & cmdList,void * handle)1030 std::shared_ptr<DrawOpItem> DrawVerticesOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1031 {
1032 return std::make_shared<DrawVerticesOpItem>(cmdList, static_cast<DrawVerticesOpItem::ConstructorHandle*>(handle));
1033 }
1034
Marshalling(DrawCmdList & cmdList)1035 void DrawVerticesOpItem::Marshalling(DrawCmdList& cmdList)
1036 {
1037 PaintHandle paintHandle;
1038 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1039 OpDataHandle opDataHandle;
1040 if (vertices_) {
1041 opDataHandle = CmdListHelper::AddVerticesToCmdList(cmdList, *vertices_);
1042 }
1043 cmdList.AddOp<ConstructorHandle>(opDataHandle, mode_, paintHandle);
1044 }
1045
Playback(Canvas * canvas,const Rect * rect)1046 void DrawVerticesOpItem::Playback(Canvas* canvas, const Rect* rect)
1047 {
1048 if (vertices_ == nullptr) {
1049 LOGD("DrawVerticesOpItem vertices is null");
1050 return;
1051 }
1052 canvas->AttachPaint(paint_);
1053 canvas->DrawVertices(*vertices_, mode_);
1054 }
1055
DumpItems(std::string & out) const1056 void DrawVerticesOpItem::DumpItems(std::string& out) const
1057 {
1058 out += " blend_mode:" + std::to_string(static_cast<int>(mode_));
1059 out += " vertices:";
1060 std::stringstream stream;
1061 stream << std::hex << vertices_.get();
1062 out += std::string(stream.str());
1063 }
1064
1065 /* DrawColorOpItem */
1066 UNMARSHALLING_REGISTER(DrawColor, DrawOpItem::COLOR_OPITEM,
1067 DrawColorOpItem::Unmarshalling, sizeof(DrawColorOpItem::ConstructorHandle));
1068
DrawColorOpItem(DrawColorOpItem::ConstructorHandle * handle)1069 DrawColorOpItem::DrawColorOpItem(DrawColorOpItem::ConstructorHandle* handle)
1070 : DrawOpItem(COLOR_OPITEM), color_(handle->color), mode_(handle->mode) {}
1071
Unmarshalling(const DrawCmdList & cmdList,void * handle)1072 std::shared_ptr<DrawOpItem> DrawColorOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1073 {
1074 return std::make_shared<DrawColorOpItem>(static_cast<DrawColorOpItem::ConstructorHandle*>(handle));
1075 }
1076
Marshalling(DrawCmdList & cmdList)1077 void DrawColorOpItem::Marshalling(DrawCmdList& cmdList)
1078 {
1079 cmdList.AddOp<ConstructorHandle>(color_, mode_);
1080 }
1081
Playback(Canvas * canvas,const Rect * rect)1082 void DrawColorOpItem::Playback(Canvas* canvas, const Rect* rect)
1083 {
1084 canvas->DrawColor(color_, mode_);
1085 }
1086
Dump(std::string & out) const1087 void DrawColorOpItem::Dump(std::string& out) const
1088 {
1089 out += GetOpDesc() + "[color";
1090 Color(color_).Dump(out);
1091 out += " blendMode:" + std::to_string(static_cast<int>(mode_));
1092 out += "]";
1093 }
1094
1095 /* DrawImageNineOpItem */
1096 UNMARSHALLING_REGISTER(DrawImageNine, DrawOpItem::IMAGE_NINE_OPITEM,
1097 DrawImageNineOpItem::Unmarshalling, sizeof(DrawImageNineOpItem::ConstructorHandle));
1098
DrawImageNineOpItem(const DrawCmdList & cmdList,DrawImageNineOpItem::ConstructorHandle * handle)1099 DrawImageNineOpItem::DrawImageNineOpItem(const DrawCmdList& cmdList, DrawImageNineOpItem::ConstructorHandle* handle)
1100 : DrawOpItem(IMAGE_NINE_OPITEM), center_(handle->center), dst_(handle->dst), filter_(handle->filter),
1101 hasBrush_(handle->hasBrush)
1102 {
1103 image_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->image);
1104 if (DrawOpItem::holdDrawingImagefunc_) {
1105 DrawOpItem::holdDrawingImagefunc_(image_);
1106 }
1107 if (hasBrush_) {
1108 BrushHandleToBrush(handle->brushHandle, cmdList, brush_);
1109 }
1110 }
1111
Unmarshalling(const DrawCmdList & cmdList,void * handle)1112 std::shared_ptr<DrawOpItem> DrawImageNineOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1113 {
1114 return std::make_shared<DrawImageNineOpItem>(cmdList, static_cast<DrawImageNineOpItem::ConstructorHandle*>(handle));
1115 }
1116
Marshalling(DrawCmdList & cmdList)1117 void DrawImageNineOpItem::Marshalling(DrawCmdList& cmdList)
1118 {
1119 OpDataHandle imageHandle;
1120 if (image_) {
1121 imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
1122 }
1123 BrushHandle brushHandle;
1124 if (hasBrush_) {
1125 BrushToBrushHandle(brush_, cmdList, brushHandle);
1126 }
1127
1128 cmdList.AddOp<ConstructorHandle>(imageHandle, center_, dst_, filter_, brushHandle, hasBrush_);
1129 }
1130
Playback(Canvas * canvas,const Rect * rect)1131 void DrawImageNineOpItem::Playback(Canvas* canvas, const Rect* rect)
1132 {
1133 if (image_ == nullptr) {
1134 LOGD("DrawImageNineOpItem image is null");
1135 return;
1136 }
1137 Brush* brushPtr = hasBrush_ ? &brush_ : nullptr;
1138 canvas->DrawImageNine(image_.get(), center_, dst_, filter_, brushPtr);
1139 }
1140
Dump(std::string & out) const1141 void DrawImageNineOpItem::Dump(std::string& out) const
1142 {
1143 out += GetOpDesc() + "[center";
1144 center_.Dump(out);
1145 out += " dst";
1146 dst_.Dump(out);
1147 out += " filterMode:" + std::to_string(static_cast<int>(filter_));
1148 out += " brush";
1149 if (hasBrush_) {
1150 brush_.Dump(out);
1151 } else {
1152 out += "[null]";
1153 }
1154 out += " image";
1155 if (image_) {
1156 image_->Dump(out);
1157 } else {
1158 out += "[null]";
1159 }
1160 out += "]";
1161 }
1162
1163 /* DrawImageLatticeOpItem */
1164 UNMARSHALLING_REGISTER(DrawImageLattice, DrawOpItem::IMAGE_LATTICE_OPITEM,
1165 DrawImageLatticeOpItem::Unmarshalling, sizeof(DrawImageLatticeOpItem::ConstructorHandle));
1166
DrawImageLatticeOpItem(const DrawCmdList & cmdList,DrawImageLatticeOpItem::ConstructorHandle * handle)1167 DrawImageLatticeOpItem::DrawImageLatticeOpItem(
1168 const DrawCmdList& cmdList, DrawImageLatticeOpItem::ConstructorHandle* handle)
1169 : DrawWithPaintOpItem(cmdList, handle->paintHandle, IMAGE_LATTICE_OPITEM),
1170 dst_(handle->dst), filter_(handle->filter)
1171 {
1172 image_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->image);
1173 if (DrawOpItem::holdDrawingImagefunc_) {
1174 DrawOpItem::holdDrawingImagefunc_(image_);
1175 }
1176 lattice_ = CmdListHelper::GetLatticeFromCmdList(cmdList, handle->latticeHandle);
1177 }
1178
Unmarshalling(const DrawCmdList & cmdList,void * handle)1179 std::shared_ptr<DrawOpItem> DrawImageLatticeOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1180 {
1181 return std::make_shared<DrawImageLatticeOpItem>(
1182 cmdList, static_cast<DrawImageLatticeOpItem::ConstructorHandle*>(handle));
1183 }
1184
Marshalling(DrawCmdList & cmdList)1185 void DrawImageLatticeOpItem::Marshalling(DrawCmdList& cmdList)
1186 {
1187 PaintHandle paintHandle;
1188 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1189 OpDataHandle imageHandle;
1190 if (image_) {
1191 imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
1192 }
1193 auto latticeHandle = CmdListHelper::AddLatticeToCmdList(cmdList, lattice_);
1194 cmdList.AddOp<ConstructorHandle>(imageHandle, latticeHandle, dst_, filter_, paintHandle);
1195 }
1196
Playback(Canvas * canvas,const Rect * rect)1197 void DrawImageLatticeOpItem::Playback(Canvas* canvas, const Rect* rect)
1198 {
1199 if (image_ == nullptr) {
1200 LOGD("DrawImageNineOpItem image is null");
1201 return;
1202 }
1203 canvas->AttachPaint(paint_);
1204 canvas->DrawImageLattice(image_.get(), lattice_, dst_, filter_);
1205 }
1206
Dump(std::string & out) const1207 void DrawImageLatticeOpItem::Dump(std::string& out) const
1208 {
1209 out += GetOpDesc() + "[lattice[";
1210 out += "xCount:" + std::to_string(lattice_.fXCount);
1211 out += " yCount:" + std::to_string(lattice_.fYCount);
1212 out += " xDivs";
1213 DumpArray(out, lattice_.fXDivs, [](std::string& out, int n) {
1214 out += std::to_string(n);
1215 });
1216 out += " yDivs";
1217 DumpArray(out, lattice_.fYDivs, [](std::string& out, int n) {
1218 out += std::to_string(n);
1219 });
1220 out += " rectTypes";
1221 DumpArray(out, lattice_.fRectTypes, [](std::string& out, Lattice::RectType n) {
1222 out += std::to_string(static_cast<int>(n));
1223 });
1224 out += " bounds";
1225 DumpArray(out, lattice_.fBounds, [](std::string& out, const RectI& n) {
1226 n.Dump(out);
1227 });
1228 out += " colors";
1229 DumpArray(out, lattice_.fColors, [](std::string& out, const Color& c) {
1230 c.Dump(out);
1231 });
1232 out += " dst";
1233 dst_.Dump(out);
1234 out += " filterMode:" + std::to_string(static_cast<int>(filter_));
1235 out += " image";
1236 if (image_) {
1237 image_->Dump(out);
1238 } else {
1239 out += "[null]";
1240 }
1241 out += "]";
1242 }
1243
1244 /* DrawAtlasOpItem */
1245 UNMARSHALLING_REGISTER(DrawAtlas, DrawOpItem::ATLAS_OPITEM,
1246 DrawAtlasOpItem::Unmarshalling, sizeof(DrawAtlasOpItem::ConstructorHandle));
1247
DrawAtlasOpItem(const DrawCmdList & cmdList,DrawAtlasOpItem::ConstructorHandle * handle)1248 DrawAtlasOpItem::DrawAtlasOpItem(const DrawCmdList& cmdList, DrawAtlasOpItem::ConstructorHandle* handle)
1249 : DrawWithPaintOpItem(cmdList, handle->paintHandle, ATLAS_OPITEM), mode_(handle->mode),
1250 samplingOptions_(handle->samplingOptions), hasCullRect_(handle->hasCullRect), cullRect_(handle->cullRect)
1251 {
1252 atlas_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->atlas);
1253 if (DrawOpItem::holdDrawingImagefunc_) {
1254 DrawOpItem::holdDrawingImagefunc_(atlas_);
1255 }
1256 xform_ = CmdListHelper::GetVectorFromCmdList<RSXform>(cmdList, handle->xform);
1257 tex_ = CmdListHelper::GetVectorFromCmdList<Rect>(cmdList, handle->tex);
1258 colors_ = CmdListHelper::GetVectorFromCmdList<ColorQuad>(cmdList, handle->colors);
1259 }
1260
Unmarshalling(const DrawCmdList & cmdList,void * handle)1261 std::shared_ptr<DrawOpItem> DrawAtlasOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1262 {
1263 return std::make_shared<DrawAtlasOpItem>(cmdList, static_cast<DrawAtlasOpItem::ConstructorHandle*>(handle));
1264 }
1265
Marshalling(DrawCmdList & cmdList)1266 void DrawAtlasOpItem::Marshalling(DrawCmdList& cmdList)
1267 {
1268 PaintHandle paintHandle;
1269 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1270 OpDataHandle imageHandle;
1271 if (atlas_) {
1272 imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *atlas_);
1273 }
1274 auto xformData = CmdListHelper::AddVectorToCmdList<RSXform>(cmdList, xform_);
1275 auto texData = CmdListHelper::AddVectorToCmdList<Rect>(cmdList, tex_);
1276 auto colorData = CmdListHelper::AddVectorToCmdList<ColorQuad>(cmdList, colors_);
1277 cmdList.AddOp<ConstructorHandle>(imageHandle, xformData, texData, colorData, mode_, samplingOptions_,
1278 hasCullRect_, cullRect_, paintHandle);
1279 }
1280
Playback(Canvas * canvas,const Rect * rect)1281 void DrawAtlasOpItem::Playback(Canvas* canvas, const Rect* rect)
1282 {
1283 if (atlas_ == nullptr) {
1284 LOGD("DrawAtlasOpItem atlas is null");
1285 return;
1286 }
1287 canvas->AttachPaint(paint_);
1288 Rect* rectPtr = hasCullRect_ ? &cullRect_ : nullptr;
1289 canvas->DrawAtlas(atlas_.get(), xform_.data(), tex_.data(), colors_.data(), xform_.size(), mode_,
1290 samplingOptions_, rectPtr);
1291 }
1292
DumpItems(std::string & out) const1293 void DrawAtlasOpItem::DumpItems(std::string& out) const
1294 {
1295 out += " Xform[";
1296 for (auto& e: xform_) {
1297 e.Dump(out);
1298 out += ' ';
1299 }
1300 if (xform_.size() > 0) {
1301 out.pop_back();
1302 }
1303 out += ']';
1304
1305 out += " Tex[";
1306 for (auto& e: tex_) {
1307 e.Dump(out);
1308 out += ' ';
1309 }
1310 if (tex_.size() > 0) {
1311 out.pop_back();
1312 }
1313 out += ']';
1314
1315 out += " Colors[";
1316 for (auto e: colors_) {
1317 Color color(e);
1318 color.Dump(out);
1319 out += ' ';
1320 }
1321 if (colors_.size() > 0) {
1322 out.pop_back();
1323 }
1324 out += ']';
1325
1326 out += " mode:" + std::to_string(static_cast<int>(mode_));
1327 out += " SamplingOption";
1328 samplingOptions_.Dump(out);
1329 out += " hasCullRect:" + std::string(hasCullRect_ ? "true" : "false");
1330 out += " CullRect";
1331 cullRect_.Dump(out);
1332 if (atlas_ != nullptr) {
1333 out += " Atlas";
1334 atlas_->Dump(out);
1335 }
1336 }
1337
1338 /* DrawBitmapOpItem */
1339 UNMARSHALLING_REGISTER(DrawBitmap, DrawOpItem::BITMAP_OPITEM,
1340 DrawBitmapOpItem::Unmarshalling, sizeof(DrawBitmapOpItem::ConstructorHandle));
1341
DrawBitmapOpItem(const DrawCmdList & cmdList,DrawBitmapOpItem::ConstructorHandle * handle)1342 DrawBitmapOpItem::DrawBitmapOpItem(const DrawCmdList& cmdList, DrawBitmapOpItem::ConstructorHandle* handle)
1343 : DrawWithPaintOpItem(cmdList, handle->paintHandle, BITMAP_OPITEM), px_(handle->px), py_(handle->py)
1344 {
1345 bitmap_ = CmdListHelper::GetBitmapFromCmdList(cmdList, handle->bitmap);
1346 }
1347
Unmarshalling(const DrawCmdList & cmdList,void * handle)1348 std::shared_ptr<DrawOpItem> DrawBitmapOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1349 {
1350 return std::make_shared<DrawBitmapOpItem>(cmdList, static_cast<DrawBitmapOpItem::ConstructorHandle*>(handle));
1351 }
1352
Marshalling(DrawCmdList & cmdList)1353 void DrawBitmapOpItem::Marshalling(DrawCmdList& cmdList)
1354 {
1355 PaintHandle paintHandle;
1356 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1357 ImageHandle bitmapHandle;
1358 if (bitmap_) {
1359 bitmapHandle = CmdListHelper::AddBitmapToCmdList(cmdList, *bitmap_);
1360 }
1361 cmdList.AddOp<ConstructorHandle>(bitmapHandle, px_, py_, paintHandle);
1362 }
1363
Playback(Canvas * canvas,const Rect * rect)1364 void DrawBitmapOpItem::Playback(Canvas* canvas, const Rect* rect)
1365 {
1366 if (bitmap_ == nullptr) {
1367 LOGD("DrawBitmapOpItem bitmap is null");
1368 return;
1369 }
1370 canvas->AttachPaint(paint_);
1371 canvas->DrawBitmap(*bitmap_, px_, py_);
1372 }
1373
DumpItems(std::string & out) const1374 void DrawBitmapOpItem::DumpItems(std::string& out) const
1375 {
1376 out += " px:" + std::to_string(px_) + " py:" + std::to_string(py_);
1377 if (bitmap_ != nullptr) {
1378 out += " Bitmap";
1379 bitmap_->Dump(out);
1380 }
1381 }
1382
1383 /* DrawImageOpItem */
1384 UNMARSHALLING_REGISTER(DrawImage, DrawOpItem::IMAGE_OPITEM,
1385 DrawImageOpItem::Unmarshalling, sizeof(DrawImageOpItem::ConstructorHandle));
1386
DrawImageOpItem(const DrawCmdList & cmdList,DrawImageOpItem::ConstructorHandle * handle)1387 DrawImageOpItem::DrawImageOpItem(const DrawCmdList& cmdList, DrawImageOpItem::ConstructorHandle* handle)
1388 : DrawWithPaintOpItem(cmdList, handle->paintHandle, IMAGE_OPITEM), px_(handle->px), py_(handle->py),
1389 samplingOptions_(handle->samplingOptions)
1390 {
1391 image_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->image);
1392 if (DrawOpItem::holdDrawingImagefunc_) {
1393 DrawOpItem::holdDrawingImagefunc_(image_);
1394 }
1395 }
1396
Unmarshalling(const DrawCmdList & cmdList,void * handle)1397 std::shared_ptr<DrawOpItem> DrawImageOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1398 {
1399 return std::make_shared<DrawImageOpItem>(cmdList, static_cast<DrawImageOpItem::ConstructorHandle*>(handle));
1400 }
1401
Marshalling(DrawCmdList & cmdList)1402 void DrawImageOpItem::Marshalling(DrawCmdList& cmdList)
1403 {
1404 PaintHandle paintHandle;
1405 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1406 OpDataHandle imageHandle;
1407 if (image_) {
1408 imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
1409 }
1410 cmdList.AddOp<ConstructorHandle>(imageHandle, px_, py_, samplingOptions_, paintHandle);
1411 }
1412
Playback(Canvas * canvas,const Rect * rect)1413 void DrawImageOpItem::Playback(Canvas* canvas, const Rect* rect)
1414 {
1415 if (image_ == nullptr) {
1416 LOGD("DrawImageOpItem image is null");
1417 return;
1418 }
1419 canvas->AttachPaint(paint_);
1420 canvas->DrawImage(*image_, px_, py_, samplingOptions_);
1421 }
1422
DumpItems(std::string & out) const1423 void DrawImageOpItem::DumpItems(std::string& out) const
1424 {
1425 out += " px:" + std::to_string(px_) + " py:" + std::to_string(py_);
1426 out += " SamplingOptions";
1427 samplingOptions_.Dump(out);
1428 if (image_ != nullptr) {
1429 out += " Image";
1430 image_->Dump(out);
1431 }
1432 }
1433
1434 /* DrawImageRectOpItem */
1435 UNMARSHALLING_REGISTER(DrawImageRect, DrawOpItem::IMAGE_RECT_OPITEM,
1436 DrawImageRectOpItem::Unmarshalling, sizeof(DrawImageRectOpItem::ConstructorHandle));
1437
DrawImageRectOpItem(const DrawCmdList & cmdList,DrawImageRectOpItem::ConstructorHandle * handle)1438 DrawImageRectOpItem::DrawImageRectOpItem(const DrawCmdList& cmdList, DrawImageRectOpItem::ConstructorHandle* handle)
1439 : DrawWithPaintOpItem(cmdList, handle->paintHandle, IMAGE_RECT_OPITEM), src_(handle->src), dst_(handle->dst),
1440 sampling_(handle->sampling), constraint_(handle->constraint), isForeground_(handle->isForeground)
1441 {
1442 image_ = CmdListHelper::GetImageFromCmdList(cmdList, handle->image);
1443 if (DrawOpItem::holdDrawingImagefunc_) {
1444 DrawOpItem::holdDrawingImagefunc_(image_);
1445 }
1446 }
1447
DrawImageRectOpItem(const Image & image,const Rect & src,const Rect & dst,const SamplingOptions & sampling,SrcRectConstraint constraint,const Paint & paint,bool isForeground)1448 DrawImageRectOpItem::DrawImageRectOpItem(const Image& image, const Rect& src,
1449 const Rect& dst, const SamplingOptions& sampling,
1450 SrcRectConstraint constraint, const Paint& paint, bool isForeground)
1451 : DrawWithPaintOpItem(paint, DrawOpItem::IMAGE_RECT_OPITEM), src_(src), dst_(dst), sampling_(sampling),
1452 constraint_(constraint), image_(std::make_shared<Image>(image)), isForeground_(isForeground)
1453 {
1454 if (DrawOpItem::holdDrawingImagefunc_) {
1455 DrawOpItem::holdDrawingImagefunc_(image_);
1456 }
1457 }
1458
Unmarshalling(const DrawCmdList & cmdList,void * handle)1459 std::shared_ptr<DrawOpItem> DrawImageRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1460 {
1461 return std::make_shared<DrawImageRectOpItem>(cmdList, static_cast<DrawImageRectOpItem::ConstructorHandle*>(handle));
1462 }
1463
Marshalling(DrawCmdList & cmdList)1464 void DrawImageRectOpItem::Marshalling(DrawCmdList& cmdList)
1465 {
1466 PaintHandle paintHandle;
1467 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1468 OpDataHandle imageHandle;
1469 if (image_) {
1470 imageHandle = CmdListHelper::AddImageToCmdList(cmdList, *image_);
1471 }
1472 cmdList.AddOp<ConstructorHandle>(imageHandle, src_, dst_, sampling_, constraint_, paintHandle);
1473 }
1474
Playback(Canvas * canvas,const Rect * rect)1475 void DrawImageRectOpItem::Playback(Canvas* canvas, const Rect* rect)
1476 {
1477 if (image_ == nullptr) {
1478 LOGD("DrawImageRectOpItem image is null");
1479 return;
1480 }
1481 if (isForeground_) {
1482 AutoCanvasRestore acr(*canvas, false);
1483 SaveLayerOps ops;
1484 canvas->SaveLayer(ops);
1485 canvas->AttachPaint(paint_);
1486 canvas->DrawImageRect(*image_, src_, dst_, sampling_, constraint_);
1487 Brush brush;
1488 brush.SetColor(canvas->GetEnvForegroundColor());
1489 brush.SetBlendMode(Drawing::BlendMode::SRC_IN);
1490 canvas->DrawBackground(brush);
1491 return;
1492 }
1493 canvas->AttachPaint(paint_);
1494 canvas->DrawImageRect(*image_, src_, dst_, sampling_, constraint_);
1495 }
1496
DumpItems(std::string & out) const1497 void DrawImageRectOpItem::DumpItems(std::string& out) const
1498 {
1499 out += " Src";
1500 src_.Dump(out);
1501 out += " Dst";
1502 src_.Dump(out);
1503 out += " Sampling";
1504 sampling_.Dump(out);
1505 out += " constraint:" + std::to_string(static_cast<int>(constraint_));
1506 if (image_ != nullptr) {
1507 out += " Image";
1508 image_->Dump(out);
1509 }
1510 out += " isForeground:" + std::string(isForeground_ ? "true" : "false");
1511 }
1512
1513 /* DrawRecordCmdOpItem */
1514 UNMARSHALLING_REGISTER(DrawRecordCmd, DrawOpItem::RECORD_CMD_OPITEM,
1515 DrawRecordCmdOpItem::Unmarshalling, sizeof(DrawRecordCmdOpItem::ConstructorHandle));
1516
DrawRecordCmdOpItem(const DrawCmdList & cmdList,DrawRecordCmdOpItem::ConstructorHandle * handle)1517 DrawRecordCmdOpItem::DrawRecordCmdOpItem(
1518 const DrawCmdList& cmdList, DrawRecordCmdOpItem::ConstructorHandle* handle)
1519 : DrawOpItem(RECORD_CMD_OPITEM), hasBrush_(handle->hasBrush)
1520 {
1521 recordCmd_ = CmdListHelper::GetRecordCmdFromCmdList(cmdList, handle->recordCmdHandle);
1522 matrix_.SetAll(handle->matrixBuffer);
1523 if (hasBrush_) {
1524 BrushHandleToBrush(handle->brushHandle, cmdList, brush_);
1525 }
1526 }
1527
DrawRecordCmdOpItem(const std::shared_ptr<RecordCmd> & recordCmd,const Matrix * matrix,const Brush * brush)1528 DrawRecordCmdOpItem::DrawRecordCmdOpItem(const std::shared_ptr<RecordCmd>& recordCmd,
1529 const Matrix* matrix, const Brush* brush)
1530 : DrawOpItem(RECORD_CMD_OPITEM), recordCmd_(recordCmd)
1531 {
1532 if (matrix != nullptr) {
1533 matrix_ = *matrix;
1534 }
1535 if (brush != nullptr) {
1536 hasBrush_ = true;
1537 brush_ = *brush;
1538 }
1539 }
1540
Unmarshalling(const DrawCmdList & cmdList,void * handle)1541 std::shared_ptr<DrawOpItem> DrawRecordCmdOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1542 {
1543 return std::make_shared<DrawRecordCmdOpItem>(
1544 cmdList, static_cast<DrawRecordCmdOpItem::ConstructorHandle*>(handle));
1545 }
1546
Marshalling(DrawCmdList & cmdList)1547 void DrawRecordCmdOpItem::Marshalling(DrawCmdList& cmdList)
1548 {
1549 auto recordCmdHandle = CmdListHelper::AddRecordCmdToCmdList(cmdList, recordCmd_);
1550 Matrix::Buffer matrixBuffer;
1551 matrix_.GetAll(matrixBuffer);
1552 BrushHandle brushHandle;
1553 if (hasBrush_) {
1554 BrushToBrushHandle(brush_, cmdList, brushHandle);
1555 }
1556 cmdList.AddOp<ConstructorHandle>(recordCmdHandle,
1557 matrixBuffer, hasBrush_, brushHandle);
1558 }
1559
Playback(Canvas * canvas,const Rect * rect)1560 void DrawRecordCmdOpItem::Playback(Canvas* canvas, const Rect* rect)
1561 {
1562 Brush* brushPtr = hasBrush_ ? &brush_ : nullptr;
1563 canvas->DrawRecordCmd(recordCmd_, &matrix_, brushPtr);
1564 }
1565
1566 /* DrawPictureOpItem */
1567 UNMARSHALLING_REGISTER(DrawPicture, DrawOpItem::PICTURE_OPITEM,
1568 DrawPictureOpItem::Unmarshalling, sizeof(DrawPictureOpItem::ConstructorHandle));
1569
DrawPictureOpItem(const DrawCmdList & cmdList,DrawPictureOpItem::ConstructorHandle * handle)1570 DrawPictureOpItem::DrawPictureOpItem(const DrawCmdList& cmdList, DrawPictureOpItem::ConstructorHandle* handle)
1571 : DrawOpItem(PICTURE_OPITEM)
1572 {
1573 picture_ = CmdListHelper::GetPictureFromCmdList(cmdList, handle->picture);
1574 }
1575
Unmarshalling(const DrawCmdList & cmdList,void * handle)1576 std::shared_ptr<DrawOpItem> DrawPictureOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1577 {
1578 return std::make_shared<DrawPictureOpItem>(cmdList, static_cast<DrawPictureOpItem::ConstructorHandle*>(handle));
1579 }
1580
Marshalling(DrawCmdList & cmdList)1581 void DrawPictureOpItem::Marshalling(DrawCmdList& cmdList)
1582 {
1583 OpDataHandle pictureHandle;
1584 if (picture_) {
1585 pictureHandle = CmdListHelper::AddPictureToCmdList(cmdList, *picture_);
1586 }
1587 cmdList.AddOp<ConstructorHandle>(pictureHandle);
1588 }
1589
Playback(Canvas * canvas,const Rect * rect)1590 void DrawPictureOpItem::Playback(Canvas* canvas, const Rect* rect)
1591 {
1592 if (picture_ == nullptr) {
1593 LOGD("DrawPictureOpItem picture is null");
1594 return;
1595 }
1596 canvas->DrawPicture(*picture_);
1597 }
1598
1599 /* DrawTextBlobOpItem */
1600 UNMARSHALLING_REGISTER(DrawTextBlob, DrawOpItem::TEXT_BLOB_OPITEM,
1601 DrawTextBlobOpItem::Unmarshalling, sizeof(DrawTextBlobOpItem::ConstructorHandle));
1602
SimplifyPaint(ColorQuad colorQuad,Paint & paint)1603 void SimplifyPaint(ColorQuad colorQuad, Paint& paint)
1604 {
1605 Color color{colorQuad};
1606 paint.SetColor(color);
1607 paint.SetShaderEffect(nullptr);
1608 if (paint.HasFilter()) {
1609 Filter filter = paint.GetFilter();
1610 if (filter.GetColorFilter() != nullptr) {
1611 filter.SetColorFilter(nullptr);
1612 paint.SetFilter(filter);
1613 }
1614 }
1615 paint.SetWidth(1.04); // 1.04 is empirical value
1616 paint.SetJoinStyle(Pen::JoinStyle::ROUND_JOIN);
1617 }
1618
DrawTextBlobOpItem(const DrawCmdList & cmdList,DrawTextBlobOpItem::ConstructorHandle * handle)1619 DrawTextBlobOpItem::DrawTextBlobOpItem(const DrawCmdList& cmdList, DrawTextBlobOpItem::ConstructorHandle* handle)
1620 : DrawWithPaintOpItem(cmdList, handle->paintHandle, TEXT_BLOB_OPITEM), x_(handle->x), y_(handle->y)
1621 {
1622 globalUniqueId_ = handle->globalUniqueId;
1623 textContrast_ = handle->textContrast;
1624 textBlob_ = CmdListHelper::GetTextBlobFromCmdList(cmdList, handle->textBlob, handle->globalUniqueId);
1625 if (textBlob_) {
1626 textBlob_->SetTextContrast(textContrast_);
1627 }
1628 }
1629
Unmarshalling(const DrawCmdList & cmdList,void * handle)1630 std::shared_ptr<DrawOpItem> DrawTextBlobOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
1631 {
1632 return std::make_shared<DrawTextBlobOpItem>(cmdList, static_cast<DrawTextBlobOpItem::ConstructorHandle*>(handle));
1633 }
1634
Marshalling(DrawCmdList & cmdList)1635 void DrawTextBlobOpItem::Marshalling(DrawCmdList& cmdList)
1636 {
1637 static uint64_t shiftedPid = static_cast<uint64_t>(GetRealPid()) << 32; // 32 for 64-bit unsignd number shift
1638 PaintHandle paintHandle;
1639 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
1640 TextBlob::Context ctx {nullptr, false};
1641 auto textBlobHandle = CmdListHelper::AddTextBlobToCmdList(cmdList, textBlob_.get(), &ctx);
1642 uint64_t globalUniqueId = 0;
1643 if (ctx.GetTypeface() != nullptr) {
1644 uint32_t typefaceId = ctx.GetTypeface()->GetUniqueID();
1645 globalUniqueId = (shiftedPid | typefaceId);
1646 }
1647
1648 if (textBlob_) {
1649 cmdList.AddOp<ConstructorHandle>(textBlobHandle,
1650 globalUniqueId, textBlob_->GetTextContrast(), x_, y_, paintHandle);
1651 }
1652 }
1653
GetTypefaceId()1654 uint64_t DrawTextBlobOpItem::GetTypefaceId()
1655 {
1656 return globalUniqueId_;
1657 }
1658
Playback(Canvas * canvas,const Rect * rect)1659 void DrawTextBlobOpItem::Playback(Canvas* canvas, const Rect* rect)
1660 {
1661 if (textBlob_ == nullptr) {
1662 LOGD("DrawTextBlobOpItem textBlob is null");
1663 return;
1664 }
1665 RectI globalClipBounds = canvas->GetDeviceClipBounds();
1666 bool saveFlag = false;
1667 if (globalClipBounds.GetWidth() == 1 || globalClipBounds.GetHeight() == 1) {
1668 // In this case, the clip area for textblob must have AA.
1669 Matrix m = canvas->GetTotalMatrix();
1670 canvas->Save();
1671 canvas->SetMatrix(m);
1672 auto bounds = textBlob_->Bounds();
1673 if (bounds && bounds->IsValid()) {
1674 canvas->ClipRect(*bounds, ClipOp::INTERSECT, true);
1675 }
1676 saveFlag = true;
1677 }
1678 TextContrast customerEnableValue = textBlob_->GetTextContrast();
1679 if (IsHighContrastEnable(canvas, customerEnableValue)) {
1680 LOGD("DrawTextBlobOpItem::Playback highContrastEnabled, %{public}s, %{public}d", __FUNCTION__, __LINE__);
1681 DrawHighContrastEnabled(canvas);
1682 } else {
1683 canvas->AttachPaint(paint_);
1684 canvas->DrawTextBlob(textBlob_.get(), x_, y_);
1685 }
1686 if (saveFlag) {
1687 canvas->Restore();
1688 }
1689 }
1690
IsHighContrastEnable(Canvas * canvas,TextContrast value) const1691 bool DrawTextBlobOpItem::IsHighContrastEnable(Canvas* canvas, TextContrast value) const
1692 {
1693 bool canvasHighContrastEnabled = canvas->isHighContrastEnabled();
1694 switch (value) {
1695 case TextContrast::FOLLOW_SYSTEM:
1696 return canvasHighContrastEnabled;
1697 case TextContrast::DISABLE_CONTRAST:
1698 return false;
1699 case TextContrast::ENABLE_CONTRAST:
1700 return true;
1701 default:
1702 return canvasHighContrastEnabled;
1703 }
1704 }
1705
GetOffScreenSurfaceAndCanvas(const Canvas & canvas,std::shared_ptr<Drawing::Surface> & offScreenSurface,std::shared_ptr<Canvas> & offScreenCanvas) const1706 bool DrawTextBlobOpItem::GetOffScreenSurfaceAndCanvas(const Canvas& canvas,
1707 std::shared_ptr<Drawing::Surface>& offScreenSurface, std::shared_ptr<Canvas>& offScreenCanvas) const
1708 {
1709 auto surface = canvas.GetSurface();
1710 auto textBlobBounds = textBlob_->Bounds();
1711 if (!surface || !textBlobBounds) {
1712 return false;
1713 }
1714 offScreenSurface = surface->MakeSurface(textBlobBounds->GetWidth(), textBlobBounds->GetHeight());
1715 if (!offScreenSurface) {
1716 return false;
1717 }
1718 offScreenCanvas = offScreenSurface->GetCanvas();
1719 if (!offScreenCanvas) {
1720 return false;
1721 }
1722 offScreenCanvas->Translate(-textBlobBounds->GetLeft(), -textBlobBounds->GetTop());
1723 return true;
1724 }
1725
DrawHighContrastEnabled(Canvas * canvas) const1726 void DrawTextBlobOpItem::DrawHighContrastEnabled(Canvas* canvas) const
1727 {
1728 ColorQuad colorQuad = paint_.GetColor().CastToColorQuad();
1729 if (Color::ColorQuadGetA(colorQuad) == 0 || paint_.HasFilter()) {
1730 canvas->AttachPaint(paint_);
1731 canvas->DrawTextBlob(textBlob_.get(), x_, y_);
1732 return;
1733 }
1734 // in case of perceptible transparent, text should be drawn offscreen to avoid stroke and content overlap.
1735 if (canvas->GetAlphaSaveCount() > 0 && canvas->GetAlpha() < HIGH_CONTRAST_OFFSCREEN_THREASHOLD) {
1736 std::shared_ptr<Drawing::Surface> offScreenSurface;
1737 std::shared_ptr<Canvas> offScreenCanvas;
1738 if (GetOffScreenSurfaceAndCanvas(*canvas, offScreenSurface, offScreenCanvas)) {
1739 DrawHighContrast(offScreenCanvas.get(), true);
1740 offScreenCanvas->Flush();
1741 auto image = offScreenSurface->GetImageSnapshot();
1742 if (image == nullptr) {
1743 return;
1744 }
1745 Drawing::Brush paint;
1746 paint.SetAntiAlias(true);
1747 canvas->AttachBrush(paint);
1748 Drawing::SamplingOptions sampling =
1749 Drawing::SamplingOptions(Drawing::FilterMode::NEAREST, Drawing::MipmapMode::NEAREST);
1750 canvas->DrawImage(*image, x_ + textBlob_->Bounds()->GetLeft(),
1751 y_ + textBlob_->Bounds()->GetTop(), sampling);
1752 canvas->DetachBrush();
1753 return;
1754 }
1755 }
1756 DrawHighContrast(canvas);
1757 }
1758
DrawHighContrast(Canvas * canvas,bool offScreen) const1759 void DrawTextBlobOpItem::DrawHighContrast(Canvas* canvas, bool offScreen) const
1760 {
1761 ColorQuad colorQuad = paint_.GetColor().CastToColorQuad();
1762 uint32_t channelSum = Color::ColorQuadGetR(colorQuad) + Color::ColorQuadGetG(colorQuad) +
1763 Color::ColorQuadGetB(colorQuad);
1764 bool flag = channelSum < 594; // 594 is empirical value
1765
1766 // draw outline stroke with pen
1767 Drawing::Pen outlinePen;
1768 outlinePen.SetColor(flag ? Color::COLOR_WHITE : Color::COLOR_BLACK);
1769 outlinePen.SetAntiAlias(true);
1770 outlinePen.SetBlenderEnabled(false);
1771 canvas->AttachPen(outlinePen);
1772 offScreen ? canvas->DrawTextBlob(textBlob_.get(), 0, 0) : canvas->DrawTextBlob(textBlob_.get(), x_, y_);
1773
1774 // draw inner content with brush
1775 Drawing::Brush innerBrush;
1776 innerBrush.SetColor(flag ? Color::COLOR_BLACK : Color::COLOR_WHITE);
1777 canvas->DetachPen();
1778 canvas->AttachBrush(innerBrush);
1779 offScreen ? canvas->DrawTextBlob(textBlob_.get(), 0, 0) : canvas->DrawTextBlob(textBlob_.get(), x_, y_);
1780 canvas->DetachBrush();
1781 }
1782
GenerateCachedOpItem(DrawCmdList & cmdList,const TextBlob * textBlob,scalar x,scalar y,Paint & p)1783 bool DrawTextBlobOpItem::ConstructorHandle::GenerateCachedOpItem(
1784 DrawCmdList& cmdList, const TextBlob* textBlob, scalar x, scalar y, Paint& p)
1785 {
1786 if (!textBlob) {
1787 LOGD("textBlob nullptr, %{public}s, %{public}d", __FUNCTION__, __LINE__);
1788 return false;
1789 }
1790
1791 auto bounds = textBlob->Bounds();
1792 if (!bounds || !bounds->IsValid()) {
1793 return false;
1794 }
1795 bounds->Offset(x, y);
1796 bounds->MakeOutset(TEXT_BLOB_CACHE_MARGIN, TEXT_BLOB_CACHE_MARGIN);
1797 // create CPU raster surface
1798 Drawing::ImageInfo offscreenInfo { bounds->GetWidth(), bounds->GetHeight(),
1799 Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL, nullptr};
1800 std::shared_ptr<Surface> offscreenSurface = Surface::MakeRaster(offscreenInfo);
1801 if (offscreenSurface == nullptr) {
1802 return false;
1803 }
1804 auto offscreenCanvas = offscreenSurface->GetCanvas();
1805 if (offscreenCanvas == nullptr) {
1806 return false;
1807 }
1808 if (bounds->GetLeft() != 0 || bounds->GetTop() != 0) {
1809 offscreenCanvas->Translate(-bounds->GetLeft(), -bounds->GetTop());
1810 }
1811
1812 //OffscreenCanvas used once, detach is unnecessary, FakeBrush/Pen avoid affecting ImageRectOp, attach is necessary.
1813 bool isForeground = false;
1814 if (p.GetColor() == Drawing::Color::COLOR_FOREGROUND) {
1815 isForeground = true;
1816 p.SetColor(Drawing::Color::COLOR_BLACK);
1817 }
1818 offscreenCanvas->AttachPaint(p);
1819 offscreenCanvas->DrawTextBlob(textBlob, x, y);
1820
1821 std::shared_ptr<Image> image = offscreenSurface->GetImageSnapshot();
1822 if (image == nullptr) {
1823 return false;
1824 }
1825 Drawing::Rect src(0, 0, image->GetWidth(), image->GetHeight());
1826 Drawing::Rect dst(bounds->GetLeft(), bounds->GetTop(),
1827 bounds->GetLeft() + image->GetWidth(), bounds->GetTop() + image->GetHeight());
1828 SamplingOptions sampling(FilterMode::LINEAR, MipmapMode::LINEAR);
1829 auto imageHandle = CmdListHelper::AddImageToCmdList(cmdList, image);
1830 PaintHandle fakePaintHandle;
1831 fakePaintHandle.isAntiAlias = true;
1832 fakePaintHandle.style = Paint::PaintStyle::PAINT_FILL;
1833 cmdList.AddOp<DrawImageRectOpItem::ConstructorHandle>(
1834 imageHandle, src, dst, sampling, SrcRectConstraint::STRICT_SRC_RECT_CONSTRAINT, fakePaintHandle, isForeground);
1835 return true;
1836 }
1837
GenerateCachedOpItem(DrawCmdList & cmdList,Canvas * canvas)1838 bool DrawTextBlobOpItem::ConstructorHandle::GenerateCachedOpItem(DrawCmdList& cmdList, Canvas* canvas)
1839 {
1840 std::shared_ptr<TextBlob> textBlob_ = CmdListHelper::GetTextBlobFromCmdList(cmdList, textBlob, globalUniqueId);
1841 if (!textBlob_) {
1842 LOGD("textBlob nullptr, %{public}s, %{public}d", __FUNCTION__, __LINE__);
1843 return false;
1844 }
1845
1846 auto bounds = textBlob_->Bounds();
1847 if (!bounds || !bounds->IsValid()) {
1848 return false;
1849 }
1850 bounds->Offset(x, y);
1851
1852 std::shared_ptr<Surface> offscreenSurface = nullptr;
1853
1854 if (auto surface = canvas != nullptr ? canvas->GetSurface() : nullptr) {
1855 // create GPU accelerated surface if possible
1856 offscreenSurface = surface->MakeSurface(bounds->GetWidth(), bounds->GetHeight());
1857 } else {
1858 // create CPU raster surface
1859 Drawing::ImageInfo offscreenInfo { bounds->GetWidth(), bounds->GetHeight(),
1860 Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL, nullptr};
1861 offscreenSurface = Surface::MakeRaster(offscreenInfo);
1862 }
1863 if (offscreenSurface == nullptr) {
1864 return false;
1865 }
1866
1867 Canvas* offscreenCanvas = offscreenSurface->GetCanvas().get();
1868 if (!offscreenCanvas) {
1869 return false;
1870 }
1871
1872 // align draw op to [0, 0]
1873 if (bounds->GetLeft() != 0 || bounds->GetTop() != 0) {
1874 offscreenCanvas->Translate(-bounds->GetLeft(), -bounds->GetTop());
1875 }
1876
1877 Paint p;
1878 GeneratePaintFromHandle(paintHandle, cmdList, p);
1879 offscreenCanvas->AttachPaint(p);
1880 offscreenCanvas->DrawTextBlob(textBlob_.get(), x, y);
1881
1882 std::shared_ptr<Image> image = offscreenSurface->GetImageSnapshot();
1883 if (image == nullptr) {
1884 return false;
1885 }
1886 Drawing::Rect src(0, 0, image->GetWidth(), image->GetHeight());
1887 Drawing::Rect dst(bounds->GetLeft(), bounds->GetTop(),
1888 bounds->GetLeft() + image->GetWidth(), bounds->GetTop() + image->GetHeight());
1889 SamplingOptions sampling;
1890 auto imageHandle = CmdListHelper::AddImageToCmdList(cmdList, image);
1891 PaintHandle fakePaintHandle;
1892 fakePaintHandle.isAntiAlias = true;
1893 fakePaintHandle.style = Paint::PaintStyle::PAINT_FILL;
1894 cmdList.AddOp<DrawImageRectOpItem::ConstructorHandle>(imageHandle, src, dst, sampling,
1895 SrcRectConstraint::FAST_SRC_RECT_CONSTRAINT, fakePaintHandle);
1896 return true;
1897 }
1898
GenerateCachedOpItem(Canvas * canvas)1899 std::shared_ptr<DrawImageRectOpItem> DrawTextBlobOpItem::GenerateCachedOpItem(Canvas* canvas)
1900 {
1901 if (!textBlob_) {
1902 LOGD("textBlob nullptr, %{public}s, %{public}d", __FUNCTION__, __LINE__);
1903 return nullptr;
1904 }
1905
1906 auto bounds = textBlob_->Bounds();
1907 if (!bounds || !bounds->IsValid()) {
1908 return nullptr;
1909 }
1910 bounds->Offset(x_, y_);
1911
1912 std::shared_ptr<Surface> offscreenSurface = nullptr;
1913
1914 if (auto surface = canvas != nullptr ? canvas->GetSurface() : nullptr) {
1915 // create GPU accelerated surface if possible
1916 offscreenSurface = surface->MakeSurface(bounds->GetWidth(), bounds->GetHeight());
1917 } else {
1918 // create CPU raster surface
1919 Drawing::ImageInfo offscreenInfo { bounds->GetWidth(), bounds->GetHeight(),
1920 Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL, nullptr};
1921 offscreenSurface = Surface::MakeRaster(offscreenInfo);
1922 }
1923 if (offscreenSurface == nullptr) {
1924 return nullptr;
1925 }
1926
1927 Canvas* offscreenCanvas = offscreenSurface->GetCanvas().get();
1928 if (!offscreenCanvas) {
1929 return nullptr;
1930 }
1931
1932 // align draw op to [0, 0]
1933 if (bounds->GetLeft() != 0 || bounds->GetTop() != 0) {
1934 offscreenCanvas->Translate(-bounds->GetLeft(), -bounds->GetTop());
1935 }
1936
1937 Playback(offscreenCanvas, nullptr);
1938
1939 std::shared_ptr<Image> image = offscreenSurface->GetImageSnapshot();
1940 if (image == nullptr) {
1941 return nullptr;
1942 }
1943 Drawing::Rect src(0, 0, image->GetWidth(), image->GetHeight());
1944 Drawing::Rect dst(bounds->GetLeft(), bounds->GetTop(), bounds->GetRight(), bounds->GetBottom());
1945 Paint fakePaint;
1946 fakePaint.SetStyle(Paint::PaintStyle::PAINT_FILL);
1947 fakePaint.SetAntiAlias(true);
1948 return std::make_shared<DrawImageRectOpItem>(*image, src, dst, SamplingOptions(),
1949 SrcRectConstraint::FAST_SRC_RECT_CONSTRAINT, fakePaint);
1950 }
1951
DumpItems(std::string & out) const1952 void DrawTextBlobOpItem::DumpItems(std::string& out) const
1953 {
1954 out += " scalarX:" + std::to_string(x_) + " scalarY:" + std::to_string(y_);
1955 if (textBlob_ != nullptr) {
1956 out += " TextBlob[";
1957 out += "UniqueID:" + std::to_string(textBlob_->UniqueID());
1958 std::vector<uint16_t> glyphIds;
1959 TextBlob::GetDrawingGlyphIDforTextBlob(textBlob_.get(), glyphIds);
1960 out += " GlyphID[";
1961 for (size_t index = 0; index < std::min(glyphIds.size(), MAX_GLYPH_ID_COUNT); index++) {
1962 out += " " + std::to_string(glyphIds[index]);
1963 }
1964 out += "]";
1965 switch (textBlob_ -> GetTextContrast()) {
1966 case TextContrast::FOLLOW_SYSTEM:
1967 out += " TextContrast: FOLLOW_SYSTEM";
1968 break;
1969 case TextContrast::DISABLE_CONTRAST:
1970 out += " TextContrast: DISABLE_CONTRAST";
1971 break;
1972 case TextContrast::ENABLE_CONTRAST:
1973 out += " TextContrast: ENABLE_CONTRAST";
1974 break;
1975 default:
1976 break;
1977 }
1978 auto bounds = textBlob_->Bounds();
1979 if (bounds != nullptr) {
1980 out += " Bounds";
1981 bounds->Dump(out);
1982 }
1983 out += " isEmoji:" + std::string(textBlob_->IsEmoji() ? "true" : "false");
1984 out += ']';
1985 }
1986 }
1987
GetOpItemCmdlistDrawRegion()1988 Rect DrawTextBlobOpItem::GetOpItemCmdlistDrawRegion()
1989 {
1990 if (textBlob_ == nullptr) {
1991 LOGD("GetOpItemCmdlistDrawRegion textBlob is nullptr");
1992 return { 0, 0, 0, 0 };
1993 }
1994
1995 auto bounds = textBlob_->Bounds();
1996 if (bounds == nullptr || bounds->IsEmpty()) {
1997 LOGD("GetOpItemCmdlistDrawRegion textBlob opItem's bounds is nullptr or empty");
1998 return { 0, 0, 0, 0 };
1999 }
2000
2001 Rect res = *bounds;
2002 res.Offset(x_, y_);
2003 return res;
2004 }
2005
2006 /* DrawSymbolOpItem */
2007 UNMARSHALLING_REGISTER(DrawSymbol, DrawOpItem::SYMBOL_OPITEM,
2008 DrawSymbolOpItem::Unmarshalling, sizeof(DrawSymbolOpItem::ConstructorHandle));
2009
DrawSymbolOpItem(const DrawCmdList & cmdList,DrawSymbolOpItem::ConstructorHandle * handle)2010 DrawSymbolOpItem::DrawSymbolOpItem(const DrawCmdList& cmdList, DrawSymbolOpItem::ConstructorHandle* handle)
2011 : DrawWithPaintOpItem(cmdList, handle->paintHandle, SYMBOL_OPITEM), locate_(handle->locate)
2012 {
2013 symbol_ = CmdListHelper::GetSymbolFromCmdList(cmdList, handle->symbolHandle);
2014 }
2015
Unmarshalling(const DrawCmdList & cmdList,void * handle)2016 std::shared_ptr<DrawOpItem> DrawSymbolOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2017 {
2018 return std::make_shared<DrawSymbolOpItem>(cmdList, static_cast<DrawSymbolOpItem::ConstructorHandle*>(handle));
2019 }
2020
Marshalling(DrawCmdList & cmdList)2021 void DrawSymbolOpItem::Marshalling(DrawCmdList& cmdList)
2022 {
2023 PaintHandle paintHandle;
2024 GenerateHandleFromPaint(cmdList, paint_, paintHandle);
2025 auto symbolHandle = CmdListHelper::AddSymbolToCmdList(cmdList, symbol_);
2026 cmdList.AddOp<ConstructorHandle>(symbolHandle, locate_, paintHandle);
2027 }
2028
Playback(Canvas * canvas,const Rect * rect)2029 void DrawSymbolOpItem::Playback(Canvas* canvas, const Rect* rect)
2030 {
2031 if (!canvas) {
2032 LOGD("SymbolOpItem::Playback failed cause by canvas is nullptr");
2033 return;
2034 }
2035 Path path(symbol_.path_);
2036
2037 // 1.0 move path
2038 path.Offset(locate_.GetX(), locate_.GetY());
2039
2040 // 2.0 split path
2041 std::vector<Path> paths;
2042 DrawingHMSymbol::PathOutlineDecompose(path, paths);
2043 std::vector<Path> pathLayers;
2044 DrawingHMSymbol::MultilayerPath(symbol_.symbolInfo_.layers, paths, pathLayers);
2045
2046 // 3.0 set paint
2047 Paint paintCopy = paint_;
2048 paintCopy.SetAntiAlias(true);
2049 paintCopy.SetStyle(Paint::PaintStyle::PAINT_FILL_STROKE);
2050 paintCopy.SetWidth(0.0f);
2051 paintCopy.SetJoinStyle(Pen::JoinStyle::ROUND_JOIN);
2052
2053 // draw path
2054 std::vector<DrawingRenderGroup> groups = symbol_.symbolInfo_.renderGroups;
2055 LOGD("SymbolOpItem::Draw RenderGroup size %{public}d", static_cast<int>(groups.size()));
2056 if (groups.size() == 0) {
2057 canvas->AttachPaint(paintCopy);
2058 canvas->DrawPath(path);
2059 }
2060 for (auto group : groups) {
2061 Path multPath;
2062 MergeDrawingPath(multPath, group, pathLayers);
2063 // color
2064 paintCopy.SetColor(Color::ColorQuadSetARGB(0xFF, group.color.r, group.color.g, group.color.b));
2065 paintCopy.SetAlphaF(group.color.a);
2066 canvas->AttachPaint(paintCopy);
2067 canvas->DrawPath(multPath);
2068 }
2069 }
2070
MergeDrawingPath(Drawing::Path & multPath,Drawing::DrawingRenderGroup & group,std::vector<Drawing::Path> & pathLayers)2071 void DrawSymbolOpItem::MergeDrawingPath(
2072 Drawing::Path& multPath, Drawing::DrawingRenderGroup& group, std::vector<Drawing::Path>& pathLayers)
2073 {
2074 for (auto groupInfo : group.groupInfos) {
2075 Drawing::Path pathTemp;
2076 for (auto k : groupInfo.layerIndexes) {
2077 if (k >= pathLayers.size()) {
2078 continue;
2079 }
2080 pathTemp.AddPath(pathLayers[k]);
2081 }
2082 for (size_t h : groupInfo.maskIndexes) {
2083 if (h >= pathLayers.size()) {
2084 continue;
2085 }
2086 Drawing::Path outPath;
2087 auto isOk = outPath.Op(pathTemp, pathLayers[h], Drawing::PathOp::DIFFERENCE);
2088 if (isOk) {
2089 pathTemp = outPath;
2090 }
2091 }
2092 multPath.AddPath(pathTemp);
2093 }
2094 }
2095
DumpItems(std::string & out) const2096 void DrawSymbolOpItem::DumpItems(std::string& out) const
2097 {
2098 out += " symbol[symbolId:" + std::to_string(symbol_.symbolId);
2099 out += " DrawingType:" + std::to_string(static_cast<int>(symbol_.path_.GetDrawingType()));
2100 auto rect = symbol_.path_.GetBounds();
2101 out += " path";
2102 rect.Dump(out);
2103 out += " symbolGlyphId:" + std::to_string(symbol_.symbolInfo_.symbolGlyphId);
2104 out += "]";
2105 out += " locate";
2106 locate_.Dump(out);
2107 }
2108
2109 /* ClipRectOpItem */
2110 UNMARSHALLING_REGISTER(ClipRect, DrawOpItem::CLIP_RECT_OPITEM,
2111 ClipRectOpItem::Unmarshalling, sizeof(ClipRectOpItem::ConstructorHandle));
2112
ClipRectOpItem(ClipRectOpItem::ConstructorHandle * handle)2113 ClipRectOpItem::ClipRectOpItem(ClipRectOpItem::ConstructorHandle* handle)
2114 : DrawOpItem(CLIP_RECT_OPITEM), rect_(handle->rect), clipOp_(handle->clipOp), doAntiAlias_(handle->doAntiAlias) {}
2115
Unmarshalling(const DrawCmdList & cmdList,void * handle)2116 std::shared_ptr<DrawOpItem> ClipRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2117 {
2118 return std::make_shared<ClipRectOpItem>(static_cast<ClipRectOpItem::ConstructorHandle*>(handle));
2119 }
2120
Marshalling(DrawCmdList & cmdList)2121 void ClipRectOpItem::Marshalling(DrawCmdList& cmdList)
2122 {
2123 cmdList.AddOp<ConstructorHandle>(rect_, clipOp_, doAntiAlias_);
2124 }
2125
Playback(Canvas * canvas,const Rect * rect)2126 void ClipRectOpItem::Playback(Canvas* canvas, const Rect* rect)
2127 {
2128 canvas->ClipRect(rect_, clipOp_, doAntiAlias_);
2129 }
2130
Dump(std::string & out) const2131 void ClipRectOpItem::Dump(std::string& out) const
2132 {
2133 out += GetOpDesc() + "[rect";
2134 rect_.Dump(out);
2135 out += " clipOp:" + std::to_string(static_cast<int>(clipOp_));
2136 out += " antiAlias:" + std::string(doAntiAlias_ ? "true" : "false");
2137 out += "]";
2138 }
2139
2140 /* ClipIRectOpItem */
2141 UNMARSHALLING_REGISTER(ClipIRect, DrawOpItem::CLIP_IRECT_OPITEM,
2142 ClipIRectOpItem::Unmarshalling, sizeof(ClipIRectOpItem::ConstructorHandle));
2143
ClipIRectOpItem(ClipIRectOpItem::ConstructorHandle * handle)2144 ClipIRectOpItem::ClipIRectOpItem(ClipIRectOpItem::ConstructorHandle* handle)
2145 : DrawOpItem(CLIP_IRECT_OPITEM), rect_(handle->rect), clipOp_(handle->clipOp) {}
2146
Unmarshalling(const DrawCmdList & cmdList,void * handle)2147 std::shared_ptr<DrawOpItem> ClipIRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2148 {
2149 return std::make_shared<ClipIRectOpItem>(static_cast<ClipIRectOpItem::ConstructorHandle*>(handle));
2150 }
2151
Marshalling(DrawCmdList & cmdList)2152 void ClipIRectOpItem::Marshalling(DrawCmdList& cmdList)
2153 {
2154 cmdList.AddOp<ConstructorHandle>(rect_, clipOp_);
2155 }
2156
Playback(Canvas * canvas,const Rect * rect)2157 void ClipIRectOpItem::Playback(Canvas* canvas, const Rect* rect)
2158 {
2159 canvas->ClipIRect(rect_, clipOp_);
2160 }
2161
Dump(std::string & out) const2162 void ClipIRectOpItem::Dump(std::string& out) const
2163 {
2164 out += GetOpDesc() + "[rect";
2165 rect_.Dump(out);
2166 out += " clipOp:" + std::to_string(static_cast<int>(clipOp_));
2167 out += "]";
2168 }
2169
2170 /* ClipRoundRectOpItem */
2171 UNMARSHALLING_REGISTER(ClipRoundRect, DrawOpItem::CLIP_ROUND_RECT_OPITEM,
2172 ClipRoundRectOpItem::Unmarshalling, sizeof(ClipRoundRectOpItem::ConstructorHandle));
2173
ClipRoundRectOpItem(ClipRoundRectOpItem::ConstructorHandle * handle)2174 ClipRoundRectOpItem::ClipRoundRectOpItem(ClipRoundRectOpItem::ConstructorHandle* handle)
2175 : DrawOpItem(CLIP_ROUND_RECT_OPITEM), rrect_(handle->rrect), clipOp_(handle->clipOp),
2176 doAntiAlias_(handle->doAntiAlias) {}
2177
Unmarshalling(const DrawCmdList & cmdList,void * handle)2178 std::shared_ptr<DrawOpItem> ClipRoundRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2179 {
2180 return std::make_shared<ClipRoundRectOpItem>(static_cast<ClipRoundRectOpItem::ConstructorHandle*>(handle));
2181 }
2182
Marshalling(DrawCmdList & cmdList)2183 void ClipRoundRectOpItem::Marshalling(DrawCmdList& cmdList)
2184 {
2185 cmdList.AddOp<ConstructorHandle>(rrect_, clipOp_, doAntiAlias_);
2186 }
2187
Playback(Canvas * canvas,const Rect * rect)2188 void ClipRoundRectOpItem::Playback(Canvas* canvas, const Rect* rect)
2189 {
2190 canvas->ClipRoundRect(rrect_, clipOp_, doAntiAlias_);
2191 }
2192
Dump(std::string & out) const2193 void ClipRoundRectOpItem::Dump(std::string& out) const
2194 {
2195 out += GetOpDesc() + "[rrect";
2196 rrect_.Dump(out);
2197 out += " clipOp:" + std::to_string(static_cast<int>(clipOp_));
2198 out += " antiAlias:" + std::string(doAntiAlias_ ? "true" : "false");
2199 out += "]";
2200 }
2201
2202 /* ClipPathOpItem */
2203 UNMARSHALLING_REGISTER(ClipPath, DrawOpItem::CLIP_PATH_OPITEM,
2204 ClipPathOpItem::Unmarshalling, sizeof(ClipPathOpItem::ConstructorHandle));
2205
ClipPathOpItem(const DrawCmdList & cmdList,ClipPathOpItem::ConstructorHandle * handle)2206 ClipPathOpItem::ClipPathOpItem(const DrawCmdList& cmdList, ClipPathOpItem::ConstructorHandle* handle)
2207 : DrawOpItem(CLIP_PATH_OPITEM), clipOp_(handle->clipOp), doAntiAlias_(handle->doAntiAlias)
2208 {
2209 path_ = CmdListHelper::GetPathFromCmdList(cmdList, handle->path);
2210 }
2211
Unmarshalling(const DrawCmdList & cmdList,void * handle)2212 std::shared_ptr<DrawOpItem> ClipPathOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2213 {
2214 return std::make_shared<ClipPathOpItem>(cmdList, static_cast<ClipPathOpItem::ConstructorHandle*>(handle));
2215 }
2216
Marshalling(DrawCmdList & cmdList)2217 void ClipPathOpItem::Marshalling(DrawCmdList& cmdList)
2218 {
2219 OpDataHandle pathHandle;
2220 if (path_) {
2221 pathHandle = CmdListHelper::AddPathToCmdList(cmdList, *path_);
2222 }
2223 cmdList.AddOp<ConstructorHandle>(pathHandle, clipOp_, doAntiAlias_);
2224 }
2225
Playback(Canvas * canvas,const Rect * rect)2226 void ClipPathOpItem::Playback(Canvas* canvas, const Rect* rect)
2227 {
2228 if (path_ == nullptr) {
2229 LOGD("ClipPathOpItem path is null!");
2230 return;
2231 }
2232 canvas->ClipPath(*path_, clipOp_, doAntiAlias_);
2233 }
2234
2235 /* ClipRegionOpItem */
2236 UNMARSHALLING_REGISTER(ClipRegion, DrawOpItem::CLIP_REGION_OPITEM,
2237 ClipRegionOpItem::Unmarshalling, sizeof(ClipRegionOpItem::ConstructorHandle));
2238
ClipRegionOpItem(const DrawCmdList & cmdList,ClipRegionOpItem::ConstructorHandle * handle)2239 ClipRegionOpItem::ClipRegionOpItem(const DrawCmdList& cmdList, ClipRegionOpItem::ConstructorHandle* handle)
2240 : DrawOpItem(CLIP_REGION_OPITEM), clipOp_(handle->clipOp)
2241 {
2242 region_ = CmdListHelper::GetRegionFromCmdList(cmdList, handle->region);
2243 }
2244
Unmarshalling(const DrawCmdList & cmdList,void * handle)2245 std::shared_ptr<DrawOpItem> ClipRegionOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2246 {
2247 return std::make_shared<ClipRegionOpItem>(cmdList, static_cast<ClipRegionOpItem::ConstructorHandle*>(handle));
2248 }
2249
Marshalling(DrawCmdList & cmdList)2250 void ClipRegionOpItem::Marshalling(DrawCmdList& cmdList)
2251 {
2252 OpDataHandle regionHandle;
2253 if (region_) {
2254 regionHandle = CmdListHelper::AddRegionToCmdList(cmdList, *region_);
2255 }
2256 cmdList.AddOp<ConstructorHandle>(regionHandle, clipOp_);
2257 }
2258
Playback(Canvas * canvas,const Rect * rect)2259 void ClipRegionOpItem::Playback(Canvas* canvas, const Rect* rect)
2260 {
2261 if (region_ == nullptr) {
2262 LOGD("ClipRegionOpItem region is null!");
2263 return;
2264 }
2265 canvas->ClipRegion(*region_, clipOp_);
2266 }
2267
Dump(std::string & out) const2268 void ClipRegionOpItem::Dump(std::string& out) const
2269 {
2270 out += GetOpDesc() + "[clipOp:";
2271 out += std::to_string(static_cast<int>(clipOp_)) + " region";
2272 if (region_) {
2273 region_->Dump(out);
2274 } else {
2275 out += "[null]";
2276 }
2277 out += "]";
2278 }
2279
2280 /* SetMatrixOpItem */
2281 UNMARSHALLING_REGISTER(SetMatrix, DrawOpItem::SET_MATRIX_OPITEM,
2282 SetMatrixOpItem::Unmarshalling, sizeof(SetMatrixOpItem::ConstructorHandle));
2283
SetMatrixOpItem(SetMatrixOpItem::ConstructorHandle * handle)2284 SetMatrixOpItem::SetMatrixOpItem(SetMatrixOpItem::ConstructorHandle* handle) : DrawOpItem(SET_MATRIX_OPITEM)
2285 {
2286 matrix_.SetAll(handle->matrixBuffer);
2287 }
2288
Unmarshalling(const DrawCmdList & cmdList,void * handle)2289 std::shared_ptr<DrawOpItem> SetMatrixOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2290 {
2291 return std::make_shared<SetMatrixOpItem>(static_cast<SetMatrixOpItem::ConstructorHandle*>(handle));
2292 }
2293
Marshalling(DrawCmdList & cmdList)2294 void SetMatrixOpItem::Marshalling(DrawCmdList& cmdList)
2295 {
2296 Matrix::Buffer matrixBuffer;
2297 matrix_.GetAll(matrixBuffer);
2298 cmdList.AddOp<ConstructorHandle>(matrixBuffer);
2299 }
2300
Playback(Canvas * canvas,const Rect * rect)2301 void SetMatrixOpItem::Playback(Canvas* canvas, const Rect* rect)
2302 {
2303 canvas->SetMatrix(matrix_);
2304 }
2305
Dump(std::string & out) const2306 void SetMatrixOpItem::Dump(std::string& out) const
2307 {
2308 out += GetOpDesc() + "[matrix";
2309 Matrix::Buffer buffer;
2310 matrix_.GetAll(buffer);
2311 DumpArray(out, buffer, [](std::string& out, float v) {
2312 out += std::to_string(v);
2313 });
2314 out += "]";
2315 }
2316
2317 /* ResetMatrixOpItem */
2318 UNMARSHALLING_REGISTER(ResetMatrix, DrawOpItem::RESET_MATRIX_OPITEM,
2319 ResetMatrixOpItem::Unmarshalling, sizeof(ResetMatrixOpItem::ConstructorHandle));
2320
ResetMatrixOpItem()2321 ResetMatrixOpItem::ResetMatrixOpItem() : DrawOpItem(RESET_MATRIX_OPITEM) {}
2322
Unmarshalling(const DrawCmdList & cmdList,void * handle)2323 std::shared_ptr<DrawOpItem> ResetMatrixOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2324 {
2325 return std::make_shared<ResetMatrixOpItem>();
2326 }
2327
Marshalling(DrawCmdList & cmdList)2328 void ResetMatrixOpItem::Marshalling(DrawCmdList& cmdList)
2329 {
2330 cmdList.AddOp<ConstructorHandle>();
2331 }
2332
Playback(Canvas * canvas,const Rect * rect)2333 void ResetMatrixOpItem::Playback(Canvas* canvas, const Rect* rect)
2334 {
2335 canvas->ResetMatrix();
2336 }
2337
2338 /* ConcatMatrixOpItem */
2339 UNMARSHALLING_REGISTER(ConcatMatrix, DrawOpItem::CONCAT_MATRIX_OPITEM,
2340 ConcatMatrixOpItem::Unmarshalling, sizeof(ConcatMatrixOpItem::ConstructorHandle));
2341
ConcatMatrixOpItem(ConcatMatrixOpItem::ConstructorHandle * handle)2342 ConcatMatrixOpItem::ConcatMatrixOpItem(ConcatMatrixOpItem::ConstructorHandle* handle) : DrawOpItem(CONCAT_MATRIX_OPITEM)
2343 {
2344 matrix_.SetAll(handle->matrixBuffer);
2345 }
2346
Unmarshalling(const DrawCmdList & cmdList,void * handle)2347 std::shared_ptr<DrawOpItem> ConcatMatrixOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2348 {
2349 return std::make_shared<ConcatMatrixOpItem>(static_cast<ConcatMatrixOpItem::ConstructorHandle*>(handle));
2350 }
2351
Marshalling(DrawCmdList & cmdList)2352 void ConcatMatrixOpItem::Marshalling(DrawCmdList& cmdList)
2353 {
2354 Matrix::Buffer matrixBuffer;
2355 matrix_.GetAll(matrixBuffer);
2356 cmdList.AddOp<ConstructorHandle>(matrixBuffer);
2357 }
2358
Playback(Canvas * canvas,const Rect * rect)2359 void ConcatMatrixOpItem::Playback(Canvas* canvas, const Rect* rect)
2360 {
2361 canvas->ConcatMatrix(matrix_);
2362 }
2363
Dump(std::string & out) const2364 void ConcatMatrixOpItem::Dump(std::string& out) const
2365 {
2366 out += GetOpDesc() + "[matrix";
2367 Matrix::Buffer buffer;
2368 matrix_.GetAll(buffer);
2369 DumpArray(out, buffer, [](std::string& out, float v) {
2370 out += std::to_string(v);
2371 });
2372 out += "]";
2373 }
2374
2375 /* TranslateOpItem */
2376 UNMARSHALLING_REGISTER(Translate, DrawOpItem::TRANSLATE_OPITEM,
2377 TranslateOpItem::Unmarshalling, sizeof(TranslateOpItem::ConstructorHandle));
2378
TranslateOpItem(TranslateOpItem::ConstructorHandle * handle)2379 TranslateOpItem::TranslateOpItem(TranslateOpItem::ConstructorHandle* handle)
2380 : DrawOpItem(TRANSLATE_OPITEM), dx_(handle->dx), dy_(handle->dy) {}
2381
Unmarshalling(const DrawCmdList & cmdList,void * handle)2382 std::shared_ptr<DrawOpItem> TranslateOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2383 {
2384 return std::make_shared<TranslateOpItem>(static_cast<TranslateOpItem::ConstructorHandle*>(handle));
2385 }
2386
Marshalling(DrawCmdList & cmdList)2387 void TranslateOpItem::Marshalling(DrawCmdList& cmdList)
2388 {
2389 cmdList.AddOp<ConstructorHandle>(dx_, dy_);
2390 }
2391
Playback(Canvas * canvas,const Rect * rect)2392 void TranslateOpItem::Playback(Canvas* canvas, const Rect* rect)
2393 {
2394 canvas->Translate(dx_, dy_);
2395 }
2396
Dump(std::string & out) const2397 void TranslateOpItem::Dump(std::string& out) const
2398 {
2399 out += GetOpDesc() + "[x:";
2400 out += std::to_string(dx_) + " y:";
2401 out += std::to_string(dy_);
2402 out += "]";
2403 }
2404
2405 /* ScaleOpItem */
2406 UNMARSHALLING_REGISTER(Scale, DrawOpItem::SCALE_OPITEM,
2407 ScaleOpItem::Unmarshalling, sizeof(ScaleOpItem::ConstructorHandle));
2408
ScaleOpItem(ScaleOpItem::ConstructorHandle * handle)2409 ScaleOpItem::ScaleOpItem(ScaleOpItem::ConstructorHandle* handle)
2410 : DrawOpItem(SCALE_OPITEM), sx_(handle->sx), sy_(handle->sy) {}
2411
Unmarshalling(const DrawCmdList & cmdList,void * handle)2412 std::shared_ptr<DrawOpItem> ScaleOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2413 {
2414 return std::make_shared<ScaleOpItem>(static_cast<ScaleOpItem::ConstructorHandle*>(handle));
2415 }
2416
Marshalling(DrawCmdList & cmdList)2417 void ScaleOpItem::Marshalling(DrawCmdList& cmdList)
2418 {
2419 cmdList.AddOp<ConstructorHandle>(sx_, sy_);
2420 }
2421
Playback(Canvas * canvas,const Rect * rect)2422 void ScaleOpItem::Playback(Canvas* canvas, const Rect* rect)
2423 {
2424 canvas->Scale(sx_, sy_);
2425 }
2426
Dump(std::string & out) const2427 void ScaleOpItem::Dump(std::string& out) const
2428 {
2429 out += GetOpDesc() + "[x:";
2430 out += std::to_string(sx_) + " y:";
2431 out += std::to_string(sy_);
2432 out += "]";
2433 }
2434
2435 /* RotateOpItem */
2436 UNMARSHALLING_REGISTER(Rotate, DrawOpItem::ROTATE_OPITEM,
2437 RotateOpItem::Unmarshalling, sizeof(RotateOpItem::ConstructorHandle));
2438
RotateOpItem(RotateOpItem::ConstructorHandle * handle)2439 RotateOpItem::RotateOpItem(RotateOpItem::ConstructorHandle* handle)
2440 : DrawOpItem(ROTATE_OPITEM), deg_(handle->deg), sx_(handle->sx), sy_(handle->sy) {}
2441
Unmarshalling(const DrawCmdList & cmdList,void * handle)2442 std::shared_ptr<DrawOpItem> RotateOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2443 {
2444 return std::make_shared<RotateOpItem>(static_cast<RotateOpItem::ConstructorHandle*>(handle));
2445 }
2446
Marshalling(DrawCmdList & cmdList)2447 void RotateOpItem::Marshalling(DrawCmdList& cmdList)
2448 {
2449 cmdList.AddOp<ConstructorHandle>(deg_, sx_, sy_);
2450 }
2451
Playback(Canvas * canvas,const Rect * rect)2452 void RotateOpItem::Playback(Canvas* canvas, const Rect* rect)
2453 {
2454 canvas->Rotate(deg_, sx_, sy_);
2455 }
2456
Dump(std::string & out) const2457 void RotateOpItem::Dump(std::string& out) const
2458 {
2459 out += GetOpDesc() + "[degree:";
2460 out += std::to_string(deg_) + " x:";
2461 out += std::to_string(sx_) + " y:";
2462 out += std::to_string(sy_);
2463 out += "]";
2464 }
2465
2466 /* ShearOpItem */
2467 UNMARSHALLING_REGISTER(Shear, DrawOpItem::SHEAR_OPITEM,
2468 ShearOpItem::Unmarshalling, sizeof(ShearOpItem::ConstructorHandle));
2469
ShearOpItem(ShearOpItem::ConstructorHandle * handle)2470 ShearOpItem::ShearOpItem(ShearOpItem::ConstructorHandle* handle)
2471 : DrawOpItem(SHEAR_OPITEM), sx_(handle->sx), sy_(handle->sy) {}
2472
Unmarshalling(const DrawCmdList & cmdList,void * handle)2473 std::shared_ptr<DrawOpItem> ShearOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2474 {
2475 return std::make_shared<ShearOpItem>(static_cast<ShearOpItem::ConstructorHandle*>(handle));
2476 }
2477
Marshalling(DrawCmdList & cmdList)2478 void ShearOpItem::Marshalling(DrawCmdList& cmdList)
2479 {
2480 cmdList.AddOp<ConstructorHandle>(sx_, sy_);
2481 }
2482
Playback(Canvas * canvas,const Rect * rect)2483 void ShearOpItem::Playback(Canvas* canvas, const Rect* rect)
2484 {
2485 canvas->Shear(sx_, sy_);
2486 }
2487
Dump(std::string & out) const2488 void ShearOpItem::Dump(std::string& out) const
2489 {
2490 out += GetOpDesc() + "[x:";
2491 out += std::to_string(sx_) + " y:";
2492 out += std::to_string(sy_);
2493 out += "]";
2494 }
2495
2496 /* FlushOpItem */
2497 UNMARSHALLING_REGISTER(Flush, DrawOpItem::FLUSH_OPITEM,
2498 FlushOpItem::Unmarshalling, sizeof(FlushOpItem::ConstructorHandle));
2499
FlushOpItem()2500 FlushOpItem::FlushOpItem() : DrawOpItem(FLUSH_OPITEM) {}
2501
Unmarshalling(const DrawCmdList & cmdList,void * handle)2502 std::shared_ptr<DrawOpItem> FlushOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2503 {
2504 return std::make_shared<FlushOpItem>();
2505 }
2506
Marshalling(DrawCmdList & cmdList)2507 void FlushOpItem::Marshalling(DrawCmdList& cmdList)
2508 {
2509 cmdList.AddOp<ConstructorHandle>();
2510 }
2511
Playback(Canvas * canvas,const Rect * rect)2512 void FlushOpItem::Playback(Canvas* canvas, const Rect* rect)
2513 {
2514 canvas->Flush();
2515 }
2516
2517 /* ClearOpItem */
2518 UNMARSHALLING_REGISTER(Clear, DrawOpItem::CLEAR_OPITEM,
2519 ClearOpItem::Unmarshalling, sizeof(ClearOpItem::ConstructorHandle));
2520
ClearOpItem(ClearOpItem::ConstructorHandle * handle)2521 ClearOpItem::ClearOpItem(ClearOpItem::ConstructorHandle* handle)
2522 : DrawOpItem(CLEAR_OPITEM), color_(handle->color) {}
2523
Unmarshalling(const DrawCmdList & cmdList,void * handle)2524 std::shared_ptr<DrawOpItem> ClearOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2525 {
2526 return std::make_shared<ClearOpItem>(static_cast<ClearOpItem::ConstructorHandle*>(handle));
2527 }
2528
Marshalling(DrawCmdList & cmdList)2529 void ClearOpItem::Marshalling(DrawCmdList& cmdList)
2530 {
2531 cmdList.AddOp<ConstructorHandle>(color_);
2532 }
2533
Playback(Canvas * canvas,const Rect * rect)2534 void ClearOpItem::Playback(Canvas* canvas, const Rect* rect)
2535 {
2536 canvas->Clear(color_);
2537 }
2538
Dump(std::string & out) const2539 void ClearOpItem::Dump(std::string& out) const
2540 {
2541 out += GetOpDesc();
2542 Color(color_).Dump(out);
2543 }
2544
2545 /* SaveOpItem */
2546 UNMARSHALLING_REGISTER(Save, DrawOpItem::SAVE_OPITEM,
2547 SaveOpItem::Unmarshalling, sizeof(SaveOpItem::ConstructorHandle));
2548
SaveOpItem()2549 SaveOpItem::SaveOpItem() : DrawOpItem(SAVE_OPITEM) {}
2550
Unmarshalling(const DrawCmdList & cmdList,void * handle)2551 std::shared_ptr<DrawOpItem> SaveOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2552 {
2553 return std::make_shared<SaveOpItem>();
2554 }
2555
Marshalling(DrawCmdList & cmdList)2556 void SaveOpItem::Marshalling(DrawCmdList& cmdList)
2557 {
2558 cmdList.AddOp<ConstructorHandle>();
2559 }
2560
Playback(Canvas * canvas,const Rect * rect)2561 void SaveOpItem::Playback(Canvas* canvas, const Rect* rect)
2562 {
2563 canvas->Save();
2564 }
2565
2566 /* SaveLayerOpItem */
2567 UNMARSHALLING_REGISTER(SaveLayer, DrawOpItem::SAVE_LAYER_OPITEM,
2568 SaveLayerOpItem::Unmarshalling, sizeof(SaveLayerOpItem::ConstructorHandle));
2569
SaveLayerOpItem(const DrawCmdList & cmdList,SaveLayerOpItem::ConstructorHandle * handle)2570 SaveLayerOpItem::SaveLayerOpItem(const DrawCmdList& cmdList, SaveLayerOpItem::ConstructorHandle* handle)
2571 : DrawOpItem(SAVE_LAYER_OPITEM), saveLayerFlags_(handle->saveLayerFlags), rect_(handle->rect),
2572 hasBrush_(handle->hasBrush)
2573 {
2574 if (hasBrush_) {
2575 BrushHandleToBrush(handle->brushHandle, cmdList, brush_);
2576 }
2577 }
2578
Unmarshalling(const DrawCmdList & cmdList,void * handle)2579 std::shared_ptr<DrawOpItem> SaveLayerOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2580 {
2581 return std::make_shared<SaveLayerOpItem>(cmdList, static_cast<SaveLayerOpItem::ConstructorHandle*>(handle));
2582 }
2583
Marshalling(DrawCmdList & cmdList)2584 void SaveLayerOpItem::Marshalling(DrawCmdList& cmdList)
2585 {
2586 BrushHandle brushHandle;
2587 if (hasBrush_) {
2588 BrushToBrushHandle(brush_, cmdList, brushHandle);
2589 }
2590 cmdList.AddOp<ConstructorHandle>(rect_, hasBrush_, brushHandle, saveLayerFlags_);
2591 }
2592
Playback(Canvas * canvas,const Rect * rect)2593 void SaveLayerOpItem::Playback(Canvas* canvas, const Rect* rect)
2594 {
2595 const Rect* rectPtr = nullptr;
2596 if (rect_.IsValid()) {
2597 rectPtr = &rect_;
2598 }
2599 Brush* brushPtr = hasBrush_ ? &brush_ : nullptr;
2600 SaveLayerOps slo(rectPtr, brushPtr, saveLayerFlags_);
2601 canvas->SaveLayer(slo);
2602 }
2603
Dump(std::string & out) const2604 void SaveLayerOpItem::Dump(std::string& out) const
2605 {
2606 out += GetOpDesc() + "[flags:";
2607 out += std::to_string(saveLayerFlags_) + " rect";
2608 rect_.Dump(out);
2609 out += " brush";
2610 if (hasBrush_) {
2611 brush_.Dump(out);
2612 } else {
2613 out += "[null]";
2614 }
2615 out += "]";
2616 }
2617
2618 /* RestoreOpItem */
2619 UNMARSHALLING_REGISTER(Restore, DrawOpItem::RESTORE_OPITEM,
2620 RestoreOpItem::Unmarshalling, sizeof(RestoreOpItem::ConstructorHandle));
2621
RestoreOpItem()2622 RestoreOpItem::RestoreOpItem() : DrawOpItem(RESTORE_OPITEM) {}
2623
Unmarshalling(const DrawCmdList & cmdList,void * handle)2624 std::shared_ptr<DrawOpItem> RestoreOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2625 {
2626 return std::make_shared<RestoreOpItem>();
2627 }
2628
Marshalling(DrawCmdList & cmdList)2629 void RestoreOpItem::Marshalling(DrawCmdList& cmdList)
2630 {
2631 cmdList.AddOp<ConstructorHandle>();
2632 }
2633
Playback(Canvas * canvas,const Rect * rect)2634 void RestoreOpItem::Playback(Canvas* canvas, const Rect* rect)
2635 {
2636 canvas->Restore();
2637 }
2638
2639 /* DiscardOpItem */
2640 UNMARSHALLING_REGISTER(Discard, DrawOpItem::DISCARD_OPITEM,
2641 DiscardOpItem::Unmarshalling, sizeof(DiscardOpItem::ConstructorHandle));
2642
DiscardOpItem()2643 DiscardOpItem::DiscardOpItem() : DrawOpItem(DISCARD_OPITEM) {}
2644
Unmarshalling(const DrawCmdList & cmdList,void * handle)2645 std::shared_ptr<DrawOpItem> DiscardOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2646 {
2647 return std::make_shared<DiscardOpItem>();
2648 }
2649
Marshalling(DrawCmdList & cmdList)2650 void DiscardOpItem::Marshalling(DrawCmdList& cmdList)
2651 {
2652 cmdList.AddOp<ConstructorHandle>();
2653 }
2654
Playback(Canvas * canvas,const Rect * rect)2655 void DiscardOpItem::Playback(Canvas* canvas, const Rect* rect)
2656 {
2657 canvas->Discard();
2658 }
2659
2660 /* ClipAdaptiveRoundRectOpItem */
2661 UNMARSHALLING_REGISTER(ClipAdaptiveRoundRect, DrawOpItem::CLIP_ADAPTIVE_ROUND_RECT_OPITEM,
2662 ClipAdaptiveRoundRectOpItem::Unmarshalling, sizeof(ClipAdaptiveRoundRectOpItem::ConstructorHandle));
2663
ClipAdaptiveRoundRectOpItem(const DrawCmdList & cmdList,ClipAdaptiveRoundRectOpItem::ConstructorHandle * handle)2664 ClipAdaptiveRoundRectOpItem::ClipAdaptiveRoundRectOpItem(
2665 const DrawCmdList& cmdList, ClipAdaptiveRoundRectOpItem::ConstructorHandle* handle)
2666 : DrawOpItem(CLIP_ADAPTIVE_ROUND_RECT_OPITEM)
2667 {
2668 radiusData_ = CmdListHelper::GetVectorFromCmdList<Point>(cmdList, handle->radiusData);
2669 }
2670
Unmarshalling(const DrawCmdList & cmdList,void * handle)2671 std::shared_ptr<DrawOpItem> ClipAdaptiveRoundRectOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2672 {
2673 return std::make_shared<ClipAdaptiveRoundRectOpItem>(
2674 cmdList, static_cast<ClipAdaptiveRoundRectOpItem::ConstructorHandle*>(handle));
2675 }
2676
Marshalling(DrawCmdList & cmdList)2677 void ClipAdaptiveRoundRectOpItem::Marshalling(DrawCmdList& cmdList)
2678 {
2679 auto radiusData = CmdListHelper::AddVectorToCmdList<Point>(cmdList, radiusData_);
2680 cmdList.AddOp<ConstructorHandle>(radiusData);
2681 }
2682
Playback(Canvas * canvas,const Rect * rect)2683 void ClipAdaptiveRoundRectOpItem::Playback(Canvas* canvas, const Rect* rect)
2684 {
2685 canvas->ClipRoundRect(*rect, radiusData_, true);
2686 }
2687
Dump(std::string & out) const2688 void ClipAdaptiveRoundRectOpItem::Dump(std::string& out) const
2689 {
2690 out += GetOpDesc() + "[radius";
2691 DumpArray(out, radiusData_, [](std::string& out, const Point& p) {
2692 out += "[";
2693 out += std::to_string(p.GetX()) + " ";
2694 out += std::to_string(p.GetY());
2695 out += "]";
2696 });
2697 out += "]";
2698 }
2699
2700 /* HybridRenderPixelMapSizeOpItem */
2701 UNMARSHALLING_REGISTER(ResetHybridRenderSize, DrawOpItem::HYBRID_RENDER_PIXELMAP_SIZE_OPITEM,
2702 HybridRenderPixelMapSizeOpItem::Unmarshalling, sizeof(HybridRenderPixelMapSizeOpItem::ConstructorHandle));
2703
HybridRenderPixelMapSizeOpItem(HybridRenderPixelMapSizeOpItem::ConstructorHandle * handle)2704 HybridRenderPixelMapSizeOpItem::HybridRenderPixelMapSizeOpItem(
2705 HybridRenderPixelMapSizeOpItem::ConstructorHandle* handle)
2706 : DrawOpItem(HYBRID_RENDER_PIXELMAP_SIZE_OPITEM), width_(handle->width), height_(handle->height) {}
2707
Unmarshalling(const DrawCmdList & cmdList,void * handle)2708 std::shared_ptr<DrawOpItem> HybridRenderPixelMapSizeOpItem::Unmarshalling(const DrawCmdList& cmdList, void* handle)
2709 {
2710 return std::make_shared<HybridRenderPixelMapSizeOpItem>(
2711 static_cast<HybridRenderPixelMapSizeOpItem::ConstructorHandle*>(handle));
2712 }
2713
Marshalling(DrawCmdList & cmdList)2714 void HybridRenderPixelMapSizeOpItem::Marshalling(DrawCmdList& cmdList)
2715 {
2716 cmdList.AddOp<ConstructorHandle>(width_, height_);
2717 }
2718
Playback(Canvas * canvas,const Rect * rect)2719 void HybridRenderPixelMapSizeOpItem::Playback(Canvas* canvas, const Rect* rect)
2720 {
2721 return;
2722 }
2723
Dump(std::string & out) const2724 void HybridRenderPixelMapSizeOpItem::Dump(std::string& out) const
2725 {
2726 out += GetOpDesc();
2727 }
2728
GetWidth() const2729 float HybridRenderPixelMapSizeOpItem::GetWidth() const
2730 {
2731 return width_;
2732 }
2733
GetHeight() const2734 float HybridRenderPixelMapSizeOpItem::GetHeight() const
2735 {
2736 return height_;
2737 }
2738 } // namespace Drawing
2739 } // namespace Rosen
2740 } // namespace OHOS
2741