ladybird/Userland/Libraries/LibWeb/SVG/SVGMaskElement.cpp
Andreas Kling bfd354492e LibWeb: Put most LibWeb GC objects in type-specific heap blocks
With this change, we now have ~1200 CellAllocators across both LibJS and
LibWeb in a normal WebContent instance.

This gives us a minimum heap size of 4.7 MiB in the scenario where we
only have one cell allocated per type. Of course, in practice there will
be many more of each type, so the effective overhead is quite a bit
smaller than that in practice.

I left a few types unconverted to this mechanism because I got tired of
doing this. :^)
2023-11-19 22:00:48 +01:00

62 lines
1.9 KiB
C++

/*
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/SVGMaskElementPrototype.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Layout/SVGGraphicsBox.h>
#include <LibWeb/SVG/AttributeNames.h>
#include <LibWeb/SVG/SVGMaskElement.h>
namespace Web::SVG {
JS_DEFINE_ALLOCATOR(SVGMaskElement);
SVGMaskElement::SVGMaskElement(DOM::Document& document, DOM::QualifiedName tag_name)
: SVGGraphicsElement(document, move(tag_name))
{
}
SVGMaskElement::~SVGMaskElement() = default;
void SVGMaskElement::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGMaskElementPrototype>(realm, "SVGMaskElement"));
}
JS::GCPtr<Layout::Node> SVGMaskElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
{
return heap().allocate_without_realm<Layout::SVGGraphicsBox>(document(), *this, move(style));
}
void SVGMaskElement::attribute_changed(FlyString const& name, Optional<String> const& value)
{
SVGGraphicsElement::attribute_changed(name, value);
if (name == AttributeNames::maskUnits) {
m_mask_units = AttributeParser::parse_units(value.value_or(String {}));
} else if (name == AttributeNames::maskContentUnits) {
m_mask_content_units = AttributeParser::parse_units(value.value_or(String {}));
}
}
MaskContentUnits SVGMaskElement::mask_content_units() const
{
return m_mask_content_units.value_or(MaskContentUnits::UserSpaceOnUse);
}
MaskUnits SVGMaskElement::mask_units() const
{
return m_mask_units.value_or(MaskUnits::ObjectBoundingBox);
}
CSSPixelRect SVGMaskElement::resolve_masking_area(CSSPixelRect const& mask_target) const
{
// TODO: Resolve this based on the x, y, width, and height of the mask.
return mask_target.inflated(mask_target.size().scaled(CSSPixels(2) / 10));
}
}