OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef SKDRAWCOMMAND_H_ | 9 #ifndef SKDRAWCOMMAND_H_ |
10 #define SKDRAWCOMMAND_H_ | 10 #define SKDRAWCOMMAND_H_ |
11 | 11 |
| 12 #include "SkPictureFlat.h" |
12 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
13 #include "SkString.h" | 14 #include "SkString.h" |
14 | 15 |
15 class SK_API SkDrawCommand { | 16 class SK_API SkDrawCommand { |
16 public: | 17 public: |
17 enum OpType { | 18 SkDrawCommand(DrawType drawType); |
18 kBeginCommentGroup_OpType, | |
19 kClipPath_OpType, | |
20 kClipRegion_OpType, | |
21 kClipRect_OpType, | |
22 kClipRRect_OpType, | |
23 kComment_OpType, | |
24 kConcat_OpType, | |
25 kDrawBitmap_OpType, | |
26 kDrawBitmapNine_OpType, | |
27 kDrawBitmapRect_OpType, | |
28 kDrawClear_OpType, | |
29 kDrawDRRect_OpType, | |
30 kDrawOval_OpType, | |
31 kDrawPaint_OpType, | |
32 kDrawPatch_OpType, | |
33 kDrawPath_OpType, | |
34 kDrawPicture_OpType, | |
35 kDrawPoints_OpType, | |
36 kDrawPosText_OpType, | |
37 kDrawPosTextH_OpType, | |
38 kDrawRect_OpType, | |
39 kDrawRRect_OpType, | |
40 kDrawSprite_OpType, | |
41 kDrawText_OpType, | |
42 kDrawTextBlob_OpType, | |
43 kDrawTextOnPath_OpType, | |
44 kDrawVertices_OpType, | |
45 kEndCommentGroup_OpType, | |
46 kRestore_OpType, | |
47 kSave_OpType, | |
48 kSaveLayer_OpType, | |
49 kSetMatrix_OpType, | |
50 | |
51 kLast_OpType = kSetMatrix_OpType | |
52 }; | |
53 | |
54 static const int kOpTypeCount = kLast_OpType + 1; | |
55 | |
56 SkDrawCommand(OpType opType); | |
57 | 19 |
58 virtual ~SkDrawCommand(); | 20 virtual ~SkDrawCommand(); |
59 | 21 |
60 virtual SkString toString() const; | 22 virtual SkString toString() const; |
61 | 23 |
62 void setOffset(size_t offset) { fOffset = offset; } | 24 void setOffset(size_t offset) { fOffset = offset; } |
63 size_t offset() const { return fOffset; } | 25 size_t offset() const { return fOffset; } |
64 | 26 |
65 virtual const char* toCString() const { | 27 virtual const char* toCString() const { |
66 return GetCommandString(fOpType); | 28 return GetCommandString(fDrawType); |
67 } | 29 } |
68 | 30 |
69 bool isVisible() const { | 31 bool isVisible() const { |
70 return fVisible; | 32 return fVisible; |
71 } | 33 } |
72 | 34 |
73 void setVisible(bool toggle) { | 35 void setVisible(bool toggle) { |
74 fVisible = toggle; | 36 fVisible = toggle; |
75 } | 37 } |
76 | 38 |
(...skipping 11 matching lines...) Expand all Loading... |
88 // saveLayers return kPushLayer but also track the active state | 50 // saveLayers return kPushLayer but also track the active state |
89 enum Action { | 51 enum Action { |
90 kNone_Action, | 52 kNone_Action, |
91 kPopLayer_Action, | 53 kPopLayer_Action, |
92 kPushLayer_Action, | 54 kPushLayer_Action, |
93 }; | 55 }; |
94 virtual Action action() const { return kNone_Action; } | 56 virtual Action action() const { return kNone_Action; } |
95 virtual void setActive(bool active) {} | 57 virtual void setActive(bool active) {} |
96 virtual bool active() const { return false; } | 58 virtual bool active() const { return false; } |
97 | 59 |
98 OpType getType() const { return fOpType; } | 60 DrawType getType() const { return fDrawType; } |
99 | 61 |
100 virtual bool render(SkCanvas* canvas) const { return false; } | 62 virtual bool render(SkCanvas* canvas) const { return false; } |
101 | 63 |
102 static const char* GetCommandString(OpType type); | 64 static const char* GetCommandString(DrawType type); |
103 | 65 |
104 protected: | 66 protected: |
105 SkTDArray<SkString*> fInfo; | 67 SkTDArray<SkString*> fInfo; |
106 | 68 |
107 private: | 69 private: |
108 OpType fOpType; | 70 DrawType fDrawType; |
109 size_t fOffset; | 71 size_t fOffset; |
110 bool fVisible; | 72 bool fVisible; |
111 }; | 73 }; |
112 | 74 |
113 class SkRestoreCommand : public SkDrawCommand { | 75 class SkRestoreCommand : public SkDrawCommand { |
114 public: | 76 public: |
115 SkRestoreCommand(); | 77 SkRestoreCommand(); |
116 void execute(SkCanvas* canvas) const SK_OVERRIDE; | 78 void execute(SkCanvas* canvas) const SK_OVERRIDE; |
117 Action action() const SK_OVERRIDE { return kPopLayer_Action; } | 79 Action action() const SK_OVERRIDE { return kPopLayer_Action; } |
118 | 80 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 407 |
446 private: | 408 private: |
447 SkAutoTUnref<const SkTextBlob> fBlob; | 409 SkAutoTUnref<const SkTextBlob> fBlob; |
448 SkScalar fXPos; | 410 SkScalar fXPos; |
449 SkScalar fYPos; | 411 SkScalar fYPos; |
450 SkPaint fPaint; | 412 SkPaint fPaint; |
451 | 413 |
452 typedef SkDrawCommand INHERITED; | 414 typedef SkDrawCommand INHERITED; |
453 }; | 415 }; |
454 | 416 |
455 class SkDrawPatchCommand : public SkDrawCommand { | |
456 public: | |
457 SkDrawPatchCommand(const SkPoint cubics[12], const SkColor colors[4], | |
458 const SkPoint texCoords[4], SkXfermode* xmode, | |
459 const SkPaint& paint); | |
460 void execute(SkCanvas* canvas) const SK_OVERRIDE; | |
461 | |
462 private: | |
463 SkPoint fCubics[12]; | |
464 SkColor fColors[4]; | |
465 SkPoint fTexCoords[4]; | |
466 SkAutoTUnref<SkXfermode> fXfermode; | |
467 SkPaint fPaint; | |
468 | |
469 typedef SkDrawCommand INHERITED; | |
470 }; | |
471 | |
472 | |
473 class SkDrawRectCommand : public SkDrawCommand { | 417 class SkDrawRectCommand : public SkDrawCommand { |
474 public: | 418 public: |
475 SkDrawRectCommand(const SkRect& rect, const SkPaint& paint); | 419 SkDrawRectCommand(const SkRect& rect, const SkPaint& paint); |
476 void execute(SkCanvas* canvas) const SK_OVERRIDE; | 420 void execute(SkCanvas* canvas) const SK_OVERRIDE; |
477 | 421 |
478 const SkRect& rect() const { return fRect; } | 422 const SkRect& rect() const { return fRect; } |
479 const SkPaint& paint() const { return fPaint; } | 423 const SkPaint& paint() const { return fPaint; } |
480 private: | 424 private: |
481 SkRect fRect; | 425 SkRect fRect; |
482 SkPaint fPaint; | 426 SkPaint fPaint; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 SkPoint* fTexs; | 485 SkPoint* fTexs; |
542 SkColor* fColors; | 486 SkColor* fColors; |
543 SkXfermode* fXfermode; | 487 SkXfermode* fXfermode; |
544 uint16_t* fIndices; | 488 uint16_t* fIndices; |
545 int fIndexCount; | 489 int fIndexCount; |
546 SkPaint fPaint; | 490 SkPaint fPaint; |
547 | 491 |
548 typedef SkDrawCommand INHERITED; | 492 typedef SkDrawCommand INHERITED; |
549 }; | 493 }; |
550 | 494 |
| 495 class SkRotateCommand : public SkDrawCommand { |
| 496 public: |
| 497 SkRotateCommand(SkScalar degrees); |
| 498 void execute(SkCanvas* canvas) const SK_OVERRIDE; |
| 499 private: |
| 500 SkScalar fDegrees; |
| 501 |
| 502 typedef SkDrawCommand INHERITED; |
| 503 }; |
| 504 |
551 class SkSaveCommand : public SkDrawCommand { | 505 class SkSaveCommand : public SkDrawCommand { |
552 public: | 506 public: |
553 SkSaveCommand(); | 507 SkSaveCommand(); |
554 void execute(SkCanvas* canvas) const SK_OVERRIDE; | 508 void execute(SkCanvas* canvas) const SK_OVERRIDE; |
555 Action action() const SK_OVERRIDE { return kPushLayer_Action; } | 509 Action action() const SK_OVERRIDE { return kPushLayer_Action; } |
556 private: | 510 private: |
557 typedef SkDrawCommand INHERITED; | 511 typedef SkDrawCommand INHERITED; |
558 }; | 512 }; |
559 | 513 |
560 class SkSaveLayerCommand : public SkDrawCommand { | 514 class SkSaveLayerCommand : public SkDrawCommand { |
(...skipping 12 matching lines...) Expand all Loading... |
573 SkRect fBounds; | 527 SkRect fBounds; |
574 SkPaint fPaint; | 528 SkPaint fPaint; |
575 SkPaint* fPaintPtr; | 529 SkPaint* fPaintPtr; |
576 SkCanvas::SaveFlags fFlags; | 530 SkCanvas::SaveFlags fFlags; |
577 | 531 |
578 bool fActive; | 532 bool fActive; |
579 | 533 |
580 typedef SkDrawCommand INHERITED; | 534 typedef SkDrawCommand INHERITED; |
581 }; | 535 }; |
582 | 536 |
| 537 class SkScaleCommand : public SkDrawCommand { |
| 538 public: |
| 539 SkScaleCommand(SkScalar sx, SkScalar sy); |
| 540 void execute(SkCanvas* canvas) const SK_OVERRIDE; |
| 541 |
| 542 SkScalar x() const { return fSx; } |
| 543 SkScalar y() const { return fSy; } |
| 544 |
| 545 private: |
| 546 SkScalar fSx; |
| 547 SkScalar fSy; |
| 548 |
| 549 typedef SkDrawCommand INHERITED; |
| 550 }; |
| 551 |
583 class SkSetMatrixCommand : public SkDrawCommand { | 552 class SkSetMatrixCommand : public SkDrawCommand { |
584 public: | 553 public: |
585 SkSetMatrixCommand(const SkMatrix& matrix); | 554 SkSetMatrixCommand(const SkMatrix& matrix); |
586 void setUserMatrix(const SkMatrix&) SK_OVERRIDE; | 555 void setUserMatrix(const SkMatrix&) SK_OVERRIDE; |
587 void execute(SkCanvas* canvas) const SK_OVERRIDE; | 556 void execute(SkCanvas* canvas) const SK_OVERRIDE; |
588 private: | 557 private: |
589 SkMatrix fUserMatrix; | 558 SkMatrix fUserMatrix; |
590 SkMatrix fMatrix; | 559 SkMatrix fMatrix; |
591 | 560 |
592 typedef SkDrawCommand INHERITED; | 561 typedef SkDrawCommand INHERITED; |
593 }; | 562 }; |
594 | 563 |
| 564 class SkSkewCommand : public SkDrawCommand { |
| 565 public: |
| 566 SkSkewCommand(SkScalar sx, SkScalar sy); |
| 567 void execute(SkCanvas* canvas) const SK_OVERRIDE; |
| 568 private: |
| 569 SkScalar fSx; |
| 570 SkScalar fSy; |
| 571 |
| 572 typedef SkDrawCommand INHERITED; |
| 573 }; |
| 574 |
| 575 class SkTranslateCommand : public SkDrawCommand { |
| 576 public: |
| 577 SkTranslateCommand(SkScalar dx, SkScalar dy); |
| 578 void execute(SkCanvas* canvas) const SK_OVERRIDE; |
| 579 |
| 580 SkScalar x() const { return fDx; } |
| 581 SkScalar y() const { return fDy; } |
| 582 |
| 583 private: |
| 584 SkScalar fDx; |
| 585 SkScalar fDy; |
| 586 |
| 587 typedef SkDrawCommand INHERITED; |
| 588 }; |
| 589 |
595 #endif | 590 #endif |
OLD | NEW |