os_android.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. /*************************************************************************/
  2. /* os_android.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "os_android.h"
  31. #include "core/io/file_access_buffered_fa.h"
  32. #include "core/project_settings.h"
  33. #include "drivers/gles2/rasterizer_gles2.h"
  34. #include "drivers/gles3/rasterizer_gles3.h"
  35. #include "drivers/unix/dir_access_unix.h"
  36. #include "drivers/unix/file_access_unix.h"
  37. #include "file_access_android.h"
  38. #include "main/main.h"
  39. #include "servers/visual/visual_server_raster.h"
  40. //#include "servers/visual/visual_server_wrap_mt.h"
  41. #ifdef ANDROID_NATIVE_ACTIVITY
  42. #include "dir_access_android.h"
  43. #include "file_access_android.h"
  44. #else
  45. #include "dir_access_jandroid.h"
  46. #include "file_access_jandroid.h"
  47. #endif
  48. #include <dlfcn.h>
  49. class AndroidLogger : public Logger {
  50. public:
  51. virtual void logv(const char *p_format, va_list p_list, bool p_err) {
  52. __android_log_vprint(p_err ? ANDROID_LOG_ERROR : ANDROID_LOG_INFO, "godot", p_format, p_list);
  53. }
  54. virtual ~AndroidLogger() {}
  55. };
  56. int OS_Android::get_video_driver_count() const {
  57. return 2;
  58. }
  59. const char *OS_Android::get_video_driver_name(int p_driver) const {
  60. switch (p_driver) {
  61. case VIDEO_DRIVER_GLES3:
  62. return "GLES3";
  63. case VIDEO_DRIVER_GLES2:
  64. return "GLES2";
  65. }
  66. ERR_EXPLAIN("Invalid video driver index " + itos(p_driver));
  67. ERR_FAIL_V(NULL);
  68. }
  69. int OS_Android::get_audio_driver_count() const {
  70. return 1;
  71. }
  72. const char *OS_Android::get_audio_driver_name(int p_driver) const {
  73. return "Android";
  74. }
  75. void OS_Android::initialize_core() {
  76. OS_Unix::initialize_core();
  77. #ifdef ANDROID_NATIVE_ACTIVITY
  78. FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES);
  79. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
  80. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
  81. //FileAccessBufferedFA<FileAccessUnix>::make_default();
  82. DirAccess::make_default<DirAccessAndroid>(DirAccess::ACCESS_RESOURCES);
  83. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
  84. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);
  85. #else
  86. if (use_apk_expansion)
  87. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
  88. else {
  89. #ifdef USE_JAVA_FILE_ACCESS
  90. FileAccess::make_default<FileAccessBufferedFA<FileAccessJAndroid> >(FileAccess::ACCESS_RESOURCES);
  91. #else
  92. //FileAccess::make_default<FileAccessBufferedFA<FileAccessAndroid> >(FileAccess::ACCESS_RESOURCES);
  93. FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES);
  94. #endif
  95. }
  96. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
  97. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
  98. //FileAccessBufferedFA<FileAccessUnix>::make_default();
  99. if (use_apk_expansion)
  100. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_RESOURCES);
  101. else
  102. DirAccess::make_default<DirAccessJAndroid>(DirAccess::ACCESS_RESOURCES);
  103. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
  104. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);
  105. #endif
  106. }
  107. void OS_Android::set_opengl_extensions(const char *p_gl_extensions) {
  108. ERR_FAIL_COND(!p_gl_extensions);
  109. gl_extensions = p_gl_extensions;
  110. }
  111. int OS_Android::get_current_video_driver() const {
  112. return video_driver_index;
  113. }
  114. Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
  115. bool use_gl3 = get_gl_version_code_func() >= 0x00030000;
  116. use_gl3 = use_gl3 && (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3");
  117. bool gl_initialization_error = false;
  118. while (true) {
  119. if (use_gl3) {
  120. if (RasterizerGLES3::is_viable() == OK) {
  121. if (gfx_init_func)
  122. gfx_init_func(gfx_init_ud, false);
  123. RasterizerGLES3::register_config();
  124. RasterizerGLES3::make_current();
  125. break;
  126. } else {
  127. if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best") {
  128. p_video_driver = VIDEO_DRIVER_GLES2;
  129. use_gl3 = false;
  130. continue;
  131. } else {
  132. gl_initialization_error = true;
  133. break;
  134. }
  135. }
  136. } else {
  137. if (RasterizerGLES2::is_viable() == OK) {
  138. if (gfx_init_func)
  139. gfx_init_func(gfx_init_ud, true);
  140. RasterizerGLES2::register_config();
  141. RasterizerGLES2::make_current();
  142. break;
  143. } else {
  144. gl_initialization_error = true;
  145. break;
  146. }
  147. }
  148. }
  149. if (gl_initialization_error) {
  150. OS::get_singleton()->alert("Your device does not support any of the supported OpenGL versions.\n"
  151. "Please try updating your Android version.",
  152. "Unable to initialize Video driver");
  153. return ERR_UNAVAILABLE;
  154. }
  155. video_driver_index = p_video_driver;
  156. visual_server = memnew(VisualServerRaster);
  157. /* if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
  158. visual_server = memnew(VisualServerWrapMT(visual_server, false));
  159. };*/
  160. visual_server->init();
  161. // visual_server->cursor_set_visible(false, 0);
  162. AudioDriverManager::initialize(p_audio_driver);
  163. input = memnew(InputDefault);
  164. input->set_fallback_mapping("Default Android Gamepad");
  165. //power_manager = memnew(power_android);
  166. return OK;
  167. }
  168. void OS_Android::set_main_loop(MainLoop *p_main_loop) {
  169. main_loop = p_main_loop;
  170. input->set_main_loop(p_main_loop);
  171. }
  172. void OS_Android::delete_main_loop() {
  173. memdelete(main_loop);
  174. }
  175. void OS_Android::finalize() {
  176. memdelete(input);
  177. }
  178. void OS_Android::alert(const String &p_alert, const String &p_title) {
  179. //print("ALERT: %s\n", p_alert.utf8().get_data());
  180. if (alert_func)
  181. alert_func(p_alert, p_title);
  182. }
  183. Error OS_Android::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
  184. p_library_handle = dlopen(p_path.utf8().get_data(), RTLD_NOW);
  185. if (!p_library_handle) {
  186. ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror());
  187. ERR_FAIL_V(ERR_CANT_OPEN);
  188. }
  189. return OK;
  190. }
  191. void OS_Android::set_mouse_show(bool p_show) {
  192. //android has no mouse...
  193. }
  194. void OS_Android::set_mouse_grab(bool p_grab) {
  195. //it really has no mouse...!
  196. }
  197. bool OS_Android::is_mouse_grab_enabled() const {
  198. //*sigh* technology has evolved so much since i was a kid..
  199. return false;
  200. }
  201. Point2 OS_Android::get_mouse_position() const {
  202. return Point2();
  203. }
  204. int OS_Android::get_mouse_button_state() const {
  205. return 0;
  206. }
  207. void OS_Android::set_window_title(const String &p_title) {
  208. }
  209. //interesting byt not yet
  210. //void set_clipboard(const String& p_text);
  211. //String get_clipboard() const;
  212. void OS_Android::set_video_mode(const VideoMode &p_video_mode, int p_screen) {
  213. }
  214. OS::VideoMode OS_Android::get_video_mode(int p_screen) const {
  215. return default_videomode;
  216. }
  217. void OS_Android::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
  218. p_list->push_back(default_videomode);
  219. }
  220. void OS_Android::set_keep_screen_on(bool p_enabled) {
  221. OS::set_keep_screen_on(p_enabled);
  222. if (set_keep_screen_on_func) {
  223. set_keep_screen_on_func(p_enabled);
  224. }
  225. }
  226. Size2 OS_Android::get_window_size() const {
  227. return Vector2(default_videomode.width, default_videomode.height);
  228. }
  229. String OS_Android::get_name() {
  230. return "Android";
  231. }
  232. MainLoop *OS_Android::get_main_loop() const {
  233. return main_loop;
  234. }
  235. bool OS_Android::can_draw() const {
  236. return true; //always?
  237. }
  238. void OS_Android::set_cursor_shape(CursorShape p_shape) {
  239. //android really really really has no mouse.. how amazing..
  240. }
  241. void OS_Android::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
  242. }
  243. void OS_Android::main_loop_begin() {
  244. if (main_loop)
  245. main_loop->init();
  246. }
  247. bool OS_Android::main_loop_iterate() {
  248. if (!main_loop)
  249. return false;
  250. return Main::iteration();
  251. }
  252. void OS_Android::main_loop_end() {
  253. if (main_loop)
  254. main_loop->finish();
  255. }
  256. void OS_Android::main_loop_focusout() {
  257. if (main_loop)
  258. main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
  259. audio_driver_android.set_pause(true);
  260. }
  261. void OS_Android::main_loop_focusin() {
  262. if (main_loop)
  263. main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
  264. audio_driver_android.set_pause(false);
  265. }
  266. void OS_Android::process_joy_event(OS_Android::JoypadEvent p_event) {
  267. switch (p_event.type) {
  268. case JOY_EVENT_BUTTON:
  269. input->joy_button(p_event.device, p_event.index, p_event.pressed);
  270. break;
  271. case JOY_EVENT_AXIS:
  272. InputDefault::JoyAxis value;
  273. value.min = -1;
  274. value.value = p_event.value;
  275. input->joy_axis(p_event.device, p_event.index, value);
  276. break;
  277. case JOY_EVENT_HAT:
  278. input->joy_hat(p_event.device, p_event.hat);
  279. break;
  280. default:
  281. return;
  282. }
  283. }
  284. void OS_Android::process_event(Ref<InputEvent> p_event) {
  285. input->parse_input_event(p_event);
  286. }
  287. void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points) {
  288. switch (p_what) {
  289. case 0: { //gesture begin
  290. if (touch.size()) {
  291. //end all if exist
  292. for (int i = 0; i < touch.size(); i++) {
  293. Ref<InputEventScreenTouch> ev;
  294. ev.instance();
  295. ev->set_index(touch[i].id);
  296. ev->set_pressed(false);
  297. ev->set_position(touch[i].pos);
  298. input->parse_input_event(ev);
  299. }
  300. }
  301. touch.resize(p_points.size());
  302. for (int i = 0; i < p_points.size(); i++) {
  303. touch.write[i].id = p_points[i].id;
  304. touch.write[i].pos = p_points[i].pos;
  305. }
  306. //send touch
  307. for (int i = 0; i < touch.size(); i++) {
  308. Ref<InputEventScreenTouch> ev;
  309. ev.instance();
  310. ev->set_index(touch[i].id);
  311. ev->set_pressed(true);
  312. ev->set_position(touch[i].pos);
  313. input->parse_input_event(ev);
  314. }
  315. } break;
  316. case 1: { //motion
  317. ERR_FAIL_COND(touch.size() != p_points.size());
  318. for (int i = 0; i < touch.size(); i++) {
  319. int idx = -1;
  320. for (int j = 0; j < p_points.size(); j++) {
  321. if (touch[i].id == p_points[j].id) {
  322. idx = j;
  323. break;
  324. }
  325. }
  326. ERR_CONTINUE(idx == -1);
  327. if (touch[i].pos == p_points[idx].pos)
  328. continue; //no move unncesearily
  329. Ref<InputEventScreenDrag> ev;
  330. ev.instance();
  331. ev->set_index(touch[i].id);
  332. ev->set_position(p_points[idx].pos);
  333. ev->set_relative(p_points[idx].pos - touch[i].pos);
  334. input->parse_input_event(ev);
  335. touch.write[i].pos = p_points[idx].pos;
  336. }
  337. } break;
  338. case 2: { //release
  339. if (touch.size()) {
  340. //end all if exist
  341. for (int i = 0; i < touch.size(); i++) {
  342. Ref<InputEventScreenTouch> ev;
  343. ev.instance();
  344. ev->set_index(touch[i].id);
  345. ev->set_pressed(false);
  346. ev->set_position(touch[i].pos);
  347. input->parse_input_event(ev);
  348. }
  349. touch.clear();
  350. }
  351. } break;
  352. case 3: { // add touch
  353. for (int i = 0; i < p_points.size(); i++) {
  354. if (p_points[i].id == p_pointer) {
  355. TouchPos tp = p_points[i];
  356. touch.push_back(tp);
  357. Ref<InputEventScreenTouch> ev;
  358. ev.instance();
  359. ev->set_index(tp.id);
  360. ev->set_pressed(true);
  361. ev->set_position(tp.pos);
  362. input->parse_input_event(ev);
  363. break;
  364. }
  365. }
  366. } break;
  367. case 4: { // remove touch
  368. for (int i = 0; i < touch.size(); i++) {
  369. if (touch[i].id == p_pointer) {
  370. Ref<InputEventScreenTouch> ev;
  371. ev.instance();
  372. ev->set_index(touch[i].id);
  373. ev->set_pressed(false);
  374. ev->set_position(touch[i].pos);
  375. input->parse_input_event(ev);
  376. touch.remove(i);
  377. break;
  378. }
  379. }
  380. } break;
  381. }
  382. }
  383. void OS_Android::process_accelerometer(const Vector3 &p_accelerometer) {
  384. input->set_accelerometer(p_accelerometer);
  385. }
  386. void OS_Android::process_gravity(const Vector3 &p_gravity) {
  387. input->set_gravity(p_gravity);
  388. }
  389. void OS_Android::process_magnetometer(const Vector3 &p_magnetometer) {
  390. input->set_magnetometer(p_magnetometer);
  391. }
  392. void OS_Android::process_gyroscope(const Vector3 &p_gyroscope) {
  393. input->set_gyroscope(p_gyroscope);
  394. }
  395. bool OS_Android::has_touchscreen_ui_hint() const {
  396. return true;
  397. }
  398. bool OS_Android::has_virtual_keyboard() const {
  399. return true;
  400. }
  401. int OS_Android::get_virtual_keyboard_height() const {
  402. if (get_virtual_keyboard_height_func) {
  403. return get_virtual_keyboard_height_func();
  404. }
  405. ERR_PRINT("Cannot obtain virtual keyboard height.");
  406. return 0;
  407. }
  408. void OS_Android::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) {
  409. if (show_virtual_keyboard_func) {
  410. show_virtual_keyboard_func(p_existing_text);
  411. } else {
  412. ERR_PRINT("Virtual keyboard not available");
  413. };
  414. }
  415. void OS_Android::hide_virtual_keyboard() {
  416. if (hide_virtual_keyboard_func) {
  417. hide_virtual_keyboard_func();
  418. } else {
  419. ERR_PRINT("Virtual keyboard not available");
  420. };
  421. }
  422. void OS_Android::init_video_mode(int p_video_width, int p_video_height) {
  423. default_videomode.width = p_video_width;
  424. default_videomode.height = p_video_height;
  425. default_videomode.fullscreen = true;
  426. default_videomode.resizable = false;
  427. }
  428. void OS_Android::main_loop_request_go_back() {
  429. if (main_loop)
  430. main_loop->notification(MainLoop::NOTIFICATION_WM_GO_BACK_REQUEST);
  431. }
  432. void OS_Android::set_display_size(Size2 p_size) {
  433. default_videomode.width = p_size.x;
  434. default_videomode.height = p_size.y;
  435. }
  436. void OS_Android::reload_gfx() {
  437. if (gfx_init_func)
  438. gfx_init_func(gfx_init_ud, use_gl2);
  439. //if (rasterizer)
  440. // rasterizer->reload_vram();
  441. }
  442. Error OS_Android::shell_open(String p_uri) {
  443. if (open_uri_func)
  444. return open_uri_func(p_uri) ? ERR_CANT_OPEN : OK;
  445. return ERR_UNAVAILABLE;
  446. }
  447. String OS_Android::get_resource_dir() const {
  448. return "/"; //android has it's own filesystem for resources inside the APK
  449. }
  450. String OS_Android::get_locale() const {
  451. if (get_locale_func)
  452. return get_locale_func();
  453. return OS_Unix::get_locale();
  454. }
  455. String OS_Android::get_model_name() const {
  456. if (get_model_func)
  457. return get_model_func();
  458. return OS_Unix::get_model_name();
  459. }
  460. int OS_Android::get_screen_dpi(int p_screen) const {
  461. if (get_screen_dpi_func) {
  462. return get_screen_dpi_func();
  463. }
  464. return 160;
  465. }
  466. void OS_Android::set_need_reload_hooks(bool p_needs_them) {
  467. use_reload_hooks = p_needs_them;
  468. }
  469. String OS_Android::get_user_data_dir() const {
  470. if (data_dir_cache != String())
  471. return data_dir_cache;
  472. if (get_user_data_dir_func) {
  473. String data_dir = get_user_data_dir_func();
  474. //store current dir
  475. char real_current_dir_name[2048];
  476. getcwd(real_current_dir_name, 2048);
  477. //go to data dir
  478. chdir(data_dir.utf8().get_data());
  479. //get actual data dir, so we resolve potential symlink (Android 6.0+ seems to use symlink)
  480. char data_current_dir_name[2048];
  481. getcwd(data_current_dir_name, 2048);
  482. //cache by parsing utf8
  483. data_dir_cache.parse_utf8(data_current_dir_name);
  484. //restore original dir so we don't mess things up
  485. chdir(real_current_dir_name);
  486. return data_dir_cache;
  487. }
  488. return ".";
  489. }
  490. void OS_Android::set_screen_orientation(ScreenOrientation p_orientation) {
  491. if (set_screen_orientation_func)
  492. set_screen_orientation_func(p_orientation);
  493. }
  494. String OS_Android::get_unique_id() const {
  495. if (get_unique_id_func)
  496. return get_unique_id_func();
  497. return OS::get_unique_id();
  498. }
  499. Error OS_Android::native_video_play(String p_path, float p_volume) {
  500. if (video_play_func)
  501. video_play_func(p_path);
  502. return OK;
  503. }
  504. bool OS_Android::native_video_is_playing() {
  505. if (video_is_playing_func)
  506. return video_is_playing_func();
  507. return false;
  508. }
  509. void OS_Android::native_video_pause() {
  510. if (video_pause_func)
  511. video_pause_func();
  512. }
  513. String OS_Android::get_system_dir(SystemDir p_dir) const {
  514. if (get_system_dir_func)
  515. return get_system_dir_func(p_dir);
  516. return String(".");
  517. }
  518. void OS_Android::native_video_stop() {
  519. if (video_stop_func)
  520. video_stop_func();
  521. }
  522. void OS_Android::set_context_is_16_bits(bool p_is_16) {
  523. //use_16bits_fbo = p_is_16;
  524. //if (rasterizer)
  525. // rasterizer->set_force_16_bits_fbo(p_is_16);
  526. }
  527. void OS_Android::joy_connection_changed(int p_device, bool p_connected, String p_name) {
  528. return input->joy_connection_changed(p_device, p_connected, p_name, "");
  529. }
  530. bool OS_Android::is_joy_known(int p_device) {
  531. return input->is_joy_mapped(p_device);
  532. }
  533. String OS_Android::get_joy_guid(int p_device) const {
  534. return input->get_joy_guid_remapped(p_device);
  535. }
  536. bool OS_Android::_check_internal_feature_support(const String &p_feature) {
  537. if (p_feature == "mobile" || p_feature == "etc" || p_feature == "etc2") {
  538. //TODO support etc2 only if GLES3 driver is selected
  539. return true;
  540. }
  541. #if defined(__aarch64__)
  542. if (p_feature == "arm64-v8a") {
  543. return true;
  544. }
  545. #elif defined(__ARM_ARCH_7A__)
  546. if (p_feature == "armeabi-v7a" || p_feature == "armeabi") {
  547. return true;
  548. }
  549. #elif defined(__arm__)
  550. if (p_feature == "armeabi") {
  551. return true;
  552. }
  553. #endif
  554. return false;
  555. }
  556. OS_Android::OS_Android(GFXInitFunc p_gfx_init_func, void *p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetUserDataDirFunc p_get_user_data_dir_func, GetLocaleFunc p_get_locale_func, GetModelFunc p_get_model_func, GetScreenDPIFunc p_get_screen_dpi_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, VirtualKeyboardHeightFunc p_vk_height_func, SetScreenOrientationFunc p_screen_orient, GetUniqueIDFunc p_get_unique_id, GetSystemDirFunc p_get_sdir_func, GetGLVersionCodeFunc p_get_gl_version_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, AlertFunc p_alert_func, bool p_use_apk_expansion) {
  557. use_apk_expansion = p_use_apk_expansion;
  558. default_videomode.width = 800;
  559. default_videomode.height = 600;
  560. default_videomode.fullscreen = true;
  561. default_videomode.resizable = false;
  562. gfx_init_func = p_gfx_init_func;
  563. gfx_init_ud = p_gfx_init_ud;
  564. main_loop = NULL;
  565. gl_extensions = NULL;
  566. //rasterizer = NULL;
  567. use_gl2 = false;
  568. open_uri_func = p_open_uri_func;
  569. get_user_data_dir_func = p_get_user_data_dir_func;
  570. get_locale_func = p_get_locale_func;
  571. get_model_func = p_get_model_func;
  572. get_screen_dpi_func = p_get_screen_dpi_func;
  573. get_unique_id_func = p_get_unique_id;
  574. get_system_dir_func = p_get_sdir_func;
  575. get_gl_version_code_func = p_get_gl_version_func;
  576. video_play_func = p_video_play_func;
  577. video_is_playing_func = p_video_is_playing_func;
  578. video_pause_func = p_video_pause_func;
  579. video_stop_func = p_video_stop_func;
  580. show_virtual_keyboard_func = p_show_vk;
  581. hide_virtual_keyboard_func = p_hide_vk;
  582. get_virtual_keyboard_height_func = p_vk_height_func;
  583. set_screen_orientation_func = p_screen_orient;
  584. set_keep_screen_on_func = p_set_keep_screen_on_func;
  585. alert_func = p_alert_func;
  586. use_reload_hooks = false;
  587. Vector<Logger *> loggers;
  588. loggers.push_back(memnew(AndroidLogger));
  589. _set_logger(memnew(CompositeLogger(loggers)));
  590. AudioDriverManager::add_driver(&audio_driver_android);
  591. }
  592. OS_Android::~OS_Android() {
  593. }