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 "SkRecord.h" | 11 #include "SkRecord.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 | 13 |
14 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::D
raw. | 14 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::D
raw. |
15 void SkRecordDraw(const SkRecord&, SkCanvas*); | 15 void SkRecordDraw(const SkRecord&, SkCanvas*); |
16 | 16 |
17 namespace SkRecords { | 17 namespace SkRecords { |
18 | 18 |
19 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. | 19 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. |
20 class Draw : SkNoncopyable { | 20 class Draw : SkNoncopyable { |
21 public: | 21 public: |
22 explicit Draw(SkCanvas* canvas) : fCanvas(canvas), fIndex(0) {} | 22 explicit Draw(SkCanvas* canvas) |
| 23 : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas), fIndex(0) {} |
23 | 24 |
24 unsigned index() const { return fIndex; } | 25 unsigned index() const { return fIndex; } |
25 void next() { ++fIndex; } | 26 void next() { ++fIndex; } |
26 | 27 |
27 template <typename T> void operator()(const T& r) { | 28 template <typename T> void operator()(const T& r) { |
28 if (!this->skip(r)) { | 29 if (!this->skip(r)) { |
29 this->draw(r); | 30 this->draw(r); |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
33 private: | 34 private: |
34 // No base case, so we'll be compile-time checked that we implement all poss
ibilities. | 35 // No base case, so we'll be compile-time checked that we implement all poss
ibilities. |
35 template <typename T> void draw(const T&); | 36 template <typename T> void draw(const T&); |
36 | 37 |
37 // skip() should return true if we can skip this command, false if not. | 38 // skip() should return true if we can skip this command, false if not. |
38 // It may update fIndex directly to skip more than just this one command. | 39 // It may update fIndex directly to skip more than just this one command. |
39 | 40 |
40 // Mostly we just blindly call fCanvas and let it handle quick rejects itsel
f. | 41 // Mostly we just blindly call fCanvas and let it handle quick rejects itsel
f. |
41 template <typename T> bool skip(const T&) { return false; } | 42 template <typename T> bool skip(const T&) { return false; } |
42 | 43 |
43 // We add our own quick rejects for commands added by optimizations. | 44 // We add our own quick rejects for commands added by optimizations. |
44 bool skip(const PairedPushCull&); | 45 bool skip(const PairedPushCull&); |
45 bool skip(const BoundedDrawPosTextH&); | 46 bool skip(const BoundedDrawPosTextH&); |
46 | 47 |
| 48 const SkMatrix fInitialCTM; |
47 SkCanvas* fCanvas; | 49 SkCanvas* fCanvas; |
48 unsigned fIndex; | 50 unsigned fIndex; |
49 }; | 51 }; |
50 | 52 |
51 } // namespace SkRecords | 53 } // namespace SkRecords |
52 | 54 |
53 #endif//SkRecordDraw_DEFINED | 55 #endif//SkRecordDraw_DEFINED |
OLD | NEW |