Skip to content

Commit df1aeda

Browse files
cqundefinekalenikaliaksandr
authored andcommitted
LibWeb: Deduplicate the WebGL null_terminated_string helper
1 parent 6c11517 commit df1aeda

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

Libraries/LibWeb/WebGL/Types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using GLuint = unsigned int;
1616
using GLint = int;
1717
using GLsizei = int;
1818
using GLintptr = long long;
19+
using GLchar = char;
1920

2021
// FIXME: This should really be "struct __GLsync*", but the linker doesn't recognise it.
2122
// Since this conflicts with the original definition of GLsync, the suffix "Internal" has been added.

Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ extern "C" {
3737

3838
namespace Web::WebGL {
3939

40-
static Vector<GLchar> null_terminated_string(StringView string)
41-
{
42-
Vector<GLchar> result;
43-
for (auto c : string.bytes())
44-
result.append(c);
45-
result.append('\0');
46-
return result;
47-
}
48-
4940
WebGL2RenderingContextImpl::WebGL2RenderingContextImpl(JS::Realm& realm, NonnullOwnPtr<OpenGLContext> context)
5041
: m_realm(realm)
5142
, m_context(move(context))

Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <LibJS/Runtime/DataView.h>
1010
#include <LibJS/Runtime/TypedArray.h>
1111
#include <LibWeb/Forward.h>
12+
#include <LibWeb/WebGL/Types.h>
1213
#include <LibWeb/WebIDL/Buffers.h>
1314
#include <LibWeb/WebIDL/Types.h>
1415

@@ -127,6 +128,16 @@ class WebGLRenderingContextBase {
127128
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 {});
128129

129130
protected:
131+
static Vector<GLchar> null_terminated_string(StringView string)
132+
{
133+
Vector<GLchar> result;
134+
result.ensure_capacity(string.length() + 1);
135+
for (auto c : string.bytes())
136+
result.append(c);
137+
result.append('\0');
138+
return result;
139+
}
140+
130141
// UNPACK_FLIP_Y_WEBGL of type boolean
131142
// If set, then during any subsequent calls to texImage2D or texSubImage2D, the source data is flipped along
132143
// the vertical axis, so that conceptually the last row is the first one transferred. The initial value is false.

Libraries/LibWeb/WebGL/WebGLRenderingContextImpl.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ extern "C" {
3333

3434
namespace Web::WebGL {
3535

36-
static Vector<GLchar> null_terminated_string(StringView string)
37-
{
38-
Vector<GLchar> result;
39-
for (auto c : string.bytes())
40-
result.append(c);
41-
result.append('\0');
42-
return result;
43-
}
44-
4536
WebGLRenderingContextImpl::WebGLRenderingContextImpl(JS::Realm& realm, NonnullOwnPtr<OpenGLContext> context)
4637
: m_realm(realm)
4738
, m_context(move(context))

0 commit comments

Comments
 (0)