Flutter Engine
The Flutter Engine
SkPictureRecord.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 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 SkPictureRecord_DEFINED
9#define SkPictureRecord_DEFINED
10
14#include "include/core/SkData.h"
17#include "include/core/SkM44.h"
19#include "include/core/SkPath.h"
33#include "src/core/SkTHash.h"
34#include "src/core/SkWriter32.h"
35
36#include <cstddef>
37#include <cstdint>
38
39class SkBitmap;
40class SkMatrix;
41class SkPixmap;
42class SkRRect;
43class SkRegion;
44class SkShader;
45class SkSurface;
46class SkSurfaceProps;
47enum class SkBlendMode;
48enum class SkClipOp;
49struct SkDrawShadowRec;
50struct SkIRect;
51struct SkISize;
52struct SkImageInfo;
53struct SkPoint;
54struct SkRSXform;
55struct SkRect;
56
57
58// These macros help with packing and unpacking a single byte value and
59// a 3 byte value into/out of a uint32_t
60#define MASK_24 0x00FFFFFF
61#define UNPACK_8_24(combined, small, large) \
62 small = (combined >> 24) & 0xFF; \
63 large = combined & MASK_24
64#define PACK_8_24(small, large) ((small << 24) | large)
65
66
67class SkPictureRecord : public SkCanvasVirtualEnforcer<SkCanvas> {
68public:
69 SkPictureRecord(const SkISize& dimensions, uint32_t recordFlags);
70
71 SkPictureRecord(const SkIRect& dimensions, uint32_t recordFlags);
72
74 return fPictures;
75 }
76
78 return fDrawables;
79 }
80
82 return fTextBlobs;
83 }
84
86 return fSlugs;
87 }
88
90 return fVertices;
91 }
92
94 return fImages;
95 }
96
98 this->validate(fWriter.bytesWritten(), 0);
99
100 if (fWriter.bytesWritten() == 0) {
101 return SkData::MakeEmpty();
102 }
103 return fWriter.snapshotAsData();
104 }
105
106 void setFlags(uint32_t recordFlags) {
107 fRecordFlags = recordFlags;
108 }
109
110 const SkWriter32& writeStream() const {
111 return fWriter;
112 }
113
114 void beginRecording();
115 void endRecording();
116
117protected:
118 void addNoOp();
119
120private:
121 void handleOptimization(int opt);
122 size_t recordRestoreOffsetPlaceholder();
123 void fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset);
124
125 SkTDArray<int32_t> fRestoreOffsetStack;
126
127 SkTDArray<uint32_t> fCullOffsetStack;
128
129 /*
130 * Write the 'drawType' operation and chunk size to the skp. 'size'
131 * can potentially be increased if the chunk size needs its own storage
132 * location (i.e., it overflows 24 bits).
133 * Returns the start offset of the chunk. This is the location at which
134 * the opcode & size are stored.
135 * TODO: since we are handing the size into here we could call reserve
136 * and then return a pointer to the memory storage. This could decrease
137 * allocation overhead but could lead to more wasted space (the tail
138 * end of blocks could go unused). Possibly add a second addDraw that
139 * operates in this manner.
140 */
141 size_t addDraw(DrawType drawType, size_t* size) {
142 size_t offset = fWriter.bytesWritten();
143
144 SkASSERT_RELEASE(this->predrawNotify());
145
146 SkASSERT(0 != *size);
147 SkASSERT(((uint8_t) drawType) == drawType);
148
149 if (0 != (*size & ~MASK_24) || *size == MASK_24) {
150 fWriter.writeInt(PACK_8_24(drawType, MASK_24));
151 *size += 1;
152 fWriter.writeInt(SkToU32(*size));
153 } else {
154 fWriter.writeInt(PACK_8_24(drawType, SkToU32(*size)));
155 }
156
157 return offset;
158 }
159
160 void addInt(int value) {
161 fWriter.writeInt(value);
162 }
163 void addScalar(SkScalar scalar) {
164 fWriter.writeScalar(scalar);
165 }
166
167 void addImage(const SkImage*);
168 void addMatrix(const SkMatrix& matrix);
169 void addPaint(const SkPaint& paint) { this->addPaintPtr(&paint); }
170 void addPaintPtr(const SkPaint* paint);
171 void addPatch(const SkPoint cubics[12]);
172 void addPath(const SkPath& path);
173 void addPicture(const SkPicture* picture);
174 void addDrawable(SkDrawable* picture);
175 void addPoint(const SkPoint& point);
176 void addPoints(const SkPoint pts[], int count);
177 void addRect(const SkRect& rect);
178 void addRectPtr(const SkRect* rect);
179 void addIRect(const SkIRect& rect);
180 void addIRectPtr(const SkIRect* rect);
181 void addRRect(const SkRRect&);
182 void addRegion(const SkRegion& region);
183 void addSampling(const SkSamplingOptions&);
184 void addText(const void* text, size_t byteLength);
185 void addTextBlob(const SkTextBlob* blob);
186 void addSlug(const sktext::gpu::Slug* slug);
187 void addVertices(const SkVertices*);
188
189 int find(const SkBitmap& bitmap);
190
191protected:
192 void validate(size_t initialOffset, size_t size) const {
193 SkASSERT(fWriter.bytesWritten() == initialOffset + size);
194 }
195
197 bool onPeekPixels(SkPixmap*) override { return false; }
198
199 void willSave() override;
200 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
201 bool onDoSaveBehind(const SkRect*) override;
202 void willRestore() override;
203
204 void didConcat44(const SkM44&) override;
205 void didSetM44(const SkM44&) override;
206 void didScale(SkScalar, SkScalar) override;
207 void didTranslate(SkScalar, SkScalar) override;
208
209 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
210
211 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
212 const SkPaint& paint) override;
213 void onDrawSlug(const sktext::gpu::Slug* slug, const SkPaint& paint) override;
214 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
215 const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint) override;
216
217 void onDrawPaint(const SkPaint&) override;
218 void onDrawBehind(const SkPaint&) override;
219 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
220 void onDrawRect(const SkRect&, const SkPaint&) override;
221 void onDrawRegion(const SkRegion&, const SkPaint&) override;
222 void onDrawOval(const SkRect&, const SkPaint&) override;
223 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
224 void onDrawRRect(const SkRRect&, const SkPaint&) override;
225 void onDrawPath(const SkPath&, const SkPaint&) override;
226
228 const SkPaint*) override;
229 void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
230 const SkPaint*, SrcRectConstraint) override;
231 void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode,
232 const SkPaint*) override;
233 void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
234 SkBlendMode, const SkSamplingOptions&, const SkRect*, const SkPaint*) override;
235
236 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
237 void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
238
239 void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
240 void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
241 void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
242 void onClipShader(sk_sp<SkShader>, SkClipOp) override;
243 void onClipRegion(const SkRegion&, SkClipOp) override;
244 void onResetClip() override;
245
246 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
247
248 void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
249 void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
250
251 void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
252 SkBlendMode) override;
253 void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
254 const SkSamplingOptions&,const SkPaint*, SrcRectConstraint) override;
255
256 int addPathToHeap(const SkPath& path); // does not write to ops stream
257
258 // These entry points allow the writing of matrices, clips, saves &
259 // restores to be deferred (e.g., if the MC state is being collapsed and
260 // only written out as needed).
261 void recordConcat(const SkMatrix& matrix);
262 void recordTranslate(const SkMatrix& matrix);
263 void recordScale(const SkMatrix& matrix);
264 size_t recordClipRect(const SkRect& rect, SkClipOp op, bool doAA);
265 size_t recordClipRRect(const SkRRect& rrect, SkClipOp op, bool doAA);
266 size_t recordClipPath(int pathID, SkClipOp op, bool doAA);
267 size_t recordClipRegion(const SkRegion& region, SkClipOp op);
268 void recordSave();
269 void recordSaveLayer(const SaveLayerRec&);
270 void recordRestore(bool fillInSkips = true);
271
272private:
274
275 struct PathHash {
276 uint32_t operator()(const SkPath& p) { return p.getGenerationID(); }
277 };
279
280 SkWriter32 fWriter;
281
288
289 uint32_t fRecordFlags;
290 int fInitialSaveCount;
291
292 friend class SkPictureData; // for SkPictureData's SkPictureRecord-based constructor
293};
294
295#endif
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBlendMode
Definition: SkBlendMode.h:38
SkClipOp
Definition: SkClipOp.h:13
uint32_t SkColor
Definition: SkColor.h:37
#define PACK_8_24(small, large)
#define MASK_24
SkFilterMode
constexpr uint32_t SkToU32(S x)
Definition: SkTo.h:26
SrcRectConstraint
Definition: SkCanvas.h:1541
SaveLayerStrategy
Definition: SkCanvas.h:2263
friend class SkPictureRecord
Definition: SkCanvas.h:2493
Definition: SkData.h:25
static sk_sp< SkData > MakeEmpty()
Definition: SkData.cpp:94
Definition: SkM44.h:150
Definition: SkPath.h:59
void onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint) override
void onDrawImage2(const SkImage *, SkScalar, SkScalar, const SkSamplingOptions &, const SkPaint *) override
void willSave() override
const skia_private::TArray< sk_sp< const SkPicture > > & getPictures() const
void onDrawSlug(const sktext::gpu::Slug *slug, const SkPaint &paint) override
void onDrawDrawable(SkDrawable *, const SkMatrix *) override
void onDrawRect(const SkRect &, const SkPaint &) override
void onDrawArc(const SkRect &, SkScalar, SkScalar, bool, const SkPaint &) override
void onDrawBehind(const SkPaint &) override
void onClipRect(const SkRect &, SkClipOp, ClipEdgeStyle) override
void validate(size_t initialOffset, size_t size) const
void onClipRRect(const SkRRect &, SkClipOp, ClipEdgeStyle) override
void recordSaveLayer(const SaveLayerRec &)
void recordScale(const SkMatrix &matrix)
size_t recordClipRRect(const SkRRect &rrect, SkClipOp op, bool doAA)
int addPathToHeap(const SkPath &path)
const skia_private::TArray< sk_sp< const SkTextBlob > > & getTextBlobs() const
void onDrawPaint(const SkPaint &) override
void onDrawPicture(const SkPicture *, const SkMatrix *, const SkPaint *) override
const skia_private::TArray< sk_sp< const SkImage > > & getImages() const
void recordRestore(bool fillInSkips=true)
void willRestore() override
const skia_private::TArray< sk_sp< const SkVertices > > & getVertices() const
void onDrawOval(const SkRect &, const SkPaint &) override
void onDrawAnnotation(const SkRect &, const char[], SkData *) override
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint &) override
void onDrawEdgeAAQuad(const SkRect &, const SkPoint[4], QuadAAFlags, const SkColor4f &, SkBlendMode) override
sk_sp< SkData > opData() const
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec &) override
void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode, const SkPaint &paint) override
void didScale(SkScalar, SkScalar) override
void onDrawAtlas2(const SkImage *, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode, const SkSamplingOptions &, const SkRect *, const SkPaint *) override
bool onDoSaveBehind(const SkRect *) override
void onDrawVerticesObject(const SkVertices *, SkBlendMode, const SkPaint &) override
void onDrawRegion(const SkRegion &, const SkPaint &) override
bool onPeekPixels(SkPixmap *) override
void recordTranslate(const SkMatrix &matrix)
const SkWriter32 & writeStream() const
const skia_private::TArray< sk_sp< SkDrawable > > & getDrawables() const
void onClipRegion(const SkRegion &, SkClipOp) override
void recordConcat(const SkMatrix &matrix)
void onDrawShadowRec(const SkPath &, const SkDrawShadowRec &) override
size_t recordClipPath(int pathID, SkClipOp op, bool doAA)
void onDrawPath(const SkPath &, const SkPaint &) override
const skia_private::TArray< sk_sp< const sktext::gpu::Slug > > & getSlugs() const
void didConcat44(const SkM44 &) override
size_t recordClipRect(const SkRect &rect, SkClipOp op, bool doAA)
void onDrawRRect(const SkRRect &, const SkPaint &) override
void onResetClip() override
void onClipPath(const SkPath &, SkClipOp, ClipEdgeStyle) override
size_t recordClipRegion(const SkRegion &region, SkClipOp op)
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[], const SkSamplingOptions &, const SkPaint *, SrcRectConstraint) override
void onDrawDRRect(const SkRRect &, const SkRRect &, const SkPaint &) override
void onDrawImageRect2(const SkImage *, const SkRect &, const SkRect &, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint) override
void onClipShader(sk_sp< SkShader >, SkClipOp) override
void didTranslate(SkScalar, SkScalar) override
sk_sp< SkSurface > onNewSurface(const SkImageInfo &, const SkSurfaceProps &) override
void didSetM44(const SkM44 &) override
void onDrawImageLattice2(const SkImage *, const Lattice &, const SkRect &, SkFilterMode, const SkPaint *) override
void setFlags(uint32_t recordFlags)
void writeInt(int32_t value)
Definition: SkWriter32.h:105
void writeScalar(SkScalar value)
Definition: SkWriter32.h:121
sk_sp< SkData > snapshotAsData() const
Definition: SkWriter32.cpp:78
size_t bytesWritten() const
Definition: SkWriter32.h:48
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
uint8_t value
std::u16string text
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkColor > colors
Definition: SkRecords.h:276
Definition: bitmap.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
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SeparatedVector2 offset
Definition: SkRect.h:32
Definition: SkSize.h:16