gpu: Make sure textures used as image are mipmapped

When getting a texture as image, we were always returning the texture
unconditionally.

However, we want to mipmap textures when the scale factor is too large,
and this code path did not do that.

The same codepath on the GL renderer doesn't do that either, so the test
is disabled for it.
This commit is contained in:
Benjamin Otte 2024-07-07 07:19:43 +02:00
parent ab37fed974
commit 31a907be35
4 changed files with 54 additions and 3 deletions

View File

@ -1420,6 +1420,22 @@ gsk_gpu_node_processor_add_border_node (GskGpuNodeProcessor *self,
colors);
}
static gboolean
texture_node_should_mipmap (GskRenderNode *node,
GskGpuFrame *frame,
const graphene_vec2_t *scale)
{
GdkTexture *texture;
texture = gsk_texture_node_get_texture (node);
if (!gsk_gpu_frame_should_optimize (frame, GSK_GPU_OPTIMIZE_MIPMAP))
return FALSE;
return gdk_texture_get_width (texture) > 2 * node->bounds.size.width * graphene_vec2_get_x (scale) ||
gdk_texture_get_height (texture) > 2 * node->bounds.size.height * graphene_vec2_get_y (scale);
}
static void
gsk_gpu_node_processor_add_texture_node (GskGpuNodeProcessor *self,
GskRenderNode *node)
@ -1448,9 +1464,7 @@ gsk_gpu_node_processor_add_texture_node (GskGpuNodeProcessor *self,
}
}
if (gsk_gpu_frame_should_optimize (self->frame, GSK_GPU_OPTIMIZE_MIPMAP) &&
(gdk_texture_get_width (texture) > 2 * node->bounds.size.width * graphene_vec2_get_x (&self->scale) ||
gdk_texture_get_height (texture) > 2 * node->bounds.size.height * graphene_vec2_get_y (&self->scale)))
if (texture_node_should_mipmap (node, self->frame, &self->scale))
{
guint32 descriptor;
@ -1504,6 +1518,9 @@ gsk_gpu_get_texture_node_as_image (GskGpuFrame *frame,
gint64 timestamp = gsk_gpu_frame_get_timestamp (frame);
GskGpuImage *image;
if (texture_node_should_mipmap (node, frame, scale))
return gsk_gpu_get_node_as_image_via_offscreen (frame, clip_bounds, scale, node, out_bounds);
image = gsk_gpu_cache_lookup_texture_image (gsk_gpu_device_get_cache (device), texture, timestamp);
if (image == NULL)
image = gsk_gpu_frame_upload_texture (frame, FALSE, texture);

View File

@ -0,0 +1,33 @@
texture {
bounds: 0 0 25 25;
texture: "texture1" url("data:image/png;base64,\
iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAACkElEQVR4nO3XoQHDMBAEwXMqcP9V\
qoMEBDtgUcAMWyb2uuts7/ucbdu5722b1vrb1855/8NDtP7Hfg14dPliaf3cLgj8YINobYNAY4No\
bYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNA\
Y4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4No\
bYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNA\
Y4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4No\
bYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNA\
Y4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4No\
bYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNA\
Y4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4No\
bYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNA\
Y4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4NobYNAY4No\
bYNAY4No/aM/Uzkk29ZNdeQAAAAASUVORK5CYII=\
");
}
color-matrix {
child: texture {
bounds: 25 0 25 25;
texture: "texture1";
}
}
color-matrix {
child: debug {
message: "magic bugfix";
child: texture {
bounds: 50 0 25 25;
texture: "texture1";
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

View File

@ -171,6 +171,7 @@ compare_render_tests = [
'text-mixed-color-nocairo',
'text-mixed-color-colrv1',
'texture-coords',
'texture-offscreen-mipmap-nogl',
'texture-scale-filters-nocairo',
'texture-scale-magnify-10000x',
'texture-scale-magnify-rotate',