OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "VulkanViewer.h" | 8 #include "VulkanViewer.h" |
9 | 9 |
10 #include "GMSlide.h" | 10 #include "GMSlide.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 fWindow->attach(Window::kVulkan_BackendType, 0, nullptr); | 74 fWindow->attach(Window::kVulkan_BackendType, 0, nullptr); |
75 | 75 |
76 // register callbacks | 76 // register callbacks |
77 fWindow->registerKeyFunc(on_key_handler, this); | 77 fWindow->registerKeyFunc(on_key_handler, this); |
78 fWindow->registerCharFunc(on_char_handler, this); | 78 fWindow->registerCharFunc(on_char_handler, this); |
79 fWindow->registerPaintFunc(on_paint_handler, this); | 79 fWindow->registerPaintFunc(on_paint_handler, this); |
80 | 80 |
81 // set up slides | 81 // set up slides |
82 this->initSlides(); | 82 this->initSlides(); |
83 | 83 |
| 84 fAnimTimer.run(); |
| 85 |
84 // set up first frame | 86 // set up first frame |
85 fCurrentSlide = 0; | 87 fCurrentSlide = 0; |
86 setupCurrentSlide(-1); | 88 setupCurrentSlide(-1); |
87 fLocalMatrix.reset(); | 89 updateMatrix(); |
88 | 90 |
89 fWindow->show(); | 91 fWindow->show(); |
90 } | 92 } |
91 | 93 |
92 void VulkanViewer::initSlides() { | 94 void VulkanViewer::initSlides() { |
93 const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head()); | 95 const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head()); |
94 while (gms) { | 96 while (gms) { |
95 SkAutoTDelete<skiagm::GM> gm(gms->factory()(nullptr)); | 97 SkAutoTDelete<skiagm::GM> gm(gms->factory()(nullptr)); |
96 | 98 |
97 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) { | 99 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 if ('s' == c) { | 249 if ('s' == c) { |
248 fDisplayStats = !fDisplayStats; | 250 fDisplayStats = !fDisplayStats; |
249 return true; | 251 return true; |
250 } | 252 } |
251 | 253 |
252 return false; | 254 return false; |
253 } | 255 } |
254 | 256 |
255 void VulkanViewer::onPaint(SkCanvas* canvas) { | 257 void VulkanViewer::onPaint(SkCanvas* canvas) { |
256 | 258 |
| 259 int count = canvas->save(); |
| 260 |
| 261 if (fWindow->supportsContentRect()) { |
| 262 SkRect contentRect = fWindow->getContentRect(); |
| 263 canvas->clipRect(contentRect); |
| 264 canvas->translate(contentRect.fLeft, contentRect.fTop); |
| 265 } |
| 266 |
257 canvas->clear(SK_ColorWHITE); | 267 canvas->clear(SK_ColorWHITE); |
258 | 268 if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) { |
259 int count = canvas->save(); | 269 const SkRect contentRect = fWindow->getContentRect(); |
260 canvas->setMatrix(fLocalMatrix); | 270 const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); |
| 271 const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.
height()); |
| 272 SkMatrix matrix; |
| 273 matrix.setRectToRect(slideBounds, contentRect, SkMatrix::kCenter_ScaleTo
Fit); |
| 274 canvas->concat(matrix); |
| 275 } |
| 276 canvas->concat(fLocalMatrix); |
261 | 277 |
262 fSlides[fCurrentSlide]->draw(canvas); | 278 fSlides[fCurrentSlide]->draw(canvas); |
263 canvas->restoreToCount(count); | 279 canvas->restoreToCount(count); |
264 | 280 |
265 if (fDisplayStats) { | 281 if (fDisplayStats) { |
266 drawStats(canvas); | 282 drawStats(canvas); |
267 } | 283 } |
268 } | 284 } |
269 | 285 |
270 void VulkanViewer::drawStats(SkCanvas* canvas) { | 286 void VulkanViewer::drawStats(SkCanvas* canvas) { |
271 static const float kPixelPerMS = 2.0f; | 287 static const float kPixelPerMS = 2.0f; |
272 static const int kDisplayWidth = 130; | 288 static const int kDisplayWidth = 130; |
273 static const int kDisplayHeight = 100; | 289 static const int kDisplayHeight = 100; |
274 static const int kDisplayPadding = 10; | 290 static const int kDisplayPadding = 10; |
275 static const int kGraphPadding = 3; | 291 static const int kGraphPadding = 3; |
276 static const SkScalar kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps | 292 static const SkScalar kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps |
277 | 293 |
278 SkISize canvasSize = canvas->getDeviceSize(); | 294 SkISize canvasSize = canvas->getDeviceSize(); |
279 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(canvasSize.fWidth-kDisplayWidth
-kDisplayPadding), | 295 SkRect rect = SkRect::MakeXYWH(SkIntToScalar(canvasSize.fWidth-kDisplayWidth
-kDisplayPadding), |
280 SkIntToScalar(kDisplayPadding), | 296 SkIntToScalar(kDisplayPadding), |
281 SkIntToScalar(kDisplayWidth), SkIntToScalar(k
DisplayHeight)); | 297 SkIntToScalar(kDisplayWidth), SkIntToScalar(k
DisplayHeight)); |
282 SkPaint paint; | 298 SkPaint paint; |
283 canvas->save(); | 299 canvas->save(); |
284 | 300 |
| 301 if (fWindow->supportsContentRect()) { |
| 302 SkRect contentRect = fWindow->getContentRect(); |
| 303 canvas->clipRect(contentRect); |
| 304 canvas->translate(contentRect.fLeft, contentRect.fTop); |
| 305 } |
| 306 |
285 canvas->clipRect(rect); | 307 canvas->clipRect(rect); |
286 paint.setColor(SK_ColorBLACK); | 308 paint.setColor(SK_ColorBLACK); |
287 canvas->drawRect(rect, paint); | 309 canvas->drawRect(rect, paint); |
288 // draw the 16ms line | 310 // draw the 16ms line |
289 paint.setColor(SK_ColorLTGRAY); | 311 paint.setColor(SK_ColorLTGRAY); |
290 canvas->drawLine(rect.fLeft, rect.fBottom - kBaseMS*kPixelPerMS, | 312 canvas->drawLine(rect.fLeft, rect.fBottom - kBaseMS*kPixelPerMS, |
291 rect.fRight, rect.fBottom - kBaseMS*kPixelPerMS, paint); | 313 rect.fRight, rect.fBottom - kBaseMS*kPixelPerMS, paint); |
292 paint.setColor(SK_ColorRED); | 314 paint.setColor(SK_ColorRED); |
293 paint.setStyle(SkPaint::kStroke_Style); | 315 paint.setStyle(SkPaint::kStroke_Style); |
294 canvas->drawRect(rect, paint); | 316 canvas->drawRect(rect, paint); |
(...skipping 18 matching lines...) Expand all Loading... |
313 // Record measurements | 335 // Record measurements |
314 fMeasurements[fCurrentMeasurement++] = ms; | 336 fMeasurements[fCurrentMeasurement++] = ms; |
315 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod | 337 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod |
316 SkASSERT(fCurrentMeasurement < kMeasurementCount); | 338 SkASSERT(fCurrentMeasurement < kMeasurementCount); |
317 | 339 |
318 fAnimTimer.updateTime(); | 340 fAnimTimer.updateTime(); |
319 if (fDisplayStats || fSlides[fCurrentSlide]->animate(fAnimTimer)) { | 341 if (fDisplayStats || fSlides[fCurrentSlide]->animate(fAnimTimer)) { |
320 fWindow->inval(); | 342 fWindow->inval(); |
321 } | 343 } |
322 } | 344 } |
OLD | NEW |