mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:57:35 +00:00
LibWeb: Make 2D and 3D canvas rendering contexts GC-allocated
This commit is contained in:
parent
b8d485e6f0
commit
4452b5ca09
11 changed files with 107 additions and 61 deletions
|
@ -7,14 +7,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefCountForwarder.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibGfx/AffineTransform.h>
|
||||
#include <LibGfx/Color.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <LibGfx/Path.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasDrawImage.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasDrawPath.h>
|
||||
|
@ -37,8 +36,7 @@ namespace Web::HTML {
|
|||
using CanvasImageSource = Variant<JS::Handle<HTMLImageElement>, JS::Handle<HTMLCanvasElement>>;
|
||||
|
||||
class CanvasRenderingContext2D
|
||||
: public RefCounted<CanvasRenderingContext2D>
|
||||
, public Bindings::Wrappable
|
||||
: public Bindings::PlatformObject
|
||||
, public CanvasPath
|
||||
, public CanvasState
|
||||
, public CanvasTransform<CanvasRenderingContext2D>
|
||||
|
@ -50,14 +48,11 @@ class CanvasRenderingContext2D
|
|||
, public CanvasImageData
|
||||
, public CanvasPathDrawingStyles<CanvasRenderingContext2D> {
|
||||
|
||||
AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D);
|
||||
AK_MAKE_NONMOVABLE(CanvasRenderingContext2D);
|
||||
WEB_PLATFORM_OBJECT(CanvasRenderingContext2D, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
using WrapperType = Bindings::CanvasRenderingContext2DWrapper;
|
||||
|
||||
static NonnullRefPtr<CanvasRenderingContext2D> create(HTMLCanvasElement& element) { return adopt_ref(*new CanvasRenderingContext2D(element)); }
|
||||
~CanvasRenderingContext2D();
|
||||
static JS::NonnullGCPtr<CanvasRenderingContext2D> create(HTML::Window&, HTMLCanvasElement&);
|
||||
virtual ~CanvasRenderingContext2D() override;
|
||||
|
||||
virtual void fill_rect(float x, float y, float width, float height) override;
|
||||
virtual void stroke_rect(float x, float y, float width, float height) override;
|
||||
|
@ -88,7 +83,9 @@ public:
|
|||
virtual void clip() override;
|
||||
|
||||
private:
|
||||
explicit CanvasRenderingContext2D(HTMLCanvasElement&);
|
||||
explicit CanvasRenderingContext2D(HTML::Window&, HTMLCanvasElement&);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
struct PreparedTextGlyph {
|
||||
unsigned int c;
|
||||
|
@ -112,7 +109,7 @@ private:
|
|||
void stroke_internal(Gfx::Path const&);
|
||||
void fill_internal(Gfx::Path&, String const& fill_rule);
|
||||
|
||||
JS::Handle<HTMLCanvasElement> m_element;
|
||||
JS::NonnullGCPtr<HTMLCanvasElement> m_element;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-origin-clean
|
||||
bool m_origin_clean { true };
|
||||
|
@ -127,3 +124,5 @@ DOM::ExceptionOr<CanvasImageSourceUsability> check_usability_of_image(CanvasImag
|
|||
bool image_is_not_origin_clean(CanvasImageSource const&);
|
||||
|
||||
}
|
||||
|
||||
WRAPPER_HACK(CanvasRenderingContext2D, Web::HTML)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue