Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPictureFlat.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#ifndef SkPictureFlat_DEFINED
8#define SkPictureFlat_DEFINED
9
18
19#include <cstddef>
20#include <cstdint>
21#include <memory>
22
23enum class SkClipOp;
24
25/*
26 * Note: While adding new DrawTypes, it is necessary to add to the end of this list
27 * and update LAST_DRAWTYPE_ENUM to avoid having the code read older skps wrong.
28 * (which can cause segfaults)
29 *
30 * Reordering can be done during version updates.
31 */
73
74 // new ops -- feel free to re-alphabetize on next version bump
76 PUSH_CULL, // deprecated, M41 was last Chromium version to write this to an .skp
77 POP_CULL, // deprecated, M41 was last Chromium version to write this to an .skp
78
79 DRAW_PATCH, // could not add in aphabetical order
87
90
95
96 TRANSLATE_Z, // deprecated (M60)
97
103
104 FLUSH, // no-op
105
107
109
111
115 MARK_CTM, // deprecated
117
122
124
126
128};
129
136
142
146
157
161
162///////////////////////////////////////////////////////////////////////////////
163// clipparams are packed in 5 bits
164// doAA:1 | clipOp:4
165
166// Newly serialized pictures will only write kIntersect or kDifference.
167static inline uint32_t ClipParams_pack(SkClipOp op, bool doAA) {
168 unsigned doAABit = doAA ? 1 : 0;
169 return (doAABit << 4) | static_cast<int>(op);
170}
171
172// But old SKPs may have been serialized with the SK_SUPPORT_DEPRECATED_CLIPOP flag, so might
173// encounter expanding clip ops. Thus, this returns the clip op as the more general Region::Op.
175 uint32_t unpacked = packed & 0xF;
176 if (buffer->validate(unpacked <= SkRegion::kIntersect_Op ||
177 (unpacked <= SkRegion::kReplace_Op &&
179 return static_cast<SkRegion::Op>(unpacked);
180 }
182}
183
184static inline bool ClipParams_unpackDoAA(uint32_t packed) {
185 return SkToBool((packed >> 4) & 1);
186}
187
188///////////////////////////////////////////////////////////////////////////////
189
191public:
192 SkTypefacePlayback() : fCount(0), fArray(nullptr) {}
194
195 void setCount(size_t count);
196
197 size_t count() const { return fCount; }
198
200 SkASSERT(index < fCount);
201 return fArray[index];
202 }
203
205 buffer.setTypefaceArray(fArray.get(), fCount);
206 }
207
208protected:
209 size_t fCount;
210 std::unique_ptr<sk_sp<SkTypeface>[]> fArray;
211};
212
214public:
215 SkFactoryPlayback(int count) : fCount(count) { fArray = new SkFlattenable::Factory[count]; }
216
217 ~SkFactoryPlayback() { delete[] fArray; }
218
219 SkFlattenable::Factory* base() const { return fArray; }
220
222 buffer.setFactoryPlayback(fArray, fCount);
223 }
224
225private:
226 int fCount;
228};
229
230#endif
int count
#define SkASSERT(cond)
Definition SkAssert.h:116
SkClipOp
Definition SkClipOp.h:13
SaveBehindFlatFlags
@ SAVEBEHIND_HAS_SUBSET
static SkRegion::Op ClipParams_unpackRegionOp(SkReadBuffer *buffer, uint32_t packed)
@ DRAW_EDGEAA_QUAD
@ BEGIN_COMMENT_GROUP_obsolete
@ DRAW_PATH
@ TRANSLATE_Z
@ DRAW_BITMAP_MATRIX_RETIRED_2016_REMOVED_2018
@ RESTORE
@ SET_M44
@ CLIP_PATH
@ SAVE_LAYER_SAVELAYERFLAGS_DEPRECATED_JAN_2016_REMOVED_01_2018
@ DRAW_POS_TEXT_REMOVED_1_2019
@ DRAW_PAINT
@ DRAW_SLUG
@ DRAW_PICTURE_MATRIX_PAINT
@ DRAW_EDGEAA_IMAGE_SET
@ DRAW_REGION
@ SET_MATRIX
@ FLUSH
@ DRAW_DATA
@ ROTATE
@ DRAW_DRAWABLE
@ DRAW_IMAGE_RECT2
@ DRAW_IMAGE2
@ DRAW_RRECT
@ DRAW_DRRECT
@ SCALE
@ LAST_DRAWTYPE_ENUM
@ DRAW_TEXT_REMOVED_1_2019
@ DRAW_IMAGE_RECT
@ DRAW_BITMAP_RETIRED_2016_REMOVED_2018
@ DRAW_PATCH
@ DRAW_BEHIND_PAINT
@ DRAW_EDGEAA_IMAGE_SET2
@ DRAW_TEXT_BLOB
@ DRAW_PICTURE
@ PUSH_CULL
@ SKEW
@ CONCAT44
@ NOOP
@ SAVE
@ DRAW_BITMAP_RECT_RETIRED_2016_REMOVED_2018
@ DRAW_IMAGE
@ RESET_CLIP
@ DRAW_DRAWABLE_MATRIX
@ DRAW_ARC
@ DRAW_RECT
@ DRAW_POS_TEXT_H_REMOVED_1_2019
@ DRAW_VERTICES_OBJECT
@ DRAW_VERTICES_RETIRED_03_2017_REMOVED_01_2018
@ MARK_CTM
@ DRAW_ANNOTATION
@ CONCAT
@ DRAW_TEXT_TOP_BOTTOM_REMOVED_1_2019
@ DRAW_TEXT_ON_PATH_RETIRED_08_2018_REMOVED_10_2018
@ SAVE_LAYER_SAVEFLAGS_DEPRECATED_2015_REMOVED_12_2020
@ DRAW_IMAGE_NINE
@ UNUSED
@ SAVE_BEHIND
@ DRAW_IMAGE_LATTICE
@ DRAW_POINTS
@ DRAW_SHADOW_REC
@ SAVE_LAYER_SAVELAYERREC
@ END_COMMENT_GROUP_obsolete
@ DRAW_ATLAS
@ DRAW_TEXT_RSXFORM_DEPRECATED_DEC_2018
@ CLIP_RRECT
@ TRANSLATE
@ COMMENT_obsolete
@ DRAW_OVAL
@ CLIP_REGION
@ DRAW_CLEAR
@ CLIP_SHADER_IN_PAINT
@ DRAW_IMAGE_RECT_STRICT_obsolete
@ DRAW_POS_TEXT_H_TOP_BOTTOM_REMOVED_1_2019
@ DRAW_BITMAP_NINE_RETIRED_2016_REMOVED_2018
@ CLIP_RECT
@ DRAW_SPRITE_RETIRED_2015_REMOVED_2018
@ DRAW_POS_TEXT_TOP_BOTTOM_REMOVED_1_2019
@ POP_CULL
@ DRAW_IMAGE_LATTICE2
static uint32_t ClipParams_pack(SkClipOp op, bool doAA)
static bool ClipParams_unpackDoAA(uint32_t packed)
SaveLayerRecFlatFlags
@ SAVELAYERREC_HAS_FLAGS
@ SAVELAYERREC_HAS_BACKDROP_SCALE
@ SAVELAYERREC_HAS_MULTIPLE_FILTERS
@ SAVELAYERREC_HAS_PAINT
@ SAVELAYERREC_HAS_CLIPMASK_OBSOLETE
@ SAVELAYERREC_HAS_CLIPMATRIX_OBSOLETE
@ SAVELAYERREC_HAS_BACKDROP
@ SAVELAYERREC_HAS_BOUNDS
DrawVertexFlags
@ DRAW_VERTICES_HAS_TEXS
@ DRAW_VERTICES_HAS_XFER
@ DRAW_VERTICES_HAS_INDICES
@ DRAW_VERTICES_HAS_COLORS
DrawTextRSXformFlags
@ DRAW_TEXT_RSXFORM_HAS_CULL
DrawAtlasFlags
@ DRAW_ATLAS_HAS_SAMPLING
@ DRAW_ATLAS_HAS_COLORS
@ DRAW_ATLAS_HAS_CULL
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
SkFlattenable::Factory * base() const
void setupBuffer(SkReadBuffer &buffer) const
SkFactoryPlayback(int count)
sk_sp< SkFlattenable >(* Factory)(SkReadBuffer &)
@ kReplace_Op
replace target with operand
Definition SkRegion.h:372
@ kIntersect_Op
target intersected with operand
Definition SkRegion.h:368
void setupBuffer(SkReadBuffer &buffer) const
size_t count() const
~SkTypefacePlayback()=default
void setCount(size_t count)
sk_sp< SkTypeface > & operator[](size_t index)
std::unique_ptr< sk_sp< SkTypeface >[]> fArray
static const uint8_t buffer[]