• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 SkPipeFormat_DEFINED
9 #define SkPipeFormat_DEFINED
10 
11 #include "SkTypes.h"
12 
13 #define kDefinePicture_ExtPipeVerb  SkSetFourByteTag('s', 'k', 'p', 'i')
14 
15 enum class SkPipeVerb : uint8_t {
16     kSave,              // extra == 0
17     kSaveLayer,
18     kRestore,           // extra == 0
19     kConcat,            // extra == SkMatrix::MaskType
20 
21     kClipRect,          // extra == (SkRegion::Op << 1) | isAntiAlias:1
22     kClipRRect,         // extra == (SkRegion::Op << 1) | isAntiAlias:1
23     kClipPath,          // extra == (SkRegion::Op << 1) | isAntiAlias:1
24     kClipRegion,        // extra == (SkRegion::Op << 1)
25 
26     kDrawArc,           // extra == useCenter
27     kDrawAtlas,         // extra == has_colors | has_cull | has_paint | mode
28     kDrawDRRect,
29     kDrawText,          // extra == byteLength:24 else next 32
30     kDrawPosText,       // extra == byteLength:24 else next 32
31     kDrawPosTextH,      // extra == byteLength:24 else next 32
32     kDrawRegion,        // extra == size:24 of region, or 0 means next 32
33     kDrawTextOnPath,
34     kDrawTextBlob,
35     kDrawTextRSXform,   // extra == (byteLength:23 << 1) else next 32 | has_cull_rect:1
36     kDrawPatch,
37     kDrawPaint,         // extra == 0
38     kDrawPoints,        // extra == PointMode
39     kDrawRect,          // extra == 0
40     kDrawPath,          // extra == 0
41     kDrawShadowRec,     // extra == 0
42     kDrawOval,          // extra == 0
43     kDrawRRect,         // extra == 0
44 
45     kDrawImage,         // extra == has_paint:1
46     kDrawImageRect,     // extra == constraint | has_src_rect | has_paint
47     kDrawImageNine,     // extra == has_paint:1
48     kDrawImageLattice,  // extra == has_paint:1
49 
50     kDrawVertices,
51 
52     kDrawPicture,       // extra == picture_index
53     kDrawAnnotation,    // extra == (key_len_plus_1:23 << 1) else next 32 | has_data:1
54 
55     kDefineImage,       // extra == image_index
56     kDefineTypeface,
57     kDefineFactory,     // extra == factory_index (followed by padded getTypeName string)
58     kDefinePicture,     // extra == 0 or forget_index + 1 (0 means we're defining a new picture)
59     kEndPicture,        // extra == picture_index
60     kWriteImage,        // extra == image_index
61     kWritePicture,      // extra == picture_index
62 };
63 
64 enum PaintUsage {
65     kText_PaintUsage        = 1 << 0,
66     kTextBlob_PaintUsage    = 1 << 1,
67     kGeometry_PaintUsage    = 1 << 2,
68     kImage_PaintUsage       = 1 << 3,
69     kSaveLayer_PaintUsage   = 1 << 4,
70     kDrawPaint_PaintUsage   = 1 << 5,
71     kVertices_PaintUsage    = 1 << 6,
72     kRespectsStroke_PaintUsage  = 1 << 7,
73     kUnknown_PaintUsage     = 0xFF,
74 };
75 
76 // must sum to <= 32
77 enum BitsPerField {
78     kFlags_BPF      = 16,
79     kFilter_BPF     = 2,
80     kStyle_BPF      = 2,
81     kCaps_BPF       = 2,
82     kJoins_BPF      = 2,
83     kHint_BPF       = 2,
84     kAlign_BPF      = 2,
85     kEncoding_BPF   = 2,
86 };
87 
88 enum {
89     kTextSize_NonDef    = 1 << 0,
90     kTextScaleX_NonDef  = 1 << 1,
91     kTextSkewX_NonDef   = 1 << 2,
92     kStrokeWidth_NonDef = 1 << 3,
93     kStrokeMiter_NonDef = 1 << 4,
94     kColor_NonDef       = 1 << 5,
95     kTypeface_NonDef    = 1 << 6,
96     kPathEffect_NonDef  = 1 << 7,
97     kShader_NonDef      = 1 << 8,
98     kMaskFilter_NonDef  = 1 << 9,
99     kColorFilter_NonDef = 1 << 10,
100     kRasterizer_NonDef  = 1 << 11,
101     kImageFilter_NonDef = 1 << 12,
102     kDrawLooper_NonDef  = 1 << 13,
103 };
104 
105 enum {
106     kFlags_SaveLayerMask            = 0xFF,
107     kHasBounds_SaveLayerMask        = 1 << 8,
108     kHasPaint_SaveLayerMask         = 1 << 9,
109     kHasBackdrop_SaveLayerMask      = 1 << 10,
110     kDontClipToLayer_SaveLayerMask  = 1 << 11,
111     kHasClipMask_SaveLayerMask      = 1 << 12,
112     kHasClipMatrix_SaveLayerMask    = 1 << 13,
113 };
114 
115 enum {
116     kObjectDefinitionBits           = 20,
117     kIndex_ObjectDefinitionMask     = ((1 << kObjectDefinitionBits) - 1),
118     kUser_ObjectDefinitionMask      = 0x7 << kObjectDefinitionBits,
119     kUndef_ObjectDefinitionMask     = 1 << 23,
120     // (Undef:1 | User:3 | Index:20) must fit in extra:24
121 };
122 
123 enum {
124     kTypeMask_ConcatMask    = 0xF,
125     kSetMatrix_ConcatMask   = 1 << 4,
126 };
127 
128 enum {
129     kMode_DrawAtlasMask         = 0xFF,
130     kHasColors_DrawAtlasMask    = 1 << 8,
131     kHasCull_DrawAtlasMask      = 1 << 9,
132     kHasPaint_DrawAtlasMask     = 1 << 10,
133 };
134 
135 enum {
136     kHasPaint_DrawImageMask     = 1 << 0,
137 };
138 
139 enum {
140     kConstraint_DrawImageRectMask   = 1 << 0,
141     kHasPaint_DrawImageRectMask     = 1 << 1,
142     kHasSrcRect_DrawImageRectMask   = 1 << 2,
143 };
144 
145 enum {
146     kHasPaint_DrawImageNineMask     = 1 << 0,
147 };
148 
149 enum {
150     // picture_index takes the first kObjectDefinitionBits bits
151     kHasMatrix_DrawPictureExtra = 1 << 21,
152     kHasPaint_DrawPictureExtra  = 1 << 22,
153 };
154 
155 enum {
156     kIndex_DefineFactoryExtraBits       = 10,
157     kNameLength_DefineFactoryExtraBits  = 14,   // includes trailing 0
158     kNameLength_DefineFactoryExtraMask  = (1 << kNameLength_DefineFactoryExtraBits) - 1,
159 };
160 
161 enum {
162     kModeEnum_DrawPatchExtraMask        = 0xFF,
163     kExplicitXfer_DrawPatchExtraValue   = 0xFF,
164     kHasColors_DrawPatchExtraMask       = 0x100,
165     kHasTexture_DrawPatchExtraMask      = 0x200,
166 };
167 
168 enum {
169     // if we store a zero for VCount, then read an int after the packedverb for the vcount
170     kVCount_DrawVerticesMask            = (1 << 11) - 1,
171 
172     kVMode_DrawVerticesShift            = 11,
173     kVMode_DrawVerticesMask             = 3 << kVMode_DrawVerticesShift,
174 
175     kXMode_DrawVerticesShift            = 13,
176     kXMode_DrawVerticesMask             = 0xFF << kXMode_DrawVerticesShift,
177 
178     kHasTex_DrawVerticesMask            = 1 << 21,
179     kHasColors_DrawVerticesMask         = 1 << 22,
180     kHasIndices_DrawVerticesMask        = 1 << 23,
181 };
182 
183 enum {
184     kTextLength_DrawTextOnPathMask      = (1 << 16) - 1,
185     kMatrixType_DrawTextOnPathShift     = 16,
186     kMatrixType_DrawTextOnPathMask      = 0xF << kMatrixType_DrawTextOnPathShift,
187 };
188 
189 enum {
190     kHasPaint_DrawImageLatticeMask  = 1 << 0,
191     kHasFlags_DrawImageLatticeMask  = 1 << 1,
192     kXCount_DrawImageLatticeShift   = 2,        // bits  2:9  are xcount or FF means 32bits follow
193     kYCount_DrawImageLatticeShift   = 10,       // bits 10:17 are ycount or FF means 32bits follow
194     kCount_DrawImageLatticeMask     = 0xFF,     // sentinel for 32bits follow,
195                                                 // thus max inline count is 254
196 };
197 
198 ///////////////////////////////////////////////////////////////////////////////////////////////////
199 
fits_in(int value,int bits)200 static inline bool fits_in(int value, int bits) {
201     return value >= 0 && value < (1 << bits);
202 }
203 
ASSERT_FITS_IN(int value,int bits)204 static inline void ASSERT_FITS_IN(int value, int bits) {
205     SkASSERT(fits_in(value, bits));
206 }
207 
208 static inline uint32_t pack_verb(SkPipeVerb verb, unsigned extra = 0) {
209     //SkDebugf("pack [%d] %d\n", verb, extra);
210     ASSERT_FITS_IN((unsigned)verb, 8);
211     ASSERT_FITS_IN(extra, 24);
212     return ((uint32_t)verb << 24) | extra;
213 }
214 
unpack_verb(uint32_t data)215 static inline SkPipeVerb unpack_verb(uint32_t data) {
216     return (SkPipeVerb)(data >> 24);
217 }
218 
unpack_verb_extra(uint32_t data)219 static inline unsigned unpack_verb_extra(uint32_t data) {
220     return data & 0xFFFFFF;
221 }
222 
223 #endif
224