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