Skip to content

Commit

Permalink
WebGL default framebuffer state management should be part of WebGLRen…
Browse files Browse the repository at this point in the history
…deringContext

https://bugs.webkit.org/show_bug.cgi?id=263963
rdar://117788476

Reviewed by Dan Glastonbury.

Move the default framebuffer dirty buffer accounting from GraphicsContextGL
to WebGLDefaultFramebuffer class. This is the beginning of moving all
the default framebuffer state and objects to the WebGL layer. Currently
the implementation is in lower level at GraphicsContextGL level.

This is work towards implementing premultipliedAlpha=false compositing.

* Source/WebCore/CMakeLists.txt:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h:
* Source/WebCore/html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::initializeDefaultObjects):
(WebCore::WebGL2RenderingContext::updateBuffersToAutoClear):
(WebCore::WebGL2RenderingContext::initializeVertexArrayObjects): Deleted.
* Source/WebCore/html/canvas/WebGL2RenderingContext.h:
* Source/WebCore/html/canvas/WebGLDefaultFramebuffer.cpp: Added.
(WebCore::WebGLDefaultFramebuffer::create):
(WebCore::WebGLDefaultFramebuffer::WebGLDefaultFramebuffer):
(WebCore::WebGLDefaultFramebuffer::reshape):
(WebCore::WebGLDefaultFramebuffer::markBuffersClear):
(WebCore::WebGLDefaultFramebuffer::markAllUnpreservedBuffersDirty):
* Source/WebCore/html/canvas/WebGLDefaultFramebuffer.h: Copied from Source/WebCore/html/canvas/WebGLRenderingContext.h.
(WebCore::WebGLDefaultFramebuffer::object const):
(WebCore::WebGLDefaultFramebuffer::hasStencil const):
(WebCore::WebGLDefaultFramebuffer::hasDepth const):
(WebCore::WebGLDefaultFramebuffer::dirtyBuffers const):
* Source/WebCore/html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::initializeDefaultObjects):
(WebCore::WebGLRenderingContext::initializeVertexArrayObjects): Deleted.
* Source/WebCore/html/canvas/WebGLRenderingContext.h:
* Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::ScopedDisableRasterizerDiscard::ScopedDisableRasterizerDiscard):
(WebCore::ScopedDisableRasterizerDiscard::~ScopedDisableRasterizerDiscard):
(WebCore::ScopedEnableBackbuffer::ScopedEnableBackbuffer):
(WebCore::ScopedEnableBackbuffer::~ScopedEnableBackbuffer):
(WebCore::WebGLRenderingContextBase::initializeNewContext):
(WebCore::WebGLRenderingContextBase::initializeContextState):
(WebCore::WebGLRenderingContextBase::initializeDefaultObjects):
(WebCore::WebGLRenderingContextBase::markContextChangedAndNotifyCanvasObserver):
(WebCore::WebGLRenderingContextBase::clearIfComposited):
(WebCore::WebGLRenderingContextBase::reshape):
(WebCore::WebGLRenderingContextBase::setFramebuffer):
(WebCore::WebGLRenderingContextBase::prepareForDisplay):
(WebCore::WebGLRenderingContextBase::restoreStateAfterClear): Deleted.
* Source/WebCore/html/canvas/WebGLRenderingContextBase.h:
* Source/WebCore/platform/graphics/GraphicsContextGL.cpp:
(WebCore::GraphicsContextGL::markContextChanged): Deleted.
(WebCore::GraphicsContextGL::setBuffersToAutoClear): Deleted.
(WebCore::GraphicsContextGL::getBuffersToAutoClear const): Deleted.
(WebCore::GraphicsContextGL::markLayerComposited): Deleted.
* Source/WebCore/platform/graphics/GraphicsContextGL.h:
* Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp:
(WebCore::GraphicsContextGLANGLE::reshape):
* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::GraphicsContextGLCocoa::prepareForDisplayWithFinishedSignal):
* Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp:
(WebCore::GraphicsContextGLGBM::prepareForDisplay):
* Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp:
(WebCore::GraphicsContextGLTextureMapperANGLE::prepareForDisplay):
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
(WebKit::RemoteGraphicsContextGL::markContextChanged): Deleted.
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h:
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in:
* Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
(WebKit::RemoteGraphicsContextGLProxy::markContextChanged): Deleted.
* Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
* Source/WebKit/WebProcess/GPU/graphics/cocoa/RemoteGraphicsContextGLProxyCocoa.mm:
* Source/WebKit/WebProcess/GPU/graphics/gbm/RemoteGraphicsContextGLProxyGBM.cpp:
(WebKit::RemoteGraphicsContextGLProxyGBM::prepareForDisplay):
* Source/WebKit/WebProcess/GPU/graphics/wc/RemoteGraphicsContextGLProxyWC.cpp:
* Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm:
(TestWebKitAPI::changeContextContents):
(TestWebKitAPI::TEST_P):

Canonical link: https://commits.webkit.org/270263@main
  • Loading branch information
kkinnunen-apple committed Nov 6, 2023
1 parent 681701c commit f4b3b4b
Show file tree
Hide file tree
Showing 26 changed files with 245 additions and 163 deletions.
1 change: 1 addition & 0 deletions Source/WebCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,7 @@ if (ENABLE_WEBGL)
html/canvas/WebGLContextEvent.cpp
html/canvas/WebGLDebugRendererInfo.cpp
html/canvas/WebGLDebugShaders.cpp
html/canvas/WebGLDefaultFramebuffer.cpp
html/canvas/WebGLDepthTexture.cpp
html/canvas/WebGLDrawBuffers.cpp
html/canvas/WebGLDrawInstancedBaseVertexBaseInstance.cpp
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@ html/canvas/WebGLCompressedTextureS3TCsRGB.cpp
html/canvas/WebGLContextEvent.cpp
html/canvas/WebGLDebugRendererInfo.cpp
html/canvas/WebGLDebugShaders.cpp
html/canvas/WebGLDefaultFramebuffer.cpp
html/canvas/WebGLDepthTexture.cpp
html/canvas/WebGLDrawBuffers.cpp
html/canvas/WebGLDrawInstancedBaseVertexBaseInstance.cpp
Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13226,6 +13226,8 @@
7B8ED5EF26F0C123008AC023 /* CVUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CVUtilities.mm; sourceTree = "<group>"; };
7B95CFE92754FF6E000060CE /* GraphicsContextGLState.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = GraphicsContextGLState.h; sourceTree = "<group>"; };
7B95CFEC2754FF7C000060CE /* GraphicsContextGLANGLE.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = GraphicsContextGLANGLE.h; sourceTree = "<group>"; };
7B97D1542AEA4C6B00471B82 /* WebGLDefaultFramebuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGLDefaultFramebuffer.h; sourceTree = "<group>"; };
7B97D1552AEA4C6B00471B82 /* WebGLDefaultFramebuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGLDefaultFramebuffer.cpp; sourceTree = "<group>"; };
7BB34A1625345CB200029D08 /* ANGLEUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANGLEUtilities.h; sourceTree = "<group>"; };
7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLImageExtractor.h; sourceTree = "<group>"; };
7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextGLImageExtractor.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -24626,6 +24628,8 @@
A0EE0DF3144F825500F80B0D /* WebGLDebugShaders.cpp */,
A0EE0DF4144F825500F80B0D /* WebGLDebugShaders.h */,
A0EE0DEF144F823200F80B0D /* WebGLDebugShaders.idl */,
7B97D1552AEA4C6B00471B82 /* WebGLDefaultFramebuffer.cpp */,
7B97D1542AEA4C6B00471B82 /* WebGLDefaultFramebuffer.h */,
6E3FAE8C14733FDB00E42307 /* WebGLDepthTexture.cpp */,
6E3FAE8D14733FDB00E42307 /* WebGLDepthTexture.h */,
6E3FAE9014733FEA00E42307 /* WebGLDepthTexture.idl */,
Expand Down
6 changes: 4 additions & 2 deletions Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "WebCoreOpaqueRootInlines.h"
#include "WebGLActiveInfo.h"
#include "WebGLBuffer.h"
#include "WebGLDefaultFramebuffer.h"
#include "WebGLExtensionAnyInlines.h"
#include "WebGLFramebuffer.h"
#include "WebGLProgram.h"
Expand Down Expand Up @@ -128,8 +129,9 @@ long long WebGL2RenderingContext::getInt64Parameter(GCGLenum pname)
return m_context->getInteger64(pname);
}

void WebGL2RenderingContext::initializeVertexArrayObjects()
void WebGL2RenderingContext::initializeDefaultObjects()
{
WebGLRenderingContextBase::initializeDefaultObjects();
m_defaultVertexArrayObject = WebGLVertexArrayObject::create(*this, WebGLVertexArrayObject::Type::Default);
m_boundVertexArrayObject = m_defaultVertexArrayObject;
if (!m_defaultVertexArrayObject)
Expand Down Expand Up @@ -3533,7 +3535,7 @@ void WebGL2RenderingContext::updateBuffersToAutoClear(ClearBufferCaller caller,
return;
}

m_context->setBuffersToAutoClear(m_context->getBuffersToAutoClear() & (~buffersToClear));
m_defaultFramebuffer->markBuffersClear(buffersToClear);
}

} // namespace WebCore
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/canvas/WebGL2RenderingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class WebGL2RenderingContext final : public WebGLRenderingContextBase {
long long getInt64Parameter(GCGLenum) final;
Vector<bool> getIndexedBooleanArrayParameter(GCGLenum pname, GCGLuint index);

void initializeVertexArrayObjects() final;
void initializeDefaultObjects() final;
bool validateBufferTarget(const char* functionName, GCGLenum target) final;
bool validateBufferTargetCompatibility(const char*, GCGLenum, WebGLBuffer*);
WebGLBuffer* validateBufferDataParameters(const char* functionName, GCGLenum target, GCGLenum usage) final;
Expand Down
73 changes: 73 additions & 0 deletions Source/WebCore/html/canvas/WebGLDefaultFramebuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once
#include "config.h"

#if ENABLE(WEBGL)
#include "WebGLDefaultFramebuffer.h"

namespace WebCore {

std::unique_ptr<WebGLDefaultFramebuffer> WebGLDefaultFramebuffer::create(WebGLRenderingContextBase& context, IntSize size)
{
auto instance = std::unique_ptr<WebGLDefaultFramebuffer> { new WebGLDefaultFramebuffer(context) };
instance->reshape(size);
return instance;
}

WebGLDefaultFramebuffer::WebGLDefaultFramebuffer(WebGLRenderingContextBase& context)
: m_context(context)
{
auto attributes = m_context.graphicsContextGL()->contextAttributes();
m_hasStencil = attributes.stencil;
m_hasDepth = attributes.depth;
if (!attributes.preserveDrawingBuffer) {
m_unpreservedBuffers = GraphicsContextGL::COLOR_BUFFER_BIT;
if (m_hasStencil)
m_unpreservedBuffers |= GraphicsContextGL::STENCIL_BUFFER_BIT;
if (m_hasDepth)
m_unpreservedBuffers |= GraphicsContextGL::DEPTH_BUFFER_BIT;
}
}

void WebGLDefaultFramebuffer::reshape(IntSize size)
{
m_context.graphicsContextGL()->reshape(size.width(), size.height());
}

void WebGLDefaultFramebuffer::markBuffersClear(GCGLbitfield clearBuffers)
{
m_dirtyBuffers &= ~clearBuffers;
}

void WebGLDefaultFramebuffer::markAllUnpreservedBuffersDirty()
{
m_dirtyBuffers = m_unpreservedBuffers;
}

}

#endif
62 changes: 62 additions & 0 deletions Source/WebCore/html/canvas/WebGLDefaultFramebuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if ENABLE(WEBGL)

#include "WebGLRenderingContextBase.h"

namespace WebCore {

// Implementation for the WebGL context default framebuffer.
class WebGLDefaultFramebuffer {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(WebGLDefaultFramebuffer);
public:
static std::unique_ptr<WebGLDefaultFramebuffer> create(WebGLRenderingContextBase&, IntSize);
~WebGLDefaultFramebuffer() = default;

PlatformGLObject object() const { return 0; }
bool hasStencil() const { return m_hasStencil; }
bool hasDepth() const { return m_hasDepth; }
void reshape(IntSize);
GCGLbitfield dirtyBuffers() const { return m_dirtyBuffers; }
void markBuffersClear(GCGLbitfield clearBuffers);
void markAllUnpreservedBuffersDirty();

private:
WebGLDefaultFramebuffer(WebGLRenderingContextBase&);

WebGLRenderingContextBase& m_context;
GCGLbitfield m_unpreservedBuffers { 0 };
GCGLbitfield m_dirtyBuffers { 0 };
bool m_hasStencil : 1;
bool m_hasDepth : 1;
};

}

#endif
3 changes: 2 additions & 1 deletion Source/WebCore/html/canvas/WebGLRenderingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ WebGLRenderingContext::~WebGLRenderingContext()
m_activeQuery = nullptr;
}

void WebGLRenderingContext::initializeVertexArrayObjects()
void WebGLRenderingContext::initializeDefaultObjects()
{
WebGLRenderingContextBase::initializeDefaultObjects();
m_defaultVertexArrayObject = WebGLVertexArrayObjectOES::createDefault(*this);
m_boundVertexArrayObject = m_defaultVertexArrayObject;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/canvas/WebGLRenderingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class WebGLRenderingContext final : public WebGLRenderingContextBase {

GCGLint getMaxDrawBuffers() final;
GCGLint getMaxColorAttachments() final;
void initializeVertexArrayObjects() final;
void initializeDefaultObjects() final;
bool validateBlendEquation(const char* functionName, GCGLenum mode) final;

void addMembersToOpaqueRoots(JSC::AbstractSlotVisitor&) final;
Expand Down
Loading

0 comments on commit f4b3b4b

Please sign in to comment.