LibWeb: Make sample_under_corners() go faster

Both page target bitmap and mask bitmap are always BGRA8888, so we can
use `get_pixel<StorageFormat::BGRA8888>` and
`set_pixel<StorageFormat::BGRA8888>` to avoid branching by not
checking a bitmap format.
This commit is contained in:
Aliaksandr Kalenik 2024-05-24 10:18:01 +01:00 committed by Andreas Kling
parent 15a8baee03
commit 3f3f3766be
Notes: sideshowbarker 2024-07-17 06:00:02 +09:00

View file

@ -61,21 +61,27 @@ void BorderRadiusCornerClipper::sample_under_corners(Gfx::Painter& page_painter)
corner_aa_painter.fill_rect_with_rounded_corners(m_corner_bitmap->rect(), Color::NamedColor::Black, corner_aa_painter.fill_rect_with_rounded_corners(m_corner_bitmap->rect(), Color::NamedColor::Black,
m_data.corner_radii.top_left, m_data.corner_radii.top_right, m_data.corner_radii.bottom_right, m_data.corner_radii.bottom_left); m_data.corner_radii.top_left, m_data.corner_radii.top_right, m_data.corner_radii.bottom_right, m_data.corner_radii.bottom_left);
auto clip_rect = page_painter.clip_rect();
auto translation = page_painter.translation();
auto copy_page_masked = [&](Gfx::IntRect const& mask_src, Gfx::IntPoint const& page_location) { auto copy_page_masked = [&](Gfx::IntRect const& mask_src, Gfx::IntPoint const& page_location) {
for (int row = 0; row < mask_src.height(); ++row) { for (int row = 0; row < mask_src.height(); ++row) {
for (int col = 0; col < mask_src.width(); ++col) { for (int col = 0; col < mask_src.width(); ++col) {
auto corner_location = mask_src.location().translated(col, row); auto corner_location = mask_src.location().translated(col, row);
auto mask_pixel = m_corner_bitmap->get_pixel(corner_location); auto mask_pixel = m_corner_bitmap->get_pixel<Gfx::StorageFormat::BGRA8888>(corner_location.x(), corner_location.y());
u8 mask_alpha = mask_pixel.alpha(); u8 mask_alpha = mask_pixel.alpha();
if (m_corner_clip == CornerClip::Outside) if (m_corner_clip == CornerClip::Outside)
mask_alpha = ~mask_pixel.alpha(); mask_alpha = ~mask_pixel.alpha();
auto final_pixel = Color(); auto final_pixel = Color();
if (mask_alpha > 0) { if (mask_alpha > 0) {
auto page_pixel = page_painter.get_pixel(page_location.translated(col, row)); auto position = page_location.translated(col, row);
if (page_pixel.has_value()) position.translate_by(translation);
final_pixel = page_pixel.value().with_alpha(mask_alpha); if (!clip_rect.contains(position))
continue;
auto page_pixel = page_painter.target()->get_pixel<Gfx::StorageFormat::BGRA8888>(position.x(), position.y());
final_pixel = page_pixel.with_alpha(mask_alpha);
} }
m_corner_bitmap->set_pixel(corner_location, final_pixel); m_corner_bitmap->set_pixel<Gfx::StorageFormat::BGRA8888>(corner_location.x(), corner_location.y(), final_pixel);
} }
} }
}; };