commit-bot@chromium.org | c4b21e6 | 2014-04-11 18:33:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 8 | #include "SkData.h" |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 9 | #include "SkRecorder.h" |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 10 | #include "SkPatchUtils.h" |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 11 | #include "SkPicture.h" |
| 12 | |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 13 | SkRecorder::SkRecorder(SkRecord* record, int width, int height) |
reed | 78e2768 | 2014-11-19 08:04:34 -0800 | [diff] [blame^] | 14 | : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip_InitFlag) |
| 15 | , fRecord(record) |
| 16 | , fSaveLayerCount(0) {} |
| 17 | |
| 18 | SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds) |
| 19 | : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) |
mtklein | 29dfaa8 | 2014-09-04 14:12:44 -0700 | [diff] [blame] | 20 | , fRecord(record) |
| 21 | , fSaveLayerCount(0) {} |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 22 | |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 23 | SkRecorder::~SkRecorder() { |
| 24 | fDrawableList.unrefAll(); |
| 25 | } |
| 26 | |
commit-bot@chromium.org | 732bd66 | 2014-04-24 15:22:55 +0000 | [diff] [blame] | 27 | void SkRecorder::forgetRecord() { |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 28 | fDrawableList.unrefAll(); |
| 29 | fDrawableList.reset(); |
commit-bot@chromium.org | 732bd66 | 2014-04-24 15:22:55 +0000 | [diff] [blame] | 30 | fRecord = NULL; |
| 31 | } |
| 32 | |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 33 | // ReleaseProc for SkData, assuming the data was allocated via sk_malloc, and its contents are an |
| 34 | // array of SkRefCnt* which need to be unref'd. |
| 35 | // |
| 36 | static void unref_all_malloc_releaseProc(const void* ptr, size_t length, void* context) { |
| 37 | SkASSERT(ptr == context); // our context is our ptr, allocated via sk_malloc |
| 38 | int count = SkToInt(length / sizeof(SkRefCnt*)); |
| 39 | SkASSERT(count * sizeof(SkRefCnt*) == length); // our length is snug for the array |
| 40 | |
| 41 | SkRefCnt* const* array = reinterpret_cast<SkRefCnt* const*>(ptr); |
| 42 | for (int i = 0; i < count; ++i) { |
| 43 | SkSafeUnref(array[i]); |
| 44 | } |
| 45 | sk_free(context); |
| 46 | } |
| 47 | |
| 48 | // Return an uninitialized SkData sized for "count" SkRefCnt pointers. They will be unref'd when |
| 49 | // the SkData is destroyed. |
| 50 | // |
| 51 | static SkData* new_uninitialized_refcnt_ptrs(int count) { |
| 52 | size_t length = count * sizeof(SkRefCnt*); |
| 53 | void* array = sk_malloc_throw(length); |
| 54 | void* context = array; |
| 55 | return SkData::NewWithProc(array, length, unref_all_malloc_releaseProc, context); |
| 56 | } |
| 57 | |
| 58 | SkData* SkRecorder::newDrawableSnapshot(SkBBHFactory* factory, uint32_t recordFlags) { |
| 59 | const int count = fDrawableList.count(); |
| 60 | if (0 == count) { |
| 61 | return NULL; |
| 62 | } |
| 63 | SkData* data = new_uninitialized_refcnt_ptrs(count); |
| 64 | SkPicture** pics = reinterpret_cast<SkPicture**>(data->writable_data()); |
| 65 | for (int i = 0; i < count; ++i) { |
| 66 | pics[i] = fDrawableList[i]->newPictureSnapshot(factory, recordFlags); |
| 67 | } |
| 68 | return data; |
| 69 | } |
| 70 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 71 | // To make appending to fRecord a little less verbose. |
| 72 | #define APPEND(T, ...) \ |
| 73 | SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__VA_ARGS__)) |
| 74 | |
commit-bot@chromium.org | a095041 | 2014-05-29 16:52:40 +0000 | [diff] [blame] | 75 | // For methods which must call back into SkCanvas. |
| 76 | #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 77 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 78 | // The structs we're creating all copy their constructor arguments. Given the way the SkRecords |
| 79 | // framework works, sometimes they happen to technically be copied twice, which is fine and elided |
| 80 | // into a single copy unless the class has a non-trivial copy constructor. For classes with |
| 81 | // non-trivial copy constructors, we skip the first copy (and its destruction) by wrapping the value |
| 82 | // with delay_copy(), forcing the argument to be passed by const&. |
| 83 | // |
| 84 | // This is used below for SkBitmap, SkPaint, SkPath, and SkRegion, which all have non-trivial copy |
| 85 | // constructors and destructors. You'll know you've got a good candidate T if you see ~T() show up |
| 86 | // unexpectedly on a profile of record time. Otherwise don't bother. |
| 87 | template <typename T> |
| 88 | class Reference { |
| 89 | public: |
| 90 | Reference(const T& x) : fX(x) {} |
| 91 | operator const T&() const { return fX; } |
| 92 | private: |
| 93 | const T& fX; |
| 94 | }; |
| 95 | |
| 96 | template <typename T> |
| 97 | static Reference<T> delay_copy(const T& x) { return Reference<T>(x); } |
| 98 | |
| 99 | // Use copy() only for optional arguments, to be copied if present or skipped if not. |
| 100 | // (For most types we just pass by value and let copy constructors do their thing.) |
| 101 | template <typename T> |
| 102 | T* SkRecorder::copy(const T* src) { |
| 103 | if (NULL == src) { |
| 104 | return NULL; |
| 105 | } |
| 106 | return SkNEW_PLACEMENT_ARGS(fRecord->alloc<T>(), T, (*src)); |
| 107 | } |
| 108 | |
| 109 | // This copy() is for arrays. |
| 110 | // It will work with POD or non-POD, though currently we only use it for POD. |
| 111 | template <typename T> |
reed | 2347b62 | 2014-08-07 12:19:50 -0700 | [diff] [blame] | 112 | T* SkRecorder::copy(const T src[], size_t count) { |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 113 | if (NULL == src) { |
| 114 | return NULL; |
| 115 | } |
| 116 | T* dst = fRecord->alloc<T>(count); |
reed | 2347b62 | 2014-08-07 12:19:50 -0700 | [diff] [blame] | 117 | for (size_t i = 0; i < count; i++) { |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 118 | SkNEW_PLACEMENT_ARGS(dst + i, T, (src[i])); |
| 119 | } |
| 120 | return dst; |
| 121 | } |
| 122 | |
| 123 | // Specialization for copying strings, using memcpy. |
| 124 | // This measured around 2x faster for copying code points, |
| 125 | // but I found no corresponding speedup for other arrays. |
| 126 | template <> |
reed | 2347b62 | 2014-08-07 12:19:50 -0700 | [diff] [blame] | 127 | char* SkRecorder::copy(const char src[], size_t count) { |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 128 | if (NULL == src) { |
| 129 | return NULL; |
| 130 | } |
| 131 | char* dst = fRecord->alloc<char>(count); |
| 132 | memcpy(dst, src, count); |
| 133 | return dst; |
| 134 | } |
| 135 | |
mtklein | 5f0e822 | 2014-08-22 11:44:26 -0700 | [diff] [blame] | 136 | // As above, assuming and copying a terminating \0. |
| 137 | template <> |
| 138 | char* SkRecorder::copy(const char* src) { |
| 139 | return this->copy(src, strlen(src)+1); |
| 140 | } |
| 141 | |
| 142 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 143 | void SkRecorder::clear(SkColor color) { |
| 144 | APPEND(Clear, color); |
| 145 | } |
| 146 | |
| 147 | void SkRecorder::drawPaint(const SkPaint& paint) { |
| 148 | APPEND(DrawPaint, delay_copy(paint)); |
| 149 | } |
| 150 | |
| 151 | void SkRecorder::drawPoints(PointMode mode, |
| 152 | size_t count, |
| 153 | const SkPoint pts[], |
| 154 | const SkPaint& paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 155 | APPEND(DrawPoints, delay_copy(paint), mode, count, this->copy(pts, count)); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | void SkRecorder::drawRect(const SkRect& rect, const SkPaint& paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 159 | APPEND(DrawRect, delay_copy(paint), rect); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void SkRecorder::drawOval(const SkRect& oval, const SkPaint& paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 163 | APPEND(DrawOval, delay_copy(paint), oval); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void SkRecorder::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 167 | APPEND(DrawRRect, delay_copy(paint), rrect); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 168 | } |
| 169 | |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 170 | void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 171 | APPEND(DrawDRRect, delay_copy(paint), outer, inner); |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 172 | } |
| 173 | |
reed | 6be2aa9 | 2014-11-18 11:08:05 -0800 | [diff] [blame] | 174 | void SkRecorder::onDrawDrawable(SkCanvasDrawable* drawable) { |
| 175 | *fDrawableList.append() = SkRef(drawable); |
| 176 | APPEND(DrawDrawable, drawable->getBounds(), fDrawableList.count() - 1); |
| 177 | } |
| 178 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 179 | void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 180 | APPEND(DrawPath, delay_copy(paint), delay_copy(path)); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void SkRecorder::drawBitmap(const SkBitmap& bitmap, |
| 184 | SkScalar left, |
| 185 | SkScalar top, |
| 186 | const SkPaint* paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 187 | APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void SkRecorder::drawBitmapRectToRect(const SkBitmap& bitmap, |
| 191 | const SkRect* src, |
| 192 | const SkRect& dst, |
| 193 | const SkPaint* paint, |
| 194 | DrawBitmapRectFlags flags) { |
| 195 | APPEND(DrawBitmapRectToRect, |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 196 | this->copy(paint), delay_copy(bitmap), this->copy(src), dst, flags); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void SkRecorder::drawBitmapMatrix(const SkBitmap& bitmap, |
| 200 | const SkMatrix& matrix, |
| 201 | const SkPaint* paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 202 | APPEND(DrawBitmapMatrix, this->copy(paint), delay_copy(bitmap), matrix); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void SkRecorder::drawBitmapNine(const SkBitmap& bitmap, |
| 206 | const SkIRect& center, |
| 207 | const SkRect& dst, |
| 208 | const SkPaint* paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 209 | APPEND(DrawBitmapNine, this->copy(paint), delay_copy(bitmap), center, dst); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 210 | } |
| 211 | |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 212 | void SkRecorder::drawImage(const SkImage* image, SkScalar left, SkScalar top, |
| 213 | const SkPaint* paint) { |
| 214 | APPEND(DrawImage, this->copy(paint), image, left, top); |
| 215 | } |
| 216 | |
| 217 | void SkRecorder::drawImageRect(const SkImage* image, const SkRect* src, |
| 218 | const SkRect& dst, |
| 219 | const SkPaint* paint) { |
| 220 | APPEND(DrawImageRect, this->copy(paint), image, this->copy(src), dst); |
| 221 | } |
| 222 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 223 | void SkRecorder::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPaint* paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 224 | APPEND(DrawSprite, this->copy(paint), delay_copy(bitmap), left, top); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 225 | } |
| 226 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 227 | void SkRecorder::onDrawText(const void* text, size_t byteLength, |
| 228 | SkScalar x, SkScalar y, const SkPaint& paint) { |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 229 | APPEND(DrawText, |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 230 | delay_copy(paint), this->copy((const char*)text, byteLength), byteLength, x, y); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 231 | } |
| 232 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 233 | void SkRecorder::onDrawPosText(const void* text, size_t byteLength, |
| 234 | const SkPoint pos[], const SkPaint& paint) { |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 235 | const unsigned points = paint.countText(text, byteLength); |
| 236 | APPEND(DrawPosText, |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 237 | delay_copy(paint), |
| 238 | this->copy((const char*)text, byteLength), |
| 239 | byteLength, |
| 240 | this->copy(pos, points)); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 241 | } |
| 242 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 243 | void SkRecorder::onDrawPosTextH(const void* text, size_t byteLength, |
| 244 | const SkScalar xpos[], SkScalar constY, const SkPaint& paint) { |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 245 | const unsigned points = paint.countText(text, byteLength); |
| 246 | APPEND(DrawPosTextH, |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 247 | delay_copy(paint), |
| 248 | this->copy((const char*)text, byteLength), |
| 249 | byteLength, |
| 250 | this->copy(xpos, points), |
| 251 | constY); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 252 | } |
| 253 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 254 | void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 255 | const SkMatrix* matrix, const SkPaint& paint) { |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 256 | APPEND(DrawTextOnPath, |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 257 | delay_copy(paint), |
| 258 | this->copy((const char*)text, byteLength), |
| 259 | byteLength, |
| 260 | delay_copy(path), |
| 261 | this->copy(matrix)); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 262 | } |
| 263 | |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 264 | void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 265 | const SkPaint& paint) { |
| 266 | APPEND(DrawTextBlob, delay_copy(paint), blob, x, y); |
| 267 | } |
| 268 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 269 | void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, const SkPaint* paint) { |
| 270 | APPEND(DrawPicture, this->copy(paint), pic, this->copy(matrix)); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | void SkRecorder::drawVertices(VertexMode vmode, |
| 274 | int vertexCount, const SkPoint vertices[], |
| 275 | const SkPoint texs[], const SkColor colors[], |
| 276 | SkXfermode* xmode, |
| 277 | const uint16_t indices[], int indexCount, const SkPaint& paint) { |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 278 | APPEND(DrawVertices, delay_copy(paint), |
| 279 | vmode, |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 280 | vertexCount, |
| 281 | this->copy(vertices, vertexCount), |
| 282 | texs ? this->copy(texs, vertexCount) : NULL, |
| 283 | colors ? this->copy(colors, vertexCount) : NULL, |
| 284 | xmode, |
| 285 | this->copy(indices, indexCount), |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 286 | indexCount); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 287 | } |
| 288 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 289 | void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 290 | const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint) { |
| 291 | APPEND(DrawPatch, delay_copy(paint), |
| 292 | cubics ? this->copy(cubics, SkPatchUtils::kNumCtrlPts) : NULL, |
| 293 | colors ? this->copy(colors, SkPatchUtils::kNumCorners) : NULL, |
| 294 | texCoords ? this->copy(texCoords, SkPatchUtils::kNumCorners) : NULL, |
| 295 | xmode); |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 298 | void SkRecorder::willSave() { |
mtklein | 29dfaa8 | 2014-09-04 14:12:44 -0700 | [diff] [blame] | 299 | fSaveIsSaveLayer.push(false); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 300 | APPEND(Save); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | SkCanvas::SaveLayerStrategy SkRecorder::willSaveLayer(const SkRect* bounds, |
| 304 | const SkPaint* paint, |
| 305 | SkCanvas::SaveFlags flags) { |
mtklein | 29dfaa8 | 2014-09-04 14:12:44 -0700 | [diff] [blame] | 306 | fSaveLayerCount++; |
| 307 | fSaveIsSaveLayer.push(true); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 308 | APPEND(SaveLayer, this->copy(bounds), this->copy(paint), flags); |
| 309 | return SkCanvas::kNoLayer_SaveLayerStrategy; |
| 310 | } |
| 311 | |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 312 | void SkRecorder::didRestore() { |
mtklein | 29dfaa8 | 2014-09-04 14:12:44 -0700 | [diff] [blame] | 313 | SkBool8 saveLayer; |
| 314 | fSaveIsSaveLayer.pop(&saveLayer); |
| 315 | if (saveLayer) { |
| 316 | fSaveLayerCount--; |
| 317 | } |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 318 | APPEND(Restore, this->devBounds(), this->getTotalMatrix()); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 319 | } |
| 320 | |
commit-bot@chromium.org | 03a99b8 | 2014-04-08 15:17:17 +0000 | [diff] [blame] | 321 | void SkRecorder::onPushCull(const SkRect& rect) { |
commit-bot@chromium.org | 88c3e27 | 2014-04-22 16:57:20 +0000 | [diff] [blame] | 322 | APPEND(PushCull, rect); |
commit-bot@chromium.org | 03a99b8 | 2014-04-08 15:17:17 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void SkRecorder::onPopCull() { |
| 326 | APPEND(PopCull); |
| 327 | } |
| 328 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 329 | void SkRecorder::didConcat(const SkMatrix& matrix) { |
mtklein | 6332f1d | 2014-08-19 07:09:40 -0700 | [diff] [blame] | 330 | this->didSetMatrix(this->getTotalMatrix()); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void SkRecorder::didSetMatrix(const SkMatrix& matrix) { |
mtklein | 46bc621 | 2014-08-20 09:44:28 -0700 | [diff] [blame] | 334 | SkDEVCODE(if (matrix != this->getTotalMatrix()) { |
mtklein | ec924b9 | 2014-08-20 09:22:28 -0700 | [diff] [blame] | 335 | matrix.dump(); |
| 336 | this->getTotalMatrix().dump(); |
| 337 | SkASSERT(matrix == this->getTotalMatrix()); |
| 338 | }) |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 339 | APPEND(SetMatrix, matrix); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void SkRecorder::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 343 | INHERITED(onClipRect, rect, op, edgeStyle); |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 344 | APPEND(ClipRect, this->devBounds(), rect, op, edgeStyle == kSoft_ClipEdgeStyle); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | void SkRecorder::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 348 | INHERITED(onClipRRect, rrect, op, edgeStyle); |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 349 | APPEND(ClipRRect, this->devBounds(), rrect, op, edgeStyle == kSoft_ClipEdgeStyle); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | void SkRecorder::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 353 | INHERITED(onClipPath, path, op, edgeStyle); |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 354 | APPEND(ClipPath, this->devBounds(), delay_copy(path), op, edgeStyle == kSoft_ClipEdgeStyle); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 358 | INHERITED(onClipRegion, deviceRgn, op); |
mtklein | a723b57 | 2014-08-15 11:49:49 -0700 | [diff] [blame] | 359 | APPEND(ClipRegion, this->devBounds(), delay_copy(deviceRgn), op); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 360 | } |
mtklein | 5f0e822 | 2014-08-22 11:44:26 -0700 | [diff] [blame] | 361 | |
| 362 | void SkRecorder::beginCommentGroup(const char* description) { |
| 363 | APPEND(BeginCommentGroup, this->copy(description)); |
| 364 | } |
| 365 | |
| 366 | void SkRecorder::addComment(const char* key, const char* value) { |
| 367 | APPEND(AddComment, this->copy(key), this->copy(value)); |
| 368 | } |
| 369 | |
| 370 | void SkRecorder::endCommentGroup() { |
| 371 | APPEND(EndCommentGroup); |
| 372 | } |
mtklein | 29dfaa8 | 2014-09-04 14:12:44 -0700 | [diff] [blame] | 373 | |
| 374 | bool SkRecorder::isDrawingToLayer() const { |
| 375 | return fSaveLayerCount > 0; |
| 376 | } |
| 377 | |
| 378 | void SkRecorder::drawData(const void* data, size_t length) { |
| 379 | APPEND(DrawData, copy((const char*)data), length); |
| 380 | } |