commit-bot@chromium.org | c4b21e6 | 2014-04-11 18:33:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 8 | #ifndef SkRecordDraw_DEFINED |
| 9 | #define SkRecordDraw_DEFINED |
| 10 | |
| 11 | #include "SkRecord.h" |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 12 | #include "SkCanvas.h" |
| 13 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 14 | // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. |
commit-bot@chromium.org | 506db0b | 2014-04-08 23:31:35 +0000 | [diff] [blame] | 15 | void SkRecordDraw(const SkRecord&, SkCanvas*); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 16 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 17 | namespace SkRecords { |
| 18 | |
| 19 | // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. |
| 20 | class Draw : SkNoncopyable { |
| 21 | public: |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame^] | 22 | explicit Draw(SkCanvas* canvas) |
| 23 | : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas), fIndex(0) {} |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 24 | |
| 25 | unsigned index() const { return fIndex; } |
| 26 | void next() { ++fIndex; } |
| 27 | |
| 28 | template <typename T> void operator()(const T& r) { |
| 29 | if (!this->skip(r)) { |
| 30 | this->draw(r); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | private: |
| 35 | // No base case, so we'll be compile-time checked that we implement all possibilities. |
| 36 | template <typename T> void draw(const T&); |
| 37 | |
| 38 | // skip() should return true if we can skip this command, false if not. |
| 39 | // It may update fIndex directly to skip more than just this one command. |
| 40 | |
| 41 | // Mostly we just blindly call fCanvas and let it handle quick rejects itself. |
| 42 | template <typename T> bool skip(const T&) { return false; } |
| 43 | |
| 44 | // We add our own quick rejects for commands added by optimizations. |
| 45 | bool skip(const PairedPushCull&); |
| 46 | bool skip(const BoundedDrawPosTextH&); |
| 47 | |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame^] | 48 | const SkMatrix fInitialCTM; |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 49 | SkCanvas* fCanvas; |
| 50 | unsigned fIndex; |
| 51 | }; |
| 52 | |
| 53 | } // namespace SkRecords |
| 54 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 55 | #endif//SkRecordDraw_DEFINED |