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