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" |
mtklein | d711d11 | 2015-07-01 07:04:37 -0700 | [diff] [blame] | 9 | #include "SkCanvasPriv.h" |
reed | 9b84f8c | 2016-07-28 14:26:13 -0700 | [diff] [blame] | 10 | #include "SkImage.h" |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 11 | #include "SkPatchUtils.h" |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 12 | #include "SkPicture.h" |
mtklein | 98b8485 | 2015-04-21 15:23:59 -0700 | [diff] [blame] | 13 | #include "SkRecorder.h" |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 14 | #include "SkSurface.h" |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 15 | |
reed | 3cb3840 | 2015-02-06 08:36:15 -0800 | [diff] [blame] | 16 | SkDrawableList::~SkDrawableList() { |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 17 | fArray.unrefAll(); |
| 18 | } |
| 19 | |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 20 | SkBigPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() { |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 21 | const int count = fArray.count(); |
| 22 | if (0 == count) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 23 | return nullptr; |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 24 | } |
| 25 | SkAutoTMalloc<const SkPicture*> pics(count); |
| 26 | for (int i = 0; i < count; ++i) { |
| 27 | pics[i] = fArray[i]->newPictureSnapshot(); |
| 28 | } |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 29 | return new SkBigPicture::SnapshotArray(pics.release(), count); |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 30 | } |
| 31 | |
reed | 3cb3840 | 2015-02-06 08:36:15 -0800 | [diff] [blame] | 32 | void SkDrawableList::append(SkDrawable* drawable) { |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 33 | *fArray.append() = SkRef(drawable); |
| 34 | } |
| 35 | |
| 36 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 37 | |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 38 | SkRecorder::SkRecorder(SkRecord* record, int width, int height, SkMiniRecorder* mr) |
Florin Malita | 439ace9 | 2016-12-02 12:05:41 -0500 | [diff] [blame] | 39 | : SkNoDrawCanvas(width, height) |
mtklein | d711d11 | 2015-07-01 07:04:37 -0700 | [diff] [blame] | 40 | , fDrawPictureMode(Record_DrawPictureMode) |
mtklein | 98b8485 | 2015-04-21 15:23:59 -0700 | [diff] [blame] | 41 | , fApproxBytesUsedBySubPictures(0) |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 42 | , fRecord(record) |
| 43 | , fMiniRecorder(mr) {} |
reed | 78e2768 | 2014-11-19 08:04:34 -0800 | [diff] [blame] | 44 | |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 45 | SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds, SkMiniRecorder* mr) |
Florin Malita | 439ace9 | 2016-12-02 12:05:41 -0500 | [diff] [blame] | 46 | : SkNoDrawCanvas(bounds.roundOut()) |
mtklein | d711d11 | 2015-07-01 07:04:37 -0700 | [diff] [blame] | 47 | , fDrawPictureMode(Record_DrawPictureMode) |
mtklein | 98b8485 | 2015-04-21 15:23:59 -0700 | [diff] [blame] | 48 | , fApproxBytesUsedBySubPictures(0) |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 49 | , fRecord(record) |
| 50 | , fMiniRecorder(mr) {} |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 51 | |
mtklein | d711d11 | 2015-07-01 07:04:37 -0700 | [diff] [blame] | 52 | void SkRecorder::reset(SkRecord* record, const SkRect& bounds, |
| 53 | DrawPictureMode dpm, SkMiniRecorder* mr) { |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 54 | this->forgetRecord(); |
mtklein | d711d11 | 2015-07-01 07:04:37 -0700 | [diff] [blame] | 55 | fDrawPictureMode = dpm; |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 56 | fRecord = record; |
Adrienne Walker | 6a280a5 | 2017-05-01 13:45:01 -0700 | [diff] [blame] | 57 | SkIRect rounded = bounds.roundOut(); |
| 58 | this->resetCanvas(rounded.right(), rounded.bottom()); |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 59 | fMiniRecorder = mr; |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 60 | } |
| 61 | |
commit-bot@chromium.org | 732bd66 | 2014-04-24 15:22:55 +0000 | [diff] [blame] | 62 | void SkRecorder::forgetRecord() { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 63 | fDrawableList.reset(nullptr); |
mtklein | 98b8485 | 2015-04-21 15:23:59 -0700 | [diff] [blame] | 64 | fApproxBytesUsedBySubPictures = 0; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 65 | fRecord = nullptr; |
commit-bot@chromium.org | 732bd66 | 2014-04-24 15:22:55 +0000 | [diff] [blame] | 66 | } |
| 67 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 68 | // To make appending to fRecord a little less verbose. |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 69 | #define APPEND(T, ...) \ |
| 70 | if (fMiniRecorder) { \ |
| 71 | this->flushMiniRecorder(); \ |
| 72 | } \ |
mtklein | 449d9b7 | 2015-09-28 10:33:02 -0700 | [diff] [blame] | 73 | new (fRecord->append<SkRecords::T>()) SkRecords::T{__VA_ARGS__} |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 74 | |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 75 | #define TRY_MINIRECORDER(method, ...) \ |
| 76 | if (fMiniRecorder && fMiniRecorder->method(__VA_ARGS__)) { return; } |
| 77 | |
Florin Malita | 439ace9 | 2016-12-02 12:05:41 -0500 | [diff] [blame] | 78 | // For methods which must call back into SkNoDrawCanvas. |
| 79 | #define INHERITED(method, ...) this->SkNoDrawCanvas::method(__VA_ARGS__) |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 80 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 81 | // Use copy() only for optional arguments, to be copied if present or skipped if not. |
| 82 | // (For most types we just pass by value and let copy constructors do their thing.) |
| 83 | template <typename T> |
| 84 | T* SkRecorder::copy(const T* src) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 85 | if (nullptr == src) { |
| 86 | return nullptr; |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 87 | } |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 88 | return new (fRecord->alloc<T>()) T(*src); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | // This copy() is for arrays. |
| 92 | // It will work with POD or non-POD, though currently we only use it for POD. |
| 93 | template <typename T> |
reed | 2347b62 | 2014-08-07 12:19:50 -0700 | [diff] [blame] | 94 | T* SkRecorder::copy(const T src[], size_t count) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 95 | if (nullptr == src) { |
| 96 | return nullptr; |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 97 | } |
| 98 | T* dst = fRecord->alloc<T>(count); |
reed | 2347b62 | 2014-08-07 12:19:50 -0700 | [diff] [blame] | 99 | for (size_t i = 0; i < count; i++) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 100 | new (dst + i) T(src[i]); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 101 | } |
| 102 | return dst; |
| 103 | } |
| 104 | |
| 105 | // Specialization for copying strings, using memcpy. |
| 106 | // This measured around 2x faster for copying code points, |
| 107 | // but I found no corresponding speedup for other arrays. |
| 108 | template <> |
reed | 2347b62 | 2014-08-07 12:19:50 -0700 | [diff] [blame] | 109 | char* SkRecorder::copy(const char src[], size_t count) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 110 | if (nullptr == src) { |
| 111 | return nullptr; |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 112 | } |
| 113 | char* dst = fRecord->alloc<char>(count); |
| 114 | memcpy(dst, src, count); |
| 115 | return dst; |
| 116 | } |
| 117 | |
mtklein | 5f0e822 | 2014-08-22 11:44:26 -0700 | [diff] [blame] | 118 | // As above, assuming and copying a terminating \0. |
| 119 | template <> |
| 120 | char* SkRecorder::copy(const char* src) { |
| 121 | return this->copy(src, strlen(src)+1); |
| 122 | } |
| 123 | |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 124 | void SkRecorder::flushMiniRecorder() { |
| 125 | if (fMiniRecorder) { |
| 126 | SkMiniRecorder* mr = fMiniRecorder; |
mtklein | d41ea1d | 2015-05-20 10:16:49 -0700 | [diff] [blame] | 127 | fMiniRecorder = nullptr; // Needs to happen before flushAndReset() or we recurse forever. |
| 128 | mr->flushAndReset(this); |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
mtklein | 5f0e822 | 2014-08-22 11:44:26 -0700 | [diff] [blame] | 131 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 132 | void SkRecorder::onDrawPaint(const SkPaint& paint) { |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 133 | APPEND(DrawPaint, paint); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 134 | } |
| 135 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 136 | void SkRecorder::onDrawPoints(PointMode mode, |
| 137 | size_t count, |
| 138 | const SkPoint pts[], |
| 139 | const SkPaint& paint) { |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 140 | APPEND(DrawPoints, paint, mode, SkToUInt(count), this->copy(pts, count)); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 141 | } |
| 142 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 143 | void SkRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 144 | TRY_MINIRECORDER(drawRect, rect, paint); |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 145 | APPEND(DrawRect, paint, rect); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 146 | } |
| 147 | |
msarett | 44df651 | 2016-08-25 13:54:30 -0700 | [diff] [blame] | 148 | void SkRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) { |
| 149 | APPEND(DrawRegion, paint, region); |
| 150 | } |
| 151 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 152 | void SkRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 153 | APPEND(DrawOval, paint, oval); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 154 | } |
| 155 | |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 156 | void SkRecorder::onDrawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, |
| 157 | bool useCenter, const SkPaint& paint) { |
| 158 | APPEND(DrawArc, paint, oval, startAngle, sweepAngle, useCenter); |
| 159 | } |
| 160 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 161 | void SkRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 162 | APPEND(DrawRRect, paint, rrect); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 163 | } |
| 164 | |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 165 | void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 166 | APPEND(DrawDRRect, paint, outer, inner); |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 167 | } |
| 168 | |
reed | a8db728 | 2015-07-07 10:22:31 -0700 | [diff] [blame] | 169 | void SkRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { |
djsollen | aa6f739 | 2015-11-17 06:18:31 -0800 | [diff] [blame] | 170 | if (fDrawPictureMode == Record_DrawPictureMode) { |
| 171 | if (!fDrawableList) { |
| 172 | fDrawableList.reset(new SkDrawableList); |
| 173 | } |
| 174 | fDrawableList->append(drawable); |
| 175 | APPEND(DrawDrawable, this->copy(matrix), drawable->getBounds(), fDrawableList->count() - 1); |
| 176 | } else { |
| 177 | SkASSERT(fDrawPictureMode == Playback_DrawPictureMode); |
| 178 | drawable->draw(this, matrix); |
reed | 1bdfd3f | 2014-11-24 14:41:51 -0800 | [diff] [blame] | 179 | } |
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 | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 184 | APPEND(DrawPath, paint, 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) { |
reed | 9b84f8c | 2016-07-28 14:26:13 -0700 | [diff] [blame] | 191 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 192 | if (image) { |
reed | 9b84f8c | 2016-07-28 14:26:13 -0700 | [diff] [blame] | 193 | this->onDrawImage(image.get(), left, top, paint); |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 194 | } |
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::onDrawBitmapRect(const SkBitmap& bitmap, |
| 198 | const SkRect* src, |
| 199 | const SkRect& dst, |
| 200 | const SkPaint* paint, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 201 | SrcRectConstraint constraint) { |
reed | 9b84f8c | 2016-07-28 14:26:13 -0700 | [diff] [blame] | 202 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 203 | if (image) { |
reed | 9b84f8c | 2016-07-28 14:26:13 -0700 | [diff] [blame] | 204 | this->onDrawImageRect(image.get(), src, dst, paint, constraint); |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 205 | } |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 206 | } |
| 207 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 208 | void SkRecorder::onDrawBitmapNine(const SkBitmap& bitmap, |
| 209 | const SkIRect& center, |
| 210 | const SkRect& dst, |
| 211 | const SkPaint* paint) { |
reed | 9b84f8c | 2016-07-28 14:26:13 -0700 | [diff] [blame] | 212 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 213 | if (image) { |
reed | 9b84f8c | 2016-07-28 14:26:13 -0700 | [diff] [blame] | 214 | this->onDrawImageNine(image.get(), center, dst, paint); |
reed | 5617900 | 2015-07-07 06:11:19 -0700 | [diff] [blame] | 215 | } |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 216 | } |
| 217 | |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 218 | void SkRecorder::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, |
| 219 | const SkRect& dst, const SkPaint* paint) { |
| 220 | sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 221 | this->onDrawImageLattice(image.get(), lattice, dst, paint); |
| 222 | } |
| 223 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 224 | void SkRecorder::onDrawImage(const SkImage* image, SkScalar left, SkScalar top, |
| 225 | const SkPaint* paint) { |
mtklein | da574d1 | 2016-08-01 11:24:03 -0700 | [diff] [blame] | 226 | APPEND(DrawImage, this->copy(paint), sk_ref_sp(image), left, top); |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 227 | } |
| 228 | |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 229 | void SkRecorder::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
| 230 | const SkPaint* paint, SrcRectConstraint constraint) { |
mtklein | da574d1 | 2016-08-01 11:24:03 -0700 | [diff] [blame] | 231 | APPEND(DrawImageRect, this->copy(paint), sk_ref_sp(image), this->copy(src), dst, constraint); |
piotaixr | 6515175 | 2014-10-16 11:58:39 -0700 | [diff] [blame] | 232 | } |
| 233 | |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 234 | void SkRecorder::onDrawImageNine(const SkImage* image, const SkIRect& center, |
| 235 | const SkRect& dst, const SkPaint* paint) { |
mtklein | da574d1 | 2016-08-01 11:24:03 -0700 | [diff] [blame] | 236 | APPEND(DrawImageNine, this->copy(paint), sk_ref_sp(image), center, dst); |
reed | 4c21dc5 | 2015-06-25 12:32:03 -0700 | [diff] [blame] | 237 | } |
| 238 | |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 239 | void SkRecorder::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst, |
| 240 | const SkPaint* paint) { |
msarett | 0764efe | 2016-09-02 11:24:30 -0700 | [diff] [blame] | 241 | int flagCount = lattice.fFlags ? (lattice.fXCount + 1) * (lattice.fYCount + 1) : 0; |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 242 | SkASSERT(lattice.fBounds); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 243 | APPEND(DrawImageLattice, this->copy(paint), sk_ref_sp(image), |
| 244 | lattice.fXCount, this->copy(lattice.fXDivs, lattice.fXCount), |
msarett | 0764efe | 2016-09-02 11:24:30 -0700 | [diff] [blame] | 245 | lattice.fYCount, this->copy(lattice.fYDivs, lattice.fYCount), |
msarett | 71df2d7 | 2016-09-30 12:41:42 -0700 | [diff] [blame] | 246 | flagCount, this->copy(lattice.fFlags, flagCount), *lattice.fBounds, dst); |
msarett | 1688206 | 2016-08-16 09:31:08 -0700 | [diff] [blame] | 247 | } |
| 248 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 249 | void SkRecorder::onDrawText(const void* text, size_t byteLength, |
| 250 | SkScalar x, SkScalar y, const SkPaint& paint) { |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 251 | APPEND(DrawText, |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 252 | paint, this->copy((const char*)text, byteLength), byteLength, x, y); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 253 | } |
| 254 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 255 | void SkRecorder::onDrawPosText(const void* text, size_t byteLength, |
| 256 | const SkPoint pos[], const SkPaint& paint) { |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 257 | const int points = paint.countText(text, byteLength); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 258 | APPEND(DrawPosText, |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 259 | paint, |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 260 | this->copy((const char*)text, byteLength), |
| 261 | byteLength, |
| 262 | this->copy(pos, points)); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 263 | } |
| 264 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 265 | void SkRecorder::onDrawPosTextH(const void* text, size_t byteLength, |
| 266 | const SkScalar xpos[], SkScalar constY, const SkPaint& paint) { |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 267 | const int points = paint.countText(text, byteLength); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 268 | APPEND(DrawPosTextH, |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 269 | paint, |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 270 | this->copy((const char*)text, byteLength), |
mtklein | 42ddcd4 | 2014-11-21 08:48:35 -0800 | [diff] [blame] | 271 | SkToUInt(byteLength), |
| 272 | constY, |
| 273 | this->copy(xpos, points)); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 274 | } |
| 275 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 276 | void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 277 | const SkMatrix* matrix, const SkPaint& paint) { |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 278 | APPEND(DrawTextOnPath, |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 279 | paint, |
commit-bot@chromium.org | 37f6e62 | 2014-05-07 22:59:38 +0000 | [diff] [blame] | 280 | this->copy((const char*)text, byteLength), |
| 281 | byteLength, |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 282 | path, |
mtklein | af57903 | 2014-12-01 11:03:37 -0800 | [diff] [blame] | 283 | matrix ? *matrix : SkMatrix::I()); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 284 | } |
| 285 | |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 286 | void SkRecorder::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 287 | const SkRect* cull, const SkPaint& paint) { |
| 288 | APPEND(DrawTextRSXform, |
| 289 | paint, |
| 290 | this->copy((const char*)text, byteLength), |
| 291 | byteLength, |
| 292 | this->copy(xform, paint.countText(text, byteLength)), |
| 293 | this->copy(cull)); |
| 294 | } |
| 295 | |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 296 | void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 297 | const SkPaint& paint) { |
mtklein | 9db912c | 2015-05-19 11:11:26 -0700 | [diff] [blame] | 298 | TRY_MINIRECORDER(drawTextBlob, blob, x, y, paint); |
mtklein | da574d1 | 2016-08-01 11:24:03 -0700 | [diff] [blame] | 299 | APPEND(DrawTextBlob, paint, sk_ref_sp(blob), x, y); |
fmalita | 00d5c2c | 2014-08-21 08:53:26 -0700 | [diff] [blame] | 300 | } |
| 301 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 302 | void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, const SkPaint* paint) { |
mtklein | d711d11 | 2015-07-01 07:04:37 -0700 | [diff] [blame] | 303 | if (fDrawPictureMode == Record_DrawPictureMode) { |
Mike Reed | 90b2005 | 2017-03-08 10:39:02 -0500 | [diff] [blame] | 304 | fApproxBytesUsedBySubPictures += pic->approximateBytesUsed(); |
mtklein | da574d1 | 2016-08-01 11:24:03 -0700 | [diff] [blame] | 305 | APPEND(DrawPicture, this->copy(paint), sk_ref_sp(pic), matrix ? *matrix : SkMatrix::I()); |
mtklein | d711d11 | 2015-07-01 07:04:37 -0700 | [diff] [blame] | 306 | } else { |
| 307 | SkASSERT(fDrawPictureMode == Playback_DrawPictureMode); |
| 308 | SkAutoCanvasMatrixPaint acmp(this, matrix, paint, pic->cullRect()); |
| 309 | pic->playback(this); |
| 310 | } |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Mike Reed | e88a1cb | 2017-03-17 09:50:46 -0400 | [diff] [blame] | 313 | void SkRecorder::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode bmode, |
| 314 | const SkPaint& paint) { |
| 315 | APPEND(DrawVertices, paint, sk_ref_sp(const_cast<SkVertices*>(vertices)), bmode); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 316 | } |
| 317 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 318 | void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 319 | const SkPoint texCoords[4], SkBlendMode bmode, |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 320 | const SkPaint& paint) { |
mtklein | c845fa0 | 2015-06-30 09:49:49 -0700 | [diff] [blame] | 321 | APPEND(DrawPatch, paint, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 322 | cubics ? this->copy(cubics, SkPatchUtils::kNumCtrlPts) : nullptr, |
| 323 | colors ? this->copy(colors, SkPatchUtils::kNumCorners) : nullptr, |
| 324 | texCoords ? this->copy(texCoords, SkPatchUtils::kNumCorners) : nullptr, |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 325 | bmode); |
dandov | 963137b | 2014-08-07 07:49:53 -0700 | [diff] [blame] | 326 | } |
| 327 | |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 328 | void SkRecorder::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 329 | const SkColor colors[], int count, SkBlendMode mode, |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 330 | const SkRect* cull, const SkPaint* paint) { |
| 331 | APPEND(DrawAtlas, this->copy(paint), |
mtklein | da574d1 | 2016-08-01 11:24:03 -0700 | [diff] [blame] | 332 | sk_ref_sp(atlas), |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 333 | this->copy(xform, count), |
| 334 | this->copy(tex, count), |
| 335 | this->copy(colors, count), |
| 336 | count, |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 337 | mode, |
reed | 71c3c76 | 2015-06-24 10:29:17 -0700 | [diff] [blame] | 338 | this->copy(cull)); |
| 339 | } |
| 340 | |
Mike Reed | 4204da2 | 2017-05-17 08:53:36 -0400 | [diff] [blame] | 341 | void SkRecorder::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { |
| 342 | APPEND(DrawShadowRec, path, rec); |
| 343 | } |
| 344 | |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 345 | void SkRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) { |
mtklein | da574d1 | 2016-08-01 11:24:03 -0700 | [diff] [blame] | 346 | APPEND(DrawAnnotation, rect, SkString(key), sk_ref_sp(value)); |
reed | f70b531 | 2016-03-04 16:36:20 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Mike Klein | 7cc49d6 | 2017-08-14 10:39:28 -0400 | [diff] [blame] | 349 | void SkRecorder::onFlush() { |
| 350 | APPEND(Flush); |
| 351 | } |
| 352 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 353 | void SkRecorder::willSave() { |
| 354 | APPEND(Save); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 355 | } |
| 356 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 357 | SkCanvas::SaveLayerStrategy SkRecorder::getSaveLayerStrategy(const SaveLayerRec& rec) { |
mtklein | da574d1 | 2016-08-01 11:24:03 -0700 | [diff] [blame] | 358 | APPEND(SaveLayer, this->copy(rec.fBounds) |
| 359 | , this->copy(rec.fPaint) |
| 360 | , sk_ref_sp(rec.fBackdrop) |
Mike Klein | b34ab04 | 2017-05-01 21:34:14 +0000 | [diff] [blame] | 361 | , sk_ref_sp(rec.fClipMask) |
Florin Malita | 53f77bd | 2017-04-28 13:48:37 -0400 | [diff] [blame] | 362 | , this->copy(rec.fClipMatrix) |
mtklein | da574d1 | 2016-08-01 11:24:03 -0700 | [diff] [blame] | 363 | , rec.fSaveLayerFlags); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 364 | return SkCanvas::kNoLayer_SaveLayerStrategy; |
| 365 | } |
| 366 | |
mtklein | 6cfa73a | 2014-08-13 13:33:49 -0700 | [diff] [blame] | 367 | void SkRecorder::didRestore() { |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 368 | APPEND(Restore, this->getDeviceClipBounds(), this->getTotalMatrix()); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 369 | } |
| 370 | |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 371 | void SkRecorder::didConcat(const SkMatrix& matrix) { |
mtklein | e9d2052 | 2015-11-19 12:08:24 -0800 | [diff] [blame] | 372 | APPEND(Concat, matrix); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | void SkRecorder::didSetMatrix(const SkMatrix& matrix) { |
| 376 | APPEND(SetMatrix, matrix); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 377 | } |
| 378 | |
mtklein | cbdf007 | 2016-08-19 09:05:27 -0700 | [diff] [blame] | 379 | void SkRecorder::didTranslate(SkScalar dx, SkScalar dy) { |
| 380 | APPEND(Translate, dx, dy); |
| 381 | } |
| 382 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 383 | void SkRecorder::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 384 | INHERITED(onClipRect, rect, op, edgeStyle); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 385 | SkRecords::ClipOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 386 | APPEND(ClipRect, this->getDeviceClipBounds(), rect, opAA); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 389 | void SkRecorder::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 390 | INHERITED(onClipRRect, rrect, op, edgeStyle); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 391 | SkRecords::ClipOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 392 | APPEND(ClipRRect, this->getDeviceClipBounds(), rrect, opAA); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 395 | void SkRecorder::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) { |
reed | d954498 | 2014-09-09 18:46:22 -0700 | [diff] [blame] | 396 | INHERITED(onClipPath, path, op, edgeStyle); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 397 | SkRecords::ClipOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 398 | APPEND(ClipPath, this->getDeviceClipBounds(), path, opAA); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 401 | void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) { |
commit-bot@chromium.org | d9ce2be | 2014-04-09 23:30:28 +0000 | [diff] [blame] | 402 | INHERITED(onClipRegion, deviceRgn, op); |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 403 | APPEND(ClipRegion, this->getDeviceClipBounds(), deviceRgn, op); |
commit-bot@chromium.org | e3ff558 | 2014-04-01 16:24:06 +0000 | [diff] [blame] | 404 | } |
mtklein | 5f0e822 | 2014-08-22 11:44:26 -0700 | [diff] [blame] | 405 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 406 | sk_sp<SkSurface> SkRecorder::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) { |
| 407 | return nullptr; |
| 408 | } |