| 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 "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkDrawable.h" | 9 #include "SkDrawable.h" |
| 10 #include "SkLayerInfo.h" | 10 #include "SkLayerInfo.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 SkRect bbhBound = fBBH->getRootBound(); | 70 SkRect bbhBound = fBBH->getRootBound(); |
| 71 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) | 71 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) |
| 72 || (bbhBound.isEmpty() && fCullRect.isEmpty())); | 72 || (bbhBound.isEmpty() && fCullRect.isEmpty())); |
| 73 fCullRect = bbhBound; | 73 fCullRect = bbhBound; |
| 74 } | 74 } |
| 75 | 75 |
| 76 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); | 76 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); |
| 77 for (int i = 0; pictList && i < pictList->count(); i++) { | 77 for (int i = 0; pictList && i < pictList->count(); i++) { |
| 78 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); | 78 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); |
| 79 } | 79 } |
| 80 SkPicture* pict = SkNEW_ARGS(SkPicture, | 80 return SkNEW_ARGS(SkPicture, (fCullRect, |
| 81 (fCullRect, fRecord.detach(), pictList, fBBH.detach(), subPictureByt
es)); | 81 fRecord.detach(), |
| 82 | 82 pictList, |
| 83 if (saveLayerData) { | 83 fBBH.detach(), |
| 84 pict->EXPERIMENTAL_addAccelData(saveLayerData); | 84 saveLayerData.detach(), |
| 85 } | 85 subPictureBytes)); |
| 86 | |
| 87 return pict; | |
| 88 } | 86 } |
| 89 | 87 |
| 90 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 88 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
| 91 if (NULL == canvas) { | 89 if (NULL == canvas) { |
| 92 return; | 90 return; |
| 93 } | 91 } |
| 94 | 92 |
| 95 int drawableCount = 0; | 93 int drawableCount = 0; |
| 96 SkDrawable* const* drawables = NULL; | 94 SkDrawable* const* drawables = NULL; |
| 97 SkDrawableList* drawableList = fRecorder->getDrawableList(); | 95 SkDrawableList* drawableList = fRecorder->getDrawableList(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // bounds in 'fBBH' | 152 // bounds in 'fBBH' |
| 155 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat
a); | 153 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat
a); |
| 156 } | 154 } |
| 157 | 155 |
| 158 size_t subPictureBytes = 0; | 156 size_t subPictureBytes = 0; |
| 159 for (int i = 0; pictList && i < pictList->count(); i++) { | 157 for (int i = 0; pictList && i < pictList->count(); i++) { |
| 160 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); | 158 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); |
| 161 } | 159 } |
| 162 // SkPicture will take ownership of a ref on both fRecord and fBBH. | 160 // SkPicture will take ownership of a ref on both fRecord and fBBH. |
| 163 // We're not willing to give up our ownership, so we must ref them for S
kPicture. | 161 // We're not willing to give up our ownership, so we must ref them for S
kPicture. |
| 164 SkPicture* pict = SkNEW_ARGS(SkPicture, | 162 return SkNEW_ARGS(SkPicture, (fBounds, |
| 165 (fBounds, SkRef(fRecord.get()), pictList, SkSafeRef(fBBH.get()),
subPictureBytes)); | 163 SkRef(fRecord.get()), |
| 166 | 164 pictList, |
| 167 if (saveLayerData) { | 165 SkSafeRef(fBBH.get()), |
| 168 pict->EXPERIMENTAL_addAccelData(saveLayerData); | 166 saveLayerData.detach(), |
| 169 } | 167 subPictureBytes)); |
| 170 return pict; | |
| 171 } | 168 } |
| 172 }; | 169 }; |
| 173 | 170 |
| 174 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { | 171 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { |
| 175 fActivelyRecording = false; | 172 fActivelyRecording = false; |
| 176 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | 173 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
| 177 // TODO: delay as much of this work until just before first playback? | 174 // TODO: delay as much of this work until just before first playback? |
| 178 SkRecordOptimize(fRecord); | 175 SkRecordOptimize(fRecord); |
| 179 | 176 |
| 180 if (fBBH.get()) { | 177 if (fBBH.get()) { |
| 181 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); | 178 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); |
| 182 } | 179 } |
| 183 | 180 |
| 184 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, | 181 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, |
| 185 (fRecord, fBBH, fRecorder->detachDrawabl
eList(), | 182 (fRecord, fBBH, fRecorder->detachDrawabl
eList(), |
| 186 fCullRect, | 183 fCullRect, |
| 187 SkToBool(fFlags & kComputeSaveLayerInfo
_RecordFlag))); | 184 SkToBool(fFlags & kComputeSaveLayerInfo
_RecordFlag))); |
| 188 | 185 |
| 189 // release our refs now, so only the drawable will be the owner. | 186 // release our refs now, so only the drawable will be the owner. |
| 190 fRecord.reset(NULL); | 187 fRecord.reset(NULL); |
| 191 fBBH.reset(NULL); | 188 fBBH.reset(NULL); |
| 192 | 189 |
| 193 return drawable; | 190 return drawable; |
| 194 } | 191 } |
| OLD | NEW |