implement some stuff to make exaple SDL app run

NOTE: the main addition in this commit is WIP support for apps which
render on an EGL surface obtained using ANativeWindow_fromSurface

currently, this EGL surface is obtained by creating a 700x700 pixel
window with GLFW (the 700x700 size is hardcoded in several places)
and only Wayland is supported

ideally, we'd want to use a wayland subsurface to position the EGL
surface above the Surface widget it's associated with (and do
whatever for X11)
This commit is contained in:
Mis012
2022-10-26 18:39:04 +02:00
parent 3627f35bd5
commit b801f0fb3c
26 changed files with 1552 additions and 161 deletions

View File

@@ -0,0 +1,163 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class android_view_SurfaceView */
#ifndef _Included_android_view_SurfaceView
#define _Included_android_view_SurfaceView
#ifdef __cplusplus
extern "C" {
#endif
#undef android_view_SurfaceView_NO_ID
#define android_view_SurfaceView_NO_ID -1L
#undef android_view_SurfaceView_NOT_FOCUSABLE
#define android_view_SurfaceView_NOT_FOCUSABLE 0L
#undef android_view_SurfaceView_FOCUSABLE
#define android_view_SurfaceView_FOCUSABLE 1L
#undef android_view_SurfaceView_FOCUSABLE_MASK
#define android_view_SurfaceView_FOCUSABLE_MASK 1L
#undef android_view_SurfaceView_FITS_SYSTEM_WINDOWS
#define android_view_SurfaceView_FITS_SYSTEM_WINDOWS 2L
#undef android_view_SurfaceView_VISIBLE
#define android_view_SurfaceView_VISIBLE 0L
#undef android_view_SurfaceView_INVISIBLE
#define android_view_SurfaceView_INVISIBLE 4L
#undef android_view_SurfaceView_GONE
#define android_view_SurfaceView_GONE 8L
#undef android_view_SurfaceView_VISIBILITY_MASK
#define android_view_SurfaceView_VISIBILITY_MASK 12L
#undef android_view_SurfaceView_ENABLED
#define android_view_SurfaceView_ENABLED 0L
#undef android_view_SurfaceView_DISABLED
#define android_view_SurfaceView_DISABLED 32L
#undef android_view_SurfaceView_ENABLED_MASK
#define android_view_SurfaceView_ENABLED_MASK 32L
#undef android_view_SurfaceView_WILL_NOT_DRAW
#define android_view_SurfaceView_WILL_NOT_DRAW 128L
#undef android_view_SurfaceView_DRAW_MASK
#define android_view_SurfaceView_DRAW_MASK 128L
#undef android_view_SurfaceView_SCROLLBARS_NONE
#define android_view_SurfaceView_SCROLLBARS_NONE 0L
#undef android_view_SurfaceView_SCROLLBARS_HORIZONTAL
#define android_view_SurfaceView_SCROLLBARS_HORIZONTAL 256L
#undef android_view_SurfaceView_SCROLLBARS_VERTICAL
#define android_view_SurfaceView_SCROLLBARS_VERTICAL 512L
#undef android_view_SurfaceView_SCROLLBARS_MASK
#define android_view_SurfaceView_SCROLLBARS_MASK 768L
#undef android_view_SurfaceView_FILTER_TOUCHES_WHEN_OBSCURED
#define android_view_SurfaceView_FILTER_TOUCHES_WHEN_OBSCURED 1024L
#undef android_view_SurfaceView_OPTIONAL_FITS_SYSTEM_WINDOWS
#define android_view_SurfaceView_OPTIONAL_FITS_SYSTEM_WINDOWS 2048L
#undef android_view_SurfaceView_FADING_EDGE_NONE
#define android_view_SurfaceView_FADING_EDGE_NONE 0L
#undef android_view_SurfaceView_FADING_EDGE_HORIZONTAL
#define android_view_SurfaceView_FADING_EDGE_HORIZONTAL 4096L
#undef android_view_SurfaceView_FADING_EDGE_VERTICAL
#define android_view_SurfaceView_FADING_EDGE_VERTICAL 8192L
#undef android_view_SurfaceView_FADING_EDGE_MASK
#define android_view_SurfaceView_FADING_EDGE_MASK 12288L
#undef android_view_SurfaceView_CLICKABLE
#define android_view_SurfaceView_CLICKABLE 16384L
#undef android_view_SurfaceView_DRAWING_CACHE_ENABLED
#define android_view_SurfaceView_DRAWING_CACHE_ENABLED 32768L
#undef android_view_SurfaceView_SAVE_DISABLED
#define android_view_SurfaceView_SAVE_DISABLED 65536L
#undef android_view_SurfaceView_SAVE_DISABLED_MASK
#define android_view_SurfaceView_SAVE_DISABLED_MASK 65536L
#undef android_view_SurfaceView_WILL_NOT_CACHE_DRAWING
#define android_view_SurfaceView_WILL_NOT_CACHE_DRAWING 131072L
#undef android_view_SurfaceView_FOCUSABLE_IN_TOUCH_MODE
#define android_view_SurfaceView_FOCUSABLE_IN_TOUCH_MODE 262144L
#undef android_view_SurfaceView_DRAWING_CACHE_QUALITY_LOW
#define android_view_SurfaceView_DRAWING_CACHE_QUALITY_LOW 524288L
#undef android_view_SurfaceView_DRAWING_CACHE_QUALITY_HIGH
#define android_view_SurfaceView_DRAWING_CACHE_QUALITY_HIGH 1048576L
#undef android_view_SurfaceView_DRAWING_CACHE_QUALITY_AUTO
#define android_view_SurfaceView_DRAWING_CACHE_QUALITY_AUTO 0L
#undef android_view_SurfaceView_DRAWING_CACHE_QUALITY_MASK
#define android_view_SurfaceView_DRAWING_CACHE_QUALITY_MASK 1572864L
#undef android_view_SurfaceView_LONG_CLICKABLE
#define android_view_SurfaceView_LONG_CLICKABLE 2097152L
#undef android_view_SurfaceView_DUPLICATE_PARENT_STATE
#define android_view_SurfaceView_DUPLICATE_PARENT_STATE 4194304L
#undef android_view_SurfaceView_SCROLLBARS_INSIDE_OVERLAY
#define android_view_SurfaceView_SCROLLBARS_INSIDE_OVERLAY 0L
#undef android_view_SurfaceView_SCROLLBARS_INSIDE_INSET
#define android_view_SurfaceView_SCROLLBARS_INSIDE_INSET 16777216L
#undef android_view_SurfaceView_SCROLLBARS_OUTSIDE_OVERLAY
#define android_view_SurfaceView_SCROLLBARS_OUTSIDE_OVERLAY 33554432L
#undef android_view_SurfaceView_SCROLLBARS_OUTSIDE_INSET
#define android_view_SurfaceView_SCROLLBARS_OUTSIDE_INSET 50331648L
#undef android_view_SurfaceView_SCROLLBARS_INSET_MASK
#define android_view_SurfaceView_SCROLLBARS_INSET_MASK 16777216L
#undef android_view_SurfaceView_SCROLLBARS_OUTSIDE_MASK
#define android_view_SurfaceView_SCROLLBARS_OUTSIDE_MASK 33554432L
#undef android_view_SurfaceView_SCROLLBARS_STYLE_MASK
#define android_view_SurfaceView_SCROLLBARS_STYLE_MASK 50331648L
#undef android_view_SurfaceView_KEEP_SCREEN_ON
#define android_view_SurfaceView_KEEP_SCREEN_ON 67108864L
#undef android_view_SurfaceView_SOUND_EFFECTS_ENABLED
#define android_view_SurfaceView_SOUND_EFFECTS_ENABLED 134217728L
#undef android_view_SurfaceView_HAPTIC_FEEDBACK_ENABLED
#define android_view_SurfaceView_HAPTIC_FEEDBACK_ENABLED 268435456L
#undef android_view_SurfaceView_PARENT_SAVE_DISABLED
#define android_view_SurfaceView_PARENT_SAVE_DISABLED 536870912L
#undef android_view_SurfaceView_PARENT_SAVE_DISABLED_MASK
#define android_view_SurfaceView_PARENT_SAVE_DISABLED_MASK 536870912L
#undef android_view_SurfaceView_FOCUSABLES_ALL
#define android_view_SurfaceView_FOCUSABLES_ALL 0L
#undef android_view_SurfaceView_FOCUSABLES_TOUCH_MODE
#define android_view_SurfaceView_FOCUSABLES_TOUCH_MODE 1L
#undef android_view_SurfaceView_FOCUS_BACKWARD
#define android_view_SurfaceView_FOCUS_BACKWARD 1L
#undef android_view_SurfaceView_FOCUS_FORWARD
#define android_view_SurfaceView_FOCUS_FORWARD 2L
#undef android_view_SurfaceView_FOCUS_LEFT
#define android_view_SurfaceView_FOCUS_LEFT 17L
#undef android_view_SurfaceView_FOCUS_UP
#define android_view_SurfaceView_FOCUS_UP 33L
#undef android_view_SurfaceView_FOCUS_RIGHT
#define android_view_SurfaceView_FOCUS_RIGHT 66L
#undef android_view_SurfaceView_FOCUS_DOWN
#define android_view_SurfaceView_FOCUS_DOWN 130L
#undef android_view_SurfaceView_MEASURED_SIZE_MASK
#define android_view_SurfaceView_MEASURED_SIZE_MASK 16777215L
#undef android_view_SurfaceView_MEASURED_STATE_MASK
#define android_view_SurfaceView_MEASURED_STATE_MASK -16777216L
#undef android_view_SurfaceView_MEASURED_HEIGHT_STATE_SHIFT
#define android_view_SurfaceView_MEASURED_HEIGHT_STATE_SHIFT 16L
#undef android_view_SurfaceView_MEASURED_STATE_TOO_SMALL
#define android_view_SurfaceView_MEASURED_STATE_TOO_SMALL 16777216L
#undef android_view_SurfaceView_PFLAG2_DRAG_CAN_ACCEPT
#define android_view_SurfaceView_PFLAG2_DRAG_CAN_ACCEPT 1L
#undef android_view_SurfaceView_PFLAG2_DRAG_HOVERED
#define android_view_SurfaceView_PFLAG2_DRAG_HOVERED 2L
#undef android_view_SurfaceView_LAYOUT_DIRECTION_LTR
#define android_view_SurfaceView_LAYOUT_DIRECTION_LTR 0L
#undef android_view_SurfaceView_LAYOUT_DIRECTION_RTL
#define android_view_SurfaceView_LAYOUT_DIRECTION_RTL 1L
#undef android_view_SurfaceView_LAYOUT_DIRECTION_INHERIT
#define android_view_SurfaceView_LAYOUT_DIRECTION_INHERIT 2L
#undef android_view_SurfaceView_LAYOUT_DIRECTION_LOCALE
#define android_view_SurfaceView_LAYOUT_DIRECTION_LOCALE 3L
#undef android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT
#define android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT 2L
#undef android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_MASK
#define android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_MASK 12L
#undef android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL
#define android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL 16L
#undef android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_RESOLVED
#define android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_RESOLVED 32L
#undef android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK
#define android_view_SurfaceView_PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK 48L
/*
* Class: android_view_SurfaceView
* Method: native_constructor
* Signature: (Landroid/content/Context;)V
*/
JNIEXPORT void JNICALL Java_android_view_SurfaceView_native_1constructor
(JNIEnv *, jobject, jobject);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -27,7 +27,8 @@ void set_up_handle_cache(JNIEnv *env, char *apk_main_activity_class)
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
handle_cache.apk_main_activity.onCreate = _METHOD(handle_cache.apk_main_activity.class, "onCreate", "(Landroid/os/Bundle;)V");
// handle_cache.apk_main_activity.onWindowFocusChanged = _METHOD(handle_cache.apk_main_activity.class, "onWindowFocusChanged", "(B)V");
handle_cache.apk_main_activity.onWindowFocusChanged = _METHOD(handle_cache.apk_main_activity.class, "onWindowFocusChanged", "(Z)V");
handle_cache.apk_main_activity.onResume = _METHOD(handle_cache.apk_main_activity.class, "onResume", "()V");
handle_cache.apk_main_activity.onDestroy = _METHOD(handle_cache.apk_main_activity.class, "onDestroy", "()V");
handle_cache.apk_main_activity.set_window = _METHOD((*env)->FindClass(env, "android/app/Activity"), "set_window", "(J)V");

View File

@@ -10,6 +10,7 @@ struct handle_cache {
jclass class;
jobject object;
jmethodID onCreate;
jmethodID onResume;
jmethodID onWindowFocusChanged;
jmethodID onDestroy;
jmethodID set_window;

View File

@@ -192,7 +192,7 @@ static void draw_function(GtkDrawingArea *area, cairo_t *cr, int width, int heig
(*env)->ExceptionDescribe(env);
}
void on_mapped(GtkWidget* self, struct jni_callback_data *d)
static void on_mapped(GtkWidget* self, struct jni_callback_data *d)
{
JNIEnv *env;
(*d->jvm)->GetEnv(d->jvm, (void**)&env, JNI_VERSION_1_6);
@@ -200,6 +200,7 @@ void on_mapped(GtkWidget* self, struct jni_callback_data *d)
(*env)->CallVoidMethod(env, d->this, _METHOD(d->this_class, "onMeasure", "(II)V"), gtk_widget_get_width(self), gtk_widget_get_height(self));
}
// FIXME: this is used in one other place as well, should probably go in util.c or gtk_util.c?
gboolean tick_callback(GtkWidget* widget, GdkFrameClock* frame_clock, gpointer user_data)
{
gtk_widget_queue_draw(widget);

View File

@@ -0,0 +1,38 @@
#include <gtk/gtk.h>
#include "../defines.h"
#include "../util.h"
#include "WrapperWidget.h"
#include "../generated_headers/android_view_SurfaceView.h"
struct jni_callback_data { JavaVM *jvm; jobject this; jclass this_class;};
static void on_mapped(GtkWidget* self, struct jni_callback_data *d)
{
JNIEnv *env;
(*d->jvm)->GetEnv(d->jvm, (void**)&env, JNI_VERSION_1_6);
(*env)->CallVoidMethod(env, d->this, _METHOD(d->this_class, "surfaceChanged", "(Landroid/view/SurfaceHolder;III)V"), _GET_OBJ_FIELD(d->this, "mSurfaceHolder", "Landroid/view/SurfaceHolder;"), 1 /*RGBA_8888*/, /*FIXME*/700, /*FIXME*/700);
}
JNIEXPORT void JNICALL Java_android_view_SurfaceView_native_1constructor(JNIEnv *env, jobject this, jobject context)
{
GtkWidget *wrapper = wrapper_widget_new();
GtkWidget *dummy = gtk_fixed_new();
gtk_widget_set_name(dummy, "dummy widget for SurfaceView");
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), dummy);
JavaVM *jvm;
(*env)->GetJavaVM(env, &jvm);
struct jni_callback_data *callback_data = malloc(sizeof(struct jni_callback_data));
callback_data->jvm = jvm;
callback_data->this = _REF(this);
callback_data->this_class = _REF(_CLASS(this));
g_signal_connect(dummy, "map", G_CALLBACK(on_mapped), callback_data);
_SET_LONG_FIELD(this, "widget", _INTPTR(dummy));
}