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 | |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 11 | #include "SkBBoxHierarchy.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" |
robertphillips | 4815fe5 | 2014-09-16 10:32:43 -0700 | [diff] [blame] | 14 | #include "SkMatrix.h" |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 15 | #include "SkRecord.h" |
| 16 | |
robertphillips | 8236591 | 2014-11-12 09:32:34 -0800 | [diff] [blame] | 17 | class SkLayerInfo; |
| 18 | |
mtklein | 5ad6ee1 | 2014-08-11 08:08:43 -0700 | [diff] [blame] | 19 | // Fill a BBH to be used by SkRecordDraw to accelerate playback. |
robertphillips | 4d52afe | 2014-11-03 08:19:44 -0800 | [diff] [blame] | 20 | void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkBBoxHierarchy*); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 21 | |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 22 | void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, |
robertphillips | 8236591 | 2014-11-12 09:32:34 -0800 | [diff] [blame] | 23 | SkBBoxHierarchy* bbh, SkLayerInfo* data); |
robertphillips | 4e8e342 | 2014-11-12 06:46:08 -0800 | [diff] [blame] | 24 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 25 | // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame^] | 26 | void SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[], int drawableCount, |
| 27 | const SkBBoxHierarchy*, SkDrawPictureCallback*); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 28 | |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 29 | // Draw a portion of an SkRecord into an SkCanvas while replacing clears with drawRects. |
robertphillips | 4815fe5 | 2014-09-16 10:32:43 -0700 | [diff] [blame] | 30 | // When drawing a portion of an SkRecord the CTM on the passed in canvas must be |
| 31 | // the composition of the replay matrix with the record-time CTM (for the portion |
| 32 | // of the record that is being replayed). For setMatrix calls to behave correctly |
| 33 | // the initialCTM parameter must set to just the replay matrix. |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame^] | 34 | void SkRecordPartialDraw(const SkRecord&, SkCanvas*, |
| 35 | SkPicture const* const drawablePicts[], int drawableCount, |
| 36 | const SkRect&, unsigned start, unsigned stop, |
robertphillips | 4815fe5 | 2014-09-16 10:32:43 -0700 | [diff] [blame] | 37 | const SkMatrix& initialCTM); |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 38 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 39 | namespace SkRecords { |
| 40 | |
| 41 | // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. |
| 42 | class Draw : SkNoncopyable { |
| 43 | public: |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame^] | 44 | explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[], int drawableCount, |
| 45 | const SkMatrix* initialCTM = NULL) |
robertphillips | 4815fe5 | 2014-09-16 10:32:43 -0700 | [diff] [blame] | 46 | : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix()) |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame^] | 47 | , fCanvas(canvas) |
| 48 | , fDrawablePicts(drawablePicts) |
| 49 | , fDrawableCount(drawableCount) |
| 50 | {} |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 51 | |
danakj | d239d42 | 2014-11-03 12:43:30 -0800 | [diff] [blame] | 52 | // This operator calls methods on the |canvas|. The various draw() wrapper |
| 53 | // methods around SkCanvas are defined by the DRAW() macro in |
| 54 | // SkRecordDraw.cpp. |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 55 | template <typename T> void operator()(const T& r) { |
mtklein | f4078ad | 2014-08-08 10:05:19 -0700 | [diff] [blame] | 56 | this->draw(r); |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 57 | } |
| 58 | |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame^] | 59 | protected: |
| 60 | SkPicture const* const* drawablePicts() const { return fDrawablePicts; } |
| 61 | int drawableCount() const { return fDrawableCount; } |
| 62 | |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 63 | private: |
| 64 | // No base case, so we'll be compile-time checked that we implement all possibilities. |
| 65 | template <typename T> void draw(const T&); |
| 66 | |
commit-bot@chromium.org | 0a98d87 | 2014-05-19 15:15:24 +0000 | [diff] [blame] | 67 | const SkMatrix fInitialCTM; |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 68 | SkCanvas* fCanvas; |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame^] | 69 | SkPicture const* const* fDrawablePicts; |
| 70 | int fDrawableCount; |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | // Used by SkRecordPartialDraw. |
| 74 | class PartialDraw : public Draw { |
| 75 | public: |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame^] | 76 | PartialDraw(SkCanvas* canvas, SkPicture const* const drawablePicts[], int drawableCount, |
| 77 | const SkRect& clearRect, const SkMatrix& initialCTM) |
| 78 | : INHERITED(canvas, drawablePicts, drawableCount, &initialCTM), fClearRect(clearRect) {} |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 79 | |
| 80 | // Same as Draw for all ops except Clear. |
| 81 | template <typename T> void operator()(const T& r) { |
| 82 | this->INHERITED::operator()(r); |
| 83 | } |
| 84 | void operator()(const Clear& c) { |
| 85 | SkPaint p; |
| 86 | p.setColor(c.color); |
| 87 | DrawRect drawRect(p, fClearRect); |
| 88 | this->INHERITED::operator()(drawRect); |
| 89 | } |
| 90 | |
| 91 | private: |
| 92 | const SkRect fClearRect; |
| 93 | typedef Draw INHERITED; |
commit-bot@chromium.org | 27f6b0d | 2014-05-09 14:59:29 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | } // namespace SkRecords |
| 97 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 98 | #endif//SkRecordDraw_DEFINED |