Modified: trunk/Source/WebCore/ChangeLog (278259 => 278260)
--- trunk/Source/WebCore/ChangeLog 2021-05-30 22:26:49 UTC (rev 278259)
+++ trunk/Source/WebCore/ChangeLog 2021-05-30 22:46:54 UTC (rev 278260)
@@ -1,5 +1,25 @@
2021-05-30 Dean Jackson <[email protected]>
+ [WebXR] Provide a way to bind and unbind IOSurfaces to ANGLE Pbuffers
+ https://bugs.webkit.org/show_bug.cgi?id=226423
+ <rdar://problem/78652783>
+
+ Reviewed by Sam Weinig.
+
+ WebXR on Cocoa platforms gets framebuffer texture targets via
+ IOSurfaces. Those must be attached to ANGLE Pbuffers, which are
+ then bound to GL textures. There is already some code in
+ GraphicsContextGL (and in the CoreVideo classes) to do this, but
+ this is an attempt to make a generic function that will handle all
+ cases.
+
+ * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+ (WebCore::GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface):
+ (WebCore::GraphicsContextGLOpenGL::destroyPbufferAndDetachIOSurface):
+ * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+
+2021-05-30 Dean Jackson <[email protected]>
+
[WebXR] No need for opaqueTexture when USE(IOSURFACE_FOR_XR_LAYER_DATA)
https://bugs.webkit.org/show_bug.cgi?id=226405
<rdar://problem/78636950>
Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (278259 => 278260)
--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2021-05-30 22:26:49 UTC (rev 278259)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2021-05-30 22:46:54 UTC (rev 278260)
@@ -611,6 +611,69 @@
return true;
}
+void* GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface(GCGLenum target, PbufferAttachmentUsage usage, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef surface, GCGLuint plane)
+{
+ if (target != GraphicsContextGL::TEXTURE_RECTANGLE_ARB && target != GraphicsContextGL::TEXTURE_2D) {
+ LOG(WebGL, "Unknown texture target %d.", static_cast<int>(target));
+ return nullptr;
+ }
+
+ auto eglTextureTarget = [&] () -> EGLint {
+ if (target == GraphicsContextGL::TEXTURE_RECTANGLE_ARB)
+ return EGL_TEXTURE_RECTANGLE_ANGLE;
+ return EGL_TEXTURE_2D;
+ }();
+
+ if (eglTextureTarget != GraphicsContextGLOpenGL::EGLDrawingBufferTextureTarget()) {
+ LOG(WebGL, "Mismatch in EGL texture target: %d should be %d.", static_cast<int>(target), GraphicsContextGLOpenGL::EGLDrawingBufferTextureTarget());
+ return nullptr;
+ }
+
+ auto usageHintAngle = [&] () -> EGLint {
+ if (usage == PbufferAttachmentUsage::Read)
+ return EGL_IOSURFACE_READ_HINT_ANGLE;
+ if (usage == PbufferAttachmentUsage::Write)
+ return EGL_IOSURFACE_WRITE_HINT_ANGLE;
+ return EGL_IOSURFACE_READ_HINT_ANGLE | EGL_IOSURFACE_WRITE_HINT_ANGLE;
+ }();
+
+ const EGLint surfaceAttributes[] = {
+ EGL_WIDTH, width,
+ EGL_HEIGHT, height,
+ EGL_IOSURFACE_PLANE_ANGLE, static_cast<EGLint>(plane),
+ EGL_TEXTURE_TARGET, static_cast<EGLint>(eglTextureTarget),
+ EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, static_cast<EGLint>(internalFormat),
+ EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
+ EGL_TEXTURE_TYPE_ANGLE, static_cast<EGLint>(type),
+ // Only has an effect on the iOS Simulator.
+ EGL_IOSURFACE_USAGE_HINT_ANGLE, usageHintAngle,
+ EGL_NONE, EGL_NONE
+ };
+
+ auto display = platformDisplay();
+ EGLSurface pbuffer = EGL_CreatePbufferFromClientBuffer(display, EGL_IOSURFACE_ANGLE, surface, platformConfig(), surfaceAttributes);
+ if (!pbuffer) {
+ LOG(WebGL, "EGL_CreatePbufferFromClientBuffer failed.");
+ return nullptr;
+ }
+
+ if (!EGL_BindTexImage(display, pbuffer, EGL_BACK_BUFFER)) {
+ LOG(WebGL, "EGL_BindTexImage failed.");
+ EGL_DestroySurface(display, pbuffer);
+ return nullptr;
+ }
+
+ return pbuffer;
+}
+
+void GraphicsContextGLOpenGL::destroyPbufferAndDetachIOSurface(void* handle)
+{
+ auto display = platformDisplay();
+ EGL_ReleaseTexImage(display, handle, EGL_BACK_BUFFER);
+ EGL_DestroySurface(display, handle);
+}
+
+
bool GraphicsContextGLOpenGL::isGLES2Compliant() const
{
return m_isForWebGL2;
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (278259 => 278260)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2021-05-30 22:26:49 UTC (rev 278259)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2021-05-30 22:46:54 UTC (rev 278260)
@@ -528,6 +528,14 @@
static void paintToCanvas(const GraphicsContextGLAttributes&, PixelBuffer&&, const IntSize& canvasSize, GraphicsContext&);
+#if PLATFORM(COCOA)
+ enum class PbufferAttachmentUsage { Read, Write, ReadWrite };
+ // Returns a handle which, if non-null, must be released via the
+ // detach call below.
+ void* createPbufferAndAttachIOSurface(GCGLenum target, PbufferAttachmentUsage, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef, GCGLuint plane);
+ void destroyPbufferAndDetachIOSurface(void* handle);
+#endif
+
private:
#if PLATFORM(COCOA)
GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLOpenGL* sharedContext = nullptr, GraphicsContextGLIOSurfaceSwapChain* = nullptr);
@@ -552,7 +560,6 @@
// Did the most recent drawing operation leave the GPU in an acceptable state?
void checkGPUStatus();
-
std::optional<PixelBuffer> readRenderingResults();
std::optional<PixelBuffer> readCompositedResults();
std::optional<PixelBuffer> readPixelsForPaintResults();