blob: 1827ec5fec35919a54b211f0f6bb26861b83eb6e [file] [log] [blame]
Tony Barbour2f18b292016-02-25 15:44:10 -07001/*
2 * Copyright (C) 2016 Google, Inc.
3 *
Jon Ashburn43b53e82016-04-19 11:30:31 -06004 * 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
Tony Barbour2f18b292016-02-25 15:44:10 -07007 *
Jon Ashburn43b53e82016-04-19 11:30:31 -06008 * http://www.apache.org/licenses/LICENSE-2.0
Tony Barbour2f18b292016-02-25 15:44:10 -07009 *
Jon Ashburn43b53e82016-04-19 11:30:31 -060010 * 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.
Tony Barbour2f18b292016-02-25 15:44:10 -070015 */
16
17#ifndef SHELL_ANDROID_H
18#define SHELL_ANDROID_H
19
20#include <android_native_app_glue.h>
21#include "Shell.h"
22
23class ShellAndroid : public Shell {
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -070024 public:
Cody Northropcf4815b2016-12-02 11:25:54 -070025 static std::vector<std::string> get_args(android_app &app);
26
Tony Barbour2f18b292016-02-25 15:44:10 -070027 ShellAndroid(android_app &app, Game &game);
28 ~ShellAndroid();
29
30 void log(LogPriority priority, const char *msg);
31
32 void run();
33 void quit();
34
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -070035 private:
Tony Barbour2f18b292016-02-25 15:44:10 -070036 PFN_vkGetInstanceProcAddr load_vk();
37 bool can_present(VkPhysicalDevice phy, uint32_t queue_family) { return true; }
38
39 VkSurfaceKHR create_surface(VkInstance instance);
40
41 void on_app_cmd(int32_t cmd);
42 int32_t on_input_event(const AInputEvent *event);
43
44 static inline void on_app_cmd(android_app *app, int32_t cmd);
45 static inline int32_t on_input_event(android_app *app, AInputEvent *event);
46
47 android_app &app_;
48
49 void *lib_handle_;
50};
51
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -070052void ShellAndroid::on_app_cmd(android_app *app, int32_t cmd) {
Tony Barbour2f18b292016-02-25 15:44:10 -070053 auto android = reinterpret_cast<ShellAndroid *>(app->userData);
54 android->on_app_cmd(cmd);
55}
56
Mark Lobodzinskibc9caa52017-01-26 12:16:30 -070057int32_t ShellAndroid::on_input_event(android_app *app, AInputEvent *event) {
Tony Barbour2f18b292016-02-25 15:44:10 -070058 auto android = reinterpret_cast<ShellAndroid *>(app->userData);
59 return android->on_input_event(event);
60}
61
62#endif // SHELL_ANDROID_H