mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
Optimize Painter::draw_rect() a bit.
Reorganize the loops to make it go fast. The draw_rect() part of painting window frames is now ~2.65x faster.
This commit is contained in:
parent
f651405694
commit
b6c3df5188
Notes:
sideshowbarker
2024-07-19 16:01:18 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b6c3df51889
2 changed files with 25 additions and 8 deletions
|
@ -60,14 +60,31 @@ void Painter::draw_rect(const Rect& rect, Color color)
|
|||
int min_x = max(r.left(), m_clip_rect.left());
|
||||
int max_x = min(r.right(), m_clip_rect.right());
|
||||
|
||||
for (int y = min_y; y <= max_y; ++y) {
|
||||
auto* bits = m_target->scanline(y);
|
||||
if (y == r.top() || y == r.bottom()) {
|
||||
fast_dword_fill(bits + min_x, color.value(), max_x - min_x + 1);
|
||||
} else {
|
||||
if (r.left() >= m_clip_rect.left() && r.left() <= m_clip_rect.right())
|
||||
if (r.top() >= min_y && r.top() <= max_y) {
|
||||
fast_dword_fill(m_target->scanline(r.top()) + min_x, color.value(), max_x - min_x + 1);
|
||||
++min_y;
|
||||
}
|
||||
if (r.bottom() <= max_y && r.bottom() >= min_y) {
|
||||
fast_dword_fill(m_target->scanline(r.bottom()) + min_x, color.value(), max_x - min_x + 1);
|
||||
--max_y;
|
||||
}
|
||||
|
||||
bool draw_left_side = r.left() >= m_clip_rect.left() && r.left() <= m_clip_rect.right();
|
||||
bool draw_right_side = r.right() >= m_clip_rect.left() && r.right() <= m_clip_rect.right();
|
||||
|
||||
if (draw_left_side && draw_right_side) {
|
||||
// Specialized loop when drawing both sides.
|
||||
for (int y = min_y; y <= max_y; ++y) {
|
||||
auto* bits = m_target->scanline(y);
|
||||
bits[r.left()] = color.value();
|
||||
bits[r.right()] = color.value();
|
||||
}
|
||||
} else {
|
||||
for (int y = min_y; y <= max_y; ++y) {
|
||||
auto* bits = m_target->scanline(y);
|
||||
if (draw_left_side)
|
||||
bits[r.left()] = color.value();
|
||||
if (r.right() >= m_clip_rect.left() && r.right() <= m_clip_rect.right())
|
||||
if (draw_right_side)
|
||||
bits[r.right()] = color.value();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,9 +158,9 @@ void WSWindowManager::paintWindowFrame(WSWindow& window)
|
|||
auto titleColor = &window == activeWindow() ? m_activeWindowTitleColor : m_inactiveWindowTitleColor;
|
||||
auto borderColor = &window == activeWindow() ? m_activeWindowBorderColor : m_inactiveWindowBorderColor;
|
||||
|
||||
m_back_painter->fill_rect(titleBarRect, borderColor);
|
||||
m_back_painter->draw_rect(borderRect, Color::MidGray);
|
||||
m_back_painter->draw_rect(outerRect, borderColor);
|
||||
m_back_painter->fill_rect(titleBarRect, borderColor);
|
||||
m_back_painter->draw_rect(inner_border_rect, borderColor);
|
||||
m_back_painter->draw_text(titleBarTitleRect, window.title(), Painter::TextAlignment::CenterLeft, titleColor);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue