| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after 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.detach(), pictList, fBBH.detach()
, | 95 return new SkBigPicture(fCullRect, fRecord.release(), pictList, fBBH.release
(), |
| 96 saveLayerData.detach(), subPictureBytes); | 96 saveLayerData.release(), subPictureBytes); |
| 97 } | 97 } |
| 98 | 98 |
| 99 SkPicture* SkPictureRecorder::endRecordingAsPicture(const SkRect& cullRect) { | 99 SkPicture* SkPictureRecorder::endRecordingAsPicture(const SkRect& cullRect) { |
| 100 fCullRect = cullRect; | 100 fCullRect = cullRect; |
| 101 return this->endRecordingAsPicture(); | 101 return this->endRecordingAsPicture(); |
| 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) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 SkRecordComputeLayers(fBounds, *fRecord, scratchBounds, pictList, sa
veLayerData); | 166 SkRecordComputeLayers(fBounds, *fRecord, scratchBounds, pictList, sa
veLayerData); |
| 167 } | 167 } |
| 168 | 168 |
| 169 size_t subPictureBytes = 0; | 169 size_t subPictureBytes = 0; |
| 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.detach(), subPictureBytes); | 176 saveLayerData.release(), subPictureBytes); |
| 177 } | 177 } |
| 178 }; | 178 }; |
| 179 | 179 |
| 180 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { | 180 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { |
| 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 SkDrawable* drawable = |
| 195 new SkRecordedDrawable(fRecord, fBBH, fRecorder->detachDrawableList(
), fCullRect, | 195 new SkRecordedDrawable(fRecord, fBBH, fRecorder->detachDrawableList(
), 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 |