os_android.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*************************************************************************/
  2. /* os_android.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef OS_ANDROID_H
  30. #define OS_ANDROID_H
  31. #include "os/input.h"
  32. #include "drivers/unix/os_unix.h"
  33. #include "os/main_loop.h"
  34. #include "servers/physics/physics_server_sw.h"
  35. #include "servers/spatial_sound/spatial_sound_server_sw.h"
  36. #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h"
  37. #include "servers/audio/audio_server_sw.h"
  38. #include "servers/physics_2d/physics_2d_server_sw.h"
  39. #include "servers/visual/rasterizer.h"
  40. #ifdef ANDROID_NATIVE_ACTIVITY
  41. #include <android/sensor.h>
  42. #include <android/log.h>
  43. #include <android_native_app_glue.h>
  44. #else
  45. #endif
  46. #include "audio_driver_jandroid.h"
  47. #include "audio_driver_opensl.h"
  48. typedef void (*GFXInitFunc)(void *ud,bool gl2);
  49. typedef int (*OpenURIFunc)(const String&);
  50. typedef String (*GetDataDirFunc)();
  51. typedef String (*GetLocaleFunc)();
  52. typedef String (*GetModelFunc)();
  53. typedef String (*GetUniqueIDFunc)();
  54. typedef void (*ShowVirtualKeyboardFunc)(const String&);
  55. typedef void (*HideVirtualKeyboardFunc)();
  56. typedef void (*SetScreenOrientationFunc)(int);
  57. typedef void (*VideoPlayFunc)(const String&);
  58. typedef bool (*VideoIsPlayingFunc)();
  59. typedef void (*VideoPauseFunc)();
  60. typedef void (*VideoStopFunc)();
  61. class OS_Android : public OS_Unix {
  62. public:
  63. struct TouchPos {
  64. int id;
  65. Point2 pos;
  66. };
  67. private:
  68. Vector<TouchPos> touch;
  69. Point2 last_mouse;
  70. unsigned int last_id;
  71. GFXInitFunc gfx_init_func;
  72. void*gfx_init_ud;
  73. bool use_gl2;
  74. bool use_reload_hooks;
  75. bool use_apk_expansion;
  76. Rasterizer *rasterizer;
  77. VisualServer *visual_server;
  78. AudioServerSW *audio_server;
  79. SampleManagerMallocSW *sample_manager;
  80. SpatialSoundServerSW *spatial_sound_server;
  81. SpatialSound2DServerSW *spatial_sound_2d_server;
  82. PhysicsServer *physics_server;
  83. Physics2DServer *physics_2d_server;
  84. #if 0
  85. AudioDriverAndroid audio_driver_android;
  86. #else
  87. AudioDriverOpenSL audio_driver_android;
  88. #endif
  89. const char* gl_extensions;
  90. InputDefault *input;
  91. VideoMode default_videomode;
  92. MainLoop * main_loop;
  93. OpenURIFunc open_uri_func;
  94. GetDataDirFunc get_data_dir_func;
  95. GetLocaleFunc get_locale_func;
  96. GetModelFunc get_model_func;
  97. ShowVirtualKeyboardFunc show_virtual_keyboard_func;
  98. HideVirtualKeyboardFunc hide_virtual_keyboard_func;
  99. SetScreenOrientationFunc set_screen_orientation_func;
  100. GetUniqueIDFunc get_unique_id_func;
  101. VideoPlayFunc video_play_func;
  102. VideoIsPlayingFunc video_is_playing_func;
  103. VideoPauseFunc video_pause_func;
  104. VideoStopFunc video_stop_func;
  105. public:
  106. // functions used by main to initialize/deintialize the OS
  107. virtual int get_video_driver_count() const;
  108. virtual const char * get_video_driver_name(int p_driver) const;
  109. virtual VideoMode get_default_video_mode() const;
  110. virtual int get_audio_driver_count() const;
  111. virtual const char * get_audio_driver_name(int p_driver) const;
  112. virtual void initialize_core();
  113. virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver);
  114. virtual void set_main_loop( MainLoop * p_main_loop );
  115. virtual void delete_main_loop();
  116. virtual void finalize();
  117. typedef int64_t ProcessID;
  118. static OS* get_singleton();
  119. virtual void vprint(const char* p_format, va_list p_list, bool p_stderr=false);
  120. virtual void print(const char *p_format, ... );
  121. virtual void alert(const String& p_alert);
  122. virtual void set_mouse_show(bool p_show);
  123. virtual void set_mouse_grab(bool p_grab);
  124. virtual bool is_mouse_grab_enabled() const;
  125. virtual Point2 get_mouse_pos() const;
  126. virtual int get_mouse_button_state() const;
  127. virtual void set_window_title(const String& p_title);
  128. //virtual void set_clipboard(const String& p_text);
  129. //virtual String get_clipboard() const;
  130. virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0);
  131. virtual VideoMode get_video_mode(int p_screen=0) const;
  132. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
  133. virtual String get_name();
  134. virtual MainLoop *get_main_loop() const;
  135. virtual bool can_draw() const;
  136. virtual void set_cursor_shape(CursorShape p_shape);
  137. void main_loop_begin();
  138. bool main_loop_iterate();
  139. void main_loop_request_quit();
  140. void main_loop_end();
  141. void main_loop_focusout();
  142. void main_loop_focusin();
  143. virtual bool has_touchscreen_ui_hint() const;
  144. virtual bool has_virtual_keyboard() const;
  145. virtual void show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect=Rect2());
  146. virtual void hide_virtual_keyboard();
  147. void set_opengl_extensions(const char* p_gl_extensions);
  148. void set_display_size(Size2 p_size);
  149. void reload_gfx();
  150. void set_need_reload_hooks(bool p_needs_them);
  151. virtual void set_screen_orientation(ScreenOrientation p_orientation);
  152. virtual Error shell_open(String p_uri);
  153. virtual String get_data_dir() const;
  154. virtual String get_resource_dir() const;
  155. virtual String get_locale() const;
  156. virtual String get_model_name() const;
  157. virtual String get_unique_ID() const;
  158. void process_accelerometer(const Vector3& p_accelerometer);
  159. void process_touch(int p_what,int p_pointer, const Vector<TouchPos>& p_points);
  160. void process_event(InputEvent p_event);
  161. void init_video_mode(int p_video_width,int p_video_height);
  162. virtual Error native_video_play(String p_path, float p_volume);
  163. virtual bool native_video_is_playing();
  164. virtual void native_video_pause();
  165. virtual void native_video_stop();
  166. OS_Android(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func,GetModelFunc p_get_model_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, SetScreenOrientationFunc p_screen_orient,GetUniqueIDFunc p_get_unique_id, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func,bool p_use_apk_expansion);
  167. ~OS_Android();
  168. };
  169. #endif