diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextOverloads.idl b/Libraries/LibWeb/WebGL/WebGLRenderingContextOverloads.idl index 2e442530c37..e2a3dbef089 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContextOverloads.idl +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextOverloads.idl @@ -1,5 +1,14 @@ #import +typedef (ImageBitmap or + ImageData or + HTMLImageElement or + HTMLCanvasElement or + HTMLVideoElement + // FIXME: OffscreenCanvas or + // FIXME: VideoFrame + ) TexImageSource; + // FIXME: BufferSource should be a Float32Array typedef (BufferSource or sequence) Float32List; @@ -16,7 +25,7 @@ interface mixin WebGLRenderingContextOverloads { [FIXME] undefined readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, [AllowShared] ArrayBufferView? pixels); undefined texImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, [AllowShared] ArrayBufferView? pixels); - [FIXME] undefined texImage2D(GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type, TexImageSource source); // May throw DOMException + undefined texImage2D(GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type, TexImageSource source); // May throw DOMException [FIXME] undefined texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, [AllowShared] ArrayBufferView? pixels); [FIXME] undefined texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLenum format, GLenum type, TexImageSource source); // May throw DOMException diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp index 1f98d8dcb53..05762f32e68 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp @@ -280,6 +280,11 @@ ErrorOr serenity_main(Main::Arguments arguments) implementation_file_generator.append(R"~~~( #include #include +#include +#include +#include +#include +#include #include #include #include @@ -322,8 +327,6 @@ WebGLRenderingContextImpl::WebGLRenderingContextImpl(JS::Realm& realm, NonnullOw #include #include #include -#include -#include #include namespace Web::WebGL { @@ -473,6 +476,49 @@ public: continue; } + if (function.name == "texImage2D"sv && function.overload_index == 1) { + // FIXME: If this function is called with an ImageData whose data attribute has been neutered, + // an INVALID_VALUE error is generated. + // FIXME: If this function is called with an ImageBitmap that has been neutered, an INVALID_VALUE + // error is generated. + // FIXME: If this function is called with an HTMLImageElement or HTMLVideoElement whose origin + // differs from the origin of the containing Document, or with an HTMLCanvasElement, + // ImageBitmap or OffscreenCanvas whose bitmap's origin-clean flag is set to false, + // a SECURITY_ERR exception must be thrown. See Origin Restrictions. + // FIXME: If source is null then an INVALID_VALUE error is generated. + function_impl_generator.append(R"~~~( + auto bitmap = source.visit( + [](GC::Root const& source) -> RefPtr { + return source->immutable_bitmap(); + }, + [](GC::Root const& source) -> RefPtr { + auto surface = source->surface(); + if (!surface) + return {}; + auto bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA8888, Gfx::AlphaType::Premultiplied, surface->size())); + surface->read_into_bitmap(*bitmap); + return Gfx::ImmutableBitmap::create(*bitmap); + }, + [](GC::Root const& source) -> RefPtr { + return Gfx::ImmutableBitmap::create(*source->bitmap()); + }, + [](GC::Root const& source) -> RefPtr { + return Gfx::ImmutableBitmap::create(*source->bitmap()); + }, + [](GC::Root const& source) -> RefPtr { + return Gfx::ImmutableBitmap::create(source->bitmap()); + }); + if (!bitmap) + return; + + void const* pixels_ptr = bitmap->bitmap()->begin(); + int width = bitmap->width(); + int height = bitmap->height(); + glTexImage2D(target, level, internalformat, width, height, 0, format, type, pixels_ptr); +)~~~"); + continue; + } + if (function.name == "getShaderParameter"sv) { function_impl_generator.append(R"~~~( GLint result = 0;