blob: 033b76d34ae5d1cc0934a7d347a3f2136ff92c7e [file] [log] [blame]
commit-bot@chromium.orgc4b21e62014-04-11 18:33:31 +00001/*
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.orge3ff5582014-04-01 16:24:06 +00008#ifndef SkRecordDraw_DEFINED
9#define SkRecordDraw_DEFINED
10
mtklein5ad6ee12014-08-11 08:08:43 -070011#include "SkBBoxHierarchy.h"
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000012#include "SkCanvas.h"
Mike Kleinc11530e2014-06-24 11:29:06 -040013#include "SkDrawPictureCallback.h"
mtklein5ad6ee12014-08-11 08:08:43 -070014#include "SkRecord.h"
15
16// Fill a BBH to be used by SkRecordDraw to accelerate playback.
17void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000018
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000019// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
mtklein5ad6ee12014-08-11 08:08:43 -070020void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000021
mtklein00f30bd2014-09-02 12:03:31 -070022// Draw a portion of an SkRecord into an SkCanvas while replacing clears with drawRects.
23void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned start, unsigned stop);
24
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000025namespace SkRecords {
26
27// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
28class Draw : SkNoncopyable {
29public:
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000030 explicit Draw(SkCanvas* canvas)
mtklein00f30bd2014-09-02 12:03:31 -070031 : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas) {}
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000032
33 template <typename T> void operator()(const T& r) {
mtkleinf4078ad2014-08-08 10:05:19 -070034 this->draw(r);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000035 }
36
37private:
38 // No base case, so we'll be compile-time checked that we implement all possibilities.
39 template <typename T> void draw(const T&);
40
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000041 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000042 SkCanvas* fCanvas;
mtklein00f30bd2014-09-02 12:03:31 -070043};
44
45// Used by SkRecordPartialDraw.
46class PartialDraw : public Draw {
47public:
48 PartialDraw(SkCanvas* canvas, const SkRect& clearRect)
49 : INHERITED(canvas), fClearRect(clearRect) {}
50
51 // Same as Draw for all ops except Clear.
52 template <typename T> void operator()(const T& r) {
53 this->INHERITED::operator()(r);
54 }
55 void operator()(const Clear& c) {
56 SkPaint p;
57 p.setColor(c.color);
58 DrawRect drawRect(p, fClearRect);
59 this->INHERITED::operator()(drawRect);
60 }
61
62private:
63 const SkRect fClearRect;
64 typedef Draw INHERITED;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000065};
66
67} // namespace SkRecords
68
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000069#endif//SkRecordDraw_DEFINED