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

Side by Side Diff: samplecode/SamplePicture.cpp

Issue 214953003: split SkPictureRecorder out of SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT (again) Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDecodingImageGenerator.h" 10 #include "SkDecodingImageGenerator.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 paint); 54 paint);
55 } 55 }
56 56
57 class PictureView : public SampleView { 57 class PictureView : public SampleView {
58 SkBitmap fBitmap; 58 SkBitmap fBitmap;
59 public: 59 public:
60 PictureView() { 60 PictureView() {
61 61
62 fBitmap = load_bitmap(); 62 fBitmap = load_bitmap();
63 63
64 fPicture = new SkPicture; 64 SkPictureRecorder recorder;
65 SkCanvas* canvas = fPicture->beginRecording(100, 100); 65
66 recorder.beginRecording(100, 100);
67 fSubPicture = recorder.endRecording();
68
69 SkCanvas* canvas = recorder.beginRecording(100, 100);
66 SkPaint paint; 70 SkPaint paint;
67 paint.setAntiAlias(true); 71 paint.setAntiAlias(true);
68 72
69 canvas->drawBitmap(fBitmap, 0, 0, NULL); 73 canvas->drawBitmap(fBitmap, 0, 0, NULL);
70 74
71 drawCircle(canvas, 50, SK_ColorBLACK); 75 drawCircle(canvas, 50, SK_ColorBLACK);
72 fSubPicture = new SkPicture;
73 canvas->drawPicture(*fSubPicture); 76 canvas->drawPicture(*fSubPicture);
74 canvas->translate(SkIntToScalar(50), 0); 77 canvas->translate(SkIntToScalar(50), 0);
75 canvas->drawPicture(*fSubPicture); 78 canvas->drawPicture(*fSubPicture);
76 canvas->translate(0, SkIntToScalar(50)); 79 canvas->translate(0, SkIntToScalar(50));
77 canvas->drawPicture(*fSubPicture); 80 canvas->drawPicture(*fSubPicture);
78 canvas->translate(SkIntToScalar(-50), 0); 81 canvas->translate(SkIntToScalar(-50), 0);
79 canvas->drawPicture(*fSubPicture); 82 canvas->drawPicture(*fSubPicture);
80 // fPicture now has (4) references to us. We can release ours, and just 83
81 // unref fPicture in our destructor, and it will in turn take care of 84 fPicture = recorder.endRecording();
85
86 // fPicture now has (4) references to fSubPicture. We can release our re f,
87 // and just unref fPicture in our destructor, and it will in turn take c are of
82 // the other references to fSubPicture 88 // the other references to fSubPicture
83 fSubPicture->unref(); 89 fSubPicture->unref();
84 } 90 }
85 91
86 virtual ~PictureView() { 92 virtual ~PictureView() {
87 fPicture->unref(); 93 fPicture->unref();
88 } 94 }
89 95
90 protected: 96 protected:
91 // overrides from SkEventSink 97 // overrides from SkEventSink
(...skipping 24 matching lines...) Expand all
116 SkIntToScalar(40), paint); 122 SkIntToScalar(40), paint);
117 canvas->drawData(afterStr, sizeof(afterStr)); 123 canvas->drawData(afterStr, sizeof(afterStr));
118 paint.setColor(SK_ColorBLACK); 124 paint.setColor(SK_ColorBLACK);
119 paint.setTextSize(SkIntToScalar(40)); 125 paint.setTextSize(SkIntToScalar(40));
120 canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62), 126 canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62),
121 paint); 127 paint);
122 128
123 } 129 }
124 130
125 virtual void onDrawContent(SkCanvas* canvas) { 131 virtual void onDrawContent(SkCanvas* canvas) {
126 drawSomething(canvas); 132 this->drawSomething(canvas);
127 133
128 SkPicture* pict = new SkPicture; 134 SkPictureRecorder recorder;
129 SkAutoUnref aur(pict); 135 this->drawSomething(recorder.beginRecording(100, 100));
130 136 SkAutoTUnref<SkPicture> pict(recorder.endRecording());
131 drawSomething(pict->beginRecording(100, 100));
132 pict->endRecording();
133 137
134 canvas->save(); 138 canvas->save();
135 canvas->translate(SkIntToScalar(300), SkIntToScalar(50)); 139 canvas->translate(SkIntToScalar(300), SkIntToScalar(50));
136 canvas->scale(-SK_Scalar1, -SK_Scalar1); 140 canvas->scale(-SK_Scalar1, -SK_Scalar1);
137 canvas->translate(-SkIntToScalar(100), -SkIntToScalar(50)); 141 canvas->translate(-SkIntToScalar(100), -SkIntToScalar(50));
138 canvas->drawPicture(*pict); 142 canvas->drawPicture(*pict);
139 canvas->restore(); 143 canvas->restore();
140 144
141 canvas->save(); 145 canvas->save();
142 canvas->translate(SkIntToScalar(200), SkIntToScalar(150)); 146 canvas->translate(SkIntToScalar(200), SkIntToScalar(150));
(...skipping 10 matching lines...) Expand all
153 canvas->restore(); 157 canvas->restore();
154 158
155 #ifdef SK_DEVELOPER 159 #ifdef SK_DEVELOPER
156 if (false) { 160 if (false) {
157 SkDebugfDumper dumper; 161 SkDebugfDumper dumper;
158 SkDumpCanvas dumpCanvas(&dumper); 162 SkDumpCanvas dumpCanvas(&dumper);
159 dumpCanvas.drawPicture(*pict); 163 dumpCanvas.drawPicture(*pict);
160 } 164 }
161 #endif 165 #endif
162 166
163 // test that we can re-record a subpicture, and see the results 167 // This used to re-record the sub-picture and redraw the parent
168 // A capability that is now forbidden!
164 169
165 SkRandom rand(SampleCode::GetAnimTime()); 170 SkRandom rand(SampleCode::GetAnimTime());
166 canvas->translate(SkIntToScalar(10), SkIntToScalar(250)); 171 canvas->translate(SkIntToScalar(10), SkIntToScalar(250));
167 drawCircle(fSubPicture->beginRecording(50, 50), 25,
168 rand.nextU() | 0xFF000000);
169 canvas->drawPicture(*fPicture); 172 canvas->drawPicture(*fPicture);
170 delayInval(500); 173 delayInval(500);
171 } 174 }
172 175
173 private: 176 private:
174 #define INVAL_ALL_TYPE "inval-all" 177 #define INVAL_ALL_TYPE "inval-all"
175 178
176 void delayInval(SkMSec delay) { 179 void delayInval(SkMSec delay) {
177 (new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay); 180 (new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay);
178 } 181 }
179 182
180 virtual bool onEvent(const SkEvent& evt) { 183 virtual bool onEvent(const SkEvent& evt) {
181 if (evt.isType(INVAL_ALL_TYPE)) { 184 if (evt.isType(INVAL_ALL_TYPE)) {
182 this->inval(NULL); 185 this->inval(NULL);
183 return true; 186 return true;
184 } 187 }
185 return this->INHERITED::onEvent(evt); 188 return this->INHERITED::onEvent(evt);
186 } 189 }
187 190
188 SkPicture* fPicture; 191 SkPicture* fPicture;
189 SkPicture* fSubPicture; 192 SkPicture* fSubPicture;
190 193
191 typedef SampleView INHERITED; 194 typedef SampleView INHERITED;
192 }; 195 };
193 196
194 ////////////////////////////////////////////////////////////////////////////// 197 //////////////////////////////////////////////////////////////////////////////
195 198
196 static SkView* MyFactory() { return new PictureView; } 199 static SkView* MyFactory() { return new PictureView; }
197 static SkViewRegister reg(MyFactory); 200 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698