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