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, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 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 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 72 | kPaintOp_DrawOp, |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 73 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 74 | kDef_Typeface_DrawOp, |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 75 | kDef_Flattenable_DrawOp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 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 | |
| 102 | static unsigned DrawOp_unpackOp(uint32_t op32) { |
| 103 | return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)); |
| 104 | } |
| 105 | |
| 106 | static unsigned DrawOp_unpackFlags(uint32_t op32) { |
| 107 | return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK; |
| 108 | } |
| 109 | |
| 110 | static unsigned DrawOp_unpackData(uint32_t op32) { |
| 111 | return op32 & DRAWOPS_DATA_MASK; |
| 112 | } |
| 113 | |
| 114 | static 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 | |
| 127 | enum { |
| 128 | kSaveLayer_HasBounds_DrawOpFlag = 1 << 0, |
| 129 | kSaveLayer_HasPaint_DrawOpFlag = 1 << 1, |
| 130 | }; |
| 131 | enum { |
| 132 | kClear_HasColor_DrawOpFlag = 1 << 0 |
| 133 | }; |
| 134 | enum { |
| 135 | kDrawTextOnPath_HasMatrix_DrawOpFlag = 1 << 0 |
| 136 | }; |
| 137 | enum { |
| 138 | kDrawVertices_HasTexs_DrawOpFlag = 1 << 0, |
| 139 | kDrawVertices_HasColors_DrawOpFlag = 1 << 1, |
| 140 | kDrawVertices_HasIndices_DrawOpFlag = 1 << 2, |
| 141 | }; |
| 142 | |
| 143 | /////////////////////////////////////////////////////////////////////////////// |
| 144 | |
| 145 | enum 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 |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 162 | kTypeface_PaintOp, // arg inline (index) - text |
| 163 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 164 | kFlatIndex_PaintOp, // flags=paintflat, data=index |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 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 | |
| 175 | static unsigned PaintOp_unpackOp(uint32_t op32) { |
| 176 | return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)); |
| 177 | } |
| 178 | |
| 179 | static unsigned PaintOp_unpackFlags(uint32_t op32) { |
| 180 | return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK; |
| 181 | } |
| 182 | |
| 183 | static unsigned PaintOp_unpackData(uint32_t op32) { |
| 184 | return op32 & PAINTOPS_DATA_MASK; |
| 185 | } |
| 186 | |
| 187 | static 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 | |
| 193 | static 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 | |
| 200 | static 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 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 210 | #endif |