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

Side by Side Diff: samplecode/SamplePicture.cpp

Issue 313613004: Alter SkCanvas::drawPicture (devirtualize, take const SkPicture, take pointer) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add staging entry point for Chromium and Android 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
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 recorder.beginRecording(100, 100, NULL, 0); 67 recorder.beginRecording(100, 100, NULL, 0);
68 fSubPicture = recorder.endRecording(); 68 fSubPicture = recorder.endRecording();
69 69
70 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0); 70 SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0);
71 SkPaint paint; 71 SkPaint paint;
72 paint.setAntiAlias(true); 72 paint.setAntiAlias(true);
73 73
74 canvas->drawBitmap(fBitmap, 0, 0, NULL); 74 canvas->drawBitmap(fBitmap, 0, 0, NULL);
75 75
76 drawCircle(canvas, 50, SK_ColorBLACK); 76 drawCircle(canvas, 50, SK_ColorBLACK);
77 canvas->drawPicture(*fSubPicture); 77 canvas->drawPicture(fSubPicture);
78 canvas->translate(SkIntToScalar(50), 0); 78 canvas->translate(SkIntToScalar(50), 0);
79 canvas->drawPicture(*fSubPicture); 79 canvas->drawPicture(fSubPicture);
80 canvas->translate(0, SkIntToScalar(50)); 80 canvas->translate(0, SkIntToScalar(50));
81 canvas->drawPicture(*fSubPicture); 81 canvas->drawPicture(fSubPicture);
82 canvas->translate(SkIntToScalar(-50), 0); 82 canvas->translate(SkIntToScalar(-50), 0);
83 canvas->drawPicture(*fSubPicture); 83 canvas->drawPicture(fSubPicture);
84 84
85 fPicture = recorder.endRecording(); 85 fPicture = recorder.endRecording();
86 86
87 // fPicture now has (4) references to fSubPicture. We can release our re f, 87 // fPicture now has (4) references to fSubPicture. We can release our re f,
88 // and just unref fPicture in our destructor, and it will in turn take c are of 88 // and just unref fPicture in our destructor, and it will in turn take c are of
89 // the other references to fSubPicture 89 // the other references to fSubPicture
90 fSubPicture->unref(); 90 fSubPicture->unref();
91 } 91 }
92 92
93 virtual ~PictureView() { 93 virtual ~PictureView() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 this->drawSomething(canvas); 133 this->drawSomething(canvas);
134 134
135 SkPictureRecorder recorder; 135 SkPictureRecorder recorder;
136 this->drawSomething(recorder.beginRecording(100, 100, NULL, 0)); 136 this->drawSomething(recorder.beginRecording(100, 100, NULL, 0));
137 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); 137 SkAutoTUnref<SkPicture> pict(recorder.endRecording());
138 138
139 canvas->save(); 139 canvas->save();
140 canvas->translate(SkIntToScalar(300), SkIntToScalar(50)); 140 canvas->translate(SkIntToScalar(300), SkIntToScalar(50));
141 canvas->scale(-SK_Scalar1, -SK_Scalar1); 141 canvas->scale(-SK_Scalar1, -SK_Scalar1);
142 canvas->translate(-SkIntToScalar(100), -SkIntToScalar(50)); 142 canvas->translate(-SkIntToScalar(100), -SkIntToScalar(50));
143 canvas->drawPicture(*pict); 143 canvas->drawPicture(pict);
144 canvas->restore(); 144 canvas->restore();
145 145
146 canvas->save(); 146 canvas->save();
147 canvas->translate(SkIntToScalar(200), SkIntToScalar(150)); 147 canvas->translate(SkIntToScalar(200), SkIntToScalar(150));
148 canvas->scale(SK_Scalar1, -SK_Scalar1); 148 canvas->scale(SK_Scalar1, -SK_Scalar1);
149 canvas->translate(0, -SkIntToScalar(50)); 149 canvas->translate(0, -SkIntToScalar(50));
150 canvas->drawPicture(*pict); 150 canvas->drawPicture(pict);
151 canvas->restore(); 151 canvas->restore();
152 152
153 canvas->save(); 153 canvas->save();
154 canvas->translate(SkIntToScalar(100), SkIntToScalar(100)); 154 canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
155 canvas->scale(-SK_Scalar1, SK_Scalar1); 155 canvas->scale(-SK_Scalar1, SK_Scalar1);
156 canvas->translate(-SkIntToScalar(100), 0); 156 canvas->translate(-SkIntToScalar(100), 0);
157 canvas->drawPicture(*pict); 157 canvas->drawPicture(pict);
158 canvas->restore(); 158 canvas->restore();
159 159
160 #ifdef SK_DEVELOPER 160 #ifdef SK_DEVELOPER
161 if (false) { 161 if (false) {
162 SkDebugfDumper dumper; 162 SkDebugfDumper dumper;
163 SkDumpCanvas dumpCanvas(&dumper); 163 SkDumpCanvas dumpCanvas(&dumper);
164 dumpCanvas.drawPicture(*pict); 164 dumpCanvas.drawPicture(pict);
165 } 165 }
166 #endif 166 #endif
167 167
168 // This used to re-record the sub-picture and redraw the parent 168 // This used to re-record the sub-picture and redraw the parent
169 // A capability that is now forbidden! 169 // A capability that is now forbidden!
170 170
171 SkRandom rand(SampleCode::GetAnimTime()); 171 SkRandom rand(SampleCode::GetAnimTime());
172 canvas->translate(SkIntToScalar(10), SkIntToScalar(250)); 172 canvas->translate(SkIntToScalar(10), SkIntToScalar(250));
173 canvas->drawPicture(*fPicture); 173 canvas->drawPicture(fPicture);
174 delayInval(500); 174 delayInval(500);
175 } 175 }
176 176
177 private: 177 private:
178 #define INVAL_ALL_TYPE "inval-all" 178 #define INVAL_ALL_TYPE "inval-all"
179 179
180 void delayInval(SkMSec delay) { 180 void delayInval(SkMSec delay) {
181 (new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay); 181 (new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay);
182 } 182 }
183 183
184 virtual bool onEvent(const SkEvent& evt) { 184 virtual bool onEvent(const SkEvent& evt) {
185 if (evt.isType(INVAL_ALL_TYPE)) { 185 if (evt.isType(INVAL_ALL_TYPE)) {
186 this->inval(NULL); 186 this->inval(NULL);
187 return true; 187 return true;
188 } 188 }
189 return this->INHERITED::onEvent(evt); 189 return this->INHERITED::onEvent(evt);
190 } 190 }
191 191
192 SkPicture* fPicture; 192 SkPicture* fPicture;
193 SkPicture* fSubPicture; 193 SkPicture* fSubPicture;
194 194
195 typedef SampleView INHERITED; 195 typedef SampleView INHERITED;
196 }; 196 };
197 197
198 ////////////////////////////////////////////////////////////////////////////// 198 //////////////////////////////////////////////////////////////////////////////
199 199
200 static SkView* MyFactory() { return new PictureView; } 200 static SkView* MyFactory() { return new PictureView; }
201 static SkViewRegister reg(MyFactory); 201 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698