Merge branch 'more-texture-tests' into 'main'

testsuite: Add more download tests

See merge request GNOME/gtk!6038
This commit is contained in:
Matthias Clasen 2023-05-31 12:01:31 +00:00
commit f4cbe26af3
4 changed files with 48 additions and 65 deletions

8
NEWS
View File

@ -8,6 +8,9 @@ Overview of Changes in 4.11.3, xx-xx-xxxx
* GtkListView:
- Don't leak the factories
* GtkColumnView:
- Support displaying sections
* GtkNotebook:
- Make the pages model implement GtkSelectionModel
@ -20,6 +23,10 @@ Overview of Changes in 4.11.3, xx-xx-xxxx
* Css:
- Add new binding-friendly css provider apis
* GDK:
- Support grayscale texture and alpha texture formats
for loading and saving to png and tiff, and in GL
* Theme:
- Show focus in the shortcuts window
@ -49,6 +56,7 @@ Overview of Changes in 4.11.3, xx-xx-xxxx
Basque
Catalan
Russian
Turkish
Overview of Changes in 4.11.2, 09-05-2023

View File

@ -204,6 +204,7 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
gsize stride = texture->width * gdk_memory_format_bytes_per_pixel (format);
guchar *pixels = g_malloc_n (stride, texture->height);
glPixelStorei (GL_PACK_ALIGNMENT, 1);
glGetTexImage (GL_TEXTURE_2D,
0,
gl_format,
@ -271,6 +272,7 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
gsize stride = actual_bpp * texture->width;
guchar *pixels = g_malloc_n (stride, texture->height);
glPixelStorei (GL_PACK_ALIGNMENT, 1);
glReadPixels (0, 0,
texture->width, texture->height,
gl_read_format,

View File

@ -2,6 +2,7 @@
#include <epoxy/gl.h>
#include "gdk/gdktextureprivate.h"
#include "gdk/gdkglcontextprivate.h"
#include "gdk/gdkgltextureprivate.h"
static cairo_surface_t *
make_surface (void)
@ -202,6 +203,11 @@ G_GNUC_END_IGNORE_DEPRECATIONS
texture = gdk_gl_texture_builder_build (builder, NULL, NULL);
g_assert_true (gdk_gl_texture_get_context (GDK_GL_TEXTURE (texture)) == context);
g_assert_true (gdk_gl_texture_get_id (GDK_GL_TEXTURE (texture)) == id);
g_assert_false (gdk_gl_texture_has_mipmap (GDK_GL_TEXTURE (texture)));
g_assert_true (gdk_gl_texture_get_sync (GDK_GL_TEXTURE (texture)) == sync);
data = g_malloc0 (64 * 64 * 4);
gdk_texture_download (texture, data, 64 * 4);

View File

@ -4,7 +4,7 @@
#include <epoxy/gl.h>
#define N 20
#define N 10
static GdkGLContext *gl_context = NULL;
static GskRenderer *gl_renderer = NULL;
@ -890,6 +890,7 @@ upload_to_gl_native (GdkTexture *texture)
glGenTextures (1, &id);
glActiveTexture (GL_TEXTURE0);
glBindTexture (GL_TEXTURE_2D, id);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexImage2D (GL_TEXTURE_2D, 0, formats[i].gl_internalformat, width, height, 0, formats[i].gl_format, formats[i].gl_type, data);
glTexParameteriv (GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, formats[i].swizzle);
@ -1063,6 +1064,7 @@ ensure_texture_format (GdkTexture *texture,
format,
bytes,
stride);
g_bytes_unref (bytes);
g_object_unref (texture);
return result;
@ -1140,7 +1142,9 @@ should_skip_download_test (GdkMemoryFormat format,
}
static void
test_download_1x1 (gconstpointer data)
test_download (gconstpointer data,
unsigned int width,
unsigned int height)
{
GdkMemoryFormat format;
TextureMethod method;
@ -1166,8 +1170,8 @@ test_download_1x1 (gconstpointer data)
(method == TEXTURE_METHOD_GL || method == TEXTURE_METHOD_GL_RELEASED || method == TEXTURE_METHOD_GL_NATIVE))
color = (GdkRGBA) { 0, 0, 0, 0 };
expected = create_texture (format, TEXTURE_METHOD_LOCAL, 1, 1, &color);
test = create_texture (format, method, 1, 1, &color);
expected = create_texture (format, TEXTURE_METHOD_LOCAL, width, height, &color);
test = create_texture (format, method, width, height, &color);
test = ensure_texture_format (test, format);
compare_textures (expected, test, texture_method_is_accurate (method));
@ -1177,76 +1181,37 @@ test_download_1x1 (gconstpointer data)
}
}
static void
test_download_1x1 (gconstpointer data)
{
test_download (data, 1, 1);
}
static void
test_download_4x4 (gconstpointer data)
{
GdkMemoryFormat format;
TextureMethod method;
GdkTexture *expected, *test;
gsize i;
if (!decode (data, &format, &method))
return;
if (should_skip_download_test (format, method))
return;
for (i = 0; i < N; i++)
{
GdkRGBA color;
create_random_color (&color);
/* these methods may premultiply during operation */
if (color.alpha == 0.f &&
!gdk_memory_format_is_premultiplied (format) &&
gdk_memory_format_has_alpha (format) &&
(method == TEXTURE_METHOD_GL || method == TEXTURE_METHOD_GL_RELEASED || method == TEXTURE_METHOD_GL_NATIVE))
color = (GdkRGBA) { 0, 0, 0, 0 };
expected = create_texture (format, TEXTURE_METHOD_LOCAL, 4, 4, &color);
test = create_texture (format, method, 4, 4, &color);
test = ensure_texture_format (test, format);
compare_textures (expected, test, texture_method_is_accurate (method));
g_object_unref (expected);
g_object_unref (test);
}
test_download (data, 4, 4);
}
/* larger than what NGL puts into the icon cache */
/* odd sizes, to trigger alignment issues */
static void
test_download_17x7 (gconstpointer data)
{
test_download (data, 17, 7);
}
/* larger than what GSK puts into the icon cache */
static void
test_download_192x192 (gconstpointer data)
{
GdkMemoryFormat format;
TextureMethod method;
GdkTexture *expected, *test;
GdkRGBA color;
test_download (data, 192, 192);
}
if (!decode (data, &format, &method))
return;
if (should_skip_download_test (format, method))
return;
create_random_color (&color);
/* these methods may premultiply during operation */
if (color.alpha == 0.f &&
!gdk_memory_format_is_premultiplied (format) &&
gdk_memory_format_has_alpha (format) &&
(method == TEXTURE_METHOD_GL || method == TEXTURE_METHOD_GL_RELEASED || method == TEXTURE_METHOD_GL_NATIVE))
color = (GdkRGBA) { 0, 0, 0, 0 };
expected = create_texture (format, TEXTURE_METHOD_LOCAL, 192, 192, &color);
test = create_texture (format, method, 192, 192, &color);
test = ensure_texture_format (test, format);
compare_textures (expected, test, texture_method_is_accurate (method));
g_object_unref (expected);
g_object_unref (test);
/* larger than the small max-texture-size we test against */
static void
test_download_1065x17 (gconstpointer data)
{
test_download (data, 1065, 17);
}
static void
@ -1382,7 +1347,9 @@ main (int argc, char *argv[])
add_test ("/memorytexture/download_1x1", test_download_1x1);
add_test ("/memorytexture/download_4x4", test_download_4x4);
add_test ("/memorytexture/download_17x7", test_download_17x7);
add_test ("/memorytexture/download_192x192", test_download_192x192);
add_test ("/memorytexture/download_1065x17", test_download_1065x17);
add_conversion_test ("/memorytexture/conversion_1x1", test_conversion_1x1);
add_conversion_test ("/memorytexture/conversion_4x4", test_conversion_4x4);