From fdeb4f8c164bcdc1b54ed46f9e5b7185694ff623 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Thu, 9 Oct 2014 17:24:21 +0200 Subject: [PATCH] gl: Make gdk_gl_context_make_current() return void Its not really reasonable to handle failures to make_current, it basically only happens if you pass invalid arguments to it, and thats not something we trap on similar things on the X drawing side. If GL is not supported that should be handled by the context creation failing, and anything going wrong after that is essentially a critical (or an async X error). --- gdk/gdkdisplay.c | 8 +++---- gdk/gdkdisplayprivate.h | 4 ++-- gdk/gdkgl.c | 3 +-- gdk/gdkglcontext.c | 8 +++---- gdk/gdkglcontext.h | 2 +- gdk/gdkwindow.c | 6 ++--- gdk/wayland/gdkglcontext-wayland.c | 28 +++++++++++------------- gdk/wayland/gdkglcontext-wayland.h | 2 +- gdk/x11/gdkglcontext-x11.c | 30 ++++++++----------------- gdk/x11/gdkglcontext-x11.h | 2 +- gtk/gtkglarea.c | 35 ++++++++++-------------------- gtk/gtkglarea.h | 2 +- tests/gtkgears.c | 13 ++--------- 13 files changed, 52 insertions(+), 91 deletions(-) diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c index f0c5e21398..d6fd187692 100644 --- a/gdk/gdkdisplay.c +++ b/gdk/gdkdisplay.c @@ -2258,17 +2258,15 @@ gdk_display_destroy_gl_context (GdkDisplay *display, * * Makes the given @context the current GL context, or unsets * the current GL context if @context is %NULL. - * - * Returns: %TRUE if successful */ -gboolean +void gdk_display_make_gl_context_current (GdkDisplay *display, GdkGLContext *context) { GdkGLContext *current = gdk_display_get_current_gl_context (display); if (current == context) - return TRUE; + return; if (context == NULL) g_object_set_data (G_OBJECT (display), "-gdk-gl-current-context", NULL); @@ -2277,7 +2275,7 @@ gdk_display_make_gl_context_current (GdkDisplay *display, g_object_ref (context), (GDestroyNotify) g_object_unref); - return GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current (display, context); + GDK_DISPLAY_GET_CLASS (display)->make_gl_context_current (display, context); } /*< private > diff --git a/gdk/gdkdisplayprivate.h b/gdk/gdkdisplayprivate.h index 65f134e9c2..0cd45f856f 100644 --- a/gdk/gdkdisplayprivate.h +++ b/gdk/gdkdisplayprivate.h @@ -225,7 +225,7 @@ struct _GdkDisplayClass gchar * (*utf8_to_string_target) (GdkDisplay *display, const gchar *text); - gboolean (*make_gl_context_current) (GdkDisplay *display, + void (*make_gl_context_current) (GdkDisplay *display, GdkGLContext *context); void (*destroy_gl_context) (GdkDisplay *display, GdkGLContext *context); @@ -310,7 +310,7 @@ GdkWindow * _gdk_display_create_window (GdkDisplay *display void gdk_display_destroy_gl_context (GdkDisplay *display, GdkGLContext *context); -gboolean gdk_display_make_gl_context_current (GdkDisplay *display, +void gdk_display_make_gl_context_current (GdkDisplay *display, GdkGLContext *context); GdkGLContext * gdk_display_get_current_gl_context (GdkDisplay *display); diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c index d9a93d9a50..90a3c1b131 100644 --- a/gdk/gdkgl.c +++ b/gdk/gdkgl.c @@ -98,8 +98,7 @@ gdk_cairo_draw_from_gl (cairo_t *cr, clip_region = gdk_cairo_region_from_clip (cr); - if (!gdk_gl_context_make_current (context)) - g_error ("make current failed"); + gdk_gl_context_make_current (context); glGenFramebuffersEXT (1, &framebuffer); glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer); diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c index 9a5f457ef5..5fbd90569f 100644 --- a/gdk/gdkglcontext.c +++ b/gdk/gdkglcontext.c @@ -270,18 +270,16 @@ gdk_gl_context_flush_buffer (GdkGLContext *context, * * Makes the @context the current one. * - * Returns: %TRUE if the context is current - * * Since: 3.16 */ -gboolean +void gdk_gl_context_make_current (GdkGLContext *context) { GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); - g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE); + g_return_if_fail (GDK_IS_GL_CONTEXT (context)); - return gdk_display_make_gl_context_current (gdk_window_get_display (priv->window), context); + gdk_display_make_gl_context_current (gdk_window_get_display (priv->window), context); } /** diff --git a/gdk/gdkglcontext.h b/gdk/gdkglcontext.h index 9447723051..5dbd57e2c4 100644 --- a/gdk/gdkglcontext.h +++ b/gdk/gdkglcontext.h @@ -48,7 +48,7 @@ GDK_AVAILABLE_IN_3_16 GdkWindow * gdk_gl_context_get_window (GdkGLContext *context); GDK_AVAILABLE_IN_3_16 -gboolean gdk_gl_context_make_current (GdkGLContext *context); +void gdk_gl_context_make_current (GdkGLContext *context); GDK_AVAILABLE_IN_3_16 GdkGLContext * gdk_gl_context_get_current (void); GDK_AVAILABLE_IN_3_16 diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index 21eddf013e..6f76eb5dbc 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -2887,13 +2887,14 @@ gdk_window_begin_paint_region (GdkWindow *window, int wh = gdk_window_get_height (window) * gdk_window_get_scale_factor (window); context = gdk_window_get_paint_gl_context (window, NULL); - if (context == NULL || !gdk_gl_context_make_current (context)) + if (context == NULL) { g_warning ("gl rendering failed, context: %p", context); window->current_paint.use_gl = FALSE; } else { + gdk_gl_context_make_current (context); /* With gl we always need a surface to combine the gl drawing with the native drawing. */ needs_surface = TRUE; @@ -3060,8 +3061,7 @@ gdk_window_end_paint (GdkWindow *window) cairo_region_subtract (opaque_region, window->current_paint.flushed_region); cairo_region_subtract (opaque_region, window->current_paint.need_blend_region); - if (!gdk_gl_context_make_current (window->gl_paint_context)) - g_error ("make current failed"); + gdk_gl_context_make_current (window->gl_paint_context); if (!cairo_region_is_empty (opaque_region)) gdk_gl_texture_from_surface (window->current_paint.surface, diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c index b6f1e9974d..60d4de7bf8 100644 --- a/gdk/wayland/gdkglcontext-wayland.c +++ b/gdk/wayland/gdkglcontext-wayland.c @@ -41,8 +41,7 @@ gdk_wayland_gl_context_update (GdkGLContext *context) GdkWindow *window = gdk_gl_context_get_window (context); int width, height; - if (!gdk_gl_context_make_current (context)) - return; + gdk_gl_context_make_current (context); width = gdk_window_get_width (window); height = gdk_window_get_height (window); @@ -76,10 +75,12 @@ gdk_wayland_window_invalidate_for_new_frame (GdkWindow *window, egl_surface = gdk_wayland_window_get_egl_surface (window->impl_window, context_wayland->egl_config); - if (display_wayland->have_egl_buffer_age && - gdk_gl_context_make_current (window->gl_paint_context)) - eglQuerySurface (display_wayland->egl_display, egl_surface, - EGL_BUFFER_AGE_EXT, &buffer_age); + if (display_wayland->have_egl_buffer_age) + { + gdk_gl_context_make_current (window->gl_paint_context); + eglQuerySurface (display_wayland->egl_display, egl_surface, + EGL_BUFFER_AGE_EXT, &buffer_age); + } invalidate_all = FALSE; if (buffer_age == 0 || buffer_age >= 4) @@ -126,8 +127,7 @@ gdk_wayland_gl_context_flush_buffer (GdkGLContext *context, GdkWaylandGLContext *context_wayland = GDK_WAYLAND_GL_CONTEXT (context); EGLSurface egl_surface; - if (!gdk_gl_context_make_current (context)) - return; + gdk_gl_context_make_current (context); egl_surface = gdk_wayland_window_get_egl_surface (window->impl_window, context_wayland->egl_config); @@ -391,7 +391,7 @@ gdk_wayland_display_destroy_gl_context (GdkDisplay *display, } } -gboolean +void gdk_wayland_display_make_gl_context_current (GdkDisplay *display, GdkGLContext *context) { @@ -404,7 +404,7 @@ gdk_wayland_display_make_gl_context_current (GdkDisplay *display, { eglMakeCurrent(display_wayland->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - return TRUE; + return; } context_wayland = GDK_WAYLAND_GL_CONTEXT (context); @@ -421,9 +421,7 @@ gdk_wayland_display_make_gl_context_current (GdkDisplay *display, context_wayland->egl_config); } - if (!eglMakeCurrent(display_wayland->egl_display, egl_surface, - egl_surface, context_wayland->egl_context)) - return FALSE; - - return TRUE; + if (!eglMakeCurrent (display_wayland->egl_display, egl_surface, + egl_surface, context_wayland->egl_context)) + g_critical ("eglMakeCurrent failed"); } diff --git a/gdk/wayland/gdkglcontext-wayland.h b/gdk/wayland/gdkglcontext-wayland.h index 3d4fe37017..6a7d8797d8 100644 --- a/gdk/wayland/gdkglcontext-wayland.h +++ b/gdk/wayland/gdkglcontext-wayland.h @@ -57,7 +57,7 @@ void gdk_wayland_window_invalidate_for_new_frame (GdkWindow cairo_region_t *update_area); void gdk_wayland_display_destroy_gl_context (GdkDisplay *display, GdkGLContext *context); -gboolean gdk_wayland_display_make_gl_context_current (GdkDisplay *display, +void gdk_wayland_display_make_gl_context_current (GdkDisplay *display, GdkGLContext *context); G_END_DECLS diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c index 4fe2936f25..be18798653 100644 --- a/gdk/x11/gdkglcontext-x11.c +++ b/gdk/x11/gdkglcontext-x11.c @@ -96,8 +96,7 @@ gdk_x11_gl_context_update (GdkGLContext *context) GdkWindow *window = gdk_gl_context_get_window (context); int width, height; - if (!gdk_gl_context_make_current (context)) - return; + gdk_gl_context_make_current (context); width = gdk_window_get_width (window); height = gdk_window_get_height (window); @@ -155,10 +154,12 @@ gdk_x11_window_invalidate_for_new_frame (GdkWindow *window, buffer_age = 0; - if (display_x11->has_glx_buffer_age && - gdk_gl_context_make_current (window->gl_paint_context)) - glXQueryDrawable(dpy, context_x11->drawable, - GLX_BACK_BUFFER_AGE_EXT, &buffer_age); + if (display_x11->has_glx_buffer_age) + { + gdk_gl_context_make_current (window->gl_paint_context); + glXQueryDrawable(dpy, context_x11->drawable, + GLX_BACK_BUFFER_AGE_EXT, &buffer_age); + } invalidate_all = FALSE; if (buffer_age == 0 || buffer_age >= 4) @@ -826,7 +827,7 @@ gdk_x11_display_destroy_gl_context (GdkDisplay *display, } } -gboolean +void gdk_x11_display_make_gl_context_current (GdkDisplay *display, GdkGLContext *context) { @@ -839,14 +840,11 @@ gdk_x11_display_make_gl_context_current (GdkDisplay *display, if (context == NULL) { glXMakeContextCurrent (dpy, None, None, NULL); - return TRUE; + return; } context_x11 = GDK_X11_GL_CONTEXT (context); - if (context_x11->glx_context == NULL) - return FALSE; - window = gdk_gl_context_get_window (context); // If the WM is compositing there is no particular need to delay @@ -862,8 +860,6 @@ gdk_x11_display_make_gl_context_current (GdkDisplay *display, g_print ("Making GLX context current to drawable %lu\n", (unsigned long) context_x11->drawable)); - gdk_x11_display_error_trap_push (display); - glXMakeContextCurrent (dpy, context_x11->drawable, context_x11->drawable, context_x11->glx_context); @@ -874,14 +870,6 @@ gdk_x11_display_make_gl_context_current (GdkDisplay *display, else glXSwapIntervalSGI (0); } - - if (gdk_x11_display_error_trap_pop (display)) - { - g_critical ("X Error received while calling glXMakeContextCurrent()"); - return FALSE; - } - - return TRUE; } /** diff --git a/gdk/x11/gdkglcontext-x11.h b/gdk/x11/gdkglcontext-x11.h index 091783e143..ae7bf2abd0 100644 --- a/gdk/x11/gdkglcontext-x11.h +++ b/gdk/x11/gdkglcontext-x11.h @@ -66,7 +66,7 @@ void gdk_x11_window_invalidate_for_new_frame (GdkWindow cairo_region_t *update_area); void gdk_x11_display_destroy_gl_context (GdkDisplay *display, GdkGLContext *context); -gboolean gdk_x11_display_make_gl_context_current (GdkDisplay *display, +void gdk_x11_display_make_gl_context_current (GdkDisplay *display, GdkGLContext *context); G_END_DECLS diff --git a/gtk/gtkglarea.c b/gtk/gtkglarea.c index 7b3ee28e90..bd8e894310 100644 --- a/gtk/gtkglarea.c +++ b/gtk/gtkglarea.c @@ -219,15 +219,9 @@ gtk_gl_area_realize (GtkWidget *widget) NULL); if (priv->context != NULL) { - if (gdk_gl_context_make_current (priv->context)) - { - glGenFramebuffersEXT (1, &priv->framebuffer); - glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, priv->framebuffer); - } - else - { - g_warning ("Unable to make new context current"); - } + gdk_gl_context_make_current (priv->context); + glGenFramebuffersEXT (1, &priv->framebuffer); + glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, priv->framebuffer); } } @@ -239,8 +233,9 @@ gtk_gl_area_unrealize (GtkWidget *widget) if (priv->context != NULL) { - if (priv->framebuffer != 0 && gtk_gl_area_make_current (self)) + if (priv->framebuffer != 0) { + gtk_gl_area_make_current (self); /* Bind 0, which means render to back buffer, as a result, fb is unbound */ glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); glDeleteFramebuffersEXT (1, &priv->framebuffer); @@ -276,8 +271,7 @@ gtk_gl_area_draw (GtkWidget *widget, if (priv->context == NULL) return FALSE; - if (!gtk_gl_area_make_current (self)) - return FALSE; + gtk_gl_area_make_current (self); scale = gtk_widget_get_scale_factor (widget); w = gtk_widget_get_allocated_width (widget) * scale; @@ -332,8 +326,7 @@ gtk_gl_area_draw (GtkWidget *widget, color_tex ? GL_TEXTURE : GL_RENDERBUFFER, scale, 0, 0, w, h); - if (!gtk_gl_area_make_current (self)) - g_error ("can't make old context current again"); + gtk_gl_area_make_current (self); } else { @@ -613,24 +606,20 @@ gtk_gl_area_get_context (GtkGLArea *area) * #GtkGLArea::render signal, and should not be called by * application code. * - * Returns: %TRUE if the context was associated successfully with - * the widget - * * Since: 3.16 */ -gboolean +void gtk_gl_area_make_current (GtkGLArea *area) { GtkGLAreaPrivate *priv = gtk_gl_area_get_instance_private (area); GtkWidget *widget; - g_return_val_if_fail (GTK_IS_GL_AREA (area), FALSE); + g_return_if_fail (GTK_IS_GL_AREA (area)); widget = GTK_WIDGET (area); - g_return_val_if_fail (gtk_widget_get_realized (widget), FALSE); - if (priv->context == NULL) - return FALSE; + g_return_if_fail (gtk_widget_get_realized (widget)); - return gdk_gl_context_make_current (priv->context); + if (priv->context) + gdk_gl_context_make_current (priv->context); } diff --git a/gtk/gtkglarea.h b/gtk/gtkglarea.h index cb0d4c75c2..559389a029 100644 --- a/gtk/gtkglarea.h +++ b/gtk/gtkglarea.h @@ -98,7 +98,7 @@ GDK_AVAILABLE_IN_3_16 GdkGLContext * gtk_gl_area_get_context (GtkGLArea *area); GDK_AVAILABLE_IN_3_16 -gboolean gtk_gl_area_make_current (GtkGLArea *area); +void gtk_gl_area_make_current (GtkGLArea *area); G_END_DECLS diff --git a/tests/gtkgears.c b/tests/gtkgears.c index f382c613cd..232fd3c2d8 100644 --- a/tests/gtkgears.c +++ b/tests/gtkgears.c @@ -292,12 +292,7 @@ gtk_gears_size_allocate (GtkWidget *widget, if (gtk_widget_get_realized (widget)) { - if (!gtk_gl_area_make_current (glarea)) - { - g_warning ("Unable to make gl context current"); - return; - } - + gtk_gl_area_make_current (glarea); reshape (allocation->width, allocation->height); } } @@ -316,11 +311,7 @@ gtk_gears_realize (GtkWidget *widget) GTK_WIDGET_CLASS (gtk_gears_parent_class)->realize (widget); - if (!gtk_gl_area_make_current (glarea)) - { - g_warning ("Unable to make gl context current"); - return; - } + gtk_gl_area_make_current (glarea); glLightfv(GL_LIGHT0, GL_POSITION, pos); glEnable(GL_CULL_FACE);