blob: 8df64cbecdde78f0f70bb16c8ccc71252eb75d0d [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
robertphillips4e8e3422014-11-12 06:46:08 -080020#if SK_SUPPORT_GPU
21class GrAccelData;
22
23void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record,
24 SkBBoxHierarchy* bbh, GrAccelData* data);
25#endif
26
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000027// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
mtklein5ad6ee12014-08-11 08:08:43 -070028void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000029
mtklein00f30bd2014-09-02 12:03:31 -070030// Draw a portion of an SkRecord into an SkCanvas while replacing clears with drawRects.
robertphillips4815fe52014-09-16 10:32:43 -070031// When drawing a portion of an SkRecord the CTM on the passed in canvas must be
32// the composition of the replay matrix with the record-time CTM (for the portion
33// of the record that is being replayed). For setMatrix calls to behave correctly
34// the initialCTM parameter must set to just the replay matrix.
35void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned start, unsigned stop,
36 const SkMatrix& initialCTM);
mtklein00f30bd2014-09-02 12:03:31 -070037
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000038namespace SkRecords {
39
40// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
41class Draw : SkNoncopyable {
42public:
robertphillips4815fe52014-09-16 10:32:43 -070043 explicit Draw(SkCanvas* canvas, const SkMatrix* initialCTM = NULL)
44 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix())
45 , fCanvas(canvas) {}
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000046
danakjd239d422014-11-03 12:43:30 -080047 // This operator calls methods on the |canvas|. The various draw() wrapper
48 // methods around SkCanvas are defined by the DRAW() macro in
49 // SkRecordDraw.cpp.
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000050 template <typename T> void operator()(const T& r) {
mtkleinf4078ad2014-08-08 10:05:19 -070051 this->draw(r);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000052 }
53
54private:
55 // No base case, so we'll be compile-time checked that we implement all possibilities.
56 template <typename T> void draw(const T&);
57
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000058 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000059 SkCanvas* fCanvas;
mtklein00f30bd2014-09-02 12:03:31 -070060};
61
62// Used by SkRecordPartialDraw.
63class PartialDraw : public Draw {
64public:
robertphillips4815fe52014-09-16 10:32:43 -070065 PartialDraw(SkCanvas* canvas, const SkRect& clearRect, const SkMatrix& initialCTM)
66 : INHERITED(canvas, &initialCTM), fClearRect(clearRect) {}
mtklein00f30bd2014-09-02 12:03:31 -070067
68 // Same as Draw for all ops except Clear.
69 template <typename T> void operator()(const T& r) {
70 this->INHERITED::operator()(r);
71 }
72 void operator()(const Clear& c) {
73 SkPaint p;
74 p.setColor(c.color);
75 DrawRect drawRect(p, fClearRect);
76 this->INHERITED::operator()(drawRect);
77 }
78
79private:
80 const SkRect fClearRect;
81 typedef Draw INHERITED;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000082};
83
84} // namespace SkRecords
85
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000086#endif//SkRecordDraw_DEFINED