Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: src/core/SkRecorder.cpp

Issue 1130333002: Revert of Sketch splitting SkPicture into an interface and SkBigPicture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkRecorder.h ('k') | src/core/SkRecords.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBigPicture.h"
9 #include "SkPatchUtils.h" 8 #include "SkPatchUtils.h"
10 #include "SkPicture.h" 9 #include "SkPicture.h"
11 #include "SkPictureUtils.h" 10 #include "SkPictureUtils.h"
12 #include "SkRecorder.h" 11 #include "SkRecorder.h"
13 12
14 SkDrawableList::~SkDrawableList() { 13 SkDrawableList::~SkDrawableList() {
15 fArray.unrefAll(); 14 fArray.unrefAll();
16 } 15 }
17 16
18 SkBigPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() { 17 SkPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() {
19 const int count = fArray.count(); 18 const int count = fArray.count();
20 if (0 == count) { 19 if (0 == count) {
21 return NULL; 20 return NULL;
22 } 21 }
23 SkAutoTMalloc<const SkPicture*> pics(count); 22 SkAutoTMalloc<const SkPicture*> pics(count);
24 for (int i = 0; i < count; ++i) { 23 for (int i = 0; i < count; ++i) {
25 pics[i] = fArray[i]->newPictureSnapshot(); 24 pics[i] = fArray[i]->newPictureSnapshot();
26 } 25 }
27 return SkNEW_ARGS(SkBigPicture::SnapshotArray, (pics.detach(), count)); 26 return SkNEW_ARGS(SkPicture::SnapshotArray, (pics.detach(), count));
28 } 27 }
29 28
30 void SkDrawableList::append(SkDrawable* drawable) { 29 void SkDrawableList::append(SkDrawable* drawable) {
31 *fArray.append() = SkRef(drawable); 30 *fArray.append() = SkRef(drawable);
32 } 31 }
33 32
34 //////////////////////////////////////////////////////////////////////////////// /////////////// 33 //////////////////////////////////////////////////////////////////////////////// ///////////////
35 34
36 SkRecorder::SkRecorder(SkRecord* record, int width, int height, SkMiniRecorder* mr) 35 SkRecorder::SkRecorder(SkRecord* record, int width, int height)
37 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip _InitFlag) 36 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip _InitFlag)
38 , fApproxBytesUsedBySubPictures(0) 37 , fApproxBytesUsedBySubPictures(0)
39 , fRecord(record) 38 , fRecord(record) {}
40 , fMiniRecorder(mr) {}
41 39
42 SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds, SkMiniRecorder* m r) 40 SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds)
43 : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) 41 : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag)
44 , fApproxBytesUsedBySubPictures(0) 42 , fApproxBytesUsedBySubPictures(0)
45 , fRecord(record) 43 , fRecord(record) {}
46 , fMiniRecorder(mr) {}
47 44
48 void SkRecorder::reset(SkRecord* record, const SkRect& bounds, SkMiniRecorder* m r) { 45 void SkRecorder::reset(SkRecord* record, const SkRect& bounds) {
49 this->forgetRecord(); 46 this->forgetRecord();
50 fRecord = record; 47 fRecord = record;
51 this->resetForNextPicture(bounds.roundOut()); 48 this->resetForNextPicture(bounds.roundOut());
52 fMiniRecorder = mr;
53 } 49 }
54 50
55 void SkRecorder::forgetRecord() { 51 void SkRecorder::forgetRecord() {
56 fDrawableList.reset(NULL); 52 fDrawableList.reset(NULL);
57 fApproxBytesUsedBySubPictures = 0; 53 fApproxBytesUsedBySubPictures = 0;
58 fRecord = NULL; 54 fRecord = NULL;
59 } 55 }
60 56
61 // To make appending to fRecord a little less verbose. 57 // To make appending to fRecord a little less verbose.
62 #define APPEND(T, ...) \ 58 #define APPEND(T, ...) \
63 if (fMiniRecorder) { this->flushMiniRecorder(); } \
64 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V A_ARGS__)) 59 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V A_ARGS__))
65 60
66 #define TRY_MINIRECORDER(method, ...) \
67 if (fMiniRecorder && fMiniRecorder->method(__VA_ARGS__)) { return; }
68
69 // For methods which must call back into SkCanvas. 61 // For methods which must call back into SkCanvas.
70 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) 62 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__)
71 63
72 // The structs we're creating all copy their constructor arguments. Given the w ay the SkRecords 64 // The structs we're creating all copy their constructor arguments. Given the w ay the SkRecords
73 // framework works, sometimes they happen to technically be copied twice, which is fine and elided 65 // framework works, sometimes they happen to technically be copied twice, which is fine and elided
74 // into a single copy unless the class has a non-trivial copy constructor. For classes with 66 // into a single copy unless the class has a non-trivial copy constructor. For classes with
75 // non-trivial copy constructors, we skip the first copy (and its destruction) b y wrapping the value 67 // non-trivial copy constructors, we skip the first copy (and its destruction) b y wrapping the value
76 // with delay_copy(), forcing the argument to be passed by const&. 68 // with delay_copy(), forcing the argument to be passed by const&.
77 // 69 //
78 // This is used below for SkBitmap, SkPaint, SkPath, and SkRegion, which all hav e non-trivial copy 70 // This is used below for SkBitmap, SkPaint, SkPath, and SkRegion, which all hav e non-trivial copy
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 memcpy(dst, src, count); 118 memcpy(dst, src, count);
127 return dst; 119 return dst;
128 } 120 }
129 121
130 // As above, assuming and copying a terminating \0. 122 // As above, assuming and copying a terminating \0.
131 template <> 123 template <>
132 char* SkRecorder::copy(const char* src) { 124 char* SkRecorder::copy(const char* src) {
133 return this->copy(src, strlen(src)+1); 125 return this->copy(src, strlen(src)+1);
134 } 126 }
135 127
136 void SkRecorder::flushMiniRecorder() {
137 if (fMiniRecorder) {
138 SkMiniRecorder* mr = fMiniRecorder;
139 fMiniRecorder = nullptr; // Needs to happen before p->playback(this) or we loop forever.
140 // TODO: this can probably be done more efficiently by SkMiniRecorder if it matters.
141 SkAutoTUnref<SkPicture> p(mr->detachAsPicture(SkRect::MakeEmpty()));
142 p->playback(this);
143 }
144 }
145 128
146 void SkRecorder::onDrawPaint(const SkPaint& paint) { 129 void SkRecorder::onDrawPaint(const SkPaint& paint) {
147 APPEND(DrawPaint, delay_copy(paint)); 130 APPEND(DrawPaint, delay_copy(paint));
148 } 131 }
149 132
150 void SkRecorder::onDrawPoints(PointMode mode, 133 void SkRecorder::onDrawPoints(PointMode mode,
151 size_t count, 134 size_t count,
152 const SkPoint pts[], 135 const SkPoint pts[],
153 const SkPaint& paint) { 136 const SkPaint& paint) {
154 APPEND(DrawPoints, delay_copy(paint), mode, SkToUInt(count), this->copy(pts, count)); 137 APPEND(DrawPoints, delay_copy(paint), mode, SkToUInt(count), this->copy(pts, count));
155 } 138 }
156 139
157 void SkRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) { 140 void SkRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) {
158 TRY_MINIRECORDER(drawRect, rect, paint);
159 APPEND(DrawRect, delay_copy(paint), rect); 141 APPEND(DrawRect, delay_copy(paint), rect);
160 } 142 }
161 143
162 void SkRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) { 144 void SkRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) {
163 APPEND(DrawOval, delay_copy(paint), oval); 145 APPEND(DrawOval, delay_copy(paint), oval);
164 } 146 }
165 147
166 void SkRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { 148 void SkRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
167 APPEND(DrawRRect, delay_copy(paint), rrect); 149 APPEND(DrawRRect, delay_copy(paint), rrect);
168 } 150 }
169 151
170 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { 152 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
171 APPEND(DrawDRRect, delay_copy(paint), outer, inner); 153 APPEND(DrawDRRect, delay_copy(paint), outer, inner);
172 } 154 }
173 155
174 void SkRecorder::onDrawDrawable(SkDrawable* drawable) { 156 void SkRecorder::onDrawDrawable(SkDrawable* drawable) {
175 if (!fDrawableList) { 157 if (!fDrawableList) {
176 fDrawableList.reset(SkNEW(SkDrawableList)); 158 fDrawableList.reset(SkNEW(SkDrawableList));
177 } 159 }
178 fDrawableList->append(drawable); 160 fDrawableList->append(drawable);
179 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList->count() - 1); 161 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList->count() - 1);
180 } 162 }
181 163
182 void SkRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) { 164 void SkRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) {
183 TRY_MINIRECORDER(drawPath, path, paint);
184 APPEND(DrawPath, delay_copy(paint), delay_copy(path)); 165 APPEND(DrawPath, delay_copy(paint), delay_copy(path));
185 } 166 }
186 167
187 void SkRecorder::onDrawBitmap(const SkBitmap& bitmap, 168 void SkRecorder::onDrawBitmap(const SkBitmap& bitmap,
188 SkScalar left, 169 SkScalar left,
189 SkScalar top, 170 SkScalar top,
190 const SkPaint* paint) { 171 const SkPaint* paint) {
191 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top); 172 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top);
192 } 173 }
193 174
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 APPEND(DrawTextOnPath, 241 APPEND(DrawTextOnPath,
261 delay_copy(paint), 242 delay_copy(paint),
262 this->copy((const char*)text, byteLength), 243 this->copy((const char*)text, byteLength),
263 byteLength, 244 byteLength,
264 delay_copy(path), 245 delay_copy(path),
265 matrix ? *matrix : SkMatrix::I()); 246 matrix ? *matrix : SkMatrix::I());
266 } 247 }
267 248
268 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, 249 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
269 const SkPaint& paint) { 250 const SkPaint& paint) {
270 TRY_MINIRECORDER(drawTextBlob, blob, x, y, paint);
271 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y); 251 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y);
272 } 252 }
273 253
274 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con st SkPaint* paint) { 254 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con st SkPaint* paint) {
275 fApproxBytesUsedBySubPictures += SkPictureUtils::ApproximateBytesUsed(pic); 255 fApproxBytesUsedBySubPictures += SkPictureUtils::ApproximateBytesUsed(pic);
276 APPEND(DrawPicture, this->copy(paint), pic, matrix ? *matrix : SkMatrix::I() ); 256 APPEND(DrawPicture, this->copy(paint), pic, matrix ? *matrix : SkMatrix::I() );
277 } 257 }
278 258
279 void SkRecorder::onDrawVertices(VertexMode vmode, 259 void SkRecorder::onDrawVertices(VertexMode vmode,
280 int vertexCount, const SkPoint vertices[], 260 int vertexCount, const SkPoint vertices[],
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 337 }
358 338
359 void SkRecorder::addComment(const char* key, const char* value) { 339 void SkRecorder::addComment(const char* key, const char* value) {
360 APPEND(AddComment, this->copy(key), this->copy(value)); 340 APPEND(AddComment, this->copy(key), this->copy(value));
361 } 341 }
362 342
363 void SkRecorder::endCommentGroup() { 343 void SkRecorder::endCommentGroup() {
364 APPEND(EndCommentGroup); 344 APPEND(EndCommentGroup);
365 } 345 }
366 346
OLDNEW
« no previous file with comments | « src/core/SkRecorder.h ('k') | src/core/SkRecords.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698