forked from AuroraMiddleware/gtk
gdk: Add a gl texture implementation
This will be used to pass a GL textures from the application (or rather, GtkGLArea) down to the GSK GL renderer.
This commit is contained in:
parent
e7cab2bc0c
commit
b366ea84a7
109
gdk/gdktexture.c
109
gdk/gdktexture.c
@ -39,6 +39,8 @@
|
|||||||
#include "gdkinternals.h"
|
#include "gdkinternals.h"
|
||||||
#include "gdkcairo.h"
|
#include "gdkcairo.h"
|
||||||
|
|
||||||
|
#include <epoxy/gl.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:gdktexture
|
* SECTION:gdktexture
|
||||||
* @Short_description: Image data for display
|
* @Short_description: Image data for display
|
||||||
@ -432,6 +434,88 @@ gdk_pixbuf_texture_init (GdkPixbufTexture *self)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* GdkGLTexture */
|
||||||
|
|
||||||
|
|
||||||
|
struct _GdkGLTexture {
|
||||||
|
GdkTexture parent_instance;
|
||||||
|
|
||||||
|
GdkGLContext *context;
|
||||||
|
int id;
|
||||||
|
|
||||||
|
GDestroyNotify destroy;
|
||||||
|
gpointer data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _GdkGLTextureClass {
|
||||||
|
GdkTextureClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (GdkGLTexture, gdk_gl_texture, GDK_TYPE_TEXTURE)
|
||||||
|
|
||||||
|
static void
|
||||||
|
gdk_gl_texture_dispose (GObject *object)
|
||||||
|
{
|
||||||
|
GdkGLTexture *self = GDK_GL_TEXTURE (object);
|
||||||
|
|
||||||
|
g_object_unref (self->context);
|
||||||
|
|
||||||
|
if (self->destroy)
|
||||||
|
self->destroy (self->data);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (gdk_gl_texture_parent_class)->dispose (object);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gdk_gl_texture_download (GdkTexture *texture,
|
||||||
|
guchar *data,
|
||||||
|
gsize stride)
|
||||||
|
{
|
||||||
|
GdkGLTexture *self = GDK_GL_TEXTURE (texture);
|
||||||
|
cairo_surface_t *surface;
|
||||||
|
cairo_t *cr;
|
||||||
|
GdkWindow *window;
|
||||||
|
|
||||||
|
surface = cairo_image_surface_create_for_data (data,
|
||||||
|
CAIRO_FORMAT_ARGB32,
|
||||||
|
texture->width, texture->height,
|
||||||
|
stride);
|
||||||
|
|
||||||
|
cr = cairo_create (surface);
|
||||||
|
window = gdk_gl_context_get_window (self->context);
|
||||||
|
gdk_cairo_draw_from_gl (cr, window, self->id, GL_TEXTURE, 1, 0, 0, texture->width, texture->height);
|
||||||
|
cairo_destroy (cr);
|
||||||
|
cairo_surface_finish (surface);
|
||||||
|
cairo_surface_destroy (surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gdk_gl_texture_class_init (GdkGLTextureClass *klass)
|
||||||
|
{
|
||||||
|
GdkTextureClass *texture_class = GDK_TEXTURE_CLASS (klass);
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
|
texture_class->download = gdk_gl_texture_download;
|
||||||
|
gobject_class->dispose = gdk_gl_texture_dispose;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gdk_gl_texture_init (GdkGLTexture *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
GdkGLContext *
|
||||||
|
gdk_gl_texture_get_context (GdkGLTexture *self)
|
||||||
|
{
|
||||||
|
return self->context;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
gdk_gl_texture_get_id (GdkGLTexture *self)
|
||||||
|
{
|
||||||
|
return self->id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gdk_texture_new_for_pixbuf:
|
* gdk_texture_new_for_pixbuf:
|
||||||
* @pixbuf: a #GdkPixbuf
|
* @pixbuf: a #GdkPixbuf
|
||||||
@ -532,6 +616,31 @@ gdk_texture_new_from_file (GFile *file,
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GdkTexture *
|
||||||
|
gdk_texture_new_for_gl (GdkGLContext *context,
|
||||||
|
int id,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
GDestroyNotify destroy,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GdkGLTexture *self;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), NULL);
|
||||||
|
|
||||||
|
self = g_object_new (GDK_TYPE_GL_TEXTURE,
|
||||||
|
"width", width,
|
||||||
|
"height", height,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
self->context = g_object_ref (context);
|
||||||
|
self->id = id;
|
||||||
|
self->destroy = destroy;
|
||||||
|
self->data = data;
|
||||||
|
|
||||||
|
return GDK_TEXTURE (self);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gdk_texture_get_width:
|
* gdk_texture_get_width:
|
||||||
* @texture: a #GdkTexture
|
* @texture: a #GdkTexture
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <gdk/gdkversionmacros.h>
|
#include <gdk/gdkversionmacros.h>
|
||||||
#include <gdk/gdktypes.h>
|
#include <gdk/gdktypes.h>
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
|
#include <gdk/gdkglcontext.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -55,6 +56,14 @@ GDK_AVAILABLE_IN_3_94
|
|||||||
GdkTexture * gdk_texture_new_from_file (GFile *file,
|
GdkTexture * gdk_texture_new_from_file (GFile *file,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
GdkTexture * gdk_texture_new_for_gl (GdkGLContext *context,
|
||||||
|
int id,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
GDestroyNotify destroy,
|
||||||
|
gpointer data);
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_3_94
|
GDK_AVAILABLE_IN_3_94
|
||||||
int gdk_texture_get_width (GdkTexture *texture);
|
int gdk_texture_get_width (GdkTexture *texture);
|
||||||
GDK_AVAILABLE_IN_3_94
|
GDK_AVAILABLE_IN_3_94
|
||||||
|
@ -44,6 +44,13 @@ void gdk_texture_clear_render_data (GdkTexture
|
|||||||
gpointer gdk_texture_get_render_data (GdkTexture *self,
|
gpointer gdk_texture_get_render_data (GdkTexture *self,
|
||||||
gpointer key);
|
gpointer key);
|
||||||
|
|
||||||
|
#define GDK_TYPE_GL_TEXTURE (gdk_gl_texture_get_type ())
|
||||||
|
|
||||||
|
G_DECLARE_FINAL_TYPE (GdkGLTexture, gdk_gl_texture, GDK, GL_TEXTURE, GdkTexture)
|
||||||
|
|
||||||
|
GdkGLContext * gdk_gl_texture_get_context (GdkGLTexture *self);
|
||||||
|
int gdk_gl_texture_get_id (GdkGLTexture *self);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GDK_TEXTURE_PRIVATE_H__ */
|
#endif /* __GDK_TEXTURE_PRIVATE_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user