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 "SkCanvasDrawable.h" | |
8 #include "SkData.h" | 9 #include "SkData.h" |
9 #include "SkLayerInfo.h" | 10 #include "SkLayerInfo.h" |
10 #include "SkPictureRecorder.h" | 11 #include "SkPictureRecorder.h" |
11 #include "SkRecord.h" | 12 #include "SkRecord.h" |
12 #include "SkRecordDraw.h" | 13 #include "SkRecordDraw.h" |
13 #include "SkRecorder.h" | 14 #include "SkRecorder.h" |
14 #include "SkRecordOpts.h" | 15 #include "SkRecordOpts.h" |
15 #include "SkTypes.h" | 16 #include "SkTypes.h" |
16 | 17 |
17 SkPictureRecorder::SkPictureRecorder() {} | 18 SkPictureRecorder::SkPictureRecorder() {} |
(...skipping 14 matching lines...) Expand all Loading... | |
32 fRecord.reset(SkNEW(SkRecord)); | 33 fRecord.reset(SkNEW(SkRecord)); |
33 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), cullRect))); | 34 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), cullRect))); |
34 return this->getRecordingCanvas(); | 35 return this->getRecordingCanvas(); |
35 } | 36 } |
36 | 37 |
37 SkCanvas* SkPictureRecorder::getRecordingCanvas() { | 38 SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
38 return fRecorder.get(); | 39 return fRecorder.get(); |
39 } | 40 } |
40 | 41 |
41 SkPicture* SkPictureRecorder::endRecording() { | 42 SkPicture* SkPictureRecorder::endRecording() { |
43 #if 0 | |
42 // TODO: delay as much of this work until just before first playback? | 44 // TODO: delay as much of this work until just before first playback? |
43 SkRecordOptimize(fRecord); | 45 SkRecordOptimize(fRecord); |
44 | 46 |
45 SkAutoTUnref<SkLayerInfo> saveLayerData; | 47 SkAutoTUnref<SkLayerInfo> saveLayerData; |
46 | 48 |
47 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { | 49 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { |
48 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); | 50 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); |
49 | 51 |
50 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); | 52 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); |
51 } | 53 } |
(...skipping 12 matching lines...) Expand all Loading... | |
64 SkAutoTDelete<SkPicture::SnapshotArray> drawablePicts( | 66 SkAutoTDelete<SkPicture::SnapshotArray> drawablePicts( |
65 fRecorder->newDrawableSnapshot(factory, recordFlags)); | 67 fRecorder->newDrawableSnapshot(factory, recordFlags)); |
66 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord.detach(), | 68 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord.detach(), |
67 drawablePicts.detach(), fBBH.get()) ); | 69 drawablePicts.detach(), fBBH.get()) ); |
68 | 70 |
69 if (saveLayerData) { | 71 if (saveLayerData) { |
70 pict->EXPERIMENTAL_addAccelData(saveLayerData); | 72 pict->EXPERIMENTAL_addAccelData(saveLayerData); |
71 } | 73 } |
72 | 74 |
73 return pict; | 75 return pict; |
76 #else | |
77 SkAutoTUnref<SkCanvasDrawable> drawable(this->EXPERIMENTAL_endRecordingAsDra wable()); | |
78 return drawable->newPictureSnapshot(); | |
79 #endif | |
74 } | 80 } |
75 | 81 |
76 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 82 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
77 if (NULL == canvas) { | 83 if (NULL == canvas) { |
78 return; | 84 return; |
79 } | 85 } |
80 | 86 |
81 int drawableCount = 0; | 87 int drawableCount = 0; |
82 SkRecordDraw(*fRecord, canvas, NULL, drawableCount, NULL/*bbh*/, NULL/*callb ack*/); | 88 SkRecordDraw(*fRecord, canvas, NULL, NULL, drawableCount, NULL/*bbh*/, NULL/ *callback*/); |
83 } | 89 } |
90 | |
91 //////////////////////////////////////////////////////////////////////////////// /////////////////// | |
92 | |
93 class SkRecordedDrawable : public SkCanvasDrawable { | |
94 SkAutoTUnref<SkRecord> fRecord; | |
95 SkAutoTUnref<SkBBoxHierarchy> fBBH; | |
96 SkAutoTDelete<SkCanvasDrawableList> fDrawableList; | |
97 const SkRect fBounds; | |
98 const bool fDoSaveLayerInfo; | |
99 | |
100 public: | |
101 SkRecordedDrawable(SkRecord* record, SkBBoxHierarchy* bbh, SkCanvasDrawableL ist* drawableList, | |
102 const SkRect& bounds, bool doSaveLayerInfo) | |
103 : fRecord(SkRef(record)) | |
104 , fBBH(SkSafeRef(bbh)) | |
105 , fDrawableList(drawableList) // we take ownership | |
106 , fBounds(bounds) | |
107 , fDoSaveLayerInfo(doSaveLayerInfo) | |
108 {} | |
109 | |
110 protected: | |
robertphillips
2014/11/24 15:42:02
one line ?
reed1
2014/11/24 17:10:48
Done.
| |
111 SkRect onGetBounds() SK_OVERRIDE { | |
112 return fBounds; | |
113 } | |
114 | |
115 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | |
116 SkCanvasDrawable* const* drawables = NULL; | |
117 int drawableCount = 0; | |
118 if (fDrawableList) { | |
119 drawables = fDrawableList->begin(); | |
120 drawableCount = fDrawableList->count(); | |
121 } | |
122 SkRecordDraw(*fRecord, canvas, NULL, drawables, drawableCount, fBBH, NUL L/*callback*/); | |
123 } | |
124 | |
125 SkPicture* onNewPictureSnapshot() SK_OVERRIDE { | |
126 SkPicture::SnapshotArray* pictList = NULL; | |
127 if (fDrawableList) { | |
robertphillips
2014/11/24 15:42:02
Are we going to plumb down the BBH and SVI prefere
reed1
2014/11/24 17:10:48
No idea -- will leave as a TODO for now.
mtklein
2014/11/24 17:29:41
Seems like if we're going to plumb BBHs further, w
reed1
2014/11/24 19:12:07
Agreed, though in the lastest patch I added a TODO
| |
128 pictList = fDrawableList->newDrawableSnapshot(); | |
129 } | |
130 | |
131 SkAutoTUnref<SkLayerInfo> saveLayerData; | |
132 | |
133 if (fBBH && fDoSaveLayerInfo) { | |
134 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); | |
135 | |
136 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); | |
137 | |
138 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece ived in constructor) | |
139 // TODO: update saveLayer info computation to reuse the already comp uted | |
140 // bounds in 'fBBH' | |
mtklein
2014/11/24 17:29:41
fBBH doesn't necessarily contain those bounds any
reed1
2014/11/24 19:12:07
Is this something that should be figured out now,
| |
141 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat a); | |
142 } | |
143 | |
144 SkPicture* pict = SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBB H)); | |
145 | |
146 if (saveLayerData) { | |
147 pict->EXPERIMENTAL_addAccelData(saveLayerData); | |
148 } | |
149 return pict; | |
150 } | |
151 }; | |
152 | |
153 SkCanvasDrawable* SkPictureRecorder::EXPERIMENTAL_endRecordingAsDrawable() { | |
154 // TODO: delay as much of this work until just before first playback? | |
155 SkRecordOptimize(fRecord); | |
156 | |
157 if (fBBH.get()) { | |
158 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); | |
159 } | |
160 | |
161 return SkNEW_ARGS(SkRecordedDrawable, (fRecord, fBBH, fRecorder->detachDrawa bleList(), | |
162 fCullRect, | |
163 SkToBool(fFlags & kComputeSaveLayerIn fo_RecordFlag))); | |
164 } | |
OLD | NEW |