blob: f3f00881ea69b2cb1be5892c6935a2b5d16df577 [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.
robertphillips4d52afe2014-11-03 08:19:44 -080018void SkRecordFillBounds(const SkRect& cullRect, 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
danakjd239d422014-11-03 12:43:30 -080040 // This operator calls methods on the |canvas|. The various draw() wrapper
41 // methods around SkCanvas are defined by the DRAW() macro in
42 // SkRecordDraw.cpp.
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000043 template <typename T> void operator()(const T& r) {
mtkleinf4078ad2014-08-08 10:05:19 -070044 this->draw(r);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000045 }
46
47private:
48 // No base case, so we'll be compile-time checked that we implement all possibilities.
49 template <typename T> void draw(const T&);
50
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000051 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000052 SkCanvas* fCanvas;
mtklein00f30bd2014-09-02 12:03:31 -070053};
54
55// Used by SkRecordPartialDraw.
56class PartialDraw : public Draw {
57public:
robertphillips4815fe52014-09-16 10:32:43 -070058 PartialDraw(SkCanvas* canvas, const SkRect& clearRect, const SkMatrix& initialCTM)
59 : INHERITED(canvas, &initialCTM), fClearRect(clearRect) {}
mtklein00f30bd2014-09-02 12:03:31 -070060
61 // Same as Draw for all ops except Clear.
62 template <typename T> void operator()(const T& r) {
63 this->INHERITED::operator()(r);
64 }
65 void operator()(const Clear& c) {
66 SkPaint p;
67 p.setColor(c.color);
68 DrawRect drawRect(p, fClearRect);
69 this->INHERITED::operator()(drawRect);
70 }
71
72private:
73 const SkRect fClearRect;
74 typedef Draw INHERITED;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000075};
76
77} // namespace SkRecords
78
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000079#endif//SkRecordDraw_DEFINED