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 | |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 10 | #include "SkBitmapHeap.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
| 12 | #include "SkPaint.h" |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 13 | #include "SkGPipe.h" |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 14 | #include "SkGPipePriv.h" |
| 15 | #include "SkReader32.h" |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 16 | #include "SkStream.h" |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 17 | |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 18 | #include "SkAnnotation.h" |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 19 | #include "SkColorFilter.h" |
| 20 | #include "SkDrawLooper.h" |
reed@google.com | 3534822 | 2013-10-16 13:05:06 +0000 | [diff] [blame] | 21 | #include "SkImageFilter.h" |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 22 | #include "SkMaskFilter.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 23 | #include "SkReadBuffer.h" |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 24 | #include "SkPathEffect.h" |
| 25 | #include "SkRasterizer.h" |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 26 | #include "SkRRect.h" |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 27 | #include "SkShader.h" |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 28 | #include "SkTypeface.h" |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 29 | #include "SkXfermode.h" |
| 30 | |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 31 | static SkFlattenable::Type paintflat_to_flattype(PaintFlats pf) { |
reed@google.com | 3534822 | 2013-10-16 13:05:06 +0000 | [diff] [blame] | 32 | static const uint8_t gEffectTypesInPaintFlatsOrder[] = { |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 33 | SkFlattenable::kSkColorFilter_Type, |
| 34 | SkFlattenable::kSkDrawLooper_Type, |
| 35 | SkFlattenable::kSkImageFilter_Type, |
| 36 | SkFlattenable::kSkMaskFilter_Type, |
| 37 | SkFlattenable::kSkPathEffect_Type, |
| 38 | SkFlattenable::kSkRasterizer_Type, |
| 39 | SkFlattenable::kSkShader_Type, |
| 40 | SkFlattenable::kSkXfermode_Type, |
reed@google.com | 3534822 | 2013-10-16 13:05:06 +0000 | [diff] [blame] | 41 | }; |
skia.committer@gmail.com | 4677acc | 2013-10-17 07:02:33 +0000 | [diff] [blame] | 42 | |
reed@google.com | 3534822 | 2013-10-16 13:05:06 +0000 | [diff] [blame] | 43 | SkASSERT((size_t)pf < SK_ARRAY_COUNT(gEffectTypesInPaintFlatsOrder)); |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 44 | return (SkFlattenable::Type)gEffectTypesInPaintFlatsOrder[pf]; |
reed@google.com | 3534822 | 2013-10-16 13:05:06 +0000 | [diff] [blame] | 45 | } |
| 46 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 47 | static void set_paintflat(SkPaint* paint, SkFlattenable* obj, unsigned paintFlat) { |
| 48 | SkASSERT(paintFlat < kCount_PaintFlats); |
| 49 | switch (paintFlat) { |
| 50 | case kColorFilter_PaintFlat: |
| 51 | paint->setColorFilter((SkColorFilter*)obj); |
| 52 | break; |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 53 | case kDrawLooper_PaintFlat: |
| 54 | paint->setLooper((SkDrawLooper*)obj); |
| 55 | break; |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 56 | case kMaskFilter_PaintFlat: |
| 57 | paint->setMaskFilter((SkMaskFilter*)obj); |
| 58 | break; |
| 59 | case kPathEffect_PaintFlat: |
| 60 | paint->setPathEffect((SkPathEffect*)obj); |
| 61 | break; |
| 62 | case kRasterizer_PaintFlat: |
| 63 | paint->setRasterizer((SkRasterizer*)obj); |
| 64 | break; |
| 65 | case kShader_PaintFlat: |
| 66 | paint->setShader((SkShader*)obj); |
| 67 | break; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 68 | case kImageFilter_PaintFlat: |
| 69 | paint->setImageFilter((SkImageFilter*)obj); |
| 70 | break; |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 71 | case kXfermode_PaintFlat: |
| 72 | paint->setXfermode((SkXfermode*)obj); |
| 73 | break; |
| 74 | default: |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 75 | SkDEBUGFAIL("never gets here"); |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 79 | template <typename T> class SkRefCntTDArray : public SkTDArray<T> { |
| 80 | public: |
| 81 | ~SkRefCntTDArray() { this->unrefAll(); } |
| 82 | }; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 83 | |
scroggo@google.com | 7ca2443 | 2012-08-14 15:48:43 +0000 | [diff] [blame] | 84 | class SkGPipeState : public SkBitmapHeapReader { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 85 | public: |
| 86 | SkGPipeState(); |
| 87 | ~SkGPipeState(); |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 88 | |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 89 | void setSilent(bool silent) { |
| 90 | fSilent = silent; |
| 91 | } |
| 92 | |
| 93 | bool shouldDraw() { |
| 94 | return !fSilent; |
| 95 | } |
| 96 | |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 97 | void setFlags(unsigned flags) { |
| 98 | if (fFlags != flags) { |
| 99 | fFlags = flags; |
| 100 | this->updateReader(); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | unsigned getFlags() const { |
| 105 | return fFlags; |
| 106 | } |
| 107 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 108 | void setReader(SkReadBuffer* reader) { |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 109 | fReader = reader; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 110 | this->updateReader(); |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 111 | } |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 112 | |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 113 | const SkPaint& paint() const { return fPaint; } |
| 114 | SkPaint* editPaint() { return &fPaint; } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 115 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 116 | SkFlattenable* getFlat(unsigned index) const { |
| 117 | if (0 == index) { |
| 118 | return NULL; |
| 119 | } |
| 120 | return fFlatArray[index - 1]; |
| 121 | } |
| 122 | |
reed@google.com | 67908f2 | 2011-06-27 14:47:50 +0000 | [diff] [blame] | 123 | void defFlattenable(PaintFlats pf, int index) { |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 124 | index--; |
commit-bot@chromium.org | c0b7e10 | 2013-10-23 17:06:21 +0000 | [diff] [blame] | 125 | SkFlattenable* obj = fReader->readFlattenable(paintflat_to_flattype(pf)); |
scroggo@google.com | d3ba5cc | 2012-07-09 16:05:53 +0000 | [diff] [blame] | 126 | if (fFlatArray.count() == index) { |
| 127 | *fFlatArray.append() = obj; |
| 128 | } else { |
| 129 | SkSafeUnref(fFlatArray[index]); |
| 130 | fFlatArray[index] = obj; |
| 131 | } |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 132 | } |
| 133 | |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 134 | void defFactory(const char* name) { |
| 135 | SkFlattenable::Factory factory = SkFlattenable::NameToFactory(name); |
| 136 | if (factory) { |
| 137 | SkASSERT(fFactoryArray.find(factory) < 0); |
| 138 | *fFactoryArray.append() = factory; |
| 139 | } |
| 140 | } |
| 141 | |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 142 | /** |
| 143 | * Add a bitmap to the array of bitmaps, or replace an existing one. |
| 144 | * This is only used when in cross process mode without a shared heap. |
| 145 | */ |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 146 | void addBitmap(int index) { |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 147 | SkASSERT(shouldFlattenBitmaps(fFlags)); |
scroggo@google.com | 4dffc59 | 2012-07-17 16:49:40 +0000 | [diff] [blame] | 148 | SkBitmap* bm; |
| 149 | if(fBitmaps.count() == index) { |
| 150 | bm = SkNEW(SkBitmap); |
| 151 | *fBitmaps.append() = bm; |
| 152 | } else { |
| 153 | bm = fBitmaps[index]; |
| 154 | } |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 155 | fReader->readBitmap(bm); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 156 | } |
| 157 | |
scroggo@google.com | 7ca2443 | 2012-08-14 15:48:43 +0000 | [diff] [blame] | 158 | /** |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 159 | * Override of SkBitmapHeapReader, so that SkReadBuffer can use |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 160 | * these SkBitmaps for bitmap shaders. Used only in cross process mode |
| 161 | * without a shared heap. |
scroggo@google.com | 7ca2443 | 2012-08-14 15:48:43 +0000 | [diff] [blame] | 162 | */ |
| 163 | virtual SkBitmap* getBitmap(int32_t index) const SK_OVERRIDE { |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 164 | SkASSERT(shouldFlattenBitmaps(fFlags)); |
scroggo@google.com | 3e26bd0 | 2012-08-14 15:20:01 +0000 | [diff] [blame] | 165 | return fBitmaps[index]; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 166 | } |
| 167 | |
scroggo@google.com | 7ca2443 | 2012-08-14 15:48:43 +0000 | [diff] [blame] | 168 | /** |
| 169 | * Needed to be a non-abstract subclass of SkBitmapHeapReader. |
| 170 | */ |
| 171 | virtual void releaseRef(int32_t) SK_OVERRIDE {} |
| 172 | |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 173 | void setSharedHeap(SkBitmapHeap* heap) { |
| 174 | SkASSERT(!shouldFlattenBitmaps(fFlags) || NULL == heap); |
| 175 | SkRefCnt_SafeAssign(fSharedHeap, heap); |
scroggo@google.com | 7ca2443 | 2012-08-14 15:48:43 +0000 | [diff] [blame] | 176 | this->updateReader(); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 177 | } |
| 178 | |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 179 | /** |
| 180 | * Access the shared heap. Only used in the case when bitmaps are not |
| 181 | * flattened. |
| 182 | */ |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 183 | SkBitmapHeap* getSharedHeap() const { |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 184 | SkASSERT(!shouldFlattenBitmaps(fFlags)); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 185 | return fSharedHeap; |
| 186 | } |
| 187 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 188 | void addTypeface() { |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 189 | size_t size = fReader->read32(); |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 190 | const void* data = fReader->skip(SkAlign4(size)); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 191 | SkMemoryStream stream(data, size, false); |
reed@google.com | f5842f7 | 2011-05-04 18:30:04 +0000 | [diff] [blame] | 192 | *fTypefaces.append() = SkTypeface::Deserialize(&stream); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 193 | } |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 194 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 195 | void setTypeface(SkPaint* paint, unsigned id) { |
| 196 | paint->setTypeface(id ? fTypefaces[id - 1] : NULL); |
| 197 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 198 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 199 | private: |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 200 | void updateReader() { |
| 201 | if (NULL == fReader) { |
| 202 | return; |
| 203 | } |
| 204 | bool crossProcess = SkToBool(fFlags & SkGPipeWriter::kCrossProcess_Flag); |
| 205 | fReader->setFlags(SkSetClearMask(fReader->getFlags(), crossProcess, |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 206 | SkReadBuffer::kCrossProcess_Flag)); |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 207 | if (crossProcess) { |
| 208 | fReader->setFactoryArray(&fFactoryArray); |
| 209 | } else { |
| 210 | fReader->setFactoryArray(NULL); |
| 211 | } |
scroggo@google.com | 7ca2443 | 2012-08-14 15:48:43 +0000 | [diff] [blame] | 212 | |
| 213 | if (shouldFlattenBitmaps(fFlags)) { |
| 214 | fReader->setBitmapStorage(this); |
| 215 | } else { |
| 216 | fReader->setBitmapStorage(fSharedHeap); |
| 217 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 218 | } |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 219 | SkReadBuffer* fReader; |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 220 | SkPaint fPaint; |
| 221 | SkTDArray<SkFlattenable*> fFlatArray; |
| 222 | SkTDArray<SkTypeface*> fTypefaces; |
reed@google.com | dde0956 | 2011-05-23 12:21:05 +0000 | [diff] [blame] | 223 | SkTDArray<SkFlattenable::Factory> fFactoryArray; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 224 | SkTDArray<SkBitmap*> fBitmaps; |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 225 | bool fSilent; |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 226 | // Only used when sharing bitmaps with the writer. |
| 227 | SkBitmapHeap* fSharedHeap; |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 228 | unsigned fFlags; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | /////////////////////////////////////////////////////////////////////////////// |
| 232 | |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 233 | template <typename T> const T* skip(SkReader32* reader, size_t count = 1) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 234 | size_t size = sizeof(T) * count; |
| 235 | SkASSERT(SkAlign4(size) == size); |
| 236 | return reinterpret_cast<const T*>(reader->skip(size)); |
| 237 | } |
| 238 | |
commit-bot@chromium.org | b45bd1f | 2014-04-24 18:17:30 +0000 | [diff] [blame] | 239 | template <typename T> const T* skipAlign(SkReader32* reader, size_t count = 1) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 240 | size_t size = SkAlign4(sizeof(T) * count); |
| 241 | return reinterpret_cast<const T*>(reader->skip(size)); |
| 242 | } |
| 243 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 244 | /////////////////////////////////////////////////////////////////////////////// |
| 245 | /////////////////////////////////////////////////////////////////////////////// |
| 246 | |
| 247 | static void clipPath_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 248 | SkGPipeState* state) { |
| 249 | SkPath path; |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 250 | reader->readPath(&path); |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 251 | bool doAA = SkToBool(DrawOp_unpackFlags(op32) & kClip_HasAntiAlias_DrawOpFlag); |
| 252 | canvas->clipPath(path, (SkRegion::Op)DrawOp_unpackData(op32), doAA); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | static void clipRegion_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 256 | SkGPipeState* state) { |
| 257 | SkRegion rgn; |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 258 | reader->readRegion(&rgn); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 259 | canvas->clipRegion(rgn, (SkRegion::Op)DrawOp_unpackData(op32)); |
| 260 | } |
| 261 | |
| 262 | static void clipRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 263 | SkGPipeState* state) { |
scroggo@google.com | 691703c | 2012-06-05 14:58:40 +0000 | [diff] [blame] | 264 | const SkRect* rect = skip<SkRect>(reader); |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 265 | bool doAA = SkToBool(DrawOp_unpackFlags(op32) & kClip_HasAntiAlias_DrawOpFlag); |
scroggo@google.com | 691703c | 2012-06-05 14:58:40 +0000 | [diff] [blame] | 266 | canvas->clipRect(*rect, (SkRegion::Op)DrawOp_unpackData(op32), doAA); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 267 | } |
| 268 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 269 | static void clipRRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 270 | SkGPipeState* state) { |
| 271 | SkRRect rrect; |
| 272 | reader->readRRect(&rrect); |
| 273 | bool doAA = SkToBool(DrawOp_unpackFlags(op32) & kClip_HasAntiAlias_DrawOpFlag); |
| 274 | canvas->clipRRect(rrect, (SkRegion::Op)DrawOp_unpackData(op32), doAA); |
| 275 | } |
| 276 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 277 | /////////////////////////////////////////////////////////////////////////////// |
| 278 | |
| 279 | static void setMatrix_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 280 | SkGPipeState* state) { |
| 281 | SkMatrix matrix; |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 282 | reader->readMatrix(&matrix); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 283 | canvas->setMatrix(matrix); |
| 284 | } |
| 285 | |
| 286 | static void concat_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 287 | SkGPipeState* state) { |
| 288 | SkMatrix matrix; |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 289 | reader->readMatrix(&matrix); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 290 | canvas->concat(matrix); |
| 291 | } |
| 292 | |
| 293 | static void scale_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 294 | SkGPipeState* state) { |
| 295 | const SkScalar* param = skip<SkScalar>(reader, 2); |
| 296 | canvas->scale(param[0], param[1]); |
| 297 | } |
| 298 | |
| 299 | static void skew_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 300 | SkGPipeState* state) { |
| 301 | const SkScalar* param = skip<SkScalar>(reader, 2); |
| 302 | canvas->skew(param[0], param[1]); |
| 303 | } |
| 304 | |
| 305 | static void rotate_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 306 | SkGPipeState* state) { |
| 307 | canvas->rotate(reader->readScalar()); |
| 308 | } |
| 309 | |
| 310 | static void translate_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 311 | SkGPipeState* state) { |
| 312 | const SkScalar* param = skip<SkScalar>(reader, 2); |
| 313 | canvas->translate(param[0], param[1]); |
| 314 | } |
| 315 | |
| 316 | /////////////////////////////////////////////////////////////////////////////// |
| 317 | |
| 318 | static void save_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 319 | SkGPipeState* state) { |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 320 | canvas->save(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static void saveLayer_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 324 | SkGPipeState* state) { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 325 | unsigned flags = DrawOp_unpackFlags(op32); |
| 326 | SkCanvas::SaveFlags saveFlags = (SkCanvas::SaveFlags)DrawOp_unpackData(op32); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 327 | |
| 328 | const SkRect* bounds = NULL; |
| 329 | if (flags & kSaveLayer_HasBounds_DrawOpFlag) { |
| 330 | bounds = skip<SkRect>(reader); |
| 331 | } |
| 332 | const SkPaint* paint = NULL; |
| 333 | if (flags & kSaveLayer_HasPaint_DrawOpFlag) { |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 334 | paint = &state->paint(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 335 | } |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 336 | canvas->saveLayer(bounds, paint, saveFlags); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static void restore_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 340 | SkGPipeState* state) { |
| 341 | canvas->restore(); |
| 342 | } |
| 343 | |
| 344 | /////////////////////////////////////////////////////////////////////////////// |
| 345 | |
| 346 | static void drawClear_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 347 | SkGPipeState* state) { |
| 348 | SkColor color = 0; |
| 349 | if (DrawOp_unpackFlags(op32) & kClear_HasColor_DrawOpFlag) { |
| 350 | color = reader->readU32(); |
| 351 | } |
| 352 | canvas->clear(color); |
| 353 | } |
| 354 | |
| 355 | static void drawPaint_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 356 | SkGPipeState* state) { |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 357 | if (state->shouldDraw()) { |
| 358 | canvas->drawPaint(state->paint()); |
| 359 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static void drawPoints_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 363 | SkGPipeState* state) { |
| 364 | SkCanvas::PointMode mode = (SkCanvas::PointMode)DrawOp_unpackFlags(op32); |
| 365 | size_t count = reader->readU32(); |
| 366 | const SkPoint* pts = skip<SkPoint>(reader, count); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 367 | if (state->shouldDraw()) { |
| 368 | canvas->drawPoints(mode, count, pts, state->paint()); |
| 369 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 370 | } |
| 371 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 372 | static void drawOval_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 373 | SkGPipeState* state) { |
| 374 | const SkRect* rect = skip<SkRect>(reader); |
| 375 | if (state->shouldDraw()) { |
| 376 | canvas->drawOval(*rect, state->paint()); |
| 377 | } |
| 378 | } |
| 379 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 380 | static void drawRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 381 | SkGPipeState* state) { |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 382 | const SkRect* rect = skip<SkRect>(reader); |
| 383 | if (state->shouldDraw()) { |
| 384 | canvas->drawRect(*rect, state->paint()); |
| 385 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 386 | } |
| 387 | |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 388 | static void drawRRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 389 | SkGPipeState* state) { |
| 390 | SkRRect rrect; |
| 391 | reader->readRRect(&rrect); |
| 392 | if (state->shouldDraw()) { |
| 393 | canvas->drawRRect(rrect, state->paint()); |
| 394 | } |
| 395 | } |
| 396 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 397 | static void drawDRRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 398 | SkGPipeState* state) { |
| 399 | SkRRect outer, inner; |
| 400 | reader->readRRect(&outer); |
| 401 | reader->readRRect(&inner); |
| 402 | if (state->shouldDraw()) { |
| 403 | canvas->drawDRRect(outer, inner, state->paint()); |
| 404 | } |
| 405 | } |
| 406 | |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame^] | 407 | static void drawPatch_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 408 | SkGPipeState* state) { |
| 409 | SkPatch patch; |
| 410 | reader->readPatch(&patch); |
| 411 | if (state->shouldDraw()) { |
| 412 | canvas->drawPatch(patch, state->paint()); |
| 413 | } |
| 414 | } |
| 415 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 416 | static void drawPath_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 417 | SkGPipeState* state) { |
| 418 | SkPath path; |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 419 | reader->readPath(&path); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 420 | if (state->shouldDraw()) { |
| 421 | canvas->drawPath(path, state->paint()); |
| 422 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static void drawVertices_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 426 | SkGPipeState* state) { |
| 427 | unsigned flags = DrawOp_unpackFlags(op32); |
| 428 | |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 429 | SkCanvas::VertexMode vmode = (SkCanvas::VertexMode)reader->readU32(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 430 | int vertexCount = reader->readU32(); |
| 431 | const SkPoint* verts = skip<SkPoint>(reader, vertexCount); |
| 432 | |
| 433 | const SkPoint* texs = NULL; |
| 434 | if (flags & kDrawVertices_HasTexs_DrawOpFlag) { |
| 435 | texs = skip<SkPoint>(reader, vertexCount); |
| 436 | } |
| 437 | |
| 438 | const SkColor* colors = NULL; |
| 439 | if (flags & kDrawVertices_HasColors_DrawOpFlag) { |
| 440 | colors = skip<SkColor>(reader, vertexCount); |
| 441 | } |
| 442 | |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 443 | SkAutoTUnref<SkXfermode> xfer; |
| 444 | if (flags & kDrawVertices_HasXfermode_DrawOpFlag) { |
| 445 | SkXfermode::Mode mode = (SkXfermode::Mode)reader->readU32(); |
| 446 | xfer.reset(SkXfermode::Create(mode)); |
| 447 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 448 | |
| 449 | int indexCount = 0; |
| 450 | const uint16_t* indices = NULL; |
| 451 | if (flags & kDrawVertices_HasIndices_DrawOpFlag) { |
| 452 | indexCount = reader->readU32(); |
| 453 | indices = skipAlign<uint16_t>(reader, indexCount); |
| 454 | } |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 455 | if (state->shouldDraw()) { |
reed@google.com | 85e143c | 2013-12-30 15:51:25 +0000 | [diff] [blame] | 456 | canvas->drawVertices(vmode, vertexCount, verts, texs, colors, xfer, |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 457 | indices, indexCount, state->paint()); |
| 458 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /////////////////////////////////////////////////////////////////////////////// |
| 462 | |
| 463 | static void drawText_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 464 | SkGPipeState* state) { |
| 465 | size_t len = reader->readU32(); |
| 466 | const void* text = reader->skip(SkAlign4(len)); |
| 467 | const SkScalar* xy = skip<SkScalar>(reader, 2); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 468 | if (state->shouldDraw()) { |
| 469 | canvas->drawText(text, len, xy[0], xy[1], state->paint()); |
| 470 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static void drawPosText_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 474 | SkGPipeState* state) { |
| 475 | size_t len = reader->readU32(); |
| 476 | const void* text = reader->skip(SkAlign4(len)); |
| 477 | size_t posCount = reader->readU32(); // compute by our writer |
| 478 | const SkPoint* pos = skip<SkPoint>(reader, posCount); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 479 | if (state->shouldDraw()) { |
| 480 | canvas->drawPosText(text, len, pos, state->paint()); |
| 481 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static void drawPosTextH_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 485 | SkGPipeState* state) { |
| 486 | size_t len = reader->readU32(); |
| 487 | const void* text = reader->skip(SkAlign4(len)); |
| 488 | size_t posCount = reader->readU32(); // compute by our writer |
| 489 | const SkScalar* xpos = skip<SkScalar>(reader, posCount); |
| 490 | SkScalar constY = reader->readScalar(); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 491 | if (state->shouldDraw()) { |
| 492 | canvas->drawPosTextH(text, len, xpos, constY, state->paint()); |
| 493 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | static void drawTextOnPath_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 497 | SkGPipeState* state) { |
| 498 | size_t len = reader->readU32(); |
| 499 | const void* text = reader->skip(SkAlign4(len)); |
| 500 | |
| 501 | SkPath path; |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 502 | reader->readPath(&path); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 503 | |
| 504 | SkMatrix matrixStorage; |
| 505 | const SkMatrix* matrix = NULL; |
| 506 | if (DrawOp_unpackFlags(op32) & kDrawTextOnPath_HasMatrix_DrawOpFlag) { |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 507 | reader->readMatrix(&matrixStorage); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 508 | matrix = &matrixStorage; |
| 509 | } |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 510 | if (state->shouldDraw()) { |
| 511 | canvas->drawTextOnPath(text, len, path, matrix, state->paint()); |
| 512 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /////////////////////////////////////////////////////////////////////////////// |
| 516 | |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 517 | class BitmapHolder : SkNoncopyable { |
| 518 | public: |
| 519 | BitmapHolder(SkReader32* reader, uint32_t op32, SkGPipeState* state); |
| 520 | ~BitmapHolder() { |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 521 | if (fHeapEntry != NULL) { |
| 522 | fHeapEntry->releaseRef(); |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 523 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 524 | } |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 525 | const SkBitmap* getBitmap() { |
| 526 | return fBitmap; |
| 527 | } |
| 528 | private: |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 529 | SkBitmapHeapEntry* fHeapEntry; |
| 530 | const SkBitmap* fBitmap; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 531 | SkBitmap fBitmapStorage; |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 532 | }; |
| 533 | |
| 534 | BitmapHolder::BitmapHolder(SkReader32* reader, uint32_t op32, |
| 535 | SkGPipeState* state) { |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 536 | const unsigned flags = state->getFlags(); |
| 537 | const unsigned index = DrawOp_unpackData(op32); |
| 538 | if (shouldFlattenBitmaps(flags)) { |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 539 | fHeapEntry = NULL; |
| 540 | fBitmap = state->getBitmap(index); |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 541 | } else { |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 542 | SkBitmapHeapEntry* entry = state->getSharedHeap()->getEntry(index); |
| 543 | if (SkToBool(flags & SkGPipeWriter::kSimultaneousReaders_Flag)) { |
| 544 | // Make a shallow copy for thread safety. Each thread will point to the same SkPixelRef, |
| 545 | // which is thread safe. |
| 546 | fBitmapStorage = *entry->getBitmap(); |
| 547 | fBitmap = &fBitmapStorage; |
| 548 | // Release the ref on the bitmap now, since we made our own copy. |
| 549 | entry->releaseRef(); |
| 550 | fHeapEntry = NULL; |
| 551 | } else { |
| 552 | SkASSERT(!shouldFlattenBitmaps(flags)); |
| 553 | SkASSERT(!SkToBool(flags & SkGPipeWriter::kSimultaneousReaders_Flag)); |
| 554 | fHeapEntry = entry; |
| 555 | fBitmap = fHeapEntry->getBitmap(); |
| 556 | } |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 557 | } |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 558 | } |
| 559 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 560 | static void drawBitmap_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 561 | SkGPipeState* state) { |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 562 | BitmapHolder holder(reader, op32, state); |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 563 | bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_DrawOpFlag); |
scroggo@google.com | 5a2e879 | 2012-04-20 17:39:51 +0000 | [diff] [blame] | 564 | SkScalar left = reader->readScalar(); |
| 565 | SkScalar top = reader->readScalar(); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 566 | const SkBitmap* bitmap = holder.getBitmap(); |
| 567 | if (state->shouldDraw()) { |
| 568 | canvas->drawBitmap(*bitmap, left, top, hasPaint ? &state->paint() : NULL); |
| 569 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static void drawBitmapMatrix_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 573 | SkGPipeState* state) { |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 574 | BitmapHolder holder(reader, op32, state); |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 575 | bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_DrawOpFlag); |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 576 | SkMatrix matrix; |
| 577 | reader->readMatrix(&matrix); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 578 | const SkBitmap* bitmap = holder.getBitmap(); |
| 579 | if (state->shouldDraw()) { |
| 580 | canvas->drawBitmapMatrix(*bitmap, matrix, |
| 581 | hasPaint ? &state->paint() : NULL); |
| 582 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 583 | } |
| 584 | |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 585 | static void drawBitmapNine_rp(SkCanvas* canvas, SkReader32* reader, |
| 586 | uint32_t op32, SkGPipeState* state) { |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 587 | BitmapHolder holder(reader, op32, state); |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 588 | bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_DrawOpFlag); |
scroggo@google.com | 691703c | 2012-06-05 14:58:40 +0000 | [diff] [blame] | 589 | const SkIRect* center = skip<SkIRect>(reader); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 590 | const SkRect* dst = skip<SkRect>(reader); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 591 | const SkBitmap* bitmap = holder.getBitmap(); |
| 592 | if (state->shouldDraw()) { |
| 593 | canvas->drawBitmapNine(*bitmap, *center, *dst, |
| 594 | hasPaint ? &state->paint() : NULL); |
| 595 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static void drawBitmapRect_rp(SkCanvas* canvas, SkReader32* reader, |
| 599 | uint32_t op32, SkGPipeState* state) { |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 600 | BitmapHolder holder(reader, op32, state); |
scroggo@google.com | 58be682 | 2012-07-30 14:40:01 +0000 | [diff] [blame] | 601 | unsigned flags = DrawOp_unpackFlags(op32); |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 602 | bool hasPaint = SkToBool(flags & kDrawBitmap_HasPaint_DrawOpFlag); |
| 603 | bool hasSrc = SkToBool(flags & kDrawBitmap_HasSrcRect_DrawOpFlag); |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 604 | const SkRect* src; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 605 | if (hasSrc) { |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 606 | src = skip<SkRect>(reader); |
scroggo@google.com | 691703c | 2012-06-05 14:58:40 +0000 | [diff] [blame] | 607 | } else { |
| 608 | src = NULL; |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 609 | } |
robertphillips@google.com | 31acc11 | 2013-08-20 12:13:48 +0000 | [diff] [blame] | 610 | SkCanvas::DrawBitmapRectFlags dbmrFlags = SkCanvas::kNone_DrawBitmapRectFlag; |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 611 | if (flags & kDrawBitmap_Bleed_DrawOpFlag) { |
| 612 | dbmrFlags = (SkCanvas::DrawBitmapRectFlags)(dbmrFlags|SkCanvas::kBleed_DrawBitmapRectFlag); |
| 613 | } |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 614 | const SkRect* dst = skip<SkRect>(reader); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 615 | const SkBitmap* bitmap = holder.getBitmap(); |
| 616 | if (state->shouldDraw()) { |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 617 | canvas->drawBitmapRectToRect(*bitmap, src, *dst, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 618 | hasPaint ? &state->paint() : NULL, dbmrFlags); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 619 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | static void drawSprite_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 623 | SkGPipeState* state) { |
scroggo@google.com | 284bf50 | 2012-07-17 16:10:34 +0000 | [diff] [blame] | 624 | BitmapHolder holder(reader, op32, state); |
scroggo@google.com | 460a23e | 2012-08-16 17:56:49 +0000 | [diff] [blame] | 625 | bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_DrawOpFlag); |
scroggo@google.com | 691703c | 2012-06-05 14:58:40 +0000 | [diff] [blame] | 626 | const SkIPoint* point = skip<SkIPoint>(reader); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 627 | const SkBitmap* bitmap = holder.getBitmap(); |
| 628 | if (state->shouldDraw()) { |
| 629 | canvas->drawSprite(*bitmap, point->fX, point->fY, hasPaint ? &state->paint() : NULL); |
| 630 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /////////////////////////////////////////////////////////////////////////////// |
| 634 | |
| 635 | static void drawData_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 636 | SkGPipeState* state) { |
| 637 | // since we don't have a paint, we can use data for our (small) sizes |
| 638 | size_t size = DrawOp_unpackData(op32); |
| 639 | if (0 == size) { |
| 640 | size = reader->readU32(); |
| 641 | } |
| 642 | const void* data = reader->skip(SkAlign4(size)); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 643 | if (state->shouldDraw()) { |
| 644 | canvas->drawData(data, size); |
| 645 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 646 | } |
| 647 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 648 | static void drawPicture_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, |
| 649 | SkGPipeState* state) { |
| 650 | UNIMPLEMENTED |
| 651 | } |
| 652 | |
| 653 | /////////////////////////////////////////////////////////////////////////////// |
| 654 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 655 | static void paintOp_rp(SkCanvas*, SkReader32* reader, uint32_t op32, |
| 656 | SkGPipeState* state) { |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 657 | size_t offset = reader->offset(); |
| 658 | size_t stop = offset + PaintOp_unpackData(op32); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 659 | SkPaint* p = state->editPaint(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 660 | |
| 661 | do { |
| 662 | uint32_t p32 = reader->readU32(); |
| 663 | unsigned op = PaintOp_unpackOp(p32); |
| 664 | unsigned data = PaintOp_unpackData(p32); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 665 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 666 | // SkDebugf(" read %08X op=%d flags=%d data=%d\n", p32, op, done, data); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 667 | |
| 668 | switch (op) { |
| 669 | case kReset_PaintOp: p->reset(); break; |
| 670 | case kFlags_PaintOp: p->setFlags(data); break; |
| 671 | case kColor_PaintOp: p->setColor(reader->readU32()); break; |
commit-bot@chromium.org | 85faf50 | 2014-04-16 12:58:02 +0000 | [diff] [blame] | 672 | case kFilterLevel_PaintOp: p->setFilterLevel((SkPaint::FilterLevel)data); break; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 673 | case kStyle_PaintOp: p->setStyle((SkPaint::Style)data); break; |
| 674 | case kJoin_PaintOp: p->setStrokeJoin((SkPaint::Join)data); break; |
| 675 | case kCap_PaintOp: p->setStrokeCap((SkPaint::Cap)data); break; |
| 676 | case kWidth_PaintOp: p->setStrokeWidth(reader->readScalar()); break; |
| 677 | case kMiter_PaintOp: p->setStrokeMiter(reader->readScalar()); break; |
| 678 | case kEncoding_PaintOp: |
| 679 | p->setTextEncoding((SkPaint::TextEncoding)data); |
| 680 | break; |
| 681 | case kHinting_PaintOp: p->setHinting((SkPaint::Hinting)data); break; |
| 682 | case kAlign_PaintOp: p->setTextAlign((SkPaint::Align)data); break; |
| 683 | case kTextSize_PaintOp: p->setTextSize(reader->readScalar()); break; |
| 684 | case kTextScaleX_PaintOp: p->setTextScaleX(reader->readScalar()); break; |
| 685 | case kTextSkewX_PaintOp: p->setTextSkewX(reader->readScalar()); break; |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 686 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 687 | case kFlatIndex_PaintOp: { |
| 688 | PaintFlats pf = (PaintFlats)PaintOp_unpackFlags(p32); |
| 689 | unsigned index = data; |
| 690 | set_paintflat(p, state->getFlat(index), pf); |
| 691 | break; |
| 692 | } |
| 693 | |
scroggo@google.com | 3cb969f | 2012-07-27 20:39:19 +0000 | [diff] [blame] | 694 | case kTypeface_PaintOp: |
| 695 | SkASSERT(SkToBool(state->getFlags() & |
| 696 | SkGPipeWriter::kCrossProcess_Flag)); |
| 697 | state->setTypeface(p, data); break; |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 698 | default: SkDEBUGFAIL("bad paintop"); return; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 699 | } |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 700 | SkASSERT(reader->offset() <= stop); |
reed@google.com | 3189158 | 2011-05-12 03:03:56 +0000 | [diff] [blame] | 701 | } while (reader->offset() < stop); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 702 | } |
| 703 | |
scroggo@google.com | 3cb969f | 2012-07-27 20:39:19 +0000 | [diff] [blame] | 704 | static void typeface_rp(SkCanvas*, SkReader32* reader, uint32_t, |
| 705 | SkGPipeState* state) { |
| 706 | SkASSERT(!SkToBool(state->getFlags() & SkGPipeWriter::kCrossProcess_Flag)); |
| 707 | SkPaint* p = state->editPaint(); |
| 708 | p->setTypeface(static_cast<SkTypeface*>(reader->readPtr())); |
| 709 | } |
| 710 | |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 711 | static void annotation_rp(SkCanvas*, SkReader32* reader, uint32_t op32, |
| 712 | SkGPipeState* state) { |
| 713 | SkPaint* p = state->editPaint(); |
skia.committer@gmail.com | fbc58a3 | 2013-10-15 07:02:27 +0000 | [diff] [blame] | 714 | |
commit-bot@chromium.org | 89ff3dd | 2013-10-29 20:29:38 +0000 | [diff] [blame] | 715 | const size_t size = DrawOp_unpackData(op32); |
| 716 | if (size > 0) { |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 717 | SkReadBuffer buffer(reader->skip(size), size); |
commit-bot@chromium.org | d957984 | 2014-02-27 11:47:36 +0000 | [diff] [blame] | 718 | p->setAnnotation(SkAnnotation::Create(buffer))->unref(); |
commit-bot@chromium.org | 89ff3dd | 2013-10-29 20:29:38 +0000 | [diff] [blame] | 719 | SkASSERT(buffer.offset() == size); |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 720 | } else { |
| 721 | p->setAnnotation(NULL); |
| 722 | } |
| 723 | } |
| 724 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 725 | /////////////////////////////////////////////////////////////////////////////// |
| 726 | |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 727 | static void def_Typeface_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState* state) { |
| 728 | state->addTypeface(); |
| 729 | } |
| 730 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 731 | static void def_PaintFlat_rp(SkCanvas*, SkReader32*, uint32_t op32, |
| 732 | SkGPipeState* state) { |
| 733 | PaintFlats pf = (PaintFlats)DrawOp_unpackFlags(op32); |
| 734 | unsigned index = DrawOp_unpackData(op32); |
| 735 | state->defFlattenable(pf, index); |
| 736 | } |
| 737 | |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 738 | static void def_Bitmap_rp(SkCanvas*, SkReader32*, uint32_t op32, |
| 739 | SkGPipeState* state) { |
| 740 | unsigned index = DrawOp_unpackData(op32); |
| 741 | state->addBitmap(index); |
| 742 | } |
| 743 | |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 744 | static void def_Factory_rp(SkCanvas*, SkReader32* reader, uint32_t, |
| 745 | SkGPipeState* state) { |
| 746 | state->defFactory(reader->readString()); |
| 747 | } |
| 748 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 749 | /////////////////////////////////////////////////////////////////////////////// |
| 750 | |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 751 | static void skip_rp(SkCanvas*, SkReader32* reader, uint32_t op32, SkGPipeState*) { |
| 752 | size_t bytes = DrawOp_unpackData(op32); |
| 753 | (void)reader->skip(bytes); |
| 754 | } |
| 755 | |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 756 | static void reportFlags_rp(SkCanvas*, SkReader32*, uint32_t op32, |
scroggo@google.com | 565254b | 2012-06-28 15:41:32 +0000 | [diff] [blame] | 757 | SkGPipeState* state) { |
| 758 | unsigned flags = DrawOp_unpackFlags(op32); |
| 759 | state->setFlags(flags); |
| 760 | } |
| 761 | |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame] | 762 | static void shareBitmapHeap_rp(SkCanvas*, SkReader32* reader, uint32_t, |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 763 | SkGPipeState* state) { |
| 764 | state->setSharedHeap(static_cast<SkBitmapHeap*>(reader->readPtr())); |
| 765 | } |
| 766 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 767 | static void done_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState*) {} |
| 768 | |
| 769 | typedef void (*ReadProc)(SkCanvas*, SkReader32*, uint32_t op32, SkGPipeState*); |
| 770 | |
| 771 | static const ReadProc gReadTable[] = { |
reed@google.com | acd471f | 2011-05-03 21:26:46 +0000 | [diff] [blame] | 772 | skip_rp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 773 | clipPath_rp, |
| 774 | clipRegion_rp, |
| 775 | clipRect_rp, |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 776 | clipRRect_rp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 777 | concat_rp, |
| 778 | drawBitmap_rp, |
| 779 | drawBitmapMatrix_rp, |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 780 | drawBitmapNine_rp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 781 | drawBitmapRect_rp, |
| 782 | drawClear_rp, |
| 783 | drawData_rp, |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 784 | drawDRRect_rp, |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 785 | drawOval_rp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 786 | drawPaint_rp, |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame^] | 787 | drawPatch_rp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 788 | drawPath_rp, |
| 789 | drawPicture_rp, |
| 790 | drawPoints_rp, |
| 791 | drawPosText_rp, |
| 792 | drawPosTextH_rp, |
| 793 | drawRect_rp, |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 794 | drawRRect_rp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 795 | drawSprite_rp, |
| 796 | drawText_rp, |
| 797 | drawTextOnPath_rp, |
| 798 | drawVertices_rp, |
| 799 | restore_rp, |
| 800 | rotate_rp, |
| 801 | save_rp, |
| 802 | saveLayer_rp, |
| 803 | scale_rp, |
| 804 | setMatrix_rp, |
| 805 | skew_rp, |
| 806 | translate_rp, |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 807 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 808 | paintOp_rp, |
scroggo@google.com | 3cb969f | 2012-07-27 20:39:19 +0000 | [diff] [blame] | 809 | typeface_rp, |
reed@google.com | 0cd2ac6 | 2013-10-14 20:02:44 +0000 | [diff] [blame] | 810 | annotation_rp, |
| 811 | |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 812 | def_Typeface_rp, |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 813 | def_PaintFlat_rp, |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 814 | def_Bitmap_rp, |
scroggo@google.com | 0c3e5fe | 2012-08-01 19:34:20 +0000 | [diff] [blame] | 815 | def_Factory_rp, |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 816 | |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 817 | reportFlags_rp, |
scroggo@google.com | d9d2967 | 2012-08-14 17:21:34 +0000 | [diff] [blame] | 818 | shareBitmapHeap_rp, |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 819 | done_rp |
| 820 | }; |
| 821 | |
| 822 | /////////////////////////////////////////////////////////////////////////////// |
| 823 | |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 824 | SkGPipeState::SkGPipeState() |
| 825 | : fReader(0) |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 826 | , fSilent(false) |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 827 | , fSharedHeap(NULL) |
| 828 | , fFlags(0) { |
| 829 | |
| 830 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 831 | |
reed@google.com | b55d118 | 2011-05-11 00:42:04 +0000 | [diff] [blame] | 832 | SkGPipeState::~SkGPipeState() { |
reed@google.com | 6bac947 | 2011-06-21 19:24:00 +0000 | [diff] [blame] | 833 | fTypefaces.safeUnrefAll(); |
| 834 | fFlatArray.safeUnrefAll(); |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 835 | fBitmaps.deleteAll(); |
scroggo@google.com | 10dccde | 2012-08-08 20:43:22 +0000 | [diff] [blame] | 836 | SkSafeUnref(fSharedHeap); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | /////////////////////////////////////////////////////////////////////////////// |
| 840 | |
| 841 | #include "SkGPipe.h" |
| 842 | |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 843 | SkGPipeReader::SkGPipeReader() { |
| 844 | fCanvas = NULL; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 845 | fState = NULL; |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 846 | fProc = NULL; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 847 | } |
| 848 | |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 849 | SkGPipeReader::SkGPipeReader(SkCanvas* target) { |
| 850 | fCanvas = NULL; |
| 851 | this->setCanvas(target); |
| 852 | fState = NULL; |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 853 | fProc = NULL; |
scroggo@google.com | 72c9672 | 2012-06-06 21:07:10 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | void SkGPipeReader::setCanvas(SkCanvas *target) { |
| 857 | SkRefCnt_SafeAssign(fCanvas, target); |
| 858 | } |
| 859 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 860 | SkGPipeReader::~SkGPipeReader() { |
| 861 | SkSafeUnref(fCanvas); |
| 862 | delete fState; |
| 863 | } |
| 864 | |
reed@google.com | 80b09de | 2011-05-23 13:54:24 +0000 | [diff] [blame] | 865 | SkGPipeReader::Status SkGPipeReader::playback(const void* data, size_t length, |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 866 | uint32_t playbackFlags, size_t* bytesRead) { |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 867 | if (NULL == fCanvas) { |
| 868 | return kError_Status; |
| 869 | } |
| 870 | |
| 871 | if (NULL == fState) { |
| 872 | fState = new SkGPipeState; |
| 873 | } |
| 874 | |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 875 | fState->setSilent(playbackFlags & kSilent_PlaybackFlag); |
| 876 | |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 877 | SkASSERT(SK_ARRAY_COUNT(gReadTable) == (kDone_DrawOp + 1)); |
| 878 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 879 | const ReadProc* table = gReadTable; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 880 | SkReadBuffer reader(data, length); |
scroggo@google.com | 74b7ffd | 2013-04-30 02:32:41 +0000 | [diff] [blame] | 881 | reader.setBitmapDecoder(fProc); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 882 | SkCanvas* canvas = fCanvas; |
reed@google.com | 80b09de | 2011-05-23 13:54:24 +0000 | [diff] [blame] | 883 | Status status = kEOF_Status; |
reed@google.com | bb6793b | 2011-05-05 15:18:15 +0000 | [diff] [blame] | 884 | |
| 885 | fState->setReader(&reader); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 886 | while (!reader.eof()) { |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 887 | uint32_t op32 = reader.readUInt(); |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 888 | unsigned op = DrawOp_unpackOp(op32); |
caryclark@google.com | 920901d | 2012-06-06 12:04:11 +0000 | [diff] [blame] | 889 | // SkDEBUGCODE(DrawOps drawOp = (DrawOps)op;) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 890 | |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 891 | if (op >= SK_ARRAY_COUNT(gReadTable)) { |
| 892 | SkDebugf("---- bad op during GPipeState::playback\n"); |
reed@google.com | 80b09de | 2011-05-23 13:54:24 +0000 | [diff] [blame] | 893 | status = kError_Status; |
| 894 | break; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 895 | } |
| 896 | if (kDone_DrawOp == op) { |
reed@google.com | 80b09de | 2011-05-23 13:54:24 +0000 | [diff] [blame] | 897 | status = kDone_Status; |
| 898 | break; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 899 | } |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 900 | table[op](canvas, reader.getReader32(), op32, fState); |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 901 | if ((playbackFlags & kReadAtom_PlaybackFlag) && |
yangsu@google.com | 1bce0a5 | 2011-06-16 21:08:19 +0000 | [diff] [blame] | 902 | (table[op] != paintOp_rp && |
| 903 | table[op] != def_Typeface_rp && |
scroggo@google.com | 16d1d0b | 2012-05-02 19:09:40 +0000 | [diff] [blame] | 904 | table[op] != def_PaintFlat_rp && |
| 905 | table[op] != def_Bitmap_rp |
yangsu@google.com | 1bce0a5 | 2011-06-16 21:08:19 +0000 | [diff] [blame] | 906 | )) { |
| 907 | status = kReadAtom_Status; |
| 908 | break; |
| 909 | } |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 910 | } |
reed@google.com | 80b09de | 2011-05-23 13:54:24 +0000 | [diff] [blame] | 911 | |
| 912 | if (bytesRead) { |
reed@google.com | ac45f00 | 2011-05-24 13:50:21 +0000 | [diff] [blame] | 913 | *bytesRead = reader.offset(); |
reed@google.com | 80b09de | 2011-05-23 13:54:24 +0000 | [diff] [blame] | 914 | } |
| 915 | return status; |
reed@google.com | bb6992a | 2011-04-26 17:41:56 +0000 | [diff] [blame] | 916 | } |