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 #include "core/SkDrawShadowInfo.h" 20 #include "include/core/SkCanvas.h" 21 #include "include/core/SkDrawable.h" 22 #include "include/core/SkImage.h" 23 #include "include/core/SkImageFilter.h" 24 #include "include/core/SkPaint.h" 25 #include "include/core/SkPath.h" 26 #include "include/core/SkPicture.h" 27 #include "include/core/SkRRect.h" 28 #include "include/core/SkRect.h" 29 #include "include/core/SkRegion.h" 30 #include "include/core/SkTextBlob.h" 31 #include "pixel_map.h" 32 33 #include "common/rs_common_def.h" 34 #include "pipeline/rs_draw_cmd_list.h" 35 #include "property/rs_properties_def.h" 36 #include "render/rs_image.h" 37 #include "transaction/rs_marshalling_helper.h" 38 39 namespace OHOS { 40 namespace Rosen { 41 class RSPaintFilterCanvas; 42 43 enum RSOpType : uint16_t { 44 OPITEM, 45 OPITEM_WITH_PAINT, 46 RECT_OPITEM, 47 ROUND_RECT_OPITEM, 48 IMAGE_WITH_PARM_OPITEM, 49 DRRECT_OPITEM, 50 OVAL_OPITEM, 51 REGION_OPITEM, 52 ARC_OPITEM, 53 SAVE_OPITEM, 54 RESTORE_OPITEM, 55 FLUSH_OPITEM, 56 MATRIX_OPITEM, 57 CLIP_RECT_OPITEM, 58 CLIP_RRECT_OPITEM, 59 CLIP_REGION_OPITEM, 60 TRANSLATE_OPITEM, 61 TEXTBLOB_OPITEM, 62 BITMAP_OPITEM, 63 BITMAP_RECT_OPITEM, 64 BITMAP_NINE_OPITEM, 65 PIXELMAP_OPITEM, 66 PIXELMAP_RECT_OPITEM, 67 ADAPTIVE_RRECT_OPITEM, 68 ADAPTIVE_RRECT_SCALE_OPITEM, 69 CLIP_ADAPTIVE_RRECT_OPITEM, 70 CLIP_OUTSET_RECT_OPITEM, 71 PATH_OPITEM, 72 CLIP_PATH_OPITEM, 73 PAINT_OPITEM, 74 CONCAT_OPITEM, 75 SAVE_LAYER_OPITEM, 76 DRAWABLE_OPITEM, 77 PICTURE_OPITEM, 78 POINTS_OPITEM, 79 VERTICES_OPITEM, 80 SHADOW_REC_OPITEM, 81 MULTIPLY_ALPHA_OPITEM, 82 SAVE_ALPHA_OPITEM, 83 RESTORE_ALPHA_OPITEM, 84 }; 85 86 class OpItem : public MemObject, public Parcelable { 87 public: OpItem(size_t size)88 explicit OpItem(size_t size) : MemObject(size) {} ~OpItem()89 virtual ~OpItem() {} 90 Draw(RSPaintFilterCanvas & canvas,const SkRect * rect)91 virtual void Draw(RSPaintFilterCanvas& canvas, const SkRect* rect) const {}; 92 virtual RSOpType GetType() const = 0; 93 94 std::unique_ptr<OpItem> GenerateCachedOpItem(SkSurface* surface) const; GetCacheBounds()95 virtual std::optional<SkRect> GetCacheBounds() const 96 { 97 // not cacheable by default 98 return std::nullopt; 99 } 100 Marshalling(Parcel & parcel)101 bool Marshalling(Parcel& parcel) const override 102 { 103 return true; 104 } 105 }; 106 107 class OpItemWithPaint : public OpItem { 108 public: OpItemWithPaint(size_t size)109 explicit OpItemWithPaint(size_t size) : OpItem(size) {} ~OpItemWithPaint()110 ~OpItemWithPaint() override {} 111 112 protected: 113 SkPaint paint_; 114 }; 115 116 class RectOpItem : public OpItemWithPaint { 117 public: 118 RectOpItem(SkRect rect, const SkPaint& paint); ~RectOpItem()119 ~RectOpItem() override {} 120 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 121 GetType()122 RSOpType GetType() const override 123 { 124 return RSOpType::RECT_OPITEM; 125 } 126 127 bool Marshalling(Parcel& parcel) const override; 128 static OpItem* Unmarshalling(Parcel& parcel); 129 130 private: 131 SkRect rect_; 132 }; 133 134 class RoundRectOpItem : public OpItemWithPaint { 135 public: 136 RoundRectOpItem(const SkRRect& rrect, const SkPaint& paint); ~RoundRectOpItem()137 ~RoundRectOpItem() override {} 138 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 139 GetType()140 RSOpType GetType() const override 141 { 142 return RSOpType::ROUND_RECT_OPITEM; 143 } 144 145 bool Marshalling(Parcel& parcel) const override; 146 static OpItem* Unmarshalling(Parcel& parcel); 147 148 private: 149 SkRRect rrect_; 150 }; 151 152 class ImageWithParmOpItem : public OpItemWithPaint { 153 public: 154 ImageWithParmOpItem( 155 const sk_sp<SkImage> img, const sk_sp<SkData> data, const RsImageInfo& rsimageInfo, const SkPaint& paint); 156 ImageWithParmOpItem( 157 const std::shared_ptr<Media::PixelMap>& pixelmap, const RsImageInfo& rsimageInfo, const SkPaint& paint); 158 ImageWithParmOpItem(const std::shared_ptr<RSImage>& rsImage, const SkPaint& paint); 159 ~ImageWithParmOpItem()160 ~ImageWithParmOpItem() override {} 161 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 162 GetType()163 RSOpType GetType() const override 164 { 165 return RSOpType::IMAGE_WITH_PARM_OPITEM; 166 } 167 168 bool Marshalling(Parcel& parcel) const override; 169 static OpItem* Unmarshalling(Parcel& parcel); 170 171 private: 172 std::shared_ptr<RSImage> rsImage_; 173 }; 174 175 class DRRectOpItem : public OpItemWithPaint { 176 public: 177 DRRectOpItem(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint); ~DRRectOpItem()178 ~DRRectOpItem() override {} 179 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 180 GetType()181 RSOpType GetType() const override 182 { 183 return RSOpType::DRRECT_OPITEM; 184 } 185 186 bool Marshalling(Parcel& parcel) const override; 187 static OpItem* Unmarshalling(Parcel& parcel); 188 189 private: 190 SkRRect outer_; 191 SkRRect inner_; 192 }; 193 194 class OvalOpItem : public OpItemWithPaint { 195 public: 196 OvalOpItem(SkRect rect, const SkPaint& paint); ~OvalOpItem()197 ~OvalOpItem() override {} 198 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; GetCacheBounds()199 std::optional<SkRect> GetCacheBounds() const override 200 { 201 return rect_; 202 } 203 GetType()204 RSOpType GetType() const override 205 { 206 return RSOpType::OVAL_OPITEM; 207 } 208 209 bool Marshalling(Parcel& parcel) const override; 210 static OpItem* Unmarshalling(Parcel& parcel); 211 212 private: 213 SkRect rect_; 214 }; 215 216 class RegionOpItem : public OpItemWithPaint { 217 public: 218 RegionOpItem(SkRegion region, const SkPaint& paint); ~RegionOpItem()219 ~RegionOpItem() override {} 220 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 221 GetType()222 RSOpType GetType() const override 223 { 224 return RSOpType::REGION_OPITEM; 225 } 226 227 bool Marshalling(Parcel& parcel) const override; 228 static OpItem* Unmarshalling(Parcel& parcel); 229 230 private: 231 SkRegion region_; 232 }; 233 234 class ArcOpItem : public OpItemWithPaint { 235 public: 236 ArcOpItem(const SkRect& rect, float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint); ~ArcOpItem()237 ~ArcOpItem() override {} 238 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 239 GetType()240 RSOpType GetType() const override 241 { 242 return RSOpType::ARC_OPITEM; 243 } 244 245 bool Marshalling(Parcel& parcel) const override; 246 static OpItem* Unmarshalling(Parcel& parcel); 247 248 private: 249 SkRect rect_; 250 float startAngle_; 251 float sweepAngle_; 252 bool useCenter_; 253 }; 254 255 class SaveOpItem : public OpItem { 256 public: 257 SaveOpItem(); ~SaveOpItem()258 ~SaveOpItem() override {} 259 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 260 GetType()261 RSOpType GetType() const override 262 { 263 return RSOpType::SAVE_OPITEM; 264 } 265 266 static OpItem* Unmarshalling(Parcel& parcel); 267 }; 268 269 class RestoreOpItem : public OpItem { 270 public: 271 RestoreOpItem(); ~RestoreOpItem()272 ~RestoreOpItem() override {} 273 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 274 GetType()275 RSOpType GetType() const override 276 { 277 return RSOpType::RESTORE_OPITEM; 278 } 279 280 static OpItem* Unmarshalling(Parcel& parcel); 281 }; 282 283 class FlushOpItem : public OpItem { 284 public: 285 FlushOpItem(); ~FlushOpItem()286 ~FlushOpItem() override {} 287 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 288 GetType()289 RSOpType GetType() const override 290 { 291 return RSOpType::FLUSH_OPITEM; 292 } 293 294 static OpItem* Unmarshalling(Parcel& parcel); 295 }; 296 297 class MatrixOpItem : public OpItem { 298 public: 299 MatrixOpItem(const SkMatrix& matrix); ~MatrixOpItem()300 ~MatrixOpItem() override {} 301 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 302 GetType()303 RSOpType GetType() const override 304 { 305 return RSOpType::MATRIX_OPITEM; 306 } 307 308 bool Marshalling(Parcel& parcel) const override; 309 static OpItem* Unmarshalling(Parcel& parcel); 310 311 private: 312 SkMatrix matrix_; 313 }; 314 315 class ClipRectOpItem : public OpItem { 316 public: 317 ClipRectOpItem(const SkRect& rect, SkClipOp op, bool doAA); ~ClipRectOpItem()318 ~ClipRectOpItem() override {} 319 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 320 GetType()321 RSOpType GetType() const override 322 { 323 return RSOpType::CLIP_RECT_OPITEM; 324 } 325 326 bool Marshalling(Parcel& parcel) const override; 327 static OpItem* Unmarshalling(Parcel& parcel); 328 329 private: 330 SkRect rect_; 331 SkClipOp clipOp_; 332 bool doAA_; 333 }; 334 335 class ClipRRectOpItem : public OpItem { 336 public: 337 ClipRRectOpItem(const SkRRect& rrect, SkClipOp op, bool doAA); ~ClipRRectOpItem()338 ~ClipRRectOpItem() override {} 339 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 340 GetType()341 RSOpType GetType() const override 342 { 343 return RSOpType::CLIP_RRECT_OPITEM; 344 } 345 346 bool Marshalling(Parcel& parcel) const override; 347 static OpItem* Unmarshalling(Parcel& parcel); 348 349 private: 350 SkRRect rrect_; 351 SkClipOp clipOp_; 352 bool doAA_; 353 }; 354 355 class ClipRegionOpItem : public OpItem { 356 public: 357 ClipRegionOpItem(const SkRegion& region, SkClipOp op); ~ClipRegionOpItem()358 ~ClipRegionOpItem() override {} 359 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 360 GetType()361 RSOpType GetType() const override 362 { 363 return RSOpType::CLIP_REGION_OPITEM; 364 } 365 366 bool Marshalling(Parcel& parcel) const override; 367 static OpItem* Unmarshalling(Parcel& parcel); 368 369 private: 370 SkRegion region_; 371 SkClipOp clipOp_; 372 }; 373 374 class TranslateOpItem : public OpItem { 375 public: 376 TranslateOpItem(float distanceX, float distanceY); ~TranslateOpItem()377 ~TranslateOpItem() override {} 378 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 379 GetType()380 RSOpType GetType() const override 381 { 382 return RSOpType::TRANSLATE_OPITEM; 383 } 384 385 bool Marshalling(Parcel& parcel) const override; 386 static OpItem* Unmarshalling(Parcel& parcel); 387 388 private: 389 float distanceX_; 390 float distanceY_; 391 }; 392 393 class TextBlobOpItem : public OpItemWithPaint { 394 public: 395 TextBlobOpItem(const sk_sp<SkTextBlob> textBlob, float x, float y, const SkPaint& paint); ~TextBlobOpItem()396 ~TextBlobOpItem() override {} 397 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; GetCacheBounds()398 std::optional<SkRect> GetCacheBounds() const override 399 { 400 // bounds of textBlob_, with additional offset [x_, y_]. textBlob_ should never be null but we should check. 401 return textBlob_ ? std::make_optional<SkRect>(textBlob_->bounds().makeOffset(x_, y_)) : std::nullopt; 402 } 403 GetType()404 RSOpType GetType() const override 405 { 406 return RSOpType::TEXTBLOB_OPITEM; 407 } 408 bool Marshalling(Parcel& parcel) const override; 409 static OpItem* Unmarshalling(Parcel& parcel); 410 411 private: 412 sk_sp<SkTextBlob> textBlob_; 413 float x_; 414 float y_; 415 }; 416 417 class BitmapOpItem : public OpItemWithPaint { 418 public: 419 BitmapOpItem(const sk_sp<SkImage> bitmapInfo, float left, float top, const SkPaint* paint); ~BitmapOpItem()420 ~BitmapOpItem() override {} 421 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 422 GetType()423 RSOpType GetType() const override 424 { 425 return RSOpType::BITMAP_OPITEM; 426 } 427 428 bool Marshalling(Parcel& parcel) const override; 429 static OpItem* Unmarshalling(Parcel& parcel); 430 431 private: 432 float left_; 433 float top_; 434 sk_sp<SkImage> bitmapInfo_; 435 }; 436 437 class BitmapRectOpItem : public OpItemWithPaint { 438 public: 439 BitmapRectOpItem( 440 const sk_sp<SkImage> bitmapInfo, const SkRect* rectSrc, const SkRect& rectDst, const SkPaint* paint); ~BitmapRectOpItem()441 ~BitmapRectOpItem() override {} 442 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 443 GetType()444 RSOpType GetType() const override 445 { 446 return RSOpType::BITMAP_RECT_OPITEM; 447 } 448 449 bool Marshalling(Parcel& parcel) const override; 450 static OpItem* Unmarshalling(Parcel& parcel); 451 452 private: 453 SkRect rectSrc_; 454 SkRect rectDst_; 455 sk_sp<SkImage> bitmapInfo_; 456 }; 457 458 class PixelMapOpItem : public OpItemWithPaint { 459 public: 460 PixelMapOpItem(const std::shared_ptr<Media::PixelMap>& pixelmap, float left, float top, const SkPaint* paint); ~PixelMapOpItem()461 ~PixelMapOpItem() override {} 462 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 463 GetType()464 RSOpType GetType() const override 465 { 466 return RSOpType::PIXELMAP_OPITEM; 467 } 468 469 bool Marshalling(Parcel& parcel) const override; 470 static OpItem* Unmarshalling(Parcel& parcel); 471 472 private: 473 std::shared_ptr<Media::PixelMap> pixelmap_; 474 float left_; 475 float top_; 476 }; 477 478 class PixelMapRectOpItem : public OpItemWithPaint { 479 public: 480 PixelMapRectOpItem( 481 const std::shared_ptr<Media::PixelMap>& pixelmap, const SkRect& src, const SkRect& dst, const SkPaint* paint); ~PixelMapRectOpItem()482 ~PixelMapRectOpItem() override {} 483 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 484 GetType()485 RSOpType GetType() const override 486 { 487 return RSOpType::PIXELMAP_RECT_OPITEM; 488 } 489 490 bool Marshalling(Parcel& parcel) const override; 491 static OpItem* Unmarshalling(Parcel& parcel); 492 493 private: 494 std::shared_ptr<Media::PixelMap> pixelmap_; 495 SkRect src_; 496 SkRect dst_; 497 }; 498 499 class BitmapNineOpItem : public OpItemWithPaint { 500 public: 501 BitmapNineOpItem( 502 const sk_sp<SkImage> bitmapInfo, const SkIRect& center, const SkRect& rectDst, const SkPaint* paint); ~BitmapNineOpItem()503 ~BitmapNineOpItem() override {} 504 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 505 GetType()506 RSOpType GetType() const override 507 { 508 return RSOpType::BITMAP_NINE_OPITEM; 509 } 510 511 bool Marshalling(Parcel& parcel) const override; 512 static OpItem* Unmarshalling(Parcel& parcel); 513 514 private: 515 SkIRect center_; 516 SkRect rectDst_; 517 sk_sp<SkImage> bitmapInfo_; 518 }; 519 520 class AdaptiveRRectOpItem : public OpItemWithPaint { 521 public: 522 AdaptiveRRectOpItem(float radius, const SkPaint& paint); ~AdaptiveRRectOpItem()523 ~AdaptiveRRectOpItem() override {} 524 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 525 GetType()526 RSOpType GetType() const override 527 { 528 return RSOpType::ADAPTIVE_RRECT_OPITEM; 529 } 530 531 bool Marshalling(Parcel& parcel) const override; 532 static OpItem* Unmarshalling(Parcel& parcel); 533 534 private: 535 float radius_; 536 SkPaint paint_; 537 }; 538 539 class AdaptiveRRectScaleOpItem : public OpItemWithPaint { 540 public: 541 AdaptiveRRectScaleOpItem(float radiusRatio, const SkPaint& paint); ~AdaptiveRRectScaleOpItem()542 ~AdaptiveRRectScaleOpItem() override {} 543 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 544 GetType()545 RSOpType GetType() const override 546 { 547 return RSOpType::ADAPTIVE_RRECT_SCALE_OPITEM; 548 } 549 550 bool Marshalling(Parcel& parcel) const override; 551 static OpItem* Unmarshalling(Parcel& parcel); 552 553 private: 554 float radiusRatio_; 555 SkPaint paint_; 556 }; 557 558 class ClipAdaptiveRRectOpItem : public OpItem { 559 public: 560 ClipAdaptiveRRectOpItem(const SkVector radius[]); ~ClipAdaptiveRRectOpItem()561 ~ClipAdaptiveRRectOpItem() override {} 562 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 563 GetType()564 RSOpType GetType() const override 565 { 566 return RSOpType::CLIP_ADAPTIVE_RRECT_OPITEM; 567 } 568 569 bool Marshalling(Parcel& parcel) const override; 570 static OpItem* Unmarshalling(Parcel& parcel); 571 572 private: 573 SkVector radius_[4]; 574 }; 575 576 class ClipOutsetRectOpItem : public OpItem { 577 public: 578 ClipOutsetRectOpItem(float dx, float dy); ~ClipOutsetRectOpItem()579 ~ClipOutsetRectOpItem() override {} 580 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 581 GetType()582 RSOpType GetType() const override 583 { 584 return RSOpType::CLIP_OUTSET_RECT_OPITEM; 585 } 586 587 bool Marshalling(Parcel& parcel) const override; 588 static OpItem* Unmarshalling(Parcel& parcel); 589 590 private: 591 float dx_; 592 float dy_; 593 }; 594 595 class PathOpItem : public OpItemWithPaint { 596 public: 597 PathOpItem(const SkPath& path, const SkPaint& paint); ~PathOpItem()598 ~PathOpItem() override {} 599 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; GetCacheBounds()600 std::optional<SkRect> GetCacheBounds() const override 601 { 602 return path_.getBounds(); 603 } 604 GetType()605 RSOpType GetType() const override 606 { 607 return RSOpType::PATH_OPITEM; 608 } 609 610 bool Marshalling(Parcel& parcel) const override; 611 static OpItem* Unmarshalling(Parcel& parcel); 612 613 private: 614 SkPath path_; 615 }; 616 617 class ClipPathOpItem : public OpItem { 618 public: 619 ClipPathOpItem(const SkPath& path, SkClipOp clipOp, bool doAA); ~ClipPathOpItem()620 ~ClipPathOpItem() override {} 621 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 622 GetType()623 RSOpType GetType() const override 624 { 625 return RSOpType::CLIP_PATH_OPITEM; 626 } 627 628 bool Marshalling(Parcel& parcel) const override; 629 static OpItem* Unmarshalling(Parcel& parcel); 630 631 private: 632 SkPath path_; 633 SkClipOp clipOp_; 634 bool doAA_; 635 }; 636 637 class PaintOpItem : public OpItemWithPaint { 638 public: 639 PaintOpItem(const SkPaint& paint); ~PaintOpItem()640 ~PaintOpItem() override {} 641 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 642 GetType()643 RSOpType GetType() const override 644 { 645 return RSOpType::PAINT_OPITEM; 646 } 647 648 bool Marshalling(Parcel& parcel) const override; 649 static OpItem* Unmarshalling(Parcel& parcel); 650 }; 651 652 class ConcatOpItem : public OpItem { 653 public: 654 ConcatOpItem(const SkMatrix& matrix); ~ConcatOpItem()655 ~ConcatOpItem() override {} 656 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 657 GetType()658 RSOpType GetType() const override 659 { 660 return RSOpType::CONCAT_OPITEM; 661 } 662 663 bool Marshalling(Parcel& parcel) const override; 664 static OpItem* Unmarshalling(Parcel& parcel); 665 666 private: 667 SkMatrix matrix_; 668 }; 669 670 class SaveLayerOpItem : public OpItemWithPaint { 671 public: 672 SaveLayerOpItem(const SkCanvas::SaveLayerRec& rec); ~SaveLayerOpItem()673 ~SaveLayerOpItem() override {} 674 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 675 GetType()676 RSOpType GetType() const override 677 { 678 return RSOpType::SAVE_LAYER_OPITEM; 679 } 680 681 bool Marshalling(Parcel& parcel) const override; 682 static OpItem* Unmarshalling(Parcel& parcel); 683 684 private: 685 SkRect* rectPtr_ = nullptr; 686 SkRect rect_ = SkRect::MakeEmpty(); 687 sk_sp<SkImageFilter> backdrop_; 688 sk_sp<SkImage> mask_; 689 SkMatrix matrix_; 690 SkCanvas::SaveLayerFlags flags_; 691 }; 692 693 class DrawableOpItem : public OpItem { 694 public: 695 DrawableOpItem(SkDrawable* drawable, const SkMatrix* matrix); ~DrawableOpItem()696 ~DrawableOpItem() override {} 697 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 698 GetType()699 RSOpType GetType() const override 700 { 701 return RSOpType::DRAWABLE_OPITEM; 702 } 703 704 bool Marshalling(Parcel& parcel) const override; 705 static OpItem* Unmarshalling(Parcel& parcel); 706 707 private: 708 sk_sp<SkDrawable> drawable_; 709 SkMatrix matrix_ = SkMatrix::I(); 710 }; 711 712 class PictureOpItem : public OpItemWithPaint { 713 public: 714 PictureOpItem(const sk_sp<SkPicture> picture, const SkMatrix* matrix, const SkPaint* paint); ~PictureOpItem()715 ~PictureOpItem() override {} 716 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 717 GetType()718 RSOpType GetType() const override 719 { 720 return RSOpType::PICTURE_OPITEM; 721 } 722 723 bool Marshalling(Parcel& parcel) const override; 724 static OpItem* Unmarshalling(Parcel& parcel); 725 726 private: 727 sk_sp<SkPicture> picture_ { nullptr }; 728 SkMatrix matrix_; 729 }; 730 731 class PointsOpItem : public OpItemWithPaint { 732 public: 733 PointsOpItem(SkCanvas::PointMode mode, int count, const SkPoint processedPoints[], const SkPaint& paint); ~PointsOpItem()734 ~PointsOpItem() override 735 { 736 delete[] processedPoints_; 737 } 738 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 739 GetType()740 RSOpType GetType() const override 741 { 742 return RSOpType::POINTS_OPITEM; 743 } 744 745 bool Marshalling(Parcel& parcel) const override; 746 static OpItem* Unmarshalling(Parcel& parcel); 747 748 private: 749 SkCanvas::PointMode mode_; 750 int count_; 751 SkPoint* processedPoints_; 752 }; 753 754 class VerticesOpItem : public OpItemWithPaint { 755 public: 756 VerticesOpItem(const SkVertices* vertices, const SkVertices::Bone bones[], 757 int boneCount, SkBlendMode mode, const SkPaint& paint); 758 ~VerticesOpItem() override; 759 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 760 GetType()761 RSOpType GetType() const override 762 { 763 return RSOpType::VERTICES_OPITEM; 764 } 765 766 bool Marshalling(Parcel& parcel) const override; 767 static OpItem* Unmarshalling(Parcel& parcel); 768 769 private: 770 sk_sp<SkVertices> vertices_; 771 SkVertices::Bone* bones_; 772 int boneCount_; 773 SkBlendMode mode_; 774 }; 775 776 class ShadowRecOpItem : public OpItem { 777 public: 778 ShadowRecOpItem(const SkPath& path, const SkDrawShadowRec& rec); ~ShadowRecOpItem()779 ~ShadowRecOpItem() override {} 780 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 781 GetType()782 RSOpType GetType() const override 783 { 784 return RSOpType::SHADOW_REC_OPITEM; 785 } 786 787 bool Marshalling(Parcel& parcel) const override; 788 static OpItem* Unmarshalling(Parcel& parcel); 789 790 private: 791 SkPath path_; 792 SkDrawShadowRec rec_; 793 }; 794 795 class MultiplyAlphaOpItem : public OpItem { 796 public: 797 MultiplyAlphaOpItem(float alpha); ~MultiplyAlphaOpItem()798 ~MultiplyAlphaOpItem() override {} 799 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 800 GetType()801 RSOpType GetType() const override 802 { 803 return RSOpType::MULTIPLY_ALPHA_OPITEM; 804 } 805 806 bool Marshalling(Parcel& parcel) const override; 807 static OpItem* Unmarshalling(Parcel& parcel); 808 809 private: 810 float alpha_; 811 }; 812 813 class SaveAlphaOpItem : public OpItem { 814 public: 815 SaveAlphaOpItem(); ~SaveAlphaOpItem()816 ~SaveAlphaOpItem() override {} 817 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 818 GetType()819 RSOpType GetType() const override 820 { 821 return RSOpType::SAVE_ALPHA_OPITEM; 822 } 823 824 static OpItem* Unmarshalling(Parcel& parcel); 825 }; 826 827 class RestoreAlphaOpItem : public OpItem { 828 public: 829 RestoreAlphaOpItem(); ~RestoreAlphaOpItem()830 ~RestoreAlphaOpItem() override {} 831 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 832 GetType()833 RSOpType GetType() const override 834 { 835 return RSOpType::RESTORE_ALPHA_OPITEM; 836 } 837 838 static OpItem* Unmarshalling(Parcel& parcel); 839 }; 840 841 } // namespace Rosen 842 } // namespace OHOS 843 844 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_H 845