Merge branch 'wip/otte/for-main' into 'main'

testsuite: Replace g_random_*() with g_test_rand_*()

See merge request GNOME/gtk!6703
This commit is contained in:
Matthias Clasen 2024-01-03 17:50:29 +00:00
commit 51fd7cf35a
14 changed files with 86 additions and 59 deletions

View File

@ -1569,10 +1569,10 @@ gdk_gl_context_init_memory_flags (GdkGLContext *self)
priv->memory_flags[GDK_MEMORY_R8G8B8A8_PREMULTIPLIED] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_RENDERABLE | GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R8G8B8A8] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_RENDERABLE | GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R8G8B8X8] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_RENDERABLE | GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16_FLOAT] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_A16_FLOAT] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16_FLOAT] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_A16_FLOAT] |= GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R32G32B32_FLOAT] |= GDK_GL_FORMAT_USABLE;
priv->memory_flags[GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED] |= GDK_GL_FORMAT_USABLE;
priv->memory_flags[GDK_MEMORY_R32G32B32A32_FLOAT] |= GDK_GL_FORMAT_USABLE;
@ -1583,12 +1583,12 @@ gdk_gl_context_init_memory_flags (GdkGLContext *self)
if (gdk_gl_version_greater_equal (&priv->gl_version, &GDK_GL_VERSION_INIT (3, 2)))
{
/* GLES 3.2 spec, table 8.10 */
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED] |= GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT] |= GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_A16_FLOAT] |= GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED] |= GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R32G32B32A32_FLOAT] |= GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_A32_FLOAT] |= GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED] |= GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT] |= GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_A16_FLOAT] |= GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED] |= GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_R32G32B32A32_FLOAT] |= GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_A32_FLOAT] |= GDK_GL_FORMAT_RENDERABLE;
}
}
@ -1639,7 +1639,8 @@ gdk_gl_context_init_memory_flags (GdkGLContext *self)
flags |= GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED] |= flags;
priv->memory_flags[GDK_MEMORY_R16G16B16A16_FLOAT] |= flags;
priv->memory_flags[GDK_MEMORY_R16G16B16_FLOAT] |= flags;
/* disabled for now, see https://gitlab.freedesktop.org/mesa/mesa/-/issues/10378 */
priv->memory_flags[GDK_MEMORY_R16G16B16_FLOAT] |= flags & ~GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_A16_FLOAT] |= flags;
}
if (epoxy_has_gl_extension ("GL_OES_texture_float"))
@ -1651,7 +1652,7 @@ gdk_gl_context_init_memory_flags (GdkGLContext *self)
flags |= GDK_GL_FORMAT_FILTERABLE;
priv->memory_flags[GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED] |= flags;
priv->memory_flags[GDK_MEMORY_R32G32B32A32_FLOAT] |= flags;
priv->memory_flags[GDK_MEMORY_R32G32B32_FLOAT] |= flags;
priv->memory_flags[GDK_MEMORY_R32G32B32_FLOAT] |= flags & ~GDK_GL_FORMAT_RENDERABLE;
priv->memory_flags[GDK_MEMORY_A32_FLOAT] |= flags;
}
}

View File

@ -1477,12 +1477,14 @@ gsk_gl_command_queue_create_framebuffer (GskGLCommandQueue *self)
static GdkMemoryFormat
memory_format_gl_format (GskGLCommandQueue *self,
GdkMemoryFormat data_format,
gboolean ensure_mipmap,
gboolean *out_can_mipmap,
GLint *gl_internalformat,
GLenum *gl_format,
GLenum *gl_type,
GLint gl_swizzle[4])
{
GdkGLMemoryFlags flags;
GdkGLMemoryFlags flags, required_flags;
GdkMemoryFormat alt_format;
const GdkMemoryFormat *fallbacks;
gsize i;
@ -1491,15 +1493,20 @@ memory_format_gl_format (GskGLCommandQueue *self,
if (gdk_memory_format_alpha (data_format) == GDK_MEMORY_ALPHA_STRAIGHT)
data_format = gdk_memory_format_get_premultiplied (data_format);
required_flags = GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE;
if (ensure_mipmap)
required_flags |= GDK_GL_FORMAT_RENDERABLE;
/* First, try the format itself */
flags = gdk_gl_context_get_format_flags (self->context, data_format);
if ((flags & (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE)) == (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE))
if ((flags & required_flags) == required_flags)
{
gdk_memory_format_gl_format (data_format,
gl_internalformat,
gl_format,
gl_type,
gl_swizzle);
*out_can_mipmap = (flags & GDK_GL_FORMAT_RENDERABLE) ? TRUE : FALSE;
return data_format;
}
@ -1512,8 +1519,10 @@ memory_format_gl_format (GskGLCommandQueue *self,
gl_swizzle))
{
flags = gdk_gl_context_get_format_flags (self->context, alt_format);
if ((flags & (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE)) == (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE))
if ((flags & required_flags) == required_flags)
{
*out_can_mipmap = (flags & GDK_GL_FORMAT_RENDERABLE) ? TRUE : FALSE;
if (self->can_swizzle)
return data_format;
@ -1532,13 +1541,15 @@ memory_format_gl_format (GskGLCommandQueue *self,
for (i = 0; fallbacks[i] != -1; i++)
{
flags = gdk_gl_context_get_format_flags (self->context, fallbacks[i]);
if (((flags & (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE)) == (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE)))
if (((flags & required_flags) == required_flags))
{
gdk_memory_format_gl_format (fallbacks[i],
gl_internalformat,
gl_format,
gl_type,
gl_swizzle);
*out_can_mipmap = (flags & GDK_GL_FORMAT_RENDERABLE) ? TRUE : FALSE;
return fallbacks[i];
}
}
@ -1552,32 +1563,24 @@ static void
gsk_gl_command_queue_do_upload_texture_chunk (GskGLCommandQueue *self,
GdkTexture *texture,
int x,
int y)
int y,
GdkMemoryFormat data_format,
GLenum gl_format,
GLenum gl_type,
GLint gl_swizzle[4])
{
G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
const guchar *data;
gsize stride;
GBytes *bytes;
GdkTextureDownloader downloader;
GdkMemoryFormat data_format;
int width, height;
GLint gl_internalformat;
GLenum gl_format;
GLenum gl_type;
GLint gl_swizzle[4];
gsize bpp;
data_format = gdk_texture_get_format (texture);
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
data_format = memory_format_gl_format (self,
data_format,
&gl_internalformat,
&gl_format,
&gl_type,
gl_swizzle);
if (GSK_DEBUG_CHECK (FALLBACK) &&
data_format != gdk_texture_get_format (texture))
{
@ -1652,8 +1655,10 @@ gsk_gl_command_queue_do_upload_texture_chunk (GskGLCommandQueue *self,
int
gsk_gl_command_queue_upload_texture_chunks (GskGLCommandQueue *self,
gboolean ensure_mipmap,
unsigned int n_chunks,
GskGLTextureChunk *chunks)
GskGLTextureChunk *chunks,
gboolean *out_can_mipmap)
{
G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
int width, height;
@ -1698,6 +1703,8 @@ gsk_gl_command_queue_upload_texture_chunks (GskGLCommandQueue *self,
data_format = gdk_texture_get_format (chunks[0].texture);
data_format = memory_format_gl_format (self,
data_format,
ensure_mipmap,
out_can_mipmap,
&gl_internalformat,
&gl_format,
&gl_type,
@ -1708,7 +1715,7 @@ gsk_gl_command_queue_upload_texture_chunks (GskGLCommandQueue *self,
for (unsigned int i = 0; i < n_chunks; i++)
{
GskGLTextureChunk *c = &chunks[i];
gsk_gl_command_queue_do_upload_texture_chunk (self, c->texture, c->x, c->y);
gsk_gl_command_queue_do_upload_texture_chunk (self, c->texture, c->x, c->y, data_format, gl_format, gl_type, gl_swizzle);
}
/* Restore previous texture state if any */
@ -1726,9 +1733,15 @@ gsk_gl_command_queue_upload_texture_chunks (GskGLCommandQueue *self,
int
gsk_gl_command_queue_upload_texture (GskGLCommandQueue *self,
GdkTexture *texture)
GdkTexture *texture,
gboolean ensure_mipmap,
gboolean *out_can_mipmap)
{
return gsk_gl_command_queue_upload_texture_chunks (self, 1, &(GskGLTextureChunk){ texture, 0, 0});
return gsk_gl_command_queue_upload_texture_chunks (self,
ensure_mipmap,
1,
&(GskGLTextureChunk){ texture, 0, 0},
out_can_mipmap);
}
void

View File

@ -313,7 +313,9 @@ void gsk_gl_command_queue_execute (GskGLCommandQueue
const cairo_region_t *scissor,
guint default_framebuffer);
int gsk_gl_command_queue_upload_texture (GskGLCommandQueue *self,
GdkTexture *texture);
GdkTexture *texture,
gboolean ensure_mipmap,
gboolean *out_can_mipmap);
int gsk_gl_command_queue_create_texture (GskGLCommandQueue *self,
int width,
int height,
@ -327,8 +329,10 @@ typedef struct {
} GskGLTextureChunk;
int gsk_gl_command_queue_upload_texture_chunks(GskGLCommandQueue *self,
gboolean ensure_mipmap,
unsigned int n_chunks,
GskGLTextureChunk *chunks);
GskGLTextureChunk *chunks,
gboolean *out_can_mipmap);
guint gsk_gl_command_queue_create_framebuffer (GskGLCommandQueue *self);
gboolean gsk_gl_command_queue_create_render_target (GskGLCommandQueue *self,

View File

@ -925,6 +925,7 @@ gsk_gl_driver_load_texture (GskGLDriver *self,
guint texture_id;
int height;
int width;
gboolean can_mipmap = FALSE;
g_return_val_if_fail (GSK_IS_GL_DRIVER (self), 0);
g_return_val_if_fail (GDK_IS_TEXTURE (texture), 0);
@ -938,7 +939,7 @@ gsk_gl_driver_load_texture (GskGLDriver *self,
t = gdk_texture_get_render_data (texture, self);
if (t && t->texture_id)
{
if (ensure_mipmap && !t->has_mipmap)
if (ensure_mipmap && t->can_mipmap && !t->has_mipmap)
{
glBindTexture (GL_TEXTURE_2D, t->texture_id);
glGenerateMipmap (GL_TEXTURE_2D);
@ -948,7 +949,7 @@ gsk_gl_driver_load_texture (GskGLDriver *self,
return t->texture_id;
}
if (GDK_IS_DMABUF_TEXTURE (texture))
if (GDK_IS_DMABUF_TEXTURE (texture) && !ensure_mipmap)
{
texture_id = gsk_gl_driver_import_dmabuf_texture (self, GDK_DMABUF_TEXTURE (texture));
}
@ -975,7 +976,7 @@ gsk_gl_driver_load_texture (GskGLDriver *self,
*/
gdk_gl_context_make_current (context);
texture_id = gsk_gl_command_queue_upload_texture (self->command_queue, GDK_TEXTURE (downloaded_texture));
texture_id = gsk_gl_command_queue_upload_texture (self->command_queue, GDK_TEXTURE (downloaded_texture), ensure_mipmap, &can_mipmap);
}
width = gdk_texture_get_width (texture);
@ -984,8 +985,10 @@ gsk_gl_driver_load_texture (GskGLDriver *self,
t = gsk_gl_texture_new (texture_id,
width, height,
self->current_frame_id);
t->can_mipmap = can_mipmap;
if (ensure_mipmap)
{
g_assert (can_mipmap);
glBindTexture (GL_TEXTURE_2D, t->texture_id);
glGenerateMipmap (GL_TEXTURE_2D);
t->has_mipmap = TRUE;
@ -1433,6 +1436,7 @@ gsk_gl_driver_add_texture_slices (GskGLDriver *self,
GdkMemoryTexture *memtex2 = NULL;
GdkMemoryTexture *memtex3 = NULL;
GdkMemoryTexture *memtex4 = NULL;
gboolean can_mipmap = TRUE, slice_can_mipmap;
g_assert (GSK_IS_GL_DRIVER (self));
g_assert (GDK_IS_TEXTURE (texture));
@ -1694,7 +1698,7 @@ gsk_gl_driver_add_texture_slices (GskGLDriver *self,
n_chunks++;
}
texture_id = gsk_gl_command_queue_upload_texture_chunks (self->command_queue, n_chunks, chunks);
texture_id = gsk_gl_command_queue_upload_texture_chunks (self->command_queue, TRUE, n_chunks, chunks, &slice_can_mipmap);
glBindTexture (GL_TEXTURE_2D, texture_id);
glGenerateMipmap (GL_TEXTURE_2D);
@ -1707,10 +1711,12 @@ gsk_gl_driver_add_texture_slices (GskGLDriver *self,
GdkTexture *subtex;
subtex = gdk_memory_texture_new_subtexture (memtex, x, y, slice_width, slice_height);
texture_id = gsk_gl_command_queue_upload_texture (self->command_queue, subtex);
texture_id = gsk_gl_command_queue_upload_texture (self->command_queue, subtex, FALSE, &slice_can_mipmap);
g_object_unref (subtex);
}
can_mipmap &= slice_can_mipmap;
slices[slice_index].rect.x = x;
slices[slice_index].rect.y = y;
slices[slice_index].rect.width = slice_width;
@ -1737,6 +1743,7 @@ gsk_gl_driver_add_texture_slices (GskGLDriver *self,
t = gsk_gl_texture_new (0,
tex_width, tex_height,
self->current_frame_id);
t->can_mipmap = can_mipmap;
t->has_mipmap = ensure_mipmap;
/* Use gsk_gl_texture_free() as destroy notify here since we are

View File

@ -73,6 +73,8 @@ struct _GskGLTexture
/* Set when used by an atlas so we don't drop the texture */
guint permanent : 1;
/* we are allowed to call glGenerateMipmap() for this texture */
guint can_mipmap : 1;
/* we called glGenerateMipmap() for this texture */
guint has_mipmap : 1;
};

View File

@ -66,11 +66,11 @@ gdk_array(test_splice) (void)
{
gsize old_size = gdk_array(get_size) (&v);
pos = g_random_int_range (0, old_size + 1);
pos = g_test_rand_int_range (0, old_size + 1);
g_assert_true (pos <= old_size);
remove = g_random_int_range (0, 4);
remove = g_test_rand_int_range (0, 4);
remove = MIN (remove, old_size - pos);
add = g_random_int_range (0, 4);
add = g_test_rand_int_range (0, 4);
for (j = 0; j < remove; j++)
sum -= gdk_array(get) (&v, pos + j);

View File

@ -67,7 +67,7 @@ create_random_content_formats (void)
for (i = 0; i < n; i++)
{
gsize j = g_random_int_range (0, G_N_ELEMENTS (possible_types));
gsize j = g_test_rand_int_range (0, G_N_ELEMENTS (possible_types));
if (possible_types[j].type_func)
gdk_content_formats_builder_add_gtype (builder, possible_types[j].type_func ());
else if (possible_types[j].mime_type)

View File

@ -59,7 +59,7 @@ test_allowed_backends (gconstpointer data)
g_assert_cmpint (api & allowed, ==, api);
g_assert_cmpint (api & not_allowed, ==, 0);
random_apis = g_random_int_range (0, ALL_APIS + 1);
random_apis = g_test_rand_int_range (0, ALL_APIS + 1);
gdk_gl_context_set_allowed_apis (context, random_apis);
g_assert_cmpint (gdk_gl_context_get_allowed_apis (context), ==, random_apis);
g_assert_cmpint (gdk_gl_context_get_api (context), ==, api);

View File

@ -71,7 +71,7 @@ random_representable_float (void)
{
/* generate a random float thats representable as fp16 */
memset (h, 0, sizeof (h));
h[0] = g_random_int_range (G_MININT16, G_MAXINT16);
h[0] = g_test_rand_int_range (G_MININT16, G_MAXINT16);
half_to_float4 (h, f);
}
while (!isnormal (f[0])); /* skip nans and infs since they don't compare well */
@ -127,8 +127,8 @@ test_many (void)
{
for (int i = 0; i < 100; i++)
{
int size = g_random_int_range (100, 200);
int offset = g_random_int_range (0, 20);
int size = g_test_rand_int_range (100, 200);
int offset = g_test_rand_int_range (0, 20);
guint16 *h = g_new0 (guint16, size);
float *f = g_new0 (float, size);
@ -150,8 +150,8 @@ test_many_c (void)
{
for (int i = 0; i < 100; i++)
{
int size = g_random_int_range (100, 200);
int offset = g_random_int_range (0, 20);
int size = g_test_rand_int_range (100, 200);
int offset = g_test_rand_int_range (0, 20);
guint16 *h = g_new0 (guint16, size);
float *f = g_new0 (float, size);

View File

@ -551,7 +551,7 @@ test_in_fill_rotated (void)
for (j = 0; j < 100; j++)
{
GskFillRule fill_rule = g_random_int_range (0, N_FILL_RULES);
GskFillRule fill_rule = g_test_rand_int_range (0, N_FILL_RULES);
float x = g_test_rand_double_range (-1000, 1000);
float y = g_test_rand_double_range (-1000, 1000);

View File

@ -62,7 +62,7 @@ test_sort (void)
for (i = 0; i < 100; i++)
{
r = g_random_int_range (0, 1000);
r = g_test_rand_int_range (0, 1000);
s = g_strdup_printf ("%d: %d", i, r);
label = gtk_label_new (s);
g_object_set_data (G_OBJECT (label), "data", GINT_TO_POINTER (r));

View File

@ -439,7 +439,7 @@ fisher_yates_shuffle (guint n_items)
for (i = 0; i < n_items; i++)
{
j = g_random_int_range (0, i + 1);
j = g_test_rand_int_range (0, i + 1);
list[i] = list[j];
list[j] = i;
}

View File

@ -251,7 +251,7 @@ fisher_yates_shuffle (GListStore *store)
n = g_list_model_get_n_items (G_LIST_MODEL (store));
for (i = 0; i < n; i++)
{
int pos = g_random_int_range (0, n - i);
int pos = g_test_rand_int_range (0, n - i);
GObject *item;
item = g_list_model_get_item (G_LIST_MODEL (store), pos);
@ -706,7 +706,7 @@ modify_sorter (GtkSorter *multi)
guint option;
current = g_list_model_get_item (G_LIST_MODEL (multi), 0);
option = g_random_int_range (0, G_N_ELEMENTS (options));
option = g_test_rand_int_range (0, G_N_ELEMENTS (options));
if (current == NULL || options[option].type != G_OBJECT_TYPE (current) || options[option].modify_func == NULL)
{
@ -760,7 +760,7 @@ test_stable (void)
for (i = 0; i < 100; i++)
{
modify_sorter (g_random_boolean () ? a : b);
modify_sorter (g_test_rand_bit () ? a : b);
assert_model_equal (model1, model2);
}

View File

@ -516,7 +516,7 @@ new_shuffled_store (guint size)
add (store, 1);
for (i = 1; i < size; i++)
insert (store, g_random_int_range (0, i), i + 1);
insert (store, g_test_rand_int_range (0, i), i + 1);
return store;
}
@ -555,7 +555,7 @@ test_incremental_remove (void)
{
guint position;
position = g_random_int_range (0, g_list_model_get_n_items (G_LIST_MODEL (store)) - 10);
position = g_test_rand_int_range (0, g_list_model_get_n_items (G_LIST_MODEL (store)) - 10);
for (i = 0; i < 10; i++)
{
GObject *item = g_list_model_get_item (G_LIST_MODEL (store), position + i);