Skip to content

Commit

Permalink
WebGL rendering contexts have redundant framebuffer functions, TexIma…
Browse files Browse the repository at this point in the history
…geSource typedef

https://bugs.webkit.org/show_bug.cgi?id=260381
rdar://problem/114072108

Reviewed by Dan Glastonbury.

Remove the unused functions and duplicated TexImageSource typedef.

Move ensureNotNull to a translation unit local free function.

* Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::getReadFramebufferBinding): Deleted.
(WebCore::WebGL2RenderingContext::restoreCurrentFramebuffer): Deleted.
* Source/WebCore/html/canvas/WebGL2RenderingContext.h:
* Source/WebCore/html/canvas/WebGLRenderingContext.cpp:
(WebCore::root):
* Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::ensureNotNull):
(WebCore::root):
(WebCore::WebGLRenderingContextBase::getReadFramebufferBinding): Deleted.
(WebCore::WebGLRenderingContextBase::ensureNotNull const): Deleted.
(WebCore::WebGLRenderingContextBase::enableOrDisable): Deleted.
(WebCore::WebGLRenderingContextBase::restoreCurrentFramebuffer): Deleted.
(WebCore::WebGLRenderingContextBase::restoreCurrentTexture2D): Deleted.
* Source/WebCore/html/canvas/WebGLRenderingContextBase.h:

Canonical link: https://commits.webkit.org/267394@main
  • Loading branch information
kkinnunen-apple committed Aug 29, 2023
1 parent 8224c07 commit c7e4339
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 66 deletions.
11 changes: 0 additions & 11 deletions Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2800,17 +2800,6 @@ WebGLFramebuffer* WebGL2RenderingContext::getFramebufferBinding(GCGLenum target)
return WebGLRenderingContextBase::getFramebufferBinding(target);
}

WebGLFramebuffer* WebGL2RenderingContext::getReadFramebufferBinding()
{
return m_readFramebufferBinding.get();
}

void WebGL2RenderingContext::restoreCurrentFramebuffer()
{
bindFramebuffer(GraphicsContextGL::DRAW_FRAMEBUFFER, m_framebufferBinding.get());
bindFramebuffer(GraphicsContextGL::READ_FRAMEBUFFER, m_readFramebufferBinding.get());
}

bool WebGL2RenderingContext::validateNonDefaultFramebufferAttachment(const char* functionName, GCGLenum attachment)
{
switch (attachment) {
Expand Down
14 changes: 0 additions & 14 deletions Source/WebCore/html/canvas/WebGL2RenderingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ class WebGL2RenderingContext final : public WebGLRenderingContextBase {
void texStorage2D(GCGLenum target, GCGLsizei levels, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height);
void texStorage3D(GCGLenum target, GCGLsizei levels, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLsizei depth);

using TexImageSource = std::variant<RefPtr<ImageBitmap>, RefPtr<ImageData>, RefPtr<HTMLImageElement>, RefPtr<HTMLCanvasElement>
#if ENABLE(VIDEO)
, RefPtr<HTMLVideoElement>
#endif
#if ENABLE(OFFSCREEN_CANVAS)
, RefPtr<OffscreenCanvas>
#endif
#if ENABLE(WEB_CODECS)
, RefPtr<WebCodecsVideoFrame>
#endif
>;

// Must override the WebGL 1.0 signatures to add extra validation.
void texImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, RefPtr<ArrayBufferView>&&) override;
ExceptionOr<void> texImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLenum format, GCGLenum type, std::optional<TexImageSource>) override;
Expand Down Expand Up @@ -298,8 +286,6 @@ class WebGL2RenderingContext final : public WebGLRenderingContextBase {
std::optional<std::span<const T>> validateClearBuffer(const char* functionName, GCGLenum buffer, TypedList<TypedArrayType, T>& values, GCGLuint srcOffset);
bool validateFramebufferTarget(GCGLenum target) final;
WebGLFramebuffer* getFramebufferBinding(GCGLenum target) final;
WebGLFramebuffer* getReadFramebufferBinding() final;
void restoreCurrentFramebuffer() final;
bool validateNonDefaultFramebufferAttachment(const char* functionName, GCGLenum attachment);
enum ActiveQueryKey { SamplesPassed = 0, PrimitivesWritten = 1, TimeElapsed = 2, NumKeys = 3 };
std::optional<ActiveQueryKey> validateQueryTarget(const char* functionName, GCGLenum target);
Expand Down
38 changes: 7 additions & 31 deletions Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,13 @@ static constexpr GCGLenum errorCodeToGLenum(GCGLErrorCode error)
return GraphicsContextGL::INVALID_OPERATION;
}

static String ensureNotNull(const String& text)
{
if (text.isNull())
return emptyString();
return text;
}

std::unique_ptr<WebGLRenderingContextBase> WebGLRenderingContextBase::create(CanvasBase& canvas, WebGLContextAttributes& attributes, WebGLVersion type)
{
auto scriptExecutionContext = canvas.scriptExecutionContext();
Expand Down Expand Up @@ -5337,11 +5344,6 @@ WebGLFramebuffer* WebGLRenderingContextBase::getFramebufferBinding(GCGLenum targ
return nullptr;
}

WebGLFramebuffer* WebGLRenderingContextBase::getReadFramebufferBinding()
{
return m_framebufferBinding.get();
}

bool WebGLRenderingContextBase::validateFramebufferFuncParameters(const char* functionName, GCGLenum target, GCGLenum attachment)
{
if (!validateFramebufferTarget(target)) {
Expand Down Expand Up @@ -5686,13 +5688,6 @@ void WebGLRenderingContextBase::simulateEventForTesting(SimulatedEventForTesting
m_context->simulateEventForTesting(event);
}

String WebGLRenderingContextBase::ensureNotNull(const String& text) const
{
if (text.isNull())
return emptyString();
return text;
}

WebGLRenderingContextBase::LRUImageBufferCache::LRUImageBufferCache(int capacity)
: m_buffers(capacity)
{
Expand Down Expand Up @@ -5748,14 +5743,6 @@ void WebGLRenderingContextBase::synthesizeLostContextGLError(GCGLenum error, con
m_contextLostState->errors.add(errorCode);
}

void WebGLRenderingContextBase::enableOrDisable(GCGLenum capability, bool enable)
{
if (enable)
m_context->enable(capability);
else
m_context->disable(capability);
}

IntSize WebGLRenderingContextBase::clampedCanvasSize()
{
IntSize canvasSize { static_cast<int>(canvasBase().width()), static_cast<int>(canvasBase().height()) };
Expand Down Expand Up @@ -5796,17 +5783,6 @@ void WebGLRenderingContextBase::setFramebuffer(const AbstractLocker&, GCGLenum t
m_context->bindFramebuffer(target, objectOrZero(buffer));
}

void WebGLRenderingContextBase::restoreCurrentFramebuffer()
{
bindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_framebufferBinding.get());
}

void WebGLRenderingContextBase::restoreCurrentTexture2D()
{
auto texture = m_textureUnits[m_activeTextureUnit].texture2DBinding.get();
bindTexture(GraphicsContextGL::TEXTURE_2D, texture);
}

bool WebGLRenderingContextBase::supportsDrawBuffers()
{
if (!m_drawBuffersWebGLRequirementsChecked) {
Expand Down
10 changes: 0 additions & 10 deletions Source/WebCore/html/canvas/WebGLRenderingContextBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,6 @@ class WebGLRenderingContextBase : public GraphicsContextGL::Client, public GPUBa
// Get the framebuffer bound to the given target.
virtual WebGLFramebuffer* getFramebufferBinding(GCGLenum target);

virtual WebGLFramebuffer* getReadFramebufferBinding();

// Helper function to validate input parameters for framebuffer functions.
// Generate GL error if parameters are illegal.
bool validateFramebufferFuncParameters(const char* functionName, GCGLenum target, GCGLenum attachment);
Expand Down Expand Up @@ -994,11 +992,6 @@ class WebGLRenderingContextBase : public GraphicsContextGL::Client, public GPUBa
void synthesizeGLError(GCGLenum, const char* functionName, const char* description);
void synthesizeLostContextGLError(GCGLenum, const char* functionName, const char* description);

String ensureNotNull(const String&) const;

// Helper for enabling or disabling a capability.
void enableOrDisable(GCGLenum capability, bool enable);

// Clamp the width and height to GL_MAX_VIEWPORT_DIMS.
IntSize clampedCanvasSize();

Expand All @@ -1008,9 +1001,6 @@ class WebGLRenderingContextBase : public GraphicsContextGL::Client, public GPUBa
void setBackDrawBuffer(GCGLenum);
void setFramebuffer(const AbstractLocker&, GCGLenum, WebGLFramebuffer*);

virtual void restoreCurrentFramebuffer();
void restoreCurrentTexture2D();

// Check if EXT_draw_buffers extension is supported and if it satisfies the WebGL requirements.
bool supportsDrawBuffers();

Expand Down

0 comments on commit c7e4339

Please sign in to comment.