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