SkGPipePriv.h revision 67908f2faee17a8bce4d074980617cc0d15fabf1
1/*
2    Copyright 2011 Google Inc.
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 */
16
17
18#ifndef SkGPipePriv_DEFINED
19#define SkGPipePriv_DEFINED
20
21#include "SkTypes.h"
22
23#define UNIMPLEMENTED
24
25// these must be contiguous, 0...N-1
26enum PaintFlats {
27    kColorFilter_PaintFlat,
28    kDrawLooper_PaintFlat,
29    kMaskFilter_PaintFlat,
30    kPathEffect_PaintFlat,
31    kRasterizer_PaintFlat,
32    kShader_PaintFlat,
33    kXfermode_PaintFlat,
34
35    kLast_PaintFlat = kXfermode_PaintFlat
36};
37#define kCount_PaintFlats   (kLast_PaintFlat + 1)
38
39enum DrawOps {
40    kSkip_DrawOp,   // skip an addition N bytes (N == data)
41
42    // these match Canvas apis
43    kClipPath_DrawOp,
44    kClipRegion_DrawOp,
45    kClipRect_DrawOp,
46    kConcat_DrawOp,
47    kDrawBitmap_DrawOp,
48    kDrawBitmapMatrix_DrawOp,
49    kDrawBitmapRect_DrawOp,
50    kDrawClear_DrawOp,
51    kDrawData_DrawOp,
52    kDrawPaint_DrawOp,
53    kDrawPath_DrawOp,
54    kDrawPicture_DrawOp,
55    kDrawPoints_DrawOp,
56    kDrawPosText_DrawOp,
57    kDrawPosTextH_DrawOp,
58    kDrawRect_DrawOp,
59    kDrawSprite_DrawOp,
60    kDrawText_DrawOp,
61    kDrawTextOnPath_DrawOp,
62    kDrawVertices_DrawOp,
63    kRestore_DrawOp,
64    kRotate_DrawOp,
65    kSave_DrawOp,
66    kSaveLayer_DrawOp,
67    kScale_DrawOp,
68    kSetMatrix_DrawOp,
69    kSkew_DrawOp,
70    kTranslate_DrawOp,
71
72    kPaintOp_DrawOp,
73
74    kDef_Typeface_DrawOp,
75    kDef_Flattenable_DrawOp,
76
77    // these are signals to playback, not drawing verbs
78    kDone_DrawOp,
79};
80
81/**
82 *  DrawOp packs into a 32bit int as follows
83 *
84 *  DrawOp:8 - Flags:4 - Data:20
85 *
86 *  Flags and Data are called out separately, so we can reuse Data between
87 *  different Ops that might have different Flags. e.g. Data might be a Paint
88 *  index for both drawRect (no flags) and saveLayer (does have flags).
89 *
90 *  All Ops that take a SkPaint use their Data field to store the index to
91 *  the paint (previously defined with kPaintOp_DrawOp).
92 */
93
94#define DRAWOPS_OP_BITS     8
95#define DRAWOPS_FLAG_BITS   4
96#define DRAWOPS_DATA_BITS   20
97
98#define DRAWOPS_OP_MASK     ((1 << DRAWOPS_OP_BITS) - 1)
99#define DRAWOPS_FLAG_MASK   ((1 << DRAWOPS_FLAG_BITS) - 1)
100#define DRAWOPS_DATA_MASK   ((1 << DRAWOPS_DATA_BITS) - 1)
101
102static unsigned DrawOp_unpackOp(uint32_t op32) {
103    return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS));
104}
105
106static unsigned DrawOp_unpackFlags(uint32_t op32) {
107    return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK;
108}
109
110static unsigned DrawOp_unpackData(uint32_t op32) {
111    return op32 & DRAWOPS_DATA_MASK;
112}
113
114static uint32_t DrawOp_packOpFlagData(DrawOps op, unsigned flags, unsigned data) {
115    SkASSERT(0 == (op & ~DRAWOPS_OP_MASK));
116    SkASSERT(0 == (flags & ~DRAWOPS_FLAG_MASK));
117    SkASSERT(0 == (data & ~DRAWOPS_DATA_MASK));
118
119    return (op << (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)) |
120           (flags << DRAWOPS_DATA_BITS) |
121            data;
122}
123
124/** DrawOp specific flag bits
125 */
126
127enum {
128    kSaveLayer_HasBounds_DrawOpFlag = 1 << 0,
129    kSaveLayer_HasPaint_DrawOpFlag = 1 << 1,
130};
131enum {
132    kClear_HasColor_DrawOpFlag  = 1 << 0
133};
134enum {
135    kDrawTextOnPath_HasMatrix_DrawOpFlag = 1 << 0
136};
137enum {
138    kDrawVertices_HasTexs_DrawOpFlag     = 1 << 0,
139    kDrawVertices_HasColors_DrawOpFlag   = 1 << 1,
140    kDrawVertices_HasIndices_DrawOpFlag  = 1 << 2,
141};
142
143///////////////////////////////////////////////////////////////////////////////
144
145enum PaintOps {
146    kReset_PaintOp,     // no arg
147
148    kFlags_PaintOp,     // arg inline
149    kColor_PaintOp,     // arg 32
150    kStyle_PaintOp,     // arg inline
151    kJoin_PaintOp,      // arg inline
152    kCap_PaintOp,       // arg inline
153    kWidth_PaintOp,     // arg scalar
154    kMiter_PaintOp,// arg scalar
155
156    kEncoding_PaintOp,  // arg inline - text
157    kHinting_PaintOp,   // arg inline - text
158    kAlign_PaintOp,     // arg inline - text
159    kTextSize_PaintOp,  // arg scalar - text
160    kTextScaleX_PaintOp,// arg scalar - text
161    kTextSkewX_PaintOp, // arg scalar - text
162    kTypeface_PaintOp,  // arg inline (index) - text
163
164    kFlatIndex_PaintOp, // flags=paintflat, data=index
165};
166
167#define PAINTOPS_OP_BITS     8
168#define PAINTOPS_FLAG_BITS   4
169#define PAINTOPS_DATA_BITS   20
170
171#define PAINTOPS_OP_MASK     ((1 << PAINTOPS_OP_BITS) - 1)
172#define PAINTOPS_FLAG_MASK   ((1 << PAINTOPS_FLAG_BITS) - 1)
173#define PAINTOPS_DATA_MASK   ((1 << PAINTOPS_DATA_BITS) - 1)
174
175static unsigned PaintOp_unpackOp(uint32_t op32) {
176    return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS));
177}
178
179static unsigned PaintOp_unpackFlags(uint32_t op32) {
180    return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK;
181}
182
183static unsigned PaintOp_unpackData(uint32_t op32) {
184    return op32 & PAINTOPS_DATA_MASK;
185}
186
187static uint32_t PaintOp_packOp(PaintOps op) {
188    SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
189
190    return op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS);
191}
192
193static uint32_t PaintOp_packOpData(PaintOps op, unsigned data) {
194    SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
195    SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
196
197    return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | data;
198}
199
200static uint32_t PaintOp_packOpFlagData(PaintOps op, unsigned flags, unsigned data) {
201    SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
202    SkASSERT(0 == (flags & ~PAINTOPS_FLAG_MASK));
203    SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
204
205    return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) |
206    (flags << PAINTOPS_DATA_BITS) |
207    data;
208}
209
210#endif
211