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

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

Issue 344253005: Use smart pointers to make SkPictureRecorder lifetimes less manual. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: record Created 6 years, 6 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 | « include/core/SkPictureRecorder.h ('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 "SkBBoxHierarchyRecord.h" 8 #include "SkBBoxHierarchyRecord.h"
9 #include "SkPicturePlayback.h" 9 #include "SkPicturePlayback.h"
10 #include "SkPictureRecord.h" 10 #include "SkPictureRecord.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 "SkTypes.h" 15 #include "SkTypes.h"
16 16
17 SkPictureRecorder::~SkPictureRecorder() { 17 SkPictureRecorder::SkPictureRecorder() {}
18 this->reset();
19 }
20 18
21 void SkPictureRecorder::reset() { 19 SkPictureRecorder::~SkPictureRecorder() {}
22 SkSafeSetNull(fPictureRecord);
23 SkSafeSetNull(fRecorder);
24 SkDELETE(fRecord);
25 fRecord = NULL;
26 }
27 20
28 SkCanvas* SkPictureRecorder::beginRecording(int width, int height, 21 SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
29 SkBBHFactory* bbhFactory /* = NULL * /, 22 SkBBHFactory* bbhFactory /* = NULL * /,
30 uint32_t recordFlags /* = 0 */) { 23 uint32_t recordFlags /* = 0 */) {
31 this->reset(); // terminate any prior recording(s)
32 fWidth = width; 24 fWidth = width;
33 fHeight = height; 25 fHeight = height;
34 26
35 const SkISize size = SkISize::Make(width, height); 27 const SkISize size = SkISize::Make(width, height);
36 28
37 if (NULL != bbhFactory) { 29 if (NULL != bbhFactory) {
38 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height)); 30 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height));
39 SkASSERT(NULL != tree); 31 SkASSERT(NULL != tree);
40 fPictureRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, t ree.get())); 32 fPictureRecord.reset(SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlag s, tree.get())));
41 } else { 33 } else {
42 fPictureRecord = SkNEW_ARGS(SkPictureRecord, (size, recordFlags)); 34 fPictureRecord.reset(SkNEW_ARGS(SkPictureRecord, (size, recordFlags)));
43 } 35 }
44 36
45 fPictureRecord->beginRecording(); 37 fPictureRecord->beginRecording();
46 return this->getRecordingCanvas(); 38 return this->getRecordingCanvas();
47 } 39 }
48 40
49 SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height, 41 SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height,
50 SkBBHFactory* bbhFactor y /* = NULL */) { 42 SkBBHFactory* bbhFactor y /* = NULL */) {
51 this->reset();
52 fWidth = width; 43 fWidth = width;
53 fHeight = height; 44 fHeight = height;
54 45
55 // TODO: plumb bbhFactory through 46 // TODO: plumb bbhFactory through
56 fRecord = SkNEW(SkRecord); 47 fRecord.reset(SkNEW(SkRecord));
57 fRecorder = SkNEW_ARGS(SkRecorder, (fRecord, width, height)); 48 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), width, height)));
58 return this->getRecordingCanvas(); 49 return this->getRecordingCanvas();
59 } 50 }
60 51
61 SkCanvas* SkPictureRecorder::getRecordingCanvas() { 52 SkCanvas* SkPictureRecorder::getRecordingCanvas() {
62 if (NULL != fRecorder) { 53 if (NULL != fRecorder.get()) {
63 return fRecorder; 54 return fRecorder.get();
64 } 55 }
65 return fPictureRecord; 56 return fPictureRecord.get();
66 } 57 }
67 58
68 SkPicture* SkPictureRecorder::endRecording() { 59 SkPicture* SkPictureRecorder::endRecording() {
69 SkPicture* picture = NULL; 60 SkPicture* picture = NULL;
70 61
71 if (NULL != fRecorder) { 62 if (NULL != fRecord.get()) {
72 // TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord)); 63 // TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord.detac h()));
73 // fRecord = NULL;
74 } 64 }
75 65
76 if (NULL != fPictureRecord) { 66 if (NULL != fPictureRecord.get()) {
77 fPictureRecord->endRecording(); 67 fPictureRecord->endRecording();
78 const bool deepCopyOps = false; 68 const bool deepCopyOps = false;
79 picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord, deepC opyOps)); 69 picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord.get(), deepCopyOps));
80 } 70 }
81 71
82 this->reset();
83 return picture; 72 return picture;
84 } 73 }
85 74
86 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) { 75 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) {
87 if (NULL != fPictureRecord) { 76 if (NULL != fPictureRecord.get()) {
88 fPictureRecord->internalOnly_EnableOpts(enableOpts); 77 fPictureRecord->internalOnly_EnableOpts(enableOpts);
89 } 78 }
90 } 79 }
91 80
92 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { 81 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
93 if (NULL == canvas) { 82 if (NULL == canvas) {
94 return; 83 return;
95 } 84 }
96 85
97 if (NULL != fRecorder) { 86 if (NULL != fRecord.get()) {
98 SkRecordDraw(*fRecord, canvas); 87 SkRecordDraw(*fRecord, canvas);
99 } 88 }
100 89
101 if (NULL != fPictureRecord) { 90 if (NULL != fPictureRecord.get()) {
102 const bool deepCopyOps = true; 91 const bool deepCopyOps = true;
103 SkPicture picture(fWidth, fHeight, *fPictureRecord, deepCopyOps); 92 SkPicture picture(fWidth, fHeight, *fPictureRecord.get(), deepCopyOps);
104 picture.draw(canvas); 93 picture.draw(canvas);
105 } 94 }
106 } 95 }
OLDNEW
« no previous file with comments | « include/core/SkPictureRecorder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698