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