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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 : SkRecorder::Record_DrawPictureMode; | 43 : SkRecorder::Record_DrawPictureMode; |
44 fRecorder->reset(fRecord.get(), cullRect, dpm, &fMiniRecorder); | 44 fRecorder->reset(fRecord.get(), cullRect, dpm, &fMiniRecorder); |
45 fActivelyRecording = true; | 45 fActivelyRecording = true; |
46 return this->getRecordingCanvas(); | 46 return this->getRecordingCanvas(); |
47 } | 47 } |
48 | 48 |
49 SkCanvas* SkPictureRecorder::getRecordingCanvas() { | 49 SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
50 return fActivelyRecording ? fRecorder.get() : nullptr; | 50 return fActivelyRecording ? fRecorder.get() : nullptr; |
51 } | 51 } |
52 | 52 |
53 SkPicture* SkPictureRecorder::endRecordingAsPicture() { | 53 sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture() { |
54 fActivelyRecording = false; | 54 fActivelyRecording = false; |
55 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | 55 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
56 | 56 |
57 if (fRecord->count() == 0) { | 57 if (fRecord->count() == 0) { |
58 return fMiniRecorder.detachAsPicture(fCullRect); | 58 return fMiniRecorder.detachAsPicture(fCullRect); |
59 } | 59 } |
60 | 60 |
61 // TODO: delay as much of this work until just before first playback? | 61 // TODO: delay as much of this work until just before first playback? |
62 SkRecordOptimize(fRecord); | 62 SkRecordOptimize(fRecord); |
63 | 63 |
(...skipping 21 matching lines...) Expand all Loading... |
85 SkRect bbhBound = fBBH->getRootBound(); | 85 SkRect bbhBound = fBBH->getRootBound(); |
86 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) | 86 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) |
87 || (bbhBound.isEmpty() && fCullRect.isEmpty())); | 87 || (bbhBound.isEmpty() && fCullRect.isEmpty())); |
88 fCullRect = bbhBound; | 88 fCullRect = bbhBound; |
89 } | 89 } |
90 | 90 |
91 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); | 91 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); |
92 for (int i = 0; pictList && i < pictList->count(); i++) { | 92 for (int i = 0; pictList && i < pictList->count(); i++) { |
93 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); | 93 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); |
94 } | 94 } |
95 return new SkBigPicture(fCullRect, fRecord.release(), pictList, fBBH.release
(), | 95 return sk_make_sp<SkBigPicture>(fCullRect, fRecord.release(), pictList, fBBH
.release(), |
96 saveLayerData.release(), subPictureBytes); | 96 saveLayerData.release(), subPictureBytes); |
97 } | 97 } |
98 | 98 |
99 SkPicture* SkPictureRecorder::endRecordingAsPicture(const SkRect& cullRect) { | 99 sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPictureWithCull(const SkRec
t& cullRect) { |
100 fCullRect = cullRect; | 100 fCullRect = cullRect; |
101 return this->endRecordingAsPicture(); | 101 return this->finishRecordingAsPicture(); |
102 } | 102 } |
103 | 103 |
104 | 104 |
105 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 105 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
106 if (nullptr == canvas) { | 106 if (nullptr == canvas) { |
107 return; | 107 return; |
108 } | 108 } |
109 | 109 |
110 int drawableCount = 0; | 110 int drawableCount = 0; |
111 SkDrawable* const* drawables = nullptr; | 111 SkDrawable* const* drawables = nullptr; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 for (int i = 0; pictList && i < pictList->count(); i++) { | 170 for (int i = 0; pictList && i < pictList->count(); i++) { |
171 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); | 171 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); |
172 } | 172 } |
173 // SkBigPicture will take ownership of a ref on both fRecord and fBBH. | 173 // SkBigPicture will take ownership of a ref on both fRecord and fBBH. |
174 // We're not willing to give up our ownership, so we must ref them for S
kPicture. | 174 // We're not willing to give up our ownership, so we must ref them for S
kPicture. |
175 return new SkBigPicture(fBounds, SkRef(fRecord.get()), pictList, SkSafeR
ef(fBBH.get()), | 175 return new SkBigPicture(fBounds, SkRef(fRecord.get()), pictList, SkSafeR
ef(fBBH.get()), |
176 saveLayerData.release(), subPictureBytes); | 176 saveLayerData.release(), subPictureBytes); |
177 } | 177 } |
178 }; | 178 }; |
179 | 179 |
180 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { | 180 sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable() { |
181 fActivelyRecording = false; | 181 fActivelyRecording = false; |
182 fRecorder->flushMiniRecorder(); | 182 fRecorder->flushMiniRecorder(); |
183 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | 183 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
184 | 184 |
185 // TODO: delay as much of this work until just before first playback? | 185 // TODO: delay as much of this work until just before first playback? |
186 SkRecordOptimize(fRecord); | 186 SkRecordOptimize(fRecord); |
187 | 187 |
188 if (fBBH.get()) { | 188 if (fBBH.get()) { |
189 SkAutoTMalloc<SkRect> bounds(fRecord->count()); | 189 SkAutoTMalloc<SkRect> bounds(fRecord->count()); |
190 SkRecordFillBounds(fCullRect, *fRecord, bounds); | 190 SkRecordFillBounds(fCullRect, *fRecord, bounds); |
191 fBBH->insert(bounds, fRecord->count()); | 191 fBBH->insert(bounds, fRecord->count()); |
192 } | 192 } |
193 | 193 |
194 SkDrawable* drawable = | 194 sk_sp<SkDrawable> drawable = |
195 new SkRecordedDrawable(fRecord, fBBH, fRecorder->detachDrawableList(
), fCullRect, | 195 sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawab
leList(), fCullRect, |
196 SkToBool(fFlags & kComputeSaveLayerInfo_Recor
dFlag)); | 196 SkToBool(fFlags & kComputeSaveLayerInfo_Recor
dFlag)); |
197 | 197 |
198 // release our refs now, so only the drawable will be the owner. | 198 // release our refs now, so only the drawable will be the owner. |
199 fRecord.reset(nullptr); | 199 fRecord.reset(nullptr); |
200 fBBH.reset(nullptr); | 200 fBBH.reset(nullptr); |
201 | 201 |
202 return drawable; | 202 return drawable; |
203 } | 203 } |
OLD | NEW |