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

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

Issue 1098183003: Reduce ref counting in SkPictureRecorder. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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/SkPicture.cpp ('k') | no next file » | 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 "SkData.h" 8 #include "SkData.h"
9 #include "SkDrawable.h" 9 #include "SkDrawable.h"
10 #include "SkLayerInfo.h" 10 #include "SkLayerInfo.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 SkRect bbhBound = fBBH->getRootBound(); 70 SkRect bbhBound = fBBH->getRootBound();
71 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) 71 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound))
72 || (bbhBound.isEmpty() && fCullRect.isEmpty())); 72 || (bbhBound.isEmpty() && fCullRect.isEmpty()));
73 fCullRect = bbhBound; 73 fCullRect = bbhBound;
74 } 74 }
75 75
76 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); 76 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures();
77 for (int i = 0; pictList && i < pictList->count(); i++) { 77 for (int i = 0; pictList && i < pictList->count(); i++) {
78 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin( )[i]); 78 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin( )[i]);
79 } 79 }
80 SkPicture* pict = 80 SkPicture* pict = SkNEW_ARGS(SkPicture,
81 SkNEW_ARGS(SkPicture, (fCullRect, fRecord, pictList, fBBH, subPictureByt es)); 81 (fCullRect, fRecord.detach(), pictList, fBBH.detach(), subPictureByt es));
82 82
83 if (saveLayerData) { 83 if (saveLayerData) {
84 pict->EXPERIMENTAL_addAccelData(saveLayerData); 84 pict->EXPERIMENTAL_addAccelData(saveLayerData);
85 } 85 }
86 86
87 // release our refs now, so only the picture will be the owner.
88 fRecord.reset(NULL);
89 fBBH.reset(NULL);
90
91 return pict; 87 return pict;
92 } 88 }
93 89
94 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { 90 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
95 if (NULL == canvas) { 91 if (NULL == canvas) {
96 return; 92 return;
97 } 93 }
98 94
99 int drawableCount = 0; 95 int drawableCount = 0;
100 SkDrawable* const* drawables = NULL; 96 SkDrawable* const* drawables = NULL;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece ived in constructor) 152 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece ived in constructor)
157 // TODO: update saveLayer info computation to reuse the already comp uted 153 // TODO: update saveLayer info computation to reuse the already comp uted
158 // bounds in 'fBBH' 154 // bounds in 'fBBH'
159 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat a); 155 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat a);
160 } 156 }
161 157
162 size_t subPictureBytes = 0; 158 size_t subPictureBytes = 0;
163 for (int i = 0; pictList && i < pictList->count(); i++) { 159 for (int i = 0; pictList && i < pictList->count(); i++) {
164 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be gin()[i]); 160 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be gin()[i]);
165 } 161 }
166 SkPicture* pict = 162 // SkPicture will take ownership of a ref on both fRecord and fBBH.
167 SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBBH, subPictureB ytes)); 163 // We're not willing to give up our ownership, so we must ref them for S kPicture.
164 SkPicture* pict = SkNEW_ARGS(SkPicture,
165 (fBounds, SkRef(fRecord.get()), pictList, SkSafeRef(fBBH.get()), subPictureBytes));
168 166
169 if (saveLayerData) { 167 if (saveLayerData) {
170 pict->EXPERIMENTAL_addAccelData(saveLayerData); 168 pict->EXPERIMENTAL_addAccelData(saveLayerData);
171 } 169 }
172 return pict; 170 return pict;
173 } 171 }
174 }; 172 };
175 173
176 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { 174 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() {
177 fActivelyRecording = false; 175 fActivelyRecording = false;
178 fRecorder->restoreToCount(1); // If we were missing any restores, add them now. 176 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
179 // TODO: delay as much of this work until just before first playback? 177 // TODO: delay as much of this work until just before first playback?
180 SkRecordOptimize(fRecord); 178 SkRecordOptimize(fRecord);
181 179
182 if (fBBH.get()) { 180 if (fBBH.get()) {
183 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); 181 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get());
184 } 182 }
185 183
186 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, 184 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable,
187 (fRecord, fBBH, fRecorder->detachDrawabl eList(), 185 (fRecord, fBBH, fRecorder->detachDrawabl eList(),
188 fCullRect, 186 fCullRect,
189 SkToBool(fFlags & kComputeSaveLayerInfo _RecordFlag))); 187 SkToBool(fFlags & kComputeSaveLayerInfo _RecordFlag)));
190 188
191 // release our refs now, so only the drawable will be the owner. 189 // release our refs now, so only the drawable will be the owner.
192 fRecord.reset(NULL); 190 fRecord.reset(NULL);
193 fBBH.reset(NULL); 191 fBBH.reset(NULL);
194 192
195 return drawable; 193 return drawable;
196 } 194 }
OLDNEW
« no previous file with comments | « src/core/SkPicture.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698