mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
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:
parent
15a8baee03
commit
3f3f3766be
Notes:
sideshowbarker
2024-07-17 06:00:02 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/3f3f3766be Pull-request: https://github.com/SerenityOS/serenity/pull/24431
1 changed files with 11 additions and 5 deletions
|
@ -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,
|
||||
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) {
|
||||
for (int row = 0; row < mask_src.height(); ++row) {
|
||||
for (int col = 0; col < mask_src.width(); ++col) {
|
||||
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();
|
||||
if (m_corner_clip == CornerClip::Outside)
|
||||
mask_alpha = ~mask_pixel.alpha();
|
||||
auto final_pixel = Color();
|
||||
if (mask_alpha > 0) {
|
||||
auto page_pixel = page_painter.get_pixel(page_location.translated(col, row));
|
||||
if (page_pixel.has_value())
|
||||
final_pixel = page_pixel.value().with_alpha(mask_alpha);
|
||||
auto position = page_location.translated(col, row);
|
||||
position.translate_by(translation);
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue