Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: src/core/SkPictureRecorder.cpp

Issue 732653004: option to return drawable from recording (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPicture.cpp ('k') | src/core/SkRecord.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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() : fBBHFactory(NULL) {}
18 19
19 SkPictureRecorder::~SkPictureRecorder() {} 20 SkPictureRecorder::~SkPictureRecorder() {}
20 21
21 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, 22 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect,
22 SkBBHFactory* bbhFactory /* = NULL * /, 23 SkBBHFactory* bbhFactory /* = NULL * /,
23 uint32_t recordFlags /* = 0 */) { 24 uint32_t recordFlags /* = 0 */) {
24 fCullRect = cullRect; 25 fCullRect = cullRect;
26 fBBHFactory = bbhFactory;
25 fFlags = recordFlags; 27 fFlags = recordFlags;
26 28
27 if (bbhFactory) { 29 if (bbhFactory) {
28 fBBH.reset((*bbhFactory)(cullRect)); 30 fBBH.reset((*bbhFactory)(cullRect));
29 SkASSERT(fBBH.get()); 31 SkASSERT(fBBH.get());
30 } 32 }
31 33
32 fRecord.reset(SkNEW(SkRecord)); 34 fRecord.reset(SkNEW(SkRecord));
33 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), cullRect))); 35 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), cullRect)));
34 return this->getRecordingCanvas(); 36 return this->getRecordingCanvas();
35 } 37 }
36 38
37 SkCanvas* SkPictureRecorder::getRecordingCanvas() { 39 SkCanvas* SkPictureRecorder::getRecordingCanvas() {
38 return fRecorder.get(); 40 return fRecorder.get();
39 } 41 }
40 42
41 SkPicture* SkPictureRecorder::endRecording() { 43 SkPicture* SkPictureRecorder::endRecordingAsPicture() {
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 }
52 54
55 SkCanvasDrawableList* drawableList = fRecorder->getDrawableList();
56 SkPicture::SnapshotArray* pictList = drawableList ? drawableList->newDrawabl eSnapshot() : NULL;
57
53 if (fBBH.get()) { 58 if (fBBH.get()) {
54 if (saveLayerData) { 59 if (saveLayerData) {
55 SkRecordComputeLayers(fCullRect, *fRecord, fBBH.get(), saveLayerData ); 60 SkRecordComputeLayers(fCullRect, *fRecord, pictList, fBBH.get(), sav eLayerData);
56 } else { 61 } else {
57 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); 62 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get());
58 } 63 }
59 } 64 }
60 65
61 // TODO: we should remember these from our caller 66 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord, pictList, fBBH) );
62 SkBBHFactory* factory = NULL;
63 uint32_t recordFlags = 0;
64 SkAutoTDelete<SkPicture::SnapshotArray> drawablePicts(
65 fRecorder->newDrawableSnapshot(factory, recordFlags));
66 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord.detach(),
67 drawablePicts.detach(), fBBH.get()) );
68 67
69 if (saveLayerData) { 68 if (saveLayerData) {
70 pict->EXPERIMENTAL_addAccelData(saveLayerData); 69 pict->EXPERIMENTAL_addAccelData(saveLayerData);
71 } 70 }
72 71
73 return pict; 72 return pict;
74 } 73 }
75 74
76 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { 75 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
77 if (NULL == canvas) { 76 if (NULL == canvas) {
78 return; 77 return;
79 } 78 }
80 79
81 int drawableCount = 0; 80 int drawableCount = 0;
82 SkRecordDraw(*fRecord, canvas, NULL, drawableCount, NULL/*bbh*/, NULL/*callb ack*/); 81 SkCanvasDrawable* const* drawables = NULL;
82 SkCanvasDrawableList* drawableList = fRecorder->getDrawableList();
83 if (drawableList) {
84 drawableCount = drawableList->count();
85 drawables = drawableList->begin();
86 }
87 SkRecordDraw(*fRecord, canvas, NULL, drawables, drawableCount, NULL/*bbh*/, NULL/*callback*/);
83 } 88 }
89
90 //////////////////////////////////////////////////////////////////////////////// ///////////////////
91
92 class SkRecordedDrawable : public SkCanvasDrawable {
93 SkAutoTUnref<SkRecord> fRecord;
94 SkAutoTUnref<SkBBoxHierarchy> fBBH;
95 SkAutoTDelete<SkCanvasDrawableList> fDrawableList;
96 const SkRect fBounds;
97 const bool fDoSaveLayerInfo;
98
99 public:
100 SkRecordedDrawable(SkRecord* record, SkBBoxHierarchy* bbh, SkCanvasDrawableL ist* drawableList,
101 const SkRect& bounds, bool doSaveLayerInfo)
102 : fRecord(SkRef(record))
103 , fBBH(SkSafeRef(bbh))
104 , fDrawableList(drawableList) // we take ownership
105 , fBounds(bounds)
106 , fDoSaveLayerInfo(doSaveLayerInfo)
107 {}
108
109 protected:
110 SkRect onGetBounds() SK_OVERRIDE { return fBounds; }
111
112 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
113 SkCanvasDrawable* const* drawables = NULL;
114 int drawableCount = 0;
115 if (fDrawableList) {
116 drawables = fDrawableList->begin();
117 drawableCount = fDrawableList->count();
118 }
119 SkRecordDraw(*fRecord, canvas, NULL, drawables, drawableCount, fBBH, NUL L/*callback*/);
120 }
121
122 SkPicture* onNewPictureSnapshot() SK_OVERRIDE {
123 SkPicture::SnapshotArray* pictList = NULL;
124 if (fDrawableList) {
125 // TODO: should we plumb-down the BBHFactory and recordFlags from ou r host
126 // PictureRecorder?
127 pictList = fDrawableList->newDrawableSnapshot();
128 }
129
130 SkAutoTUnref<SkLayerInfo> saveLayerData;
131
132 if (fBBH && fDoSaveLayerInfo) {
133 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
134
135 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
136
137 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece ived in constructor)
138 // TODO: update saveLayer info computation to reuse the already comp uted
139 // bounds in 'fBBH'
140 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat a);
141 }
142
143 SkPicture* pict = SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBB H));
144
145 if (saveLayerData) {
146 pict->EXPERIMENTAL_addAccelData(saveLayerData);
147 }
148 return pict;
149 }
150 };
151
152 SkCanvasDrawable* SkPictureRecorder::EXPERIMENTAL_endRecordingAsDrawable() {
153 // TODO: delay as much of this work until just before first playback?
154 SkRecordOptimize(fRecord);
155
156 if (fBBH.get()) {
157 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get());
158 }
159
160 return SkNEW_ARGS(SkRecordedDrawable, (fRecord, fBBH, fRecorder->detachDrawa bleList(),
161 fCullRect,
162 SkToBool(fFlags & kComputeSaveLayerIn fo_RecordFlag)));
163 }
OLDNEW
« no previous file with comments | « src/core/SkPicture.cpp ('k') | src/core/SkRecord.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698