diff --git a/Libraries/LibDraw/Painter.cpp b/Libraries/LibDraw/Painter.cpp index 8ecb91571a..24642c715a 100644 --- a/Libraries/LibDraw/Painter.cpp +++ b/Libraries/LibDraw/Painter.cpp @@ -54,6 +54,24 @@ void Painter::fill_rect_with_draw_op(const Rect& a_rect, Color color) } } +void Painter::clear_rect(const Rect& a_rect, Color color) +{ + auto rect = a_rect.translated(translation()).intersected(clip_rect()); + if (rect.is_empty()) + return; + + ASSERT(m_target->rect().contains(rect)); + + RGBA32* dst = m_target->scanline(rect.top()) + rect.left(); + const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); + + for (int i = rect.height() - 1; i >= 0; --i) { + fast_u32_fill(dst, color.value(), rect.width()); + dst += dst_skip; + } +} + + void Painter::fill_rect(const Rect& a_rect, Color color) { if (color.alpha() == 0) @@ -64,6 +82,11 @@ void Painter::fill_rect(const Rect& a_rect, Color color) return; } + if (color.alpha() == 0xff) { + clear_rect(a_rect, color); + return; + } + auto rect = a_rect.translated(translation()).intersected(clip_rect()); if (rect.is_empty()) return; @@ -73,14 +96,6 @@ void Painter::fill_rect(const Rect& a_rect, Color color) RGBA32* dst = m_target->scanline(rect.top()) + rect.left(); const size_t dst_skip = m_target->pitch() / sizeof(RGBA32); - if (color.alpha() == 0xff) { - for (int i = rect.height() - 1; i >= 0; --i) { - fast_u32_fill(dst, color.value(), rect.width()); - dst += dst_skip; - } - return; - } - for (int i = rect.height() - 1; i >= 0; --i) { for (int j = 0; j < rect.width(); ++j) dst[j] = Color::from_rgba(dst[j]).blend(color).value(); diff --git a/Libraries/LibDraw/Painter.h b/Libraries/LibDraw/Painter.h index ddbfc0162e..75cdecad6d 100644 --- a/Libraries/LibDraw/Painter.h +++ b/Libraries/LibDraw/Painter.h @@ -19,6 +19,7 @@ class Painter { public: explicit Painter(GraphicsBitmap&); ~Painter(); + void clear_rect(const Rect&, Color); void fill_rect(const Rect&, Color); void fill_rect_with_gradient(const Rect&, Color gradient_start, Color gradient_end); void draw_rect(const Rect&, Color, bool rough = false);