glcontext: Store the buffer age regions in the GL context

That way, we can store the right region there: The actual painted area
instead of the exposed area (which is way too small).

Also, the GL context is the only user of this data, so storing it there
seems way smarter.
This commit is contained in:
Benjamin Otte
2018-04-09 00:58:31 +02:00
parent c8e38c6065
commit bb8f6f87ae
6 changed files with 42 additions and 45 deletions

View File

@@ -133,6 +133,17 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GdkGLContext, gdk_gl_context, GDK_TYPE_DRAW
static GPrivate thread_current_context = G_PRIVATE_INIT (g_object_unref);
static void
gdk_gl_context_clear_old_updated_area (GdkGLContext *context)
{
int i;
for (i = 0; i < 2; i++)
{
g_clear_pointer (&context->old_updated_area[i], cairo_region_destroy);
}
}
static void
gdk_gl_context_dispose (GObject *gobject)
{
@@ -140,6 +151,8 @@ gdk_gl_context_dispose (GObject *gobject)
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
GdkGLContext *current;
gdk_gl_context_clear_old_updated_area (context);
current = g_private_get (&thread_current_context);
if (current == context)
g_private_replace (&thread_current_context, NULL);
@@ -325,6 +338,19 @@ gdk_gl_context_real_end_frame (GdkDrawContext *draw_context,
gdk_draw_context_end_frame (GDK_DRAW_CONTEXT (shared), painted, damage);
return;
}
if (context->old_updated_area[1])
cairo_region_destroy (context->old_updated_area[1]);
context->old_updated_area[1] = context->old_updated_area[0];
context->old_updated_area[0] = cairo_region_reference (painted);
}
static void
gdk_gl_context_surface_resized (GdkDrawContext *draw_context)
{
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
gdk_gl_context_clear_old_updated_area (context);
}
static void
@@ -338,6 +364,7 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
draw_context_class->begin_frame = gdk_gl_context_real_begin_frame;
draw_context_class->end_frame = gdk_gl_context_real_end_frame;
draw_context_class->surface_resized = gdk_gl_context_surface_resized;
/**
* GdkGLContext:shared-context:

View File

@@ -35,6 +35,9 @@ typedef struct _GdkGLContextClass GdkGLContextClass;
struct _GdkGLContext
{
GdkDrawContext parent_instance;
/* We store the old drawn areas to support buffer-age optimizations */
cairo_region_t *old_updated_area[2];
};
struct _GdkGLContextClass

View File

@@ -177,8 +177,6 @@ struct _GdkSurface
started. It may be smaller than the expose area if we'e painting
more than we have to, but it represents the "true" damage. */
cairo_region_t *active_update_area;
/* We store the old expose areas to support buffer-age optimizations */
cairo_region_t *old_updated_area[2];
GdkSurfaceState old_state;
GdkSurfaceState state;

View File

@@ -594,31 +594,6 @@ recompute_visible_regions (GdkSurface *private,
recalculate_children);
}
static void
gdk_surface_clear_old_updated_area (GdkSurface *surface)
{
int i;
for (i = 0; i < 2; i++)
{
if (surface->old_updated_area[i])
{
cairo_region_destroy (surface->old_updated_area[i]);
surface->old_updated_area[i] = NULL;
}
}
}
static void
gdk_surface_append_old_updated_area (GdkSurface *surface,
cairo_region_t *region)
{
if (surface->old_updated_area[1])
cairo_region_destroy (surface->old_updated_area[1]);
surface->old_updated_area[1] = surface->old_updated_area[0];
surface->old_updated_area[0] = cairo_region_reference (region);
}
void
_gdk_surface_update_size (GdkSurface *surface)
{
@@ -627,7 +602,6 @@ _gdk_surface_update_size (GdkSurface *surface)
for (l = surface->draw_contexts; l; l = l->next)
gdk_draw_context_surface_resized (l->data);
gdk_surface_clear_old_updated_area (surface);
recompute_visible_regions (surface, FALSE);
}
@@ -2120,8 +2094,6 @@ gdk_surface_process_updates_internal (GdkSurface *surface)
gdk_surface_process_updates_recurse (surface, expose_region);
gdk_surface_append_old_updated_area (surface, surface->active_update_area);
cairo_region_destroy (expose_region);
}
@@ -3035,7 +3007,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS
impl_class->hide (surface);
}
gdk_surface_clear_old_updated_area (surface);
recompute_visible_regions (surface, FALSE);
if (was_mapped && !gdk_surface_has_impl (surface))
@@ -3093,7 +3064,6 @@ gdk_surface_withdraw (GdkSurface *surface)
gdk_gl_context_clear_current ();
recompute_visible_regions (surface, FALSE);
gdk_surface_clear_old_updated_area (surface);
}
}

View File

@@ -184,16 +184,16 @@ gdk_wayland_gl_context_get_damage (GdkGLContext *context)
if (buffer_age == 2)
{
if (surface->old_updated_area[0])
return cairo_region_copy (surface->old_updated_area[0]);
if (context->old_updated_area[0])
return cairo_region_copy (context->old_updated_area[0]);
}
else if (buffer_age == 3)
{
if (surface->old_updated_area[0] &&
surface->old_updated_area[1])
if (context->old_updated_area[0] &&
context->old_updated_area[1])
{
cairo_region_t *damage = cairo_region_copy (surface->old_updated_area[0]);
cairo_region_union (damage, surface->old_updated_area[1]);
cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
cairo_region_union (damage, context->old_updated_area[1]);
return damage;
}
}

View File

@@ -196,7 +196,6 @@ gdk_x11_gl_context_get_damage (GdkGLContext *context)
GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
Display *dpy = gdk_x11_display_get_xdisplay (display);
GdkSurface *surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context));
unsigned int buffer_age = 0;
if (display_x11->has_glx_buffer_age)
@@ -215,16 +214,16 @@ gdk_x11_gl_context_get_damage (GdkGLContext *context)
if (buffer_age == 2)
{
if (surface->old_updated_area[0])
return cairo_region_copy (surface->old_updated_area[0]);
if (context->old_updated_area[0])
return cairo_region_copy (context->old_updated_area[0]);
}
else if (buffer_age == 3)
{
if (surface->old_updated_area[0] &&
surface->old_updated_area[1])
if (context->old_updated_area[0] &&
context->old_updated_area[1])
{
cairo_region_t *damage = cairo_region_copy (surface->old_updated_area[0]);
cairo_region_union (damage, surface->old_updated_area[1]);
cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
cairo_region_union (damage, context->old_updated_area[1]);
return damage;
}
}