OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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" |
11 #include "SampleCode.h" | 11 #include "SampleCode.h" |
| 12 #include "SkAnimTimer.h" |
12 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
13 #include "SkInterpolator.h" | 14 #include "SkInterpolator.h" |
14 #include "SkSurface.h" | 15 #include "SkSurface.h" |
15 #include "SkRandom.h" | 16 #include "SkRandom.h" |
16 #include "SkTime.h" | 17 #include "SkTime.h" |
17 | 18 |
18 static SkSurface* make_surface(SkCanvas* canvas, const SkImageInfo& info) { | 19 static SkSurface* make_surface(SkCanvas* canvas, const SkImageInfo& info) { |
19 SkSurface* surface = canvas->newSurface(info); | 20 SkSurface* surface = canvas->newSurface(info); |
20 if (!surface) { | 21 if (!surface) { |
21 surface = SkSurface::NewRaster(info); | 22 surface = SkSurface::NewRaster(info); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 canvas->drawRect(r, p); | 125 canvas->drawRect(r, p); |
125 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), p); | 126 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), p); |
126 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), p); | 127 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), p); |
127 } | 128 } |
128 | 129 |
129 class FilterQualityView : public SampleView { | 130 class FilterQualityView : public SampleView { |
130 SkAutoTUnref<SkImage> fImage; | 131 SkAutoTUnref<SkImage> fImage; |
131 AnimValue fScale, fAngle; | 132 AnimValue fScale, fAngle; |
132 SkSize fCell; | 133 SkSize fCell; |
133 SkInterpolator fTrans; | 134 SkInterpolator fTrans; |
| 135 SkMSec fCurrTime; |
134 bool fShowFatBits; | 136 bool fShowFatBits; |
135 | 137 |
136 public: | 138 public: |
137 FilterQualityView() : fImage(make_image()), fTrans(2, 2), fShowFatBits(true)
{ | 139 FilterQualityView() : fImage(make_image()), fTrans(2, 2), fShowFatBits(true)
{ |
138 fCell.set(256, 256); | 140 fCell.set(256, 256); |
139 | 141 |
140 fScale.set(1, SK_Scalar1 / 8, 1); | 142 fScale.set(1, SK_Scalar1 / 8, 1); |
141 fAngle.setMod(0, 360); | 143 fAngle.setMod(0, 360); |
142 | 144 |
143 SkScalar values[2]; | 145 SkScalar values[2]; |
144 fTrans.setMirror(true); | 146 fTrans.setMirror(true); |
145 fTrans.setReset(true); | 147 fTrans.setReset(true); |
146 | 148 |
| 149 fCurrTime = 0; |
| 150 |
147 fTrans.setRepeatCount(999); | 151 fTrans.setRepeatCount(999); |
148 values[0] = values[1] = 0; | 152 values[0] = values[1] = 0; |
149 fTrans.setKeyFrame(0, SkTime::GetMSecs(), values); | 153 fTrans.setKeyFrame(0, fCurrTime, values); |
150 values[0] = values[1] = 1; | 154 values[0] = values[1] = 1; |
151 fTrans.setKeyFrame(1, SkTime::GetMSecs() + 2000, values); | 155 fTrans.setKeyFrame(1, fCurrTime + 2000, values); |
152 } | 156 } |
153 | 157 |
154 protected: | 158 protected: |
155 bool onQuery(SkEvent* evt) SK_OVERRIDE { | 159 bool onQuery(SkEvent* evt) SK_OVERRIDE { |
156 if (SampleCode::TitleQ(*evt)) { | 160 if (SampleCode::TitleQ(*evt)) { |
157 SampleCode::TitleR(evt, "FilterQuality"); | 161 SampleCode::TitleR(evt, "FilterQuality"); |
158 return true; | 162 return true; |
159 } | 163 } |
160 SkUnichar uni; | 164 SkUnichar uni; |
161 if (SampleCode::CharQ(*evt, &uni)) { | 165 if (SampleCode::CharQ(*evt, &uni)) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 r.inset(SK_ScalarHalf, SK_ScalarHalf); | 236 r.inset(SK_ScalarHalf, SK_ScalarHalf); |
233 canvas->drawRect(r, p); | 237 canvas->drawRect(r, p); |
234 canvas->drawLine(r.left(), r.centerY(), r.right(), r.centerY(), p); | 238 canvas->drawLine(r.left(), r.centerY(), r.right(), r.centerY(), p); |
235 canvas->drawLine(r.centerX(), r.top(), r.centerX(), r.bottom(), p); | 239 canvas->drawLine(r.centerX(), r.top(), r.centerX(), r.bottom(), p); |
236 } | 240 } |
237 | 241 |
238 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 242 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
239 fCell.set(this->height() / 2, this->height() / 2); | 243 fCell.set(this->height() / 2, this->height() / 2); |
240 | 244 |
241 SkScalar trans[2]; | 245 SkScalar trans[2]; |
242 fTrans.timeToValues(SkTime::GetMSecs(), trans); | 246 fTrans.timeToValues(fCurrTime, trans); |
243 | 247 |
244 for (int y = 0; y < 2; ++y) { | 248 for (int y = 0; y < 2; ++y) { |
245 for (int x = 0; x < 2; ++x) { | 249 for (int x = 0; x < 2; ++x) { |
246 int index = y * 2 + x; | 250 int index = y * 2 + x; |
247 SkAutoCanvasRestore acr(canvas, true); | 251 SkAutoCanvasRestore acr(canvas, true); |
248 canvas->translate(fCell.width() * x, fCell.height() * y); | 252 canvas->translate(fCell.width() * x, fCell.height() * y); |
249 SkRect r = SkRect::MakeWH(fCell.width(), fCell.height()); | 253 SkRect r = SkRect::MakeWH(fCell.width(), fCell.height()); |
250 r.inset(4, 4); | 254 r.inset(4, 4); |
251 canvas->clipRect(r); | 255 canvas->clipRect(r); |
252 this->drawHere(canvas, SkPaint::FilterLevel(index), trans[0], tr
ans[1]); | 256 this->drawHere(canvas, SkPaint::FilterLevel(index), trans[0], tr
ans[1]); |
(...skipping 10 matching lines...) Expand all Loading... |
263 SkString str; | 267 SkString str; |
264 str.appendScalar(fScale); | 268 str.appendScalar(fScale); |
265 canvas->drawText(str.c_str(), str.size(), textX, 100, paint); | 269 canvas->drawText(str.c_str(), str.size(), textX, 100, paint); |
266 str.reset(); str.appendScalar(fAngle); | 270 str.reset(); str.appendScalar(fAngle); |
267 canvas->drawText(str.c_str(), str.size(), textX, 150, paint); | 271 canvas->drawText(str.c_str(), str.size(), textX, 150, paint); |
268 | 272 |
269 str.reset(); str.appendScalar(trans[0]); | 273 str.reset(); str.appendScalar(trans[0]); |
270 canvas->drawText(str.c_str(), str.size(), textX, 200, paint); | 274 canvas->drawText(str.c_str(), str.size(), textX, 200, paint); |
271 str.reset(); str.appendScalar(trans[1]); | 275 str.reset(); str.appendScalar(trans[1]); |
272 canvas->drawText(str.c_str(), str.size(), textX, 250, paint); | 276 canvas->drawText(str.c_str(), str.size(), textX, 250, paint); |
| 277 } |
273 | 278 |
274 this->inval(NULL); | 279 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { |
| 280 fCurrTime = timer.msec(); |
| 281 return true; |
275 } | 282 } |
276 | 283 |
277 virtual bool handleKey(SkKey key) { | 284 virtual bool handleKey(SkKey key) { |
278 this->inval(NULL); | 285 this->inval(NULL); |
279 return true; | 286 return true; |
280 } | 287 } |
281 | 288 |
282 private: | 289 private: |
283 typedef SampleView INHERITED; | 290 typedef SampleView INHERITED; |
284 }; | 291 }; |
285 | 292 |
286 ////////////////////////////////////////////////////////////////////////////// | 293 ////////////////////////////////////////////////////////////////////////////// |
287 | 294 |
288 static SkView* MyFactory() { return new FilterQualityView; } | 295 static SkView* MyFactory() { return new FilterQualityView; } |
289 static SkViewRegister reg(MyFactory); | 296 static SkViewRegister reg(MyFactory); |
OLD | NEW |