| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { | 66 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { |
| 67 saveLayerData.reset(new SkLayerInfo); | 67 saveLayerData.reset(new SkLayerInfo); |
| 68 } | 68 } |
| 69 | 69 |
| 70 SkDrawableList* drawableList = fRecorder->getDrawableList(); | 70 SkDrawableList* drawableList = fRecorder->getDrawableList(); |
| 71 SkBigPicture::SnapshotArray* pictList = | 71 SkBigPicture::SnapshotArray* pictList = |
| 72 drawableList ? drawableList->newDrawableSnapshot() : nullptr; | 72 drawableList ? drawableList->newDrawableSnapshot() : nullptr; |
| 73 | 73 |
| 74 if (fBBH.get()) { | 74 if (fBBH.get()) { |
| 75 SkAutoTMalloc<SkRect> bounds(fRecord->count()); |
| 75 if (saveLayerData) { | 76 if (saveLayerData) { |
| 76 SkRecordComputeLayers(fCullRect, *fRecord, pictList, fBBH.get(), sav
eLayerData); | 77 SkRecordComputeLayers(fCullRect, *fRecord, bounds, pictList, saveLay
erData); |
| 77 } else { | 78 } else { |
| 78 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); | 79 SkRecordFillBounds(fCullRect, *fRecord, bounds); |
| 79 } | 80 } |
| 81 fBBH->insert(bounds, fRecord->count()); |
| 82 |
| 83 // Now that we've calculated content bounds, we can update fCullRect, of
ten trimming it. |
| 84 // TODO: get updated fCullRect from bounds instead of forcing the BBH to
return it? |
| 80 SkRect bbhBound = fBBH->getRootBound(); | 85 SkRect bbhBound = fBBH->getRootBound(); |
| 81 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) | 86 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) |
| 82 || (bbhBound.isEmpty() && fCullRect.isEmpty())); | 87 || (bbhBound.isEmpty() && fCullRect.isEmpty())); |
| 83 fCullRect = bbhBound; | 88 fCullRect = bbhBound; |
| 84 } | 89 } |
| 85 | 90 |
| 86 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); | 91 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); |
| 87 for (int i = 0; pictList && i < pictList->count(); i++) { | 92 for (int i = 0; pictList && i < pictList->count(); i++) { |
| 88 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); | 93 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); |
| 89 } | 94 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 151 |
| 147 SkPicture* onNewPictureSnapshot() override { | 152 SkPicture* onNewPictureSnapshot() override { |
| 148 SkBigPicture::SnapshotArray* pictList = nullptr; | 153 SkBigPicture::SnapshotArray* pictList = nullptr; |
| 149 if (fDrawableList) { | 154 if (fDrawableList) { |
| 150 // TODO: should we plumb-down the BBHFactory and recordFlags from ou
r host | 155 // TODO: should we plumb-down the BBHFactory and recordFlags from ou
r host |
| 151 // PictureRecorder? | 156 // PictureRecorder? |
| 152 pictList = fDrawableList->newDrawableSnapshot(); | 157 pictList = fDrawableList->newDrawableSnapshot(); |
| 153 } | 158 } |
| 154 | 159 |
| 155 SkAutoTUnref<SkLayerInfo> saveLayerData; | 160 SkAutoTUnref<SkLayerInfo> saveLayerData; |
| 156 | |
| 157 if (fBBH && fDoSaveLayerInfo) { | 161 if (fBBH && fDoSaveLayerInfo) { |
| 162 // TODO: can we avoid work by not allocating / filling these bounds? |
| 163 SkAutoTMalloc<SkRect> scratchBounds(fRecord->count()); |
| 158 saveLayerData.reset(new SkLayerInfo); | 164 saveLayerData.reset(new SkLayerInfo); |
| 159 | 165 |
| 160 SkBBoxHierarchy* bbh = nullptr; // we've already computed fBBH (r
eceived in constructor) | 166 SkRecordComputeLayers(fBounds, *fRecord, scratchBounds, pictList, sa
veLayerData); |
| 161 // TODO: update saveLayer info computation to reuse the already comp
uted | |
| 162 // bounds in 'fBBH' | |
| 163 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat
a); | |
| 164 } | 167 } |
| 165 | 168 |
| 166 size_t subPictureBytes = 0; | 169 size_t subPictureBytes = 0; |
| 167 for (int i = 0; pictList && i < pictList->count(); i++) { | 170 for (int i = 0; pictList && i < pictList->count(); i++) { |
| 168 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); | 171 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); |
| 169 } | 172 } |
| 170 // 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. |
| 171 // 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. |
| 172 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()), |
| 173 saveLayerData.detach(), subPictureBytes); | 176 saveLayerData.detach(), subPictureBytes); |
| 174 } | 177 } |
| 175 }; | 178 }; |
| 176 | 179 |
| 177 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { | 180 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { |
| 178 fActivelyRecording = false; | 181 fActivelyRecording = false; |
| 179 fRecorder->flushMiniRecorder(); | 182 fRecorder->flushMiniRecorder(); |
| 180 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. |
| 181 | 184 |
| 182 // 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? |
| 183 SkRecordOptimize(fRecord); | 186 SkRecordOptimize(fRecord); |
| 184 | 187 |
| 185 if (fBBH.get()) { | 188 if (fBBH.get()) { |
| 186 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); | 189 SkAutoTMalloc<SkRect> bounds(fRecord->count()); |
| 190 SkRecordFillBounds(fCullRect, *fRecord, bounds); |
| 191 fBBH->insert(bounds, fRecord->count()); |
| 187 } | 192 } |
| 188 | 193 |
| 189 SkDrawable* drawable = | 194 SkDrawable* drawable = |
| 190 new SkRecordedDrawable(fRecord, fBBH, fRecorder->detachDrawableList(
), fCullRect, | 195 new SkRecordedDrawable(fRecord, fBBH, fRecorder->detachDrawableList(
), fCullRect, |
| 191 SkToBool(fFlags & kComputeSaveLayerInfo_Recor
dFlag)); | 196 SkToBool(fFlags & kComputeSaveLayerInfo_Recor
dFlag)); |
| 192 | 197 |
| 193 // 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. |
| 194 fRecord.reset(nullptr); | 199 fRecord.reset(nullptr); |
| 195 fBBH.reset(nullptr); | 200 fBBH.reset(nullptr); |
| 196 | 201 |
| 197 return drawable; | 202 return drawable; |
| 198 } | 203 } |
| OLD | NEW |