diff options
author | mtklein <mtklein@chromium.org> | 2014-09-02 12:03:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-02 12:03:31 -0700 |
commit | 00f30bdc9e34b013da54b4406f36556c5be8d041 (patch) | |
tree | bc3dac91df9e6d0f2e610855a0ca21fb97594c6a /src | |
parent | aca21d6d2f9984da8f941b76f4ee11772d0e48ec (diff) |
SkRecordPartialDraw with less code duplication
BUG=skia:
R=robertphillips@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/527423002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkRecordDraw.cpp | 18 | ||||
-rw-r--r-- | src/core/SkRecordDraw.h | 31 |
2 files changed, 42 insertions, 7 deletions
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp index 0117adeefa..f7f02997df 100644 --- a/src/core/SkRecordDraw.cpp +++ b/src/core/SkRecordDraw.cpp @@ -35,15 +35,29 @@ void SkRecordDraw(const SkRecord& record, } } else { // Draw all ops. - for (SkRecords::Draw draw(canvas); draw.index() < record.count(); draw.next()) { + SkRecords::Draw draw(canvas); + for (unsigned i = 0; i < record.count(); i++) { if (NULL != callback && callback->abortDrawing()) { return; } - record.visit<void>(draw.index(), draw); + record.visit<void>(i, draw); } } } +void SkRecordPartialDraw(const SkRecord& record, + SkCanvas* canvas, + const SkRect& clearRect, + unsigned start, unsigned stop) { + SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); + + stop = SkTMin(stop, record.count()); + SkRecords::PartialDraw draw(canvas, clearRect); + for (unsigned i = start; i < stop; i++) { + record.visit<void>(i, draw); + } +} + namespace SkRecords { // FIXME: SkBitmaps are stateful, so we need to copy them to play back in multiple threads. diff --git a/src/core/SkRecordDraw.h b/src/core/SkRecordDraw.h index 8da7fb5e4a..033b76d34a 100644 --- a/src/core/SkRecordDraw.h +++ b/src/core/SkRecordDraw.h @@ -19,16 +19,16 @@ void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*); // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*); +// Draw a portion of an SkRecord into an SkCanvas while replacing clears with drawRects. +void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned start, unsigned stop); + namespace SkRecords { // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. class Draw : SkNoncopyable { public: explicit Draw(SkCanvas* canvas) - : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas), fIndex(0) {} - - unsigned index() const { return fIndex; } - void next() { ++fIndex; } + : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas) {} template <typename T> void operator()(const T& r) { this->draw(r); @@ -40,7 +40,28 @@ private: const SkMatrix fInitialCTM; SkCanvas* fCanvas; - unsigned fIndex; +}; + +// Used by SkRecordPartialDraw. +class PartialDraw : public Draw { +public: + PartialDraw(SkCanvas* canvas, const SkRect& clearRect) + : INHERITED(canvas), fClearRect(clearRect) {} + + // Same as Draw for all ops except Clear. + template <typename T> void operator()(const T& r) { + this->INHERITED::operator()(r); + } + void operator()(const Clear& c) { + SkPaint p; + p.setColor(c.color); + DrawRect drawRect(p, fClearRect); + this->INHERITED::operator()(drawRect); + } + +private: + const SkRect fClearRect; + typedef Draw INHERITED; }; } // namespace SkRecords |