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 "SkMatrix.h" |
15 #include "SkRecord.h" | 15 #include "SkRecord.h" |
16 | 16 |
17 class SkLayerInfo; | 17 class SkLayerInfo; |
18 | 18 |
19 // Fill a BBH to be used by SkRecordDraw to accelerate playback. | 19 // Fill a BBH to be used by SkRecordDraw to accelerate playback. |
20 void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkBBoxHierarchy
*); | 20 void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkBBoxHierarchy
*); |
21 | 21 |
22 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, | 22 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, |
23 SkBBoxHierarchy* bbh, SkLayerInfo* data); | 23 SkBBoxHierarchy* bbh, SkLayerInfo* data); |
24 | 24 |
25 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::D
raw. | 25 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::D
raw. |
26 void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPict
ureCallback*); | 26 void SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePic
ts[], int drawableCount, |
| 27 const SkBBoxHierarchy*, SkDrawPictureCallback*); |
27 | 28 |
28 // Draw a portion of an SkRecord into an SkCanvas while replacing clears with dr
awRects. | 29 // Draw a portion of an SkRecord into an SkCanvas while replacing clears with dr
awRects. |
29 // When drawing a portion of an SkRecord the CTM on the passed in canvas must be | 30 // When drawing a portion of an SkRecord the CTM on the passed in canvas must be |
30 // the composition of the replay matrix with the record-time CTM (for the portio
n | 31 // the composition of the replay matrix with the record-time CTM (for the portio
n |
31 // of the record that is being replayed). For setMatrix calls to behave correctl
y | 32 // of the record that is being replayed). For setMatrix calls to behave correctl
y |
32 // the initialCTM parameter must set to just the replay matrix. | 33 // the initialCTM parameter must set to just the replay matrix. |
33 void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned sta
rt, unsigned stop, | 34 void SkRecordPartialDraw(const SkRecord&, SkCanvas*, |
| 35 SkPicture const* const drawablePicts[], int drawableCou
nt, |
| 36 const SkRect&, unsigned start, unsigned stop, |
34 const SkMatrix& initialCTM); | 37 const SkMatrix& initialCTM); |
35 | 38 |
36 namespace SkRecords { | 39 namespace SkRecords { |
37 | 40 |
38 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. | 41 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. |
39 class Draw : SkNoncopyable { | 42 class Draw : SkNoncopyable { |
40 public: | 43 public: |
41 explicit Draw(SkCanvas* canvas, const SkMatrix* initialCTM = NULL) | 44 explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[], int
drawableCount, |
| 45 const SkMatrix* initialCTM = NULL) |
42 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix()) | 46 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix()) |
43 , fCanvas(canvas) {} | 47 , fCanvas(canvas) |
| 48 , fDrawablePicts(drawablePicts) |
| 49 , fDrawableCount(drawableCount) |
| 50 {} |
44 | 51 |
45 // This operator calls methods on the |canvas|. The various draw() wrapper | 52 // This operator calls methods on the |canvas|. The various draw() wrapper |
46 // methods around SkCanvas are defined by the DRAW() macro in | 53 // methods around SkCanvas are defined by the DRAW() macro in |
47 // SkRecordDraw.cpp. | 54 // SkRecordDraw.cpp. |
48 template <typename T> void operator()(const T& r) { | 55 template <typename T> void operator()(const T& r) { |
49 this->draw(r); | 56 this->draw(r); |
50 } | 57 } |
51 | 58 |
| 59 protected: |
| 60 SkPicture const* const* drawablePicts() const { return fDrawablePicts; } |
| 61 int drawableCount() const { return fDrawableCount; } |
| 62 |
52 private: | 63 private: |
53 // No base case, so we'll be compile-time checked that we implement all poss
ibilities. | 64 // No base case, so we'll be compile-time checked that we implement all poss
ibilities. |
54 template <typename T> void draw(const T&); | 65 template <typename T> void draw(const T&); |
55 | 66 |
56 const SkMatrix fInitialCTM; | 67 const SkMatrix fInitialCTM; |
57 SkCanvas* fCanvas; | 68 SkCanvas* fCanvas; |
| 69 SkPicture const* const* fDrawablePicts; |
| 70 int fDrawableCount; |
58 }; | 71 }; |
59 | 72 |
60 // Used by SkRecordPartialDraw. | 73 // Used by SkRecordPartialDraw. |
61 class PartialDraw : public Draw { | 74 class PartialDraw : public Draw { |
62 public: | 75 public: |
63 PartialDraw(SkCanvas* canvas, const SkRect& clearRect, const SkMatrix& initi
alCTM) | 76 PartialDraw(SkCanvas* canvas, SkPicture const* const drawablePicts[], int dr
awableCount, |
64 : INHERITED(canvas, &initialCTM), fClearRect(clearRect) {} | 77 const SkRect& clearRect, const SkMatrix& initialCTM) |
| 78 : INHERITED(canvas, drawablePicts, drawableCount, &initialCTM), fClearRe
ct(clearRect) {} |
65 | 79 |
66 // Same as Draw for all ops except Clear. | 80 // Same as Draw for all ops except Clear. |
67 template <typename T> void operator()(const T& r) { | 81 template <typename T> void operator()(const T& r) { |
68 this->INHERITED::operator()(r); | 82 this->INHERITED::operator()(r); |
69 } | 83 } |
70 void operator()(const Clear& c) { | 84 void operator()(const Clear& c) { |
71 SkPaint p; | 85 SkPaint p; |
72 p.setColor(c.color); | 86 p.setColor(c.color); |
73 DrawRect drawRect(p, fClearRect); | 87 DrawRect drawRect(p, fClearRect); |
74 this->INHERITED::operator()(drawRect); | 88 this->INHERITED::operator()(drawRect); |
75 } | 89 } |
76 | 90 |
77 private: | 91 private: |
78 const SkRect fClearRect; | 92 const SkRect fClearRect; |
79 typedef Draw INHERITED; | 93 typedef Draw INHERITED; |
80 }; | 94 }; |
81 | 95 |
82 } // namespace SkRecords | 96 } // namespace SkRecords |
83 | 97 |
84 #endif//SkRecordDraw_DEFINED | 98 #endif//SkRecordDraw_DEFINED |
OLD | NEW |