Commit 849692b2 authored by Matthias Clasen's avatar Matthias Clasen
Browse files

ngl: Fix unevenly scaled shadows

Ensure that we don't cut them off at the edges.
parent f3bf4e48
Pipeline #273936 failed with stages
in 18 minutes and 40 seconds
......@@ -2299,7 +2299,8 @@ gsk_ngl_render_job_visit_blurred_outset_shadow_node (GskNglRenderJob *job,
float blur_radius = gsk_outset_shadow_node_get_blur_radius (node);
float blur_extra = blur_radius * 2.0f; /* 2.0 = shader radius_multiplier */
float half_blur_extra = blur_extra / 2.0f;
int extra_blur_pixels = ceilf (half_blur_extra * scale_x);
int extra_blur_pixels_x = ceilf (half_blur_extra * scale_x);
int extra_blur_pixels_y = ceilf (half_blur_extra * scale_y);
float spread = gsk_outset_shadow_node_get_spread (node);
float dx = gsk_outset_shadow_node_get_dx (node);
float dy = gsk_outset_shadow_node_get_dy (node);
......@@ -2352,10 +2353,10 @@ gsk_ngl_render_job_visit_blurred_outset_shadow_node (GskNglRenderJob *job,
texture_width = (int)ceil ((scaled_outline.bounds.size.width + blur_extra) * scale_x);
texture_height = (int)ceil ((scaled_outline.bounds.size.height + blur_extra) * scale_y);
scaled_outline.bounds.origin.x = extra_blur_pixels;
scaled_outline.bounds.origin.y = extra_blur_pixels;
scaled_outline.bounds.size.width = texture_width - (extra_blur_pixels * 2);
scaled_outline.bounds.size.height = texture_height - (extra_blur_pixels * 2);
scaled_outline.bounds.origin.x = extra_blur_pixels_x;
scaled_outline.bounds.origin.y = extra_blur_pixels_y;
scaled_outline.bounds.size.width = texture_width - (extra_blur_pixels_x * 2);
scaled_outline.bounds.size.height = texture_height - (extra_blur_pixels_y * 2);
for (guint i = 0; i < G_N_ELEMENTS (scaled_outline.corner); i++)
{
......@@ -2493,12 +2494,13 @@ gsk_ngl_render_job_visit_blurred_outset_shadow_node (GskNglRenderJob *job,
GskNglTexture *texture;
texture = gsk_ngl_driver_get_texture_by_id (job->driver, blurred_texture_id);
slices = gsk_ngl_texture_get_nine_slice (texture, &scaled_outline, extra_blur_pixels);
slices = gsk_ngl_texture_get_nine_slice (texture, &scaled_outline, extra_blur_pixels_x, extra_blur_pixels_y);
offscreen.was_offscreen = TRUE;
/* Our texture coordinates MUST be scaled, while the actual vertex coords
* MUST NOT be scaled. */
* MUST NOT be scaled.
*/
left_width = slices[NINE_SLICE_TOP_LEFT].rect.width / scale_x;
right_width = slices[NINE_SLICE_TOP_RIGHT].rect.width / scale_x;
......
......@@ -170,7 +170,8 @@ gsk_ngl_texture_new (guint texture_id,
const GskNglTextureNineSlice *
gsk_ngl_texture_get_nine_slice (GskNglTexture *texture,
const GskRoundedRect *outline,
float extra_pixels)
float extra_pixels_x,
float extra_pixels_y)
{
g_assert (texture != NULL);
g_assert (outline != NULL);
......@@ -180,7 +181,7 @@ gsk_ngl_texture_get_nine_slice (GskNglTexture *texture,
texture->nine_slice = g_new0 (GskNglTextureNineSlice, 9);
nine_slice_rounded_rect (texture->nine_slice, outline);
nine_slice_grow (texture->nine_slice, extra_pixels);
nine_slice_grow (texture->nine_slice, extra_pixels_x, extra_pixels_y);
nine_slice_to_texture_coords (texture->nine_slice, texture->width, texture->height);
}
......
......@@ -94,7 +94,8 @@ GskNglTexture *gsk_ngl_texture_new (guint
gint64 frame_id);
const GskNglTextureNineSlice *gsk_ngl_texture_get_nine_slice (GskNglTexture *texture,
const GskRoundedRect *outline,
float extra_pixels);
float extra_pixels_x,
float extra_pixels_y);
void gsk_ngl_texture_free (GskNglTexture *texture);
G_END_DECLS
......
......@@ -159,121 +159,122 @@ nine_slice_to_texture_coords (GskNglTextureNineSlice *slices,
static inline void
nine_slice_grow (GskNglTextureNineSlice *slices,
int amount)
int amount_x,
int amount_y)
{
if (amount == 0)
if (amount_x == 0 && amount_y == 0)
return;
/* top left */
slices[0].rect.x -= amount;
slices[0].rect.y -= amount;
if (amount > slices[0].rect.width)
slices[0].rect.width += amount * 2;
slices[0].rect.x -= amount_x;
slices[0].rect.y -= amount_y;
if (amount_x > slices[0].rect.width)
slices[0].rect.width += amount_x * 2;
else
slices[0].rect.width += amount;
slices[0].rect.width += amount_x;
if (amount > slices[0].rect.height)
slices[0].rect.height += amount * 2;
if (amount_y > slices[0].rect.height)
slices[0].rect.height += amount_y * 2;
else
slices[0].rect.height += amount;
slices[0].rect.height += amount_y;
/* Top center */
slices[1].rect.y -= amount;
if (amount > slices[1].rect.height)
slices[1].rect.height += amount * 2;
slices[1].rect.y -= amount_y;
if (amount_y > slices[1].rect.height)
slices[1].rect.height += amount_y * 2;
else
slices[1].rect.height += amount;
slices[1].rect.height += amount_y;
/* top right */
slices[2].rect.y -= amount;
if (amount > slices[2].rect.width)
slices[2].rect.y -= amount_y;
if (amount_x > slices[2].rect.width)
{
slices[2].rect.x -= amount;
slices[2].rect.width += amount * 2;
slices[2].rect.x -= amount_x;
slices[2].rect.width += amount_x * 2;
}
else
{
slices[2].rect.width += amount;
slices[2].rect.width += amount_x;
}
if (amount > slices[2].rect.height)
slices[2].rect.height += amount * 2;
if (amount_y > slices[2].rect.height)
slices[2].rect.height += amount_y * 2;
else
slices[2].rect.height += amount;
slices[2].rect.height += amount_y;
slices[3].rect.x -= amount;
if (amount > slices[3].rect.width)
slices[3].rect.width += amount * 2;
slices[3].rect.x -= amount_x;
if (amount_x > slices[3].rect.width)
slices[3].rect.width += amount_x * 2;
else
slices[3].rect.width += amount;
slices[3].rect.width += amount_x;
/* Leave center alone */
if (amount > slices[5].rect.width)
if (amount_x > slices[5].rect.width)
{
slices[5].rect.x -= amount;
slices[5].rect.width += amount * 2;
slices[5].rect.x -= amount_x;
slices[5].rect.width += amount_x * 2;
}
else
{
slices[5].rect.width += amount;
slices[5].rect.width += amount_x;
}
/* Bottom left */
slices[6].rect.x -= amount;
if (amount > slices[6].rect.width)
slices[6].rect.x -= amount_x;
if (amount_x > slices[6].rect.width)
{
slices[6].rect.width += amount * 2;
slices[6].rect.width += amount_x * 2;
}
else
{
slices[6].rect.width += amount;
slices[6].rect.width += amount_x;
}
if (amount > slices[6].rect.height)
if (amount_y > slices[6].rect.height)
{
slices[6].rect.y -= amount;
slices[6].rect.height += amount * 2;
slices[6].rect.y -= amount_y;
slices[6].rect.height += amount_y * 2;
}
else
{
slices[6].rect.height += amount;
slices[6].rect.height += amount_y;
}
/* Bottom center */
if (amount > slices[7].rect.height)
if (amount_y > slices[7].rect.height)
{
slices[7].rect.y -= amount;
slices[7].rect.height += amount * 2;
slices[7].rect.y -= amount_y;
slices[7].rect.height += amount_y * 2;
}
else
{
slices[7].rect.height += amount;
slices[7].rect.height += amount_y;
}
if (amount > slices[8].rect.width)
if (amount_x > slices[8].rect.width)
{
slices[8].rect.x -= amount;
slices[8].rect.width += amount * 2;
slices[8].rect.x -= amount_x;
slices[8].rect.width += amount_x * 2;
}
else
{
slices[8].rect.width += amount;
slices[8].rect.width += amount_x;
}
if (amount > slices[8].rect.height)
if (amount_y > slices[8].rect.height)
{
slices[8].rect.y -= amount;
slices[8].rect.height += amount * 2;
slices[8].rect.y -= amount_y;
slices[8].rect.height += amount_y * 2;
}
else
{
slices[8].rect.height += amount;
slices[8].rect.height += amount_y;
}
#ifdef DEBUG_NINE_SLICE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment