fix the whole mutex shito
fixes potential crash when resizing window
This commit is contained in:
parent
d8d7ba9251
commit
464b116916
|
@ -3,6 +3,18 @@
|
||||||
|
|
||||||
extern GThread* gtkthread;
|
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 {
|
struct areaWidget {
|
||||||
GtkDrawingArea parent_instance;
|
GtkDrawingArea parent_instance;
|
||||||
uiArea *a;
|
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)
|
static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr)
|
||||||
{
|
{
|
||||||
areaWidget *aw = areaWidget(w);
|
areaWidget *aw = areaWidget(w);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
void* glXGetProcAddressARB(const GLubyte* name);
|
void* glXGetProcAddressARB(const GLubyte* name);
|
||||||
|
|
||||||
extern GThread* gtkthread;
|
extern GThread* gtkthread;
|
||||||
|
extern GMutex glmutex;
|
||||||
|
|
||||||
struct uiGLContext
|
struct uiGLContext
|
||||||
{
|
{
|
||||||
|
@ -15,8 +16,6 @@ struct uiGLContext
|
||||||
GdkGLContext *gctx;
|
GdkGLContext *gctx;
|
||||||
int vermaj, vermin;
|
int vermaj, vermin;
|
||||||
|
|
||||||
GMutex mutex;
|
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
int scale;
|
int scale;
|
||||||
GLuint renderbuffer[2][2];
|
GLuint renderbuffer[2][2];
|
||||||
|
@ -96,8 +95,6 @@ uiGLContext *createGLContext(GtkWidget* widget, int maj, int min)
|
||||||
areaAllocRenderbuffer(ctx);
|
areaAllocRenderbuffer(ctx);
|
||||||
ctx->backbuffer = 0;
|
ctx->backbuffer = 0;
|
||||||
|
|
||||||
g_mutex_init(&ctx->mutex);
|
|
||||||
|
|
||||||
ctx->widget = widget;
|
ctx->widget = widget;
|
||||||
ctx->window = gdkwin;
|
ctx->window = gdkwin;
|
||||||
ctx->gctx = gctx;
|
ctx->gctx = gctx;
|
||||||
|
@ -144,7 +141,7 @@ static void areaAllocRenderbuffer(uiGLContext* glctx)
|
||||||
// printf("FRAMEBUFFER IS BAD!! %04X\n", _glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
// 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]);
|
_glBindRenderbuffer(GL_RENDERBUFFER, glctx->renderbuffer[0][0]);
|
||||||
_glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, glctx->width*glctx->scale, glctx->height*glctx->scale);
|
_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);
|
//_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)
|
void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, uiGLContext* glctx)
|
||||||
{
|
{
|
||||||
int window_scale = gdk_window_get_scale_factor(glctx->window);
|
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->width = dp->AreaWidth;
|
||||||
glctx->height = dp->AreaHeight;
|
glctx->height = dp->AreaHeight;
|
||||||
glctx->scale = window_scale;
|
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)
|
int uiGLGetFramebuffer(uiGLContext* ctx)
|
||||||
|
@ -215,7 +204,7 @@ void uiGLBegin(uiGLContext* ctx)
|
||||||
{
|
{
|
||||||
if (g_thread_self() != gtkthread)
|
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)
|
if (g_thread_self() != gtkthread)
|
||||||
{
|
{
|
||||||
g_mutex_unlock(&ctx->mutex);
|
g_mutex_unlock(&glmutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,24 +5,16 @@ uiInitOptions options;
|
||||||
|
|
||||||
// kind of a hack
|
// kind of a hack
|
||||||
GThread* gtkthread;
|
GThread* gtkthread;
|
||||||
|
|
||||||
GMutex glmutex;
|
GMutex glmutex;
|
||||||
int boub(GtkWidget* w);
|
|
||||||
void baba(GtkWidget* w);
|
|
||||||
|
|
||||||
static void _eventfilter(GdkEvent* evt, gpointer data)
|
static void _eventfilter(GdkEvent* evt, gpointer data)
|
||||||
{
|
{
|
||||||
if (evt->type == GDK_EXPOSE)
|
if (evt->type == GDK_EXPOSE)
|
||||||
{
|
{
|
||||||
GtkWidget* widget = gtk_get_event_widget(evt);
|
g_mutex_lock(&glmutex);
|
||||||
if (isAreaWidget(widget))
|
gtk_main_do_event(evt);
|
||||||
{
|
g_mutex_unlock(&glmutex);
|
||||||
areaWidget* area = areaWidget(widget);
|
return;
|
||||||
areaPreRedraw(area);
|
|
||||||
gtk_main_do_event(evt);
|
|
||||||
areaPostRedraw(area);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_main_do_event(evt);
|
gtk_main_do_event(evt);
|
||||||
|
@ -48,6 +40,7 @@ const char *uiInit(uiInitOptions *o)
|
||||||
loadFutures();
|
loadFutures();
|
||||||
|
|
||||||
gtkthread = g_thread_self();
|
gtkthread = g_thread_self();
|
||||||
|
g_mutex_init(&glmutex);
|
||||||
|
|
||||||
GList* iconlist = NULL;
|
GList* iconlist = NULL;
|
||||||
iconlist = g_list_append(iconlist, gdk_pixbuf_new_from_resource("/org/kuriboland/melonDS/icon/melon_16x16.png", NULL));
|
iconlist = g_list_append(iconlist, gdk_pixbuf_new_from_resource("/org/kuriboland/melonDS/icon/melon_16x16.png", NULL));
|
||||||
|
|
|
@ -67,22 +67,5 @@ extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path,
|
||||||
// gl.c
|
// gl.c
|
||||||
extern uiGLContext *createGLContext(GtkWidget* widget, int maj, int min);
|
extern uiGLContext *createGLContext(GtkWidget* widget, int maj, int min);
|
||||||
extern void freeGLContext(uiGLContext* glctx);
|
extern void freeGLContext(uiGLContext* glctx);
|
||||||
extern void areaPreRedrawGL(uiGLContext* glctx);
|
|
||||||
extern void areaDrawGL(GtkWidget* widget, uiAreaDrawParams* dp, cairo_t* cr, 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);
|
|
||||||
|
|
||||||
|
|
|
@ -430,12 +430,6 @@ void GLScreen_DrawScreen()
|
||||||
uiGLSwapBuffers(GLContext);
|
uiGLSwapBuffers(GLContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void norp(void* data)
|
|
||||||
{
|
|
||||||
uiGLMakeContextCurrent(GLContext);
|
|
||||||
GLScreen_DrawScreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MicLoadWav(char* name)
|
void MicLoadWav(char* name)
|
||||||
{
|
{
|
||||||
SDL_AudioSpec format;
|
SDL_AudioSpec format;
|
||||||
|
|
Loading…
Reference in New Issue