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_android.h" | 8 #include "Window_android.h" |
9 | 9 |
10 #include "VulkanWindowContext_android.h" | 10 #include "VulkanWindowContext_android.h" |
11 | 11 |
12 namespace sk_app { | 12 namespace sk_app { |
13 | 13 |
14 Window* Window::CreateNativeWindow(void* platformData) { | 14 Window* Window::CreateNativeWindow(void* platformData) { |
15 Window_android* window = new Window_android(); | 15 Window_android* window = new Window_android(); |
16 if (!window->init((android_app*)platformData)) { | 16 if (!window->init((AppThread*)platformData)) { |
17 delete window; | 17 delete window; |
18 return nullptr; | 18 return nullptr; |
19 } | 19 } |
20 return window; | 20 return window; |
21 } | 21 } |
22 | 22 |
23 static void handle_cmd(struct android_app* app, int32_t cmd); | 23 static void handle_cmd(struct android_app* app, int32_t cmd); |
24 static int32_t handle_input(struct android_app* app, AInputEvent* event); | 24 static int32_t handle_input(struct android_app* app, AInputEvent* event); |
25 | 25 |
| 26 bool Window_android::init(AppThread* appThread) { |
| 27 SkASSERT(appThread); |
| 28 mAppThread = appThread; |
| 29 mAppThread->window = this; |
| 30 return true; |
| 31 } |
| 32 |
26 bool Window_android::init(android_app* app) { | 33 bool Window_android::init(android_app* app) { |
27 SkASSERT(app); | 34 SkASSERT(app); |
28 mApp = app; | 35 mApp = app; |
29 mApp->userData = this; | 36 mApp->userData = this; |
30 mApp->onAppCmd = handle_cmd; | 37 mApp->onAppCmd = handle_cmd; |
31 mApp->onInputEvent = handle_input; | 38 mApp->onInputEvent = handle_input; |
32 return true; | 39 return true; |
33 } | 40 } |
34 | 41 |
35 void Window_android::setTitle(const char* title) { | 42 void Window_android::setTitle(const char* title) { |
(...skipping 11 matching lines...) Expand all Loading... |
47 // We delay the creation of fTestContext until Android informs us that | 54 // We delay the creation of fTestContext until Android informs us that |
48 // the native window is ready to use. | 55 // the native window is ready to use. |
49 return true; | 56 return true; |
50 } | 57 } |
51 | 58 |
52 void Window_android::initDisplay(ANativeWindow* window) { | 59 void Window_android::initDisplay(ANativeWindow* window) { |
53 SkASSERT(window); | 60 SkASSERT(window); |
54 ContextPlatformData_android platformData; | 61 ContextPlatformData_android platformData; |
55 platformData.fNativeWindow = window; | 62 platformData.fNativeWindow = window; |
56 fWindowContext = VulkanWindowContext::Create((void*)&platformData, mSampleCo
unt); | 63 fWindowContext = VulkanWindowContext::Create((void*)&platformData, mSampleCo
unt); |
| 64 nativeWindowInitialized = true; |
57 } | 65 } |
58 | 66 |
59 static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) { | 67 static void android_app_write_cmd(struct android_app* android_app, int8_t cmd) { |
60 if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd)) { | 68 if (write(android_app->msgwrite, &cmd, sizeof(cmd)) != sizeof(cmd)) { |
61 SkDebugf("Failure writing android_app cmd: %s\n", strerror(errno)); | 69 SkDebugf("Failure writing android_app cmd: %s\n", strerror(errno)); |
62 } | 70 } |
63 } | 71 } |
64 | 72 |
65 void Window_android::inval() { | 73 void Window_android::inval() { |
66 android_app_write_cmd(mApp, APP_CMD_INVAL_WINDOW); | 74 if (mApp) { |
| 75 android_app_write_cmd(mApp, APP_CMD_INVAL_WINDOW); |
| 76 } else { |
| 77 paintIfNeeded(); |
| 78 } |
67 } | 79 } |
68 | 80 |
69 void Window_android::paintIfNeeded() { | 81 void Window_android::paintIfNeeded() { |
70 if (mApp->window || !mContentRect.isEmpty()) { | 82 if ((mApp && (mApp->window || !mContentRect.isEmpty())) || nativeWindowIniti
alized) { |
71 this->onPaint(); | 83 this->onPaint(); |
72 } | 84 } |
73 } | 85 } |
74 | 86 |
75 /** | 87 /** |
76 * Process the next main command. | 88 * Process the next main command. |
77 */ | 89 */ |
78 static void handle_cmd(struct android_app* app, int32_t cmd) { | 90 static void handle_cmd(struct android_app* app, int32_t cmd) { |
79 Window_android* window = (Window_android*)app->userData; | 91 Window_android* window = (Window_android*)app->userData; |
80 switch (cmd) { | 92 switch (cmd) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 Window::Key key = get_key(AKeyEvent_getKeyCode(event)); | 186 Window::Key key = get_key(AKeyEvent_getKeyCode(event)); |
175 Window::InputState state = get_action(AKeyEvent_getAction(event)); | 187 Window::InputState state = get_action(AKeyEvent_getAction(event)); |
176 int32_t mod = get_key_modifiers(event); | 188 int32_t mod = get_key_modifiers(event); |
177 window->onKey(key, state, mod); | 189 window->onKey(key, state, mod); |
178 return true; // eat all key events | 190 return true; // eat all key events |
179 } | 191 } |
180 return 0; | 192 return 0; |
181 } | 193 } |
182 | 194 |
183 } // namespace sk_app | 195 } // namespace sk_app |
OLD | NEW |