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