| 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 "Window.h" | |
| 9 | |
| 10 #include "SkSurface.h" | |
| 11 #include "SkCanvas.h" | |
| 12 #include "VulkanTestContext.h" | |
| 13 | |
| 14 static bool default_char_func(SkUnichar c, uint32_t modifiers, void* userData) { | |
| 15 return false; | |
| 16 } | |
| 17 | |
| 18 static bool default_key_func(Window::Key key, Window::InputState state, uint32_t
modifiers, | |
| 19 void* userData) { | |
| 20 return false; | |
| 21 } | |
| 22 | |
| 23 static bool default_mouse_func(int x, int y, Window::InputState state, uint32_t
modifiers, | |
| 24 void* userData) { | |
| 25 return false; | |
| 26 } | |
| 27 | |
| 28 static void default_paint_func(SkCanvas*, void* userData) {} | |
| 29 | |
| 30 Window::Window() : fCharFunc(default_char_func) | |
| 31 , fKeyFunc(default_key_func) | |
| 32 , fMouseFunc(default_mouse_func) | |
| 33 , fPaintFunc(default_paint_func) { | |
| 34 } | |
| 35 | |
| 36 void Window::detach() { | |
| 37 delete fTestContext; | |
| 38 fTestContext = nullptr; | |
| 39 } | |
| 40 | |
| 41 bool Window::onChar(SkUnichar c, uint32_t modifiers) { | |
| 42 return fCharFunc(c, modifiers, fCharUserData); | |
| 43 } | |
| 44 | |
| 45 bool Window::onKey(Key key, InputState state, uint32_t modifiers) { | |
| 46 return fKeyFunc(key, state, modifiers, fKeyUserData); | |
| 47 } | |
| 48 | |
| 49 bool Window::onMouse(int x, int y, InputState state, uint32_t modifiers) { | |
| 50 return fMouseFunc(x, y, state, modifiers, fMouseUserData); | |
| 51 } | |
| 52 | |
| 53 void Window::onPaint() { | |
| 54 SkSurface* backbuffer = fTestContext->getBackbufferSurface(); | |
| 55 if (backbuffer) { | |
| 56 // draw into the canvas of this surface | |
| 57 SkCanvas* canvas = backbuffer->getCanvas(); | |
| 58 | |
| 59 fPaintFunc(canvas, fPaintUserData); | |
| 60 | |
| 61 canvas->flush(); | |
| 62 | |
| 63 fTestContext->swapBuffers(); | |
| 64 } else { | |
| 65 // try recreating testcontext | |
| 66 } | |
| 67 | |
| 68 } | |
| 69 | |
| 70 void Window::onResize(uint32_t w, uint32_t h) { | |
| 71 fWidth = w; | |
| 72 fHeight = h; | |
| 73 fTestContext->resize(w, h); | |
| 74 } | |
| OLD | NEW |