| 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" |
| 11 #include "SkPictureRecorder.h" | 11 #include "SkPictureRecorder.h" |
| 12 #include "SkRecord.h" | 12 #include "SkRecord.h" |
| 13 #include "SkRecordDraw.h" | 13 #include "SkRecordDraw.h" |
| 14 #include "SkRecorder.h" | 14 #include "SkRecorder.h" |
| 15 #include "SkRecordOpts.h" | 15 #include "SkRecordOpts.h" |
| 16 #include "SkTypes.h" | 16 #include "SkTypes.h" |
| 17 | 17 |
| 18 SkPictureRecorder::SkPictureRecorder() {} | 18 SkPictureRecorder::SkPictureRecorder() { |
| 19 fRecorder.reset(SkNEW_ARGS(SkRecorder, (nullptr, SkRect::MakeWH(0,0)))); |
| 20 } |
| 19 | 21 |
| 20 SkPictureRecorder::~SkPictureRecorder() {} | 22 SkPictureRecorder::~SkPictureRecorder() {} |
| 21 | 23 |
| 22 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, | 24 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, |
| 23 SkBBHFactory* bbhFactory /* = NULL *
/, | 25 SkBBHFactory* bbhFactory /* = NULL *
/, |
| 24 uint32_t recordFlags /* = 0 */) { | 26 uint32_t recordFlags /* = 0 */) { |
| 25 fCullRect = cullRect; | 27 fCullRect = cullRect; |
| 26 fFlags = recordFlags; | 28 fFlags = recordFlags; |
| 27 | 29 |
| 28 if (bbhFactory) { | 30 if (bbhFactory) { |
| 29 fBBH.reset((*bbhFactory)(cullRect)); | 31 fBBH.reset((*bbhFactory)(cullRect)); |
| 30 SkASSERT(fBBH.get()); | 32 SkASSERT(fBBH.get()); |
| 31 } | 33 } |
| 32 | 34 |
| 33 fRecord.reset(SkNEW(SkRecord)); | 35 fRecord.reset(SkNEW(SkRecord)); |
| 34 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), cullRect))); | 36 fRecorder->reset(fRecord.get(), cullRect); |
| 35 return this->getRecordingCanvas(); | 37 return this->getRecordingCanvas(); |
| 36 } | 38 } |
| 37 | 39 |
| 38 SkCanvas* SkPictureRecorder::getRecordingCanvas() { | 40 SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
| 39 return fRecorder.get(); | 41 return fRecorder.get(); |
| 40 } | 42 } |
| 41 | 43 |
| 42 SkPicture* SkPictureRecorder::endRecordingAsPicture() { | 44 SkPicture* SkPictureRecorder::endRecordingAsPicture() { |
| 45 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
| 43 // TODO: delay as much of this work until just before first playback? | 46 // TODO: delay as much of this work until just before first playback? |
| 44 SkRecordOptimize(fRecord); | 47 SkRecordOptimize(fRecord); |
| 45 | 48 |
| 46 SkAutoTUnref<SkLayerInfo> saveLayerData; | 49 SkAutoTUnref<SkLayerInfo> saveLayerData; |
| 47 | 50 |
| 48 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { | 51 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { |
| 49 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); | 52 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); |
| 50 | 53 |
| 51 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); | 54 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); |
| 52 } | 55 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 66 fCullRect = bbhBound; | 69 fCullRect = bbhBound; |
| 67 } | 70 } |
| 68 | 71 |
| 69 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord, pictList, fBBH)
); | 72 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord, pictList, fBBH)
); |
| 70 | 73 |
| 71 if (saveLayerData) { | 74 if (saveLayerData) { |
| 72 pict->EXPERIMENTAL_addAccelData(saveLayerData); | 75 pict->EXPERIMENTAL_addAccelData(saveLayerData); |
| 73 } | 76 } |
| 74 | 77 |
| 75 // release our refs now, so only the picture will be the owner. | 78 // release our refs now, so only the picture will be the owner. |
| 76 fRecorder.reset(NULL); | |
| 77 fRecord.reset(NULL); | 79 fRecord.reset(NULL); |
| 78 fBBH.reset(NULL); | 80 fBBH.reset(NULL); |
| 79 | 81 |
| 80 return pict; | 82 return pict; |
| 81 } | 83 } |
| 82 | 84 |
| 83 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 85 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
| 84 if (NULL == canvas) { | 86 if (NULL == canvas) { |
| 85 return; | 87 return; |
| 86 } | 88 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 SkPicture* pict = SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBB
H)); | 153 SkPicture* pict = SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBB
H)); |
| 152 | 154 |
| 153 if (saveLayerData) { | 155 if (saveLayerData) { |
| 154 pict->EXPERIMENTAL_addAccelData(saveLayerData); | 156 pict->EXPERIMENTAL_addAccelData(saveLayerData); |
| 155 } | 157 } |
| 156 return pict; | 158 return pict; |
| 157 } | 159 } |
| 158 }; | 160 }; |
| 159 | 161 |
| 160 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { | 162 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { |
| 163 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
| 161 // TODO: delay as much of this work until just before first playback? | 164 // TODO: delay as much of this work until just before first playback? |
| 162 SkRecordOptimize(fRecord); | 165 SkRecordOptimize(fRecord); |
| 163 | 166 |
| 164 if (fBBH.get()) { | 167 if (fBBH.get()) { |
| 165 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); | 168 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); |
| 166 } | 169 } |
| 167 | 170 |
| 168 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, | 171 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, |
| 169 (fRecord, fBBH, fRecorder->detachDrawabl
eList(), | 172 (fRecord, fBBH, fRecorder->detachDrawabl
eList(), |
| 170 fCullRect, | 173 fCullRect, |
| 171 SkToBool(fFlags & kComputeSaveLayerInfo
_RecordFlag))); | 174 SkToBool(fFlags & kComputeSaveLayerInfo
_RecordFlag))); |
| 172 | 175 |
| 173 // release our refs now, so only the drawable will be the owner. | 176 // release our refs now, so only the drawable will be the owner. |
| 174 fRecorder.reset(NULL); | |
| 175 fRecord.reset(NULL); | 177 fRecord.reset(NULL); |
| 176 fBBH.reset(NULL); | 178 fBBH.reset(NULL); |
| 177 | 179 |
| 178 return drawable; | 180 return drawable; |
| 179 } | 181 } |
| OLD | NEW |