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