OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkRecordDraw_DEFINED | 8 #ifndef SkRecordDraw_DEFINED |
9 #define SkRecordDraw_DEFINED | 9 #define SkRecordDraw_DEFINED |
10 | 10 |
11 #include "SkBBoxHierarchy.h" | 11 #include "SkBBoxHierarchy.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkDrawPictureCallback.h" | 13 #include "SkDrawPictureCallback.h" |
14 #include "SkMatrix.h" | |
14 #include "SkRecord.h" | 15 #include "SkRecord.h" |
15 | 16 |
16 // Fill a BBH to be used by SkRecordDraw to accelerate playback. | 17 // Fill a BBH to be used by SkRecordDraw to accelerate playback. |
17 void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*); | 18 void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*); |
18 | 19 |
19 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::D raw. | 20 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::D raw. |
20 void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPict ureCallback*); | 21 void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPict ureCallback*); |
21 | 22 |
22 // Draw a portion of an SkRecord into an SkCanvas while replacing clears with dr awRects. | 23 // Draw a portion of an SkRecord into an SkCanvas while replacing clears with dr awRects. |
23 void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned sta rt, unsigned stop); | 24 // When drawing a portion of an SkRecord the CTM on the passed in canvas must be |
25 // the composition of the replay matrix with the record-time CTM (for the portio n | |
26 // of the record that is being replayed). For setMatrix calls to behave correctl y | |
27 // the initialCTM parameter must set to just the replay matrix. | |
28 void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned sta rt, unsigned stop, | |
29 const SkMatrix& initialCTM); | |
24 | 30 |
25 namespace SkRecords { | 31 namespace SkRecords { |
26 | 32 |
27 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. | 33 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. |
28 class Draw : SkNoncopyable { | 34 class Draw : SkNoncopyable { |
29 public: | 35 public: |
30 explicit Draw(SkCanvas* canvas) | 36 explicit Draw(SkCanvas* canvas) |
mtklein
2014/09/08 18:41:23
Would slightly prefer
Draw(SkCanvas* canvas, cons
robertphillips
2014/09/15 18:33:19
Done.
| |
31 : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas) {} | 37 : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas) {} |
32 | 38 |
33 template <typename T> void operator()(const T& r) { | 39 template <typename T> void operator()(const T& r) { |
34 this->draw(r); | 40 this->draw(r); |
35 } | 41 } |
36 | 42 |
43 protected: | |
44 SkMatrix fInitialCTM; | |
45 | |
37 private: | 46 private: |
38 // No base case, so we'll be compile-time checked that we implement all poss ibilities. | 47 // No base case, so we'll be compile-time checked that we implement all poss ibilities. |
39 template <typename T> void draw(const T&); | 48 template <typename T> void draw(const T&); |
40 | 49 |
41 const SkMatrix fInitialCTM; | |
42 SkCanvas* fCanvas; | 50 SkCanvas* fCanvas; |
43 }; | 51 }; |
44 | 52 |
45 // Used by SkRecordPartialDraw. | 53 // Used by SkRecordPartialDraw. |
46 class PartialDraw : public Draw { | 54 class PartialDraw : public Draw { |
47 public: | 55 public: |
48 PartialDraw(SkCanvas* canvas, const SkRect& clearRect) | 56 PartialDraw(SkCanvas* canvas, const SkRect& clearRect, const SkMatrix& initi alCTM) |
49 : INHERITED(canvas), fClearRect(clearRect) {} | 57 : INHERITED(canvas), fClearRect(clearRect) { |
58 fInitialCTM = initialCTM; | |
59 } | |
50 | 60 |
51 // Same as Draw for all ops except Clear. | 61 // Same as Draw for all ops except Clear. |
52 template <typename T> void operator()(const T& r) { | 62 template <typename T> void operator()(const T& r) { |
53 this->INHERITED::operator()(r); | 63 this->INHERITED::operator()(r); |
54 } | 64 } |
55 void operator()(const Clear& c) { | 65 void operator()(const Clear& c) { |
56 SkPaint p; | 66 SkPaint p; |
57 p.setColor(c.color); | 67 p.setColor(c.color); |
58 DrawRect drawRect(p, fClearRect); | 68 DrawRect drawRect(p, fClearRect); |
59 this->INHERITED::operator()(drawRect); | 69 this->INHERITED::operator()(drawRect); |
60 } | 70 } |
61 | 71 |
62 private: | 72 private: |
63 const SkRect fClearRect; | 73 const SkRect fClearRect; |
64 typedef Draw INHERITED; | 74 typedef Draw INHERITED; |
65 }; | 75 }; |
66 | 76 |
67 } // namespace SkRecords | 77 } // namespace SkRecords |
68 | 78 |
69 #endif//SkRecordDraw_DEFINED | 79 #endif//SkRecordDraw_DEFINED |
OLD | NEW |