epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 11 | #ifndef SkGPipePriv_DEFINED |
| 12 | #define SkGPipePriv_DEFINED |
| 13 | |
| 14 | #include "SkTypes.h" |
| 15 | |
| 16 | #define UNIMPLEMENTED |
| 17 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 18 | // these must be contiguous, 0...N-1 |
| 19 | enum PaintFlats { |
| 20 | kColorFilter_PaintFlat, |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 21 | kDrawLooper_PaintFlat, |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 22 | 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.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 32 | enum DrawOps { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 33 | kSkip_DrawOp, // skip an addition N bytes (N == data) |
| 34 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 35 | // 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.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 52 | 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.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 65 | kPaintOp_DrawOp, |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 66 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 67 | kDef_Typeface_DrawOp, |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 68 | kDef_Flattenable_DrawOp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 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 | |
| 95 | static unsigned DrawOp_unpackOp(uint32_t op32) { |
| 96 | return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)); |
| 97 | } |
| 98 | |
| 99 | static unsigned DrawOp_unpackFlags(uint32_t op32) { |
| 100 | return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK; |
| 101 | } |
| 102 | |
| 103 | static unsigned DrawOp_unpackData(uint32_t op32) { |
| 104 | return op32 & DRAWOPS_DATA_MASK; |
| 105 | } |
| 106 | |
| 107 | static 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.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 112 | return (op << (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)) | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 113 | (flags << DRAWOPS_DATA_BITS) | |
| 114 | data; |
| 115 | } |
| 116 | |
| 117 | /** DrawOp specific flag bits |
| 118 | */ |
| 119 | |
| 120 | enum { |
| 121 | kSaveLayer_HasBounds_DrawOpFlag = 1 << 0, |
| 122 | kSaveLayer_HasPaint_DrawOpFlag = 1 << 1, |
| 123 | }; |
| 124 | enum { |
| 125 | kClear_HasColor_DrawOpFlag = 1 << 0 |
| 126 | }; |
| 127 | enum { |
| 128 | kDrawTextOnPath_HasMatrix_DrawOpFlag = 1 << 0 |
| 129 | }; |
| 130 | enum { |
| 131 | kDrawVertices_HasTexs_DrawOpFlag = 1 << 0, |
| 132 | kDrawVertices_HasColors_DrawOpFlag = 1 << 1, |
| 133 | kDrawVertices_HasIndices_DrawOpFlag = 1 << 2, |
| 134 | }; |
| 135 | |
| 136 | /////////////////////////////////////////////////////////////////////////////// |
| 137 | |
| 138 | enum 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.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 155 | kTypeface_PaintOp, // arg inline (index) - text |
| 156 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 157 | kFlatIndex_PaintOp, // flags=paintflat, data=index |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 158 | }; |
| 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 | |
| 168 | static unsigned PaintOp_unpackOp(uint32_t op32) { |
| 169 | return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)); |
| 170 | } |
| 171 | |
| 172 | static unsigned PaintOp_unpackFlags(uint32_t op32) { |
| 173 | return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK; |
| 174 | } |
| 175 | |
| 176 | static unsigned PaintOp_unpackData(uint32_t op32) { |
| 177 | return op32 & PAINTOPS_DATA_MASK; |
| 178 | } |
| 179 | |
| 180 | static uint32_t PaintOp_packOp(PaintOps op) { |
| 181 | SkASSERT(0 == (op & ~PAINTOPS_OP_MASK)); |
| 182 | |
reed@google.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 183 | return op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static 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.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 190 | return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | data; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static 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.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 198 | return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 199 | (flags << PAINTOPS_DATA_BITS) | |
| 200 | data; |
| 201 | } |
| 202 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 203 | #endif |