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" |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 13 | #include "SkDrawPictureCallback.h" |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 14 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 15 | // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. |
Mike Klein | c11530e | 2014-06-24 11:29:06 -0400 | [diff] [blame] | 16 | void SkRecordDraw(const SkRecord&, SkCanvas*, SkDrawPictureCallback* = NULL); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 17 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 18 | namespace SkRecords { |
| 19 | |
| 20 | // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. |
| 21 | class Draw : SkNoncopyable { |
| 22 | public: |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame] | 23 | explicit Draw(SkCanvas* canvas) |
| 24 | : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas), fIndex(0) {} |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 25 | |
| 26 | unsigned index() const { return fIndex; } |
| 27 | void next() { ++fIndex; } |
| 28 | |
| 29 | template <typename T> void operator()(const T& r) { |
mtklein | f4078ad | 2014-08-08 10:05:19 -0700 | [diff] [blame^] | 30 | this->draw(r); |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | private: |
| 34 | // No base case, so we'll be compile-time checked that we implement all possibilities. |
| 35 | template <typename T> void draw(const T&); |
| 36 | |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame] | 37 | const SkMatrix fInitialCTM; |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 38 | SkCanvas* fCanvas; |
| 39 | unsigned fIndex; |
| 40 | }; |
| 41 | |
| 42 | } // namespace SkRecords |
| 43 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 44 | #endif//SkRecordDraw_DEFINED |