| 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 "SkBigPicture.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkDrawable.h" | 10 #include "SkDrawable.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 : SkRecorder::Record_DrawPictureMode; | 44 : SkRecorder::Record_DrawPictureMode; |
| 45 fRecorder->reset(fRecord.get(), cullRect, dpm, &fMiniRecorder); | 45 fRecorder->reset(fRecord.get(), cullRect, dpm, &fMiniRecorder); |
| 46 fActivelyRecording = true; | 46 fActivelyRecording = true; |
| 47 return this->getRecordingCanvas(); | 47 return this->getRecordingCanvas(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 SkCanvas* SkPictureRecorder::getRecordingCanvas() { | 50 SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
| 51 return fActivelyRecording ? fRecorder.get() : nullptr; | 51 return fActivelyRecording ? fRecorder.get() : nullptr; |
| 52 } | 52 } |
| 53 | 53 |
| 54 sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture() { | 54 sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture(uint32_t finishFlag
s) { |
| 55 fActivelyRecording = false; | 55 fActivelyRecording = false; |
| 56 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | 56 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
| 57 | 57 |
| 58 if (fRecord->count() == 0) { | 58 if (fRecord->count() == 0) { |
| 59 if (finishFlags & kReturnNullForEmpty_FinishFlag) { |
| 60 return nullptr; |
| 61 } |
| 59 return fMiniRecorder.detachAsPicture(fCullRect); | 62 return fMiniRecorder.detachAsPicture(fCullRect); |
| 60 } | 63 } |
| 61 | 64 |
| 62 // TODO: delay as much of this work until just before first playback? | 65 // TODO: delay as much of this work until just before first playback? |
| 63 SkRecordOptimize(fRecord); | 66 SkRecordOptimize(fRecord); |
| 64 | 67 |
| 68 if (fRecord->count() == 0) { |
| 69 if (finishFlags & kReturnNullForEmpty_FinishFlag) { |
| 70 return nullptr; |
| 71 } |
| 72 } |
| 73 |
| 65 SkAutoTUnref<SkLayerInfo> saveLayerData; | 74 SkAutoTUnref<SkLayerInfo> saveLayerData; |
| 66 | 75 |
| 67 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { | 76 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { |
| 68 saveLayerData.reset(new SkLayerInfo); | 77 saveLayerData.reset(new SkLayerInfo); |
| 69 } | 78 } |
| 70 | 79 |
| 71 SkDrawableList* drawableList = fRecorder->getDrawableList(); | 80 SkDrawableList* drawableList = fRecorder->getDrawableList(); |
| 72 SkBigPicture::SnapshotArray* pictList = | 81 SkBigPicture::SnapshotArray* pictList = |
| 73 drawableList ? drawableList->newDrawableSnapshot() : nullptr; | 82 drawableList ? drawableList->newDrawableSnapshot() : nullptr; |
| 74 | 83 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 90 } | 99 } |
| 91 | 100 |
| 92 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); | 101 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); |
| 93 for (int i = 0; pictList && i < pictList->count(); i++) { | 102 for (int i = 0; pictList && i < pictList->count(); i++) { |
| 94 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); | 103 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); |
| 95 } | 104 } |
| 96 return sk_make_sp<SkBigPicture>(fCullRect, fRecord.release(), pictList, fBBH
.release(), | 105 return sk_make_sp<SkBigPicture>(fCullRect, fRecord.release(), pictList, fBBH
.release(), |
| 97 saveLayerData.release(), subPictureBytes); | 106 saveLayerData.release(), subPictureBytes); |
| 98 } | 107 } |
| 99 | 108 |
| 100 sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPictureWithCull(const SkRec
t& cullRect) { | 109 sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPictureWithCull(const SkRec
t& cullRect, |
| 110 uint32_t fi
nishFlags) { |
| 101 fCullRect = cullRect; | 111 fCullRect = cullRect; |
| 102 return this->finishRecordingAsPicture(); | 112 return this->finishRecordingAsPicture(finishFlags); |
| 103 } | 113 } |
| 104 | 114 |
| 105 | 115 |
| 106 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 116 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
| 107 if (nullptr == canvas) { | 117 if (nullptr == canvas) { |
| 108 return; | 118 return; |
| 109 } | 119 } |
| 110 | 120 |
| 111 int drawableCount = 0; | 121 int drawableCount = 0; |
| 112 SkDrawable* const* drawables = nullptr; | 122 SkDrawable* const* drawables = nullptr; |
| 113 SkDrawableList* drawableList = fRecorder->getDrawableList(); | 123 SkDrawableList* drawableList = fRecorder->getDrawableList(); |
| 114 if (drawableList) { | 124 if (drawableList) { |
| 115 drawableCount = drawableList->count(); | 125 drawableCount = drawableList->count(); |
| 116 drawables = drawableList->begin(); | 126 drawables = drawableList->begin(); |
| 117 } | 127 } |
| 118 SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, nullptr/*b
bh*/, nullptr/*callback*/); | 128 SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, nullptr/*b
bh*/, nullptr/*callback*/); |
| 119 } | 129 } |
| 120 | 130 |
| 121 sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable() { | 131 sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable(uint32_t finishFl
ags) { |
| 122 fActivelyRecording = false; | 132 fActivelyRecording = false; |
| 123 fRecorder->flushMiniRecorder(); | 133 fRecorder->flushMiniRecorder(); |
| 124 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | 134 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
| 125 | 135 |
| 126 // TODO: delay as much of this work until just before first playback? | |
| 127 SkRecordOptimize(fRecord); | 136 SkRecordOptimize(fRecord); |
| 128 | 137 |
| 138 if (fRecord->count() == 0) { |
| 139 if (finishFlags & kReturnNullForEmpty_FinishFlag) { |
| 140 return nullptr; |
| 141 } |
| 142 } |
| 143 |
| 129 if (fBBH.get()) { | 144 if (fBBH.get()) { |
| 130 SkAutoTMalloc<SkRect> bounds(fRecord->count()); | 145 SkAutoTMalloc<SkRect> bounds(fRecord->count()); |
| 131 SkRecordFillBounds(fCullRect, *fRecord, bounds); | 146 SkRecordFillBounds(fCullRect, *fRecord, bounds); |
| 132 fBBH->insert(bounds, fRecord->count()); | 147 fBBH->insert(bounds, fRecord->count()); |
| 133 } | 148 } |
| 134 | 149 |
| 135 sk_sp<SkDrawable> drawable = | 150 sk_sp<SkDrawable> drawable = |
| 136 sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawab
leList(), fCullRect, | 151 sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawab
leList(), fCullRect, |
| 137 SkToBool(fFlags & kComputeSaveLayerInfo_Recor
dFlag)); | 152 SkToBool(fFlags & kComputeSaveLayerInfo_Recor
dFlag)); |
| 138 | 153 |
| 139 // release our refs now, so only the drawable will be the owner. | 154 // release our refs now, so only the drawable will be the owner. |
| 140 fRecord.reset(nullptr); | 155 fRecord.reset(nullptr); |
| 141 fBBH.reset(nullptr); | 156 fBBH.reset(nullptr); |
| 142 | 157 |
| 143 return drawable; | 158 return drawable; |
| 144 } | 159 } |
| OLD | NEW |