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