blob: 2baf75aaccde59e192821f2b047ff9881c0e6968 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.combb6992a2011-04-26 17:41:56 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.combb6992a2011-04-26 17:41:56 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.combb6992a2011-04-26 17:41:56 +000011#ifndef SkGPipePriv_DEFINED
12#define SkGPipePriv_DEFINED
13
14#include "SkTypes.h"
15
16#define UNIMPLEMENTED
17
reed@google.comb55d1182011-05-11 00:42:04 +000018// these must be contiguous, 0...N-1
19enum PaintFlats {
20 kColorFilter_PaintFlat,
reed@google.com0faac1e2011-05-11 05:58:58 +000021 kDrawLooper_PaintFlat,
reed@google.comb55d1182011-05-11 00:42:04 +000022 kMaskFilter_PaintFlat,
23 kPathEffect_PaintFlat,
24 kRasterizer_PaintFlat,
25 kShader_PaintFlat,
26 kXfermode_PaintFlat,
27
28 kLast_PaintFlat = kXfermode_PaintFlat
29};
30#define kCount_PaintFlats (kLast_PaintFlat + 1)
31
reed@google.combb6992a2011-04-26 17:41:56 +000032enum DrawOps {
reed@google.comacd471f2011-05-03 21:26:46 +000033 kSkip_DrawOp, // skip an addition N bytes (N == data)
34
reed@google.combb6992a2011-04-26 17:41:56 +000035 // these match Canvas apis
36 kClipPath_DrawOp,
37 kClipRegion_DrawOp,
38 kClipRect_DrawOp,
39 kConcat_DrawOp,
40 kDrawBitmap_DrawOp,
41 kDrawBitmapMatrix_DrawOp,
42 kDrawBitmapRect_DrawOp,
43 kDrawClear_DrawOp,
44 kDrawData_DrawOp,
45 kDrawPaint_DrawOp,
46 kDrawPath_DrawOp,
47 kDrawPicture_DrawOp,
48 kDrawPoints_DrawOp,
49 kDrawPosText_DrawOp,
50 kDrawPosTextH_DrawOp,
51 kDrawRect_DrawOp,
reed@google.combb6992a2011-04-26 17:41:56 +000052 kDrawSprite_DrawOp,
53 kDrawText_DrawOp,
54 kDrawTextOnPath_DrawOp,
55 kDrawVertices_DrawOp,
56 kRestore_DrawOp,
57 kRotate_DrawOp,
58 kSave_DrawOp,
59 kSaveLayer_DrawOp,
60 kScale_DrawOp,
61 kSetMatrix_DrawOp,
62 kSkew_DrawOp,
63 kTranslate_DrawOp,
64
reed@google.combb6992a2011-04-26 17:41:56 +000065 kPaintOp_DrawOp,
reed@google.combb6793b2011-05-05 15:18:15 +000066
reed@google.combb6793b2011-05-05 15:18:15 +000067 kDef_Typeface_DrawOp,
reed@google.com0faac1e2011-05-11 05:58:58 +000068 kDef_Flattenable_DrawOp,
reed@google.combb6992a2011-04-26 17:41:56 +000069
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
reed@google.com67908f22011-06-27 14:47:50 +0000112 return (op << (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)) |
reed@google.combb6992a2011-04-26 17:41:56 +0000113 (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
reed@google.comf5842f72011-05-04 18:30:04 +0000155 kTypeface_PaintOp, // arg inline (index) - text
156
reed@google.comb55d1182011-05-11 00:42:04 +0000157 kFlatIndex_PaintOp, // flags=paintflat, data=index
reed@google.combb6992a2011-04-26 17:41:56 +0000158};
159
160#define PAINTOPS_OP_BITS 8
161#define PAINTOPS_FLAG_BITS 4
162#define PAINTOPS_DATA_BITS 20
163
164#define PAINTOPS_OP_MASK ((1 << PAINTOPS_OP_BITS) - 1)
165#define PAINTOPS_FLAG_MASK ((1 << PAINTOPS_FLAG_BITS) - 1)
166#define PAINTOPS_DATA_MASK ((1 << PAINTOPS_DATA_BITS) - 1)
167
168static unsigned PaintOp_unpackOp(uint32_t op32) {
169 return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS));
170}
171
172static unsigned PaintOp_unpackFlags(uint32_t op32) {
173 return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK;
174}
175
176static unsigned PaintOp_unpackData(uint32_t op32) {
177 return op32 & PAINTOPS_DATA_MASK;
178}
179
180static uint32_t PaintOp_packOp(PaintOps op) {
181 SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
182
reed@google.com67908f22011-06-27 14:47:50 +0000183 return op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS);
reed@google.combb6992a2011-04-26 17:41:56 +0000184}
185
186static uint32_t PaintOp_packOpData(PaintOps op, unsigned data) {
187 SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
188 SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
189
reed@google.com67908f22011-06-27 14:47:50 +0000190 return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | data;
reed@google.combb6992a2011-04-26 17:41:56 +0000191}
192
193static uint32_t PaintOp_packOpFlagData(PaintOps op, unsigned flags, unsigned data) {
194 SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
195 SkASSERT(0 == (flags & ~PAINTOPS_FLAG_MASK));
196 SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
197
reed@google.com67908f22011-06-27 14:47:50 +0000198 return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) |
reed@google.combb6992a2011-04-26 17:41:56 +0000199 (flags << PAINTOPS_DATA_BITS) |
200 data;
201}
202
reed@google.combb6992a2011-04-26 17:41:56 +0000203#endif