blob: 8da131068d13b9ae14dcfc153eeb8f58c78b46cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/ByteBuffer.h>
#include <LibGfx/Forward.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/WebGL/WebGLRenderingContext.h>
namespace Web::HTML {
class HTMLCanvasElement final : public HTMLElement {
public:
using WrapperType = Bindings::HTMLCanvasElementWrapper;
using RenderingContext = Variant<NonnullRefPtr<CanvasRenderingContext2D>, NonnullRefPtr<WebGL::WebGLRenderingContext>, Empty>;
HTMLCanvasElement(DOM::Document&, DOM::QualifiedName);
virtual ~HTMLCanvasElement() override;
Gfx::Bitmap const* bitmap() const { return m_bitmap; }
Gfx::Bitmap* bitmap() { return m_bitmap; }
bool create_bitmap(size_t minimum_width = 0, size_t minimum_height = 0);
JS::ThrowCompletionOr<RenderingContext> get_context(String const& type, JS::Value options);
unsigned width() const;
unsigned height() const;
void set_width(unsigned);
void set_height(unsigned);
String to_data_url(String const& type, Optional<double> quality) const;
void present();
private:
virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
enum class HasOrCreatedContext {
No,
Yes,
};
HasOrCreatedContext create_2d_context();
JS::ThrowCompletionOr<HasOrCreatedContext> create_webgl_context(JS::Value options);
void reset_context_to_default_state();
RefPtr<Gfx::Bitmap> m_bitmap;
RenderingContext m_context;
};
}
|