forked from AuroraMiddleware/gtk
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).
This commit is contained in:
parent
017775f288
commit
fdeb4f8c16
@ -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 >
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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))
|
||||
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);
|
||||
@ -423,7 +423,5 @@ gdk_wayland_display_make_gl_context_current (GdkDisplay *display,
|
||||
|
||||
if (!eglMakeCurrent (display_wayland->egl_display, egl_surface,
|
||||
egl_surface, context_wayland->egl_context))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
g_critical ("eglMakeCurrent failed");
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -219,16 +219,10 @@ gtk_gl_area_realize (GtkWidget *widget)
|
||||
NULL);
|
||||
if (priv->context != NULL)
|
||||
{
|
||||
if (gdk_gl_context_make_current (priv->context))
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user