Compare commits

...

3 Commits

Author SHA1 Message Date
Matthias Clasen
ae0d0fcb61 Add a comment
This is something that wasn't clear to me, and it
is important to know to understand how we are handling
(un)premultiplication here.
2023-05-29 15:17:50 -04:00
Matthias Clasen
8a704d75dc gsk: Use matching memory format
memory_format_gl_format returns the new memory
format if it made a change, we should not drop
that on the floor.
2023-05-29 15:01:01 -04:00
Matthias Clasen
6b25a375fa gl: Prevent bad downloads
When the format we want doesn't match the format
of the GL texture, we need to download as RGBA
and convert.
2023-05-29 13:48:35 -04:00
3 changed files with 22 additions and 8 deletions

View File

@@ -171,13 +171,21 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
Download *download = download_; Download *download = download_;
GLenum gl_internal_format, gl_format, gl_type; GLenum gl_internal_format, gl_format, gl_type;
int major, minor; int major, minor;
unsigned int internal_texture_format, dummy;
expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format); expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format);
gdk_gl_context_get_version (context, &major, &minor); gdk_gl_context_get_version (context, &major, &minor);
gdk_memory_format_gl_format (gdk_texture_get_format (texture),
FALSE,
major, minor,
&internal_texture_format,
&dummy, &dummy);
if (download->stride == expected_stride && if (download->stride == expected_stride &&
!gdk_gl_context_get_use_es (context) && !gdk_gl_context_get_use_es (context) &&
gdk_memory_format_gl_format (download->format, TRUE, major, minor, &gl_internal_format, &gl_format, &gl_type)) gdk_memory_format_gl_format (download->format, FALSE, major, minor, &gl_internal_format, &gl_format, &gl_type) &&
gl_internal_format == internal_texture_format)
{ {
glGetTexImage (GL_TEXTURE_2D, glGetTexImage (GL_TEXTURE_2D,
0, 0,

View File

@@ -600,6 +600,11 @@ gdk_memory_convert (guchar *dest_data,
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
{ {
src_desc->to_float (tmp, src_data, width); src_desc->to_float (tmp, src_data, width);
/* Note: Converting from a premultiplied format to an opaque format is defined
* to yield the same result as compositing over black, which works out to
* using the premultiplied values, and just dropping alpha.
*/
if (src_desc->alpha == GDK_MEMORY_ALPHA_PREMULTIPLIED && dest_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT) if (src_desc->alpha == GDK_MEMORY_ALPHA_PREMULTIPLIED && dest_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT)
unpremultiply (tmp, width); unpremultiply (tmp, width);
else if (src_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT && dest_desc->alpha != GDK_MEMORY_ALPHA_STRAIGHT) else if (src_desc->alpha == GDK_MEMORY_ALPHA_STRAIGHT && dest_desc->alpha != GDK_MEMORY_ALPHA_STRAIGHT)

View File

@@ -1447,6 +1447,7 @@ gsk_gl_command_queue_create_framebuffer (GskGLCommandQueue *self)
return fbo_id; return fbo_id;
} }
static GdkMemoryFormat static GdkMemoryFormat
memory_format_gl_format (GdkMemoryFormat data_format, memory_format_gl_format (GdkMemoryFormat data_format,
gboolean use_es, gboolean use_es,
@@ -1611,7 +1612,7 @@ gsk_gl_command_queue_upload_texture_chunks (GskGLCommandQueue *self,
use_es = gdk_gl_context_get_use_es (self->context); use_es = gdk_gl_context_get_use_es (self->context);
gdk_gl_context_get_version (self->context, &major, &minor); gdk_gl_context_get_version (self->context, &major, &minor);
data_format = gdk_texture_get_format (chunks[0].texture); data_format = gdk_texture_get_format (chunks[0].texture);
memory_format_gl_format (data_format, data_format = memory_format_gl_format (data_format,
use_es, use_es,
major, major,
minor, minor,