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, |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 26 | kImageFilter_PaintFlat, |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 27 | kXfermode_PaintFlat, |
| 28 | |
| 29 | kLast_PaintFlat = kXfermode_PaintFlat |
| 30 | }; |
| 31 | #define kCount_PaintFlats (kLast_PaintFlat + 1) |
| 32 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 33 | enum DrawOps { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 34 | kSkip_DrawOp, // skip an addition N bytes (N == data) |
| 35 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 36 | // these match Canvas apis |
| 37 | kClipPath_DrawOp, |
| 38 | kClipRegion_DrawOp, |
| 39 | kClipRect_DrawOp, |
| 40 | kConcat_DrawOp, |
| 41 | kDrawBitmap_DrawOp, |
| 42 | kDrawBitmapMatrix_DrawOp, |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 43 | kDrawBitmapNine_DrawOp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 44 | kDrawBitmapRect_DrawOp, |
| 45 | kDrawClear_DrawOp, |
| 46 | kDrawData_DrawOp, |
| 47 | kDrawPaint_DrawOp, |
| 48 | kDrawPath_DrawOp, |
| 49 | kDrawPicture_DrawOp, |
| 50 | kDrawPoints_DrawOp, |
| 51 | kDrawPosText_DrawOp, |
| 52 | kDrawPosTextH_DrawOp, |
| 53 | kDrawRect_DrawOp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 54 | kDrawSprite_DrawOp, |
| 55 | kDrawText_DrawOp, |
| 56 | kDrawTextOnPath_DrawOp, |
| 57 | kDrawVertices_DrawOp, |
| 58 | kRestore_DrawOp, |
| 59 | kRotate_DrawOp, |
| 60 | kSave_DrawOp, |
| 61 | kSaveLayer_DrawOp, |
| 62 | kScale_DrawOp, |
| 63 | kSetMatrix_DrawOp, |
| 64 | kSkew_DrawOp, |
| 65 | kTranslate_DrawOp, |
| 66 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 67 | kPaintOp_DrawOp, |
scroggo@google.com | 3cb969f | 2012-07-27 20:39:19 +0000 | [diff] [blame] | 68 | kSetTypeface_DrawOp, |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 69 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 70 | kDef_Typeface_DrawOp, |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 71 | kDef_Flattenable_DrawOp, |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 72 | kDef_Bitmap_DrawOp, |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 73 | kDef_Factory_DrawOp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 74 | |
| 75 | // these are signals to playback, not drawing verbs |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 76 | kReportFlags_DrawOp, |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame^] | 77 | kShareBitmapHeap_DrawOp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 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 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 102 | static inline unsigned DrawOp_unpackOp(uint32_t op32) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 103 | return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)); |
| 104 | } |
| 105 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 106 | static inline unsigned DrawOp_unpackFlags(uint32_t op32) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 107 | return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK; |
| 108 | } |
| 109 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 110 | static inline unsigned DrawOp_unpackData(uint32_t op32) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 111 | return op32 & DRAWOPS_DATA_MASK; |
| 112 | } |
| 113 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 114 | static inline uint32_t DrawOp_packOpFlagData(DrawOps op, unsigned flags, unsigned data) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 115 | SkASSERT(0 == (op & ~DRAWOPS_OP_MASK)); |
| 116 | SkASSERT(0 == (flags & ~DRAWOPS_FLAG_MASK)); |
| 117 | SkASSERT(0 == (data & ~DRAWOPS_DATA_MASK)); |
| 118 | |
reed@google.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 119 | return (op << (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)) | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 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 | }; |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 142 | enum { |
| 143 | kDrawBitmap_HasPaint_DrawOpsFlag = 1 << 0, |
| 144 | // Specific to drawBitmapRect, but needs to be different from HasPaint, |
| 145 | // which is used for all drawBitmap calls, so include it here. |
| 146 | kDrawBitmap_HasSrcRect_DrawOpsFlag = 1 << 1, |
| 147 | }; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 148 | |
| 149 | /////////////////////////////////////////////////////////////////////////////// |
| 150 | |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 151 | class BitmapInfo : SkNoncopyable { |
| 152 | public: |
| 153 | BitmapInfo(SkBitmap* bitmap, uint32_t genID, int toBeDrawnCount) |
| 154 | : fBitmap(bitmap) |
| 155 | , fGenID(genID) |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 156 | , fBytesAllocated(0) |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 157 | , fMoreRecentlyUsed(NULL) |
| 158 | , fLessRecentlyUsed(NULL) |
| 159 | , fToBeDrawnCount(toBeDrawnCount) |
| 160 | {} |
| 161 | |
| 162 | ~BitmapInfo() { |
| 163 | SkASSERT(0 == fToBeDrawnCount); |
| 164 | SkDELETE(fBitmap); |
| 165 | } |
| 166 | |
| 167 | void addDraws(int drawsToAdd) { |
| 168 | if (0 == fToBeDrawnCount) { |
| 169 | // The readers will only ever decrement the count, so once the |
| 170 | // count is zero, the writer will be the only one modifying it, |
| 171 | // so it does not need to be an atomic operation. |
| 172 | fToBeDrawnCount = drawsToAdd; |
| 173 | } else { |
| 174 | sk_atomic_add(&fToBeDrawnCount, drawsToAdd); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | void decDraws() { |
| 179 | sk_atomic_dec(&fToBeDrawnCount); |
| 180 | } |
| 181 | |
| 182 | int drawCount() const { |
| 183 | return fToBeDrawnCount; |
| 184 | } |
| 185 | |
| 186 | SkBitmap* fBitmap; |
| 187 | // Store the generation ID of the original bitmap, since copying does |
| 188 | // not copy this field, so fBitmap's generation ID will not be useful |
| 189 | // for comparing. |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 190 | // FIXME: Is it reasonable to make copying a bitmap/pixelref copy the |
| 191 | // generation ID? |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 192 | uint32_t fGenID; |
scroggo@google.com | 15011ee | 2012-07-26 20:03:32 +0000 | [diff] [blame] | 193 | // Keep track of the bytes allocated for this bitmap. When replacing the |
| 194 | // bitmap or removing this BitmapInfo we know how much memory has been |
| 195 | // reclaimed. |
| 196 | size_t fBytesAllocated; |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 197 | // TODO: Generalize the LRU caching mechanism |
| 198 | BitmapInfo* fMoreRecentlyUsed; |
| 199 | BitmapInfo* fLessRecentlyUsed; |
| 200 | private: |
| 201 | int fToBeDrawnCount; |
| 202 | }; |
| 203 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 204 | static inline bool shouldFlattenBitmaps(uint32_t flags) { |
scroggo@google.com | 3cb969f | 2012-07-27 20:39:19 +0000 | [diff] [blame] | 205 | return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag |
| 206 | && !(flags & SkGPipeWriter::kSharedAddressSpace_Flag)); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /////////////////////////////////////////////////////////////////////////////// |
| 210 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 211 | enum PaintOps { |
| 212 | kReset_PaintOp, // no arg |
| 213 | |
| 214 | kFlags_PaintOp, // arg inline |
| 215 | kColor_PaintOp, // arg 32 |
| 216 | kStyle_PaintOp, // arg inline |
| 217 | kJoin_PaintOp, // arg inline |
| 218 | kCap_PaintOp, // arg inline |
| 219 | kWidth_PaintOp, // arg scalar |
| 220 | kMiter_PaintOp,// arg scalar |
| 221 | |
| 222 | kEncoding_PaintOp, // arg inline - text |
| 223 | kHinting_PaintOp, // arg inline - text |
| 224 | kAlign_PaintOp, // arg inline - text |
| 225 | kTextSize_PaintOp, // arg scalar - text |
| 226 | kTextScaleX_PaintOp,// arg scalar - text |
| 227 | kTextSkewX_PaintOp, // arg scalar - text |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 228 | kTypeface_PaintOp, // arg inline (index) - text |
| 229 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 230 | kFlatIndex_PaintOp, // flags=paintflat, data=index |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | #define PAINTOPS_OP_BITS 8 |
| 234 | #define PAINTOPS_FLAG_BITS 4 |
| 235 | #define PAINTOPS_DATA_BITS 20 |
| 236 | |
| 237 | #define PAINTOPS_OP_MASK ((1 << PAINTOPS_OP_BITS) - 1) |
| 238 | #define PAINTOPS_FLAG_MASK ((1 << PAINTOPS_FLAG_BITS) - 1) |
| 239 | #define PAINTOPS_DATA_MASK ((1 << PAINTOPS_DATA_BITS) - 1) |
| 240 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 241 | static inline unsigned PaintOp_unpackOp(uint32_t op32) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 242 | return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)); |
| 243 | } |
| 244 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 245 | static inline unsigned PaintOp_unpackFlags(uint32_t op32) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 246 | return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK; |
| 247 | } |
| 248 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 249 | static inline unsigned PaintOp_unpackData(uint32_t op32) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 250 | return op32 & PAINTOPS_DATA_MASK; |
| 251 | } |
| 252 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 253 | static inline uint32_t PaintOp_packOp(PaintOps op) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 254 | SkASSERT(0 == (op & ~PAINTOPS_OP_MASK)); |
| 255 | |
reed@google.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 256 | return op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 257 | } |
| 258 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 259 | static inline uint32_t PaintOp_packOpData(PaintOps op, unsigned data) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 260 | SkASSERT(0 == (op & ~PAINTOPS_OP_MASK)); |
| 261 | SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK)); |
| 262 | |
reed@google.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 263 | return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | data; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 264 | } |
| 265 | |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 266 | static inline uint32_t PaintOp_packOpFlagData(PaintOps op, unsigned flags, unsigned data) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 267 | SkASSERT(0 == (op & ~PAINTOPS_OP_MASK)); |
| 268 | SkASSERT(0 == (flags & ~PAINTOPS_FLAG_MASK)); |
| 269 | SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK)); |
| 270 | |
reed@google.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 271 | return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 272 | (flags << PAINTOPS_DATA_BITS) | |
| 273 | data; |
| 274 | } |
| 275 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 276 | #endif |