[gtk+/master.fcw: 265/648] gdkgl: Use vfunc For Uploading Textures



commit 7859eade89181f6eb39147083c122010d6535933
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Dec 17 10:43:44 2014 +0800

    gdkgl: Use vfunc For Uploading Textures
    
    As the alignments, strides and image formats may be different across
    platforms, make the texture upload a vfunc to allow backends to override
    the GL commands for uploading textures for the software implementation for
    gdk_gl_texture_from_surface(), if necessary.
    
    Suggested by Alex to avoid copying non-trivial portions of code which would
    then add maintainenace burden.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740795

 gdk/gdkgl.c               |    7 ++-----
 gdk/gdkglcontext.c        |   20 ++++++++++++++++++++
 gdk/gdkglcontextprivate.h |   10 ++++++++++
 3 files changed, 32 insertions(+), 5 deletions(-)
---
diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c
index bc08bbc..9cea524 100644
--- a/gdk/gdkgl.c
+++ b/gdk/gdkgl.c
@@ -720,11 +720,8 @@ gdk_gl_texture_from_surface (cairo_surface_t *surface,
       e.height *= sy;
       image = cairo_surface_map_to_image (surface, &e);
 
-      glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
-      glPixelStorei (GL_UNPACK_ROW_LENGTH, cairo_image_surface_get_stride (image)/4);
-      glTexImage2D (target, 0, 4, e.width, e.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
-                    cairo_image_surface_get_data (image));
-      glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
+      /* We might have a different alignment, stride or format, so allow overriding here if needed */
+      GDK_GL_CONTEXT_GET_CLASS (paint_context)->upload_texture (paint_context, image, e.width, e.height, 
target);
 
       cairo_surface_unmap_image (surface, image);
 
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 949562e..9c9f53c 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -301,6 +301,9 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
   gobject_class->dispose = gdk_gl_context_dispose;
   gobject_class->finalize = gdk_gl_context_finalize;
 
+  /* Default Implementation of upload_texture() for gdk_gl_texture_from_surface() */
+  klass->upload_texture = gdk_gl_context_upload_texture;
+
   g_object_class_install_properties (gobject_class, LAST_PROP, obj_pspecs);
 }
 
@@ -393,6 +396,23 @@ gdk_gl_context_realize (GdkGLContext *context)
   priv->realized = TRUE;
 }
 
+/* Default implementation of upload_texture() for gdk_gl_texture_from_surface() */
+static void
+gdk_gl_context_upload_texture (GdkGLContext    *context,
+                               cairo_surface_t *image_surface,
+                               int              width,
+                               int              height,
+                               guint            texture_target)
+{
+  g_return_if_fail (GDK_IS_GL_CONTEXT (context));
+
+  glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
+  glPixelStorei (GL_UNPACK_ROW_LENGTH, cairo_image_surface_get_stride (image_surface)/4);
+  glTexImage2D (texture_target, 0, 4, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
+                cairo_image_surface_get_data (image_surface));
+  glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
+}
+
 /**
  * gdk_gl_context_make_current:
  * @context: a #GdkGLContext
diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h
index 7f5f574..c4a999d 100644
--- a/gdk/gdkglcontextprivate.h
+++ b/gdk/gdkglcontextprivate.h
@@ -46,6 +46,11 @@ struct _GdkGLContextClass
   gboolean (* texture_from_surface) (GdkGLContext    *context,
                                      cairo_surface_t *surface,
                                      cairo_region_t  *region);
+  void (* upload_texture) (GdkGLContext    *context,
+                           cairo_surface_t *image_surface,
+                           int              width,
+                           int              height,
+                           guint            texture_target);
 };
 
 typedef struct {
@@ -73,6 +78,11 @@ gboolean               gdk_gl_context_has_frame_terminator  (GdkGLContext   *con
 void                   gdk_gl_context_end_frame             (GdkGLContext   *context,
                                                              cairo_region_t *painted,
                                                              cairo_region_t *damage);
+void                   gdk_gl_context_upload_texture        (GdkGLContext    *context,
+                                                             cairo_surface_t *image_surface,
+                                                             int              width,
+                                                             int              height,
+                                                             guint            texture_target);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]