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

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

Issue 1130333002: Revert of Sketch splitting SkPicture into an interface and SkBigPicture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months 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/SkPictureCommon.h ('k') | src/core/SkRecordDraw.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 "SkBigPicture.h"
9 #include "SkData.h" 8 #include "SkData.h"
10 #include "SkDrawable.h" 9 #include "SkDrawable.h"
11 #include "SkLayerInfo.h" 10 #include "SkLayerInfo.h"
12 #include "SkPictureRecorder.h" 11 #include "SkPictureRecorder.h"
13 #include "SkPictureUtils.h" 12 #include "SkPictureUtils.h"
14 #include "SkRecord.h" 13 #include "SkRecord.h"
15 #include "SkRecordDraw.h" 14 #include "SkRecordDraw.h"
16 #include "SkRecordOpts.h" 15 #include "SkRecordOpts.h"
17 #include "SkRecorder.h" 16 #include "SkRecorder.h"
18 #include "SkTypes.h" 17 #include "SkTypes.h"
19 18
20 SkPictureRecorder::SkPictureRecorder() { 19 SkPictureRecorder::SkPictureRecorder() {
21 fActivelyRecording = false; 20 fActivelyRecording = false;
22 fRecorder.reset(SkNEW_ARGS(SkRecorder, (nullptr, SkRect::MakeWH(0,0), &fMini Recorder))); 21 fRecorder.reset(SkNEW_ARGS(SkRecorder, (nullptr, SkRect::MakeWH(0,0))));
23 } 22 }
24 23
25 SkPictureRecorder::~SkPictureRecorder() {} 24 SkPictureRecorder::~SkPictureRecorder() {}
26 25
27 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, 26 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect,
28 SkBBHFactory* bbhFactory /* = NULL * /, 27 SkBBHFactory* bbhFactory /* = NULL * /,
29 uint32_t recordFlags /* = 0 */) { 28 uint32_t recordFlags /* = 0 */) {
30 fCullRect = cullRect; 29 fCullRect = cullRect;
31 fFlags = recordFlags; 30 fFlags = recordFlags;
32 31
33 if (bbhFactory) { 32 if (bbhFactory) {
34 fBBH.reset((*bbhFactory)(cullRect)); 33 fBBH.reset((*bbhFactory)(cullRect));
35 SkASSERT(fBBH.get()); 34 SkASSERT(fBBH.get());
36 } 35 }
37 36
38 if (!fRecord) { 37 fRecord.reset(SkNEW(SkRecord));
39 fRecord.reset(SkNEW(SkRecord)); 38 fRecorder->reset(fRecord.get(), cullRect);
40 }
41 fRecorder->reset(fRecord.get(), cullRect, &fMiniRecorder);
42 fActivelyRecording = true; 39 fActivelyRecording = true;
43 return this->getRecordingCanvas(); 40 return this->getRecordingCanvas();
44 } 41 }
45 42
46 SkCanvas* SkPictureRecorder::getRecordingCanvas() { 43 SkCanvas* SkPictureRecorder::getRecordingCanvas() {
47 return fActivelyRecording ? fRecorder.get() : nullptr; 44 return fActivelyRecording ? fRecorder.get() : nullptr;
48 } 45 }
49 46
50 SkPicture* SkPictureRecorder::endRecordingAsPicture() { 47 SkPicture* SkPictureRecorder::endRecordingAsPicture() {
51 fActivelyRecording = false; 48 fActivelyRecording = false;
52 fRecorder->restoreToCount(1); // If we were missing any restores, add them now. 49 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
53
54 if (fRecord->count() == 0) {
55 return fMiniRecorder.detachAsPicture(fCullRect);
56 }
57
58 // TODO: delay as much of this work until just before first playback? 50 // TODO: delay as much of this work until just before first playback?
59 SkRecordOptimize(fRecord); 51 SkRecordOptimize(fRecord);
60 52
61 SkAutoTUnref<SkLayerInfo> saveLayerData; 53 SkAutoTUnref<SkLayerInfo> saveLayerData;
62 54
63 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { 55 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) {
64 saveLayerData.reset(SkNEW(SkLayerInfo)); 56 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
57
58 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
65 } 59 }
66 60
67 SkDrawableList* drawableList = fRecorder->getDrawableList(); 61 SkDrawableList* drawableList = fRecorder->getDrawableList();
68 SkBigPicture::SnapshotArray* pictList = 62 SkPicture::SnapshotArray* pictList = drawableList ? drawableList->newDrawabl eSnapshot() : NULL;
69 drawableList ? drawableList->newDrawableSnapshot() : NULL;
70 63
71 if (fBBH.get()) { 64 if (fBBH.get()) {
72 if (saveLayerData) { 65 if (saveLayerData) {
73 SkRecordComputeLayers(fCullRect, *fRecord, pictList, fBBH.get(), sav eLayerData); 66 SkRecordComputeLayers(fCullRect, *fRecord, pictList, fBBH.get(), sav eLayerData);
74 } else { 67 } else {
75 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); 68 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get());
76 } 69 }
77 SkRect bbhBound = fBBH->getRootBound(); 70 SkRect bbhBound = fBBH->getRootBound();
78 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) 71 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound))
79 || (bbhBound.isEmpty() && fCullRect.isEmpty())); 72 || (bbhBound.isEmpty() && fCullRect.isEmpty()));
80 fCullRect = bbhBound; 73 fCullRect = bbhBound;
81 } 74 }
82 75
83 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); 76 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures();
84 for (int i = 0; pictList && i < pictList->count(); i++) { 77 for (int i = 0; pictList && i < pictList->count(); i++) {
85 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin( )[i]); 78 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin( )[i]);
86 } 79 }
87 return SkNEW_ARGS(SkBigPicture, (fCullRect, 80 return SkNEW_ARGS(SkPicture, (fCullRect,
88 fRecord.detach(), 81 fRecord.detach(),
89 pictList, 82 pictList,
90 fBBH.detach(), 83 fBBH.detach(),
91 saveLayerData.detach(), 84 saveLayerData.detach(),
92 subPictureBytes)); 85 subPictureBytes));
93 } 86 }
94 87
95 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { 88 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
96 if (NULL == canvas) { 89 if (NULL == canvas) {
97 return; 90 return;
98 } 91 }
99 92
100 int drawableCount = 0; 93 int drawableCount = 0;
101 SkDrawable* const* drawables = NULL; 94 SkDrawable* const* drawables = NULL;
102 SkDrawableList* drawableList = fRecorder->getDrawableList(); 95 SkDrawableList* drawableList = fRecorder->getDrawableList();
(...skipping 30 matching lines...) Expand all
133 SkDrawable* const* drawables = NULL; 126 SkDrawable* const* drawables = NULL;
134 int drawableCount = 0; 127 int drawableCount = 0;
135 if (fDrawableList) { 128 if (fDrawableList) {
136 drawables = fDrawableList->begin(); 129 drawables = fDrawableList->begin();
137 drawableCount = fDrawableList->count(); 130 drawableCount = fDrawableList->count();
138 } 131 }
139 SkRecordDraw(*fRecord, canvas, NULL, drawables, drawableCount, fBBH, NUL L/*callback*/); 132 SkRecordDraw(*fRecord, canvas, NULL, drawables, drawableCount, fBBH, NUL L/*callback*/);
140 } 133 }
141 134
142 SkPicture* onNewPictureSnapshot() override { 135 SkPicture* onNewPictureSnapshot() override {
143 SkBigPicture::SnapshotArray* pictList = NULL; 136 SkPicture::SnapshotArray* pictList = NULL;
144 if (fDrawableList) { 137 if (fDrawableList) {
145 // TODO: should we plumb-down the BBHFactory and recordFlags from ou r host 138 // TODO: should we plumb-down the BBHFactory and recordFlags from ou r host
146 // PictureRecorder? 139 // PictureRecorder?
147 pictList = fDrawableList->newDrawableSnapshot(); 140 pictList = fDrawableList->newDrawableSnapshot();
148 } 141 }
149 142
150 SkAutoTUnref<SkLayerInfo> saveLayerData; 143 SkAutoTUnref<SkLayerInfo> saveLayerData;
151 144
152 if (fBBH && fDoSaveLayerInfo) { 145 if (fBBH && fDoSaveLayerInfo) {
153 saveLayerData.reset(SkNEW(SkLayerInfo)); 146 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
147
148 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
154 149
155 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece ived in constructor) 150 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece ived in constructor)
156 // TODO: update saveLayer info computation to reuse the already comp uted 151 // TODO: update saveLayer info computation to reuse the already comp uted
157 // bounds in 'fBBH' 152 // bounds in 'fBBH'
158 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat a); 153 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat a);
159 } 154 }
160 155
161 size_t subPictureBytes = 0; 156 size_t subPictureBytes = 0;
162 for (int i = 0; pictList && i < pictList->count(); i++) { 157 for (int i = 0; pictList && i < pictList->count(); i++) {
163 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be gin()[i]); 158 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be gin()[i]);
164 } 159 }
165 // SkBigPicture will take ownership of a ref on both fRecord and fBBH. 160 // SkPicture will take ownership of a ref on both fRecord and fBBH.
166 // We're not willing to give up our ownership, so we must ref them for S kPicture. 161 // We're not willing to give up our ownership, so we must ref them for S kPicture.
167 return SkNEW_ARGS(SkBigPicture, (fBounds, 162 return SkNEW_ARGS(SkPicture, (fBounds,
168 SkRef(fRecord.get()), 163 SkRef(fRecord.get()),
169 pictList, 164 pictList,
170 SkSafeRef(fBBH.get()), 165 SkSafeRef(fBBH.get()),
171 saveLayerData.detach(), 166 saveLayerData.detach(),
172 subPictureBytes)); 167 subPictureBytes));
173 } 168 }
174 }; 169 };
175 170
176 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { 171 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() {
177 fActivelyRecording = false; 172 fActivelyRecording = false;
178 fRecorder->flushMiniRecorder();
179 fRecorder->restoreToCount(1); // If we were missing any restores, add them now. 173 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
180
181 // TODO: delay as much of this work until just before first playback? 174 // TODO: delay as much of this work until just before first playback?
182 SkRecordOptimize(fRecord); 175 SkRecordOptimize(fRecord);
183 176
184 if (fBBH.get()) { 177 if (fBBH.get()) {
185 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); 178 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get());
186 } 179 }
187 180
188 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, 181 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable,
189 (fRecord, fBBH, fRecorder->detachDrawabl eList(), 182 (fRecord, fBBH, fRecorder->detachDrawabl eList(),
190 fCullRect, 183 fCullRect,
191 SkToBool(fFlags & kComputeSaveLayerInfo _RecordFlag))); 184 SkToBool(fFlags & kComputeSaveLayerInfo _RecordFlag)));
192 185
193 // release our refs now, so only the drawable will be the owner. 186 // release our refs now, so only the drawable will be the owner.
194 fRecord.reset(NULL); 187 fRecord.reset(NULL);
195 fBBH.reset(NULL); 188 fBBH.reset(NULL);
196 189
197 return drawable; 190 return drawable;
198 } 191 }
OLDNEW
« no previous file with comments | « src/core/SkPictureCommon.h ('k') | src/core/SkRecordDraw.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698