texture: Expose subclasses as subclasses

This is necessary so that bidnings work properly and don't make
gdk_gl_texture_release() a function on GdkTexture.
It also allows code to identify what type of texture they are dealing
with.

Finally, we can now decide to add getters later without screwing
anything up, if we want to allow people to access GL textures directly.
This commit is contained in:
Benjamin Otte 2018-03-18 05:14:52 +01:00
parent d54ca3c74f
commit 82a99a3643
7 changed files with 47 additions and 21 deletions

View File

@ -751,6 +751,16 @@ gdk_texture_get_type
GDK_TYPE_TEXTURE GDK_TYPE_TEXTURE
GDK_IS_TEXTURE GDK_IS_TEXTURE
GDK_TEXTURE GDK_TEXTURE
GdkGLTextureClass
gdk_gl_texture_get_type
GDK_TYPE_GL_TEXTURE
GDK_IS_GL_TEXTURE
GDK_GL_TEXTURE
GdkMemoryTextureClass
gdk_memory_texture_get_type
GDK_TYPE_MEMORY_TEXTURE
GDK_IS_MEMORY_TEXTURE
GDK_MEMORY_TEXTURE
</SECTION> </SECTION>
<SECTION> <SECTION>

View File

@ -133,28 +133,26 @@ gdk_gl_texture_get_id (GdkGLTexture *self)
/** /**
* gdk_gl_texture_release: * gdk_gl_texture_release:
* @texture: a #GdkTexture wrapping a GL texture * @self: a #GdkTexture wrapping a GL texture
* *
* Releases the GL resources held by a #GdkTexture that * Releases the GL resources held by a #GdkGLTexture that
* was created with gdk_texture_new_for_gl(). * was created with gdk_gl_texture_new().
* *
* The texture contents are still available via the * The texture contents are still available via the
* gdk_texture_download() function, after this function * gdk_texture_download() function, after this function
* has been called. * has been called.
*/ */
void void
gdk_gl_texture_release (GdkTexture *texture) gdk_gl_texture_release (GdkGLTexture *self)
{ {
GdkGLTexture *self;
GdkWindow *window; GdkWindow *window;
GdkTexture *texture;
cairo_t *cr; cairo_t *cr;
g_return_if_fail (GDK_IS_GL_TEXTURE (texture)); g_return_if_fail (GDK_IS_GL_TEXTURE (self));
self = GDK_GL_TEXTURE (texture);
g_return_if_fail (self->saved == NULL); g_return_if_fail (self->saved == NULL);
texture = GDK_TEXTURE (self);
self->saved = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, self->saved = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
texture->width, texture->height); texture->width, texture->height);
@ -178,7 +176,7 @@ gdk_gl_texture_release (GdkTexture *texture)
} }
/** /**
* gdk_gl_texture_new: (constructor) * gdk_gl_texture_new:
* @context: a #GdkGLContext * @context: a #GdkGLContext
* @id: the ID of a texture that was created with @context * @id: the ID of a texture that was created with @context
* @width: the nominal width of the texture * @width: the nominal width of the texture

View File

@ -23,11 +23,23 @@
#error "Only <gdk/gdk.h> can be included directly." #error "Only <gdk/gdk.h> can be included directly."
#endif #endif
#include <gdk/gdktypes.h>
#include <gdk/gdkglcontext.h> #include <gdk/gdkglcontext.h>
#include <gdk/gdktexture.h>
G_BEGIN_DECLS G_BEGIN_DECLS
#define GDK_TYPE_GL_TEXTURE (gdk_gl_texture_get_type ())
#define GDK_GL_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_GL_TEXTURE, GdkGLTexture))
#define GDK_IS_GL_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_GL_TEXTURE))
typedef struct _GdkGLTexture GdkGLTexture;
typedef struct _GdkGLTextureClass GdkGLTextureClass;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkGLTexture, g_object_unref)
GDK_AVAILABLE_IN_ALL
GType gdk_gl_texture_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GdkTexture * gdk_gl_texture_new (GdkGLContext *context, GdkTexture * gdk_gl_texture_new (GdkGLContext *context,
@ -38,7 +50,7 @@ GdkTexture * gdk_gl_texture_new (GdkGLContext
gpointer data); gpointer data);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gdk_gl_texture_release (GdkTexture *texture); void gdk_gl_texture_release (GdkGLTexture *texture);
G_END_DECLS G_END_DECLS

View File

@ -7,10 +7,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#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); GdkGLContext * gdk_gl_texture_get_context (GdkGLTexture *self);
guint gdk_gl_texture_get_id (GdkGLTexture *self); guint gdk_gl_texture_get_id (GdkGLTexture *self);

View File

@ -86,6 +86,20 @@ typedef enum {
#error "Unknown byte order for GDK_MEMORY_DEFAULT" #error "Unknown byte order for GDK_MEMORY_DEFAULT"
#endif #endif
#define GDK_TYPE_MEMORY_TEXTURE (gdk_memory_texture_get_type ())
#define GDK_MEMORY_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_MEMORY_TEXTURE, GdkMemoryTexture))
#define GDK_IS_MEMORY_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_MEMORY_TEXTURE))
typedef struct _GdkMemoryTexture GdkMemoryTexture;
typedef struct _GdkMemoryTextureClass GdkMemoryTextureClass;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkMemoryTexture, g_object_unref)
GDK_AVAILABLE_IN_ALL
GType gdk_memory_texture_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GdkTexture * gdk_memory_texture_new (int width, GdkTexture * gdk_memory_texture_new (int width,
int height, int height,

View File

@ -31,10 +31,6 @@ G_BEGIN_DECLS
#define GDK_MEMORY_CAIRO_FORMAT_ARGB32 GDK_MEMORY_DEFAULT #define GDK_MEMORY_CAIRO_FORMAT_ARGB32 GDK_MEMORY_DEFAULT
#define GDK_TYPE_MEMORY_TEXTURE (gdk_memory_texture_get_type ())
G_DECLARE_FINAL_TYPE (GdkMemoryTexture, gdk_memory_texture, GDK, MEMORY_TEXTURE, GdkTexture)
GdkMemoryFormat gdk_memory_texture_get_format (GdkMemoryTexture *self); GdkMemoryFormat gdk_memory_texture_get_format (GdkMemoryTexture *self);
const guchar * gdk_memory_texture_get_data (GdkMemoryTexture *self); const guchar * gdk_memory_texture_get_data (GdkMemoryTexture *self);
gsize gdk_memory_texture_get_stride (GdkMemoryTexture *self); gsize gdk_memory_texture_get_stride (GdkMemoryTexture *self);

View File

@ -386,7 +386,7 @@ delete_one_texture (gpointer data)
Texture *texture = data; Texture *texture = data;
if (texture->holder) if (texture->holder)
gdk_gl_texture_release (texture->holder); gdk_gl_texture_release (GDK_GL_TEXTURE (texture->holder));
if (texture->id != 0) if (texture->id != 0)
{ {