aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pipe/SkPipeFormat.h
blob: 13fdca5012fd1eade7a063d3fa6b8e82216e292d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkPipeFormat_DEFINED
#define SkPipeFormat_DEFINED

#include "SkTypes.h"

#define kDefinePicture_ExtPipeVerb  SkSetFourByteTag('s', 'k', 'p', 'i')

enum class SkPipeVerb : uint8_t {
    kSave,              // extra == 0
    kSaveLayer,
    kRestore,           // extra == 0
    kConcat,            // extra == SkMatrix::MaskType

    kClipRect,          // extra == (SkRegion::Op << 1) | isAntiAlias:1
    kClipRRect,         // extra == (SkRegion::Op << 1) | isAntiAlias:1
    kClipPath,          // extra == (SkRegion::Op << 1) | isAntiAlias:1
    kClipRegion,        // extra == (SkRegion::Op << 1)

    kDrawArc,           // extra == useCenter
    kDrawAtlas,         // extra == has_colors | has_cull | has_paint | mode
    kDrawDRRect,
    kDrawText,          // extra == byteLength:24 else next 32
    kDrawPosText,       // extra == byteLength:24 else next 32
    kDrawPosTextH,      // extra == byteLength:24 else next 32
    kDrawRegion,        // extra == size:24 of region, or 0 means next 32
    kDrawTextOnPath,
    kDrawTextBlob,
    kDrawTextRSXform,   // extra == (byteLength:23 << 1) else next 32 | has_cull_rect:1
    kDrawPatch,
    kDrawPaint,         // extra == 0
    kDrawPoints,        // extra == PointMode
    kDrawRect,          // extra == 0
    kDrawPath,          // extra == 0
    kDrawShadowRec,     // extra == 0
    kDrawOval,          // extra == 0
    kDrawRRect,         // extra == 0

    kDrawImage,         // extra == has_paint:1
    kDrawImageRect,     // extra == constraint | has_src_rect | has_paint
    kDrawImageNine,     // extra == has_paint:1
    kDrawImageLattice,  // extra == has_paint:1

    kDrawVertices,

    kDrawPicture,       // extra == picture_index
    kDrawAnnotation,    // extra == (key_len_plus_1:23 << 1) else next 32 | has_data:1

    kDefineImage,       // extra == image_index
    kDefineTypeface,
    kDefineFactory,     // extra == factory_index (followed by padded getTypeName string)
    kDefinePicture,     // extra == 0 or forget_index + 1 (0 means we're defining a new picture)
    kEndPicture,        // extra == picture_index
    kWriteImage,        // extra == image_index
    kWritePicture,      // extra == picture_index
};

enum PaintUsage {
    kText_PaintUsage        = 1 << 0,
    kTextBlob_PaintUsage    = 1 << 1,
    kGeometry_PaintUsage    = 1 << 2,
    kImage_PaintUsage       = 1 << 3,
    kSaveLayer_PaintUsage   = 1 << 4,
    kDrawPaint_PaintUsage   = 1 << 5,
    kVertices_PaintUsage    = 1 << 6,
    kRespectsStroke_PaintUsage  = 1 << 7,
    kUnknown_PaintUsage     = 0xFF,
};

// must sum to <= 32
enum BitsPerField {
    kFlags_BPF      = 16,
    kFilter_BPF     = 2,
    kStyle_BPF      = 2,
    kCaps_BPF       = 2,
    kJoins_BPF      = 2,
    kHint_BPF       = 2,
    kAlign_BPF      = 2,
    kEncoding_BPF   = 2,
};

enum {
    kTextSize_NonDef    = 1 << 0,
    kTextScaleX_NonDef  = 1 << 1,
    kTextSkewX_NonDef   = 1 << 2,
    kStrokeWidth_NonDef = 1 << 3,
    kStrokeMiter_NonDef = 1 << 4,
    kColor_NonDef       = 1 << 5,
    kTypeface_NonDef    = 1 << 6,
    kPathEffect_NonDef  = 1 << 7,
    kShader_NonDef      = 1 << 8,
    kMaskFilter_NonDef  = 1 << 9,
    kColorFilter_NonDef = 1 << 10,
    kRasterizer_NonDef  = 1 << 11,
    kImageFilter_NonDef = 1 << 12,
    kDrawLooper_NonDef  = 1 << 13,
};

enum {
    kFlags_SaveLayerMask            = 0xFF,
    kHasBounds_SaveLayerMask        = 1 << 8,
    kHasPaint_SaveLayerMask         = 1 << 9,
    kHasBackdrop_SaveLayerMask      = 1 << 10,
    kDontClipToLayer_SaveLayerMask  = 1 << 11,
    kHasClipMask_SaveLayerMask      = 1 << 12,
    kHasClipMatrix_SaveLayerMask    = 1 << 13,
};

enum {
    kObjectDefinitionBits           = 20,
    kIndex_ObjectDefinitionMask     = ((1 << kObjectDefinitionBits) - 1),
    kUser_ObjectDefinitionMask      = 0x7 << kObjectDefinitionBits,
    kUndef_ObjectDefinitionMask     = 1 << 23,
    // (Undef:1 | User:3 | Index:20) must fit in extra:24
};

enum {
    kTypeMask_ConcatMask    = 0xF,
    kSetMatrix_ConcatMask   = 1 << 4,
};

enum {
    kMode_DrawAtlasMask         = 0xFF,
    kHasColors_DrawAtlasMask    = 1 << 8,
    kHasCull_DrawAtlasMask      = 1 << 9,
    kHasPaint_DrawAtlasMask     = 1 << 10,
};

enum {
    kHasPaint_DrawImageMask     = 1 << 0,
};

enum {
    kConstraint_DrawImageRectMask   = 1 << 0,
    kHasPaint_DrawImageRectMask     = 1 << 1,
    kHasSrcRect_DrawImageRectMask   = 1 << 2,
};

enum {
    kHasPaint_DrawImageNineMask     = 1 << 0,
};

enum {
    // picture_index takes the first kObjectDefinitionBits bits
    kHasMatrix_DrawPictureExtra = 1 << 21,
    kHasPaint_DrawPictureExtra  = 1 << 22,
};

enum {
    kIndex_DefineFactoryExtraBits       = 10,
    kNameLength_DefineFactoryExtraBits  = 14,   // includes trailing 0
    kNameLength_DefineFactoryExtraMask  = (1 << kNameLength_DefineFactoryExtraBits) - 1,
};

enum {
    kModeEnum_DrawPatchExtraMask        = 0xFF,
    kExplicitXfer_DrawPatchExtraValue   = 0xFF,
    kHasColors_DrawPatchExtraMask       = 0x100,
    kHasTexture_DrawPatchExtraMask      = 0x200,
};

enum {
    // if we store a zero for VCount, then read an int after the packedverb for the vcount
    kVCount_DrawVerticesMask            = (1 << 11) - 1,

    kVMode_DrawVerticesShift            = 11,
    kVMode_DrawVerticesMask             = 3 << kVMode_DrawVerticesShift,

    kXMode_DrawVerticesShift            = 13,
    kXMode_DrawVerticesMask             = 0xFF << kXMode_DrawVerticesShift,

    kHasTex_DrawVerticesMask            = 1 << 21,
    kHasColors_DrawVerticesMask         = 1 << 22,
    kHasIndices_DrawVerticesMask        = 1 << 23,
};

enum {
    kTextLength_DrawTextOnPathMask      = (1 << 16) - 1,
    kMatrixType_DrawTextOnPathShift     = 16,
    kMatrixType_DrawTextOnPathMask      = 0xF << kMatrixType_DrawTextOnPathShift,
};

enum {
    kHasPaint_DrawImageLatticeMask  = 1 << 0,
    kHasFlags_DrawImageLatticeMask  = 1 << 1,
    kXCount_DrawImageLatticeShift   = 2,        // bits  2:9  are xcount or FF means 32bits follow
    kYCount_DrawImageLatticeShift   = 10,       // bits 10:17 are ycount or FF means 32bits follow
    kCount_DrawImageLatticeMask     = 0xFF,     // sentinel for 32bits follow,
                                                // thus max inline count is 254
};

///////////////////////////////////////////////////////////////////////////////////////////////////

static inline bool fits_in(int value, int bits) {
    return value >= 0 && value < (1 << bits);
}

static inline void ASSERT_FITS_IN(int value, int bits) {
    SkASSERT(fits_in(value, bits));
}

static inline uint32_t pack_verb(SkPipeVerb verb, unsigned extra = 0) {
    //SkDebugf("pack [%d] %d\n", verb, extra);
    ASSERT_FITS_IN((unsigned)verb, 8);
    ASSERT_FITS_IN(extra, 24);
    return ((uint32_t)verb << 24) | extra;
}

static inline SkPipeVerb unpack_verb(uint32_t data) {
    return (SkPipeVerb)(data >> 24);
}

static inline unsigned unpack_verb_extra(uint32_t data) {
    return data & 0xFFFFFF;
}

#endif