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 "Viewer.h" | 8 #include "Viewer.h" |
9 | 9 |
10 #include "GMSlide.h" | 10 #include "GMSlide.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 fWindow->attach(fBackendType, DisplayParams()); | 76 fWindow->attach(fBackendType, DisplayParams()); |
77 | 77 |
78 // register callbacks | 78 // register callbacks |
79 fCommands.attach(fWindow); | 79 fCommands.attach(fWindow); |
80 fWindow->registerPaintFunc(on_paint_handler, this); | 80 fWindow->registerPaintFunc(on_paint_handler, this); |
81 fWindow->registerTouchFunc(on_touch_handler, this); | 81 fWindow->registerTouchFunc(on_touch_handler, this); |
82 | 82 |
83 // add key-bindings | 83 // add key-bindings |
84 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { | 84 fCommands.addCommand('s', "Overlays", "Toggle stats display", [this]() { |
85 this->fDisplayStats = !this->fDisplayStats; | 85 this->fDisplayStats = !this->fDisplayStats; |
86 fWindow->inval(); | 86 fWindow->invalIfNeeded(); |
87 }); | 87 }); |
88 fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() { | 88 fCommands.addCommand('c', "Modes", "Toggle sRGB color mode", [this]() { |
89 DisplayParams params = fWindow->getDisplayParams(); | 89 DisplayParams params = fWindow->getDisplayParams(); |
90 params.fProfileType = (kLinear_SkColorProfileType == params.fProfileType
) | 90 params.fProfileType = (kLinear_SkColorProfileType == params.fProfileType
) |
91 ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType; | 91 ? kSRGB_SkColorProfileType : kLinear_SkColorProfileType; |
92 fWindow->setDisplayParams(params); | 92 fWindow->setDisplayParams(params); |
93 this->updateTitle(); | 93 this->updateTitle(); |
94 fWindow->inval(); | 94 fWindow->invalIfNeeded(); |
95 }); | 95 }); |
96 fCommands.addCommand(Window::Key::kRight, "Right", "Navigation", "Next slide
", [this]() { | 96 fCommands.addCommand(Window::Key::kRight, "Right", "Navigation", "Next slide
", [this]() { |
97 int previousSlide = fCurrentSlide; | 97 int previousSlide = fCurrentSlide; |
98 fCurrentSlide++; | 98 fCurrentSlide++; |
99 if (fCurrentSlide >= fSlides.count()) { | 99 if (fCurrentSlide >= fSlides.count()) { |
100 fCurrentSlide = 0; | 100 fCurrentSlide = 0; |
101 } | 101 } |
102 this->setupCurrentSlide(previousSlide); | 102 this->setupCurrentSlide(previousSlide); |
103 }); | 103 }); |
104 fCommands.addCommand(Window::Key::kLeft, "Left", "Navigation", "Previous sli
de", [this]() { | 104 fCommands.addCommand(Window::Key::kLeft, "Left", "Navigation", "Previous sli
de", [this]() { |
105 int previousSlide = fCurrentSlide; | 105 int previousSlide = fCurrentSlide; |
106 fCurrentSlide--; | 106 fCurrentSlide--; |
107 if (fCurrentSlide < 0) { | 107 if (fCurrentSlide < 0) { |
108 fCurrentSlide = fSlides.count() - 1; | 108 fCurrentSlide = fSlides.count() - 1; |
109 } | 109 } |
110 this->setupCurrentSlide(previousSlide); | 110 this->setupCurrentSlide(previousSlide); |
111 }); | 111 }); |
112 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this](
) { | 112 fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this](
) { |
113 this->changeZoomLevel(1.f / 32.f); | 113 this->changeZoomLevel(1.f / 32.f); |
114 fWindow->inval(); | 114 fWindow->invalIfNeeded(); |
115 }); | 115 }); |
116 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t
his]() { | 116 fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [t
his]() { |
117 this->changeZoomLevel(-1.f / 32.f); | 117 this->changeZoomLevel(-1.f / 32.f); |
118 fWindow->inval(); | 118 fWindow->invalIfNeeded(); |
119 }); | 119 }); |
120 #ifndef SK_BUILD_FOR_ANDROID | 120 #ifndef SK_BUILD_FOR_ANDROID |
121 fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() { | 121 fCommands.addCommand('d', "Modes", "Change rendering backend", [this]() { |
122 fWindow->detach(); | 122 fWindow->detach(); |
123 | 123 |
124 if (sk_app::Window::kVulkan_BackendType == fBackendType) { | 124 if (sk_app::Window::kVulkan_BackendType == fBackendType) { |
125 fBackendType = sk_app::Window::kNativeGL_BackendType; | 125 fBackendType = sk_app::Window::kNativeGL_BackendType; |
126 } | 126 } |
127 // TODO: get Vulkan -> OpenGL working without swapchain creation failure | 127 // TODO: get Vulkan -> OpenGL working without swapchain creation failure |
128 //else if (sk_app::Window::kNativeGL_BackendType == fBackendType) { | 128 //else if (sk_app::Window::kNativeGL_BackendType == fBackendType) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 SkRect windowRect = fWindow->getContentRect(); | 232 SkRect windowRect = fWindow->getContentRect(); |
233 fDefaultMatrixInv.mapRect(&windowRect); | 233 fDefaultMatrixInv.mapRect(&windowRect); |
234 fGesture.setTransLimit(SkRect::MakeWH(slideSize.width(), slideSize.heigh
t()), windowRect); | 234 fGesture.setTransLimit(SkRect::MakeWH(slideSize.width(), slideSize.heigh
t()), windowRect); |
235 } | 235 } |
236 | 236 |
237 this->updateTitle(); | 237 this->updateTitle(); |
238 fSlides[fCurrentSlide]->load(); | 238 fSlides[fCurrentSlide]->load(); |
239 if (previousSlide >= 0) { | 239 if (previousSlide >= 0) { |
240 fSlides[previousSlide]->unload(); | 240 fSlides[previousSlide]->unload(); |
241 } | 241 } |
242 fWindow->inval(); | 242 fWindow->invalIfNeeded(); |
243 } | 243 } |
244 | 244 |
245 #define MAX_ZOOM_LEVEL 8 | 245 #define MAX_ZOOM_LEVEL 8 |
246 #define MIN_ZOOM_LEVEL -8 | 246 #define MIN_ZOOM_LEVEL -8 |
247 | 247 |
248 void Viewer::changeZoomLevel(float delta) { | 248 void Viewer::changeZoomLevel(float delta) { |
249 fZoomLevel += delta; | 249 fZoomLevel += delta; |
250 if (fZoomLevel > 0) { | 250 if (fZoomLevel > 0) { |
251 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); | 251 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); |
252 fZoomScale = fZoomLevel + SK_Scalar1; | 252 fZoomScale = fZoomLevel + SK_Scalar1; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 312 } |
313 case Window::kDown_InputState: { | 313 case Window::kDown_InputState: { |
314 fGesture.touchBegin(castedOwner, touchPoint.fX, touchPoint.fY); | 314 fGesture.touchBegin(castedOwner, touchPoint.fX, touchPoint.fY); |
315 break; | 315 break; |
316 } | 316 } |
317 case Window::kMove_InputState: { | 317 case Window::kMove_InputState: { |
318 fGesture.touchMoved(castedOwner, touchPoint.fX, touchPoint.fY); | 318 fGesture.touchMoved(castedOwner, touchPoint.fX, touchPoint.fY); |
319 break; | 319 break; |
320 } | 320 } |
321 } | 321 } |
322 fWindow->inval(); | 322 fWindow->invalIfNeeded(); |
323 return true; | 323 return true; |
324 } | 324 } |
325 | 325 |
326 void Viewer::drawStats(SkCanvas* canvas) { | 326 void Viewer::drawStats(SkCanvas* canvas) { |
327 static const float kPixelPerMS = 2.0f; | 327 static const float kPixelPerMS = 2.0f; |
328 static const int kDisplayWidth = 130; | 328 static const int kDisplayWidth = 130; |
329 static const int kDisplayHeight = 100; | 329 static const int kDisplayHeight = 100; |
330 static const int kDisplayPadding = 10; | 330 static const int kDisplayPadding = 10; |
331 static const int kGraphPadding = 3; | 331 static const int kGraphPadding = 3; |
332 static const SkScalar kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps | 332 static const SkScalar kBaseMS = 1000.f / 60.f; // ms/frame to hit 60 fps |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 372 } |
373 | 373 |
374 void Viewer::onIdle(double ms) { | 374 void Viewer::onIdle(double ms) { |
375 // Record measurements | 375 // Record measurements |
376 fMeasurements[fCurrentMeasurement++] = ms; | 376 fMeasurements[fCurrentMeasurement++] = ms; |
377 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod | 377 fCurrentMeasurement &= (kMeasurementCount - 1); // fast mod |
378 SkASSERT(fCurrentMeasurement < kMeasurementCount); | 378 SkASSERT(fCurrentMeasurement < kMeasurementCount); |
379 | 379 |
380 fAnimTimer.updateTime(); | 380 fAnimTimer.updateTime(); |
381 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { | 381 if (fSlides[fCurrentSlide]->animate(fAnimTimer) || fDisplayStats) { |
382 fWindow->inval(); | 382 fWindow->invalIfNeeded(); |
383 } | 383 } |
384 } | 384 } |
OLD | NEW |