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

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

Issue 1112523006: Sketch splitting SkPicture into an interface and SkBigPicture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nullptr 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
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"
8 #include "SkData.h" 9 #include "SkData.h"
9 #include "SkDrawable.h" 10 #include "SkDrawable.h"
10 #include "SkLayerInfo.h" 11 #include "SkLayerInfo.h"
11 #include "SkPictureRecorder.h" 12 #include "SkPictureRecorder.h"
12 #include "SkPictureUtils.h" 13 #include "SkPictureUtils.h"
13 #include "SkRecord.h" 14 #include "SkRecord.h"
14 #include "SkRecordDraw.h" 15 #include "SkRecordDraw.h"
15 #include "SkRecordOpts.h" 16 #include "SkRecordOpts.h"
16 #include "SkRecorder.h" 17 #include "SkRecorder.h"
17 #include "SkTypes.h" 18 #include "SkTypes.h"
(...skipping 28 matching lines...) Expand all
46 47
47 SkPicture* SkPictureRecorder::endRecordingAsPicture() { 48 SkPicture* SkPictureRecorder::endRecordingAsPicture() {
48 fActivelyRecording = false; 49 fActivelyRecording = false;
49 fRecorder->restoreToCount(1); // If we were missing any restores, add them now. 50 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
50 // TODO: delay as much of this work until just before first playback? 51 // TODO: delay as much of this work until just before first playback?
51 SkRecordOptimize(fRecord); 52 SkRecordOptimize(fRecord);
52 53
53 SkAutoTUnref<SkLayerInfo> saveLayerData; 54 SkAutoTUnref<SkLayerInfo> saveLayerData;
54 55
55 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { 56 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) {
56 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); 57 saveLayerData.reset(SkNEW(SkLayerInfo));
57
58 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
59 } 58 }
60 59
61 SkDrawableList* drawableList = fRecorder->getDrawableList(); 60 SkDrawableList* drawableList = fRecorder->getDrawableList();
62 SkPicture::SnapshotArray* pictList = drawableList ? drawableList->newDrawabl eSnapshot() : NULL; 61 SkBigPicture::SnapshotArray* pictList =
62 drawableList ? drawableList->newDrawableSnapshot() : NULL;
63 63
64 if (fBBH.get()) { 64 if (fBBH.get()) {
65 if (saveLayerData) { 65 if (saveLayerData) {
66 SkRecordComputeLayers(fCullRect, *fRecord, pictList, fBBH.get(), sav eLayerData); 66 SkRecordComputeLayers(fCullRect, *fRecord, pictList, fBBH.get(), sav eLayerData);
67 } else { 67 } else {
68 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); 68 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get());
69 } 69 }
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 return SkNEW_ARGS(SkPicture, (fCullRect, 80 return SkNEW_ARGS(SkBigPicture, (fCullRect,
81 fRecord.detach(), 81 fRecord.detach(),
82 pictList, 82 pictList,
83 fBBH.detach(), 83 fBBH.detach(),
84 saveLayerData.detach(), 84 saveLayerData.detach(),
85 subPictureBytes)); 85 subPictureBytes));
86 } 86 }
87 87
88 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { 88 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
89 if (NULL == canvas) { 89 if (NULL == canvas) {
90 return; 90 return;
91 } 91 }
92 92
93 int drawableCount = 0; 93 int drawableCount = 0;
94 SkDrawable* const* drawables = NULL; 94 SkDrawable* const* drawables = NULL;
95 SkDrawableList* drawableList = fRecorder->getDrawableList(); 95 SkDrawableList* drawableList = fRecorder->getDrawableList();
(...skipping 30 matching lines...) Expand all
126 SkDrawable* const* drawables = NULL; 126 SkDrawable* const* drawables = NULL;
127 int drawableCount = 0; 127 int drawableCount = 0;
128 if (fDrawableList) { 128 if (fDrawableList) {
129 drawables = fDrawableList->begin(); 129 drawables = fDrawableList->begin();
130 drawableCount = fDrawableList->count(); 130 drawableCount = fDrawableList->count();
131 } 131 }
132 SkRecordDraw(*fRecord, canvas, NULL, drawables, drawableCount, fBBH, NUL L/*callback*/); 132 SkRecordDraw(*fRecord, canvas, NULL, drawables, drawableCount, fBBH, NUL L/*callback*/);
133 } 133 }
134 134
135 SkPicture* onNewPictureSnapshot() override { 135 SkPicture* onNewPictureSnapshot() override {
136 SkPicture::SnapshotArray* pictList = NULL; 136 SkBigPicture::SnapshotArray* pictList = NULL;
137 if (fDrawableList) { 137 if (fDrawableList) {
138 // 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
139 // PictureRecorder? 139 // PictureRecorder?
140 pictList = fDrawableList->newDrawableSnapshot(); 140 pictList = fDrawableList->newDrawableSnapshot();
141 } 141 }
142 142
143 SkAutoTUnref<SkLayerInfo> saveLayerData; 143 SkAutoTUnref<SkLayerInfo> saveLayerData;
144 144
145 if (fBBH && fDoSaveLayerInfo) { 145 if (fBBH && fDoSaveLayerInfo) {
146 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); 146 saveLayerData.reset(SkNEW(SkLayerInfo));
147
148 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
149 147
150 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece ived in constructor) 148 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece ived in constructor)
151 // TODO: update saveLayer info computation to reuse the already comp uted 149 // TODO: update saveLayer info computation to reuse the already comp uted
152 // bounds in 'fBBH' 150 // bounds in 'fBBH'
153 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat a); 151 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat a);
154 } 152 }
155 153
156 size_t subPictureBytes = 0; 154 size_t subPictureBytes = 0;
157 for (int i = 0; pictList && i < pictList->count(); i++) { 155 for (int i = 0; pictList && i < pictList->count(); i++) {
158 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be gin()[i]); 156 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be gin()[i]);
159 } 157 }
160 // SkPicture will take ownership of a ref on both fRecord and fBBH. 158 // SkBigPicture will take ownership of a ref on both fRecord and fBBH.
161 // We're not willing to give up our ownership, so we must ref them for S kPicture. 159 // We're not willing to give up our ownership, so we must ref them for S kPicture.
162 return SkNEW_ARGS(SkPicture, (fBounds, 160 return SkNEW_ARGS(SkBigPicture, (fBounds,
163 SkRef(fRecord.get()), 161 SkRef(fRecord.get()),
164 pictList, 162 pictList,
165 SkSafeRef(fBBH.get()), 163 SkSafeRef(fBBH.get()),
166 saveLayerData.detach(), 164 saveLayerData.detach(),
167 subPictureBytes)); 165 subPictureBytes));
168 } 166 }
169 }; 167 };
170 168
171 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { 169 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() {
172 fActivelyRecording = false; 170 fActivelyRecording = false;
173 fRecorder->restoreToCount(1); // If we were missing any restores, add them now. 171 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
174 // TODO: delay as much of this work until just before first playback? 172 // TODO: delay as much of this work until just before first playback?
175 SkRecordOptimize(fRecord); 173 SkRecordOptimize(fRecord);
176 174
177 if (fBBH.get()) { 175 if (fBBH.get()) {
178 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); 176 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get());
179 } 177 }
180 178
181 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, 179 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable,
182 (fRecord, fBBH, fRecorder->detachDrawabl eList(), 180 (fRecord, fBBH, fRecorder->detachDrawabl eList(),
183 fCullRect, 181 fCullRect,
184 SkToBool(fFlags & kComputeSaveLayerInfo _RecordFlag))); 182 SkToBool(fFlags & kComputeSaveLayerInfo _RecordFlag)));
185 183
186 // release our refs now, so only the drawable will be the owner. 184 // release our refs now, so only the drawable will be the owner.
187 fRecord.reset(NULL); 185 fRecord.reset(NULL);
188 fBBH.reset(NULL); 186 fBBH.reset(NULL);
189 187
190 return drawable; 188 return drawable;
191 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698