| 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 "SkRecorder.h" | 8 #include "SkRecorder.h" |
| 9 #include "SkPatchUtils.h" | 9 #include "SkPatchUtils.h" |
| 10 #include "SkPicture.h" | 10 #include "SkPicture.h" |
| 11 | 11 |
| 12 SkCanvasDrawableList::~SkCanvasDrawableList() { |
| 13 fArray.unrefAll(); |
| 14 } |
| 15 |
| 16 SkPicture::SnapshotArray* SkCanvasDrawableList::newDrawableSnapshot() { |
| 17 const int count = fArray.count(); |
| 18 if (0 == count) { |
| 19 return NULL; |
| 20 } |
| 21 SkAutoTMalloc<const SkPicture*> pics(count); |
| 22 for (int i = 0; i < count; ++i) { |
| 23 pics[i] = fArray[i]->newPictureSnapshot(); |
| 24 } |
| 25 return SkNEW_ARGS(SkPicture::SnapshotArray, (pics.detach(), count)); |
| 26 } |
| 27 |
| 28 void SkCanvasDrawableList::append(SkCanvasDrawable* drawable) { |
| 29 *fArray.append() = SkRef(drawable); |
| 30 } |
| 31 |
| 32 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
| 33 |
| 12 SkRecorder::SkRecorder(SkRecord* record, int width, int height) | 34 SkRecorder::SkRecorder(SkRecord* record, int width, int height) |
| 13 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip
_InitFlag) | 35 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip
_InitFlag) |
| 14 , fRecord(record) | 36 , fRecord(record) |
| 15 , fSaveLayerCount(0) {} | 37 , fSaveLayerCount(0) {} |
| 16 | 38 |
| 17 SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds) | 39 SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds) |
| 18 : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) | 40 : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) |
| 19 , fRecord(record) | 41 , fRecord(record) |
| 20 , fSaveLayerCount(0) {} | 42 , fSaveLayerCount(0) {} |
| 21 | 43 |
| 22 SkRecorder::~SkRecorder() { | |
| 23 fDrawableList.unrefAll(); | |
| 24 } | |
| 25 | |
| 26 void SkRecorder::forgetRecord() { | 44 void SkRecorder::forgetRecord() { |
| 27 fDrawableList.unrefAll(); | 45 fDrawableList.reset(NULL); |
| 28 fDrawableList.reset(); | |
| 29 fRecord = NULL; | 46 fRecord = NULL; |
| 30 } | 47 } |
| 31 | 48 |
| 32 SkPicture::SnapshotArray* SkRecorder::newDrawableSnapshot(SkBBHFactory* factory, | |
| 33 uint32_t recordFlags)
{ | |
| 34 const int count = fDrawableList.count(); | |
| 35 if (0 == count) { | |
| 36 return NULL; | |
| 37 } | |
| 38 SkAutoTMalloc<const SkPicture*> pics(count); | |
| 39 for (int i = 0; i < count; ++i) { | |
| 40 pics[i] = fDrawableList[i]->newPictureSnapshot(factory, recordFlags); | |
| 41 } | |
| 42 return SkNEW_ARGS(SkPicture::SnapshotArray, (pics.detach(), count)); | |
| 43 } | |
| 44 | |
| 45 // To make appending to fRecord a little less verbose. | 49 // To make appending to fRecord a little less verbose. |
| 46 #define APPEND(T, ...) \ | 50 #define APPEND(T, ...) \ |
| 47 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V
A_ARGS__)) | 51 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V
A_ARGS__)) |
| 48 | 52 |
| 49 // For methods which must call back into SkCanvas. | 53 // For methods which must call back into SkCanvas. |
| 50 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) | 54 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) |
| 51 | 55 |
| 52 // The structs we're creating all copy their constructor arguments. Given the w
ay the SkRecords | 56 // The structs we're creating all copy their constructor arguments. Given the w
ay the SkRecords |
| 53 // framework works, sometimes they happen to technically be copied twice, which
is fine and elided | 57 // framework works, sometimes they happen to technically be copied twice, which
is fine and elided |
| 54 // into a single copy unless the class has a non-trivial copy constructor. For
classes with | 58 // into a single copy unless the class has a non-trivial copy constructor. For
classes with |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 143 |
| 140 void SkRecorder::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 144 void SkRecorder::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 141 APPEND(DrawRRect, delay_copy(paint), rrect); | 145 APPEND(DrawRRect, delay_copy(paint), rrect); |
| 142 } | 146 } |
| 143 | 147 |
| 144 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const
SkPaint& paint) { | 148 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const
SkPaint& paint) { |
| 145 APPEND(DrawDRRect, delay_copy(paint), outer, inner); | 149 APPEND(DrawDRRect, delay_copy(paint), outer, inner); |
| 146 } | 150 } |
| 147 | 151 |
| 148 void SkRecorder::onDrawDrawable(SkCanvasDrawable* drawable) { | 152 void SkRecorder::onDrawDrawable(SkCanvasDrawable* drawable) { |
| 149 *fDrawableList.append() = SkRef(drawable); | 153 if (!fDrawableList) { |
| 150 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList.count() - 1); | 154 fDrawableList.reset(SkNEW(SkCanvasDrawableList)); |
| 155 } |
| 156 fDrawableList->append(drawable); |
| 157 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList->count() - 1); |
| 151 } | 158 } |
| 152 | 159 |
| 153 void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) { | 160 void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) { |
| 154 APPEND(DrawPath, delay_copy(paint), delay_copy(path)); | 161 APPEND(DrawPath, delay_copy(paint), delay_copy(path)); |
| 155 } | 162 } |
| 156 | 163 |
| 157 void SkRecorder::drawBitmap(const SkBitmap& bitmap, | 164 void SkRecorder::drawBitmap(const SkBitmap& bitmap, |
| 158 SkScalar left, | 165 SkScalar left, |
| 159 SkScalar top, | 166 SkScalar top, |
| 160 const SkPaint* paint) { | 167 const SkPaint* paint) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 APPEND(EndCommentGroup); | 361 APPEND(EndCommentGroup); |
| 355 } | 362 } |
| 356 | 363 |
| 357 bool SkRecorder::isDrawingToLayer() const { | 364 bool SkRecorder::isDrawingToLayer() const { |
| 358 return fSaveLayerCount > 0; | 365 return fSaveLayerCount > 0; |
| 359 } | 366 } |
| 360 | 367 |
| 361 void SkRecorder::drawData(const void* data, size_t length) { | 368 void SkRecorder::drawData(const void* data, size_t length) { |
| 362 APPEND(DrawData, copy((const char*)data), length); | 369 APPEND(DrawData, copy((const char*)data), length); |
| 363 } | 370 } |
| OLD | NEW |