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

Side by Side Diff: samplecode/SamplePicture.cpp

Issue 888283002: allow GMs to animate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: switch all existing animations to use animatePulse Created 5 years, 10 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 | « samplecode/SamplePathEffects.cpp ('k') | samplecode/SampleSpiral.cpp » ('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 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 "gm.h" 8 #include "gm.h"
9 9
10 #include "Resources.h" 10 #include "Resources.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // the other references to fSubPicture 88 // the other references to fSubPicture
89 fSubPicture->unref(); 89 fSubPicture->unref();
90 } 90 }
91 91
92 virtual ~PictureView() { 92 virtual ~PictureView() {
93 fPicture->unref(); 93 fPicture->unref();
94 } 94 }
95 95
96 protected: 96 protected:
97 // overrides from SkEventSink 97 // overrides from SkEventSink
98 virtual bool onQuery(SkEvent* evt) { 98 bool onQuery(SkEvent* evt) SK_OVERRIDE {
99 if (SampleCode::TitleQ(*evt)) { 99 if (SampleCode::TitleQ(*evt)) {
100 SampleCode::TitleR(evt, "Picture"); 100 SampleCode::TitleR(evt, "Picture");
101 return true; 101 return true;
102 } 102 }
103 return this->INHERITED::onQuery(evt); 103 return this->INHERITED::onQuery(evt);
104 } 104 }
105 105
106 void drawSomething(SkCanvas* canvas) { 106 void drawSomething(SkCanvas* canvas) {
107 SkPaint paint; 107 SkPaint paint;
108 108
109 canvas->save(); 109 canvas->save();
110 canvas->scale(0.5f, 0.5f); 110 canvas->scale(0.5f, 0.5f);
111 canvas->drawBitmap(fBitmap, 0, 0, NULL); 111 canvas->drawBitmap(fBitmap, 0, 0, NULL);
112 canvas->restore(); 112 canvas->restore();
113 113
114 paint.setAntiAlias(true); 114 paint.setAntiAlias(true);
115 115
116 paint.setColor(SK_ColorRED); 116 paint.setColor(SK_ColorRED);
117 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), 117 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
118 SkIntToScalar(40), paint); 118 SkIntToScalar(40), paint);
119 paint.setColor(SK_ColorBLACK); 119 paint.setColor(SK_ColorBLACK);
120 paint.setTextSize(SkIntToScalar(40)); 120 paint.setTextSize(SkIntToScalar(40));
121 canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62), 121 canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62),
122 paint); 122 paint);
123 123
124 } 124 }
125 125
126 virtual void onDrawContent(SkCanvas* canvas) { 126 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
127 this->drawSomething(canvas); 127 this->drawSomething(canvas);
128 128
129 SkPictureRecorder recorder; 129 SkPictureRecorder recorder;
130 this->drawSomething(recorder.beginRecording(100, 100, NULL, 0)); 130 this->drawSomething(recorder.beginRecording(100, 100, NULL, 0));
131 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); 131 SkAutoTUnref<SkPicture> pict(recorder.endRecording());
132 132
133 canvas->save(); 133 canvas->save();
134 canvas->translate(SkIntToScalar(300), SkIntToScalar(50)); 134 canvas->translate(SkIntToScalar(300), SkIntToScalar(50));
135 canvas->scale(-SK_Scalar1, -SK_Scalar1); 135 canvas->scale(-SK_Scalar1, -SK_Scalar1);
136 canvas->translate(-SkIntToScalar(100), -SkIntToScalar(50)); 136 canvas->translate(-SkIntToScalar(100), -SkIntToScalar(50));
137 canvas->drawPicture(pict); 137 canvas->drawPicture(pict);
138 canvas->restore(); 138 canvas->restore();
139 139
140 canvas->save(); 140 canvas->save();
141 canvas->translate(SkIntToScalar(200), SkIntToScalar(150)); 141 canvas->translate(SkIntToScalar(200), SkIntToScalar(150));
142 canvas->scale(SK_Scalar1, -SK_Scalar1); 142 canvas->scale(SK_Scalar1, -SK_Scalar1);
143 canvas->translate(0, -SkIntToScalar(50)); 143 canvas->translate(0, -SkIntToScalar(50));
144 canvas->drawPicture(pict); 144 canvas->drawPicture(pict);
145 canvas->restore(); 145 canvas->restore();
146 146
147 canvas->save(); 147 canvas->save();
148 canvas->translate(SkIntToScalar(100), SkIntToScalar(100)); 148 canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
149 canvas->scale(-SK_Scalar1, SK_Scalar1); 149 canvas->scale(-SK_Scalar1, SK_Scalar1);
150 canvas->translate(-SkIntToScalar(100), 0); 150 canvas->translate(-SkIntToScalar(100), 0);
151 canvas->drawPicture(pict); 151 canvas->drawPicture(pict);
152 canvas->restore(); 152 canvas->restore();
153
154 #ifdef SK_DEVELOPER
155 if (false) {
156 SkDebugfDumper dumper;
157 SkDumpCanvas dumpCanvas(&dumper);
158 dumpCanvas.drawPicture(pict);
159 }
160 #endif
161
162 // This used to re-record the sub-picture and redraw the parent
163 // A capability that is now forbidden!
164
165 SkRandom rand(SampleCode::GetAnimTime());
166 canvas->translate(SkIntToScalar(10), SkIntToScalar(250));
167 canvas->drawPicture(fPicture);
168 delayInval(500);
169 } 153 }
170 154
171 private: 155 private:
172 #define INVAL_ALL_TYPE "inval-all" 156 #define INVAL_ALL_TYPE "inval-all"
173 157
174 void delayInval(SkMSec delay) { 158 void delayInval(SkMSec delay) {
175 (new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay); 159 (new SkEvent(INVAL_ALL_TYPE, this->getSinkID()))->postDelay(delay);
176 } 160 }
177 161
178 virtual bool onEvent(const SkEvent& evt) { 162 bool onEvent(const SkEvent& evt) SK_OVERRIDE {
179 if (evt.isType(INVAL_ALL_TYPE)) { 163 if (evt.isType(INVAL_ALL_TYPE)) {
180 this->inval(NULL); 164 this->inval(NULL);
181 return true; 165 return true;
182 } 166 }
183 return this->INHERITED::onEvent(evt); 167 return this->INHERITED::onEvent(evt);
184 } 168 }
185 169
186 SkPicture* fPicture; 170 SkPicture* fPicture;
187 SkPicture* fSubPicture; 171 SkPicture* fSubPicture;
188 172
189 typedef SampleView INHERITED; 173 typedef SampleView INHERITED;
190 }; 174 };
191 175
192 ////////////////////////////////////////////////////////////////////////////// 176 //////////////////////////////////////////////////////////////////////////////
193 177
194 static SkView* MyFactory() { return new PictureView; } 178 static SkView* MyFactory() { return new PictureView; }
195 static SkViewRegister reg(MyFactory); 179 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SamplePathEffects.cpp ('k') | samplecode/SampleSpiral.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698