1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 06:55:07 +00:00
serenity/Userland/Libraries/LibWeb/SVG/SVGGraphicsElement.h
Aliaksandr Kalenik 063e66cae9 LibWeb: Introduce RecordingPainter to serialize painting commands
This modification introduces a new layer to the painting process. The
stacking context traversal no longer immediately calls the
Gfx::Painter methods. Instead, it writes serialized painting commands
into newly introduced RecordingPainter. Created list of commands is
executed later to produce resulting bitmap.

Producing painting command list will make it easier to add new
optimizations:
- It's simpler to check if the painting result is not visible in the
  viewport at the command level rather than during stacking context
  traversal.
- Run painting in a separate thread. The painting thread can process
  serialized painting commands, while the main thread can work on the
  next paintable tree and safely invalidate the previous one.
- As we consider GPU-accelerated painting support, it would be easier
  to back each painting command rather than constructing an alternative
  for the entire Gfx::Painter API.
2023-10-18 10:58:42 +02:00

92 lines
2.6 KiB
C++

/*
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGfx/PaintStyle.h>
#include <LibGfx/Path.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/SVG/AttributeParser.h>
#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/SVG/SVGGradientElement.h>
#include <LibWeb/SVG/TagNames.h>
#include <LibWeb/SVG/ViewBox.h>
namespace Web::SVG {
class SVGGraphicsElement : public SVGElement {
WEB_PLATFORM_OBJECT(SVGGraphicsElement, SVGElement);
public:
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
virtual void attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value) override;
Optional<Gfx::Color> fill_color() const;
Optional<FillRule> fill_rule() const;
Optional<Gfx::Color> stroke_color() const;
Optional<float> stroke_width() const;
Optional<float> fill_opacity() const;
Optional<float> stroke_opacity() const;
float visible_stroke_width() const
{
if (auto color = stroke_color(); color.has_value() && color->alpha() > 0)
return stroke_width().value_or(0);
return 0;
}
Gfx::AffineTransform get_transform() const;
Optional<Gfx::PaintStyle const&> fill_paint_style(SVGPaintContext const&) const;
Optional<Gfx::PaintStyle const&> stroke_paint_style(SVGPaintContext const&) const;
JS::GCPtr<SVG::SVGMaskElement const> mask() const;
Optional<ViewBox> view_box() const;
protected:
SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);
virtual void initialize(JS::Realm&) override;
virtual Gfx::AffineTransform element_transform() const
{
return m_transform;
}
Optional<Gfx::PaintStyle const&> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;
Gfx::AffineTransform m_transform = {};
template<typename T>
JS::GCPtr<T> try_resolve_url_to(AK::URL const& url) const
{
if (!url.fragment().has_value())
return {};
auto node = document().get_element_by_id(*url.fragment());
if (!node)
return {};
if (is<T>(*node))
return static_cast<T&>(*node);
return {};
}
private:
virtual bool is_svg_graphics_element() const final { return true; }
};
Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list);
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<SVG::SVGGraphicsElement>() const { return is_svg_graphics_element(); }
}