LibWeb: Deduplicate the WebGL null_terminated_string helper

This commit is contained in:
Undefine 2025-11-03 16:38:47 +01:00 committed by Alexander Kalenik
parent 6c115171da
commit df1aeda955
Notes: github-actions[bot] 2025-11-05 01:20:56 +00:00
4 changed files with 12 additions and 18 deletions

View file

@ -16,6 +16,7 @@ using GLuint = unsigned int;
using GLint = int;
using GLsizei = int;
using GLintptr = long long;
using GLchar = char;
// FIXME: This should really be "struct __GLsync*", but the linker doesn't recognise it.
// Since this conflicts with the original definition of GLsync, the suffix "Internal" has been added.

View file

@ -37,15 +37,6 @@ extern "C" {
namespace Web::WebGL {
static Vector<GLchar> null_terminated_string(StringView string)
{
Vector<GLchar> result;
for (auto c : string.bytes())
result.append(c);
result.append('\0');
return result;
}
WebGL2RenderingContextImpl::WebGL2RenderingContextImpl(JS::Realm& realm, NonnullOwnPtr<OpenGLContext> context)
: m_realm(realm)
, m_context(move(context))

View file

@ -9,6 +9,7 @@
#include <LibJS/Runtime/DataView.h>
#include <LibJS/Runtime/TypedArray.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebGL/Types.h>
#include <LibWeb/WebIDL/Buffers.h>
#include <LibWeb/WebIDL/Types.h>
@ -127,6 +128,16 @@ public:
Optional<ConvertedTexture> read_and_pixel_convert_texture_image_source(TexImageSource const& source, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, Optional<int> destination_width = OptionalNone {}, Optional<int> destination_height = OptionalNone {});
protected:
static Vector<GLchar> null_terminated_string(StringView string)
{
Vector<GLchar> result;
result.ensure_capacity(string.length() + 1);
for (auto c : string.bytes())
result.append(c);
result.append('\0');
return result;
}
// UNPACK_FLIP_Y_WEBGL of type boolean
// If set, then during any subsequent calls to texImage2D or texSubImage2D, the source data is flipped along
// the vertical axis, so that conceptually the last row is the first one transferred. The initial value is false.

View file

@ -33,15 +33,6 @@ extern "C" {
namespace Web::WebGL {
static Vector<GLchar> null_terminated_string(StringView string)
{
Vector<GLchar> result;
for (auto c : string.bytes())
result.append(c);
result.append('\0');
return result;
}
WebGLRenderingContextImpl::WebGLRenderingContextImpl(JS::Realm& realm, NonnullOwnPtr<OpenGLContext> context)
: m_realm(realm)
, m_context(move(context))