1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

WindowServer: Don't crash on wallpapers smaller than the desktop with fill mode 'simple'

blit() calls draw_scaled_bitmap() behind the scenes in scaled contexts,
and that doesn't  like src_rect to be outside of the source bitmap's
bounds. Implicitly clip with the source rect, like the non-scaled
codepath already does.

Fixes #5017 even more.
This commit is contained in:
Nico Weber 2021-01-22 18:56:01 -05:00 committed by Andreas Kling
parent dcc967d1ad
commit 345909c009
3 changed files with 8 additions and 6 deletions

View file

@ -660,11 +660,11 @@ void Painter::blit_offset(const IntPoint& a_position, const Gfx::Bitmap& source,
void Painter::blit_with_alpha(const IntPoint& position, const Gfx::Bitmap& source, const IntRect& a_src_rect)
{
auto safe_src_rect = a_src_rect.intersected(source.rect());
if (scale() != source.scale())
return draw_scaled_bitmap({ position, a_src_rect.size() }, source, a_src_rect);
return draw_scaled_bitmap({ position, safe_src_rect.size() }, source, safe_src_rect);
ASSERT(source.has_alpha_channel());
IntRect safe_src_rect = a_src_rect.intersected(source.rect());
auto dst_rect = IntRect(position, safe_src_rect.size()).translated(translation());
auto clipped_rect = dst_rect.intersected(clip_rect());
@ -709,13 +709,13 @@ void Painter::blit(const IntPoint& position, const Gfx::Bitmap& source, const In
return blit_with_opacity(position, source, a_src_rect, opacity);
if (source.has_alpha_channel())
return blit_with_alpha(position, source, a_src_rect);
auto safe_src_rect = a_src_rect.intersected(source.rect());
if (scale() != source.scale())
return draw_scaled_bitmap({ position, a_src_rect.size() }, source, a_src_rect, opacity);
return draw_scaled_bitmap({ position, safe_src_rect.size() }, source, safe_src_rect, opacity);
// If we get here, the Painter might have a scale factor, but the source bitmap has the same scale factor.
// We need to transform from logical to physical coordinates, but we can just copy pixels without resampling.
auto safe_src_rect = a_src_rect.intersected(source.rect());
ASSERT(source.rect().contains(safe_src_rect));
auto dst_rect = IntRect(position, safe_src_rect.size()).translated(translation());
auto clipped_rect = dst_rect.intersected(clip_rect());
if (clipped_rect.is_empty())