Merge branch 'matthiasc/for-main' into 'main'

jpeg: Port to GdkMemoryTextureBuilder

See merge request GNOME/gtk!7502
This commit is contained in:
Matthias Clasen 2024-07-26 23:09:27 +00:00
commit 3b08f8026e
4 changed files with 25 additions and 6 deletions

View File

@ -955,13 +955,13 @@ gdk_texture_download_surface (GdkTexture *texture,
gdk_texture_downloader_init (&downloader, texture); gdk_texture_downloader_init (&downloader, texture);
gdk_texture_downloader_set_format (&downloader, gdk_texture_downloader_set_format (&downloader,
gdk_cairo_format_to_memory_format (surface_format)); gdk_cairo_format_to_memory_format (surface_format));
gdk_texture_downloader_set_color_state (&downloader, color_state);
gdk_texture_downloader_download_into (&downloader, gdk_texture_downloader_download_into (&downloader,
cairo_image_surface_get_data (surface), cairo_image_surface_get_data (surface),
cairo_image_surface_get_stride (surface)); cairo_image_surface_get_stride (surface));
gdk_texture_downloader_finish (&downloader); gdk_texture_downloader_finish (&downloader);
gdk_cairo_surface_convert_color_state (surface, texture->color_state, color_state);
cairo_surface_mark_dirty (surface); cairo_surface_mark_dirty (surface);
return surface; return surface;

View File

@ -68,6 +68,9 @@ gdk_texture_downloader_finish (GdkTextureDownloader *self)
* *
* Creates a new texture downloader for @texture. * Creates a new texture downloader for @texture.
* *
* By default, the downloader will convert the data to
* the default memory format, and to the sRGB color state.
*
* Returns: A new texture downloader * Returns: A new texture downloader
* *
* Since: 4.10 * Since: 4.10

View File

@ -24,6 +24,8 @@
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include "gdktexture.h" #include "gdktexture.h"
#include "gdktexturedownloaderprivate.h" #include "gdktexturedownloaderprivate.h"
#include "gdkmemorytexturebuilder.h"
#include "gdkcolorstateprivate.h"
#include "gdkprofilerprivate.h" #include "gdkprofilerprivate.h"
@ -144,8 +146,10 @@ gdk_load_jpeg (GBytes *input_bytes,
unsigned char *data = NULL; unsigned char *data = NULL;
unsigned char *row[1]; unsigned char *row[1];
GBytes *bytes; GBytes *bytes;
GdkMemoryTextureBuilder *builder;
GdkTexture *texture; GdkTexture *texture;
GdkMemoryFormat format; GdkMemoryFormat format;
GdkColorState *color_state;
G_GNUC_UNUSED guint64 before = GDK_PROFILER_CURRENT_TIME; G_GNUC_UNUSED guint64 before = GDK_PROFILER_CURRENT_TIME;
info.err = jpeg_std_error (&jerr.pub); info.err = jpeg_std_error (&jerr.pub);
@ -175,6 +179,8 @@ gdk_load_jpeg (GBytes *input_bytes,
width = info.output_width; width = info.output_width;
height = info.output_height; height = info.output_height;
color_state = GDK_COLOR_STATE_SRGB;
switch ((int)info.out_color_space) switch ((int)info.out_color_space)
{ {
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
@ -231,14 +237,23 @@ gdk_load_jpeg (GBytes *input_bytes,
bytes = g_bytes_new_take (data, stride * height); bytes = g_bytes_new_take (data, stride * height);
texture = gdk_memory_texture_new (width, height, builder = gdk_memory_texture_builder_new ();
format,
bytes, stride);
gdk_memory_texture_builder_set_bytes (builder, bytes);
gdk_memory_texture_builder_set_stride (builder, stride);
gdk_memory_texture_builder_set_width (builder, width);
gdk_memory_texture_builder_set_height (builder, height);
gdk_memory_texture_builder_set_format (builder, format);
gdk_memory_texture_builder_set_color_state (builder, color_state);
texture = gdk_memory_texture_builder_build (builder);
gdk_color_state_unref (color_state);
g_object_unref (builder);
g_bytes_unref (bytes); g_bytes_unref (bytes);
gdk_profiler_end_mark (before, "Load jpeg", NULL); gdk_profiler_end_mark (before, "Load jpeg", NULL);
return texture; return texture;
} }

View File

@ -249,6 +249,7 @@ gsk_gpu_upload_texture_op_draw (GskGpuOp *op,
downloader = gdk_texture_downloader_new (self->texture); downloader = gdk_texture_downloader_new (self->texture);
gdk_texture_downloader_set_format (downloader, gsk_gpu_image_get_format (self->image)); gdk_texture_downloader_set_format (downloader, gsk_gpu_image_get_format (self->image));
gdk_texture_downloader_set_color_state (downloader, gdk_texture_get_color_state (self->texture));
gdk_texture_downloader_download_into (downloader, data, stride); gdk_texture_downloader_download_into (downloader, data, stride);
gdk_texture_downloader_free (downloader); gdk_texture_downloader_free (downloader);
} }