1 /* 2 * Copyright (c) 2021 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 "common/rs_common_def.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 "pipeline/rs_draw_cmd_list.h" 32 #include "render/rs_image.h" 33 34 namespace OHOS { 35 namespace Rosen { 36 class RSPaintFilterCanvas; 37 38 class OpItem : public MemObject { 39 public: OpItem(size_t size)40 explicit OpItem(size_t size) : MemObject(size) {} ~OpItem()41 virtual ~OpItem() {} 42 Draw(RSPaintFilterCanvas & canvas,const SkRect * rect)43 virtual void Draw(RSPaintFilterCanvas& canvas, const SkRect* rect) const {}; 44 }; 45 46 class OpItemWithPaint : public OpItem { 47 public: OpItemWithPaint(size_t size)48 explicit OpItemWithPaint(size_t size) : OpItem(size) {} 49 ~OpItemWithPaint()50 ~OpItemWithPaint() override {} 51 52 protected: 53 SkPaint paint_; 54 }; 55 56 class RectOpItem : public OpItemWithPaint { 57 public: 58 RectOpItem(SkRect rect, const SkPaint& paint); ~RectOpItem()59 ~RectOpItem() override {} 60 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 61 62 private: 63 SkRect rect_; 64 }; 65 66 class RoundRectOpItem : public OpItemWithPaint { 67 public: 68 RoundRectOpItem(const SkRRect& rrect, const SkPaint& paint); ~RoundRectOpItem()69 ~RoundRectOpItem() override {} 70 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 71 72 private: 73 SkRRect rrect_; 74 }; 75 76 class ImageWithParmOpItem : public OpItemWithPaint { 77 public: 78 ImageWithParmOpItem(const sk_sp<SkImage> img, int fitNum, int repeatNum, float radius, const SkPaint& paint); ~ImageWithParmOpItem()79 ~ImageWithParmOpItem() override {} 80 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 81 82 private: 83 std::shared_ptr<RSImage> rsImage_; 84 }; 85 86 class DRRectOpItem : public OpItemWithPaint { 87 public: 88 DRRectOpItem(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint); ~DRRectOpItem()89 ~DRRectOpItem() override {} 90 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 91 92 private: 93 SkRRect outer_; 94 SkRRect inner_; 95 }; 96 97 class OvalOpItem : public OpItemWithPaint { 98 public: 99 OvalOpItem(SkRect rect, const SkPaint& paint); ~OvalOpItem()100 ~OvalOpItem() override {} 101 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 102 103 private: 104 SkRect rect_; 105 }; 106 107 class RegionOpItem : public OpItemWithPaint { 108 public: 109 RegionOpItem(SkRegion region, const SkPaint& paint); ~RegionOpItem()110 ~RegionOpItem() override {} 111 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 112 113 private: 114 SkRegion region_; 115 }; 116 117 class ArcOpItem : public OpItemWithPaint { 118 public: 119 ArcOpItem(const SkRect& rect, float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint); ~ArcOpItem()120 ~ArcOpItem() override {} 121 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 122 123 private: 124 SkRect rect_; 125 float startAngle_; 126 float sweepAngle_; 127 bool useCenter_; 128 }; 129 130 class SaveOpItem : public OpItem { 131 public: 132 SaveOpItem(); ~SaveOpItem()133 ~SaveOpItem() override {} 134 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 135 }; 136 137 class RestoreOpItem : public OpItem { 138 public: 139 RestoreOpItem(); ~RestoreOpItem()140 ~RestoreOpItem() override {} 141 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 142 }; 143 144 class FlushOpItem : public OpItem { 145 public: 146 FlushOpItem(); ~FlushOpItem()147 ~FlushOpItem() override {} 148 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 149 }; 150 151 class MatrixOpItem : public OpItem { 152 public: 153 MatrixOpItem(const SkMatrix& matrix); ~MatrixOpItem()154 ~MatrixOpItem() override {} 155 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 156 157 private: 158 SkMatrix matrix_; 159 }; 160 161 class ClipRectOpItem : public OpItem { 162 public: 163 ClipRectOpItem(const SkRect& rect, SkClipOp op, bool doAA); ~ClipRectOpItem()164 ~ClipRectOpItem() override {} 165 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 166 167 private: 168 SkRect rect_; 169 SkClipOp clipOp_; 170 bool doAA_; 171 }; 172 173 class ClipRRectOpItem : public OpItem { 174 public: 175 ClipRRectOpItem(const SkRRect& rrect, SkClipOp op, bool doAA); ~ClipRRectOpItem()176 ~ClipRRectOpItem() override {} 177 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 178 179 private: 180 SkRRect rrect_; 181 SkClipOp clipOp_; 182 bool doAA_; 183 }; 184 185 class ClipRegionOpItem : public OpItem { 186 public: 187 ClipRegionOpItem(const SkRegion& region, SkClipOp op); ~ClipRegionOpItem()188 ~ClipRegionOpItem() override {} 189 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 190 191 private: 192 SkRegion region_; 193 SkClipOp clipOp_; 194 }; 195 196 class TranslateOpItem : public OpItem { 197 public: 198 TranslateOpItem(float distanceX, float distanceY); ~TranslateOpItem()199 ~TranslateOpItem() override {} 200 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 201 202 private: 203 float distanceX_; 204 float distanceY_; 205 }; 206 207 class TextBlobOpItem : public OpItemWithPaint { 208 public: 209 TextBlobOpItem(const sk_sp<SkTextBlob> textBlob, float x, float y, const SkPaint& paint); ~TextBlobOpItem()210 ~TextBlobOpItem() override {} 211 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 212 213 private: 214 sk_sp<SkTextBlob> textBlob_; 215 float x_; 216 float y_; 217 }; 218 219 class BitmapOpItem : public OpItemWithPaint { 220 public: 221 BitmapOpItem(const sk_sp<SkImage> bitmapInfo, float left, float top, const SkPaint* paint); ~BitmapOpItem()222 ~BitmapOpItem() override {} 223 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 224 225 private: 226 float left_; 227 float top_; 228 sk_sp<SkImage> bitmapInfo_; 229 }; 230 231 class BitmapRectOpItem : public OpItemWithPaint { 232 public: 233 BitmapRectOpItem( 234 const sk_sp<SkImage> bitmapInfo, const SkRect* rectSrc, const SkRect& rectDst, const SkPaint* paint); ~BitmapRectOpItem()235 ~BitmapRectOpItem() override {} 236 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 237 238 private: 239 SkRect rectSrc_; 240 SkRect rectDst_; 241 sk_sp<SkImage> bitmapInfo_; 242 }; 243 244 class BitmapLatticeOpItem : public OpItemWithPaint { 245 public: 246 BitmapLatticeOpItem( 247 const sk_sp<SkImage> bitmapInfo, const SkCanvas::Lattice& lattice, const SkRect& rect, const SkPaint* paint); ~BitmapLatticeOpItem()248 ~BitmapLatticeOpItem() override {} 249 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 250 251 private: 252 SkRect rect_; 253 SkCanvas::Lattice lattice_; 254 sk_sp<SkImage> bitmapInfo_; 255 }; 256 257 class BitmapNineOpItem : public OpItemWithPaint { 258 public: 259 BitmapNineOpItem( 260 const sk_sp<SkImage> bitmapInfo, const SkIRect& center, const SkRect& rectDst, const SkPaint* paint); ~BitmapNineOpItem()261 ~BitmapNineOpItem() override {} 262 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 263 264 private: 265 SkIRect center_; 266 SkRect rectDst_; 267 sk_sp<SkImage> bitmapInfo_; 268 }; 269 270 class AdaptiveRRectOpItem : public OpItemWithPaint { 271 public: 272 AdaptiveRRectOpItem(float radius, const SkPaint& paint); ~AdaptiveRRectOpItem()273 ~AdaptiveRRectOpItem() override {} 274 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 275 276 private: 277 float radius_; 278 SkPaint paint_; 279 }; 280 281 class ClipAdaptiveRRectOpItem : public OpItemWithPaint { 282 public: 283 ClipAdaptiveRRectOpItem(float radius); ~ClipAdaptiveRRectOpItem()284 ~ClipAdaptiveRRectOpItem() override {} 285 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 286 287 private: 288 float radius_; 289 }; 290 291 class PathOpItem : public OpItemWithPaint { 292 public: 293 PathOpItem(const SkPath& path, const SkPaint& paint); ~PathOpItem()294 ~PathOpItem() override {} 295 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 296 297 private: 298 SkPath path_; 299 }; 300 301 class ClipPathOpItem : public OpItem { 302 public: 303 ClipPathOpItem(const SkPath& path, SkClipOp clipOp, bool doAA); ~ClipPathOpItem()304 ~ClipPathOpItem() override {} 305 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 306 307 private: 308 SkPath path_; 309 SkClipOp clipOp_; 310 bool doAA_; 311 }; 312 313 class PaintOpItem : public OpItemWithPaint { 314 public: 315 PaintOpItem(const SkPaint& paint); ~PaintOpItem()316 ~PaintOpItem() override {} 317 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 318 }; 319 320 class ConcatOpItem : public OpItem { 321 public: 322 ConcatOpItem(const SkMatrix& matrix); ~ConcatOpItem()323 ~ConcatOpItem() override {} 324 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 325 326 private: 327 SkMatrix matrix_; 328 }; 329 330 class SaveLayerOpItem : public OpItemWithPaint { 331 public: 332 SaveLayerOpItem(const SkCanvas::SaveLayerRec& rec); ~SaveLayerOpItem()333 ~SaveLayerOpItem() override {} 334 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 335 336 private: 337 SkRect* rectPtr_ = nullptr; 338 SkRect rect_ = SkRect::MakeEmpty(); 339 sk_sp<SkImageFilter> backdrop_; 340 sk_sp<SkImage> mask_; 341 SkMatrix matrix_; 342 SkCanvas::SaveLayerFlags flags_; 343 }; 344 345 class DrawableOpItem : public OpItem { 346 public: 347 DrawableOpItem(SkDrawable* drawable, const SkMatrix* matrix); ~DrawableOpItem()348 ~DrawableOpItem() override {} 349 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 350 351 private: 352 sk_sp<SkDrawable> drawable_; 353 SkMatrix matrix_ = SkMatrix::I(); 354 }; 355 356 class PictureOpItem : public OpItemWithPaint { 357 public: 358 PictureOpItem(const sk_sp<SkPicture> picture, const SkMatrix* matrix, const SkPaint* paint); ~PictureOpItem()359 ~PictureOpItem() override {} 360 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 361 362 private: 363 sk_sp<SkPicture> picture_ { nullptr }; 364 SkMatrix matrix_; 365 }; 366 367 class PointsOpItem : public OpItemWithPaint { 368 public: 369 PointsOpItem(SkCanvas::PointMode mode, int count, const SkPoint processedPoints[], const SkPaint& paint); ~PointsOpItem()370 ~PointsOpItem() override 371 { 372 delete[] processedPoints_; 373 } 374 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 375 376 private: 377 SkCanvas::PointMode mode_; 378 int count_; 379 SkPoint* processedPoints_; 380 }; 381 382 class VerticesOpItem : public OpItemWithPaint { 383 public: 384 VerticesOpItem(const SkVertices* vertices, const SkVertices::Bone bones[], 385 int boneCount, SkBlendMode mode, const SkPaint& paint); 386 ~VerticesOpItem() override; 387 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 388 389 private: 390 sk_sp<SkVertices> vertices_; 391 SkVertices::Bone* bones_; 392 int boneCount_; 393 SkBlendMode mode_; 394 }; 395 396 class MultiplyAlphaOpItem : public OpItem { 397 public: 398 MultiplyAlphaOpItem(float alpha); ~MultiplyAlphaOpItem()399 ~MultiplyAlphaOpItem() override {} 400 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 401 402 private: 403 float alpha_; 404 }; 405 406 class SaveAlphaOpItem : public OpItem { 407 public: 408 SaveAlphaOpItem(); ~SaveAlphaOpItem()409 ~SaveAlphaOpItem() override {} 410 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 411 }; 412 413 class RestoreAlphaOpItem : public OpItem { 414 public: 415 RestoreAlphaOpItem(); ~RestoreAlphaOpItem()416 ~RestoreAlphaOpItem() override {} 417 void Draw(RSPaintFilterCanvas& canvas, const SkRect*) const override; 418 }; 419 420 } // namespace Rosen 421 } // namespace OHOS 422 423 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_H 424