gpu: Add an optional memory_id to GL images

This implements initial support for GL_EXT_external_objects.
An external memory object is (unlike EGL images) represented by a
GLuint just like all other GL objects.
It needs to be kept alive for as long as the memory is used, which
means it needs to outlive the texture ID.

That's why the object is handed over to the texture code and the
finalizer will then free the memory object.

This is just plumbing, users will follow in future commits.
This commit is contained in:
Benjamin Otte
2024-10-31 10:15:14 +01:00
parent 768fcfb718
commit c9d58ee54e
3 changed files with 9 additions and 0 deletions

View File

@@ -89,6 +89,7 @@ gsk_gl_frame_upload_texture (GskGpuFrame *frame,
image = gsk_gl_image_new_for_texture (GSK_GL_DEVICE (gsk_gpu_frame_get_device (frame)),
texture,
gdk_gl_texture_get_id (gl_texture),
0,
FALSE,
gdk_gl_texture_has_mipmap (gl_texture) ? (GSK_GPU_IMAGE_CAN_MIPMAP | GSK_GPU_IMAGE_MIPMAP) : 0);
@@ -115,6 +116,7 @@ gsk_gl_frame_upload_texture (GskGpuFrame *frame,
return gsk_gl_image_new_for_texture (GSK_GL_DEVICE (gsk_gpu_frame_get_device (frame)),
texture,
tex_id,
0,
TRUE,
(external ? GSK_GPU_IMAGE_EXTERNAL | GSK_GPU_IMAGE_NO_BLIT : 0));
}

View File

@@ -10,6 +10,7 @@ struct _GskGLImage
GskGpuImage parent_instance;
guint texture_id;
guint memory_id;
guint framebuffer_id;
GLint gl_internal_format;
@@ -49,6 +50,9 @@ gsk_gl_image_finalize (GObject *object)
if (self->owns_texture)
glDeleteTextures (1, &self->texture_id);
if (self->memory_id)
glDeleteMemoryObjectsEXT (1, &self->memory_id);
G_OBJECT_CLASS (gsk_gl_image_parent_class)->finalize (object);
}
@@ -216,6 +220,7 @@ GskGpuImage *
gsk_gl_image_new_for_texture (GskGLDevice *device,
GdkTexture *owner,
GLuint tex_id,
GLuint mem_id,
gboolean take_ownership,
GskGpuImageFlags extra_flags)
{
@@ -258,6 +263,7 @@ gsk_gl_image_new_for_texture (GskGLDevice *device,
gsk_gpu_image_toggle_ref_texture (GSK_GPU_IMAGE (self), owner);
self->texture_id = tex_id;
self->memory_id = mem_id;
self->owns_texture = take_ownership;
return GSK_GPU_IMAGE (self);

View File

@@ -25,6 +25,7 @@ GskGpuImage * gsk_gl_image_new (GskGLDe
GskGpuImage * gsk_gl_image_new_for_texture (GskGLDevice *device,
GdkTexture *owner,
GLuint tex_id,
GLuint mem_id,
gboolean take_ownership,
GskGpuImageFlags extra_flags);