SkGPipePriv.h revision bb6793bd7751f7a4e48c942567cd6c5270661a2f
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
25enum DrawOps {
26    kSkip_DrawOp,   // skip an addition N bytes (N == data)
27
28    // these match Canvas apis
29    kClipPath_DrawOp,
30    kClipRegion_DrawOp,
31    kClipRect_DrawOp,
32    kConcat_DrawOp,
33    kDrawBitmap_DrawOp,
34    kDrawBitmapMatrix_DrawOp,
35    kDrawBitmapRect_DrawOp,
36    kDrawClear_DrawOp,
37    kDrawData_DrawOp,
38    kDrawPaint_DrawOp,
39    kDrawPath_DrawOp,
40    kDrawPicture_DrawOp,
41    kDrawPoints_DrawOp,
42    kDrawPosText_DrawOp,
43    kDrawPosTextH_DrawOp,
44    kDrawRect_DrawOp,
45    kDrawShape_DrawOp,
46    kDrawSprite_DrawOp,
47    kDrawText_DrawOp,
48    kDrawTextOnPath_DrawOp,
49    kDrawVertices_DrawOp,
50    kRestore_DrawOp,
51    kRotate_DrawOp,
52    kSave_DrawOp,
53    kSaveLayer_DrawOp,
54    kScale_DrawOp,
55    kSetMatrix_DrawOp,
56    kSkew_DrawOp,
57    kTranslate_DrawOp,
58
59    kPaintOp_DrawOp,
60
61    kDef_ColorFilter_DrawOp,
62    kDef_DrawLooper_DrawOp,
63    kDef_MaskFilter_DrawOp,
64    kDef_PathEffect_DrawOp,
65    kDef_Rasterizer_DrawOp,
66    kDef_Shader_DrawOp,
67    kDef_Typeface_DrawOp,
68    kDef_Xfermode_DrawOp,
69
70    // these are signals to playback, not drawing verbs
71    kDone_DrawOp,
72};
73
74/**
75 *  DrawOp packs into a 32bit int as follows
76 *
77 *  DrawOp:8 - Flags:4 - Data:20
78 *
79 *  Flags and Data are called out separately, so we can reuse Data between
80 *  different Ops that might have different Flags. e.g. Data might be a Paint
81 *  index for both drawRect (no flags) and saveLayer (does have flags).
82 *
83 *  All Ops that take a SkPaint use their Data field to store the index to
84 *  the paint (previously defined with kPaintOp_DrawOp).
85 */
86
87#define DRAWOPS_OP_BITS     8
88#define DRAWOPS_FLAG_BITS   4
89#define DRAWOPS_DATA_BITS   20
90
91#define DRAWOPS_OP_MASK     ((1 << DRAWOPS_OP_BITS) - 1)
92#define DRAWOPS_FLAG_MASK   ((1 << DRAWOPS_FLAG_BITS) - 1)
93#define DRAWOPS_DATA_MASK   ((1 << DRAWOPS_DATA_BITS) - 1)
94
95static unsigned DrawOp_unpackOp(uint32_t op32) {
96    return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS));
97}
98
99static unsigned DrawOp_unpackFlags(uint32_t op32) {
100    return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK;
101}
102
103static unsigned DrawOp_unpackData(uint32_t op32) {
104    return op32 & DRAWOPS_DATA_MASK;
105}
106
107static uint32_t DrawOp_packOpFlagData(DrawOps op, unsigned flags, unsigned data) {
108    SkASSERT(0 == (op & ~DRAWOPS_OP_MASK));
109    SkASSERT(0 == (flags & ~DRAWOPS_FLAG_MASK));
110    SkASSERT(0 == (data & ~DRAWOPS_DATA_MASK));
111
112    return (op << DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS) |
113           (flags << DRAWOPS_DATA_BITS) |
114            data;
115}
116
117/** DrawOp specific flag bits
118 */
119
120enum {
121    kSaveLayer_HasBounds_DrawOpFlag = 1 << 0,
122    kSaveLayer_HasPaint_DrawOpFlag = 1 << 1,
123};
124enum {
125    kClear_HasColor_DrawOpFlag  = 1 << 0
126};
127enum {
128    kDrawTextOnPath_HasMatrix_DrawOpFlag = 1 << 0
129};
130enum {
131    kDrawVertices_HasTexs_DrawOpFlag     = 1 << 0,
132    kDrawVertices_HasColors_DrawOpFlag   = 1 << 1,
133    kDrawVertices_HasIndices_DrawOpFlag  = 1 << 2,
134};
135
136///////////////////////////////////////////////////////////////////////////////
137
138enum PaintOps {
139    kReset_PaintOp,     // no arg
140
141    kFlags_PaintOp,     // arg inline
142    kColor_PaintOp,     // arg 32
143    kStyle_PaintOp,     // arg inline
144    kJoin_PaintOp,      // arg inline
145    kCap_PaintOp,       // arg inline
146    kWidth_PaintOp,     // arg scalar
147    kMiter_PaintOp,// arg scalar
148
149    kEncoding_PaintOp,  // arg inline - text
150    kHinting_PaintOp,   // arg inline - text
151    kAlign_PaintOp,     // arg inline - text
152    kTextSize_PaintOp,  // arg scalar - text
153    kTextScaleX_PaintOp,// arg scalar - text
154    kTextSkewX_PaintOp, // arg scalar - text
155    kTypeface_PaintOp,  // arg inline (index) - text
156
157    kPathEffect_PaintOp,    // arg inline
158    kShader_PaintOp,
159    kXfermode_PaintOp,
160    kMaskFilter_PaintOp,
161    kColorFilter_PaintOp,
162    kRasterizer_PaintOp,
163    kDrawLooper_PaintOp,
164};
165
166#define PAINTOPS_OP_BITS     8
167#define PAINTOPS_FLAG_BITS   4
168#define PAINTOPS_DATA_BITS   20
169
170#define PAINTOPS_OP_MASK     ((1 << PAINTOPS_OP_BITS) - 1)
171#define PAINTOPS_FLAG_MASK   ((1 << PAINTOPS_FLAG_BITS) - 1)
172#define PAINTOPS_DATA_MASK   ((1 << PAINTOPS_DATA_BITS) - 1)
173
174static unsigned PaintOp_unpackOp(uint32_t op32) {
175    return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS));
176}
177
178static unsigned PaintOp_unpackFlags(uint32_t op32) {
179    return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK;
180}
181
182static unsigned PaintOp_unpackData(uint32_t op32) {
183    return op32 & PAINTOPS_DATA_MASK;
184}
185
186static uint32_t PaintOp_packOp(PaintOps op) {
187    SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
188
189    return (op << PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS);
190}
191
192static uint32_t PaintOp_packOpData(PaintOps op, unsigned data) {
193    SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
194    SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
195
196    return (op << PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS) | data;
197}
198
199static uint32_t PaintOp_packOpFlagData(PaintOps op, unsigned flags, unsigned data) {
200    SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
201    SkASSERT(0 == (flags & ~PAINTOPS_FLAG_MASK));
202    SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
203
204    return (op << PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS) |
205    (flags << PAINTOPS_DATA_BITS) |
206    data;
207}
208
209enum {
210    kLastOp_PaintOpFlag = 1 << 0
211};
212
213#endif
214