Skip to content

Commit c70886a

Browse files
cqundefinekalenikaliaksandr
authored andcommitted
LibWeb: Split off WebGLRenderingContextImpl to Impl and Overloads
This is more like what the IDL files specify with two different mixins, but the inheritance structure here is slightly different for easier maintenance. This will also allow the WebGL2 Impl to inherit from the WebGL1 Impl as WebGL versions don't share the functions defined in the Overloads interfaces.
1 parent 7f0f1c3 commit c70886a

File tree

7 files changed

+379
-324
lines changed

7 files changed

+379
-324
lines changed

Libraries/LibWeb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ set(SOURCES
10521052
WebGL/WebGLRenderingContext.cpp
10531053
WebGL/WebGLRenderingContextBase.cpp
10541054
WebGL/WebGLRenderingContextImpl.cpp
1055+
WebGL/WebGLRenderingContextOverloads.cpp
10551056
WebGL/WebGLSampler.cpp
10561057
WebGL/WebGLShader.cpp
10571058
WebGL/WebGLShaderPrecisionFormat.cpp

Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ JS::ThrowCompletionOr<GC::Ptr<WebGLRenderingContext>> WebGLRenderingContext::cre
7575

7676
WebGLRenderingContext::WebGLRenderingContext(JS::Realm& realm, HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<OpenGLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
7777
: PlatformObject(realm)
78-
, WebGLRenderingContextImpl(realm, move(context))
78+
, WebGLRenderingContextOverloads(realm, move(context))
7979
, m_canvas_element(canvas_element)
8080
, m_context_creation_parameters(context_creation_parameters)
8181
, m_actual_context_parameters(actual_context_parameters)

Libraries/LibWeb/WebGL/WebGLRenderingContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
#include <LibWeb/Forward.h>
1313
#include <LibWeb/WebGL/Types.h>
1414
#include <LibWeb/WebGL/WebGLContextAttributes.h>
15-
#include <LibWeb/WebGL/WebGLRenderingContextImpl.h>
15+
#include <LibWeb/WebGL/WebGLRenderingContextOverloads.h>
1616

1717
namespace Web::WebGL {
1818

1919
class WebGLRenderingContext final : public Bindings::PlatformObject
20-
, public WebGLRenderingContextImpl {
20+
, public WebGLRenderingContextOverloads {
2121
WEB_PLATFORM_OBJECT(WebGLRenderingContext, Bindings::PlatformObject);
2222
GC_DECLARE_ALLOCATOR(WebGLRenderingContext);
2323

Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.cpp

Lines changed: 0 additions & 299 deletions
Original file line numberDiff line numberDiff line change
@@ -48,305 +48,6 @@ WebGLRenderingContextImpl::WebGLRenderingContextImpl(JS::Realm& realm, NonnullOw
4848
{
4949
}
5050

51-
void WebGLRenderingContextImpl::buffer_data(WebIDL::UnsignedLong target, WebIDL::LongLong size, WebIDL::UnsignedLong usage)
52-
{
53-
m_context->make_current();
54-
55-
glBufferData(target, size, 0, usage);
56-
}
57-
58-
void WebGLRenderingContextImpl::buffer_data(WebIDL::UnsignedLong target, GC::Root<WebIDL::BufferSource> data, WebIDL::UnsignedLong usage)
59-
{
60-
m_context->make_current();
61-
62-
auto span = MUST(get_offset_span<u8 const>(*data, /* src_offset= */ 0));
63-
glBufferData(target, span.size(), span.data(), usage);
64-
}
65-
66-
void WebGLRenderingContextImpl::buffer_sub_data(WebIDL::UnsignedLong target, WebIDL::LongLong offset, GC::Root<WebIDL::BufferSource> data)
67-
{
68-
m_context->make_current();
69-
70-
auto span = MUST(get_offset_span<u8 const>(*data, /* src_offset= */ 0));
71-
glBufferSubData(target, offset, span.size(), span.data());
72-
}
73-
74-
void WebGLRenderingContextImpl::compressed_tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::UnsignedLong internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, GC::Root<WebIDL::ArrayBufferView> data)
75-
{
76-
m_context->make_current();
77-
78-
auto span = MUST(get_offset_span<u8 const>(*data, /* src_offset= */ 0));
79-
glCompressedTexImage2DRobustANGLE(target, level, internalformat, width, height, border, span.size(), span.size(), span.data());
80-
}
81-
82-
void WebGLRenderingContextImpl::compressed_tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, GC::Root<WebIDL::ArrayBufferView> data)
83-
{
84-
m_context->make_current();
85-
86-
auto span = MUST(get_offset_span<u8 const>(*data, /* src_offset= */ 0));
87-
glCompressedTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, format, span.size(), span.size(), span.data());
88-
}
89-
90-
void WebGLRenderingContextImpl::read_pixels(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels)
91-
{
92-
m_context->make_current();
93-
94-
if (!pixels) {
95-
return;
96-
}
97-
98-
auto span = MUST(get_offset_span<u8>(*pixels, /* src_offset= */ 0));
99-
glReadPixelsRobustANGLE(x, y, width, height, format, type, span.size(), nullptr, nullptr, nullptr, span.data());
100-
}
101-
102-
void WebGLRenderingContextImpl::tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels)
103-
{
104-
m_context->make_current();
105-
106-
if (pixels) {
107-
auto span = MUST(get_offset_span<u8>(*pixels, /* src_offset= */ 0));
108-
glTexImage2DRobustANGLE(target, level, internalformat, width, height, border, format, type, span.size(), span.data());
109-
return;
110-
}
111-
112-
Checked<size_t> bytes = 0;
113-
if (type == GL_UNSIGNED_SHORT_5_6_5 && format != GL_RGB) {
114-
set_error(GL_INVALID_OPERATION);
115-
return;
116-
}
117-
118-
if ((type == GL_UNSIGNED_SHORT_4_4_4_4 || type == GL_UNSIGNED_SHORT_5_5_5_1) && format != GL_RGBA) {
119-
set_error(GL_INVALID_OPERATION);
120-
return;
121-
}
122-
123-
switch (format) {
124-
case GL_ALPHA:
125-
case GL_LUMINANCE:
126-
case GL_LUMINANCE_ALPHA: {
127-
if (type != GL_UNSIGNED_BYTE) {
128-
set_error(GL_INVALID_ENUM);
129-
return;
130-
}
131-
132-
bytes = format == GL_LUMINANCE_ALPHA ? 2 : 1;
133-
break;
134-
}
135-
case GL_RGB:
136-
case GL_RGBA: {
137-
switch (type) {
138-
case GL_UNSIGNED_BYTE:
139-
bytes = format == GL_RGB ? 3 : 4;
140-
break;
141-
case GL_UNSIGNED_SHORT_4_4_4_4:
142-
case GL_UNSIGNED_SHORT_5_5_5_1:
143-
case GL_UNSIGNED_SHORT_5_6_5:
144-
bytes = 2;
145-
break;
146-
default:
147-
set_error(GL_INVALID_ENUM);
148-
return;
149-
}
150-
151-
break;
152-
}
153-
default:
154-
set_error(GL_INVALID_ENUM);
155-
return;
156-
}
157-
158-
bytes *= width;
159-
bytes *= height;
160-
161-
if (bytes.has_overflow()) {
162-
set_error(GL_INVALID_OPERATION);
163-
return;
164-
}
165-
166-
auto byte_buffer = MUST(ByteBuffer::create_zeroed(bytes.value_unchecked()));
167-
glTexImage2DRobustANGLE(target, level, internalformat, width, height, border, format, type, byte_buffer.size(), byte_buffer.data());
168-
}
169-
170-
void WebGLRenderingContextImpl::tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source)
171-
{
172-
m_context->make_current();
173-
174-
auto maybe_converted_texture = read_and_pixel_convert_texture_image_source(source, format, type);
175-
if (!maybe_converted_texture.has_value())
176-
return;
177-
auto converted_texture = maybe_converted_texture.release_value();
178-
glTexImage2DRobustANGLE(target, level, internalformat, converted_texture.width, converted_texture.height, 0, format, type, converted_texture.buffer.size(), converted_texture.buffer.data());
179-
}
180-
181-
void WebGLRenderingContextImpl::tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels)
182-
{
183-
m_context->make_current();
184-
185-
auto span = MUST(get_offset_span<u8>(*pixels, /* src_offset= */ 0));
186-
glTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, format, type, span.size(), span.data());
187-
}
188-
189-
void WebGLRenderingContextImpl::tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source)
190-
{
191-
m_context->make_current();
192-
193-
auto maybe_converted_texture = read_and_pixel_convert_texture_image_source(source, format, type);
194-
195-
if (!maybe_converted_texture.has_value())
196-
return;
197-
auto converted_texture = maybe_converted_texture.release_value();
198-
glTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, converted_texture.width, converted_texture.height, format, type, converted_texture.buffer.size(), converted_texture.buffer.data());
199-
}
200-
201-
void WebGLRenderingContextImpl::uniform1fv(GC::Root<WebGLUniformLocation> location, Float32List v)
202-
{
203-
m_context->make_current();
204-
205-
if (!location)
206-
return;
207-
auto span = MUST(span_from_float32_list(v, /* src_offset= */ 0));
208-
glUniform1fv(location->handle(), span.size(), span.data());
209-
}
210-
211-
void WebGLRenderingContextImpl::uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List v)
212-
{
213-
m_context->make_current();
214-
215-
if (!location)
216-
return;
217-
auto span = MUST(span_from_float32_list(v, /* src_offset= */ 0));
218-
if (span.size() % 2 != 0) [[unlikely]] {
219-
set_error(GL_INVALID_VALUE);
220-
return;
221-
}
222-
glUniform2fv(location->handle(), span.size() / 2, span.data());
223-
}
224-
225-
void WebGLRenderingContextImpl::uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List v)
226-
{
227-
m_context->make_current();
228-
229-
if (!location)
230-
return;
231-
auto span = MUST(span_from_float32_list(v, /* src_offset= */ 0));
232-
if (span.size() % 3 != 0) [[unlikely]] {
233-
set_error(GL_INVALID_VALUE);
234-
return;
235-
}
236-
glUniform3fv(location->handle(), span.size() / 3, span.data());
237-
}
238-
239-
void WebGLRenderingContextImpl::uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List v)
240-
{
241-
m_context->make_current();
242-
243-
if (!location)
244-
return;
245-
auto span = MUST(span_from_float32_list(v, /* src_offset= */ 0));
246-
if (span.size() % 4 != 0) [[unlikely]] {
247-
set_error(GL_INVALID_VALUE);
248-
return;
249-
}
250-
glUniform4fv(location->handle(), span.size() / 4, span.data());
251-
}
252-
253-
void WebGLRenderingContextImpl::uniform1iv(GC::Root<WebGLUniformLocation> location, Int32List v)
254-
{
255-
m_context->make_current();
256-
257-
if (!location)
258-
return;
259-
auto span = MUST(span_from_int32_list(v, /* src_offset= */ 0));
260-
glUniform1iv(location->handle(), span.size(), span.data());
261-
}
262-
263-
void WebGLRenderingContextImpl::uniform2iv(GC::Root<WebGLUniformLocation> location, Int32List v)
264-
{
265-
m_context->make_current();
266-
267-
if (!location)
268-
return;
269-
auto span = MUST(span_from_int32_list(v, /* src_offset= */ 0));
270-
if (span.size() % 2 != 0) [[unlikely]] {
271-
set_error(GL_INVALID_VALUE);
272-
return;
273-
}
274-
glUniform2iv(location->handle(), span.size() / 2, span.data());
275-
}
276-
277-
void WebGLRenderingContextImpl::uniform3iv(GC::Root<WebGLUniformLocation> location, Int32List v)
278-
{
279-
m_context->make_current();
280-
281-
if (!location)
282-
return;
283-
auto span = MUST(span_from_int32_list(v, /* src_offset= */ 0));
284-
if (span.size() % 3 != 0) [[unlikely]] {
285-
set_error(GL_INVALID_VALUE);
286-
return;
287-
}
288-
glUniform3iv(location->handle(), span.size() / 3, span.data());
289-
}
290-
291-
void WebGLRenderingContextImpl::uniform4iv(GC::Root<WebGLUniformLocation> location, Int32List v)
292-
{
293-
m_context->make_current();
294-
295-
if (!location)
296-
return;
297-
auto span = MUST(span_from_int32_list(v, /* src_offset= */ 0));
298-
if (span.size() % 4 != 0) [[unlikely]] {
299-
set_error(GL_INVALID_VALUE);
300-
return;
301-
}
302-
glUniform4iv(location->handle(), span.size() / 4, span.data());
303-
}
304-
305-
void WebGLRenderingContextImpl::uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
306-
{
307-
m_context->make_current();
308-
309-
if (!location)
310-
return;
311-
constexpr auto matrix_size = 2 * 2;
312-
auto span = MUST(span_from_float32_list(value, /* src_offset= */ 0));
313-
if (span.size() % matrix_size != 0) [[unlikely]] {
314-
set_error(GL_INVALID_VALUE);
315-
return;
316-
}
317-
glUniformMatrix2fv(location->handle(), span.size() / matrix_size, transpose, span.data());
318-
}
319-
320-
void WebGLRenderingContextImpl::uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
321-
{
322-
m_context->make_current();
323-
324-
if (!location)
325-
return;
326-
constexpr auto matrix_size = 3 * 3;
327-
auto span = MUST(span_from_float32_list(value, /* src_offset= */ 0));
328-
if (span.size() % matrix_size != 0) [[unlikely]] {
329-
set_error(GL_INVALID_VALUE);
330-
return;
331-
}
332-
glUniformMatrix3fv(location->handle(), span.size() / matrix_size, transpose, span.data());
333-
}
334-
335-
void WebGLRenderingContextImpl::uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value)
336-
{
337-
m_context->make_current();
338-
339-
if (!location)
340-
return;
341-
constexpr auto matrix_size = 4 * 4;
342-
auto span = MUST(span_from_float32_list(value, /* src_offset= */ 0));
343-
if (span.size() % matrix_size != 0) [[unlikely]] {
344-
set_error(GL_INVALID_VALUE);
345-
return;
346-
}
347-
glUniformMatrix4fv(location->handle(), span.size() / matrix_size, transpose, span.data());
348-
}
349-
35051
void WebGLRenderingContextImpl::active_texture(WebIDL::UnsignedLong texture)
35152
{
35253
m_context->make_current();

Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ class WebGLRenderingContextImpl : public WebGLRenderingContextBase {
2929
virtual void present() = 0;
3030
virtual void needs_to_present() = 0;
3131
virtual void set_error(GLenum) = 0;
32-
void buffer_data(WebIDL::UnsignedLong target, WebIDL::LongLong size, WebIDL::UnsignedLong usage);
33-
void buffer_data(WebIDL::UnsignedLong target, GC::Root<WebIDL::BufferSource> data, WebIDL::UnsignedLong usage);
34-
void buffer_sub_data(WebIDL::UnsignedLong target, WebIDL::LongLong offset, GC::Root<WebIDL::BufferSource> data);
35-
void compressed_tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::UnsignedLong internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, GC::Root<WebIDL::ArrayBufferView> data);
36-
void compressed_tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, GC::Root<WebIDL::ArrayBufferView> data);
37-
void read_pixels(WebIDL::Long x, WebIDL::Long y, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels);
38-
void tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::Long width, WebIDL::Long height, WebIDL::Long border, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels);
39-
void tex_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long internalformat, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source);
40-
void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::Long width, WebIDL::Long height, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, GC::Root<WebIDL::ArrayBufferView> pixels);
41-
void tex_sub_image2d(WebIDL::UnsignedLong target, WebIDL::Long level, WebIDL::Long xoffset, WebIDL::Long yoffset, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, TexImageSource source);
42-
void uniform1fv(GC::Root<WebGLUniformLocation> location, Float32List v);
43-
void uniform2fv(GC::Root<WebGLUniformLocation> location, Float32List v);
44-
void uniform3fv(GC::Root<WebGLUniformLocation> location, Float32List v);
45-
void uniform4fv(GC::Root<WebGLUniformLocation> location, Float32List v);
46-
void uniform1iv(GC::Root<WebGLUniformLocation> location, Int32List v);
47-
void uniform2iv(GC::Root<WebGLUniformLocation> location, Int32List v);
48-
void uniform3iv(GC::Root<WebGLUniformLocation> location, Int32List v);
49-
void uniform4iv(GC::Root<WebGLUniformLocation> location, Int32List v);
50-
void uniform_matrix2fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value);
51-
void uniform_matrix3fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value);
52-
void uniform_matrix4fv(GC::Root<WebGLUniformLocation> location, bool transpose, Float32List value);
5332
void active_texture(WebIDL::UnsignedLong texture);
5433
void attach_shader(GC::Root<WebGLProgram> program, GC::Root<WebGLShader> shader);
5534
void bind_attrib_location(GC::Root<WebGLProgram> program, WebIDL::UnsignedLong index, String name);
@@ -165,7 +144,6 @@ class WebGLRenderingContextImpl : public WebGLRenderingContextBase {
165144
protected:
166145
virtual void visit_edges(JS::Cell::Visitor&) override;
167146

168-
private:
169147
GC::Ref<JS::Realm> m_realm;
170148
GC::Ptr<WebGLBuffer> m_array_buffer_binding;
171149
GC::Ptr<WebGLBuffer> m_element_array_buffer_binding;

0 commit comments

Comments
 (0)