• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef DRAW_CMD_H
17 #define DRAW_CMD_H
18 
19 #include <chrono>
20 #include <cstdint>
21 #include <ctime>
22 #include <functional>
23 #include <shared_mutex>
24 #include <stack>
25 #include <unordered_map>
26 #include <utility>
27 
28 #include "draw/canvas.h"
29 #include "draw/paint.h"
30 #include "recording/cmd_list.h"
31 
32 #define UNMARSHALLING_REGISTER(name, type, func, size) \
33     static bool isRegistered##name = OHOS::Rosen::Drawing::UnmarshallingHelper::Instance().Register(type, func, size)
34 
35 namespace OHOS {
36 namespace Rosen {
37 namespace Drawing {
38 class DrawCmdList;
39 class DRAWING_API DrawOpItem : public OpItem {
40 public:
DrawOpItem(uint32_t type)41     explicit DrawOpItem(uint32_t type) : OpItem(type) {}
42     ~DrawOpItem() override = default;
43 
44     enum Type : uint32_t {
45         OPITEM_HEAD,
46         POINT_OPITEM,
47         POINTS_OPITEM,
48         LINE_OPITEM,
49         RECT_OPITEM,
50         ROUND_RECT_OPITEM,
51         NESTED_ROUND_RECT_OPITEM,
52         ARC_OPITEM,
53         PIE_OPITEM,
54         OVAL_OPITEM,
55         CIRCLE_OPITEM,
56         COLOR_OPITEM,
57         IMAGE_NINE_OPITEM,
58         IMAGE_LATTICE_OPITEM,
59         PATH_OPITEM,
60         BACKGROUND_OPITEM,
61         SHADOW_OPITEM,
62         SHADOW_STYLE_OPITEM,
63         ATLAS_OPITEM,
64         BITMAP_OPITEM,
65         IMAGE_OPITEM,
66         IMAGE_RECT_OPITEM,
67         PICTURE_OPITEM,
68         TEXT_BLOB_OPITEM,
69         SYMBOL_OPITEM,
70         CLIP_RECT_OPITEM,
71         CLIP_IRECT_OPITEM,
72         CLIP_ROUND_RECT_OPITEM,
73         CLIP_PATH_OPITEM,
74         CLIP_REGION_OPITEM,
75         SET_MATRIX_OPITEM,
76         RESET_MATRIX_OPITEM,
77         CONCAT_MATRIX_OPITEM,
78         TRANSLATE_OPITEM,
79         SCALE_OPITEM,
80         ROTATE_OPITEM,
81         SHEAR_OPITEM,
82         FLUSH_OPITEM,
83         CLEAR_OPITEM,
84         SAVE_OPITEM,
85         SAVE_LAYER_OPITEM,
86         RESTORE_OPITEM,
87         DISCARD_OPITEM,
88         CLIP_ADAPTIVE_ROUND_RECT_OPITEM,
89         IMAGE_WITH_PARM_OPITEM,
90         PIXELMAP_WITH_PARM_OPITEM,
91         PIXELMAP_RECT_OPITEM,
92         PIXELMAP_NINE_OPITEM,
93         PIXELMAP_LATTICE_OPITEM,
94         REGION_OPITEM,
95         PATCH_OPITEM,
96         EDGEAAQUAD_OPITEM,
97         VERTICES_OPITEM,
98         IMAGE_SNAPSHOT_OPITEM,
99         SURFACEBUFFER_OPITEM,
100         DRAW_FUNC_OPITEM,
101         RECORD_CMD_OPITEM,
102     };
103 
104     static void BrushHandleToBrush(const BrushHandle& brushHandle, const DrawCmdList& cmdList, Brush& brush);
105     static void BrushToBrushHandle(const Brush& brush, DrawCmdList& cmdList, BrushHandle& brushHandle);
106     static void GeneratePaintFromHandle(const PaintHandle& paintHandle, const DrawCmdList& cmdList, Paint& paint);
107     static void GenerateHandleFromPaint(CmdList& cmdList, const Paint& paint, PaintHandle& paintHandle);
108 
109     virtual void Marshalling(DrawCmdList& cmdList) = 0;
110     virtual void Playback(Canvas* canvas, const Rect* rect) = 0;
111 
SetNodeId(NodeId id)112     virtual void SetNodeId(NodeId id) {}
113     virtual void Dump(std::string& out) const;
114 
115     std::string GetOpDesc() const;
116 
117     static void SetBaseCallback(
118         std::function<void (std::shared_ptr<Drawing::Image> image)> holdDrawingImagefunc);
119     static std::function<void (std::shared_ptr<Drawing::Image> image)> holdDrawingImagefunc_;
120 
121     static void SetTypefaceQueryCallBack(
122         std::function<std::shared_ptr<Drawing::Typeface>(uint64_t)> customTypefaceQueryfunc);
123     static std::function<std::shared_ptr<Drawing::Typeface>(uint64_t)> customTypefaceQueryfunc_;
124 
Purge()125     virtual void Purge() {}
126 
127     size_t GetOpSize();
128 };
129 
130 class DRAWING_API UnmarshallingHelper {
131     using UnmarshallingFunc = std::shared_ptr<DrawOpItem>(*)(const DrawCmdList& cmdList, void* handle);
132 public:
133     static UnmarshallingHelper& Instance();
134 
135     bool Register(uint32_t type, UnmarshallingFunc func, size_t unmarshallingSize);
136     std::pair<UnmarshallingFunc, size_t> GetFuncAndSize(uint32_t type);
137 
138 private:
139     UnmarshallingHelper() = default;
140     ~UnmarshallingHelper() = default;
141     UnmarshallingHelper(const UnmarshallingHelper& other) = delete;
142     UnmarshallingHelper(const UnmarshallingHelper&& other) = delete;
143     UnmarshallingHelper& operator=(const UnmarshallingHelper& other) = delete;
144     UnmarshallingHelper& operator=(const UnmarshallingHelper&& other) = delete;
145 
146     std::shared_mutex mtx_;
147     std::unordered_map<uint32_t, UnmarshallingFunc> opUnmarshallingFuncLUT_;
148     std::unordered_map<uint32_t, size_t> opUnmarshallingSize_;
149 };
150 
151 class UnmarshallingPlayer {
152 public:
153     UnmarshallingPlayer(const DrawCmdList& cmdList);
154     ~UnmarshallingPlayer() = default;
155 
156     std::shared_ptr<DrawOpItem> Unmarshalling(uint32_t type, void* handle, size_t avaliableSize);
157 private:
158     const DrawCmdList& cmdList_;
159 };
160 
161 class GenerateCachedOpItemPlayer {
162 public:
163     GenerateCachedOpItemPlayer(DrawCmdList &cmdList, Canvas* canvas = nullptr, const Rect* rect = nullptr);
164     ~GenerateCachedOpItemPlayer() = default;
165 
166     bool GenerateCachedOpItem(uint32_t type, void* handle, size_t avaliableSize);
167 
168     Canvas* canvas_ = nullptr;
169     const Rect* rect_;
170     DrawCmdList& cmdList_;
171 };
172 
173 class DRAWING_API DrawWithPaintOpItem : public DrawOpItem {
174 public:
DrawWithPaintOpItem(const Paint & paint,uint32_t type)175     explicit DrawWithPaintOpItem(const Paint& paint, uint32_t type) : DrawOpItem(type), paint_(paint) {}
176     DrawWithPaintOpItem(const DrawCmdList& cmdList, const PaintHandle& paintHandle, uint32_t type);
177     ~DrawWithPaintOpItem() override = default;
Marshalling(DrawCmdList & cmdList)178     void Marshalling(DrawCmdList& cmdList) override {}
Playback(Canvas * canvas,const Rect * rect)179     void Playback(Canvas* canvas, const Rect* rect) override {}
180     virtual void Dump(std::string& out) const override;
DumpItems(std::string & out)181     virtual void DumpItems(std::string& out) const {}
182 protected:
183     Paint paint_;
184 };
185 
186 class DrawShadowStyleOpItem : public DrawOpItem {
187 public:
188     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle189         ConstructorHandle(const OpDataHandle& path, const Point3& planeParams, const Point3& devLightPos,
190             scalar lightRadius, Color ambientColor, Color spotColor, ShadowFlags flag, bool isLimitElevation)
191             : OpItem(DrawOpItem::SHADOW_STYLE_OPITEM),
192               path(path),
193               planeParams(planeParams),
194               devLightPos(devLightPos),
195               lightRadius(lightRadius),
196               ambientColor(ambientColor),
197               spotColor(spotColor),
198               flag(flag),
199               isLimitElevation(isLimitElevation)
200         {}
201         ~ConstructorHandle() override = default;
202         OpDataHandle path;
203         Point3 planeParams;
204         Point3 devLightPos;
205         scalar lightRadius;
206         Color ambientColor;
207         Color spotColor;
208         ShadowFlags flag;
209         bool isLimitElevation;
210     };
211     DrawShadowStyleOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawShadowStyleOpItem(const Path & path,const Point3 & planeParams,const Point3 & devLightPos,scalar lightRadius,Color ambientColor,Color spotColor,ShadowFlags flag,bool isLimitElevation)212     DrawShadowStyleOpItem(const Path& path, const Point3& planeParams, const Point3& devLightPos, scalar lightRadius,
213         Color ambientColor, Color spotColor, ShadowFlags flag, bool isLimitElevation)
214         : DrawOpItem(DrawOpItem::SHADOW_STYLE_OPITEM),
215           planeParams_(planeParams),
216           devLightPos_(devLightPos),
217           lightRadius_(lightRadius),
218           ambientColor_(ambientColor),
219           spotColor_(spotColor),
220           flag_(flag),
221           isLimitElevation_(isLimitElevation),
222           path_(std::make_shared<Path>(path))
223     {}
224     ~DrawShadowStyleOpItem() override = default;
225 
226     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
227     void Marshalling(DrawCmdList& cmdList) override;
228     void Playback(Canvas* canvas, const Rect* rect) override;
229     void Dump(std::string& out) const override;
230 private:
231     Point3 planeParams_;
232     Point3 devLightPos_;
233     scalar lightRadius_;
234     Color ambientColor_;
235     Color spotColor_;
236     ShadowFlags flag_;
237     bool isLimitElevation_;
238     std::shared_ptr<Path> path_;
239 };
240 
241 class DrawPointOpItem : public DrawWithPaintOpItem {
242 public:
243     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle244         ConstructorHandle(const Point& point, const PaintHandle& paintHandle)
245             : OpItem(DrawOpItem::POINT_OPITEM), point(point), paintHandle(paintHandle) {}
246         ~ConstructorHandle() override = default;
247         Point point;
248         PaintHandle paintHandle;
249     };
250     DrawPointOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawPointOpItem(const Point & point,const Paint & paint)251     explicit DrawPointOpItem(const Point& point, const Paint& paint)
252         : DrawWithPaintOpItem(paint, DrawOpItem::POINT_OPITEM), point_(point) {}
253     ~DrawPointOpItem() override = default;
254 
255     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
256     void Marshalling(DrawCmdList& cmdList) override;
257     void Playback(Canvas* canvas, const Rect* rect) override;
258     virtual void DumpItems(std::string& out) const override;
259 private:
260     Point point_;
261 };
262 
263 class DrawPointsOpItem : public DrawWithPaintOpItem {
264 public:
265     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle266         ConstructorHandle(PointMode mode, const std::pair<size_t, size_t>& pts, const PaintHandle& paintHandle)
267             : OpItem(DrawOpItem::POINTS_OPITEM), mode(mode), pts(pts), paintHandle(paintHandle) {}
268         ~ConstructorHandle() override = default;
269         PointMode mode;
270         std::pair<size_t, size_t> pts;
271         PaintHandle paintHandle;
272     };
273     DrawPointsOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawPointsOpItem(PointMode mode,std::vector<Point> & pts,const Paint & paint)274     DrawPointsOpItem(PointMode mode, std::vector<Point>& pts, const Paint& paint)
275         : DrawWithPaintOpItem(paint, DrawOpItem::POINTS_OPITEM), mode_(mode), pts_(pts) {}
276     ~DrawPointsOpItem() override = default;
277 
278     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
279     void Marshalling(DrawCmdList& cmdList) override;
280     void Playback(Canvas* canvas, const Rect* rect) override;
281 private:
282     PointMode mode_;
283     std::vector<Point> pts_;
284 };
285 
286 class DrawLineOpItem : public DrawWithPaintOpItem {
287 public:
288     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle289         ConstructorHandle(const Point& startPt, const Point& endPt, const PaintHandle& paintHandle)
290             : OpItem(DrawOpItem::LINE_OPITEM), startPt(startPt), endPt(endPt), paintHandle(paintHandle) {}
291         ~ConstructorHandle() override = default;
292         Point startPt;
293         Point endPt;
294         PaintHandle paintHandle;
295     };
296     DrawLineOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawLineOpItem(const Point & startPt,const Point & endPt,const Paint & paint)297     DrawLineOpItem(const Point& startPt, const Point& endPt, const Paint& paint)
298         : DrawWithPaintOpItem(paint, DrawOpItem::LINE_OPITEM), startPt_(startPt), endPt_(endPt) {}
299     ~DrawLineOpItem() override = default;
300 
301     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
302     void Marshalling(DrawCmdList& cmdList) override;
303     void Playback(Canvas* canvas, const Rect* rect) override;
304     virtual void DumpItems(std::string& out) const override;
305 private:
306     Point startPt_;
307     Point endPt_;
308 };
309 
310 class DrawRectOpItem : public DrawWithPaintOpItem {
311 public:
312     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle313         ConstructorHandle(const Rect& rect, const PaintHandle& paintHandle)
314             : OpItem(DrawOpItem::RECT_OPITEM), rect(rect), paintHandle(paintHandle) {}
315         ~ConstructorHandle() override = default;
316         Rect rect;
317         PaintHandle paintHandle;
318     };
319     DrawRectOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawRectOpItem(const Rect & rect,const Paint & paint)320     explicit DrawRectOpItem(const Rect& rect, const Paint& paint)
321         : DrawWithPaintOpItem(paint, DrawOpItem::RECT_OPITEM), rect_(rect) {}
322     ~DrawRectOpItem() override = default;
323 
324     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
325     void Marshalling(DrawCmdList& cmdList) override;
326     void Playback(Canvas* canvas, const Rect* rect) override;
327     virtual void DumpItems(std::string& out) const override;
328 private:
329     Rect rect_;
330 };
331 
332 class DrawRoundRectOpItem : public DrawWithPaintOpItem {
333 public:
334     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle335         ConstructorHandle(const RoundRect& rrect, const PaintHandle& paintHandle)
336             : OpItem(DrawOpItem::ROUND_RECT_OPITEM), rrect(rrect), paintHandle(paintHandle) {}
337         ~ConstructorHandle() override = default;
338         RoundRect rrect;
339         PaintHandle paintHandle;
340     };
341     DrawRoundRectOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawRoundRectOpItem(const RoundRect & rrect,const Paint & paint)342     explicit DrawRoundRectOpItem(const RoundRect& rrect, const Paint& paint)
343         : DrawWithPaintOpItem(paint, DrawOpItem::ROUND_RECT_OPITEM), rrect_(rrect) {}
344     ~DrawRoundRectOpItem() override = default;
345 
346     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
347     void Marshalling(DrawCmdList& cmdList) override;
348     void Playback(Canvas* canvas, const Rect* rect) override;
349     virtual void DumpItems(std::string& out) const override;
350 private:
351     RoundRect rrect_;
352 };
353 
354 class DrawNestedRoundRectOpItem : public DrawWithPaintOpItem {
355 public:
356     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle357         ConstructorHandle(const RoundRect& outerRRect, const RoundRect& innerRRect, const PaintHandle& paintHandle)
358             : OpItem(DrawOpItem::NESTED_ROUND_RECT_OPITEM), outerRRect(outerRRect), innerRRect(innerRRect),
359               paintHandle(paintHandle) {}
360         ~ConstructorHandle() override = default;
361         RoundRect outerRRect;
362         RoundRect innerRRect;
363         PaintHandle paintHandle;
364     };
365     DrawNestedRoundRectOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawNestedRoundRectOpItem(const RoundRect & outer,const RoundRect & inner,const Paint & paint)366     DrawNestedRoundRectOpItem(const RoundRect& outer, const RoundRect& inner, const Paint& paint)
367         : DrawWithPaintOpItem(paint, DrawOpItem::NESTED_ROUND_RECT_OPITEM), outerRRect_(outer), innerRRect_(inner) {}
368     ~DrawNestedRoundRectOpItem() override = default;
369 
370     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
371     void Marshalling(DrawCmdList& cmdList) override;
372     void Playback(Canvas* canvas, const Rect* rect) override;
373     virtual void DumpItems(std::string& out) const override;
374 private:
375     RoundRect outerRRect_;
376     RoundRect innerRRect_;
377 };
378 
379 class DrawArcOpItem : public DrawWithPaintOpItem {
380 public:
381     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle382         ConstructorHandle(const Rect& rect, scalar startAngle, scalar sweepAngle, const PaintHandle& paintHandle)
383             : OpItem(DrawOpItem::ARC_OPITEM), rect(rect), startAngle(startAngle), sweepAngle(sweepAngle),
384               paintHandle(paintHandle) {}
385         ~ConstructorHandle() override = default;
386         Rect rect;
387         scalar startAngle;
388         scalar sweepAngle;
389         PaintHandle paintHandle;
390     };
391     DrawArcOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawArcOpItem(const Rect & oval,scalar startAngle,scalar sweepAngle,const Paint & paint)392     DrawArcOpItem(const Rect& oval, scalar startAngle, scalar sweepAngle, const Paint& paint)
393         : DrawWithPaintOpItem(paint, DrawOpItem::ARC_OPITEM), rect_(oval), startAngle_(startAngle),
394           sweepAngle_(sweepAngle) {}
395     ~DrawArcOpItem() override = default;
396 
397     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
398     void Marshalling(DrawCmdList& cmdList) override;
399     void Playback(Canvas* canvas, const Rect* rect) override;
400     virtual void DumpItems(std::string& out) const override;
401 private:
402     Rect rect_;
403     scalar startAngle_;
404     scalar sweepAngle_;
405 };
406 
407 class DrawPieOpItem : public DrawWithPaintOpItem {
408 public:
409     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle410         ConstructorHandle(const Rect& rect, scalar startAngle, scalar sweepAngle, const PaintHandle& paintHandle)
411             : OpItem(DrawOpItem::PIE_OPITEM), rect(rect), startAngle(startAngle), sweepAngle(sweepAngle),
412               paintHandle(paintHandle) {}
413         ~ConstructorHandle() override = default;
414         Rect rect;
415         scalar startAngle;
416         scalar sweepAngle;
417         PaintHandle paintHandle;
418     };
419     DrawPieOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawPieOpItem(const Rect & oval,scalar startAngle,scalar sweepAngle,const Paint & paint)420     DrawPieOpItem(const Rect& oval, scalar startAngle, scalar sweepAngle, const Paint& paint)
421         : DrawWithPaintOpItem(paint, DrawOpItem::PIE_OPITEM), rect_(oval), startAngle_(startAngle),
422           sweepAngle_(sweepAngle) {}
423     ~DrawPieOpItem() override = default;
424 
425     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
426     void Marshalling(DrawCmdList& cmdList) override;
427     void Playback(Canvas* canvas, const Rect* rect) override;
428     virtual void DumpItems(std::string& out) const override;
429 private:
430     Rect rect_;
431     scalar startAngle_;
432     scalar sweepAngle_;
433 };
434 
435 class DrawOvalOpItem : public DrawWithPaintOpItem {
436 public:
437     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle438         ConstructorHandle(const Rect& rect, const PaintHandle& paintHandle)
439             : OpItem(DrawOpItem::OVAL_OPITEM), rect(rect), paintHandle(paintHandle) {}
440         ~ConstructorHandle() override = default;
441         Rect rect;
442         PaintHandle paintHandle;
443     };
444     DrawOvalOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawOvalOpItem(const Rect & oval,const Paint & paint)445     explicit DrawOvalOpItem(const Rect& oval, const Paint& paint)
446         : DrawWithPaintOpItem(paint, DrawOpItem::OVAL_OPITEM), rect_(oval) {}
447     ~DrawOvalOpItem() override = default;
448 
449     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
450     void Marshalling(DrawCmdList& cmdList) override;
451     void Playback(Canvas* canvas, const Rect* rect) override;
452     virtual void DumpItems(std::string& out) const override;
453 private:
454     Rect rect_;
455 };
456 
457 class DrawCircleOpItem : public DrawWithPaintOpItem {
458 public:
459     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle460         ConstructorHandle(const Point& centerPt, scalar radius, const PaintHandle& paintHandle)
461             : OpItem(DrawOpItem::CIRCLE_OPITEM), centerPt(centerPt), radius(radius), paintHandle(paintHandle) {}
462         ~ConstructorHandle() override = default;
463         Point centerPt;
464         scalar radius;
465         PaintHandle paintHandle;
466     };
467     DrawCircleOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawCircleOpItem(const Point & centerPt,scalar radius,const Paint & paint)468     DrawCircleOpItem(const Point& centerPt, scalar radius, const Paint& paint)
469         : DrawWithPaintOpItem(paint, DrawOpItem::CIRCLE_OPITEM), centerPt_(centerPt), radius_(radius) {}
470     ~DrawCircleOpItem() override = default;
471 
472     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
473     void Marshalling(DrawCmdList& cmdList) override;
474     void Playback(Canvas* canvas, const Rect* rect) override;
475     virtual void DumpItems(std::string& out) const override;
476 private:
477     Point centerPt_;
478     scalar radius_;
479 };
480 
481 class DrawPathOpItem : public DrawWithPaintOpItem {
482 public:
483     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle484         ConstructorHandle(const OpDataHandle& path, const PaintHandle& paintHandle)
485             : OpItem(DrawOpItem::PATH_OPITEM), path(path), paintHandle(paintHandle) {}
486         ~ConstructorHandle() override = default;
487         OpDataHandle path;
488         PaintHandle paintHandle;
489     };
490     DrawPathOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawPathOpItem(const Path & path,const Paint & paint)491     explicit DrawPathOpItem(const Path& path, const Paint& paint)
492         : DrawWithPaintOpItem(paint, DrawOpItem::PATH_OPITEM), path_(std::make_shared<Path>(path)) {}
493     ~DrawPathOpItem() override = default;
494 
495     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
496     void Marshalling(DrawCmdList& cmdList) override;
497     void Playback(Canvas* canvas, const Rect* rect) override;
498     void DumpItems(std::string& out) const override;
499 private:
500     std::shared_ptr<Path> path_;
501 };
502 
503 class DrawBackgroundOpItem : public DrawOpItem {
504 public:
505     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle506         ConstructorHandle(const BrushHandle& brushHandle)
507             : OpItem(DrawOpItem::BACKGROUND_OPITEM), brushHandle(brushHandle) {}
508         ~ConstructorHandle() override = default;
509         BrushHandle brushHandle;
510     };
511     DrawBackgroundOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawBackgroundOpItem(const Brush & brush)512     explicit DrawBackgroundOpItem(const Brush& brush) : DrawOpItem(DrawOpItem::BACKGROUND_OPITEM), brush_(brush) {}
513     ~DrawBackgroundOpItem() override = default;
514 
515     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
516     void Marshalling(DrawCmdList& cmdList) override;
517     void Playback(Canvas* canvas, const Rect* rect) override;
518 private:
519     Brush brush_;
520 };
521 
522 class DrawShadowOpItem : public DrawOpItem {
523 public:
524     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle525         ConstructorHandle(const OpDataHandle& path, const Point3& planeParams, const Point3& devLightPos,
526             scalar lightRadius, Color ambientColor, Color spotColor, ShadowFlags flag)
527             : OpItem(DrawOpItem::SHADOW_OPITEM), path(path), planeParams(planeParams), devLightPos(devLightPos),
528             lightRadius(lightRadius), ambientColor(ambientColor), spotColor(spotColor), flag(flag) {}
529         ~ConstructorHandle() override = default;
530         OpDataHandle path;
531         Point3 planeParams;
532         Point3 devLightPos;
533         scalar lightRadius;
534         Color ambientColor;
535         Color spotColor;
536         ShadowFlags flag;
537     };
538     DrawShadowOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawShadowOpItem(const Path & path,const Point3 & planeParams,const Point3 & devLightPos,scalar lightRadius,Color ambientColor,Color spotColor,ShadowFlags flag)539     DrawShadowOpItem(const Path& path, const Point3& planeParams, const Point3& devLightPos, scalar lightRadius,
540         Color ambientColor, Color spotColor, ShadowFlags flag)
541         : DrawOpItem(DrawOpItem::SHADOW_OPITEM), planeParams_(planeParams), devLightPos_(devLightPos),
542           lightRadius_(lightRadius), ambientColor_(ambientColor), spotColor_(spotColor), flag_(flag),
543           path_(std::make_shared<Path>(path)) {}
544     ~DrawShadowOpItem() override = default;
545 
546     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
547     void Marshalling(DrawCmdList& cmdList) override;
548     void Playback(Canvas* canvas, const Rect* rect) override;
549     void Dump(std::string& out) const override;
550 private:
551     Point3 planeParams_;
552     Point3 devLightPos_;
553     scalar lightRadius_;
554     Color ambientColor_;
555     Color spotColor_;
556     ShadowFlags flag_;
557     std::shared_ptr<Path> path_;
558 };
559 
560 class DrawRegionOpItem : public DrawWithPaintOpItem {
561 public:
562     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle563         ConstructorHandle(const OpDataHandle& region, const PaintHandle& paintHandle)
564             : OpItem(DrawOpItem::REGION_OPITEM), region(region), paintHandle(paintHandle) {}
565         ~ConstructorHandle() override = default;
566         OpDataHandle region;
567         PaintHandle paintHandle;
568     };
569     DrawRegionOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawRegionOpItem(const Region & region,const Paint & paint)570     explicit DrawRegionOpItem(const Region& region, const Paint& paint)
571         : DrawWithPaintOpItem(paint, DrawOpItem::REGION_OPITEM), region_(std::make_shared<Region>(region)) {}
572     ~DrawRegionOpItem() override = default;
573 
574     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
575     void Marshalling(DrawCmdList& cmdList) override;
576     void Playback(Canvas* canvas, const Rect* rect) override;
577     void DumpItems(std::string& out) const override;
578 private:
579     std::shared_ptr<Region> region_;
580 };
581 
582 class DrawVerticesOpItem : public DrawWithPaintOpItem {
583 public:
584     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle585         ConstructorHandle(const OpDataHandle& vertices, BlendMode mode, const PaintHandle& paintHandle)
586             : OpItem(DrawOpItem::VERTICES_OPITEM), vertices(vertices), mode(mode), paintHandle(paintHandle) {}
587         ~ConstructorHandle() override = default;
588         OpDataHandle vertices;
589         BlendMode mode;
590         PaintHandle paintHandle;
591     };
592     DrawVerticesOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawVerticesOpItem(const Vertices & vertices,BlendMode mode,const Paint & paint)593     DrawVerticesOpItem(const Vertices& vertices, BlendMode mode, const Paint& paint)
594         : DrawWithPaintOpItem(paint, DrawOpItem::VERTICES_OPITEM), mode_(mode),
595           vertices_(std::make_shared<Vertices>(vertices)) {}
596     ~DrawVerticesOpItem() override = default;
597 
598     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
599     void Marshalling(DrawCmdList& cmdList) override;
600     void Playback(Canvas* canvas, const Rect* rect) override;
601     void DumpItems(std::string& out) const override;
602 private:
603     BlendMode mode_;
604     std::shared_ptr<Vertices> vertices_;
605 };
606 
607 class DrawColorOpItem : public DrawOpItem {
608 public:
609     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle610         ConstructorHandle(ColorQuad color, BlendMode mode)
611             : OpItem(DrawOpItem::COLOR_OPITEM), color(color), mode(mode) {}
612         ~ConstructorHandle() override = default;
613         ColorQuad color;
614         BlendMode mode;
615     };
616     explicit DrawColorOpItem(ConstructorHandle* handle);
DrawColorOpItem(ColorQuad color,BlendMode mode)617     DrawColorOpItem(ColorQuad color, BlendMode mode)
618         : DrawOpItem(DrawOpItem::COLOR_OPITEM), color_(color), mode_(mode) {}
619     ~DrawColorOpItem() override = default;
620 
621     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
622     void Marshalling(DrawCmdList& cmdList) override;
623     void Playback(Canvas* canvas, const Rect* rect) override;
624     void Dump(std::string& out) const override;
625 private:
626     ColorQuad color_;
627     BlendMode mode_;
628 };
629 
630 class DrawImageNineOpItem : public DrawOpItem {
631 public:
632     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle633         ConstructorHandle(const OpDataHandle& image, const RectI& center, const Rect& dst, FilterMode filterMode,
634             const BrushHandle& brushHandle, bool hasBrush) : OpItem(DrawOpItem::IMAGE_NINE_OPITEM), image(image),
635             center(center), dst(dst), filter(filterMode), brushHandle(brushHandle), hasBrush(hasBrush) {}
636         ~ConstructorHandle() override = default;
637         OpDataHandle image;
638         RectI center;
639         Rect dst;
640         FilterMode filter;
641         BrushHandle brushHandle;
642         bool hasBrush;
643     };
644     DrawImageNineOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawImageNineOpItem(const Image * image,const RectI & center,const Rect & dst,FilterMode filterMode,const Brush * brush)645     DrawImageNineOpItem(const Image* image, const RectI& center, const Rect& dst, FilterMode filterMode,
646         const Brush* brush) : DrawOpItem(DrawOpItem::IMAGE_NINE_OPITEM), center_(center), dst_(dst), filter_(filterMode)
647     {
648         if (brush) {
649             hasBrush_ = true;
650             brush_ = *brush;
651         } else {
652             hasBrush_ = false;
653         }
654         image_ = std::make_shared<Image>(*image);
655     }
656     ~DrawImageNineOpItem() override = default;
657 
658     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
659     void Marshalling(DrawCmdList& cmdList) override;
660     void Playback(Canvas* canvas, const Rect* rect) override;
661     void Dump(std::string& out) const override;
662 private:
663     RectI center_;
664     Rect dst_;
665     FilterMode filter_;
666     bool hasBrush_;
667     Brush brush_;
668     std::shared_ptr<Image> image_;
669 };
670 
671 class DrawImageLatticeOpItem : public DrawWithPaintOpItem {
672 public:
673     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle674         ConstructorHandle(const OpDataHandle& image, const LatticeHandle& latticeHandle, const Rect& dst,
675             FilterMode filterMode, const PaintHandle& paintHandle) : OpItem(DrawOpItem::IMAGE_LATTICE_OPITEM),
676             image(image), latticeHandle(latticeHandle), dst(dst), filter(filterMode), paintHandle(paintHandle) {}
677         ~ConstructorHandle() override = default;
678         OpDataHandle image;
679         LatticeHandle latticeHandle;
680         Rect dst;
681         FilterMode filter;
682         PaintHandle paintHandle;
683     };
684     DrawImageLatticeOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawImageLatticeOpItem(const Image * image,const Lattice & lattice,const Rect & dst,FilterMode filterMode,const Paint & paint)685     DrawImageLatticeOpItem(const Image* image, const Lattice& lattice, const Rect& dst, FilterMode filterMode,
686         const Paint& paint) : DrawWithPaintOpItem(paint, DrawOpItem::IMAGE_LATTICE_OPITEM), lattice_(lattice),
687         dst_(dst), filter_(filterMode), image_(std::make_shared<Image>(*image)) {}
688     ~DrawImageLatticeOpItem() override = default;
689 
690     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
691     void Marshalling(DrawCmdList& cmdList) override;
692     void Playback(Canvas* canvas, const Rect* rect) override;
693     void Dump(std::string& out) const override;
694 private:
695     Lattice lattice_;
696     Rect dst_;
697     FilterMode filter_;
698     std::shared_ptr<Image> image_;
699 };
700 
701 class DrawAtlasOpItem : public DrawWithPaintOpItem {
702 public:
703     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle704         ConstructorHandle(const OpDataHandle& atlas, const std::pair<size_t, size_t>& xform,
705             const std::pair<size_t, size_t>& tex, const std::pair<size_t, size_t>& colors, BlendMode mode,
706             const SamplingOptions& samplingOptions, bool hasCullRect, const Rect& cullRect,
707             const PaintHandle& paintHandle)
708             : OpItem(DrawOpItem::ATLAS_OPITEM), atlas(atlas), xform(xform), tex(tex), colors(colors), mode(mode),
709               samplingOptions(samplingOptions), hasCullRect(hasCullRect), cullRect(cullRect),
710               paintHandle(paintHandle) {}
711         ~ConstructorHandle() override = default;
712         OpDataHandle atlas;
713         std::pair<size_t, size_t> xform;
714         std::pair<size_t, size_t> tex;
715         std::pair<size_t, size_t> colors;
716         BlendMode mode;
717         SamplingOptions samplingOptions;
718         bool hasCullRect;
719         Rect cullRect;
720         PaintHandle paintHandle;
721     };
722     DrawAtlasOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawAtlasOpItem(const Image * atlas,const std::vector<RSXform> & xform,const std::vector<Rect> & tex,const std::vector<ColorQuad> & colors,BlendMode mode,const SamplingOptions & samplingOptions,bool hasCullRect,const Rect & cullRect,const Paint & paint)723     DrawAtlasOpItem(const Image* atlas, const std::vector<RSXform>& xform,
724         const std::vector<Rect>& tex, const std::vector<ColorQuad>& colors, BlendMode mode,
725         const SamplingOptions& samplingOptions, bool hasCullRect, const Rect& cullRect, const Paint& paint)
726         : DrawWithPaintOpItem(paint, DrawOpItem::ATLAS_OPITEM), xform_(xform), tex_(tex), colors_(colors), mode_(mode),
727           samplingOptions_(samplingOptions), hasCullRect_(hasCullRect), cullRect_(cullRect),
728           atlas_(std::make_shared<Image>(*atlas)) {}
729     ~DrawAtlasOpItem() override = default;
730 
731     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
732     void Marshalling(DrawCmdList& cmdList) override;
733     void Playback(Canvas* canvas, const Rect* rect) override;
734     void DumpItems(std::string& out) const override;
735 
736 private:
737     std::vector<RSXform> xform_;
738     std::vector<Rect> tex_;
739     std::vector<ColorQuad> colors_;
740     BlendMode mode_;
741     SamplingOptions samplingOptions_;
742     bool hasCullRect_;
743     Rect cullRect_;
744     std::shared_ptr<Image> atlas_;
745 };
746 
747 class DrawBitmapOpItem : public DrawWithPaintOpItem {
748 public:
749     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle750         ConstructorHandle(const ImageHandle& bitmap, scalar px, scalar py, const PaintHandle& paintHandle)
751             : OpItem(DrawOpItem::BITMAP_OPITEM), bitmap(bitmap), px(px), py(py), paintHandle(paintHandle) {}
752         ~ConstructorHandle() override = default;
753         ImageHandle bitmap;
754         scalar px;
755         scalar py;
756         PaintHandle paintHandle;
757     };
758     DrawBitmapOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawBitmapOpItem(const Bitmap & bitmap,const scalar px,const scalar py,const Paint & paint)759     DrawBitmapOpItem(const Bitmap& bitmap, const scalar px, const scalar py, const Paint& paint)
760         : DrawWithPaintOpItem(paint, DrawOpItem::BITMAP_OPITEM), px_(px), py_(py),
761           bitmap_(std::make_shared<Bitmap>(bitmap)) {}
762     ~DrawBitmapOpItem() override = default;
763 
764     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
765     void Marshalling(DrawCmdList& cmdList) override;
766     void Playback(Canvas* canvas, const Rect* rect) override;
767     void DumpItems(std::string& out) const override;
768 
769 private:
770     scalar px_;
771     scalar py_;
772     std::shared_ptr<Bitmap> bitmap_;
773 };
774 
775 class DrawImageOpItem : public DrawWithPaintOpItem {
776 public:
777     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle778         ConstructorHandle(const OpDataHandle& image, scalar px, scalar py, const SamplingOptions& samplingOptions,
779             const PaintHandle& paintHandle)
780             : OpItem(DrawOpItem::IMAGE_OPITEM), image(image), px(px), py(py), samplingOptions(samplingOptions),
781               paintHandle(paintHandle) {}
782         ~ConstructorHandle() override = default;
783         OpDataHandle image;
784         scalar px;
785         scalar py;
786         SamplingOptions samplingOptions;
787         PaintHandle paintHandle;
788     };
789     DrawImageOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawImageOpItem(const Image & image,const scalar px,const scalar py,const SamplingOptions & sampling,const Paint & paint)790     DrawImageOpItem(const Image& image, const scalar px, const scalar py, const SamplingOptions& sampling,
791         const Paint& paint) : DrawWithPaintOpItem(paint, DrawOpItem::IMAGE_OPITEM), px_(px), py_(py),
792         samplingOptions_(sampling), image_(std::make_shared<Image>(image)) {}
793     ~DrawImageOpItem() override = default;
794 
795     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
796     void Marshalling(DrawCmdList& cmdList) override;
797     void Playback(Canvas* canvas, const Rect* rect) override;
798     void DumpItems(std::string& out) const override;
799 
800 private:
801     scalar px_;
802     scalar py_;
803     SamplingOptions samplingOptions_;
804     std::shared_ptr<Image> image_;
805 };
806 
807 class DrawImageRectOpItem : public DrawWithPaintOpItem {
808 public:
809     struct ConstructorHandle : public OpItem {
810         ConstructorHandle(const OpDataHandle& image, const Rect& src, const Rect& dst, const SamplingOptions& sampling,
811             SrcRectConstraint constraint, const PaintHandle& paintHandle, bool isForeground = false)
OpItemConstructorHandle812             : OpItem(DrawOpItem::IMAGE_RECT_OPITEM), image(image), src(src), dst(dst),
813               sampling(sampling), constraint(constraint), paintHandle(paintHandle), isForeground(isForeground) {}
814         ~ConstructorHandle() override = default;
815         OpDataHandle image;
816         Rect src;
817         Rect dst;
818         SamplingOptions sampling;
819         SrcRectConstraint constraint;
820         PaintHandle paintHandle;
821         bool isForeground;
822     };
823     DrawImageRectOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
824     DrawImageRectOpItem(const Image& image, const Rect& src, const Rect& dst, const SamplingOptions& sampling,
825         SrcRectConstraint constraint, const Paint& paint, bool isForeground = false);
826     ~DrawImageRectOpItem() override = default;
827 
828     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
829     void Marshalling(DrawCmdList& cmdList) override;
830     void Playback(Canvas* canvas, const Rect* rect) override;
831     void DumpItems(std::string& out) const override;
832 private:
833     Rect src_;
834     Rect dst_;
835     SamplingOptions sampling_;
836     SrcRectConstraint constraint_;
837     std::shared_ptr<Image> image_;
838     bool isForeground_ = false;
839 };
840 
841 class DrawRecordCmdOpItem : public DrawOpItem {
842 public:
843     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle844         ConstructorHandle(const OpDataHandle& recordCmdHandle, const Matrix::Buffer& matrixBuffer,
845             bool hasBrush, const BrushHandle& brushHandle)
846             : OpItem(DrawOpItem::RECORD_CMD_OPITEM), recordCmdHandle(recordCmdHandle),
847             matrixBuffer(matrixBuffer), hasBrush(hasBrush), brushHandle(brushHandle) {}
848         ~ConstructorHandle() override = default;
849         OpDataHandle recordCmdHandle;
850         Matrix::Buffer matrixBuffer;
851         bool hasBrush = false;
852         BrushHandle brushHandle;
853     };
854     DrawRecordCmdOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
855     explicit DrawRecordCmdOpItem(const std::shared_ptr<RecordCmd>& recordCmd,
856         const Matrix* matrix, const Brush* brush);
857     ~DrawRecordCmdOpItem() override = default;
858 
859     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
860     void Marshalling(DrawCmdList& cmdList) override;
861     void Playback(Canvas* canvas, const Rect* rect) override;
862 private:
863     std::shared_ptr<RecordCmd> recordCmd_ = nullptr;
864     Matrix matrix_;
865     bool hasBrush_ = false;
866     Brush brush_;
867 };
868 
869 class DrawPictureOpItem : public DrawOpItem {
870 public:
871     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle872         ConstructorHandle(const OpDataHandle& picture) : OpItem(DrawOpItem::PICTURE_OPITEM), picture(picture) {}
873         ~ConstructorHandle() override = default;
874         OpDataHandle picture;
875     };
876     DrawPictureOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawPictureOpItem(const Picture & picture)877     explicit DrawPictureOpItem(const Picture& picture)
878         : DrawOpItem(DrawOpItem::PICTURE_OPITEM), picture_(std::make_shared<Picture>(picture)) {}
879     ~DrawPictureOpItem() override = default;
880 
881     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
882     void Marshalling(DrawCmdList& cmdList) override;
883     void Playback(Canvas* canvas, const Rect* rect) override;
884 private:
885     std::shared_ptr<Picture> picture_;
886 };
887 
888 class DrawTextBlobOpItem : public DrawWithPaintOpItem {
889 public:
890     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle891         ConstructorHandle(const OpDataHandle& textBlob, const uint64_t& globalUniqueId,
892             scalar x, scalar y, const PaintHandle& paintHandle)
893             : OpItem(DrawOpItem::TEXT_BLOB_OPITEM), textBlob(textBlob), globalUniqueId(globalUniqueId),
894             x(x), y(y), paintHandle(paintHandle) {}
895         ~ConstructorHandle() override = default;
896         static bool GenerateCachedOpItem(DrawCmdList& cmdList, const TextBlob* textBlob, scalar x, scalar y, Paint& p);
897         bool GenerateCachedOpItem(DrawCmdList& cmdList, Canvas* canvas);
898         OpDataHandle textBlob;
899         uint64_t globalUniqueId;
900         scalar x;
901         scalar y;
902         PaintHandle paintHandle;
903     };
904     DrawTextBlobOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawTextBlobOpItem(const TextBlob * blob,const scalar x,const scalar y,const Paint & paint)905     DrawTextBlobOpItem(const TextBlob* blob, const scalar x, const scalar y, const Paint& paint)
906         : DrawWithPaintOpItem(paint, DrawOpItem::TEXT_BLOB_OPITEM), x_(x), y_(y),
907           textBlob_(std::make_shared<TextBlob>(*blob)) {}
908     ~DrawTextBlobOpItem() override = default;
909 
910     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
911     void Marshalling(DrawCmdList& cmdList) override;
912     void Playback(Canvas* canvas, const Rect* rect) override;
913     virtual void DumpItems(std::string& out) const override;
914 
915     std::shared_ptr<DrawImageRectOpItem> GenerateCachedOpItem(Canvas* canvas);
916 protected:
917     void DrawHighContrast(Canvas* canvas, bool offSreen = false) const;
918     void DrawHighContrastEnabled(Canvas* canvas) const;
919     bool GetOffScreenSurfaceAndCanvas(const Canvas& canvas,
920         std::shared_ptr<Drawing::Surface>& offScreenSurface, std::shared_ptr<Canvas>& offScreenCanvas) const;
921 private:
922     scalar x_;
923     scalar y_;
924     std::shared_ptr<TextBlob> textBlob_;
925 };
926 
927 class DrawSymbolOpItem : public DrawWithPaintOpItem {
928 public:
929     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle930         ConstructorHandle(const SymbolOpHandle& symbolHandle, Point locate, const PaintHandle& paintHandle)
931             : OpItem(DrawOpItem::SYMBOL_OPITEM), symbolHandle(symbolHandle), locate(locate), paintHandle(paintHandle) {}
932         ~ConstructorHandle() override = default;
933         SymbolOpHandle symbolHandle;
934         Point locate;
935         PaintHandle paintHandle;
936     };
937     DrawSymbolOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
DrawSymbolOpItem(const DrawingHMSymbolData & symbol,Point locate,const Paint & paint)938     DrawSymbolOpItem(const DrawingHMSymbolData& symbol, Point locate, const Paint& paint)
939         : DrawWithPaintOpItem(paint, DrawOpItem::SYMBOL_OPITEM), symbol_(symbol), locate_(locate) {}
940     ~DrawSymbolOpItem() override = default;
941 
942     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
943     void Marshalling(DrawCmdList& cmdList) override;
944     void Playback(Canvas* canvas, const Rect* rect) override;
945     virtual void DumpItems(std::string& out) const override;
946 
947 private:
948     static void MergeDrawingPath(
949         Path& multPath, DrawingRenderGroup& group, std::vector<Path>& pathLayers);
950     DrawingHMSymbolData symbol_;
951     Point locate_;
952 };
953 
954 class ClipRectOpItem : public DrawOpItem {
955 public:
956     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle957         ConstructorHandle(const Rect& rect, ClipOp op, bool doAntiAlias)
958             : OpItem(DrawOpItem::CLIP_RECT_OPITEM), rect(rect), clipOp(op), doAntiAlias(doAntiAlias) {}
959         ~ConstructorHandle() override = default;
960         Rect rect;
961         ClipOp clipOp;
962         bool doAntiAlias;
963     };
964     explicit ClipRectOpItem(ConstructorHandle* handle);
ClipRectOpItem(const Rect & rect,ClipOp op,bool doAntiAlias)965     ClipRectOpItem(const Rect& rect, ClipOp op, bool doAntiAlias)
966         : DrawOpItem(DrawOpItem::CLIP_RECT_OPITEM), rect_(rect), clipOp_(op), doAntiAlias_(doAntiAlias) {}
967     ~ClipRectOpItem() override = default;
968 
969     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
970     void Marshalling(DrawCmdList& cmdList) override;
971     void Playback(Canvas* canvas, const Rect* rect) override;
972     void Dump(std::string& out) const override;
973 private:
974     Rect rect_;
975     ClipOp clipOp_;
976     bool doAntiAlias_;
977 };
978 
979 class ClipIRectOpItem : public DrawOpItem {
980 public:
981     struct ConstructorHandle : public OpItem {
982         ConstructorHandle(const RectI& rect, ClipOp op = ClipOp::INTERSECT)
OpItemConstructorHandle983             : OpItem(DrawOpItem::CLIP_IRECT_OPITEM), rect(rect), clipOp(op) {}
984         ~ConstructorHandle() override = default;
985         RectI rect;
986         ClipOp clipOp;
987     };
988     explicit ClipIRectOpItem(ConstructorHandle* handle);
ClipIRectOpItem(const RectI & rect,ClipOp op)989     ClipIRectOpItem(const RectI& rect, ClipOp op)
990         : DrawOpItem(DrawOpItem::CLIP_IRECT_OPITEM), rect_(rect), clipOp_(op) {}
991     ~ClipIRectOpItem() override = default;
992 
993     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
994     void Marshalling(DrawCmdList& cmdList) override;
995     void Playback(Canvas* canvas, const Rect* rect) override;
996     void Dump(std::string& out) const override;
997 private:
998     RectI rect_;
999     ClipOp clipOp_;
1000 };
1001 
1002 class ClipRoundRectOpItem : public DrawOpItem {
1003 public:
1004     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1005         ConstructorHandle(const RoundRect& rrect, ClipOp op, bool doAntiAlias)
1006             : OpItem(DrawOpItem::CLIP_ROUND_RECT_OPITEM), rrect(rrect), clipOp(op), doAntiAlias(doAntiAlias) {}
1007         ~ConstructorHandle() override = default;
1008         RoundRect rrect;
1009         ClipOp clipOp;
1010         bool doAntiAlias;
1011     };
1012     explicit ClipRoundRectOpItem(ConstructorHandle* handle);
ClipRoundRectOpItem(const RoundRect & roundRect,ClipOp op,bool doAntiAlias)1013     ClipRoundRectOpItem(const RoundRect& roundRect, ClipOp op, bool doAntiAlias)
1014         : DrawOpItem(DrawOpItem::CLIP_ROUND_RECT_OPITEM), rrect_(roundRect), clipOp_(op), doAntiAlias_(doAntiAlias) {}
1015     ~ClipRoundRectOpItem() override = default;
1016 
1017     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1018     void Marshalling(DrawCmdList& cmdList) override;
1019     void Playback(Canvas* canvas, const Rect* rect) override;
1020     void Dump(std::string& out) const override;
1021 private:
1022     RoundRect rrect_;
1023     ClipOp clipOp_;
1024     bool doAntiAlias_;
1025 };
1026 
1027 class ClipPathOpItem : public DrawOpItem {
1028 public:
1029     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1030         ConstructorHandle(const OpDataHandle& path, ClipOp clipOp, bool doAntiAlias)
1031             : OpItem(DrawOpItem::CLIP_PATH_OPITEM), path(path), clipOp(clipOp), doAntiAlias(doAntiAlias) {}
1032         ~ConstructorHandle() override = default;
1033         OpDataHandle path;
1034         ClipOp clipOp;
1035         bool doAntiAlias;
1036     };
1037     ClipPathOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
ClipPathOpItem(const Path & path,ClipOp op,bool doAntiAlias)1038     ClipPathOpItem(const Path& path, ClipOp op, bool doAntiAlias)
1039         : DrawOpItem(DrawOpItem::CLIP_PATH_OPITEM), clipOp_(op), doAntiAlias_(doAntiAlias),
1040           path_(std::make_shared<Path>(path)) {}
1041     ~ClipPathOpItem() override = default;
1042 
1043     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1044     void Marshalling(DrawCmdList& cmdList) override;
1045     void Playback(Canvas* canvas, const Rect* rect) override;
1046 private:
1047     ClipOp clipOp_;
1048     bool doAntiAlias_;
1049     std::shared_ptr<Path> path_;
1050 };
1051 
1052 class ClipRegionOpItem : public DrawOpItem {
1053 public:
1054     struct ConstructorHandle : public OpItem {
1055         ConstructorHandle(const OpDataHandle& region, ClipOp clipOp = ClipOp::INTERSECT)
OpItemConstructorHandle1056             : OpItem(DrawOpItem::CLIP_REGION_OPITEM), region(region), clipOp(clipOp) {}
1057         ~ConstructorHandle() override = default;
1058         OpDataHandle region;
1059         ClipOp clipOp;
1060     };
1061     ClipRegionOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
ClipRegionOpItem(const Region & region,ClipOp op)1062     ClipRegionOpItem(const Region& region, ClipOp op)
1063         : DrawOpItem(DrawOpItem::CLIP_REGION_OPITEM), clipOp_(op), region_(std::make_shared<Region>(region)) {}
1064     ~ClipRegionOpItem() override = default;
1065 
1066     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1067     void Marshalling(DrawCmdList& cmdList) override;
1068     void Playback(Canvas* canvas, const Rect* rect) override;
1069     void Dump(std::string& out) const override;
1070 private:
1071     ClipOp clipOp_;
1072     std::shared_ptr<Region> region_;
1073 };
1074 
1075 class SetMatrixOpItem : public DrawOpItem {
1076 public:
1077     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1078         ConstructorHandle(const Matrix::Buffer& matrixBuffer)
1079             : OpItem(DrawOpItem::SET_MATRIX_OPITEM), matrixBuffer(matrixBuffer) {}
1080         ~ConstructorHandle() override = default;
1081         Matrix::Buffer matrixBuffer;
1082     };
1083     explicit SetMatrixOpItem(ConstructorHandle* handle);
SetMatrixOpItem(const Matrix & matrix)1084     explicit SetMatrixOpItem(const Matrix& matrix) : DrawOpItem(DrawOpItem::SET_MATRIX_OPITEM), matrix_(matrix) {}
1085     ~SetMatrixOpItem() override = default;
1086 
1087     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1088     void Marshalling(DrawCmdList& cmdList) override;
1089     void Playback(Canvas* canvas, const Rect* rect) override;
1090     void Dump(std::string& out) const override;
1091 private:
1092     Matrix matrix_;
1093 };
1094 
1095 class ResetMatrixOpItem : public DrawOpItem {
1096 public:
1097     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1098         ConstructorHandle() : OpItem(DrawOpItem::RESET_MATRIX_OPITEM) {}
1099         ~ConstructorHandle() override = default;
1100     };
1101     ResetMatrixOpItem();
1102     ~ResetMatrixOpItem() override = default;
1103 
1104     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1105     void Marshalling(DrawCmdList& cmdList) override;
1106     void Playback(Canvas* canvas, const Rect* rect) override;
1107 };
1108 
1109 class ConcatMatrixOpItem : public DrawOpItem {
1110 public:
1111     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1112         ConstructorHandle(const Matrix::Buffer& matrixBuffer)
1113             : OpItem(DrawOpItem::CONCAT_MATRIX_OPITEM), matrixBuffer(matrixBuffer) {}
1114         ~ConstructorHandle() override = default;
1115         Matrix::Buffer matrixBuffer;
1116     };
1117     explicit ConcatMatrixOpItem(ConstructorHandle* handle);
ConcatMatrixOpItem(const Matrix & matrix)1118     explicit ConcatMatrixOpItem(const Matrix& matrix) : DrawOpItem(DrawOpItem::CONCAT_MATRIX_OPITEM), matrix_(matrix) {}
1119     ~ConcatMatrixOpItem() override = default;
1120 
1121     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1122     void Marshalling(DrawCmdList& cmdList) override;
1123     void Playback(Canvas* canvas, const Rect* rect) override;
1124     void Dump(std::string& out) const override;
1125 private:
1126     Matrix matrix_;
1127 };
1128 
1129 class TranslateOpItem : public DrawOpItem {
1130 public:
1131     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1132         ConstructorHandle(scalar dx, scalar dy) : OpItem(DrawOpItem::TRANSLATE_OPITEM), dx(dx), dy(dy) {}
1133         ~ConstructorHandle() override = default;
1134         scalar dx;
1135         scalar dy;
1136     };
1137     explicit TranslateOpItem(ConstructorHandle* handle);
TranslateOpItem(scalar dx,scalar dy)1138     TranslateOpItem(scalar dx, scalar dy) : DrawOpItem(DrawOpItem::TRANSLATE_OPITEM), dx_(dx), dy_(dy) {}
1139     ~TranslateOpItem() override = default;
1140 
1141     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1142     void Marshalling(DrawCmdList& cmdList) override;
1143     void Playback(Canvas* canvas, const Rect* rect) override;
1144     void Dump(std::string& out) const override;
1145 private:
1146     scalar dx_;
1147     scalar dy_;
1148 };
1149 
1150 class ScaleOpItem : public DrawOpItem {
1151 public:
1152     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1153         ConstructorHandle(scalar sx, scalar sy) : OpItem(DrawOpItem::SCALE_OPITEM), sx(sx), sy(sy) {}
1154         ~ConstructorHandle() override = default;
1155         scalar sx;
1156         scalar sy;
1157     };
1158     explicit ScaleOpItem(ConstructorHandle* handle);
ScaleOpItem(scalar sx,scalar sy)1159     ScaleOpItem(scalar sx, scalar sy) : DrawOpItem(DrawOpItem::SCALE_OPITEM), sx_(sx), sy_(sy) {}
1160     ~ScaleOpItem() override = default;
1161 
1162     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1163     void Marshalling(DrawCmdList& cmdList) override;
1164     void Playback(Canvas* canvas, const Rect* rect) override;
1165     void Dump(std::string& out) const override;
1166 private:
1167     scalar sx_;
1168     scalar sy_;
1169 };
1170 
1171 class RotateOpItem : public DrawOpItem {
1172 public:
1173     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1174         ConstructorHandle(scalar deg, scalar sx, scalar sy)
1175             : OpItem(DrawOpItem::ROTATE_OPITEM), deg(deg), sx(sx), sy(sy) {}
1176         ~ConstructorHandle() override = default;
1177         scalar deg;
1178         scalar sx;
1179         scalar sy;
1180     };
1181     explicit RotateOpItem(ConstructorHandle* handle);
RotateOpItem(scalar deg,scalar sx,scalar sy)1182     RotateOpItem(scalar deg, scalar sx, scalar sy)
1183         : DrawOpItem(DrawOpItem::ROTATE_OPITEM), deg_(deg), sx_(sx), sy_(sy) {}
1184     ~RotateOpItem() override = default;
1185 
1186     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1187     void Marshalling(DrawCmdList& cmdList) override;
1188     void Playback(Canvas* canvas, const Rect* rect) override;
1189     void Dump(std::string& out) const override;
1190 private:
1191     scalar deg_;
1192     scalar sx_;
1193     scalar sy_;
1194 };
1195 
1196 class ShearOpItem : public DrawOpItem {
1197 public:
1198     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1199         ConstructorHandle(scalar sx, scalar sy) : OpItem(DrawOpItem::SHEAR_OPITEM), sx(sx), sy(sy) {}
1200         ~ConstructorHandle() override = default;
1201         scalar sx;
1202         scalar sy;
1203     };
1204     explicit ShearOpItem(ConstructorHandle* handle);
ShearOpItem(scalar sx,scalar sy)1205     ShearOpItem(scalar sx, scalar sy) : DrawOpItem(DrawOpItem::SHEAR_OPITEM), sx_(sx), sy_(sy) {}
1206     ~ShearOpItem() override = default;
1207 
1208     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1209     void Marshalling(DrawCmdList& cmdList) override;
1210     void Playback(Canvas* canvas, const Rect* rect) override;
1211     void Dump(std::string& out) const override;
1212 private:
1213     scalar sx_;
1214     scalar sy_;
1215 };
1216 
1217 class FlushOpItem : public DrawOpItem {
1218 public:
1219     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1220         ConstructorHandle() : OpItem(DrawOpItem::FLUSH_OPITEM) {}
1221         ~ConstructorHandle() override = default;
1222     };
1223     FlushOpItem();
1224     ~FlushOpItem() override = default;
1225     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1226     void Marshalling(DrawCmdList& cmdList) override;
1227     void Playback(Canvas* canvas, const Rect* rect) override;
1228 };
1229 
1230 class ClearOpItem : public DrawOpItem {
1231 public:
1232     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1233         ConstructorHandle(ColorQuad color) : OpItem(DrawOpItem::CLEAR_OPITEM), color(color) {}
1234         ~ConstructorHandle() override = default;
1235         ColorQuad color;
1236     };
1237     explicit ClearOpItem(ConstructorHandle* handle);
ClearOpItem(ColorQuad color)1238     explicit ClearOpItem(ColorQuad color) : DrawOpItem(DrawOpItem::CLEAR_OPITEM), color_(color) {}
1239     ~ClearOpItem() override = default;
1240     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1241     void Marshalling(DrawCmdList& cmdList) override;
1242     void Playback(Canvas* canvas, const Rect* rect) override;
1243     void Dump(std::string& out) const override;
1244 private:
1245     ColorQuad color_;
1246 };
1247 
1248 class SaveOpItem : public DrawOpItem {
1249 public:
1250     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1251         ConstructorHandle() : OpItem(DrawOpItem::SAVE_OPITEM) {}
1252         ~ConstructorHandle() override = default;
1253     };
1254     SaveOpItem();
1255     ~SaveOpItem() override = default;
1256     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1257     void Marshalling(DrawCmdList& cmdList) override;
1258     void Playback(Canvas* canvas, const Rect* rect) override;
1259 };
1260 
1261 class SaveLayerOpItem : public DrawOpItem {
1262 public:
1263     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1264         ConstructorHandle(const Rect& rect, bool hasBrush, const BrushHandle& brushHandle, uint32_t saveLayerFlags)
1265             : OpItem(DrawOpItem::SAVE_LAYER_OPITEM), rect(rect), hasBrush(hasBrush), brushHandle(brushHandle),
1266               saveLayerFlags(saveLayerFlags) {}
1267         ~ConstructorHandle() override = default;
1268         Rect rect;
1269         bool hasBrush;
1270         BrushHandle brushHandle;
1271         uint32_t saveLayerFlags;
1272     };
1273     SaveLayerOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
SaveLayerOpItem(const SaveLayerOps & saveLayerOps)1274     SaveLayerOpItem(const SaveLayerOps& saveLayerOps)
1275         : DrawOpItem(DrawOpItem::SAVE_LAYER_OPITEM), saveLayerFlags_(saveLayerOps.GetSaveLayerFlags())
1276     {
1277         if (saveLayerOps.GetBounds() != nullptr) {
1278             rect_ = *saveLayerOps.GetBounds();
1279         }
1280         const Brush* brush = saveLayerOps.GetBrush();
1281         if (brush != nullptr) {
1282             hasBrush_ = true;
1283             brush_ = *brush;
1284         }
1285     }
1286     ~SaveLayerOpItem() override = default;
1287 
1288     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1289     void Marshalling(DrawCmdList& cmdList) override;
1290     void Playback(Canvas* canvas, const Rect* rect) override;
1291     void Dump(std::string& out) const override;
1292 private:
1293     uint32_t saveLayerFlags_;
1294     Rect rect_;
1295     bool hasBrush_ = false;
1296     Brush brush_;
1297 };
1298 
1299 class RestoreOpItem : public DrawOpItem {
1300 public:
1301     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1302         ConstructorHandle() : OpItem(DrawOpItem::RESTORE_OPITEM) {}
1303         ~ConstructorHandle() override = default;
1304     };
1305     RestoreOpItem();
1306     ~RestoreOpItem() override = default;
1307     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1308     void Marshalling(DrawCmdList& cmdList) override;
1309     void Playback(Canvas* canvas, const Rect* rect) override;
1310 };
1311 
1312 class DiscardOpItem : public DrawOpItem {
1313 public:
1314     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1315         ConstructorHandle() : OpItem(DrawOpItem::DISCARD_OPITEM) {}
1316         ~ConstructorHandle() override = default;
1317     };
1318     DiscardOpItem();
1319     ~DiscardOpItem() override = default;
1320     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1321     void Marshalling(DrawCmdList& cmdList) override;
1322     void Playback(Canvas* canvas, const Rect* rect) override;
1323 };
1324 
1325 class ClipAdaptiveRoundRectOpItem : public DrawOpItem {
1326 public:
1327     struct ConstructorHandle : public OpItem {
ConstructorHandleConstructorHandle1328         ConstructorHandle(const std::pair<size_t, size_t>& radiusData)
1329             : OpItem(DrawOpItem::CLIP_ADAPTIVE_ROUND_RECT_OPITEM), radiusData(radiusData) {}
1330         ~ConstructorHandle() override = default;
1331         std::pair<size_t, size_t> radiusData;
1332     };
1333     ClipAdaptiveRoundRectOpItem(const DrawCmdList& cmdList, ConstructorHandle* handle);
ClipAdaptiveRoundRectOpItem(const std::vector<Point> & radiusData)1334     explicit ClipAdaptiveRoundRectOpItem(const std::vector<Point>& radiusData)
1335         : DrawOpItem(DrawOpItem::CLIP_ADAPTIVE_ROUND_RECT_OPITEM),  radiusData_(radiusData) {}
1336     ~ClipAdaptiveRoundRectOpItem() override = default;
1337     static std::shared_ptr<DrawOpItem> Unmarshalling(const DrawCmdList& cmdList, void* handle);
1338     void Marshalling(DrawCmdList& cmdList) override;
1339     void Playback(Canvas* canvas, const Rect* rect) override;
1340     void Dump(std::string& out) const override;
1341 private:
1342     std::vector<Point> radiusData_;
1343 };
1344 } // namespace Drawing
1345 } // namespace Rosen
1346 } // namespace OHOS
1347 #endif
1348