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