blur-effect: Floor downscaled frambuffer sizes

Floor the downscaled size of the new framebuffer to make sure we don't
initialize a framebuffer with a floating point value that might be
interpreted wrong by `cogl_texture_2d_new_with_size` and end up with a
slightly wrong aspect ratio of the framebuffer.

This fixes situations where the widths or heights of downscaled
framebuffers sometimes miss some pixels at the border.

While at it, remove the `downscale_factor` argument from
`setup_projection_matrix` since that function doesn't need the initial
size of the actor anyway.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/991
This commit is contained in:
Jonas Dreßler 2020-02-10 15:22:33 +01:00 committed by Georges Basile Stavracas Neto
parent b4d491a4d2
commit ea2ddaa9dd

View File

@ -323,21 +323,18 @@ update_brightness_uniform (ShellBlurEffect *self)
static void
setup_projection_matrix (CoglFramebuffer *framebuffer,
float width,
float height,
float downscale_factor)
float height)
{
CoglMatrix projection;
float downscaled_width = width / downscale_factor;
float downscaled_height = height / downscale_factor;
cogl_matrix_init_identity (&projection);
cogl_matrix_scale (&projection,
2.0 / downscaled_width,
-2.0 / downscaled_height,
2.0 / width,
-2.0 / height,
1.f);
cogl_matrix_translate (&projection,
-downscaled_width / 2.0,
-downscaled_height / 2.0,
-width / 2.0,
-height / 2.0,
0);
cogl_framebuffer_set_projection_matrix (framebuffer, &projection);
@ -355,10 +352,10 @@ update_fbo (FramebufferData *data,
g_clear_pointer (&data->texture, cogl_object_unref);
g_clear_pointer (&data->framebuffer, cogl_object_unref);
data->texture =
cogl_texture_2d_new_with_size (ctx,
width / downscale_factor,
height / downscale_factor);
float new_width = floorf (width / downscale_factor);
float new_height = floorf (height / downscale_factor);
data->texture = cogl_texture_2d_new_with_size (ctx, new_width, new_height);
if (!data->texture)
return FALSE;
@ -371,7 +368,7 @@ update_fbo (FramebufferData *data,
return FALSE;
}
setup_projection_matrix (data->framebuffer, width, height, downscale_factor);
setup_projection_matrix (data->framebuffer, new_width, new_height);
return TRUE;
}