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

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

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

Powered by Google App Engine
This is Rietveld 408576698