blob: 9b39dd6adb903ab534ada47194af2ff11a601d07 [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.
mtklein5ad6ee12014-08-11 08:08:43 -070026void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000027
mtklein00f30bd2014-09-02 12:03:31 -070028// Draw a portion of an SkRecord into an SkCanvas while replacing clears with drawRects.
robertphillips4815fe52014-09-16 10:32:43 -070029// When drawing a portion of an SkRecord the CTM on the passed in canvas must be
30// the composition of the replay matrix with the record-time CTM (for the portion
31// of the record that is being replayed). For setMatrix calls to behave correctly
32// the initialCTM parameter must set to just the replay matrix.
33void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned start, unsigned stop,
34 const SkMatrix& initialCTM);
mtklein00f30bd2014-09-02 12:03:31 -070035
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000036namespace SkRecords {
37
38// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
39class Draw : SkNoncopyable {
40public:
robertphillips4815fe52014-09-16 10:32:43 -070041 explicit Draw(SkCanvas* canvas, const SkMatrix* initialCTM = NULL)
42 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix())
43 , fCanvas(canvas) {}
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000044
danakjd239d422014-11-03 12:43:30 -080045 // This operator calls methods on the |canvas|. The various draw() wrapper
46 // methods around SkCanvas are defined by the DRAW() macro in
47 // SkRecordDraw.cpp.
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000048 template <typename T> void operator()(const T& r) {
mtkleinf4078ad2014-08-08 10:05:19 -070049 this->draw(r);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000050 }
51
52private:
53 // No base case, so we'll be compile-time checked that we implement all possibilities.
54 template <typename T> void draw(const T&);
55
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000056 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000057 SkCanvas* fCanvas;
mtklein00f30bd2014-09-02 12:03:31 -070058};
59
60// Used by SkRecordPartialDraw.
61class PartialDraw : public Draw {
62public:
robertphillips4815fe52014-09-16 10:32:43 -070063 PartialDraw(SkCanvas* canvas, const SkRect& clearRect, const SkMatrix& initialCTM)
64 : INHERITED(canvas, &initialCTM), fClearRect(clearRect) {}
mtklein00f30bd2014-09-02 12:03:31 -070065
66 // Same as Draw for all ops except Clear.
67 template <typename T> void operator()(const T& r) {
68 this->INHERITED::operator()(r);
69 }
70 void operator()(const Clear& c) {
71 SkPaint p;
72 p.setColor(c.color);
73 DrawRect drawRect(p, fClearRect);
74 this->INHERITED::operator()(drawRect);
75 }
76
77private:
78 const SkRect fClearRect;
79 typedef Draw INHERITED;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000080};
81
82} // namespace SkRecords
83
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000084#endif//SkRecordDraw_DEFINED