@@ -481,11 +481,13 @@ void handle_input_events()
481481 auto & glob = get_glob ();
482482 utki::assert (glob.input_queue , SL);
483483
484+ auto & glue = get_glue ();
485+
486+ // TODO: remove
484487 auto & app = ruisapp::inst ();
485488
486489 // read and handle input events
487- AInputEvent* event;
488- while (AInputQueue_getEvent (glob.input_queue , &event) >= 0 ) {
490+ while (AInputEvent* event; AInputQueue_getEvent (glob.input_queue , &event) >= 0 ) {
489491 utki::assert (event, SL);
490492
491493 // utki::log_debug([&](auto&o){o << "New input event: type = " <<
@@ -675,9 +677,9 @@ void handle_input_events()
675677 );
676678 }
677679
678- get_impl (app) .render (app );
680+ glue .render ();
679681
680- fd_flag.set ();
682+ glob. fd_flag .set ();
681683}
682684} // namespace
683685
@@ -735,17 +737,14 @@ void on_configuration_changed(ANativeActivity* activity)
735737
736738 auto & glob = get_glob ();
737739
738- // find out what exactly has changed in the configuration
739- int32_t diff;
740- {
741- utki::assert (activity->assetManager , SL);
742- auto config = utki::make_unique<android_configuration_wrapper>(*activity->assetManager );
740+ // find out what exactly has changed in the configuration
741+ utki::assert (activity->assetManager , SL);
742+ auto config = utki::make_unique<android_configuration_wrapper>(*activity->assetManager );
743743
744- diff = glob.cur_android_configuration .diff (config);
744+ int32_t diff = glob.cur_android_configuration .diff (config);
745745
746- // store new configuration
747- glob.cur_android_configuration = std::move (config);
748- }
746+ // store new configuration
747+ glob.cur_android_configuration = std::move (config);
749748
750749 // if orientation has changed
751750 if (diff & ACONFIGURATION_ORIENTATION) {
@@ -792,53 +791,22 @@ void on_native_window_created(
792791 utki::assert (globals_wrapper::native_activity, SL);
793792 utki::assert (activity == globals_wrapper::native_activity, SL);
794793
794+ utki::assert (window, SL);
795+
795796 utki::log_debug ([](auto & o) {
796797 o << " on_native_window_created(): invoked" << std::endl;
797798 });
798799
799800 auto & glob = get_glob ();
800801
801- // save window in a static var, so it is accessible for creating window surface
802- glob.android_window = window;
803-
804802 glob.cur_window_dims .x () = float (ANativeWindow_getWidth (window));
805803 glob.cur_window_dims .y () = float (ANativeWindow_getHeight (window));
806804
807- // If we have no application instance yet, create it now.
808- // Otherwise the window was re-created after moving the app from background to foreground
809- // and we just need to create EGL surface for the new window.
810- if (!glob.app ) {
811- try {
812- // TODO: create application in globals_wrapper, do not create surface there, create surface here
813- application* app = ruisapp::application_factory::make_application (
814- 0 , // argc
815- nullptr // argv
816- )
817- .release ();
818-
819- // android application should always have GUI
820- utki::assert_always (app, SL);
821-
822- activity->instance = app;
823-
824- // Set the fd_flag to call the update() for the first time if there
825- // were any updateables started during creating application
826- // object.
827- glob.fd_flag .set ();
828- } catch (std::exception& e) {
829- utki::log_debug ([&](auto & o) {
830- o << " std::exception uncaught while creating application instance: " << e.what () << std::endl;
831- });
832- throw ;
833- } catch (...) {
834- utki::log_debug ([](auto & o) {
835- o << " unknown exception uncaught while creating application instance!" << std::endl;
836- });
837- throw ;
838- }
839- } else {
840- get_impl (get_app (activity)).create_surface ();
841- }
805+ auto & glue = get_glue ();
806+
807+ // The android window was just initially created or was re-created after moving the app
808+ // from background to foreground. In any case we just need to create EGL surface for the new android window.
809+ glue.create_window_surface (*window);
842810}
843811
844812void on_native_window_resized (ANativeActivity* activity,//
@@ -848,6 +816,10 @@ void on_native_window_resized(ANativeActivity* activity,//
848816 o << " on_native_window_resized(): invoked" << std::endl;
849817 });
850818
819+ utki::assert (window, SL);
820+
821+ auto & glob = get_glob ();
822+
851823 // save window dimensions
852824 glob.cur_window_dims .x () = float (ANativeWindow_getWidth (window));
853825 glob.cur_window_dims .y () = float (ANativeWindow_getHeight (window));
@@ -864,9 +836,8 @@ void on_native_window_redraw_needed(ANativeActivity* activity, //
864836 o << " on_native_window_redraw_needed(): invoked" << std::endl;
865837 });
866838
867- auto & app = get_app (activity);
868-
869- get_impl (app).render (app);
839+ auto & glue = get_glue ();
840+ glue.render ();
870841}
871842
872843// This function is called right before destroying Window object, according to
@@ -879,12 +850,12 @@ void on_native_window_destroyed(ANativeActivity* activity, //
879850 o << " on_native_window_destroyed(): invoked" << std::endl;
880851 });
881852
853+ auto & glue = get_glue ();
854+
882855 // destroy EGL drawing surface associated with the window.
883856 // the EGL context remains existing and should preserve all resources like
884857 // textures, vertex buffers, etc.
885- get_impl (get_app (activity)).destroy_surface ();
886-
887- android_window = nullptr ;
858+ glue.destroy_window_surface ();
888859}
889860
890861int on_input_events_ready_for_reading_from_queue (
@@ -999,6 +970,7 @@ void on_content_rect_changed(
999970 o << " on_content_rect_changed(): cur_window_dims = " << glob.cur_window_dims << std::endl;
1000971 });
1001972
973+ // TODO: this check is not needed anymore, since app object outlives window now
1002974 // Sometimes Android calls on_content_rect_changed() even after native window
1003975 // was destroyed, i.e. on_native_window_destroyed() was called and, thus,
1004976 // application object was destroyed. So need to check if our application is
@@ -1017,15 +989,15 @@ void on_content_rect_changed(
1017989 update_window_rect (
1018990 app,
1019991 ruis::rect (
1020- float (rect->left ),
992+ float (rect->left ), //
1021993 glob.cur_window_dims .y () - float (rect->bottom ),
1022994 float (rect->right - rect->left ),
1023995 float (rect->bottom - rect->top )
1024996 )
1025997 );
1026998
1027999 // redraw, since WindowRedrawNeeded not always comes
1028- get_impl (app) .render (app );
1000+ glob .render ();
10291001}
10301002
10311003void on_destroy (ANativeActivity* activity)
0 commit comments