1 /*
2 * Copyright (C) 2016 Google, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef SHELL_ANDROID_H
18 #define SHELL_ANDROID_H
19
20 #include <android_native_app_glue.h>
21 #include "Shell.h"
22
23 class ShellAndroid : public Shell {
24 public:
25 ShellAndroid(android_app &app, Game &game);
26 ~ShellAndroid();
27
28 void log(LogPriority priority, const char *msg);
29
30 void run();
31 void quit();
32
33 private:
34 PFN_vkGetInstanceProcAddr load_vk();
can_present(VkPhysicalDevice phy,uint32_t queue_family)35 bool can_present(VkPhysicalDevice phy, uint32_t queue_family) { return true; }
36
37 VkSurfaceKHR create_surface(VkInstance instance);
38
39 void on_app_cmd(int32_t cmd);
40 int32_t on_input_event(const AInputEvent *event);
41
42 static inline void on_app_cmd(android_app *app, int32_t cmd);
43 static inline int32_t on_input_event(android_app *app, AInputEvent *event);
44
45 android_app &app_;
46
47 void *lib_handle_;
48 };
49
on_app_cmd(android_app * app,int32_t cmd)50 void ShellAndroid::on_app_cmd(android_app *app, int32_t cmd)
51 {
52 auto android = reinterpret_cast<ShellAndroid *>(app->userData);
53 android->on_app_cmd(cmd);
54 }
55
on_input_event(android_app * app,AInputEvent * event)56 int32_t ShellAndroid::on_input_event(android_app *app, AInputEvent *event)
57 {
58 auto android = reinterpret_cast<ShellAndroid *>(app->userData);
59 return android->on_input_event(event);
60 }
61
62 #endif // SHELL_ANDROID_H
63