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