gdkgl: Don't constantly re-create the tmp framebuffer

This commit is contained in:
Alexander Larsson 2014-11-05 15:19:00 +01:00
parent 0ac24904bd
commit 3c34ca3405
3 changed files with 41 additions and 6 deletions

View File

@ -86,9 +86,10 @@ gdk_cairo_draw_from_gl (cairo_t *cr,
gboolean trivial_transform;
cairo_surface_t *group_target;
GdkWindow *direct_window, *impl_window;
GLuint framebuffer;
GLint alpha_size = 0;
guint framebuffer;
int alpha_size = 0;
cairo_region_t *clip_region;
GdkGLContextPaintData *paint_data;
impl_window = window->impl_window;
@ -104,6 +105,10 @@ gdk_cairo_draw_from_gl (cairo_t *cr,
clip_region = gdk_cairo_region_from_clip (cr);
gdk_gl_context_make_current (context);
paint_data = gdk_gl_context_get_paint_data (context);
if (paint_data->tmp_framebuffer == 0)
glGenFramebuffersEXT (1, &paint_data->tmp_framebuffer);
if (source_type == GL_RENDERBUFFER)
{
@ -150,7 +155,7 @@ gdk_cairo_draw_from_gl (cairo_t *cr,
/* Create a framebuffer with the source renderbuffer and
make it the current target for reads */
glGenFramebuffersEXT (1, &framebuffer);
framebuffer = paint_data->tmp_framebuffer;
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer);
glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_RENDERBUFFER_EXT, source);
@ -213,7 +218,6 @@ gdk_cairo_draw_from_gl (cairo_t *cr,
glDisable (GL_SCISSOR_TEST);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT (1, &framebuffer);
#undef FLIP_Y
@ -353,7 +357,7 @@ gdk_cairo_draw_from_gl (cairo_t *cr,
cairo_surface_set_device_scale (image, buffer_scale, buffer_scale);
#endif
glGenFramebuffersEXT (1, &framebuffer);
framebuffer = paint_data->tmp_framebuffer;
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, framebuffer);
if (source_type == GL_RENDERBUFFER)
@ -378,7 +382,6 @@ gdk_cairo_draw_from_gl (cairo_t *cr,
glPixelStorei (GL_PACK_ROW_LENGTH, 0);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT (1, &framebuffer);
cairo_surface_mark_dirty (image);

View File

@ -87,6 +87,7 @@ typedef struct {
guint realized : 1;
guint use_texture_rectangle : 1;
GdkGLContextPaintData *paint_data;
} GdkGLContextPrivate;
enum {
@ -126,6 +127,15 @@ gdk_gl_context_dispose (GObject *gobject)
G_OBJECT_CLASS (gdk_gl_context_parent_class)->dispose (gobject);
}
static void
gdk_gl_context_finalize (GObject *gobject)
{
GdkGLContext *context = GDK_GL_CONTEXT (gobject);
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
g_clear_pointer (&priv->paint_data, g_free);
}
static void
gdk_gl_context_set_property (GObject *gobject,
guint prop_id,
@ -286,6 +296,7 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
gobject_class->set_property = gdk_gl_context_set_property;
gobject_class->get_property = gdk_gl_context_get_property;
gobject_class->dispose = gdk_gl_context_dispose;
gobject_class->finalize = gdk_gl_context_finalize;
g_object_class_install_properties (gobject_class, LAST_PROP, obj_pspecs);
}
@ -319,6 +330,18 @@ gdk_gl_context_end_frame (GdkGLContext *context,
GDK_GL_CONTEXT_GET_CLASS (context)->end_frame (context, painted, damage);
}
GdkGLContextPaintData *
gdk_gl_context_get_paint_data (GdkGLContext *context)
{
GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
if (priv->paint_data == NULL)
priv->paint_data = g_new0 (GdkGLContextPaintData, 1);
return priv->paint_data;
}
gboolean
gdk_gl_context_use_texture_rectangle (GdkGLContext *context)
{

View File

@ -54,6 +54,15 @@ void gdk_gl_context_end_frame (GdkGLContext *context,
cairo_region_t *painted,
cairo_region_t *damage);
typedef struct {
guint tmp_framebuffer;
} GdkGLContextPaintData;
GdkGLContextPaintData *gdk_gl_context_get_paint_data (GdkGLContext *context);
G_END_DECLS
#endif /* __GDK_GL_CONTEXT_PRIVATE_H__ */