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