blob: 8ea1bbd72fdc79e9fc63b488f31ba917512a4729 [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
robertphillips82365912014-11-12 09:32:34 -080017class SkLayerInfo;
18
mtklein5ad6ee12014-08-11 08:08:43 -070019// Fill a BBH to be used by SkRecordDraw to accelerate playback.
robertphillips4d52afe2014-11-03 08:19:44 -080020void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkBBoxHierarchy*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000021
robertphillips4e8e3422014-11-12 06:46:08 -080022void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record,
robertphillips82365912014-11-12 09:32:34 -080023 SkBBoxHierarchy* bbh, SkLayerInfo* data);
robertphillips4e8e3422014-11-12 06:46:08 -080024
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000025// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
reed6be2aa92014-11-18 11:08:05 -080026void SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[], int drawableCount,
27 const SkBBoxHierarchy*, SkDrawPictureCallback*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000028
mtklein00f30bd2014-09-02 12:03:31 -070029// Draw a portion of an SkRecord into an SkCanvas while replacing clears with drawRects.
robertphillips4815fe52014-09-16 10:32:43 -070030// When drawing a portion of an SkRecord the CTM on the passed in canvas must be
31// the composition of the replay matrix with the record-time CTM (for the portion
32// of the record that is being replayed). For setMatrix calls to behave correctly
33// the initialCTM parameter must set to just the replay matrix.
reed6be2aa92014-11-18 11:08:05 -080034void SkRecordPartialDraw(const SkRecord&, SkCanvas*,
35 SkPicture const* const drawablePicts[], int drawableCount,
36 const SkRect&, unsigned start, unsigned stop,
robertphillips4815fe52014-09-16 10:32:43 -070037 const SkMatrix& initialCTM);
mtklein00f30bd2014-09-02 12:03:31 -070038
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000039namespace SkRecords {
40
41// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
42class Draw : SkNoncopyable {
43public:
reed6be2aa92014-11-18 11:08:05 -080044 explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[], int drawableCount,
45 const SkMatrix* initialCTM = NULL)
robertphillips4815fe52014-09-16 10:32:43 -070046 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix())
reed6be2aa92014-11-18 11:08:05 -080047 , fCanvas(canvas)
48 , fDrawablePicts(drawablePicts)
49 , fDrawableCount(drawableCount)
50 {}
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000051
danakjd239d422014-11-03 12:43:30 -080052 // This operator calls methods on the |canvas|. The various draw() wrapper
53 // methods around SkCanvas are defined by the DRAW() macro in
54 // SkRecordDraw.cpp.
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000055 template <typename T> void operator()(const T& r) {
mtkleinf4078ad2014-08-08 10:05:19 -070056 this->draw(r);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000057 }
58
reed6be2aa92014-11-18 11:08:05 -080059protected:
60 SkPicture const* const* drawablePicts() const { return fDrawablePicts; }
61 int drawableCount() const { return fDrawableCount; }
62
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000063private:
64 // No base case, so we'll be compile-time checked that we implement all possibilities.
65 template <typename T> void draw(const T&);
66
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000067 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000068 SkCanvas* fCanvas;
reed6be2aa92014-11-18 11:08:05 -080069 SkPicture const* const* fDrawablePicts;
70 int fDrawableCount;
mtklein00f30bd2014-09-02 12:03:31 -070071};
72
73// Used by SkRecordPartialDraw.
74class PartialDraw : public Draw {
75public:
reed6be2aa92014-11-18 11:08:05 -080076 PartialDraw(SkCanvas* canvas, SkPicture const* const drawablePicts[], int drawableCount,
77 const SkRect& clearRect, const SkMatrix& initialCTM)
78 : INHERITED(canvas, drawablePicts, drawableCount, &initialCTM), fClearRect(clearRect) {}
mtklein00f30bd2014-09-02 12:03:31 -070079
80 // Same as Draw for all ops except Clear.
81 template <typename T> void operator()(const T& r) {
82 this->INHERITED::operator()(r);
83 }
84 void operator()(const Clear& c) {
85 SkPaint p;
86 p.setColor(c.color);
87 DrawRect drawRect(p, fClearRect);
88 this->INHERITED::operator()(drawRect);
89 }
90
91private:
92 const SkRect fClearRect;
93 typedef Draw INHERITED;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000094};
95
96} // namespace SkRecords
97
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000098#endif//SkRecordDraw_DEFINED