| OLD | NEW |
| 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, ...) \ |
| 63 if (fMiniRecorder) { this->flushMiniRecorder(); } \ |
| 59 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V
A_ARGS__)) | 64 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V
A_ARGS__)) |
| 60 | 65 |
| 66 #define TRY_MINIRECORDER(method, ...) \ |
| 67 if (fMiniRecorder && fMiniRecorder->method(__VA_ARGS__)) { return; } |
| 68 |
| 61 // For methods which must call back into SkCanvas. | 69 // For methods which must call back into SkCanvas. |
| 62 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) | 70 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) |
| 63 | 71 |
| 64 // The structs we're creating all copy their constructor arguments. Given the w
ay the SkRecords | 72 // 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 | 73 // 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 | 74 // 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 | 75 // 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&. | 76 // with delay_copy(), forcing the argument to be passed by const&. |
| 69 // | 77 // |
| 70 // This is used below for SkBitmap, SkPaint, SkPath, and SkRegion, which all hav
e non-trivial copy | 78 // 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 Loading... |
| 118 memcpy(dst, src, count); | 126 memcpy(dst, src, count); |
| 119 return dst; | 127 return dst; |
| 120 } | 128 } |
| 121 | 129 |
| 122 // As above, assuming and copying a terminating \0. | 130 // As above, assuming and copying a terminating \0. |
| 123 template <> | 131 template <> |
| 124 char* SkRecorder::copy(const char* src) { | 132 char* SkRecorder::copy(const char* src) { |
| 125 return this->copy(src, strlen(src)+1); | 133 return this->copy(src, strlen(src)+1); |
| 126 } | 134 } |
| 127 | 135 |
| 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 } |
| 128 | 145 |
| 129 void SkRecorder::onDrawPaint(const SkPaint& paint) { | 146 void SkRecorder::onDrawPaint(const SkPaint& paint) { |
| 130 APPEND(DrawPaint, delay_copy(paint)); | 147 APPEND(DrawPaint, delay_copy(paint)); |
| 131 } | 148 } |
| 132 | 149 |
| 133 void SkRecorder::onDrawPoints(PointMode mode, | 150 void SkRecorder::onDrawPoints(PointMode mode, |
| 134 size_t count, | 151 size_t count, |
| 135 const SkPoint pts[], | 152 const SkPoint pts[], |
| 136 const SkPaint& paint) { | 153 const SkPaint& paint) { |
| 137 APPEND(DrawPoints, delay_copy(paint), mode, SkToUInt(count), this->copy(pts,
count)); | 154 APPEND(DrawPoints, delay_copy(paint), mode, SkToUInt(count), this->copy(pts,
count)); |
| 138 } | 155 } |
| 139 | 156 |
| 140 void SkRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) { | 157 void SkRecorder::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
| 158 TRY_MINIRECORDER(drawRect, rect, paint); |
| 141 APPEND(DrawRect, delay_copy(paint), rect); | 159 APPEND(DrawRect, delay_copy(paint), rect); |
| 142 } | 160 } |
| 143 | 161 |
| 144 void SkRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) { | 162 void SkRecorder::onDrawOval(const SkRect& oval, const SkPaint& paint) { |
| 145 APPEND(DrawOval, delay_copy(paint), oval); | 163 APPEND(DrawOval, delay_copy(paint), oval); |
| 146 } | 164 } |
| 147 | 165 |
| 148 void SkRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { | 166 void SkRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 149 APPEND(DrawRRect, delay_copy(paint), rrect); | 167 APPEND(DrawRRect, delay_copy(paint), rrect); |
| 150 } | 168 } |
| 151 | 169 |
| 152 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const
SkPaint& paint) { | 170 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const
SkPaint& paint) { |
| 153 APPEND(DrawDRRect, delay_copy(paint), outer, inner); | 171 APPEND(DrawDRRect, delay_copy(paint), outer, inner); |
| 154 } | 172 } |
| 155 | 173 |
| 156 void SkRecorder::onDrawDrawable(SkDrawable* drawable) { | 174 void SkRecorder::onDrawDrawable(SkDrawable* drawable) { |
| 157 if (!fDrawableList) { | 175 if (!fDrawableList) { |
| 158 fDrawableList.reset(SkNEW(SkDrawableList)); | 176 fDrawableList.reset(SkNEW(SkDrawableList)); |
| 159 } | 177 } |
| 160 fDrawableList->append(drawable); | 178 fDrawableList->append(drawable); |
| 161 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList->count() - 1); | 179 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList->count() - 1); |
| 162 } | 180 } |
| 163 | 181 |
| 164 void SkRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) { | 182 void SkRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) { |
| 183 TRY_MINIRECORDER(drawPath, path, paint); |
| 165 APPEND(DrawPath, delay_copy(paint), delay_copy(path)); | 184 APPEND(DrawPath, delay_copy(paint), delay_copy(path)); |
| 166 } | 185 } |
| 167 | 186 |
| 168 void SkRecorder::onDrawBitmap(const SkBitmap& bitmap, | 187 void SkRecorder::onDrawBitmap(const SkBitmap& bitmap, |
| 169 SkScalar left, | 188 SkScalar left, |
| 170 SkScalar top, | 189 SkScalar top, |
| 171 const SkPaint* paint) { | 190 const SkPaint* paint) { |
| 172 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top); | 191 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top); |
| 173 } | 192 } |
| 174 | 193 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 APPEND(DrawTextOnPath, | 260 APPEND(DrawTextOnPath, |
| 242 delay_copy(paint), | 261 delay_copy(paint), |
| 243 this->copy((const char*)text, byteLength), | 262 this->copy((const char*)text, byteLength), |
| 244 byteLength, | 263 byteLength, |
| 245 delay_copy(path), | 264 delay_copy(path), |
| 246 matrix ? *matrix : SkMatrix::I()); | 265 matrix ? *matrix : SkMatrix::I()); |
| 247 } | 266 } |
| 248 | 267 |
| 249 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, | 268 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 250 const SkPaint& paint) { | 269 const SkPaint& paint) { |
| 270 TRY_MINIRECORDER(drawTextBlob, blob, x, y, paint); |
| 251 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y); | 271 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y); |
| 252 } | 272 } |
| 253 | 273 |
| 254 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con
st SkPaint* paint) { | 274 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con
st SkPaint* paint) { |
| 255 fApproxBytesUsedBySubPictures += SkPictureUtils::ApproximateBytesUsed(pic); | 275 fApproxBytesUsedBySubPictures += SkPictureUtils::ApproximateBytesUsed(pic); |
| 256 APPEND(DrawPicture, this->copy(paint), pic, matrix ? *matrix : SkMatrix::I()
); | 276 APPEND(DrawPicture, this->copy(paint), pic, matrix ? *matrix : SkMatrix::I()
); |
| 257 } | 277 } |
| 258 | 278 |
| 259 void SkRecorder::onDrawVertices(VertexMode vmode, | 279 void SkRecorder::onDrawVertices(VertexMode vmode, |
| 260 int vertexCount, const SkPoint vertices[], | 280 int vertexCount, const SkPoint vertices[], |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 357 } |
| 338 | 358 |
| 339 void SkRecorder::addComment(const char* key, const char* value) { | 359 void SkRecorder::addComment(const char* key, const char* value) { |
| 340 APPEND(AddComment, this->copy(key), this->copy(value)); | 360 APPEND(AddComment, this->copy(key), this->copy(value)); |
| 341 } | 361 } |
| 342 | 362 |
| 343 void SkRecorder::endCommentGroup() { | 363 void SkRecorder::endCommentGroup() { |
| 344 APPEND(EndCommentGroup); | 364 APPEND(EndCommentGroup); |
| 345 } | 365 } |
| 346 | 366 |
| OLD | NEW |