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

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

Issue 1067893002: SkCanvas::resetForNextPicture() (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Return null when we're not recording. Should fix printing failures. Created 5 years, 8 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/SkCanvas.cpp ('k') | src/core/SkRecorder.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 "SkData.h" 8 #include "SkData.h"
9 #include "SkDrawable.h" 9 #include "SkDrawable.h"
10 #include "SkLayerInfo.h" 10 #include "SkLayerInfo.h"
11 #include "SkPictureRecorder.h" 11 #include "SkPictureRecorder.h"
12 #include "SkRecord.h" 12 #include "SkRecord.h"
13 #include "SkRecordDraw.h" 13 #include "SkRecordDraw.h"
14 #include "SkRecorder.h" 14 #include "SkRecorder.h"
15 #include "SkRecordOpts.h" 15 #include "SkRecordOpts.h"
16 #include "SkTypes.h" 16 #include "SkTypes.h"
17 17
18 SkPictureRecorder::SkPictureRecorder() {} 18 SkPictureRecorder::SkPictureRecorder() {
19 fActivelyRecording = false;
20 fRecorder.reset(SkNEW_ARGS(SkRecorder, (nullptr, SkRect::MakeWH(0,0))));
21 }
19 22
20 SkPictureRecorder::~SkPictureRecorder() {} 23 SkPictureRecorder::~SkPictureRecorder() {}
21 24
22 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, 25 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect,
23 SkBBHFactory* bbhFactory /* = NULL * /, 26 SkBBHFactory* bbhFactory /* = NULL * /,
24 uint32_t recordFlags /* = 0 */) { 27 uint32_t recordFlags /* = 0 */) {
25 fCullRect = cullRect; 28 fCullRect = cullRect;
26 fFlags = recordFlags; 29 fFlags = recordFlags;
27 30
28 if (bbhFactory) { 31 if (bbhFactory) {
29 fBBH.reset((*bbhFactory)(cullRect)); 32 fBBH.reset((*bbhFactory)(cullRect));
30 SkASSERT(fBBH.get()); 33 SkASSERT(fBBH.get());
31 } 34 }
32 35
33 fRecord.reset(SkNEW(SkRecord)); 36 fRecord.reset(SkNEW(SkRecord));
34 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), cullRect))); 37 fRecorder->reset(fRecord.get(), cullRect);
38 fActivelyRecording = true;
35 return this->getRecordingCanvas(); 39 return this->getRecordingCanvas();
36 } 40 }
37 41
38 SkCanvas* SkPictureRecorder::getRecordingCanvas() { 42 SkCanvas* SkPictureRecorder::getRecordingCanvas() {
39 return fRecorder.get(); 43 return fActivelyRecording ? fRecorder.get() : nullptr;
40 } 44 }
41 45
42 SkPicture* SkPictureRecorder::endRecordingAsPicture() { 46 SkPicture* SkPictureRecorder::endRecordingAsPicture() {
47 fActivelyRecording = false;
48 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
43 // TODO: delay as much of this work until just before first playback? 49 // TODO: delay as much of this work until just before first playback?
44 SkRecordOptimize(fRecord); 50 SkRecordOptimize(fRecord);
45 51
46 SkAutoTUnref<SkLayerInfo> saveLayerData; 52 SkAutoTUnref<SkLayerInfo> saveLayerData;
47 53
48 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { 54 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) {
49 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); 55 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey();
50 56
51 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); 57 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key)));
52 } 58 }
(...skipping 13 matching lines...) Expand all
66 fCullRect = bbhBound; 72 fCullRect = bbhBound;
67 } 73 }
68 74
69 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord, pictList, fBBH) ); 75 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord, pictList, fBBH) );
70 76
71 if (saveLayerData) { 77 if (saveLayerData) {
72 pict->EXPERIMENTAL_addAccelData(saveLayerData); 78 pict->EXPERIMENTAL_addAccelData(saveLayerData);
73 } 79 }
74 80
75 // release our refs now, so only the picture will be the owner. 81 // release our refs now, so only the picture will be the owner.
76 fRecorder.reset(NULL);
77 fRecord.reset(NULL); 82 fRecord.reset(NULL);
78 fBBH.reset(NULL); 83 fBBH.reset(NULL);
79 84
80 return pict; 85 return pict;
81 } 86 }
82 87
83 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { 88 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
84 if (NULL == canvas) { 89 if (NULL == canvas) {
85 return; 90 return;
86 } 91 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 SkPicture* pict = SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBB H)); 156 SkPicture* pict = SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBB H));
152 157
153 if (saveLayerData) { 158 if (saveLayerData) {
154 pict->EXPERIMENTAL_addAccelData(saveLayerData); 159 pict->EXPERIMENTAL_addAccelData(saveLayerData);
155 } 160 }
156 return pict; 161 return pict;
157 } 162 }
158 }; 163 };
159 164
160 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { 165 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() {
166 fActivelyRecording = false;
167 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
161 // TODO: delay as much of this work until just before first playback? 168 // TODO: delay as much of this work until just before first playback?
162 SkRecordOptimize(fRecord); 169 SkRecordOptimize(fRecord);
163 170
164 if (fBBH.get()) { 171 if (fBBH.get()) {
165 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); 172 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get());
166 } 173 }
167 174
168 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, 175 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable,
169 (fRecord, fBBH, fRecorder->detachDrawabl eList(), 176 (fRecord, fBBH, fRecorder->detachDrawabl eList(),
170 fCullRect, 177 fCullRect,
171 SkToBool(fFlags & kComputeSaveLayerInfo _RecordFlag))); 178 SkToBool(fFlags & kComputeSaveLayerInfo _RecordFlag)));
172 179
173 // release our refs now, so only the drawable will be the owner. 180 // release our refs now, so only the drawable will be the owner.
174 fRecorder.reset(NULL);
175 fRecord.reset(NULL); 181 fRecord.reset(NULL);
176 fBBH.reset(NULL); 182 fBBH.reset(NULL);
177 183
178 return drawable; 184 return drawable;
179 } 185 }
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | src/core/SkRecorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698