| 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 "SkLayerInfo.h" |
| 8 #include "SkPictureRecorder.h" | 9 #include "SkPictureRecorder.h" |
| 9 #include "SkRecord.h" | 10 #include "SkRecord.h" |
| 10 #include "SkRecordDraw.h" | 11 #include "SkRecordDraw.h" |
| 11 #include "SkRecorder.h" | 12 #include "SkRecorder.h" |
| 12 #include "SkRecordOpts.h" | 13 #include "SkRecordOpts.h" |
| 13 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 14 | 15 |
| 15 // Must place SK_SUPPORT_GPU after other includes so it is defined in the | |
| 16 // Android framework build. | |
| 17 #if SK_SUPPORT_GPU | |
| 18 #include "GrPictureUtils.h" | |
| 19 #endif | |
| 20 | |
| 21 SkPictureRecorder::SkPictureRecorder() {} | 16 SkPictureRecorder::SkPictureRecorder() {} |
| 22 | 17 |
| 23 SkPictureRecorder::~SkPictureRecorder() {} | 18 SkPictureRecorder::~SkPictureRecorder() {} |
| 24 | 19 |
| 25 SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height, | 20 SkCanvas* SkPictureRecorder::beginRecording(SkScalar width, SkScalar height, |
| 26 SkBBHFactory* bbhFactory /* = NULL *
/, | 21 SkBBHFactory* bbhFactory /* = NULL *
/, |
| 27 uint32_t recordFlags /* = 0 */) { | 22 uint32_t recordFlags /* = 0 */) { |
| 28 fFlags = recordFlags; | 23 fFlags = recordFlags; |
| 29 fCullWidth = width; | 24 fCullWidth = width; |
| 30 fCullHeight = height; | 25 fCullHeight = height; |
| 31 | 26 |
| 32 if (bbhFactory) { | 27 if (bbhFactory) { |
| 33 fBBH.reset((*bbhFactory)(width, height)); | 28 fBBH.reset((*bbhFactory)(width, height)); |
| 34 SkASSERT(fBBH.get()); | 29 SkASSERT(fBBH.get()); |
| 35 } | 30 } |
| 36 | 31 |
| 37 fRecord.reset(SkNEW(SkRecord)); | 32 fRecord.reset(SkNEW(SkRecord)); |
| 38 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height))); | 33 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height))); |
| 39 return this->getRecordingCanvas(); | 34 return this->getRecordingCanvas(); |
| 40 } | 35 } |
| 41 | 36 |
| 42 SkCanvas* SkPictureRecorder::getRecordingCanvas() { | 37 SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
| 43 return fRecorder.get(); | 38 return fRecorder.get(); |
| 44 } | 39 } |
| 45 | 40 |
| 46 SkPicture* SkPictureRecorder::endRecording() { | 41 SkPicture* SkPictureRecorder::endRecording() { |
| 47 // TODO: delay as much of this work until just before first playback? | 42 // TODO: delay as much of this work until just before first playback? |
| 48 SkRecordOptimize(fRecord); | 43 SkRecordOptimize(fRecord); |
| 49 | 44 |
| 50 #if SK_SUPPORT_GPU | 45 SkAutoTUnref<SkLayerInfo> saveLayerData; |
| 51 SkAutoTUnref<GrAccelData> saveLayerData; | |
| 52 | 46 |
| 53 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { | 47 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { |
| 54 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 48 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); |
| 55 | 49 |
| 56 saveLayerData.reset(SkNEW_ARGS(GrAccelData, (key))); | 50 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); |
| 57 } | 51 } |
| 58 #endif | |
| 59 | 52 |
| 60 if (fBBH.get()) { | 53 if (fBBH.get()) { |
| 61 SkRect cullRect = SkRect::MakeWH(fCullWidth, fCullHeight); | 54 SkRect cullRect = SkRect::MakeWH(fCullWidth, fCullHeight); |
| 62 | 55 |
| 63 #if SK_SUPPORT_GPU | |
| 64 if (saveLayerData) { | 56 if (saveLayerData) { |
| 65 SkRecordComputeLayers(cullRect, *fRecord, fBBH.get(), saveLayerData)
; | 57 SkRecordComputeLayers(cullRect, *fRecord, fBBH.get(), saveLayerData)
; |
| 66 } else { | 58 } else { |
| 67 #endif | |
| 68 SkRecordFillBounds(cullRect, *fRecord, fBBH.get()); | 59 SkRecordFillBounds(cullRect, *fRecord, fBBH.get()); |
| 69 #if SK_SUPPORT_GPU | |
| 70 } | 60 } |
| 71 #endif | |
| 72 } | 61 } |
| 73 | 62 |
| 74 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight, fRecord.de
tach(), fBBH.get())); | 63 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullWidth, fCullHeight, fRecord.de
tach(), fBBH.get())); |
| 75 | 64 |
| 76 #if SK_SUPPORT_GPU | |
| 77 if (saveLayerData) { | 65 if (saveLayerData) { |
| 78 pict->EXPERIMENTAL_addAccelData(saveLayerData); | 66 pict->EXPERIMENTAL_addAccelData(saveLayerData); |
| 79 } | 67 } |
| 80 #endif | |
| 81 | 68 |
| 82 return pict; | 69 return pict; |
| 83 } | 70 } |
| 84 | 71 |
| 85 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 72 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
| 86 if (NULL == canvas) { | 73 if (NULL == canvas) { |
| 87 return; | 74 return; |
| 88 } | 75 } |
| 89 SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/); | 76 SkRecordDraw(*fRecord, canvas, NULL/*bbh*/, NULL/*callback*/); |
| 90 } | 77 } |
| OLD | NEW |