gpu: Add gsk_gpu_device_create_download_image()

This way, we can differentiate between regular offscreens and images
that are meant to be used for gsk_renderer_render_texture() or similar.
This commit is contained in:
Benjamin Otte 2023-11-24 01:27:44 +01:00
parent 38c0e2bdf6
commit 683878c733
5 changed files with 63 additions and 15 deletions

View File

@ -91,6 +91,20 @@ gsk_gl_device_create_upload_image (GskGpuDevice *device,
height);
}
static GskGpuImage *
gsk_gl_device_create_download_image (GskGpuDevice *device,
GdkMemoryDepth depth,
gsize width,
gsize height)
{
GskGLDevice *self = GSK_GL_DEVICE (device);
return gsk_gl_image_new (self,
gdk_memory_depth_get_format (depth),
width,
height);
}
static GskGpuImage *
gsk_gl_device_create_atlas_image (GskGpuDevice *device,
gsize width,
@ -129,6 +143,7 @@ gsk_gl_device_class_init (GskGLDeviceClass *klass)
gpu_device_class->create_offscreen_image = gsk_gl_device_create_offscreen_image;
gpu_device_class->create_atlas_image = gsk_gl_device_create_atlas_image;
gpu_device_class->create_upload_image = gsk_gl_device_create_upload_image;
gpu_device_class->create_download_image = gsk_gl_device_create_download_image;
object_class->finalize = gsk_gl_device_finalize;
}

View File

@ -454,6 +454,15 @@ gsk_gpu_device_create_upload_image (GskGpuDevice *self,
return GSK_GPU_DEVICE_GET_CLASS (self)->create_upload_image (self, with_mipmap, format, width, height);
}
GskGpuImage *
gsk_gpu_device_create_download_image (GskGpuDevice *self,
GdkMemoryDepth depth,
gsize width,
gsize height)
{
return GSK_GPU_DEVICE_GET_CLASS (self)->create_download_image (self, depth, width, height);
}
/* This rounds up to the next number that has <= 2 bits set:
* 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, ...
* That is roughly sqrt(2), so it should limit waste

View File

@ -37,6 +37,10 @@ struct _GskGpuDeviceClass
GdkMemoryFormat format,
gsize width,
gsize height);
GskGpuImage * (* create_download_image) (GskGpuDevice *self,
GdkMemoryDepth depth,
gsize width,
gsize height);
};
GType gsk_gpu_device_get_type (void) G_GNUC_CONST;
@ -61,6 +65,10 @@ GskGpuImage * gsk_gpu_device_create_upload_image (GskGpuD
GdkMemoryFormat format,
gsize width,
gsize height);
GskGpuImage * gsk_gpu_device_create_download_image (GskGpuDevice *self,
GdkMemoryDepth depth,
gsize width,
gsize height);
GskGpuImage * gsk_gpu_device_lookup_texture_image (GskGpuDevice *self,
GdkTexture *texture,

View File

@ -202,11 +202,10 @@ gsk_gpu_renderer_fallback_render_texture (GskGpuRenderer *self,
depth = gsk_render_node_get_preferred_depth (root);
do
{
image = gsk_gpu_device_create_offscreen_image (priv->device,
FALSE,
gsk_render_node_get_preferred_depth (root),
MIN (max_size, rounded_viewport->size.width),
MIN (max_size, rounded_viewport->size.height));
image = gsk_gpu_device_create_download_image (priv->device,
gsk_render_node_get_preferred_depth (root),
MIN (max_size, rounded_viewport->size.width),
MIN (max_size, rounded_viewport->size.height));
max_size /= 2;
}
while (image == NULL);
@ -227,11 +226,10 @@ gsk_gpu_renderer_fallback_render_texture (GskGpuRenderer *self,
{
texture = NULL;
if (image == NULL)
image = gsk_gpu_device_create_offscreen_image (priv->device,
FALSE,
depth,
MIN (image_width, width - x),
MIN (image_height, height - y));
image = gsk_gpu_device_create_download_image (priv->device,
depth,
MIN (image_width, width - x),
MIN (image_height, height - y));
frame = gsk_gpu_renderer_create_frame (self);
gsk_gpu_frame_render (frame,
@ -283,11 +281,10 @@ gsk_gpu_renderer_render_texture (GskRenderer *renderer,
viewport->origin.y,
ceil (viewport->size.width),
ceil (viewport->size.height));
image = gsk_gpu_device_create_offscreen_image (priv->device,
FALSE,
gsk_render_node_get_preferred_depth (root),
rounded_viewport.size.width,
rounded_viewport.size.height);
image = gsk_gpu_device_create_download_image (priv->device,
gsk_render_node_get_preferred_depth (root),
rounded_viewport.size.width,
rounded_viewport.size.height);
if (image == NULL)
return gsk_gpu_renderer_fallback_render_texture (self, root, &rounded_viewport);

View File

@ -392,6 +392,24 @@ gsk_vulkan_device_create_upload_image (GskGpuDevice *device,
height);
}
static GskGpuImage *
gsk_vulkan_device_create_download_image (GskGpuDevice *device,
GdkMemoryDepth depth,
gsize width,
gsize height)
{
GskVulkanDevice *self = GSK_VULKAN_DEVICE (device);
GskGpuImage *image;
image = gsk_vulkan_image_new_for_offscreen (self,
FALSE,
gdk_memory_depth_get_format (depth),
width,
height);
return image;
}
static void
gsk_vulkan_device_finalize (GObject *object)
{
@ -459,6 +477,7 @@ gsk_vulkan_device_class_init (GskVulkanDeviceClass *klass)
gpu_device_class->create_offscreen_image = gsk_vulkan_device_create_offscreen_image;
gpu_device_class->create_atlas_image = gsk_vulkan_device_create_atlas_image;
gpu_device_class->create_upload_image = gsk_vulkan_device_create_upload_image;
gpu_device_class->create_download_image = gsk_vulkan_device_create_download_image;
object_class->finalize = gsk_vulkan_device_finalize;
}