Flutter Engine
The Flutter Engine
SkRecorder.h
Go to the documentation of this file.
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 SkRecorder_DEFINED
9#define SkRecorder_DEFINED
10
13#include "include/core/SkM44.h"
22
23#include <cstddef>
24#include <memory>
25#include <utility>
26
27class SkBlender;
28class SkData;
29class SkDrawable;
30class SkImage;
31class SkMatrix;
32class SkMesh;
33class SkPaint;
34class SkPath;
35class SkPicture;
36class SkRRect;
37class SkRecord;
38class SkRegion;
39class SkShader;
40class SkSurface;
41class SkSurfaceProps;
42class SkTextBlob;
43class SkVertices;
44enum class SkBlendMode;
45enum class SkClipOp;
46struct SkDrawShadowRec;
47struct SkImageInfo;
48struct SkPoint;
49struct SkRSXform;
50struct SkRect;
51
52namespace sktext {
53 class GlyphRunList;
54 namespace gpu { class Slug; }
55}
56
58public:
61
62 int count() const { return fArray.size(); }
63 SkDrawable* const* begin() const { return fArray.begin(); }
64 SkDrawable* const* end() const { return fArray.end(); }
65
66 void append(SkDrawable* drawable);
67
68 // Return a new or ref'd array of pictures that were snapped from our drawables.
70
71private:
73};
74
75// SkRecorder provides an SkCanvas interface for recording into an SkRecord.
76
77class SkRecorder final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> {
78public:
79 // Does not take ownership of the SkRecord.
80 SkRecorder(SkRecord*, int width, int height); // TODO: remove
82
83 void reset(SkRecord*, const SkRect& bounds);
84
85 size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; }
86
87 SkDrawableList* getDrawableList() const { return fDrawableList.get(); }
88 std::unique_ptr<SkDrawableList> detachDrawableList() { return std::move(fDrawableList); }
89
90 // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail.
91 void forgetRecord();
92
93 void willSave() override;
94 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
95 bool onDoSaveBehind(const SkRect*) override;
96 void willRestore() override {}
97 void didRestore() override;
98
99 void didConcat44(const SkM44&) override;
100 void didSetM44(const SkM44&) override;
101 void didScale(SkScalar, SkScalar) override;
102 void didTranslate(SkScalar, SkScalar) override;
103
104 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
105 void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
106 void onDrawTextBlob(const SkTextBlob* blob,
107 SkScalar x,
108 SkScalar y,
109 const SkPaint& paint) override;
110 void onDrawSlug(const sktext::gpu::Slug* slug, const SkPaint& paint) override;
112 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override;
113 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
114 const SkPoint texCoords[4], SkBlendMode,
115 const SkPaint& paint) override;
116
117 void onDrawPaint(const SkPaint&) override;
118 void onDrawBehind(const SkPaint&) override;
119 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
120 void onDrawRect(const SkRect&, const SkPaint&) override;
121 void onDrawRegion(const SkRegion&, const SkPaint&) override;
122 void onDrawOval(const SkRect&, const SkPaint&) override;
123 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
124 void onDrawRRect(const SkRRect&, const SkPaint&) override;
125 void onDrawPath(const SkPath&, const SkPaint&) override;
126
128 const SkPaint*) override;
129 void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
130 const SkPaint*, SrcRectConstraint) override;
131 void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode,
132 const SkPaint*) override;
133 void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
134 SkBlendMode, const SkSamplingOptions&, const SkRect*, const SkPaint*) override;
135
136 void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
137
138 void onDrawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override;
139
140 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
141
142 void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override;
143 void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override;
144 void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override;
145 void onClipShader(sk_sp<SkShader>, SkClipOp) override;
146 void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override;
147 void onResetClip() override;
148
149 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
150
151 void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
152
153 void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
154 SkBlendMode) override;
155 void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
156 const SkSamplingOptions&, const SkPaint*,
157 SrcRectConstraint) override;
158
160
161private:
162 template <typename T>
163 T* copy(const T*);
164
165 template <typename T>
166 T* copy(const T[], size_t count);
167
168 template<typename T, typename... Args>
169 void append(Args&&...);
170
171 size_t fApproxBytesUsedBySubPictures;
172 SkRecord* fRecord;
173 std::unique_ptr<SkDrawableList> fDrawableList;
174};
175
176#endif//SkRecorder_DEFINED
int count
Definition: FontMgrTest.cpp:50
SkBlendMode
Definition: SkBlendMode.h:38
SkClipOp
Definition: SkClipOp.h:13
uint32_t SkColor
Definition: SkColor.h:37
SkFilterMode
SrcRectConstraint
Definition: SkCanvas.h:1541
SaveLayerStrategy
Definition: SkCanvas.h:2263
Definition: SkData.h:25
SkDrawable *const * end() const
Definition: SkRecorder.h:64
SkBigPicture::SnapshotArray * newDrawableSnapshot()
Definition: SkRecorder.cpp:62
int count() const
Definition: SkRecorder.h:62
SkDrawable *const * begin() const
Definition: SkRecorder.h:63
void append(SkDrawable *drawable)
Definition: SkRecorder.cpp:74
Definition: SkM44.h:150
Definition: SkMesh.h:263
Definition: SkPath.h:59
void didScale(SkScalar, SkScalar) override
Definition: SkRecorder.cpp:375
void onDrawShadowRec(const SkPath &, const SkDrawShadowRec &) override
Definition: SkRecorder.cpp:308
void didTranslate(SkScalar, SkScalar) override
Definition: SkRecorder.cpp:379
void didConcat44(const SkM44 &) override
Definition: SkRecorder.cpp:367
void onDrawDRRect(const SkRRect &, const SkRRect &, const SkPaint &) override
Definition: SkRecorder.cpp:209
void onDrawPicture(const SkPicture *, const SkMatrix *, const SkPaint *) override
Definition: SkRecorder.cpp:267
void onClipShader(sk_sp< SkShader >, SkClipOp) override
Definition: SkRecorder.cpp:401
void onDrawDrawable(SkDrawable *, const SkMatrix *) override
Definition: SkRecorder.cpp:213
void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode, const SkPaint &paint) override
Definition: SkRecorder.cpp:283
std::unique_ptr< SkDrawableList > detachDrawableList()
Definition: SkRecorder.h:88
void onDrawPaint(const SkPaint &) override
Definition: SkRecorder.cpp:173
void onClipRRect(const SkRRect &rrect, SkClipOp, ClipEdgeStyle) override
Definition: SkRecorder.cpp:389
void onClipRegion(const SkRegion &deviceRgn, SkClipOp) override
Definition: SkRecorder.cpp:406
void onDrawSlug(const sktext::gpu::Slug *slug, const SkPaint &paint) override
Definition: SkRecorder.cpp:253
void onDrawPath(const SkPath &, const SkPaint &) override
Definition: SkRecorder.cpp:221
void onDrawMesh(const SkMesh &, sk_sp< SkBlender >, const SkPaint &) override
Definition: SkRecorder.cpp:279
void onDrawBehind(const SkPaint &) override
Definition: SkRecorder.cpp:177
void onDrawImage2(const SkImage *, SkScalar, SkScalar, const SkSamplingOptions &, const SkPaint *) override
Definition: SkRecorder.cpp:225
SkDrawableList * getDrawableList() const
Definition: SkRecorder.h:87
void onDrawEdgeAAQuad(const SkRect &, const SkPoint[4], QuadAAFlags, const SkColor4f &, SkBlendMode) override
Definition: SkRecorder.cpp:316
void didSetM44(const SkM44 &) override
Definition: SkRecorder.cpp:371
void onDrawRegion(const SkRegion &, const SkPaint &) override
Definition: SkRecorder.cpp:192
void onDrawVerticesObject(const SkVertices *, SkBlendMode, const SkPaint &) override
Definition: SkRecorder.cpp:272
void onDrawRect(const SkRect &, const SkPaint &) override
Definition: SkRecorder.cpp:188
void onResetClip() override
Definition: SkRecorder.cpp:411
size_t approxBytesUsedBySubPictures() const
Definition: SkRecorder.h:85
void onDrawImageLattice2(const SkImage *, const Lattice &, const SkRect &, SkFilterMode, const SkPaint *) override
Definition: SkRecorder.cpp:237
void onClipRect(const SkRect &rect, SkClipOp, ClipEdgeStyle) override
Definition: SkRecorder.cpp:383
sk_sp< SkSurface > onNewSurface(const SkImageInfo &, const SkSurfaceProps &) override
Definition: SkRecorder.cpp:416
bool onDoSaveBehind(const SkRect *) override
Definition: SkRecorder.cpp:358
void onDrawGlyphRunList(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint) override
Definition: SkRecorder.cpp:257
void onDrawArc(const SkRect &, SkScalar, SkScalar, bool, const SkPaint &) override
Definition: SkRecorder.cpp:200
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint &) override
Definition: SkRecorder.cpp:181
void onDrawAtlas2(const SkImage *, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode, const SkSamplingOptions &, const SkRect *, const SkPaint *) override
Definition: SkRecorder.cpp:293
void didRestore() override
Definition: SkRecorder.cpp:363
void onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint) override
Definition: SkRecorder.cpp:248
void reset(SkRecord *, const SkRect &bounds)
Definition: SkRecorder.cpp:108
void onDrawImageRect2(const SkImage *, const SkRect &, const SkRect &, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint) override
Definition: SkRecorder.cpp:230
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[], const SkSamplingOptions &, const SkPaint *, SrcRectConstraint) override
Definition: SkRecorder.cpp:322
SkRecorder(SkRecord *, int width, int height)
Definition: SkRecorder.cpp:94
void onDrawAnnotation(const SkRect &, const char[], SkData *) override
Definition: SkRecorder.cpp:312
void willRestore() override
Definition: SkRecorder.h:96
void forgetRecord()
Definition: SkRecorder.cpp:115
void onClipPath(const SkPath &path, SkClipOp, ClipEdgeStyle) override
Definition: SkRecorder.cpp:395
void onDrawOval(const SkRect &, const SkPaint &) override
Definition: SkRecorder.cpp:196
void willSave() override
Definition: SkRecorder.cpp:339
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec &) override
Definition: SkRecorder.cpp:343
void onDrawRRect(const SkRRect &, const SkPaint &) override
Definition: SkRecorder.cpp:205
T * end()
Definition: SkTDArray.h:152
int size() const
Definition: SkTDArray.h:138
T * begin()
Definition: SkTDArray.h:150
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
double x
Optional< SkRect > bounds
Definition: SkRecords.h:189
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkColor > colors
Definition: SkRecords.h:276
Definition: copy.py:1
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
#define T
Definition: precompiler.cc:65
int32_t height
int32_t width