Skip to content

Commit 6da5f7a

Browse files
committed
stuff
1 parent 4e1f40e commit 6da5f7a

8 files changed

Lines changed: 91 additions & 50 deletions

File tree

src/ruisapp/glue/android/application.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
#include "android_globals.hxx"
44
#include "asset_file.hxx"
55

6+
application_glue::application_glue(utki::version_duplet gl_version) :
7+
gl_version(std::move(gl_version))
8+
{}
9+
610
std::unique_ptr<papki::file> ruisapp::application::get_res_file(std::string_view path) const
711
{
8-
utki::assert(android_globals_wrapper::native_activity, SL);
9-
utki::assert(android_globals_wrapper::native_activity->assetManager, SL);
12+
utki::assert(globals_wrapper::native_activity, SL);
13+
utki::assert(globals_wrapper::native_activity->assetManager, SL);
1014

1115
return std::make_unique<asset_file>(
12-
android_globals_wrapper::native_activity->assetManager, //
16+
globals_wrapper::native_activity->assetManager, //
1317
path
1418
);
1519
}

src/ruisapp/glue/android/application.hxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ namespace {
99
class app_window : public ruisapp::window
1010
{
1111
public:
12+
utki::shared_ref<native_window> ruis_native_Window;
13+
1214
};
1315
} // namespace
1416

1517
namespace {
1618
class application_glue : public utki::destructable
1719
{
20+
const utki::version_duplet gl_version;
21+
22+
// Only one window on android.
23+
std::optional<app_window> window;
1824
public:
1925
utki::shared_ref<ruis::updater> updater = utki::make_shared<ruis::updater>();
26+
27+
application_glue(utki::version_duplet gl_version);
2028
};
2129
} // namespace
2230

src/ruisapp/glue/android/android_globals.cxx renamed to src/ruisapp/glue/android/globals.cxx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
#include "android_globals.hxx"
22

3-
void android_globals_wrapper::create(ANativeActivity* native_activity)
3+
void globals_wrapper::create(ANativeActivity* activity)
44
{
5-
utki::assert(native_activity, SL);
6-
utki::assert(!native_activity->instance, SL);
5+
utki::assert(activity, SL);
6+
utki::assert(!activity->instance, SL);
77

8-
utki::assert(!android_globals_wrapper::native_activity, SL);
8+
utki::assert(!globals_wrapper::native_activity, SL);
99

1010
try {
11-
android_globals_wrapper::native_activity = native_activity;
11+
globals_wrapper::native_activity = activity;
1212

13-
native_activity->instance = new android_globals_wrapper();
13+
activity->instance = new globals_wrapper();
1414
} catch (...) {
15-
android_globals_wrapper::native_activity = nullptr;
15+
globals_wrapper::native_activity = nullptr;
1616
throw;
1717
}
1818
}
1919

20-
void android_globals_wrapper::destroy()
20+
void globals_wrapper::destroy()
2121
{
22-
utki::assert(android_globals_wrapper::native_activity, SL);
23-
utki::assert(android_globals_wrapper::native_activity->instance, SL);
22+
utki::assert(globals_wrapper::native_activity, SL);
23+
utki::assert(globals_wrapper::native_activity->instance, SL);
2424

25-
auto wrapper = static_cast<android_globals_wrapper*>(android_globals_wrapper::native_activity->instance);
25+
auto wrapper = static_cast<globals_wrapper*>(globals_wrapper::native_activity->instance);
2626
delete wrapper;
2727

28-
android_globals_wrapper::native_activity->instance = nullptr;
29-
android_globals_wrapper::native_activity = nullptr;
28+
globals_wrapper::native_activity->instance = nullptr;
29+
globals_wrapper::native_activity = nullptr;
3030
}
3131

3232
namespace {
@@ -79,7 +79,7 @@ int on_update_timer_expired(
7979
}
8080
} // namespace
8181

82-
android_globals_wrapper()
82+
globals_wrapper()
8383
{
8484
// add timer descriptor to looper, this is needed for updatable to work
8585
if (ALooper_addFd(
@@ -108,7 +108,7 @@ android_globals_wrapper()
108108
}
109109
}
110110

111-
~android_globals_wrapper()
111+
~globals_wrapper()
112112
{
113113
// remove UI message queue descriptor from looper
114114
ALooper_removeFd(

src/ruisapp/glue/android/android_globals.hxx renamed to src/ruisapp/glue/android/globals.hxx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@
1313
#include "linux_timer.hxx"
1414

1515
namespace {
16-
struct android_globals_wrapper final {
16+
struct globals_wrapper final {
1717
static ANativeActivity* native_activity = nullptr;
1818

19-
static void create(ANativeActivity* native_activity);
19+
static void create(ANativeActivity* activity);
2020
static void destroy();
2121

22-
static android_globals_wrapper& get()
22+
static globals_wrapper& get()
2323
{
2424
utki::assert(native_activity, SL);
2525
utki::assert(native_activity->instance, SL);
2626
return
2727
}
2828

29-
android_globals_wrapper();
29+
globals_wrapper();
3030

31-
android_globals_wrapper(const android_globals_wrapper&) = delete;
32-
android_globals_wrapper& operator=(const android_globals_wrapper&) = delete;
31+
globals_wrapper(const globals_wrapper&) = delete;
32+
globals_wrapper& operator=(const globals_wrapper&) = delete;
3333

34-
android_globals_wrapper(android_globals_wrapper&&) = delete;
35-
android_globals_wrapper& operator=(android_globals_wrapper&&) = delete;
34+
globals_wrapper(globals_wrapper&&) = delete;
35+
globals_wrapper& operator=(globals_wrapper&&) = delete;
3636

37-
~android_globals_wrapper();
37+
~globals_wrapper();
3838

3939
java_functions_wrapper java_functions;
4040

@@ -58,16 +58,18 @@ struct android_globals_wrapper final {
5858
AInputQueue* input_queue = nullptr;
5959
ANativeWindow* android_window = nullptr;
6060

61+
ruis::vector2 cur_window_dims(0, 0);
62+
6163
std::unique_ptr<ruisapp::application> app;
6264
};
6365
} // namespace
6466

6567
namespace {
66-
inline android_globals_wrapper& get_glob()
68+
inline globals_wrapper& get_glob()
6769
{
68-
auto na = android_globals_wrapper::native_activity;
70+
auto na = globals_wrapper::native_activity;
6971
utki::assert(na, SL);
7072
utki::assert(na->instance, SL);
71-
return *static_cast<android_globals_wrapper*>(na->instance);
73+
return *static_cast<globals_wrapper*>(na->instance);
7274
}
7375
} // namespace

src/ruisapp/glue/android/glue.cxx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1919

2020
/* ================ LICENSE END ================ */
2121

22-
#include "android_globals.hxx"
22+
#include "globals.hxx"
2323

2424
// TODO: remove
2525
using namespace ruisapp;
2626

27-
namesapce
27+
namespace
2828
{
2929
// struct window_wrapper : public utki::destructable {
3030
// // EGLDisplay display;
@@ -232,8 +232,6 @@ namesapce
232232
// return get_impl(get_window_pimpl(app));
233233
// }
234234

235-
ruis::vector2 cur_window_dims(0, 0);
236-
237235
// array of current pointer positions, needed to detect which pointers have
238236
// actually moved.
239237
std::array<ruis::vector2, 10> pointers;
@@ -243,7 +241,10 @@ namesapce
243241
const ruis::vector2& p
244242
)
245243
{
246-
ruis::vector2 ret(p.x(), p.y() - (cur_window_dims.y() - win_dim.y()));
244+
auto& glob = get_glob();
245+
246+
ruis::vector2 ret(p.x(), //
247+
p.y() - (glob.cur_window_dims.y() - win_dim.y()));
247248
// utki::log_debug([&](auto&o){o << "android_win_coords_to_ruis_win_rect_coords(): ret
248249
//= " << ret << std::endl;});
249250
using std::round;
@@ -725,8 +726,8 @@ void on_stop(ANativeActivity* activity)
725726

726727
void on_configuration_changed(ANativeActivity* activity)
727728
{
728-
utki::assert(android_globals_wrapper::native_activity, SL);
729-
utki::assert(activity == android_globals_wrapper::native_activity, SL);
729+
utki::assert(globals_wrapper::native_activity, SL);
730+
utki::assert(activity == globals_wrapper::native_activity, SL);
730731

731732
utki::log_debug([](auto& o) {
732733
o << "on_configuration_changed(): invoked" << std::endl;
@@ -752,7 +753,7 @@ void on_configuration_changed(ANativeActivity* activity)
752753
case ACONFIGURATION_ORIENTATION_LAND:
753754
case ACONFIGURATION_ORIENTATION_PORT:
754755
using std::swap;
755-
swap(cur_window_dims.x(), cur_window_dims.y());
756+
swap(glob.cur_window_dims.x(), glob.cur_window_dims.y());
756757
break;
757758
case ACONFIGURATION_ORIENTATION_SQUARE:
758759
// do nothing
@@ -788,8 +789,8 @@ void on_native_window_created(
788789
ANativeWindow* window
789790
)
790791
{
791-
utki::assert(android_globals_wrapper::native_activity, SL);
792-
utki::assert(activity == android_globals_wrapper::native_activity, SL);
792+
utki::assert(globals_wrapper::native_activity, SL);
793+
utki::assert(activity == globals_wrapper::native_activity, SL);
793794

794795
utki::log_debug([](auto& o) {
795796
o << "on_native_window_created(): invoked" << std::endl;
@@ -800,8 +801,8 @@ void on_native_window_created(
800801
// save window in a static var, so it is accessible for creating window surface
801802
glob.android_window = window;
802803

803-
cur_window_dims.x() = float(ANativeWindow_getWidth(window));
804-
cur_window_dims.y() = float(ANativeWindow_getHeight(window));
804+
glob.cur_window_dims.x() = float(ANativeWindow_getWidth(window));
805+
glob.cur_window_dims.y() = float(ANativeWindow_getHeight(window));
805806

806807
// If we have no application instance yet, create it now.
807808
// Otherwise the window was re-created after moving the app from background to foreground
@@ -848,11 +849,11 @@ void on_native_window_resized(ANativeActivity* activity,//
848849
});
849850

850851
// save window dimensions
851-
cur_window_dims.x() = float(ANativeWindow_getWidth(window));
852-
cur_window_dims.y() = float(ANativeWindow_getHeight(window));
852+
glob.cur_window_dims.x() = float(ANativeWindow_getWidth(window));
853+
glob.cur_window_dims.y() = float(ANativeWindow_getHeight(window));
853854

854855
utki::log_debug([&](auto& o) {
855-
o << "on_native_window_resized(): cur_window_dims = " << cur_window_dims << std::endl;
856+
o << "on_native_window_resized(): cur_window_dims = " << glob.cur_window_dims << std::endl;
856857
});
857858
}
858859

@@ -988,12 +989,14 @@ void on_content_rect_changed(
988989
const ARect* rect
989990
)
990991
{
992+
auto& glob = get_glob();
993+
991994
utki::log_debug([&](auto& o) {
992995
o << "on_content_rect_changed(): invoked, left = " << rect->left << " right = " << rect->right
993996
<< " top = " << rect->top << " bottom = " << rect->bottom << std::endl;
994997
});
995998
utki::log_debug([&](auto& o) {
996-
o << "on_content_rect_changed(): cur_window_dims = " << cur_window_dims << std::endl;
999+
o << "on_content_rect_changed(): cur_window_dims = " << glob.cur_window_dims << std::endl;
9971000
});
9981001

9991002
// Sometimes Android calls on_content_rect_changed() even after native window
@@ -1015,7 +1018,7 @@ void on_content_rect_changed(
10151018
app,
10161019
ruis::rect(
10171020
float(rect->left),
1018-
cur_window_dims.y() - float(rect->bottom),
1021+
glob.cur_window_dims.y() - float(rect->bottom),
10191022
float(rect->right - rect->left),
10201023
float(rect->bottom - rect->top)
10211024
)
@@ -1031,7 +1034,7 @@ void on_destroy(ANativeActivity* activity)
10311034
o << "on_destroy(): invoked" << std::endl;
10321035
});
10331036

1034-
android_globals_wrapper::destroy();
1037+
globals_wrapper::destroy();
10351038
}
10361039
} // namespace
10371040

@@ -1062,5 +1065,5 @@ void ANativeActivity_onCreate(
10621065
activity->callbacks->onInputQueueDestroyed = &on_input_queue_destroyed;
10631066
activity->callbacks->onContentRectChanged = &on_content_rect_changed;
10641067

1065-
android_globals_wrapper::create(activity);
1068+
globals_wrapper::create(activity);
10661069
}

src/ruisapp/glue/android/java_functions.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
java_functions_wrapper::java_functions_wrapper()
88
{
9-
auto a = android_globals_wrapper::native_activity;
9+
auto a = globals_wrapper::native_activity;
1010

1111
this->env = a->env;
1212
this->obj = a->clazz;

src/ruisapp/glue/android/window.cxx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
#include "window.hxx"
22

3+
native_window::native_window(
4+
const utki::version_duplet& gl_version,//
5+
const ruisapp::window_parameters& window_params
6+
) :
7+
egl_config(
8+
this->egl_display, //
9+
gl_version,
10+
window_params
11+
),
12+
egl_context(
13+
this->egl_display, //
14+
gl_version,
15+
this->egl_config,
16+
EGL_NO_CONTEXT // no shared context
17+
)
18+
{}
19+
320
void native_window::swap_frame_buffers(){
421
if(this->egl_surface.has_value()){
522
this->egl_surface.value().swap_frame_buffers();

src/ruisapp/glue/android/window.hxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <ruis/render/native_window.hpp>
44

5+
#include "../../window.hpp"
6+
57
#include "../egl_utils.hxx"
68

79
namespace {
@@ -14,6 +16,11 @@ class native_window : public ruis::render::native_window
1416
std::optional<egl_surface_wrapper> egl_surface;
1517

1618
public:
19+
native_window(
20+
const utki::version_duplet& gl_version,//
21+
const ruisapp::window_parameters& window_params
22+
);
23+
1724
void swap_frame_buffers()override;
1825

1926
void create_surface();

0 commit comments

Comments
 (0)