blob: 75921d182fd3de1e5596114b7fce2e033cba696c [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"
robertphillips4815fe52014-09-16 10:32:43 -070014#include "SkMatrix.h"
mtklein5ad6ee12014-08-11 08:08:43 -070015#include "SkRecord.h"
16
17// Fill a BBH to be used by SkRecordDraw to accelerate playback.
18void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000019
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000020// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
mtklein5ad6ee12014-08-11 08:08:43 -070021void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000022
mtklein00f30bd2014-09-02 12:03:31 -070023// Draw a portion of an SkRecord into an SkCanvas while replacing clears with drawRects.
robertphillips4815fe52014-09-16 10:32:43 -070024// When drawing a portion of an SkRecord the CTM on the passed in canvas must be
25// the composition of the replay matrix with the record-time CTM (for the portion
26// of the record that is being replayed). For setMatrix calls to behave correctly
27// the initialCTM parameter must set to just the replay matrix.
28void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned start, unsigned stop,
29 const SkMatrix& initialCTM);
mtklein00f30bd2014-09-02 12:03:31 -070030
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000031namespace SkRecords {
32
33// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
34class Draw : SkNoncopyable {
35public:
robertphillips4815fe52014-09-16 10:32:43 -070036 explicit Draw(SkCanvas* canvas, const SkMatrix* initialCTM = NULL)
37 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix())
38 , fCanvas(canvas) {}
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000039
40 template <typename T> void operator()(const T& r) {
mtkleinf4078ad2014-08-08 10:05:19 -070041 this->draw(r);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000042 }
43
44private:
45 // No base case, so we'll be compile-time checked that we implement all possibilities.
46 template <typename T> void draw(const T&);
47
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000048 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000049 SkCanvas* fCanvas;
mtklein00f30bd2014-09-02 12:03:31 -070050};
51
52// Used by SkRecordPartialDraw.
53class PartialDraw : public Draw {
54public:
robertphillips4815fe52014-09-16 10:32:43 -070055 PartialDraw(SkCanvas* canvas, const SkRect& clearRect, const SkMatrix& initialCTM)
56 : INHERITED(canvas, &initialCTM), fClearRect(clearRect) {}
mtklein00f30bd2014-09-02 12:03:31 -070057
58 // Same as Draw for all ops except Clear.
59 template <typename T> void operator()(const T& r) {
60 this->INHERITED::operator()(r);
61 }
62 void operator()(const Clear& c) {
63 SkPaint p;
64 p.setColor(c.color);
65 DrawRect drawRect(p, fClearRect);
66 this->INHERITED::operator()(drawRect);
67 }
68
69private:
70 const SkRect fClearRect;
71 typedef Draw INHERITED;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000072};
73
74} // namespace SkRecords
75
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000076#endif//SkRecordDraw_DEFINED