1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SKDRAWCOMMAND_H_ 9 #define SKDRAWCOMMAND_H_ 10 11 #include "SkCanvas.h" 12 #include "SkTLazy.h" 13 #include "SkPath.h" 14 #include "SkRegion.h" 15 #include "SkRRect.h" 16 #include "SkRSXform.h" 17 #include "SkString.h" 18 #include "SkTDArray.h" 19 #include "SkVertices.h" 20 #include "SkJSONCPP.h" 21 #include "UrlDataManager.h" 22 23 class SkDrawCommand { 24 public: 25 enum OpType { 26 kBeginDrawPicture_OpType, 27 kBeginDrawShadowedPicture_OpType, 28 kClipPath_OpType, 29 kClipRegion_OpType, 30 kClipRect_OpType, 31 kClipRRect_OpType, 32 kConcat_OpType, 33 kDrawAnnotation_OpType, 34 kDrawBitmap_OpType, 35 kDrawBitmapNine_OpType, 36 kDrawBitmapRect_OpType, 37 kDrawClear_OpType, 38 kDrawDRRect_OpType, 39 kDrawImage_OpType, 40 kDrawImageLattice_OpType, 41 kDrawImageRect_OpType, 42 kDrawOval_OpType, 43 kDrawPaint_OpType, 44 kDrawPatch_OpType, 45 kDrawPath_OpType, 46 kDrawPoints_OpType, 47 kDrawPosText_OpType, 48 kDrawPosTextH_OpType, 49 kDrawRect_OpType, 50 kDrawRRect_OpType, 51 kDrawText_OpType, 52 kDrawTextBlob_OpType, 53 kDrawTextOnPath_OpType, 54 kDrawTextRSXform_OpType, 55 kDrawVertices_OpType, 56 kEndDrawPicture_OpType, 57 kEndDrawShadowedPicture_OpType, 58 kRestore_OpType, 59 kSave_OpType, 60 kSaveLayer_OpType, 61 kSetMatrix_OpType, 62 kTranslateZ_OpType, 63 64 kLast_OpType = kTranslateZ_OpType 65 }; 66 67 static const int kOpTypeCount = kLast_OpType + 1; 68 69 static void WritePNG(const uint8_t* rgba, unsigned width, unsigned height, 70 SkWStream& out, bool isOpaque); 71 72 SkDrawCommand(OpType opType); 73 74 virtual ~SkDrawCommand(); 75 76 virtual SkString toString() const; 77 toCString()78 virtual const char* toCString() const { 79 return GetCommandString(fOpType); 80 } 81 isVisible()82 bool isVisible() const { 83 return fVisible; 84 } 85 setVisible(bool toggle)86 void setVisible(bool toggle) { 87 fVisible = toggle; 88 } 89 Info()90 const SkTDArray<SkString*>* Info() const { return &fInfo; } 91 virtual void execute(SkCanvas*) const = 0; vizExecute(SkCanvas *)92 virtual void vizExecute(SkCanvas*) const {} 93 setUserMatrix(const SkMatrix &)94 virtual void setUserMatrix(const SkMatrix&) {} 95 96 // The next "active" system is only used by save, saveLayer, and restore. 97 // It is used to determine which saveLayers are currently active (at a 98 // given point in the rendering). 99 // saves just return a kPushLayer action but don't track active state 100 // restores just return a kPopLayer action 101 // saveLayers return kPushLayer but also track the active state 102 enum Action { 103 kNone_Action, 104 kPopLayer_Action, 105 kPushLayer_Action, 106 }; action()107 virtual Action action() const { return kNone_Action; } setActive(bool active)108 virtual void setActive(bool active) {} active()109 virtual bool active() const { return false; } 110 getType()111 OpType getType() const { return fOpType; } 112 render(SkCanvas * canvas)113 virtual bool render(SkCanvas* canvas) const { return false; } 114 115 virtual Json::Value toJSON(UrlDataManager& urlDataManager) const; 116 117 /* Converts a JSON representation of a command into a newly-allocated SkDrawCommand object. It 118 * is the caller's responsibility to delete this object. This method may return null if an error 119 * occurs. 120 */ 121 static SkDrawCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 122 123 static const char* GetCommandString(OpType type); 124 125 // Helper methods for converting things to JSON 126 static Json::Value MakeJsonColor(const SkColor color); 127 static Json::Value MakeJsonColor4f(const SkColor4f& color); 128 static Json::Value MakeJsonPoint(const SkPoint& point); 129 static Json::Value MakeJsonPoint(SkScalar x, SkScalar y); 130 static Json::Value MakeJsonRect(const SkRect& rect); 131 static Json::Value MakeJsonIRect(const SkIRect&); 132 static Json::Value MakeJsonMatrix(const SkMatrix&); 133 static Json::Value MakeJsonScalar(SkScalar); 134 static Json::Value MakeJsonPath(const SkPath& path); 135 static Json::Value MakeJsonRegion(const SkRegion& region); 136 static Json::Value MakeJsonPaint(const SkPaint& paint, UrlDataManager& urlDataManager); 137 static Json::Value MakeJsonLattice(const SkCanvas::Lattice& lattice); 138 139 static void flatten(const SkFlattenable* flattenable, Json::Value* target, 140 UrlDataManager& urlDataManager); 141 static bool flatten(const SkImage& image, Json::Value* target, 142 UrlDataManager& urlDataManager); 143 static bool flatten(const SkBitmap& bitmap, Json::Value* target, 144 UrlDataManager& urlDataManager); 145 146 protected: 147 SkTDArray<SkString*> fInfo; 148 149 private: 150 OpType fOpType; 151 bool fVisible; 152 }; 153 154 class SkRestoreCommand : public SkDrawCommand { 155 public: 156 SkRestoreCommand(); 157 void execute(SkCanvas* canvas) const override; action()158 Action action() const override { return kPopLayer_Action; } 159 static SkRestoreCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 160 161 private: 162 typedef SkDrawCommand INHERITED; 163 }; 164 165 class SkClearCommand : public SkDrawCommand { 166 public: 167 SkClearCommand(SkColor color); 168 void execute(SkCanvas* canvas) const override; 169 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 170 static SkClearCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 171 172 private: 173 SkColor fColor; 174 175 typedef SkDrawCommand INHERITED; 176 }; 177 178 class SkClipPathCommand : public SkDrawCommand { 179 public: 180 SkClipPathCommand(const SkPath& path, SkClipOp op, bool doAA); 181 void execute(SkCanvas* canvas) const override; 182 bool render(SkCanvas* canvas) const override; 183 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 184 static SkClipPathCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 185 186 private: 187 SkPath fPath; 188 SkClipOp fOp; 189 bool fDoAA; 190 191 typedef SkDrawCommand INHERITED; 192 }; 193 194 class SkClipRegionCommand : public SkDrawCommand { 195 public: 196 SkClipRegionCommand(const SkRegion& region, SkClipOp op); 197 void execute(SkCanvas* canvas) const override; 198 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 199 static SkClipRegionCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 200 201 private: 202 SkRegion fRegion; 203 SkClipOp fOp; 204 205 typedef SkDrawCommand INHERITED; 206 }; 207 208 class SkClipRectCommand : public SkDrawCommand { 209 public: 210 SkClipRectCommand(const SkRect& rect, SkClipOp op, bool doAA); 211 void execute(SkCanvas* canvas) const override; 212 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 213 static SkClipRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 214 rect()215 const SkRect& rect() const { return fRect; } op()216 SkClipOp op() const { return fOp; } doAA()217 bool doAA() const { return fDoAA; } 218 219 private: 220 SkRect fRect; 221 SkClipOp fOp; 222 bool fDoAA; 223 224 typedef SkDrawCommand INHERITED; 225 }; 226 227 class SkClipRRectCommand : public SkDrawCommand { 228 public: 229 SkClipRRectCommand(const SkRRect& rrect, SkClipOp op, bool doAA); 230 void execute(SkCanvas* canvas) const override; 231 bool render(SkCanvas* canvas) const override; 232 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 233 static SkClipRRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 234 rrect()235 const SkRRect& rrect() const { return fRRect; } op()236 SkClipOp op() const { return fOp; } doAA()237 bool doAA() const { return fDoAA; } 238 239 private: 240 SkRRect fRRect; 241 SkClipOp fOp; 242 bool fDoAA; 243 244 typedef SkDrawCommand INHERITED; 245 }; 246 247 class SkConcatCommand : public SkDrawCommand { 248 public: 249 SkConcatCommand(const SkMatrix& matrix); 250 void execute(SkCanvas* canvas) const override; 251 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 252 static SkConcatCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 253 254 private: 255 SkMatrix fMatrix; 256 257 typedef SkDrawCommand INHERITED; 258 }; 259 260 class SkDrawAnnotationCommand : public SkDrawCommand { 261 public: 262 SkDrawAnnotationCommand(const SkRect&, const char key[], sk_sp<SkData> value); 263 void execute(SkCanvas* canvas) const override; 264 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 265 static SkDrawAnnotationCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 266 267 private: 268 SkRect fRect; 269 SkString fKey; 270 sk_sp<SkData> fValue; 271 272 typedef SkDrawCommand INHERITED; 273 }; 274 275 class SkDrawBitmapCommand : public SkDrawCommand { 276 public: 277 SkDrawBitmapCommand(const SkBitmap& bitmap, SkScalar left, SkScalar top, 278 const SkPaint* paint); 279 void execute(SkCanvas* canvas) const override; 280 bool render(SkCanvas* canvas) const override; 281 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 282 static SkDrawBitmapCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 283 284 private: 285 SkBitmap fBitmap; 286 SkScalar fLeft; 287 SkScalar fTop; 288 SkPaint fPaint; 289 SkPaint* fPaintPtr; 290 291 typedef SkDrawCommand INHERITED; 292 }; 293 294 class SkDrawBitmapNineCommand : public SkDrawCommand { 295 public: 296 SkDrawBitmapNineCommand(const SkBitmap& bitmap, const SkIRect& center, 297 const SkRect& dst, const SkPaint* paint); 298 void execute(SkCanvas* canvas) const override; 299 bool render(SkCanvas* canvas) const override; 300 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 301 static SkDrawBitmapNineCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 302 303 private: 304 SkBitmap fBitmap; 305 SkIRect fCenter; 306 SkRect fDst; 307 SkPaint fPaint; 308 SkPaint* fPaintPtr; 309 310 typedef SkDrawCommand INHERITED; 311 }; 312 313 class SkDrawBitmapRectCommand : public SkDrawCommand { 314 public: 315 SkDrawBitmapRectCommand(const SkBitmap& bitmap, const SkRect* src, 316 const SkRect& dst, const SkPaint* paint, 317 SkCanvas::SrcRectConstraint); 318 void execute(SkCanvas* canvas) const override; 319 bool render(SkCanvas* canvas) const override; 320 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 321 static SkDrawBitmapRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 322 bitmap()323 const SkBitmap& bitmap() const { return fBitmap; } 324 325 // The non-const 'paint' method allows modification of this object's 326 // SkPaint. For this reason the ctor and setPaint method make a local copy. 327 // The 'fPaintPtr' member acts a signal that the local SkPaint is valid 328 // (since only an SkPaint* is passed into the ctor). paint()329 const SkPaint* paint() const { return fPaintPtr; } paint()330 SkPaint* paint() { return fPaintPtr; } 331 setPaint(const SkPaint & paint)332 void setPaint(const SkPaint& paint) { fPaint = paint; fPaintPtr = &fPaint; } 333 srcRect()334 const SkRect* srcRect() const { return fSrc.isEmpty() ? nullptr : &fSrc; } setSrcRect(const SkRect & src)335 void setSrcRect(const SkRect& src) { fSrc = src; } 336 dstRect()337 const SkRect& dstRect() const { return fDst; } setDstRect(const SkRect & dst)338 void setDstRect(const SkRect& dst) { fDst = dst; } 339 constraint()340 SkCanvas::SrcRectConstraint constraint() const { return fConstraint; } setConstraint(SkCanvas::SrcRectConstraint constraint)341 void setConstraint(SkCanvas::SrcRectConstraint constraint) { fConstraint = constraint; } 342 343 private: 344 SkBitmap fBitmap; 345 SkRect fSrc; 346 SkRect fDst; 347 SkPaint fPaint; 348 SkPaint* fPaintPtr; 349 SkCanvas::SrcRectConstraint fConstraint; 350 351 typedef SkDrawCommand INHERITED; 352 }; 353 354 class SkDrawImageCommand : public SkDrawCommand { 355 public: 356 SkDrawImageCommand(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint); 357 void execute(SkCanvas* canvas) const override; 358 bool render(SkCanvas* canvas) const override; 359 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 360 static SkDrawImageCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 361 362 private: 363 sk_sp<const SkImage> fImage; 364 SkScalar fLeft; 365 SkScalar fTop; 366 SkTLazy<SkPaint> fPaint; 367 368 typedef SkDrawCommand INHERITED; 369 }; 370 371 class SkDrawImageLatticeCommand : public SkDrawCommand { 372 public: 373 SkDrawImageLatticeCommand(const SkImage* image, const SkCanvas::Lattice& lattice, 374 const SkRect& dst, const SkPaint* paint); 375 void execute(SkCanvas* canvas) const override; 376 bool render(SkCanvas* canvas) const override; 377 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 378 379 private: 380 sk_sp<const SkImage> fImage; 381 SkCanvas::Lattice fLattice; 382 SkRect fDst; 383 SkTLazy<SkPaint> fPaint; 384 385 typedef SkDrawCommand INHERITED; 386 }; 387 388 class SkDrawImageRectCommand : public SkDrawCommand { 389 public: 390 SkDrawImageRectCommand(const SkImage* image, const SkRect* src, const SkRect& dst, 391 const SkPaint* paint, SkCanvas::SrcRectConstraint constraint); 392 void execute(SkCanvas* canvas) const override; 393 bool render(SkCanvas* canvas) const override; 394 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 395 static SkDrawImageRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 396 397 private: 398 sk_sp<const SkImage> fImage; 399 SkTLazy<SkRect> fSrc; 400 SkRect fDst; 401 SkTLazy<SkPaint> fPaint; 402 SkCanvas::SrcRectConstraint fConstraint; 403 404 typedef SkDrawCommand INHERITED; 405 }; 406 407 class SkDrawOvalCommand : public SkDrawCommand { 408 public: 409 SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint); 410 void execute(SkCanvas* canvas) const override; 411 bool render(SkCanvas* canvas) const override; 412 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 413 static SkDrawOvalCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 414 415 private: 416 SkRect fOval; 417 SkPaint fPaint; 418 419 typedef SkDrawCommand INHERITED; 420 }; 421 422 class SkDrawArcCommand : public SkDrawCommand { 423 public: 424 SkDrawArcCommand(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, 425 const SkPaint& paint); 426 void execute(SkCanvas* canvas) const override; 427 bool render(SkCanvas* canvas) const override; 428 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 429 static SkDrawArcCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 430 431 private: 432 SkRect fOval; 433 SkScalar fStartAngle; 434 SkScalar fSweepAngle; 435 bool fUseCenter; 436 SkPaint fPaint; 437 438 typedef SkDrawCommand INHERITED; 439 }; 440 441 class SkDrawPaintCommand : public SkDrawCommand { 442 public: 443 SkDrawPaintCommand(const SkPaint& paint); 444 void execute(SkCanvas* canvas) const override; 445 bool render(SkCanvas* canvas) const override; 446 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 447 static SkDrawPaintCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 448 449 private: 450 SkPaint fPaint; 451 452 typedef SkDrawCommand INHERITED; 453 }; 454 455 class SkDrawPathCommand : public SkDrawCommand { 456 public: 457 SkDrawPathCommand(const SkPath& path, const SkPaint& paint); 458 void execute(SkCanvas* canvas) const override; 459 bool render(SkCanvas* canvas) const override; 460 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 461 static SkDrawPathCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 462 463 private: 464 SkPath fPath; 465 SkPaint fPaint; 466 467 typedef SkDrawCommand INHERITED; 468 }; 469 470 class SkBeginDrawPictureCommand : public SkDrawCommand { 471 public: 472 SkBeginDrawPictureCommand(const SkPicture* picture, 473 const SkMatrix* matrix, 474 const SkPaint* paint); 475 476 void execute(SkCanvas* canvas) const override; 477 bool render(SkCanvas* canvas) const override; 478 479 private: 480 sk_sp<const SkPicture> fPicture; 481 SkTLazy<SkMatrix> fMatrix; 482 SkTLazy<SkPaint> fPaint; 483 484 typedef SkDrawCommand INHERITED; 485 }; 486 487 class SkEndDrawPictureCommand : public SkDrawCommand { 488 public: 489 SkEndDrawPictureCommand(bool restore); 490 491 void execute(SkCanvas* canvas) const override; 492 493 private: 494 bool fRestore; 495 496 typedef SkDrawCommand INHERITED; 497 }; 498 499 class SkBeginDrawShadowedPictureCommand : public SkDrawCommand { 500 public: 501 SkBeginDrawShadowedPictureCommand(const SkPicture* picture, 502 const SkMatrix* matrix, 503 const SkPaint* paint, 504 const SkShadowParams& params); 505 506 void execute(SkCanvas* canvas) const override; 507 bool render(SkCanvas* canvas) const override; 508 509 private: 510 sk_sp<const SkPicture> fPicture; 511 SkTLazy<SkMatrix> fMatrix; 512 SkTLazy<SkPaint> fPaint; 513 #ifdef SK_EXPERIMENTAL_SHADOWING 514 SkShadowParams fShadowParams; 515 #endif 516 517 typedef SkDrawCommand INHERITED; 518 }; 519 520 class SkEndDrawShadowedPictureCommand : public SkDrawCommand { 521 public: 522 SkEndDrawShadowedPictureCommand(bool restore); 523 524 void execute(SkCanvas* canvas) const override; 525 526 private: 527 bool fRestore; 528 529 typedef SkDrawCommand INHERITED; 530 }; 531 532 class SkDrawPointsCommand : public SkDrawCommand { 533 public: 534 SkDrawPointsCommand(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], 535 const SkPaint& paint); ~SkDrawPointsCommand()536 ~SkDrawPointsCommand() override { delete [] fPts; } 537 void execute(SkCanvas* canvas) const override; 538 bool render(SkCanvas* canvas) const override; 539 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 540 static SkDrawPointsCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 541 542 private: 543 SkCanvas::PointMode fMode; 544 size_t fCount; 545 SkPoint* fPts; 546 SkPaint fPaint; 547 548 typedef SkDrawCommand INHERITED; 549 }; 550 551 class SkDrawTextCommand : public SkDrawCommand { 552 public: 553 SkDrawTextCommand(const void* text, size_t byteLength, SkScalar x, SkScalar y, 554 const SkPaint& paint); ~SkDrawTextCommand()555 ~SkDrawTextCommand() override { delete [] fText; } 556 void execute(SkCanvas* canvas) const override; 557 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 558 static SkDrawTextCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 559 560 private: 561 char* fText; 562 size_t fByteLength; 563 SkScalar fX; 564 SkScalar fY; 565 SkPaint fPaint; 566 567 typedef SkDrawCommand INHERITED; 568 }; 569 570 class SkDrawPosTextCommand : public SkDrawCommand { 571 public: 572 SkDrawPosTextCommand(const void* text, size_t byteLength, const SkPoint pos[], 573 const SkPaint& paint); ~SkDrawPosTextCommand()574 ~SkDrawPosTextCommand() override { delete [] fPos; delete [] fText; } 575 void execute(SkCanvas* canvas) const override; 576 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 577 static SkDrawPosTextCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 578 579 private: 580 char* fText; 581 size_t fByteLength; 582 SkPoint* fPos; 583 SkPaint fPaint; 584 585 typedef SkDrawCommand INHERITED; 586 }; 587 588 class SkDrawTextOnPathCommand : public SkDrawCommand { 589 public: 590 SkDrawTextOnPathCommand(const void* text, size_t byteLength, const SkPath& path, 591 const SkMatrix* matrix, const SkPaint& paint); ~SkDrawTextOnPathCommand()592 ~SkDrawTextOnPathCommand() override { delete [] fText; } 593 void execute(SkCanvas* canvas) const override; 594 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 595 static SkDrawTextOnPathCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 596 597 private: 598 char* fText; 599 size_t fByteLength; 600 SkPath fPath; 601 SkMatrix fMatrix; 602 SkPaint fPaint; 603 604 typedef SkDrawCommand INHERITED; 605 }; 606 607 class SkDrawTextRSXformCommand : public SkDrawCommand { 608 public: 609 SkDrawTextRSXformCommand(const void* text, size_t byteLength, const SkRSXform[], 610 const SkRect*, const SkPaint& paint); ~SkDrawTextRSXformCommand()611 ~SkDrawTextRSXformCommand() override { delete[] fText; delete[] fXform; } 612 void execute(SkCanvas* canvas) const override; 613 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 614 static SkDrawTextRSXformCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 615 616 private: 617 char* fText; 618 size_t fByteLength; 619 SkRSXform* fXform; 620 SkRect* fCull; 621 SkRect fCullStorage; 622 SkPaint fPaint; 623 624 typedef SkDrawCommand INHERITED; 625 }; 626 627 class SkDrawPosTextHCommand : public SkDrawCommand { 628 public: 629 SkDrawPosTextHCommand(const void* text, size_t byteLength, const SkScalar xpos[], 630 SkScalar constY, const SkPaint& paint); ~SkDrawPosTextHCommand()631 ~SkDrawPosTextHCommand() override { delete [] fXpos; delete [] fText; } 632 void execute(SkCanvas* canvas) const override; 633 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 634 static SkDrawPosTextHCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 635 636 private: 637 SkScalar* fXpos; 638 char* fText; 639 size_t fByteLength; 640 SkScalar fConstY; 641 SkPaint fPaint; 642 643 typedef SkDrawCommand INHERITED; 644 }; 645 646 class SkDrawTextBlobCommand : public SkDrawCommand { 647 public: 648 SkDrawTextBlobCommand(sk_sp<SkTextBlob> blob, SkScalar x, SkScalar y, const SkPaint& paint); 649 650 void execute(SkCanvas* canvas) const override; 651 bool render(SkCanvas* canvas) const override; 652 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 653 static SkDrawTextBlobCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 654 655 private: 656 sk_sp<SkTextBlob> fBlob; 657 SkScalar fXPos; 658 SkScalar fYPos; 659 SkPaint fPaint; 660 661 typedef SkDrawCommand INHERITED; 662 }; 663 664 class SkDrawPatchCommand : public SkDrawCommand { 665 public: 666 SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4], 667 const SkPoint texCoords[4], SkBlendMode bmode, 668 const SkPaint& paint); 669 void execute(SkCanvas* canvas) const override; 670 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 671 static SkDrawPatchCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 672 673 private: 674 SkPoint fCubics[12]; 675 SkColor* fColorsPtr; 676 SkColor fColors[4]; 677 SkPoint* fTexCoordsPtr; 678 SkPoint fTexCoords[4]; 679 SkBlendMode fBlendMode; 680 SkPaint fPaint; 681 682 typedef SkDrawCommand INHERITED; 683 }; 684 685 686 class SkDrawRectCommand : public SkDrawCommand { 687 public: 688 SkDrawRectCommand(const SkRect& rect, const SkPaint& paint); 689 void execute(SkCanvas* canvas) const override; 690 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 691 static SkDrawRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 692 rect()693 const SkRect& rect() const { return fRect; } paint()694 const SkPaint& paint() const { return fPaint; } 695 private: 696 SkRect fRect; 697 SkPaint fPaint; 698 699 typedef SkDrawCommand INHERITED; 700 }; 701 702 class SkDrawRRectCommand : public SkDrawCommand { 703 public: 704 SkDrawRRectCommand(const SkRRect& rrect, const SkPaint& paint); 705 void execute(SkCanvas* canvas) const override; 706 bool render(SkCanvas* canvas) const override; 707 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 708 static SkDrawRRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 709 710 private: 711 SkRRect fRRect; 712 SkPaint fPaint; 713 714 typedef SkDrawCommand INHERITED; 715 }; 716 717 class SkDrawDRRectCommand : public SkDrawCommand { 718 public: 719 SkDrawDRRectCommand(const SkRRect& outer, const SkRRect& inner, 720 const SkPaint& paint); 721 void execute(SkCanvas* canvas) const override; 722 bool render(SkCanvas* canvas) const override; 723 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 724 static SkDrawDRRectCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 725 726 private: 727 SkRRect fOuter; 728 SkRRect fInner; 729 SkPaint fPaint; 730 731 typedef SkDrawCommand INHERITED; 732 }; 733 734 class SkDrawVerticesCommand : public SkDrawCommand { 735 public: 736 SkDrawVerticesCommand(sk_sp<SkVertices>, SkBlendMode, const SkPaint&); 737 738 void execute(SkCanvas* canvas) const override; 739 740 private: 741 sk_sp<SkVertices> fVertices; 742 SkBlendMode fBlendMode; 743 SkPaint fPaint; 744 745 typedef SkDrawCommand INHERITED; 746 }; 747 748 class SkSaveCommand : public SkDrawCommand { 749 public: 750 SkSaveCommand(); 751 void execute(SkCanvas* canvas) const override; action()752 Action action() const override { return kPushLayer_Action; } 753 static SkSaveCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 754 755 private: 756 typedef SkDrawCommand INHERITED; 757 }; 758 759 class SkSaveLayerCommand : public SkDrawCommand { 760 public: 761 SkSaveLayerCommand(const SkCanvas::SaveLayerRec&); 762 ~SkSaveLayerCommand() override; 763 void execute(SkCanvas* canvas) const override; 764 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 765 static SkSaveLayerCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 766 void vizExecute(SkCanvas* canvas) const override; action()767 Action action() const override{ return kPushLayer_Action; } setActive(bool active)768 void setActive(bool active) override { fActive = active; } active()769 bool active() const override { return fActive; } 770 paint()771 const SkPaint* paint() const { return fPaintPtr; } 772 773 private: 774 SkRect fBounds; 775 SkPaint fPaint; 776 SkPaint* fPaintPtr; 777 const SkImageFilter* fBackdrop; 778 uint32_t fSaveLayerFlags; 779 780 bool fActive; 781 782 typedef SkDrawCommand INHERITED; 783 }; 784 785 class SkSetMatrixCommand : public SkDrawCommand { 786 public: 787 SkSetMatrixCommand(const SkMatrix& matrix); 788 void setUserMatrix(const SkMatrix&) override; 789 void execute(SkCanvas* canvas) const override; 790 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 791 static SkSetMatrixCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 792 793 private: 794 SkMatrix fUserMatrix; 795 SkMatrix fMatrix; 796 797 typedef SkDrawCommand INHERITED; 798 }; 799 800 class SkTranslateZCommand : public SkDrawCommand { 801 public: 802 SkTranslateZCommand(SkScalar); 803 void execute(SkCanvas* canvas) const override; 804 Json::Value toJSON(UrlDataManager& urlDataManager) const override; 805 static SkTranslateZCommand* fromJSON(Json::Value& command, UrlDataManager& urlDataManager); 806 807 private: 808 SkScalar fZTranslate; 809 810 typedef SkDrawCommand INHERITED; 811 }; 812 #endif 813 814