reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 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 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 25 | // these must be contiguous, 0...N-1 |
| 26 | enum PaintFlats { |
| 27 | kColorFilter_PaintFlat, |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame^] | 28 | kDrawLooper_PaintFlat, |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 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 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 39 | enum DrawOps { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 40 | kSkip_DrawOp, // skip an addition N bytes (N == data) |
| 41 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 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 | kDrawShape_DrawOp, |
| 60 | kDrawSprite_DrawOp, |
| 61 | kDrawText_DrawOp, |
| 62 | kDrawTextOnPath_DrawOp, |
| 63 | kDrawVertices_DrawOp, |
| 64 | kRestore_DrawOp, |
| 65 | kRotate_DrawOp, |
| 66 | kSave_DrawOp, |
| 67 | kSaveLayer_DrawOp, |
| 68 | kScale_DrawOp, |
| 69 | kSetMatrix_DrawOp, |
| 70 | kSkew_DrawOp, |
| 71 | kTranslate_DrawOp, |
| 72 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 73 | kPaintOp_DrawOp, |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 74 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 75 | kDef_Typeface_DrawOp, |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame^] | 76 | kDef_Flattenable_DrawOp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 77 | |
| 78 | // these are signals to playback, not drawing verbs |
| 79 | kDone_DrawOp, |
| 80 | }; |
| 81 | |
| 82 | /** |
| 83 | * DrawOp packs into a 32bit int as follows |
| 84 | * |
| 85 | * DrawOp:8 - Flags:4 - Data:20 |
| 86 | * |
| 87 | * Flags and Data are called out separately, so we can reuse Data between |
| 88 | * different Ops that might have different Flags. e.g. Data might be a Paint |
| 89 | * index for both drawRect (no flags) and saveLayer (does have flags). |
| 90 | * |
| 91 | * All Ops that take a SkPaint use their Data field to store the index to |
| 92 | * the paint (previously defined with kPaintOp_DrawOp). |
| 93 | */ |
| 94 | |
| 95 | #define DRAWOPS_OP_BITS 8 |
| 96 | #define DRAWOPS_FLAG_BITS 4 |
| 97 | #define DRAWOPS_DATA_BITS 20 |
| 98 | |
| 99 | #define DRAWOPS_OP_MASK ((1 << DRAWOPS_OP_BITS) - 1) |
| 100 | #define DRAWOPS_FLAG_MASK ((1 << DRAWOPS_FLAG_BITS) - 1) |
| 101 | #define DRAWOPS_DATA_MASK ((1 << DRAWOPS_DATA_BITS) - 1) |
| 102 | |
| 103 | static unsigned DrawOp_unpackOp(uint32_t op32) { |
| 104 | return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)); |
| 105 | } |
| 106 | |
| 107 | static unsigned DrawOp_unpackFlags(uint32_t op32) { |
| 108 | return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK; |
| 109 | } |
| 110 | |
| 111 | static unsigned DrawOp_unpackData(uint32_t op32) { |
| 112 | return op32 & DRAWOPS_DATA_MASK; |
| 113 | } |
| 114 | |
| 115 | static uint32_t DrawOp_packOpFlagData(DrawOps op, unsigned flags, unsigned data) { |
| 116 | SkASSERT(0 == (op & ~DRAWOPS_OP_MASK)); |
| 117 | SkASSERT(0 == (flags & ~DRAWOPS_FLAG_MASK)); |
| 118 | SkASSERT(0 == (data & ~DRAWOPS_DATA_MASK)); |
| 119 | |
| 120 | return (op << DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS) | |
| 121 | (flags << DRAWOPS_DATA_BITS) | |
| 122 | data; |
| 123 | } |
| 124 | |
| 125 | /** DrawOp specific flag bits |
| 126 | */ |
| 127 | |
| 128 | enum { |
| 129 | kSaveLayer_HasBounds_DrawOpFlag = 1 << 0, |
| 130 | kSaveLayer_HasPaint_DrawOpFlag = 1 << 1, |
| 131 | }; |
| 132 | enum { |
| 133 | kClear_HasColor_DrawOpFlag = 1 << 0 |
| 134 | }; |
| 135 | enum { |
| 136 | kDrawTextOnPath_HasMatrix_DrawOpFlag = 1 << 0 |
| 137 | }; |
| 138 | enum { |
| 139 | kDrawVertices_HasTexs_DrawOpFlag = 1 << 0, |
| 140 | kDrawVertices_HasColors_DrawOpFlag = 1 << 1, |
| 141 | kDrawVertices_HasIndices_DrawOpFlag = 1 << 2, |
| 142 | }; |
| 143 | |
| 144 | /////////////////////////////////////////////////////////////////////////////// |
| 145 | |
| 146 | enum PaintOps { |
| 147 | kReset_PaintOp, // no arg |
| 148 | |
| 149 | kFlags_PaintOp, // arg inline |
| 150 | kColor_PaintOp, // arg 32 |
| 151 | kStyle_PaintOp, // arg inline |
| 152 | kJoin_PaintOp, // arg inline |
| 153 | kCap_PaintOp, // arg inline |
| 154 | kWidth_PaintOp, // arg scalar |
| 155 | kMiter_PaintOp,// arg scalar |
| 156 | |
| 157 | kEncoding_PaintOp, // arg inline - text |
| 158 | kHinting_PaintOp, // arg inline - text |
| 159 | kAlign_PaintOp, // arg inline - text |
| 160 | kTextSize_PaintOp, // arg scalar - text |
| 161 | kTextScaleX_PaintOp,// arg scalar - text |
| 162 | kTextSkewX_PaintOp, // arg scalar - text |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 163 | kTypeface_PaintOp, // arg inline (index) - text |
| 164 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 165 | kFlatIndex_PaintOp, // flags=paintflat, data=index |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | #define PAINTOPS_OP_BITS 8 |
| 169 | #define PAINTOPS_FLAG_BITS 4 |
| 170 | #define PAINTOPS_DATA_BITS 20 |
| 171 | |
| 172 | #define PAINTOPS_OP_MASK ((1 << PAINTOPS_OP_BITS) - 1) |
| 173 | #define PAINTOPS_FLAG_MASK ((1 << PAINTOPS_FLAG_BITS) - 1) |
| 174 | #define PAINTOPS_DATA_MASK ((1 << PAINTOPS_DATA_BITS) - 1) |
| 175 | |
| 176 | static unsigned PaintOp_unpackOp(uint32_t op32) { |
| 177 | return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)); |
| 178 | } |
| 179 | |
| 180 | static unsigned PaintOp_unpackFlags(uint32_t op32) { |
| 181 | return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK; |
| 182 | } |
| 183 | |
| 184 | static unsigned PaintOp_unpackData(uint32_t op32) { |
| 185 | return op32 & PAINTOPS_DATA_MASK; |
| 186 | } |
| 187 | |
| 188 | static uint32_t PaintOp_packOp(PaintOps op) { |
| 189 | SkASSERT(0 == (op & ~PAINTOPS_OP_MASK)); |
| 190 | |
| 191 | return (op << PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS); |
| 192 | } |
| 193 | |
| 194 | static uint32_t PaintOp_packOpData(PaintOps op, unsigned data) { |
| 195 | SkASSERT(0 == (op & ~PAINTOPS_OP_MASK)); |
| 196 | SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK)); |
| 197 | |
| 198 | return (op << PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS) | data; |
| 199 | } |
| 200 | |
| 201 | static uint32_t PaintOp_packOpFlagData(PaintOps op, unsigned flags, unsigned data) { |
| 202 | SkASSERT(0 == (op & ~PAINTOPS_OP_MASK)); |
| 203 | SkASSERT(0 == (flags & ~PAINTOPS_FLAG_MASK)); |
| 204 | SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK)); |
| 205 | |
| 206 | return (op << PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS) | |
| 207 | (flags << PAINTOPS_DATA_BITS) | |
| 208 | data; |
| 209 | } |
| 210 | |
| 211 | enum { |
| 212 | kLastOp_PaintOpFlag = 1 << 0 |
| 213 | }; |
| 214 | |
| 215 | #endif |