blob: c9d88fc503cc5662a37382924c47a809cb5ac5db [file] [log] [blame]
commit-bot@chromium.orgc4b21e62014-04-11 18:33:31 +00001/*
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
mtklein9db912c2015-05-19 11:11:26 -07008#include "SkBigPicture.h"
mtkleind711d112015-07-01 07:04:37 -07009#include "SkCanvasPriv.h"
reed9b84f8c2016-07-28 14:26:13 -070010#include "SkImage.h"
dandovb3c9d1c2014-08-12 08:34:29 -070011#include "SkPatchUtils.h"
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000012#include "SkPicture.h"
mtklein98b84852015-04-21 15:23:59 -070013#include "SkRecorder.h"
reede8f30622016-03-23 18:59:25 -070014#include "SkSurface.h"
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000015
reed3cb38402015-02-06 08:36:15 -080016SkDrawableList::~SkDrawableList() {
reed1bdfd3f2014-11-24 14:41:51 -080017 fArray.unrefAll();
18}
19
mtklein9db912c2015-05-19 11:11:26 -070020SkBigPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() {
reed1bdfd3f2014-11-24 14:41:51 -080021 const int count = fArray.count();
22 if (0 == count) {
halcanary96fcdcc2015-08-27 07:41:13 -070023 return nullptr;
reed1bdfd3f2014-11-24 14:41:51 -080024 }
25 SkAutoTMalloc<const SkPicture*> pics(count);
26 for (int i = 0; i < count; ++i) {
27 pics[i] = fArray[i]->newPictureSnapshot();
28 }
mtklein18300a32016-03-16 13:53:35 -070029 return new SkBigPicture::SnapshotArray(pics.release(), count);
reed1bdfd3f2014-11-24 14:41:51 -080030}
31
reed3cb38402015-02-06 08:36:15 -080032void SkDrawableList::append(SkDrawable* drawable) {
reed1bdfd3f2014-11-24 14:41:51 -080033 *fArray.append() = SkRef(drawable);
34}
35
36///////////////////////////////////////////////////////////////////////////////////////////////
37
mtklein9db912c2015-05-19 11:11:26 -070038SkRecorder::SkRecorder(SkRecord* record, int width, int height, SkMiniRecorder* mr)
Florin Malita439ace92016-12-02 12:05:41 -050039 : SkNoDrawCanvas(width, height)
mtkleind711d112015-07-01 07:04:37 -070040 , fDrawPictureMode(Record_DrawPictureMode)
mtklein98b84852015-04-21 15:23:59 -070041 , fApproxBytesUsedBySubPictures(0)
mtklein9db912c2015-05-19 11:11:26 -070042 , fRecord(record)
43 , fMiniRecorder(mr) {}
reed78e27682014-11-19 08:04:34 -080044
mtklein9db912c2015-05-19 11:11:26 -070045SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds, SkMiniRecorder* mr)
Florin Malita439ace92016-12-02 12:05:41 -050046 : SkNoDrawCanvas(bounds.roundOut())
mtkleind711d112015-07-01 07:04:37 -070047 , fDrawPictureMode(Record_DrawPictureMode)
mtklein98b84852015-04-21 15:23:59 -070048 , fApproxBytesUsedBySubPictures(0)
mtklein9db912c2015-05-19 11:11:26 -070049 , fRecord(record)
50 , fMiniRecorder(mr) {}
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000051
mtkleind711d112015-07-01 07:04:37 -070052void SkRecorder::reset(SkRecord* record, const SkRect& bounds,
53 DrawPictureMode dpm, SkMiniRecorder* mr) {
mtkleinfeaadee2015-04-08 11:25:48 -070054 this->forgetRecord();
mtkleind711d112015-07-01 07:04:37 -070055 fDrawPictureMode = dpm;
mtkleinfeaadee2015-04-08 11:25:48 -070056 fRecord = record;
57 this->resetForNextPicture(bounds.roundOut());
mtklein9db912c2015-05-19 11:11:26 -070058 fMiniRecorder = mr;
mtkleinfeaadee2015-04-08 11:25:48 -070059}
60
commit-bot@chromium.org732bd662014-04-24 15:22:55 +000061void SkRecorder::forgetRecord() {
halcanary96fcdcc2015-08-27 07:41:13 -070062 fDrawableList.reset(nullptr);
mtklein98b84852015-04-21 15:23:59 -070063 fApproxBytesUsedBySubPictures = 0;
halcanary96fcdcc2015-08-27 07:41:13 -070064 fRecord = nullptr;
commit-bot@chromium.org732bd662014-04-24 15:22:55 +000065}
66
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000067// To make appending to fRecord a little less verbose.
halcanary385fe4d2015-08-26 13:07:48 -070068#define APPEND(T, ...) \
69 if (fMiniRecorder) { \
70 this->flushMiniRecorder(); \
71 } \
mtklein449d9b72015-09-28 10:33:02 -070072 new (fRecord->append<SkRecords::T>()) SkRecords::T{__VA_ARGS__}
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000073
mtklein9db912c2015-05-19 11:11:26 -070074#define TRY_MINIRECORDER(method, ...) \
75 if (fMiniRecorder && fMiniRecorder->method(__VA_ARGS__)) { return; }
76
Florin Malita439ace92016-12-02 12:05:41 -050077// For methods which must call back into SkNoDrawCanvas.
78#define INHERITED(method, ...) this->SkNoDrawCanvas::method(__VA_ARGS__)
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +000079
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000080// 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.)
82template <typename T>
83T* SkRecorder::copy(const T* src) {
halcanary96fcdcc2015-08-27 07:41:13 -070084 if (nullptr == src) {
85 return nullptr;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000086 }
halcanary385fe4d2015-08-26 13:07:48 -070087 return new (fRecord->alloc<T>()) T(*src);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000088}
89
90// This copy() is for arrays.
91// It will work with POD or non-POD, though currently we only use it for POD.
92template <typename T>
reed2347b622014-08-07 12:19:50 -070093T* SkRecorder::copy(const T src[], size_t count) {
halcanary96fcdcc2015-08-27 07:41:13 -070094 if (nullptr == src) {
95 return nullptr;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000096 }
97 T* dst = fRecord->alloc<T>(count);
reed2347b622014-08-07 12:19:50 -070098 for (size_t i = 0; i < count; i++) {
halcanary385fe4d2015-08-26 13:07:48 -070099 new (dst + i) T(src[i]);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000100 }
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.
107template <>
reed2347b622014-08-07 12:19:50 -0700108char* SkRecorder::copy(const char src[], size_t count) {
halcanary96fcdcc2015-08-27 07:41:13 -0700109 if (nullptr == src) {
110 return nullptr;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000111 }
112 char* dst = fRecord->alloc<char>(count);
113 memcpy(dst, src, count);
114 return dst;
115}
116
mtklein5f0e8222014-08-22 11:44:26 -0700117// As above, assuming and copying a terminating \0.
118template <>
119char* SkRecorder::copy(const char* src) {
120 return this->copy(src, strlen(src)+1);
121}
122
mtklein9db912c2015-05-19 11:11:26 -0700123void SkRecorder::flushMiniRecorder() {
124 if (fMiniRecorder) {
125 SkMiniRecorder* mr = fMiniRecorder;
mtkleind41ea1d2015-05-20 10:16:49 -0700126 fMiniRecorder = nullptr; // Needs to happen before flushAndReset() or we recurse forever.
127 mr->flushAndReset(this);
mtklein9db912c2015-05-19 11:11:26 -0700128 }
129}
mtklein5f0e8222014-08-22 11:44:26 -0700130
reed41af9662015-01-05 07:49:08 -0800131void SkRecorder::onDrawPaint(const SkPaint& paint) {
mtkleinc845fa02015-06-30 09:49:49 -0700132 APPEND(DrawPaint, paint);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000133}
134
reed41af9662015-01-05 07:49:08 -0800135void SkRecorder::onDrawPoints(PointMode mode,
136 size_t count,
137 const SkPoint pts[],
138 const SkPaint& paint) {
mtkleinc845fa02015-06-30 09:49:49 -0700139 APPEND(DrawPoints, paint, mode, SkToUInt(count), this->copy(pts, count));
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000140}
141
reed41af9662015-01-05 07:49:08 -0800142void SkRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) {
mtklein9db912c2015-05-19 11:11:26 -0700143 TRY_MINIRECORDER(drawRect, rect, paint);
mtkleinc845fa02015-06-30 09:49:49 -0700144 APPEND(DrawRect, paint, rect);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000145}
146
msarett44df6512016-08-25 13:54:30 -0700147void SkRecorder::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
148 APPEND(DrawRegion, paint, region);
149}
150
reed41af9662015-01-05 07:49:08 -0800151void SkRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) {
mtkleinc845fa02015-06-30 09:49:49 -0700152 APPEND(DrawOval, paint, oval);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000153}
154
bsalomonac3aa242016-08-19 11:25:19 -0700155void 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
reed41af9662015-01-05 07:49:08 -0800160void SkRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
mtkleinc845fa02015-06-30 09:49:49 -0700161 APPEND(DrawRRect, paint, rrect);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000162}
163
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +0000164void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
mtkleinc845fa02015-06-30 09:49:49 -0700165 APPEND(DrawDRRect, paint, outer, inner);
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +0000166}
167
reeda8db7282015-07-07 10:22:31 -0700168void SkRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
djsollenaa6f7392015-11-17 06:18:31 -0800169 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);
reed1bdfd3f2014-11-24 14:41:51 -0800178 }
reed6be2aa92014-11-18 11:08:05 -0800179}
180
reed41af9662015-01-05 07:49:08 -0800181void SkRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) {
mtklein9db912c2015-05-19 11:11:26 -0700182 TRY_MINIRECORDER(drawPath, path, paint);
mtkleinc845fa02015-06-30 09:49:49 -0700183 APPEND(DrawPath, paint, path);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000184}
185
reed41af9662015-01-05 07:49:08 -0800186void SkRecorder::onDrawBitmap(const SkBitmap& bitmap,
187 SkScalar left,
188 SkScalar top,
189 const SkPaint* paint) {
reed9b84f8c2016-07-28 14:26:13 -0700190 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
reed56179002015-07-07 06:11:19 -0700191 if (image) {
reed9b84f8c2016-07-28 14:26:13 -0700192 this->onDrawImage(image.get(), left, top, paint);
reed56179002015-07-07 06:11:19 -0700193 }
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000194}
195
reed41af9662015-01-05 07:49:08 -0800196void SkRecorder::onDrawBitmapRect(const SkBitmap& bitmap,
197 const SkRect* src,
198 const SkRect& dst,
199 const SkPaint* paint,
reed562fe472015-07-28 07:35:14 -0700200 SrcRectConstraint constraint) {
reed9b84f8c2016-07-28 14:26:13 -0700201 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
reed56179002015-07-07 06:11:19 -0700202 if (image) {
reed9b84f8c2016-07-28 14:26:13 -0700203 this->onDrawImageRect(image.get(), src, dst, paint, constraint);
reed56179002015-07-07 06:11:19 -0700204 }
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000205}
206
reed41af9662015-01-05 07:49:08 -0800207void SkRecorder::onDrawBitmapNine(const SkBitmap& bitmap,
208 const SkIRect& center,
209 const SkRect& dst,
210 const SkPaint* paint) {
reed9b84f8c2016-07-28 14:26:13 -0700211 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
reed56179002015-07-07 06:11:19 -0700212 if (image) {
reed9b84f8c2016-07-28 14:26:13 -0700213 this->onDrawImageNine(image.get(), center, dst, paint);
reed56179002015-07-07 06:11:19 -0700214 }
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000215}
216
msarett16882062016-08-16 09:31:08 -0700217void 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
reed41af9662015-01-05 07:49:08 -0800223void SkRecorder::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
224 const SkPaint* paint) {
mtkleinda574d12016-08-01 11:24:03 -0700225 APPEND(DrawImage, this->copy(paint), sk_ref_sp(image), left, top);
piotaixr65151752014-10-16 11:58:39 -0700226}
227
reed562fe472015-07-28 07:35:14 -0700228void SkRecorder::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
229 const SkPaint* paint, SrcRectConstraint constraint) {
mtkleinda574d12016-08-01 11:24:03 -0700230 APPEND(DrawImageRect, this->copy(paint), sk_ref_sp(image), this->copy(src), dst, constraint);
piotaixr65151752014-10-16 11:58:39 -0700231}
232
reed4c21dc52015-06-25 12:32:03 -0700233void SkRecorder::onDrawImageNine(const SkImage* image, const SkIRect& center,
234 const SkRect& dst, const SkPaint* paint) {
mtkleinda574d12016-08-01 11:24:03 -0700235 APPEND(DrawImageNine, this->copy(paint), sk_ref_sp(image), center, dst);
reed4c21dc52015-06-25 12:32:03 -0700236}
237
msarett16882062016-08-16 09:31:08 -0700238void SkRecorder::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
239 const SkPaint* paint) {
msarett0764efe2016-09-02 11:24:30 -0700240 int flagCount = lattice.fFlags ? (lattice.fXCount + 1) * (lattice.fYCount + 1) : 0;
msarett71df2d72016-09-30 12:41:42 -0700241 SkASSERT(lattice.fBounds);
msarett16882062016-08-16 09:31:08 -0700242 APPEND(DrawImageLattice, this->copy(paint), sk_ref_sp(image),
243 lattice.fXCount, this->copy(lattice.fXDivs, lattice.fXCount),
msarett0764efe2016-09-02 11:24:30 -0700244 lattice.fYCount, this->copy(lattice.fYDivs, lattice.fYCount),
msarett71df2d72016-09-30 12:41:42 -0700245 flagCount, this->copy(lattice.fFlags, flagCount), *lattice.fBounds, dst);
msarett16882062016-08-16 09:31:08 -0700246}
247
reed@google.come0d9ce82014-04-23 04:00:17 +0000248void SkRecorder::onDrawText(const void* text, size_t byteLength,
249 SkScalar x, SkScalar y, const SkPaint& paint) {
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000250 APPEND(DrawText,
mtkleinc845fa02015-06-30 09:49:49 -0700251 paint, this->copy((const char*)text, byteLength), byteLength, x, y);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000252}
253
reed@google.come0d9ce82014-04-23 04:00:17 +0000254void SkRecorder::onDrawPosText(const void* text, size_t byteLength,
255 const SkPoint pos[], const SkPaint& paint) {
mtkleinc6ad06a2015-08-19 09:51:00 -0700256 const int points = paint.countText(text, byteLength);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000257 APPEND(DrawPosText,
mtkleinc845fa02015-06-30 09:49:49 -0700258 paint,
commit-bot@chromium.org37f6e622014-05-07 22:59:38 +0000259 this->copy((const char*)text, byteLength),
260 byteLength,
261 this->copy(pos, points));
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000262}
263
reed@google.come0d9ce82014-04-23 04:00:17 +0000264void SkRecorder::onDrawPosTextH(const void* text, size_t byteLength,
265 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) {
mtkleinc6ad06a2015-08-19 09:51:00 -0700266 const int points = paint.countText(text, byteLength);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000267 APPEND(DrawPosTextH,
mtkleinc845fa02015-06-30 09:49:49 -0700268 paint,
commit-bot@chromium.org37f6e622014-05-07 22:59:38 +0000269 this->copy((const char*)text, byteLength),
mtklein42ddcd42014-11-21 08:48:35 -0800270 SkToUInt(byteLength),
271 constY,
272 this->copy(xpos, points));
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000273}
274
reed@google.come0d9ce82014-04-23 04:00:17 +0000275void SkRecorder::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
276 const SkMatrix* matrix, const SkPaint& paint) {
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000277 APPEND(DrawTextOnPath,
mtkleinc845fa02015-06-30 09:49:49 -0700278 paint,
commit-bot@chromium.org37f6e622014-05-07 22:59:38 +0000279 this->copy((const char*)text, byteLength),
280 byteLength,
mtkleinc845fa02015-06-30 09:49:49 -0700281 path,
mtkleinaf579032014-12-01 11:03:37 -0800282 matrix ? *matrix : SkMatrix::I());
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000283}
284
reed45561a02016-07-07 12:47:17 -0700285void 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
fmalita00d5c2c2014-08-21 08:53:26 -0700295void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
296 const SkPaint& paint) {
mtklein9db912c2015-05-19 11:11:26 -0700297 TRY_MINIRECORDER(drawTextBlob, blob, x, y, paint);
mtkleinda574d12016-08-01 11:24:03 -0700298 APPEND(DrawTextBlob, paint, sk_ref_sp(blob), x, y);
fmalita00d5c2c2014-08-21 08:53:26 -0700299}
300
reedd5fa1a42014-08-09 11:08:05 -0700301void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, const SkPaint* paint) {
mtkleind711d112015-07-01 07:04:37 -0700302 if (fDrawPictureMode == Record_DrawPictureMode) {
Mike Reed90b20052017-03-08 10:39:02 -0500303 fApproxBytesUsedBySubPictures += pic->approximateBytesUsed();
mtkleinda574d12016-08-01 11:24:03 -0700304 APPEND(DrawPicture, this->copy(paint), sk_ref_sp(pic), matrix ? *matrix : SkMatrix::I());
mtkleind711d112015-07-01 07:04:37 -0700305 } else {
306 SkASSERT(fDrawPictureMode == Playback_DrawPictureMode);
307 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, pic->cullRect());
308 pic->playback(this);
309 }
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000310}
311
vjiaoblacke6f5d562016-08-25 06:30:23 -0700312void SkRecorder::onDrawShadowedPicture(const SkPicture* pic, const SkMatrix* matrix,
313 const SkPaint* paint, const SkShadowParams& params) {
vjiaoblack95302da2016-07-21 10:25:54 -0700314 if (fDrawPictureMode == Record_DrawPictureMode) {
Mike Reed90b20052017-03-08 10:39:02 -0500315 fApproxBytesUsedBySubPictures += pic->approximateBytesUsed();
mtkleinda574d12016-08-01 11:24:03 -0700316 APPEND(DrawShadowedPicture, this->copy(paint),
317 sk_ref_sp(pic),
vjiaoblacke6f5d562016-08-25 06:30:23 -0700318 matrix ? *matrix : SkMatrix::I(),
319 params);
vjiaoblack95302da2016-07-21 10:25:54 -0700320 } else {
vjiaoblacke6f5d562016-08-25 06:30:23 -0700321 // TODO update pic->playback(this) to draw the shadowed pic
vjiaoblack95302da2016-07-21 10:25:54 -0700322 SkASSERT(fDrawPictureMode == Playback_DrawPictureMode);
323 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, pic->cullRect());
324 pic->playback(this);
325 }
326}
327
328
Mike Reede88a1cb2017-03-17 09:50:46 -0400329void 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.orge3ff5582014-04-01 16:24:06 +0000332}
333
dandovb3c9d1c2014-08-12 08:34:29 -0700334void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -0400335 const SkPoint texCoords[4], SkBlendMode bmode,
Mike Reed7d954ad2016-10-28 15:42:34 -0400336 const SkPaint& paint) {
mtkleinc845fa02015-06-30 09:49:49 -0700337 APPEND(DrawPatch, paint,
halcanary96fcdcc2015-08-27 07:41:13 -0700338 cubics ? this->copy(cubics, SkPatchUtils::kNumCtrlPts) : nullptr,
339 colors ? this->copy(colors, SkPatchUtils::kNumCorners) : nullptr,
340 texCoords ? this->copy(texCoords, SkPatchUtils::kNumCorners) : nullptr,
Mike Reed7d954ad2016-10-28 15:42:34 -0400341 bmode);
dandov963137b2014-08-07 07:49:53 -0700342}
343
reed71c3c762015-06-24 10:29:17 -0700344void SkRecorder::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
Mike Reedfaba3712016-11-03 14:45:31 -0400345 const SkColor colors[], int count, SkBlendMode mode,
reed71c3c762015-06-24 10:29:17 -0700346 const SkRect* cull, const SkPaint* paint) {
347 APPEND(DrawAtlas, this->copy(paint),
mtkleinda574d12016-08-01 11:24:03 -0700348 sk_ref_sp(atlas),
reed71c3c762015-06-24 10:29:17 -0700349 this->copy(xform, count),
350 this->copy(tex, count),
351 this->copy(colors, count),
352 count,
Mike Reedfaba3712016-11-03 14:45:31 -0400353 mode,
reed71c3c762015-06-24 10:29:17 -0700354 this->copy(cull));
355}
356
reedf70b5312016-03-04 16:36:20 -0800357void SkRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
mtkleinda574d12016-08-01 11:24:03 -0700358 APPEND(DrawAnnotation, rect, SkString(key), sk_ref_sp(value));
reedf70b5312016-03-04 16:36:20 -0800359}
360
Florin Malita5f6102d2014-06-30 10:13:28 -0400361void SkRecorder::willSave() {
362 APPEND(Save);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000363}
364
reed4960eee2015-12-18 07:09:18 -0800365SkCanvas::SaveLayerStrategy SkRecorder::getSaveLayerStrategy(const SaveLayerRec& rec) {
mtkleinda574d12016-08-01 11:24:03 -0700366 APPEND(SaveLayer, this->copy(rec.fBounds)
367 , this->copy(rec.fPaint)
368 , sk_ref_sp(rec.fBackdrop)
Florin Malita53f77bd2017-04-28 13:48:37 -0400369 , rec.fClipMask
370 , this->copy(rec.fClipMatrix)
mtkleinda574d12016-08-01 11:24:03 -0700371 , rec.fSaveLayerFlags);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000372 return SkCanvas::kNoLayer_SaveLayerStrategy;
373}
374
mtklein6cfa73a2014-08-13 13:33:49 -0700375void SkRecorder::didRestore() {
Mike Reed42e8c532017-01-23 14:09:13 -0500376 APPEND(Restore, this->getDeviceClipBounds(), this->getTotalMatrix());
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000377}
378
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000379void SkRecorder::didConcat(const SkMatrix& matrix) {
mtkleine9d20522015-11-19 12:08:24 -0800380 APPEND(Concat, matrix);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000381}
382
383void SkRecorder::didSetMatrix(const SkMatrix& matrix) {
384 APPEND(SetMatrix, matrix);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000385}
386
mtkleincbdf0072016-08-19 09:05:27 -0700387void SkRecorder::didTranslate(SkScalar dx, SkScalar dy) {
388 APPEND(Translate, dx, dy);
389}
390
vjiaoblack95302da2016-07-21 10:25:54 -0700391void SkRecorder::didTranslateZ(SkScalar z) {
392#ifdef SK_EXPERIMENTAL_SHADOWING
vjiaoblacke5de1302016-07-13 14:05:28 -0700393 APPEND(TranslateZ, z);
vjiaoblack95302da2016-07-21 10:25:54 -0700394#endif
vjiaoblacke5de1302016-07-13 14:05:28 -0700395}
396
Mike Reedc1f77742016-12-09 09:00:50 -0500397void SkRecorder::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +0000398 INHERITED(onClipRect, rect, op, edgeStyle);
reed73603f32016-09-20 08:42:38 -0700399 SkRecords::ClipOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle);
Mike Reed42e8c532017-01-23 14:09:13 -0500400 APPEND(ClipRect, this->getDeviceClipBounds(), rect, opAA);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000401}
402
Mike Reedc1f77742016-12-09 09:00:50 -0500403void SkRecorder::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
reedd9544982014-09-09 18:46:22 -0700404 INHERITED(onClipRRect, rrect, op, edgeStyle);
reed73603f32016-09-20 08:42:38 -0700405 SkRecords::ClipOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle);
Mike Reed42e8c532017-01-23 14:09:13 -0500406 APPEND(ClipRRect, this->getDeviceClipBounds(), rrect, opAA);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000407}
408
Mike Reedc1f77742016-12-09 09:00:50 -0500409void SkRecorder::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
reedd9544982014-09-09 18:46:22 -0700410 INHERITED(onClipPath, path, op, edgeStyle);
reed73603f32016-09-20 08:42:38 -0700411 SkRecords::ClipOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle);
Mike Reed42e8c532017-01-23 14:09:13 -0500412 APPEND(ClipPath, this->getDeviceClipBounds(), path, opAA);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000413}
414
Mike Reedc1f77742016-12-09 09:00:50 -0500415void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) {
commit-bot@chromium.orgd9ce2be2014-04-09 23:30:28 +0000416 INHERITED(onClipRegion, deviceRgn, op);
Mike Reed42e8c532017-01-23 14:09:13 -0500417 APPEND(ClipRegion, this->getDeviceClipBounds(), deviceRgn, op);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000418}
mtklein5f0e8222014-08-22 11:44:26 -0700419
reede8f30622016-03-23 18:59:25 -0700420sk_sp<SkSurface> SkRecorder::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) {
421 return nullptr;
422}