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

Side by Side Diff: tools/vulkan/viewer/VulkanViewer.cpp

Issue 1865553005: Clean up input handling in VulkanViewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rename resize params Created 4 years, 8 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 | « tools/vulkan/viewer/VulkanViewer.h ('k') | tools/vulkan/win/Window_win.h » ('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 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 "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkRandom.h" 11 #include "SkRandom.h"
12 #include "SkCommonFlags.h" 12 #include "SkCommonFlags.h"
13 13
14 DEFINE_string(key, "", 14 DEFINE_string(key, "",
15 "Space-separated key/value pairs to add to JSON identifying this b uilder."); 15 "Space-separated key/value pairs to add to JSON identifying this b uilder.");
16 16
17 Application* Application::Create(int argc, char** argv, void* platformData) { 17 Application* Application::Create(int argc, char** argv, void* platformData) {
18 return new VulkanViewer(argc, argv, platformData); 18 return new VulkanViewer(argc, argv, platformData);
19 } 19 }
20 20
21 static bool on_key_handler(int key, bool keyDown, void* userData) { 21 static bool on_key_handler(Window::Key key, Window::InputState state, uint32_t m odifiers,
22 void* userData) {
22 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData); 23 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
23 24
24 return vv->onKey(key, keyDown); 25 return vv->onKey(key, state, modifiers);
25 }
26
27 static bool on_mouse_handler(int x, int y, bool mouseDown, void* userData) {
28 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
29
30 return vv->onMouse(x, y, mouseDown);
31 } 26 }
32 27
33 static void on_paint_handler(SkCanvas* canvas, void* userData) { 28 static void on_paint_handler(SkCanvas* canvas, void* userData) {
34 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData); 29 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData);
35 30
36 return vv->onPaint(canvas); 31 return vv->onPaint(canvas);
37 } 32 }
38 33
39 VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) : 34 VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) :
40 fGMs(skiagm::GMRegistry::Head()){ 35 fGMs(skiagm::GMRegistry::Head()){
41 36
42 fWindow = Window::CreateNativeWindow(platformData); 37 fWindow = Window::CreateNativeWindow(platformData);
43 fWindow->attach(Window::kVulkan_BackendType, 0, nullptr); 38 fWindow->attach(Window::kVulkan_BackendType, 0, nullptr);
44 39
45 // register callbacks 40 // register callbacks
46 fWindow->registerKeyFunc(on_key_handler, this); 41 fWindow->registerKeyFunc(on_key_handler, this);
47 fWindow->registerMouseFunc(on_mouse_handler, this);
48 fWindow->registerPaintFunc(on_paint_handler, this); 42 fWindow->registerPaintFunc(on_paint_handler, this);
49 43
50 fWindow->setTitle("VulkanViewer"); 44 fWindow->setTitle("VulkanViewer");
51 fWindow->show(); 45 fWindow->show();
52 } 46 }
53 47
54 VulkanViewer::~VulkanViewer() { 48 VulkanViewer::~VulkanViewer() {
55 fWindow->detach(); 49 fWindow->detach();
56 delete fWindow; 50 delete fWindow;
57 } 51 }
58 52
59 bool VulkanViewer::onKey(int key, bool keyDown) { 53 bool VulkanViewer::onKey(Window::Key key, Window::InputState state, uint32_t mod ifiers) {
60 if (keyDown) { 54 if (Window::kDown_InputState == state && (modifiers & Window::kFirstPress_Mo difierKey) &&
61 fInputHandler.onKeyDown(key); 55 key == Window::kRight_Key) {
62 } else { 56 fGMs = fGMs->next();
63 fInputHandler.onKeyUp(key); 57 }
64 } 58
65 return true; 59 return true;
66 } 60 }
67 61
68 bool VulkanViewer::onMouse(int x, int y, bool mouseDown) {
69 if (mouseDown) {
70 fInputHandler.onMouseDown(x, y);
71 } else {
72 fInputHandler.onMouseUp();
73 }
74 return true;
75 }
76
77 void VulkanViewer::onPaint(SkCanvas* canvas) { 62 void VulkanViewer::onPaint(SkCanvas* canvas) {
78 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); 63 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr));
79 64
80 canvas->save(); 65 canvas->save();
81 66
82 gm->draw(canvas); 67 gm->draw(canvas);
83 68
84 canvas->restore(); 69 canvas->restore();
85 } 70 }
86 71
87 void VulkanViewer::onIdle(float dt) { 72 void VulkanViewer::onIdle(float dt) {
88 if (fInputHandler.isKeyPressed('l') || fInputHandler.isKeyPressed('L')) {
89 fGMs = fGMs->next();
90 }
91 fWindow->onPaint(); 73 fWindow->onPaint();
92
93 fInputHandler.Update();
94 } 74 }
OLDNEW
« no previous file with comments | « tools/vulkan/viewer/VulkanViewer.h ('k') | tools/vulkan/win/Window_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698