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