Home | History | Annotate | Download | only in smoke
      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     static std::vector<std::string> get_args(android_app &app);
     26 
     27     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 
     35    private:
     36     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 
     52 void ShellAndroid::on_app_cmd(android_app *app, int32_t cmd) {
     53     auto android = reinterpret_cast<ShellAndroid *>(app->userData);
     54     android->on_app_cmd(cmd);
     55 }
     56 
     57 int32_t ShellAndroid::on_input_event(android_app *app, AInputEvent *event) {
     58     auto android = reinterpret_cast<ShellAndroid *>(app->userData);
     59     return android->on_input_event(event);
     60 }
     61 
     62 #endif  // SHELL_ANDROID_H
     63