1/*
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
8#ifndef SkRecordDraw_DEFINED
9#define SkRecordDraw_DEFINED
10
11#include "include/core/SkBBHFactory.h"
12#include "include/core/SkCanvas.h"
13#include "include/core/SkMatrix.h"
14#include "src/core/SkBigPicture.h"
15#include "src/core/SkRecord.h"
16
17class SkDrawable;
18class SkLayerInfo;
19
20// Calculate conservative identity space bounds for each op in the record.
21void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&,
22 SkRect bounds[], SkBBoxHierarchy::Metadata[]);
23
24// SkRecordFillBounds(), and gathers information about saveLayers and stores it for later
25// use (e.g., layer hoisting). The gathered information is sufficient to determine
26// where each saveLayer will land and which ops in the picture it represents.
27void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord&, SkRect bounds[],
28 const SkBigPicture::SnapshotArray*, SkLayerInfo* data);
29
30// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
31void SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[],
32 SkDrawable* const drawables[], int drawableCount,
33 const SkBBoxHierarchy*, SkPicture::AbortCallback*);
34
35// Draw a portion of an SkRecord into an SkCanvas.
36// When drawing a portion of an SkRecord the CTM on the passed in canvas must be
37// the composition of the replay matrix with the record-time CTM (for the portion
38// of the record that is being replayed). For setMatrix calls to behave correctly
39// the initialCTM parameter must set to just the replay matrix.
40void SkRecordPartialDraw(const SkRecord&, SkCanvas*,
41 SkPicture const* const drawablePicts[], int drawableCount,
42 int start, int stop, const SkMatrix& initialCTM);
43
44namespace SkRecords {
45
46// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
47class Draw : SkNoncopyable {
48public:
49 explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[],
50 SkDrawable* const drawables[], int drawableCount,
51 const SkMatrix* initialCTM = nullptr)
52 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix())
53 , fCanvas(canvas)
54 , fDrawablePicts(drawablePicts)
55 , fDrawables(drawables)
56 , fDrawableCount(drawableCount)
57 {}
58
59 // This operator calls methods on the |canvas|. The various draw() wrapper
60 // methods around SkCanvas are defined by the DRAW() macro in
61 // SkRecordDraw.cpp.
62 template <typename T> void operator()(const T& r) {
63 this->draw(r);
64 }
65
66protected:
67 SkPicture const* const* drawablePicts() const { return fDrawablePicts; }
68 int drawableCount() const { return fDrawableCount; }
69
70private:
71 // No base case, so we'll be compile-time checked that we implement all possibilities.
72 template <typename T> void draw(const T&);
73
74 const SkMatrix fInitialCTM;
75 SkCanvas* fCanvas;
76 SkPicture const* const* fDrawablePicts;
77 SkDrawable* const* fDrawables;
78 int fDrawableCount;
79};
80
81} // namespace SkRecords
82
83#endif//SkRecordDraw_DEFINED
84