blob: fdf98824acf867f42836779dd6ceb3ab8abf7e50 [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"
mtklein9db912c2015-05-19 11:11:26 -070012#include "SkBigPicture.h"
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000013#include "SkCanvas.h"
robertphillips4815fe52014-09-16 10:32:43 -070014#include "SkMatrix.h"
mtklein5ad6ee12014-08-11 08:08:43 -070015#include "SkRecord.h"
16
reed3cb38402015-02-06 08:36:15 -080017class SkDrawable;
robertphillips82365912014-11-12 09:32:34 -080018class SkLayerInfo;
19
mtklein40732b32015-10-24 07:45:47 -070020// Calculate conservative identity space bounds for each op in the record.
21void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkRect bounds[]);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000022
mtklein40732b32015-10-24 07:45:47 -070023// SkRecordFillBounds(), and gathers information about saveLayers and stores it for later
24// use (e.g., layer hoisting). The gathered information is sufficient to determine
25// where each saveLayer will land and which ops in the picture it represents.
26void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord&, SkRect bounds[],
27 const SkBigPicture::SnapshotArray*, SkLayerInfo* data);
robertphillips4e8e3422014-11-12 06:46:08 -080028
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000029// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
reed1bdfd3f2014-11-24 14:41:51 -080030void SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[],
reed3cb38402015-02-06 08:36:15 -080031 SkDrawable* const drawables[], int drawableCount,
robertphillips783fe162015-01-07 07:28:41 -080032 const SkBBoxHierarchy*, SkPicture::AbortCallback*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000033
reed8eddfb52014-12-04 07:50:14 -080034// Draw a portion of an SkRecord into an SkCanvas.
robertphillips4815fe52014-09-16 10:32:43 -070035// When drawing a portion of an SkRecord the CTM on the passed in canvas must be
36// the composition of the replay matrix with the record-time CTM (for the portion
37// of the record that is being replayed). For setMatrix calls to behave correctly
38// the initialCTM parameter must set to just the replay matrix.
reed6be2aa92014-11-18 11:08:05 -080039void SkRecordPartialDraw(const SkRecord&, SkCanvas*,
40 SkPicture const* const drawablePicts[], int drawableCount,
mtkleinc6ad06a2015-08-19 09:51:00 -070041 int start, int stop, const SkMatrix& initialCTM);
mtklein00f30bd2014-09-02 12:03:31 -070042
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000043namespace SkRecords {
44
45// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
46class Draw : SkNoncopyable {
47public:
reed1bdfd3f2014-11-24 14:41:51 -080048 explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[],
reed3cb38402015-02-06 08:36:15 -080049 SkDrawable* const drawables[], int drawableCount,
halcanary96fcdcc2015-08-27 07:41:13 -070050 const SkMatrix* initialCTM = nullptr)
robertphillips4815fe52014-09-16 10:32:43 -070051 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix())
reed6be2aa92014-11-18 11:08:05 -080052 , fCanvas(canvas)
53 , fDrawablePicts(drawablePicts)
reed1bdfd3f2014-11-24 14:41:51 -080054 , fDrawables(drawables)
reed6be2aa92014-11-18 11:08:05 -080055 , fDrawableCount(drawableCount)
56 {}
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000057
danakjd239d422014-11-03 12:43:30 -080058 // This operator calls methods on the |canvas|. The various draw() wrapper
59 // methods around SkCanvas are defined by the DRAW() macro in
60 // SkRecordDraw.cpp.
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000061 template <typename T> void operator()(const T& r) {
mtkleinf4078ad2014-08-08 10:05:19 -070062 this->draw(r);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000063 }
64
reed6be2aa92014-11-18 11:08:05 -080065protected:
66 SkPicture const* const* drawablePicts() const { return fDrawablePicts; }
67 int drawableCount() const { return fDrawableCount; }
68
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000069private:
70 // No base case, so we'll be compile-time checked that we implement all possibilities.
71 template <typename T> void draw(const T&);
72
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000073 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000074 SkCanvas* fCanvas;
reed6be2aa92014-11-18 11:08:05 -080075 SkPicture const* const* fDrawablePicts;
reed3cb38402015-02-06 08:36:15 -080076 SkDrawable* const* fDrawables;
reed6be2aa92014-11-18 11:08:05 -080077 int fDrawableCount;
mtklein00f30bd2014-09-02 12:03:31 -070078};
79
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000080} // namespace SkRecords
81
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000082#endif//SkRecordDraw_DEFINED