ANativeWindow: make the while loop hack work on main thread

This commit is contained in:
Mis012
2024-04-17 19:27:16 +02:00
parent db3ba9b929
commit 21627aecad
2 changed files with 4 additions and 1 deletions

View File

@@ -16,7 +16,7 @@ struct native_message_queue {
bool is_main_thread;
};
static GThread *main_thread_id;
GThread *main_thread_id;
void prepare_main_looper(JNIEnv* env) {
main_thread_id = g_thread_self();

View File

@@ -245,6 +245,7 @@ static void on_resize(GtkWidget* self, gint width, gint height, EGLNativeWindowT
}
}
extern GThread *main_thread_id;
ANativeWindow * ANativeWindow_fromSurface(JNIEnv* env, jobject surface)
{
int width;
@@ -265,6 +266,8 @@ ANativeWindow * ANativeWindow_fromSurface(JNIEnv* env, jobject surface)
GtkWidget *window = GTK_WIDGET(gtk_widget_get_native(surface_view_widget));
while( (width = gtk_widget_get_width(surface_view_widget)) == 0 ) {
// FIXME: UGLY: this loop waits until the SurfaceView widget gets mapped
if(g_thread_self() == main_thread_id)
g_main_context_iteration(g_main_context_default(), false);
}
height = gtk_widget_get_height(surface_view_widget);