• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_H
17 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_H
18 
19 #ifdef ROSEN_OHOS
20 #include <GLES/gl.h>
21 
22 #include "EGL/egl.h"
23 #include "EGL/eglext.h"
24 #include "GLES2/gl2.h"
25 #include "GLES2/gl2ext.h"
26 #endif
27 #ifndef USE_ROSEN_DRAWING
28 #include "include/core/SkCanvas.h"
29 #include "include/core/SkDrawable.h"
30 #include "include/core/SkImage.h"
31 #include "include/core/SkImageFilter.h"
32 #include "include/core/SkPaint.h"
33 #include "include/core/SkPath.h"
34 #include "include/core/SkPicture.h"
35 #include "include/core/SkRRect.h"
36 #include "include/core/SkRect.h"
37 #include "include/core/SkRegion.h"
38 #include "include/core/SkTextBlob.h"
39 #ifdef NEW_SKIA
40 #include "include/core/SkVertices.h"
41 #endif
42 #include "pixel_map.h"
43 #include "src/core/SkDrawShadowInfo.h"
44 #ifdef ROSEN_OHOS
45 #include "surface_buffer.h"
46 #include "window.h"
47 #endif
48 
49 #include "common/rs_common_def.h"
50 #include "pipeline/rs_draw_cmd_list.h"
51 #include "pipeline/rs_recording_canvas.h"
52 #include "property/rs_properties_def.h"
53 #include "render/rs_image.h"
54 #include "transaction/rs_marshalling_helper.h"
55 #include <optional>
56 
57 namespace OHOS {
58 namespace Rosen {
59 class RSPaintFilterCanvas;
60 
61 enum RSOpType : uint16_t {
62     OPITEM,
63     OPITEM_WITH_PAINT,
64     RECT_OPITEM,
65     ROUND_RECT_OPITEM,
66     IMAGE_WITH_PARM_OPITEM,
67     DRRECT_OPITEM,
68     OVAL_OPITEM,
69     REGION_OPITEM,
70     ARC_OPITEM,
71     SAVE_OPITEM,
72     RESTORE_OPITEM,
73     FLUSH_OPITEM,
74     MATRIX_OPITEM,
75     CLIP_RECT_OPITEM,
76     CLIP_RRECT_OPITEM,
77     CLIP_REGION_OPITEM,
78     TRANSLATE_OPITEM,
79     TEXTBLOB_OPITEM,
80     BITMAP_OPITEM,
81     COLOR_FILTER_BITMAP_OPITEM,
82     BITMAP_RECT_OPITEM,
83     BITMAP_NINE_OPITEM,
84     PIXELMAP_OPITEM,
85     PIXELMAP_RECT_OPITEM,
86     ADAPTIVE_RRECT_OPITEM,
87     ADAPTIVE_RRECT_SCALE_OPITEM,
88     CLIP_ADAPTIVE_RRECT_OPITEM,
89     CLIP_OUTSET_RECT_OPITEM,
90     PATH_OPITEM,
91     CLIP_PATH_OPITEM,
92     PAINT_OPITEM,
93     CONCAT_OPITEM,
94     SAVE_LAYER_OPITEM,
95     DRAWABLE_OPITEM,
96     PICTURE_OPITEM,
97     POINTS_OPITEM,
98     VERTICES_OPITEM,
99     SHADOW_REC_OPITEM,
100     MULTIPLY_ALPHA_OPITEM,
101     SAVE_ALPHA_OPITEM,
102     RESTORE_ALPHA_OPITEM,
103     SURFACEBUFFER_OPITEM,
104     SCALE_OPITEM,
105 };
106 namespace {
GetOpTypeString(RSOpType type)107     std::string GetOpTypeString(RSOpType type)
108     {
109 #define GETOPTYPESTRING(t) case (t): return #t
110         switch (type) {
111             GETOPTYPESTRING(OPITEM);
112             GETOPTYPESTRING(OPITEM_WITH_PAINT);
113             GETOPTYPESTRING(RECT_OPITEM);
114             GETOPTYPESTRING(ROUND_RECT_OPITEM);
115             GETOPTYPESTRING(IMAGE_WITH_PARM_OPITEM);
116             GETOPTYPESTRING(DRRECT_OPITEM);
117             GETOPTYPESTRING(OVAL_OPITEM);
118             GETOPTYPESTRING(REGION_OPITEM);
119             GETOPTYPESTRING(ARC_OPITEM);
120             GETOPTYPESTRING(SAVE_OPITEM);
121             GETOPTYPESTRING(RESTORE_OPITEM);
122             GETOPTYPESTRING(FLUSH_OPITEM);
123             GETOPTYPESTRING(MATRIX_OPITEM);
124             GETOPTYPESTRING(CLIP_RECT_OPITEM);
125             GETOPTYPESTRING(CLIP_RRECT_OPITEM);
126             GETOPTYPESTRING(CLIP_REGION_OPITEM);
127             GETOPTYPESTRING(TRANSLATE_OPITEM);
128             GETOPTYPESTRING(TEXTBLOB_OPITEM);
129             GETOPTYPESTRING(BITMAP_OPITEM);
130             GETOPTYPESTRING(COLOR_FILTER_BITMAP_OPITEM);
131             GETOPTYPESTRING(BITMAP_RECT_OPITEM);
132             GETOPTYPESTRING(BITMAP_NINE_OPITEM);
133             GETOPTYPESTRING(PIXELMAP_OPITEM);
134             GETOPTYPESTRING(PIXELMAP_RECT_OPITEM);
135             GETOPTYPESTRING(ADAPTIVE_RRECT_OPITEM);
136             GETOPTYPESTRING(ADAPTIVE_RRECT_SCALE_OPITEM);
137             GETOPTYPESTRING(CLIP_ADAPTIVE_RRECT_OPITEM);
138             GETOPTYPESTRING(CLIP_OUTSET_RECT_OPITEM);
139             GETOPTYPESTRING(PATH_OPITEM);
140             GETOPTYPESTRING(CLIP_PATH_OPITEM);
141             GETOPTYPESTRING(PAINT_OPITEM);
142             GETOPTYPESTRING(CONCAT_OPITEM);
143             GETOPTYPESTRING(SAVE_LAYER_OPITEM);
144             GETOPTYPESTRING(DRAWABLE_OPITEM);
145             GETOPTYPESTRING(PICTURE_OPITEM);
146             GETOPTYPESTRING(POINTS_OPITEM);
147             GETOPTYPESTRING(VERTICES_OPITEM);
148             GETOPTYPESTRING(SHADOW_REC_OPITEM);
149             GETOPTYPESTRING(MULTIPLY_ALPHA_OPITEM);
150             GETOPTYPESTRING(SAVE_ALPHA_OPITEM);
151             GETOPTYPESTRING(RESTORE_ALPHA_OPITEM);
152             GETOPTYPESTRING(SURFACEBUFFER_OPITEM);
153             GETOPTYPESTRING(SCALE_OPITEM);
154             default:
155                 break;
156         }
157         return "";
158     }
159 #undef GETOPTYPESTRING
160 }
161 
162 class RSB_EXPORT OpItemTasks {
163 public:
164     static OpItemTasks& Instance();
165     void AddTask(std::function<void()> task);
166     void ProcessTask();
167     bool IsEmpty();
168 private:
169     OpItemTasks() = default;
170     ~OpItemTasks() = default;
171     OpItemTasks(const OpItemTasks&);
172     OpItemTasks(const OpItemTasks&&);
173     OpItemTasks& operator=(const OpItemTasks&);
174     OpItemTasks& operator=(const OpItemTasks&&);
175 
176     std::mutex mutex_;
177     std::vector<std::function<void()>> tasks_ = {};
178 };
179 
180 class OpItem : public MemObject, public Parcelable {
181 public:
OpItem(size_t size)182     explicit OpItem(size_t size) : MemObject(size) {}
~OpItem()183     virtual ~OpItem() {}
184 
Draw(RSPaintFilterCanvas & canvas,const SkRect * rect)185     virtual void Draw(RSPaintFilterCanvas& canvas, const SkRect* rect) const {};
186     virtual RSOpType GetType() const = 0;
187     virtual std::string GetTypeWithDesc() const = 0;
188 
189     virtual std::unique_ptr<OpItem> GenerateCachedOpItem(
190         const RSPaintFilterCanvas* canvas = nullptr, const SkRect* rect = nullptr) const
191     {
192         return nullptr;
193     }
GetCacheBounds()194     virtual std::optional<SkRect> GetCacheBounds() const
195     {
196         // not cacheable by default
197         return std::nullopt;
198     }
199 
Marshalling(Parcel & parcel)200     bool Marshalling(Parcel& parcel) const override
201     {
202         return true;
203     }
IsImageOp()204     virtual bool IsImageOp() const
205     {
206         return false;
207     }
SetNodeId(NodeId id)208     virtual void SetNodeId(NodeId id) {}
209 };
210 
211 class OpItemWithPaint : public OpItem {
212 public:
OpItemWithPaint(size_t size)213     explicit OpItemWithPaint(size_t size) : OpItem(size) {}
~OpItemWithPaint()214     ~OpItemWithPaint() override {}
215 
216     std::unique_ptr<OpItem> GenerateCachedOpItem(const RSPaintFilterCanvas* canvas, const SkRect* rect) const override;
217 
218 protected:
219     SkPaint paint_;
220 };
221 
222 class OpItemWithRSImage : public OpItemWithPaint {
223 public:
224 #ifdef NEW_SKIA
OpItemWithRSImage(std::shared_ptr<RSImageBase> rsImage,const SkSamplingOptions & samplingOptions,const SkPaint & paint,size_t size)225     OpItemWithRSImage(std::shared_ptr<RSImageBase> rsImage, const SkSamplingOptions& samplingOptions,
226         const SkPaint& paint, size_t size)
227         : OpItemWithPaint(size), rsImage_(rsImage), samplingOptions_(samplingOptions)
228     {
229         paint_ = paint;
230     }
OpItemWithRSImage(const SkSamplingOptions & samplingOptions,size_t size)231     explicit OpItemWithRSImage(const SkSamplingOptions& samplingOptions, size_t size)
232         : OpItemWithPaint(size), samplingOptions_(samplingOptions)
233     {}
234 #else
235     OpItemWithRSImage(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint, size_t size)
236         : OpItemWithPaint(size), rsImage_(rsImage)
237     {
238         paint_ = paint;
239     }
240     explicit OpItemWithRSImage(size_t size) : OpItemWithPaint(size) {}
241 #endif
~OpItemWithRSImage()242     ~OpItemWithRSImage() override {}
243     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
244     void SetNodeId(NodeId id) override;
IsImageOp()245     bool IsImageOp() const override
246     {
247         return true;
248     }
249 protected:
250     std::shared_ptr<RSImageBase> rsImage_;
251 #ifdef NEW_SKIA
252 private:
253     SkSamplingOptions samplingOptions_;
254 #endif
255 };
256 
257 class RectOpItem : public OpItemWithPaint {
258 public:
259     RectOpItem(SkRect rect, const SkPaint& paint);
~RectOpItem()260     ~RectOpItem() override {}
261     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
262 
GetTypeWithDesc()263     std::string GetTypeWithDesc() const override
264     {
265         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
266         int depth = 1;
267         rect_.dump(desc, depth);
268         desc += "}, \n";
269         return desc;
270     }
271 
GetType()272     RSOpType GetType() const override
273     {
274         return RSOpType::RECT_OPITEM;
275     }
276 
277     bool Marshalling(Parcel& parcel) const override;
278     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
279 
280 private:
281     SkRect rect_;
282 };
283 
284 class RoundRectOpItem : public OpItemWithPaint {
285 public:
286     RoundRectOpItem(const SkRRect& rrect, const SkPaint& paint);
~RoundRectOpItem()287     ~RoundRectOpItem() override {}
288     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
289 
GetTypeWithDesc()290     std::string GetTypeWithDesc() const override
291     {
292         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
293         int depth = 1;
294         rrect_.dump(desc, depth);
295         desc += "}, \n";
296         return desc;
297     }
298 
GetType()299     RSOpType GetType() const override
300     {
301         return RSOpType::ROUND_RECT_OPITEM;
302     }
303 
304     bool Marshalling(Parcel& parcel) const override;
305     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
306 
307 private:
308     SkRRect rrect_;
309 };
310 
311 class ImageWithParmOpItem : public OpItemWithPaint {
312 public:
313 #ifdef NEW_SKIA
314     ImageWithParmOpItem(
315         const sk_sp<SkImage> img, const sk_sp<SkData> data, const RsImageInfo& rsimageInfo,
316         const SkSamplingOptions& samplingOptions, const SkPaint& paint);
317     ImageWithParmOpItem(
318         const std::shared_ptr<Media::PixelMap>& pixelmap, const RsImageInfo& rsimageInfo,
319         const SkSamplingOptions& samplingOptions, const SkPaint& paint);
320     ImageWithParmOpItem(const std::shared_ptr<RSImage>& rsImage,
321         const SkSamplingOptions& samplingOptions, const SkPaint& paint);
322 #else
323     ImageWithParmOpItem(
324         const sk_sp<SkImage> img, const sk_sp<SkData> data, const RsImageInfo& rsimageInfo, const SkPaint& paint);
325     ImageWithParmOpItem(
326         const std::shared_ptr<Media::PixelMap>& pixelmap, const RsImageInfo& rsimageInfo, const SkPaint& paint);
327     ImageWithParmOpItem(const std::shared_ptr<RSImage>& rsImage, const SkPaint& paint);
328 #endif
329     ~ImageWithParmOpItem() override;
330     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
331 
GetTypeWithDesc()332     std::string GetTypeWithDesc() const override
333     {
334         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
335         if (rsImage_ == nullptr) {
336             desc += "\trsImage_ == nullptr";
337         } else {
338             int depth = 1;
339             rsImage_->dump(desc, depth);
340         }
341         desc += "}, \n";
342         return desc;
343     }
344 
GetType()345     RSOpType GetType() const override
346     {
347         return RSOpType::IMAGE_WITH_PARM_OPITEM;
348     }
IsImageOp()349     bool IsImageOp() const override
350     {
351         return true;
352     }
353     void SetNodeId(NodeId id) override;
354 
355     bool Marshalling(Parcel& parcel) const override;
356     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
357 #if defined(ROSEN_OHOS) && defined(RS_ENABLE_GL)
358 #ifndef USE_ROSEN_DRAWING
359     sk_sp<SkImage> GetSkImageFromSurfaceBuffer(SkCanvas& canvas, SurfaceBuffer* surfaceBuffer) const;
360 #endif
361 #endif
362 private:
363     std::shared_ptr<RSImage> rsImage_;
364 #if defined(ROSEN_OHOS) && defined(RS_ENABLE_GL)
365 #ifndef USE_ROSEN_DRAWING
366     mutable EGLImageKHR eglImage_ = EGL_NO_IMAGE_KHR;
367     mutable GLuint texId_ = 0;
368     mutable OHNativeWindowBuffer* nativeWindowBuffer_ = nullptr;
369 #endif
370 #endif
371 #ifdef NEW_SKIA
372     SkSamplingOptions samplingOptions_;
373 #endif
374 };
375 
376 class DRRectOpItem : public OpItemWithPaint {
377 public:
378     DRRectOpItem(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint);
~DRRectOpItem()379     ~DRRectOpItem() override {}
380     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
381 
GetTypeWithDesc()382     std::string GetTypeWithDesc() const override
383     {
384         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
385         int depth = 1;
386         desc += "outer_";
387         outer_.dump(desc, depth);
388         desc += "\ninner_";
389         inner_.dump(desc, depth);
390         desc += "}, \n";
391         return desc;
392     }
393 
GetType()394     RSOpType GetType() const override
395     {
396         return RSOpType::DRRECT_OPITEM;
397     }
398 
399     bool Marshalling(Parcel& parcel) const override;
400     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
401 
402 private:
403     SkRRect outer_;
404     SkRRect inner_;
405 };
406 
407 class OvalOpItem : public OpItemWithPaint {
408 public:
409     OvalOpItem(SkRect rect, const SkPaint& paint);
~OvalOpItem()410     ~OvalOpItem() override {}
411     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
412 
GetTypeWithDesc()413     std::string GetTypeWithDesc() const override
414     {
415         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
416         int depth = 1;
417         rect_.dump(desc, depth);
418         desc += "}, \n";
419         return desc;
420     }
421 
GetType()422     RSOpType GetType() const override
423     {
424         return RSOpType::OVAL_OPITEM;
425     }
426 
427     bool Marshalling(Parcel& parcel) const override;
428     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
429 
430 private:
431     SkRect rect_;
432 };
433 
434 class RegionOpItem : public OpItemWithPaint {
435 public:
436     RegionOpItem(SkRegion region, const SkPaint& paint);
~RegionOpItem()437     ~RegionOpItem() override {}
438     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
439 
GetTypeWithDesc()440     std::string GetTypeWithDesc() const override
441     {
442         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
443         int depth = 1;
444         region_.dump(desc, depth);
445         desc += "}, \n";
446         return desc;
447     }
448 
GetType()449     RSOpType GetType() const override
450     {
451         return RSOpType::REGION_OPITEM;
452     }
453 
454     bool Marshalling(Parcel& parcel) const override;
455     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
456 
457 private:
458     SkRegion region_;
459 };
460 
461 class ArcOpItem : public OpItemWithPaint {
462 public:
463     ArcOpItem(const SkRect& rect, float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint);
~ArcOpItem()464     ~ArcOpItem() override {}
465     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
466 
GetTypeWithDesc()467     std::string GetTypeWithDesc() const override
468     {
469         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
470         int depth = 1;
471         rect_.dump(desc, depth);
472         desc += "\tstartAngle_: " + std::to_string(startAngle_) + "\n";
473         desc += "\tsweepAngle_: " + std::to_string(sweepAngle_) + "\n";
474         desc += "\tuseCenter_: " + std::to_string(useCenter_) + "\n";
475         desc += "}, \n";
476         return desc;
477     }
478 
GetType()479     RSOpType GetType() const override
480     {
481         return RSOpType::ARC_OPITEM;
482     }
483 
484     bool Marshalling(Parcel& parcel) const override;
485     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
486 
487 private:
488     SkRect rect_;
489     float startAngle_;
490     float sweepAngle_;
491     bool useCenter_;
492 };
493 
494 class SaveOpItem : public OpItem {
495 public:
496     SaveOpItem();
~SaveOpItem()497     ~SaveOpItem() override {}
498     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
499 
GetTypeWithDesc()500     std::string GetTypeWithDesc() const override
501     {
502         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
503         desc += "}, \n";
504         return desc;
505     }
506 
GetType()507     RSOpType GetType() const override
508     {
509         return RSOpType::SAVE_OPITEM;
510     }
511 
512     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
513 };
514 
515 class RestoreOpItem : public OpItem {
516 public:
517     RestoreOpItem();
~RestoreOpItem()518     ~RestoreOpItem() override {}
519     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
520 
GetTypeWithDesc()521     std::string GetTypeWithDesc() const override
522     {
523         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
524         desc += "}, \n";
525         return desc;
526     }
527 
GetType()528     RSOpType GetType() const override
529     {
530         return RSOpType::RESTORE_OPITEM;
531     }
532 
533     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
534 };
535 
536 class FlushOpItem : public OpItem {
537 public:
538     FlushOpItem();
~FlushOpItem()539     ~FlushOpItem() override {}
540     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
541 
GetTypeWithDesc()542     std::string GetTypeWithDesc() const override
543     {
544         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
545         desc += "}, \n";
546         return desc;
547     }
548 
GetType()549     RSOpType GetType() const override
550     {
551         return RSOpType::FLUSH_OPITEM;
552     }
553 
554     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
555 };
556 
557 class MatrixOpItem : public OpItem {
558 public:
559 #ifdef NEW_SKIA
560     MatrixOpItem(const SkM44& matrix);
561 #else
562     MatrixOpItem(const SkMatrix& matrix);
563 #endif
~MatrixOpItem()564     ~MatrixOpItem() override {}
565     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
566 
GetTypeWithDesc()567     std::string GetTypeWithDesc() const override
568     {
569         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
570 #ifndef NEW_SKIA
571         int depth = 1;
572         matrix_.dump(desc, depth);
573 #endif
574         desc += "}, \n";
575         return desc;
576     }
577 
GetType()578     RSOpType GetType() const override
579     {
580         return RSOpType::MATRIX_OPITEM;
581     }
582 
583     bool Marshalling(Parcel& parcel) const override;
584     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
585 
586 private:
587 #ifdef NEW_SKIA
588     SkM44 matrix_;
589 #else
590     SkMatrix matrix_;
591 #endif
592 };
593 
594 class ClipRectOpItem : public OpItem {
595 public:
596     ClipRectOpItem(const SkRect& rect, SkClipOp op, bool doAA);
~ClipRectOpItem()597     ~ClipRectOpItem() override {}
598     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
599 
GetTypeWithDesc()600     std::string GetTypeWithDesc() const override
601     {
602         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
603         int depth = 1;
604         rect_.dump(desc, depth);
605         desc += "\tclipOp_: " + std::to_string(static_cast<int>(clipOp_)) + "\n";
606         desc += "\tdoAA_: " + std::to_string(doAA_) + "\n";
607         desc += "}, \n";
608         return desc;
609     }
610 
GetType()611     RSOpType GetType() const override
612     {
613         return RSOpType::CLIP_RECT_OPITEM;
614     }
615 
616     bool Marshalling(Parcel& parcel) const override;
617     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
618 
619     // functions that are dedicated to driven render [start]
GetClipRect()620     std::optional<SkRect> GetClipRect() const
621     {
622         return rect_;
623     }
624     // functions that are dedicated to driven render [end]
625 
626 private:
627     SkRect rect_;
628     SkClipOp clipOp_;
629     bool doAA_;
630 };
631 
632 class ClipRRectOpItem : public OpItem {
633 public:
634     ClipRRectOpItem(const SkRRect& rrect, SkClipOp op, bool doAA);
~ClipRRectOpItem()635     ~ClipRRectOpItem() override {}
636     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
637 
GetTypeWithDesc()638     std::string GetTypeWithDesc() const override
639     {
640         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
641         int depth = 1;
642         rrect_.dump(desc, depth);
643         desc += "\tclipOp_: " + std::to_string(static_cast<int>(clipOp_)) + "\n";
644         desc += "\tdoAA_: " + std::to_string(doAA_) + "\n";
645         desc += "}, \n";
646         return desc;
647     }
648 
GetType()649     RSOpType GetType() const override
650     {
651         return RSOpType::CLIP_RRECT_OPITEM;
652     }
653 
654     bool Marshalling(Parcel& parcel) const override;
655     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
656 
657 private:
658     SkRRect rrect_;
659     SkClipOp clipOp_;
660     bool doAA_;
661 };
662 
663 class ClipRegionOpItem : public OpItem {
664 public:
665     ClipRegionOpItem(const SkRegion& region, SkClipOp op);
~ClipRegionOpItem()666     ~ClipRegionOpItem() override {}
667     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
668 
GetTypeWithDesc()669     std::string GetTypeWithDesc() const override
670     {
671         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
672         int depth = 1;
673         region_.dump(desc, depth);
674         desc += "\tclipOp_: " + std::to_string(static_cast<int>(clipOp_)) + "\n";
675         desc += "}, \n";
676         return desc;
677     }
678 
GetType()679     RSOpType GetType() const override
680     {
681         return RSOpType::CLIP_REGION_OPITEM;
682     }
683 
684     bool Marshalling(Parcel& parcel) const override;
685     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
686 
687 private:
688     SkRegion region_;
689     SkClipOp clipOp_;
690 };
691 
692 class TranslateOpItem : public OpItem {
693 public:
694     TranslateOpItem(float distanceX, float distanceY);
~TranslateOpItem()695     ~TranslateOpItem() override {}
696     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
697 
GetTypeWithDesc()698     std::string GetTypeWithDesc() const override
699     {
700         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
701         desc += "\tdistanceX_: " + std::to_string(distanceX_) + "\n";
702         desc += "\tdistanceY_: " + std::to_string(distanceY_) + "\n";
703         desc += "}, \n";
704         return desc;
705     }
706 
GetType()707     RSOpType GetType() const override
708     {
709         return RSOpType::TRANSLATE_OPITEM;
710     }
711 
712     bool Marshalling(Parcel& parcel) const override;
713     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
714 
715 private:
716     float distanceX_;
717     float distanceY_;
718 };
719 
720 class ScaleOpItem : public OpItem {
721 public:
722     ScaleOpItem(float scaleX, float scaleY);
~ScaleOpItem()723     ~ScaleOpItem() override {}
724     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
725 
GetTypeWithDesc()726     std::string GetTypeWithDesc() const override
727     {
728         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
729         desc += "\tscaleX_: " + std::to_string(scaleX_) + "\n";
730         desc += "\tscaleY_: " + std::to_string(scaleY_) + "\n";
731         desc += "}, \n";
732         return desc;
733     }
734 
GetType()735     RSOpType GetType() const override
736     {
737         return RSOpType::SCALE_OPITEM;
738     }
739 
740     bool Marshalling(Parcel& parcel) const override;
741     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
742 
743 private:
744     float scaleX_ = 1.0f;
745     float scaleY_ = 1.0f;
746 };
747 
748 class TextBlobOpItem : public OpItemWithPaint {
749 public:
750     TextBlobOpItem(const sk_sp<SkTextBlob> textBlob, float x, float y, const SkPaint& paint);
~TextBlobOpItem()751     ~TextBlobOpItem() override {}
752     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
GetCacheBounds()753     std::optional<SkRect> GetCacheBounds() const override
754     {
755         // bounds of textBlob_, with additional offset [x_, y_]. textBlob_ should never be null but we should check.
756         return textBlob_ ? std::make_optional<SkRect>(textBlob_->bounds().makeOffset(x_, y_)) : std::nullopt;
757     }
758 
GetTypeWithDesc()759     std::string GetTypeWithDesc() const override
760     {
761         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
762         int depth = 1;
763         if (textBlob_ == nullptr) {
764             desc += "\ttextBlob_ = nullptr\n";
765         } else {
766             textBlob_->dump(desc, depth);
767         }
768         desc += "\tx_: " + std::to_string(x_) + "\n";
769         desc += "\ty_: " + std::to_string(y_) + "\n";
770         desc += "}, \n";
771         return desc;
772     }
773 
GetType()774     RSOpType GetType() const override
775     {
776         return RSOpType::TEXTBLOB_OPITEM;
777     }
778     bool Marshalling(Parcel& parcel) const override;
779     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
780 
781 private:
782     sk_sp<SkTextBlob> textBlob_;
783     float x_;
784     float y_;
785 };
786 
787 class BitmapOpItem : public OpItemWithRSImage {
788 public:
789 #ifdef NEW_SKIA
790     BitmapOpItem(const sk_sp<SkImage> bitmapInfo, float left, float top,
791         const SkSamplingOptions& samplingOptions, const SkPaint* paint);
792     BitmapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkSamplingOptions& samplingOptions, const SkPaint& paint);
793 #else
794     BitmapOpItem(const sk_sp<SkImage> bitmapInfo, float left, float top, const SkPaint* paint);
795     BitmapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint);
796 #endif
~BitmapOpItem()797     ~BitmapOpItem() override {}
798 
GetTypeWithDesc()799     std::string GetTypeWithDesc() const override
800     {
801         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
802         desc += "}, \n";
803         return desc;
804     }
805 
GetType()806     RSOpType GetType() const override
807     {
808         return RSOpType::BITMAP_OPITEM;
809     }
810 
811     bool Marshalling(Parcel& parcel) const override;
812     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
813 
814 #ifdef NEW_SKIA
815 private:
816     SkSamplingOptions samplingOptions_;
817 #endif
818 };
819 
820 class ColorFilterBitmapOpItem : public BitmapOpItem {
821 public:
822 #ifdef NEW_SKIA
823     ColorFilterBitmapOpItem(const sk_sp<SkImage> bitmapInfo, float left, float top,
824         const SkSamplingOptions& samplingOptions, const SkPaint* paint);
825     ColorFilterBitmapOpItem(std::shared_ptr<RSImageBase> rsImage,
826         const SkSamplingOptions& samplingOptions, const SkPaint& paint);
827 #else
828     ColorFilterBitmapOpItem(const sk_sp<SkImage> bitmapInfo, float left, float top, const SkPaint* paint);
829     ColorFilterBitmapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint);
830 #endif
~ColorFilterBitmapOpItem()831     ~ColorFilterBitmapOpItem() override {}
832 
GetTypeWithDesc()833     std::string GetTypeWithDesc() const override
834     {
835         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
836         desc += "}, \n";
837         return desc;
838     }
839 
GetType()840     RSOpType GetType() const override
841     {
842         return RSOpType::COLOR_FILTER_BITMAP_OPITEM;
843     }
844 
845     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
846 
847     bool Marshalling(Parcel& parcel) const override;
848     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
849 };
850 
851 class BitmapRectOpItem : public OpItemWithRSImage {
852 public:
853 #ifdef NEW_SKIA
854     BitmapRectOpItem(const sk_sp<SkImage> bitmapInfo, const SkRect* rectSrc, const SkRect& rectDst,
855         const SkSamplingOptions& samplingOptions, const SkPaint* paint, SkCanvas::SrcRectConstraint constraint);
856     BitmapRectOpItem(std::shared_ptr<RSImageBase> rsImage, const SkSamplingOptions& samplingOptions,
857         const SkPaint& paint, SkCanvas::SrcRectConstraint constraint);
858 #else
859     BitmapRectOpItem(
860         const sk_sp<SkImage> bitmapInfo, const SkRect* rectSrc, const SkRect& rectDst, const SkPaint* paint);
861     BitmapRectOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint);
862 #endif
~BitmapRectOpItem()863     ~BitmapRectOpItem() override {}
864 
GetTypeWithDesc()865     std::string GetTypeWithDesc() const override
866     {
867         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
868         desc += "}, \n";
869         return desc;
870     }
871 
GetType()872     RSOpType GetType() const override
873     {
874         return RSOpType::BITMAP_RECT_OPITEM;
875     }
876 
877     bool Marshalling(Parcel& parcel) const override;
878     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
879 
880 #ifdef NEW_SKIA
881 private:
882     SkSamplingOptions samplingOptions_;
883     SkCanvas::SrcRectConstraint constraint_;
884 #endif
885 };
886 
887 class PixelMapOpItem : public OpItemWithRSImage {
888 public:
889 #ifdef NEW_SKIA
890     PixelMapOpItem(const std::shared_ptr<Media::PixelMap>& pixelmap, float left, float top,
891         const SkSamplingOptions& samplingOptions, const SkPaint* paint);
892     PixelMapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkSamplingOptions& samplingOptions,
893         const SkPaint& paint);
894 #else
895     PixelMapOpItem(const std::shared_ptr<Media::PixelMap>& pixelmap, float left, float top, const SkPaint* paint);
896     PixelMapOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint);
897 #endif
~PixelMapOpItem()898     ~PixelMapOpItem() override {}
899 
GetTypeWithDesc()900     std::string GetTypeWithDesc() const override
901     {
902         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
903         desc += "}, \n";
904         return desc;
905     }
906 
GetType()907     RSOpType GetType() const override
908     {
909         return RSOpType::PIXELMAP_OPITEM;
910     }
911 
912     bool Marshalling(Parcel& parcel) const override;
913     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
914 
915 #ifdef NEW_SKIA
916 private:
917     SkSamplingOptions samplingOptions_;
918 #endif
919 };
920 
921 class PixelMapRectOpItem : public OpItemWithRSImage {
922 public:
923 #ifdef NEW_SKIA
924     PixelMapRectOpItem(
925         const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& src, const SkRect& dst,
926         const SkSamplingOptions& samplingOptions, const SkPaint* paint, SkCanvas::SrcRectConstraint constraint);
927     PixelMapRectOpItem(std::shared_ptr<RSImageBase> rsImage,  const SkSamplingOptions& samplingOptions,
928     const SkPaint& paint, SkCanvas::SrcRectConstraint constraint);
929 #else
930     PixelMapRectOpItem(
931         const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& src, const SkRect& dst, const SkPaint* paint);
932     PixelMapRectOpItem(std::shared_ptr<RSImageBase> rsImage, const SkPaint& paint);
933 #endif
~PixelMapRectOpItem()934     ~PixelMapRectOpItem() override {}
935 
GetTypeWithDesc()936     std::string GetTypeWithDesc() const override
937     {
938         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
939         desc += "}, \n";
940         return desc;
941     }
942 
GetType()943     RSOpType GetType() const override
944     {
945         return RSOpType::PIXELMAP_RECT_OPITEM;
946     }
947 
948     bool Marshalling(Parcel& parcel) const override;
949     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
950 
951 #ifdef NEW_SKIA
952 private:
953     SkSamplingOptions samplingOptions_;
954     SkCanvas::SrcRectConstraint constraint_;
955 #endif
956 };
957 
958 class BitmapNineOpItem : public OpItemWithPaint {
959 public:
960 #ifdef NEW_SKIA
961     BitmapNineOpItem(const sk_sp<SkImage> bitmapInfo, const SkIRect& center, const SkRect& rectDst,
962         SkFilterMode filter, const SkPaint* paint);
963 #else
964     BitmapNineOpItem(
965         const sk_sp<SkImage> bitmapInfo, const SkIRect& center, const SkRect& rectDst, const SkPaint* paint);
966 #endif
~BitmapNineOpItem()967     ~BitmapNineOpItem() override {}
968     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
969 
GetTypeWithDesc()970     std::string GetTypeWithDesc() const override
971     {
972         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
973         int depth = 1;
974         center_.dump(desc, depth);
975         rectDst_.dump(desc, depth);
976         if (bitmapInfo_ == nullptr) {
977             desc += "\tbitmapInfo_ = nullptr\n";
978         } else {
979             int depth = 1;
980             bitmapInfo_->dump(desc, depth);
981         }
982         desc += "}, \n";
983         return desc;
984     }
985 
GetType()986     RSOpType GetType() const override
987     {
988         return RSOpType::BITMAP_NINE_OPITEM;
989     }
990 
991     bool Marshalling(Parcel& parcel) const override;
992     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
993 
994 private:
995     SkIRect center_;
996     SkRect rectDst_;
997     sk_sp<SkImage> bitmapInfo_;
998 #ifdef NEW_SKIA
999     SkFilterMode filter_;
1000 #endif
1001 };
1002 
1003 class AdaptiveRRectOpItem : public OpItemWithPaint {
1004 public:
1005     AdaptiveRRectOpItem(float radius, const SkPaint& paint);
~AdaptiveRRectOpItem()1006     ~AdaptiveRRectOpItem() override {}
1007     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1008 
GetTypeWithDesc()1009     std::string GetTypeWithDesc() const override
1010     {
1011         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1012         desc += "\tradius_: " + std::to_string(radius_);
1013         desc += "\tpaint_: Omit";
1014         desc += "}, \n";
1015         return desc;
1016     }
1017 
GetType()1018     RSOpType GetType() const override
1019     {
1020         return RSOpType::ADAPTIVE_RRECT_OPITEM;
1021     }
1022 
1023     bool Marshalling(Parcel& parcel) const override;
1024     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1025 
1026 private:
1027     float radius_;
1028     SkPaint paint_;
1029 };
1030 
1031 class AdaptiveRRectScaleOpItem : public OpItemWithPaint {
1032 public:
1033     AdaptiveRRectScaleOpItem(float radiusRatio, const SkPaint& paint);
~AdaptiveRRectScaleOpItem()1034     ~AdaptiveRRectScaleOpItem() override {}
1035     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1036 
GetTypeWithDesc()1037     std::string GetTypeWithDesc() const override
1038     {
1039         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1040         desc += "\tradiusRatio_: " + std::to_string(radiusRatio_) + "\n";
1041         desc += "\tpaint_: Omit\n";
1042         desc += "}, \n";
1043         return desc;
1044     }
1045 
GetType()1046     RSOpType GetType() const override
1047     {
1048         return RSOpType::ADAPTIVE_RRECT_SCALE_OPITEM;
1049     }
1050 
1051     bool Marshalling(Parcel& parcel) const override;
1052     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1053 
1054 private:
1055     float radiusRatio_;
1056     SkPaint paint_;
1057 };
1058 
1059 class ClipAdaptiveRRectOpItem : public OpItem {
1060 public:
1061     ClipAdaptiveRRectOpItem(const SkVector radius[]);
~ClipAdaptiveRRectOpItem()1062     ~ClipAdaptiveRRectOpItem() override {}
1063     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1064 
GetTypeWithDesc()1065     std::string GetTypeWithDesc() const override
1066     {
1067         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1068         desc += "\tradius_:{";
1069         int radiusSize = 4;
1070         for (int i = 0; i < radiusSize; i++) {
1071             int depth = 2;
1072             radius_[i].dump(desc, depth);
1073         }
1074         desc += "}}, \n";
1075         return desc;
1076     }
1077 
GetType()1078     RSOpType GetType() const override
1079     {
1080         return RSOpType::CLIP_ADAPTIVE_RRECT_OPITEM;
1081     }
1082 
1083     bool Marshalling(Parcel& parcel) const override;
1084     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1085 
1086 private:
1087     SkVector radius_[4];
1088 };
1089 
1090 class ClipOutsetRectOpItem : public OpItem {
1091 public:
1092     ClipOutsetRectOpItem(float dx, float dy);
~ClipOutsetRectOpItem()1093     ~ClipOutsetRectOpItem() override {}
1094     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1095 
GetTypeWithDesc()1096     std::string GetTypeWithDesc() const override
1097     {
1098         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1099         desc += "\tdx_: " + std::to_string(dx_) + "\n";
1100         desc += "\tdy_: " + std::to_string(dy_) + "\n";
1101         desc += "}, \n";
1102         return desc;
1103     }
1104 
GetType()1105     RSOpType GetType() const override
1106     {
1107         return RSOpType::CLIP_OUTSET_RECT_OPITEM;
1108     }
1109 
1110     bool Marshalling(Parcel& parcel) const override;
1111     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1112 
1113 private:
1114     float dx_;
1115     float dy_;
1116 };
1117 
1118 class PathOpItem : public OpItemWithPaint {
1119 public:
1120     PathOpItem(const SkPath& path, const SkPaint& paint);
~PathOpItem()1121     ~PathOpItem() override {}
1122     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1123 
GetTypeWithDesc()1124     std::string GetTypeWithDesc() const override
1125     {
1126         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1127         int depth = 1;
1128         path_.dump(desc, depth);
1129         desc += "}, \n";
1130         return desc;
1131     }
1132 
GetType()1133     RSOpType GetType() const override
1134     {
1135         return RSOpType::PATH_OPITEM;
1136     }
1137 
1138     bool Marshalling(Parcel& parcel) const override;
1139     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1140 
1141 private:
1142     SkPath path_;
1143 };
1144 
1145 class ClipPathOpItem : public OpItem {
1146 public:
1147     ClipPathOpItem(const SkPath& path, SkClipOp clipOp, bool doAA);
~ClipPathOpItem()1148     ~ClipPathOpItem() override {}
1149     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1150 
GetTypeWithDesc()1151     std::string GetTypeWithDesc() const override
1152     {
1153         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1154         int depth = 1;
1155         path_.dump(desc, depth);
1156         desc += "\tclipOp_: " + std::to_string(static_cast<int>(clipOp_)) + "\n";
1157         desc += "\tdoAA_: " + std::to_string(doAA_) + "\n";
1158         desc += "}, \n";
1159         return desc;
1160     }
1161 
GetType()1162     RSOpType GetType() const override
1163     {
1164         return RSOpType::CLIP_PATH_OPITEM;
1165     }
1166 
1167     bool Marshalling(Parcel& parcel) const override;
1168     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1169 
1170 private:
1171     SkPath path_;
1172     SkClipOp clipOp_;
1173     bool doAA_;
1174 };
1175 
1176 class PaintOpItem : public OpItemWithPaint {
1177 public:
1178     PaintOpItem(const SkPaint& paint);
~PaintOpItem()1179     ~PaintOpItem() override {}
1180     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1181 
GetTypeWithDesc()1182     std::string GetTypeWithDesc() const override
1183     {
1184         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1185         desc += "}, \n";
1186         return desc;
1187     }
1188 
GetType()1189     RSOpType GetType() const override
1190     {
1191         return RSOpType::PAINT_OPITEM;
1192     }
1193 
1194     bool Marshalling(Parcel& parcel) const override;
1195     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1196 };
1197 
1198 class ConcatOpItem : public OpItem {
1199 public:
1200 #ifdef NEW_SKIA
1201     ConcatOpItem(const SkM44& matrix);
1202 #else
1203     ConcatOpItem(const SkMatrix& matrix);
1204 #endif
~ConcatOpItem()1205     ~ConcatOpItem() override {}
1206     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1207 
GetTypeWithDesc()1208     std::string GetTypeWithDesc() const override
1209     {
1210         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1211 #ifndef NEW_SKIA
1212         int depth = 1;
1213         matrix_.dump(desc, depth);
1214 #endif
1215         desc += "}, \n";
1216         return desc;
1217     }
1218 
GetType()1219     RSOpType GetType() const override
1220     {
1221         return RSOpType::CONCAT_OPITEM;
1222     }
1223 
1224     bool Marshalling(Parcel& parcel) const override;
1225     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1226 
1227 private:
1228 #ifdef NEW_SKIA
1229     SkM44 matrix_;
1230 #else
1231     SkMatrix matrix_;
1232 #endif
1233 };
1234 
1235 class SaveLayerOpItem : public OpItemWithPaint {
1236 public:
1237     SaveLayerOpItem(const SkCanvas::SaveLayerRec& rec);
~SaveLayerOpItem()1238     ~SaveLayerOpItem() override {}
1239     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1240 
GetTypeWithDesc()1241     std::string GetTypeWithDesc() const override
1242     {
1243         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1244         int depth = 1;
1245         if (rectPtr_ == nullptr) {
1246             desc += "\trectPtr_ = nullptr\n";
1247         } else {
1248             rectPtr_->dump(desc, depth);
1249         }
1250         rect_.dump(desc, depth);
1251         desc += "\tbackdrop_:Omit\n";
1252 #ifndef NEW_SKIA
1253         if (mask_ == nullptr) {
1254             desc += "\tmask_ = nullptr\n";
1255         } else {
1256             mask_->dump(desc, depth);
1257         }
1258         matrix_.dump(desc, depth);
1259 #endif
1260         desc += "\tflags_:" + std::to_string(static_cast<int>(flags_)) + "\n";
1261         desc += "}, \n";
1262         return desc;
1263     }
1264 
GetType()1265     RSOpType GetType() const override
1266     {
1267         return RSOpType::SAVE_LAYER_OPITEM;
1268     }
1269 
1270     bool Marshalling(Parcel& parcel) const override;
1271     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1272 
1273 private:
1274     SkRect* rectPtr_ = nullptr;
1275     SkRect rect_ = SkRect::MakeEmpty();
1276     sk_sp<SkImageFilter> backdrop_;
1277     SkCanvas::SaveLayerFlags flags_;
1278 #ifndef NEW_SKIA
1279     sk_sp<SkImage> mask_;
1280     SkMatrix matrix_;
1281 #endif
1282 };
1283 
1284 class DrawableOpItem : public OpItem {
1285 public:
1286     DrawableOpItem(SkDrawable* drawable, const SkMatrix* matrix);
~DrawableOpItem()1287     ~DrawableOpItem() override {}
1288     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1289 
GetTypeWithDesc()1290     std::string GetTypeWithDesc() const override
1291     {
1292         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1293         int depth = 1;
1294         if (drawable_ == nullptr) {
1295             desc += "\tdrawable_ == nullptr\n";
1296         } else {
1297             desc += "\t drawable_:" + std::to_string(drawable_->getGenerationID()) + "\n";
1298         }
1299         matrix_.dump(desc, depth);
1300         desc += "}, \n";
1301         return desc;
1302     }
1303 
GetType()1304     RSOpType GetType() const override
1305     {
1306         return RSOpType::DRAWABLE_OPITEM;
1307     }
1308 
1309     bool Marshalling(Parcel& parcel) const override;
1310     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1311 
1312 private:
1313     sk_sp<SkDrawable> drawable_;
1314     SkMatrix matrix_ = SkMatrix::I();
1315 };
1316 
1317 class PictureOpItem : public OpItemWithPaint {
1318 public:
1319     PictureOpItem(const sk_sp<SkPicture> picture, const SkMatrix* matrix, const SkPaint* paint);
~PictureOpItem()1320     ~PictureOpItem() override {}
1321     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1322 
GetTypeWithDesc()1323     std::string GetTypeWithDesc() const override
1324     {
1325         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1326         int depth = 1;
1327         desc += "\tpicture_:Omit\n";
1328         matrix_.dump(desc, depth);
1329         desc += "}, \n";
1330         return desc;
1331     }
1332 
GetType()1333     RSOpType GetType() const override
1334     {
1335         return RSOpType::PICTURE_OPITEM;
1336     }
1337 
1338     bool Marshalling(Parcel& parcel) const override;
1339     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1340 
1341 private:
1342     sk_sp<SkPicture> picture_ { nullptr };
1343     SkMatrix matrix_;
1344 };
1345 
1346 class PointsOpItem : public OpItemWithPaint {
1347 public:
1348     PointsOpItem(SkCanvas::PointMode mode, int count, const SkPoint processedPoints[], const SkPaint& paint);
~PointsOpItem()1349     ~PointsOpItem() override
1350     {
1351         delete[] processedPoints_;
1352     }
1353     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1354 
GetTypeWithDesc()1355     std::string GetTypeWithDesc() const override
1356     {
1357         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1358         int depth = 1;
1359         desc += "\tmode_:" + std::to_string(static_cast<int>(mode_)) + "\n";
1360         desc += "\tcount_:" + std::to_string(count_) + "\n";
1361         if (processedPoints_ == nullptr) {
1362             desc += "\tprocessedPoints_ == nullptr";
1363         } else {
1364             processedPoints_->dump(desc, depth);
1365         }
1366         desc += "}, \n";
1367         return desc;
1368     }
1369 
GetType()1370     RSOpType GetType() const override
1371     {
1372         return RSOpType::POINTS_OPITEM;
1373     }
1374 
1375     bool Marshalling(Parcel& parcel) const override;
1376     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1377 
1378 private:
1379     SkCanvas::PointMode mode_;
1380     int count_;
1381     SkPoint* processedPoints_;
1382 };
1383 
1384 class VerticesOpItem : public OpItemWithPaint {
1385 public:
1386 #ifdef NEW_SKIA
1387     VerticesOpItem(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint);
1388 #else
1389     VerticesOpItem(const SkVertices* vertices, const SkVertices::Bone bones[],
1390         int boneCount, SkBlendMode mode, const SkPaint& paint);
1391 #endif
1392     ~VerticesOpItem() override;
1393     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1394 
GetTypeWithDesc()1395     std::string GetTypeWithDesc() const override
1396     {
1397         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1398         int depth = 1;
1399         if (vertices_ == nullptr) {
1400             desc += "\tvertices_ = nullptr\n";
1401         } else {
1402             vertices_->dump(desc, depth);
1403         }
1404 #ifndef NEW_SKIA
1405         if (bones_ == nullptr) {
1406             desc += "\tbones_ = nullptr\n";
1407         } else {
1408             bones_->dump(desc, depth);
1409         }
1410         desc += "\tboneCount_:" + std::to_string(boneCount_) + "\n";
1411 #endif
1412         desc += "\tmode_:" + std::to_string(static_cast<int>(mode_)) + "\n";
1413         desc += "}, \n";
1414         return desc;
1415     }
1416 
GetType()1417     RSOpType GetType() const override
1418     {
1419         return RSOpType::VERTICES_OPITEM;
1420     }
1421 
1422     bool Marshalling(Parcel& parcel) const override;
1423     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1424 
1425 private:
1426     sk_sp<SkVertices> vertices_;
1427 #ifndef NEW_SKIA
1428     SkVertices::Bone* bones_;
1429     int boneCount_;
1430 #endif
1431     SkBlendMode mode_;
1432 };
1433 
1434 class ShadowRecOpItem : public OpItem {
1435 public:
1436     ShadowRecOpItem(const SkPath& path, const SkDrawShadowRec& rec);
~ShadowRecOpItem()1437     ~ShadowRecOpItem() override {}
1438     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1439 
GetTypeWithDesc()1440     std::string GetTypeWithDesc() const override
1441     {
1442         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1443         int depth = 1;
1444         path_.dump(desc, depth);
1445         rec_.dump(desc, depth);
1446         desc += "}, \n";
1447         return desc;
1448     }
1449 
GetType()1450     RSOpType GetType() const override
1451     {
1452         return RSOpType::SHADOW_REC_OPITEM;
1453     }
1454 
1455     bool Marshalling(Parcel& parcel) const override;
1456     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1457 
1458 private:
1459     SkPath path_;
1460     SkDrawShadowRec rec_;
1461 };
1462 
1463 class MultiplyAlphaOpItem : public OpItem {
1464 public:
1465     MultiplyAlphaOpItem(float alpha);
~MultiplyAlphaOpItem()1466     ~MultiplyAlphaOpItem() override {}
1467     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1468 
GetTypeWithDesc()1469     std::string GetTypeWithDesc() const override
1470     {
1471         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1472         desc += "alpha_:" + std::to_string(alpha_);
1473         desc += "}, \n";
1474         return desc;
1475     }
1476 
GetType()1477     RSOpType GetType() const override
1478     {
1479         return RSOpType::MULTIPLY_ALPHA_OPITEM;
1480     }
1481 
1482     bool Marshalling(Parcel& parcel) const override;
1483     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1484 
1485 private:
1486     float alpha_;
1487 };
1488 
1489 class SaveAlphaOpItem : public OpItem {
1490 public:
1491     SaveAlphaOpItem();
~SaveAlphaOpItem()1492     ~SaveAlphaOpItem() override {}
1493     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1494 
GetTypeWithDesc()1495     std::string GetTypeWithDesc() const override
1496     {
1497         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1498         desc += "}, \n";
1499         return desc;
1500     }
1501 
GetType()1502     RSOpType GetType() const override
1503     {
1504         return RSOpType::SAVE_ALPHA_OPITEM;
1505     }
1506 
1507     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1508 };
1509 
1510 class RestoreAlphaOpItem : public OpItem {
1511 public:
1512     RestoreAlphaOpItem();
~RestoreAlphaOpItem()1513     ~RestoreAlphaOpItem() override {}
1514     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1515 
GetTypeWithDesc()1516     std::string GetTypeWithDesc() const override
1517     {
1518         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1519         desc += "}, \n";
1520         return desc;
1521     }
1522 
GetType()1523     RSOpType GetType() const override
1524     {
1525         return RSOpType::RESTORE_ALPHA_OPITEM;
1526     }
1527 
1528     [[nodiscard]] static OpItem* Unmarshalling(Parcel& parcel);
1529 };
1530 
1531 #ifdef ROSEN_OHOS
1532 class SurfaceBufferOpItem : public OpItemWithPaint {
1533 public:
1534     SurfaceBufferOpItem(const RSSurfaceBufferInfo& surfaceBufferInfo);
1535     ~SurfaceBufferOpItem() override;
1536     void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override;
1537 
GetTypeWithDesc()1538     std::string GetTypeWithDesc() const override
1539     {
1540         std::string desc = "{OpType: " + GetOpTypeString(GetType()) +", Description:{";
1541         desc += "}, \n";
1542         return desc;
1543     }
1544 
GetType()1545     RSOpType GetType() const override
1546     {
1547         return RSOpType::SURFACEBUFFER_OPITEM;
1548     }
1549 
1550     bool Marshalling(Parcel& parcel) const override;
1551     static OpItem* Unmarshalling(Parcel& parcel);
1552 
1553 private:
1554     mutable RSSurfaceBufferInfo surfaceBufferInfo_;
1555 #ifdef RS_ENABLE_GL
1556     mutable EGLImageKHR eglImage_ = EGL_NO_IMAGE_KHR;
1557     mutable GLuint texId_ = 0;
1558     mutable OHNativeWindowBuffer* nativeWindowBuffer_ = nullptr;
1559 #endif
1560 };
1561 #endif
1562 } // namespace Rosen
1563 } // namespace OHOS
1564 
1565 #endif // USE_ROSEN_DRAWING
1566 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_H
1567