OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "VulkanViewer.h" |
| 9 |
| 10 #include "SkCanvas.h" |
| 11 #include "SkRandom.h" |
| 12 #include "SkCommonFlags.h" |
| 13 |
| 14 DEFINE_string(key, "", |
| 15 "Space-separated key/value pairs to add to JSON identifying this b
uilder."); |
| 16 |
| 17 Application* Application::Create(int argc, char** argv, void* platformData) { |
| 18 return new VulkanViewer(argc, argv, platformData); |
| 19 } |
| 20 |
| 21 static bool on_key_handler(int key, bool keyDown, void* userData) { |
| 22 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData); |
| 23 |
| 24 return vv->onKey(key, keyDown); |
| 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 } |
| 32 |
| 33 static void on_paint_handler(SkCanvas* canvas, void* userData) { |
| 34 VulkanViewer* vv = reinterpret_cast<VulkanViewer*>(userData); |
| 35 |
| 36 return vv->onPaint(canvas); |
| 37 } |
| 38 |
| 39 VulkanViewer::VulkanViewer(int argc, char** argv, void* platformData) : |
| 40 fGMs(skiagm::GMRegistry::Head()){ |
| 41 |
| 42 fWindow = Window::CreateNativeWindow(platformData); |
| 43 fWindow->attach(Window::kVulkan_BackendType, 0, nullptr); |
| 44 |
| 45 // register callbacks |
| 46 fWindow->registerKeyFunc(on_key_handler, this); |
| 47 fWindow->registerMouseFunc(on_mouse_handler, this); |
| 48 fWindow->registerPaintFunc(on_paint_handler, this); |
| 49 |
| 50 fWindow->setTitle("VulkanViewer"); |
| 51 fWindow->show(); |
| 52 } |
| 53 |
| 54 VulkanViewer::~VulkanViewer() { |
| 55 fWindow->detach(); |
| 56 delete fWindow; |
| 57 } |
| 58 |
| 59 bool VulkanViewer::onKey(int key, bool keyDown) { |
| 60 if (keyDown) { |
| 61 fInputHandler.onKeyDown(key); |
| 62 } else { |
| 63 fInputHandler.onKeyUp(key); |
| 64 } |
| 65 return true; |
| 66 } |
| 67 |
| 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) { |
| 78 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); |
| 79 |
| 80 canvas->save(); |
| 81 |
| 82 gm->draw(canvas); |
| 83 |
| 84 canvas->restore(); |
| 85 } |
| 86 |
| 87 void VulkanViewer::onIdle(float dt) { |
| 88 if (fInputHandler.isKeyPressed('l') || fInputHandler.isKeyPressed('L')) { |
| 89 fGMs = fGMs->next(); |
| 90 } |
| 91 fWindow->onPaint(); |
| 92 |
| 93 fInputHandler.Update(); |
| 94 } |
OLD | NEW |