Skip to content

Commit

Permalink
[WebXR] Unify all paths for requesting required ANGLE extensions for …
Browse files Browse the repository at this point in the history
…WebXR

https://bugs.webkit.org/show_bug.cgi?id=259354
rdar://109814502

Reviewed by Dean Jackson.

There are two ways to create a WebXR compatible WebGL context. These paths have
a habit of getting out-of-sync. This patch unifies the two paths in calling
`enableRequiredWebXRExtensions` on the underlying GraphicsContextGL. This
function enables all the extensions required to support any combination of
WebXRLayer attributes, which can be independent of the attributes used to create
the WebGLRenderingContext.

* Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::makeXRCompatible):
* Source/WebCore/platform/graphics/GraphicsContextGL.h:
* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.h:
* Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
(WebCore::GraphicsContextGLCocoa::platformInitialize):
(WebCore::GraphicsContextGLCocoa::enableRequiredWebXRExtensions):
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in:
* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLFunctionsGenerated.h:
(enableRequiredWebXRExtensions):
* Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
* Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxyFunctionsGenerated.cpp:
(WebKit::RemoteGraphicsContextGLProxy::enableRequiredWebXRExtensions):

Canonical link: https://commits.webkit.org/266189@main
  • Loading branch information
djg committed Jul 20, 2023
1 parent fab4103 commit 99ec089
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 11 deletions.
8 changes: 2 additions & 6 deletions Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3279,12 +3279,8 @@ void WebGLRenderingContextBase::makeXRCompatible(MakeXRCompatiblePromise&& promi
m_isXRCompatible = true;

#if PLATFORM(COCOA)
// FIXME: This is ugly. It's something needed at the GraphicsContextGL
// level, not WebGLRenderingContext. We should move this down to a
// virtual makeXRCompatible or something on GCGL.
enableSupportedExtension("GL_OES_EGL_image"_s);
enableSupportedExtension("GL_EXT_sRGB"_s);
enableSupportedExtension("GL_ANGLE_framebuffer_multisample"_s);
if (!m_context->enableRequiredWebXRExtensions())
return;
#endif

promise.resolve();
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/platform/graphics/GraphicsContextGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,8 @@ class GraphicsContextGL : public RefCounted<GraphicsContextGL> {
// Has no other side-effects.
virtual bool isExtensionEnabled(const String&) = 0;

virtual bool enableRequiredWebXRExtensions() { return true; }

// GL_ANGLE_translated_shader_source
virtual String getTranslatedShaderSourceANGLE(PlatformGLObject) = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class WEBCORE_EXPORT GraphicsContextGLCocoa : public GraphicsContextGLANGLE {
// Short term support for in-process WebGL.
GCEGLSync createEGLSync(id, uint64_t);

bool enableRequiredWebXRExtensions() final;

void waitUntilWorkScheduled();

// GraphicsContextGLANGLE overrides.
Expand Down
27 changes: 22 additions & 5 deletions Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,8 @@ static bool needsEAGLOnMac()
}
#endif // PLATFORM(MAC) || PLATFORM(MACCATALYST)
#if ENABLE(WEBXR)
if (attributes.xrCompatible) {
requiredExtensions.append("GL_OES_EGL_image"_s);
requiredExtensions.append("GL_EXT_sRGB"_s);
requiredExtensions.append("GL_ANGLE_framebuffer_multisample"_s);
}
if (attributes.xrCompatible && !enableRequiredWebXRExtensions())
return false;
#endif
if (m_isForWebGL2)
requiredExtensions.append("GL_ANGLE_framebuffer_multisample"_s);
Expand Down Expand Up @@ -766,6 +763,26 @@ static bool needsEAGLOnMac()
return createEGLSync(sharedEvent.get(), signalValue);
}

bool GraphicsContextGLCocoa::enableRequiredWebXRExtensions()
{
#if ENABLE(WEBXR)
String requiredExtensions[] = {
"GL_ANGLE_framebuffer_multisample"_str,
"GL_ANGLE_framebuffer_blit"_str,
"GL_EXT_sRGB"_str,
"GL_OES_EGL_image"_str,
"GL_OES_rgb8_rgba8"_str
};

for (const auto& ext : requiredExtensions) {
if (!supportsExtension(ext))
return false;
ensureExtensionEnabled(ext);
}
#endif
return true;
}

GCEGLSync GraphicsContextGLCocoa::createEGLSync(id sharedEvent, uint64_t signalValue)
{
COMPILE_ASSERT(sizeof(EGLAttrib) == sizeof(void*), "EGLAttrib not pointer-sized!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ messages -> RemoteGraphicsContextGL NotRefCounted Stream {
void PaintRenderingResultsToPixelBuffer() -> (RefPtr<WebCore::PixelBuffer> returnValue) Synchronous
void DestroyEGLSync(uint64_t arg0) -> (bool returnValue) Synchronous
void ClientWaitEGLSyncWithFlush(uint64_t arg0, uint64_t timeout)
void EnableRequiredWebXRExtensions() -> (bool returnValue) Synchronous
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -1501,4 +1501,11 @@
assertIsCurrent(workQueue());
m_context->clientWaitEGLSyncWithFlush(reinterpret_cast<GCEGLSync>(static_cast<intptr_t>(arg0)), timeout);
}
void enableRequiredWebXRExtensions(CompletionHandler<void(bool)>&& completionHandler)
{
bool returnValue = { };
assertIsCurrent(workQueue());
returnValue = m_context->enableRequiredWebXRExtensions();
completionHandler(returnValue);
}

Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ class RemoteGraphicsContextGLProxy
RefPtr<WebCore::PixelBuffer> paintRenderingResultsToPixelBuffer() final;
bool destroyEGLSync(GCEGLSync) final;
void clientWaitEGLSyncWithFlush(GCEGLSync, uint64_t timeout) final;

bool enableRequiredWebXRExtensions() final;
// End of list used by generate-gpup-webgl script.

static bool handleMessageToRemovedDestination(IPC::Connection&, IPC::Decoder&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3097,6 +3097,19 @@ void RemoteGraphicsContextGLProxy::clientWaitEGLSyncWithFlush(GCEGLSync arg0, ui
}
}

bool RemoteGraphicsContextGLProxy::enableRequiredWebXRExtensions()
{
if (isContextLost())
return { };
auto sendResult = sendSync(Messages::RemoteGraphicsContextGL::EnableRequiredWebXRExtensions());
if (!sendResult.succeeded()) {
markContextLost();
return { };
}
auto& [returnValue] = sendResult.reply();
return returnValue;
}

}

#endif
Expand Down

0 comments on commit 99ec089

Please sign in to comment.