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_;
GLenum gl_internal_format, gl_format, gl_type;
int major, minor;
unsigned int internal_texture_format, dummy;
expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format);
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 &&
!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,
0,

View File

@@ -600,6 +600,11 @@ gdk_memory_convert (guchar *dest_data,
for (y = 0; y < height; y++)
{
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)
unpremultiply (tmp, width);
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;
}
static GdkMemoryFormat
memory_format_gl_format (GdkMemoryFormat data_format,
gboolean use_es,
@@ -1611,13 +1612,13 @@ gsk_gl_command_queue_upload_texture_chunks (GskGLCommandQueue *self,
use_es = gdk_gl_context_get_use_es (self->context);
gdk_gl_context_get_version (self->context, &major, &minor);
data_format = gdk_texture_get_format (chunks[0].texture);
memory_format_gl_format (data_format,
use_es,
major,
minor,
&gl_internalformat,
&gl_format,
&gl_type);
data_format = memory_format_gl_format (data_format,
use_es,
major,
minor,
&gl_internalformat,
&gl_format,
&gl_type);
glTexImage2D (GL_TEXTURE_2D, 0, gl_internalformat, width, height, 0, gl_format, gl_type, NULL);