diff options
author | StapleButter <thetotalworm@gmail.com> | 2019-05-31 04:15:37 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2019-05-31 04:15:37 +0200 |
commit | 464b1169165b2e4d866c033e4c3288c9742539a8 (patch) | |
tree | a9aeec16f99008fbdfed1ec47d9b636e819697f0 /src | |
parent | d8d7ba9251042fbef425509831fe5b642cf083f1 (diff) |
fix the whole mutex shito
fixes potential crash when resizing window
Diffstat (limited to 'src')
-rw-r--r-- | src/libui_sdl/libui/unix/area.c | 28 | ||||
-rw-r--r-- | src/libui_sdl/libui/unix/gl.c | 33 | ||||
-rw-r--r-- | src/libui_sdl/libui/unix/main.c | 17 | ||||
-rw-r--r-- | src/libui_sdl/libui/unix/uipriv_unix.h | 17 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 6 |
5 files changed, 28 insertions, 73 deletions
diff --git a/src/libui_sdl/libui/unix/area.c b/src/libui_sdl/libui/unix/area.c index 62fe512..5734b4b 100644 --- a/src/libui_sdl/libui/unix/area.c +++ b/src/libui_sdl/libui/unix/area.c @@ -3,6 +3,18 @@ extern GThread* gtkthread; +// notes: +// - G_DECLARE_DERIVABLE/FINAL_INTERFACE() requires glib 2.44 and that's starting with debian stretch (testing) (GTK+ 3.18) and ubuntu 15.04 (GTK+ 3.14) - debian jessie has 2.42 (GTK+ 3.14) +#define areaWidgetType (areaWidget_get_type()) +#define areaWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), areaWidgetType, areaWidget)) +#define isAreaWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), areaWidgetType)) +#define areaWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), areaWidgetType, areaWidgetClass)) +#define isAreaWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), areaWidget)) +#define getAreaWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), areaWidgetType, areaWidgetClass)) + +typedef struct areaWidget areaWidget; +typedef struct areaWidgetClass areaWidgetClass; + struct areaWidget { GtkDrawingArea parent_instance; uiArea *a; @@ -131,22 +143,6 @@ static void loadAreaSize(uiArea *a, double *width, double *height) } } -void areaPreRedraw(areaWidget* widget) -{ - uiArea* a = widget->a; - if (!a->opengl) return; - - areaPreRedrawGL(a->glContext); -} - -void areaPostRedraw(areaWidget* widget) -{ - uiArea* a = widget->a; - if (!a->opengl) return; - - areaPostRedrawGL(a->glContext); -} - static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) { areaWidget *aw = areaWidget(w); diff --git a/src/libui_sdl/libui/unix/gl.c b/src/libui_sdl/libui/unix/gl.c index 0511639..6965969 100644 --- a/src/libui_sdl/libui/unix/gl.c +++ b/src/libui_sdl/libui/unix/gl.c @@ -6,6 +6,7 @@ void* glXGetProcAddressARB(const GLubyte* name); extern GThread* gtkthread; +extern GMutex glmutex; struct uiGLContext { @@ -15,8 +16,6 @@ struct uiGLContext GdkGLContext *gctx; int vermaj, vermin; - GMutex mutex; - int width, height; int scale; GLuint renderbuffer[2][2]; @@ -96,8 +95,6 @@ uiGLContext *createGLContext(GtkWidget* widget, int maj, int min) areaAllocRenderbuffer(ctx); ctx->backbuffer = 0; - g_mutex_init(&ctx->mutex); - ctx->widget = widget; ctx->window = gdkwin; ctx->gctx = gctx; @@ -144,7 +141,7 @@ static void areaAllocRenderbuffer(uiGLContext* glctx) // printf("FRAMEBUFFER IS BAD!! %04X\n", _glCheckFramebufferStatus(GL_FRAMEBUFFER)); } -static void areaRellocRenderbuffer(uiGLContext* glctx) +static void areaReallocRenderbuffer(uiGLContext* glctx) { _glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][0]); _glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale); @@ -157,16 +154,6 @@ static void areaRellocRenderbuffer(uiGLContext* glctx) //_glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, glctx->width*glctx->scale, glctx->height*glctx->scale); } -void areaPreRedrawGL(uiGLContext* glctx) -{ - g_mutex_lock(&glctx->mutex); -} - -void areaPostRedrawGL(uiGLContext* glctx) -{ - g_mutex_unlock(&glctx->mutex); -} - void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx) { int window_scale = gdk_window_get_scale_factor(glctx->window); @@ -176,12 +163,14 @@ void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContex glctx->width = dp->AreaWidth; glctx->height = dp->AreaHeight; glctx->scale = window_scale; - areaRellocRenderbuffer(glctx); + areaReallocRenderbuffer(glctx); + } + else + { + gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(widget), + glctx->renderbuffer[glctx->backbuffer][0], GL_RENDERBUFFER, + 1, 0, 0, glctx->width*glctx->scale, glctx->height*glctx->scale); } - - gdk_cairo_draw_from_gl(cr, gtk_widget_get_window(widget), - glctx->renderbuffer[glctx->backbuffer][0], GL_RENDERBUFFER, - 1, 0, 0, glctx->width*glctx->scale, glctx->height*glctx->scale); } int uiGLGetFramebuffer(uiGLContext* ctx) @@ -215,7 +204,7 @@ void uiGLBegin(uiGLContext* ctx) { if (g_thread_self() != gtkthread) { - g_mutex_lock(&ctx->mutex); + g_mutex_lock(&glmutex); } } @@ -223,7 +212,7 @@ void uiGLEnd(uiGLContext* ctx) { if (g_thread_self() != gtkthread) { - g_mutex_unlock(&ctx->mutex); + g_mutex_unlock(&glmutex); } } diff --git a/src/libui_sdl/libui/unix/main.c b/src/libui_sdl/libui/unix/main.c index 66bd335..516bd76 100644 --- a/src/libui_sdl/libui/unix/main.c +++ b/src/libui_sdl/libui/unix/main.c @@ -5,24 +5,16 @@ uiInitOptions options; // kind of a hack GThread* gtkthread; - GMutex glmutex; -int boub(GtkWidget* w); -void baba(GtkWidget* w); static void _eventfilter(GdkEvent* evt, gpointer data) { if (evt->type == GDK_EXPOSE) { - GtkWidget* widget = gtk_get_event_widget(evt); - if (isAreaWidget(widget)) - { - areaWidget* area = areaWidget(widget); - areaPreRedraw(area); - gtk_main_do_event(evt); - areaPostRedraw(area); - return; - } + g_mutex_lock(&glmutex); + gtk_main_do_event(evt); + g_mutex_unlock(&glmutex); + return; } gtk_main_do_event(evt); @@ -48,6 +40,7 @@ const char *uiInit(uiInitOptions *o) loadFutures(); gtkthread = g_thread_self(); + g_mutex_init(&glmutex); GList* iconlist = NULL; iconlist = g_list_append(iconlist, gdk_pixbuf_new_from_resource("/org/kuriboland/melonDS/icon/melon_16x16.png", NULL)); diff --git a/src/libui_sdl/libui/unix/uipriv_unix.h b/src/libui_sdl/libui/unix/uipriv_unix.h index 6f14091..9b77188 100644 --- a/src/libui_sdl/libui/unix/uipriv_unix.h +++ b/src/libui_sdl/libui/unix/uipriv_unix.h @@ -67,22 +67,5 @@ extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, // gl.c extern uiGLContext *createGLContext(GtkWidget* widget, int maj, int min); extern void freeGLContext(uiGLContext* glctx); -extern void areaPreRedrawGL(uiGLContext* glctx); extern void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx); -extern void areaPostRedrawGL(uiGLContext* glctx); - -// notes: -// - G_DECLARE_DERIVABLE/FINAL_INTERFACE() requires glib 2.44 and that's starting with debian stretch (testing) (GTK+ 3.18) and ubuntu 15.04 (GTK+ 3.14) - debian jessie has 2.42 (GTK+ 3.14) -#define areaWidgetType (areaWidget_get_type()) -#define areaWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), areaWidgetType, areaWidget)) -#define isAreaWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), areaWidgetType)) -#define areaWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), areaWidgetType, areaWidgetClass)) -#define isAreaWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), areaWidget)) -#define getAreaWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), areaWidgetType, areaWidgetClass)) - -typedef struct areaWidget areaWidget; -typedef struct areaWidgetClass areaWidgetClass; - -extern void areaPreRedraw(areaWidget* widget); -extern void areaPostRedraw(areaWidget* widget); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 74d3fc9..6cc6c50 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -430,12 +430,6 @@ void GLScreen_DrawScreen() uiGLSwapBuffers(GLContext); } -void norp(void* data) -{ - uiGLMakeContextCurrent(GLContext); - GLScreen_DrawScreen(); -} - void MicLoadWav(char* name) { SDL_AudioSpec format; |