mirror of
https://github.com/RGBCube/serenity
synced 2025-07-13 16:07:34 +00:00

BorderRadiusCornerClipper usage to clip border radius is specific to CPU painter so it should not be stored in painting commands. Also with this change bitmaps for corner sampling are allocated during painting commands replaying instead of commands recording.
85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGfx/AntiAliasingPainter.h>
|
|
#include <LibGfx/Forward.h>
|
|
#include <LibWeb/CSS/ComputedValues.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
struct BorderRadiusData {
|
|
CSSPixels horizontal_radius { 0 };
|
|
CSSPixels vertical_radius { 0 };
|
|
|
|
Gfx::AntiAliasingPainter::CornerRadius as_corner(PaintContext& context) const;
|
|
|
|
inline operator bool() const
|
|
{
|
|
return horizontal_radius > 0 && vertical_radius > 0;
|
|
}
|
|
|
|
inline void shrink(CSSPixels horizontal, CSSPixels vertical)
|
|
{
|
|
if (horizontal_radius != 0)
|
|
horizontal_radius = max(CSSPixels(0), horizontal_radius - horizontal);
|
|
if (vertical_radius != 0)
|
|
vertical_radius = max(CSSPixels(0), vertical_radius - vertical);
|
|
}
|
|
};
|
|
|
|
using CornerRadius = Gfx::AntiAliasingPainter::CornerRadius;
|
|
|
|
struct CornerRadii {
|
|
CornerRadius top_left;
|
|
CornerRadius top_right;
|
|
CornerRadius bottom_right;
|
|
CornerRadius bottom_left;
|
|
|
|
inline bool has_any_radius() const
|
|
{
|
|
return top_left || top_right || bottom_right || bottom_left;
|
|
}
|
|
};
|
|
|
|
struct BorderRadiiData {
|
|
BorderRadiusData top_left;
|
|
BorderRadiusData top_right;
|
|
BorderRadiusData bottom_right;
|
|
BorderRadiusData bottom_left;
|
|
|
|
inline bool has_any_radius() const
|
|
{
|
|
return top_left || top_right || bottom_right || bottom_left;
|
|
}
|
|
|
|
inline void shrink(CSSPixels top, CSSPixels right, CSSPixels bottom, CSSPixels left)
|
|
{
|
|
top_left.shrink(left, top);
|
|
top_right.shrink(right, top);
|
|
bottom_right.shrink(right, bottom);
|
|
bottom_left.shrink(left, bottom);
|
|
}
|
|
|
|
inline void inflate(CSSPixels top, CSSPixels right, CSSPixels bottom, CSSPixels left)
|
|
{
|
|
shrink(-top, -right, -bottom, -left);
|
|
}
|
|
|
|
inline CornerRadii as_corners(PaintContext& context) const
|
|
{
|
|
return CornerRadii {
|
|
top_left.as_corner(context),
|
|
top_right.as_corner(context),
|
|
bottom_right.as_corner(context),
|
|
bottom_left.as_corner(context)
|
|
};
|
|
}
|
|
};
|
|
|
|
}
|