<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[279298] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/279298">279298</a></dd>
<dt>Author</dt> <dd>dino@apple.com</dd>
<dt>Date</dt> <dd>2021-06-25 15:06:49 -0700 (Fri, 25 Jun 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add support for MTLSharedTextures in WebXR
https://bugs.webkit.org/show_bug.cgi?id=227245
<rdar://problem/79591620>

Reviewed by Tim Horton.

Source/WebCore:

Sometimes, the IOSurface passed to WebXR come from a shared MTLTexture. In
this case we can't treat the IOSurface data as a regular single-plane
image. Instead we should use it to recreate the MTLTexture and then
bind that to WebGL's framebuffer.

* Modules/webxr/WebXROpaqueFramebuffer.cpp: Use some new binding methods on GraphicsContextGLOpenGL
if given a shared texture.
(WebCore::WebXROpaqueFramebuffer::startFrame):
(WebCore::WebXROpaqueFramebuffer::endFrame):
* Modules/webxr/WebXROpaqueFramebuffer.h:
* platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm: New methods to link an
IOSurface to a GL texture, going through a MTLSharedTexture.
(WebCore::GraphicsContextGLOpenGL::attachIOSurfaceToSharedTexture):
(WebCore::GraphicsContextGLOpenGL::detachIOSurfaceFromSharedTexture):
* platform/graphics/opengl/GraphicsContextGLOpenGL.h:
* platform/xr/PlatformXR.h: Add a new "isShared" member to LayerData
to differentiate between normal IOSurfaces and those that came
from a shared texture.
(PlatformXR::Device::FrameData::LayerData::encode const):
(PlatformXR::Device::FrameData::LayerData::decode):

Source/WebCore/PAL:

Define MTLSharedTextureHandle's initWithIOSurface.

* pal/spi/cocoa/MetalSPI.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModuleswebxrWebXROpaqueFramebuffercpp">trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModuleswebxrWebXROpaqueFramebufferh">trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h</a></li>
<li><a href="#trunkSourceWebCorePALChangeLog">trunk/Source/WebCore/PAL/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorePALpalspicocoaMetalSPIh">trunk/Source/WebCore/PAL/pal/spi/cocoa/MetalSPI.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscocoaGraphicsContextGLOpenGLCocoamm">trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsopenglGraphicsContextGLOpenGLh">trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h</a></li>
<li><a href="#trunkSourceWebCoreplatformxrPlatformXRh">trunk/Source/WebCore/platform/xr/PlatformXR.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (279297 => 279298)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-06-25 20:50:25 UTC (rev 279297)
+++ trunk/Source/WebCore/ChangeLog      2021-06-25 22:06:49 UTC (rev 279298)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2021-06-22  Dean Jackson  <dino@apple.com>
+
+        Add support for MTLSharedTextures in WebXR
+        https://bugs.webkit.org/show_bug.cgi?id=227245
+        <rdar://problem/79591620>
+
+        Reviewed by Tim Horton.
+
+        Sometimes, the IOSurface passed to WebXR come from a shared MTLTexture. In
+        this case we can't treat the IOSurface data as a regular single-plane
+        image. Instead we should use it to recreate the MTLTexture and then
+        bind that to WebGL's framebuffer.
+
+        * Modules/webxr/WebXROpaqueFramebuffer.cpp: Use some new binding methods on GraphicsContextGLOpenGL
+        if given a shared texture.
+        (WebCore::WebXROpaqueFramebuffer::startFrame):
+        (WebCore::WebXROpaqueFramebuffer::endFrame):
+        * Modules/webxr/WebXROpaqueFramebuffer.h:
+        * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm: New methods to link an
+        IOSurface to a GL texture, going through a MTLSharedTexture.
+        (WebCore::GraphicsContextGLOpenGL::attachIOSurfaceToSharedTexture):
+        (WebCore::GraphicsContextGLOpenGL::detachIOSurfaceFromSharedTexture):
+        * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+        * platform/xr/PlatformXR.h: Add a new "isShared" member to LayerData
+        to differentiate between normal IOSurfaces and those that came
+        from a shared texture.
+        (PlatformXR::Device::FrameData::LayerData::encode const):
+        (PlatformXR::Device::FrameData::LayerData::decode):
+
</ins><span class="cx"> 2021-06-25  Alex Christensen  <achristensen@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Fix null crash in AudioMediaStreamTrackRendererCocoa::start
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebxrWebXROpaqueFramebuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp (279297 => 279298)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp    2021-06-25 20:50:25 UTC (rev 279297)
+++ trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp       2021-06-25 22:06:49 UTC (rev 279298)
</span><span class="lines">@@ -125,9 +125,6 @@
</span><span class="cx">     auto gCGL = static_cast<GraphicsContextGLOpenGL*>(m_context.graphicsContextGL());
</span><span class="cx">     GCGLenum textureTarget = GraphicsContextGLOpenGL::drawingBufferTextureTarget();
</span><span class="cx"> 
</span><del>-    auto size = data.surface->size();
-    if (!size.width() || !size.height())
-        return;
</del><span class="cx"> 
</span><span class="cx">     if (!m_opaqueTexture)
</span><span class="cx">         m_opaqueTexture = gCGL->createTexture();
</span><span class="lines">@@ -139,18 +136,29 @@
</span><span class="cx">     gCGL->texParameteri(textureTarget, GL::TEXTURE_WRAP_T, GL::CLAMP_TO_EDGE);
</span><span class="cx"> 
</span><span class="cx">     // Tell the GraphicsContextGL to use the IOSurface as the backing store for m_opaqueTexture.
</span><del>-    m_ioSurfaceTextureHandle = gCGL->createPbufferAndAttachIOSurface(textureTarget, GraphicsContextGLOpenGL::PbufferAttachmentUsage::Write, GL::BGRA, size.width(), size.height(), GL::UNSIGNED_BYTE, data.surface->surface(), 0);
-    if (!m_ioSurfaceTextureHandle && m_opaqueTexture) {
</del><ins>+    if (data.isShared) {
+        m_ioSurfaceTextureHandle = gCGL->attachIOSurfaceToSharedTexture(textureTarget, data.surface.get());
+        m_ioSurfaceTextureHandleIsShared = true;
+    } else {
+        auto size = data.surface->size();
+        if (!size.width() || !size.height())
+            return;
+        m_ioSurfaceTextureHandle = gCGL->createPbufferAndAttachIOSurface(textureTarget, GraphicsContextGLOpenGL::PbufferAttachmentUsage::Write, GL::BGRA, size.width(), size.height(), GL::UNSIGNED_BYTE, data.surface->surface(), 0);
+        m_ioSurfaceTextureHandleIsShared = false;
+    }
+
+    if (!m_ioSurfaceTextureHandle) {
</ins><span class="cx">         gCGL->deleteTexture(m_opaqueTexture);
</span><ins>+        m_opaqueTexture = 0;
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // FIXME: This is assuming multisampling is turned off and we're rendering directly into the framebuffer.
-
</del><span class="cx">     // Now set up the framebuffer to use the texture that points to the IOSurface. The depth and
</span><span class="cx">     // stencil buffers were attached by startFrame.
</span><span class="cx">     gl.framebufferTexture2D(GL::FRAMEBUFFER, GL::COLOR_ATTACHMENT0, GL::TEXTURE_2D, m_opaqueTexture, 0);
</span><span class="cx"> 
</span><ins>+    // FIXME: This is assuming multisampling is turned off and we're rendering directly into the framebuffer.
+
</ins><span class="cx">     // At this point the framebuffer should be "complete".
</span><span class="cx">     ASSERT(gl.checkFramebufferStatus(GL::FRAMEBUFFER) == GL::FRAMEBUFFER_COMPLETE);
</span><span class="cx"> #else
</span><span class="lines">@@ -187,7 +195,12 @@
</span><span class="cx"> 
</span><span class="cx">     if (m_ioSurfaceTextureHandle) {
</span><span class="cx">         auto gCGL = static_cast<GraphicsContextGLOpenGL*>(&gl);
</span><del>-        gCGL->destroyPbufferAndDetachIOSurface(m_ioSurfaceTextureHandle);
</del><ins>+        if (m_ioSurfaceTextureHandleIsShared)
+            gCGL->detachIOSurfaceFromSharedTexture(m_ioSurfaceTextureHandle);
+        else
+            gCGL->destroyPbufferAndDetachIOSurface(m_ioSurfaceTextureHandle);
+        m_ioSurfaceTextureHandle = nullptr;
+        m_ioSurfaceTextureHandleIsShared = false;
</ins><span class="cx">     }
</span><span class="cx"> #else
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebxrWebXROpaqueFramebufferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h (279297 => 279298)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h      2021-06-25 20:50:25 UTC (rev 279297)
+++ trunk/Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h 2021-06-25 22:06:49 UTC (rev 279298)
</span><span class="lines">@@ -79,6 +79,7 @@
</span><span class="cx">     PlatformGLObject m_opaqueTexture { 0 };
</span><span class="cx"> #if USE(IOSURFACE_FOR_XR_LAYER_DATA)
</span><span class="cx">     void* m_ioSurfaceTextureHandle { nullptr };
</span><ins>+    bool m_ioSurfaceTextureHandleIsShared { false };
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorePALChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PAL/ChangeLog (279297 => 279298)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PAL/ChangeLog       2021-06-25 20:50:25 UTC (rev 279297)
+++ trunk/Source/WebCore/PAL/ChangeLog  2021-06-25 22:06:49 UTC (rev 279298)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2021-06-22  Dean Jackson  <dino@apple.com>
+
+        Add support for MTLSharedTextures in WebXR
+        https://bugs.webkit.org/show_bug.cgi?id=227245
+        <rdar://problem/79591620>
+
+        Reviewed by Tim Horton.
+
+        Define MTLSharedTextureHandle's initWithIOSurface.
+
+        * pal/spi/cocoa/MetalSPI.h:
+
</ins><span class="cx"> 2021-06-25  Wenson Hsieh  <wenson_hsieh@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, fix the macOS Monterey build
</span></span></pre></div>
<a id="trunkSourceWebCorePALpalspicocoaMetalSPIh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PAL/pal/spi/cocoa/MetalSPI.h (279297 => 279298)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PAL/pal/spi/cocoa/MetalSPI.h        2021-06-25 20:50:25 UTC (rev 279297)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/MetalSPI.h   2021-06-25 22:06:49 UTC (rev 279298)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(APPLE_INTERNAL_SDK)
</span><span class="cx"> 
</span><ins>+#import <Metal/MTLTexture_Private.h>
</ins><span class="cx"> #import <Metal/MetalPrivate.h>
</span><span class="cx"> 
</span><span class="cx"> #else
</span><span class="lines">@@ -31,6 +32,8 @@
</span><span class="cx"> 
</span><span class="cx"> #import <Foundation/NSObject.h>
</span><span class="cx"> 
</span><ins>+typedef struct __IOSurface *IOSurfaceRef;
+
</ins><span class="cx"> @protocol MTLDeviceSPI <MTLDevice>
</span><span class="cx"> - (NSString*)vendorName;
</span><span class="cx"> - (NSString*)familyName;
</span><span class="lines">@@ -41,4 +44,8 @@
</span><span class="cx"> - (void)_purgeDevice;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+@interface MTLSharedTextureHandle(Private)
+- (instancetype)initWithIOSurface:(IOSurfaceRef)ioSurface label:(NSString*)label;
+@end
+
</ins><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscocoaGraphicsContextGLOpenGLCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (279297 => 279298)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm     2021-06-25 20:50:25 UTC (rev 279297)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm        2021-06-25 22:06:49 UTC (rev 279298)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx"> #import "WebGLLayer.h"
</span><span class="cx"> #import <CoreGraphics/CGBitmapContext.h>
</span><span class="cx"> #import <Metal/Metal.h>
</span><ins>+#import <pal/spi/cocoa/MetalSPI.h>
</ins><span class="cx"> #import <wtf/BlockObjCExceptions.h>
</span><span class="cx"> #import <wtf/darwin/WeakLinking.h>
</span><span class="cx"> #import <wtf/text/CString.h>
</span><span class="lines">@@ -684,7 +685,52 @@
</span><span class="cx">     EGL_DestroySurface(display, handle);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void* GraphicsContextGLOpenGL::attachIOSurfaceToSharedTexture(GCGLenum target, IOSurface* surface)
+{
+    constexpr EGLint emptyAttributes[] = { EGL_NONE };
</ins><span class="cx"> 
</span><ins>+    // Create a MTLTexture out of the IOSurface.
+    // FIXME: We need to use the same device that ANGLE is using, which might not be the default.
+
+    RetainPtr<MTLSharedTextureHandle> handle = adoptNS([[MTLSharedTextureHandle alloc] initWithIOSurface:surface->surface() label:@"WebXR"]);
+    if (!handle) {
+        LOG(WebGL, "Unable to create a MTLSharedTextureHandle from the IOSurface in attachIOSurfaceToTexture.");
+        return nullptr;
+    }
+
+    if (!handle.get().device) {
+        LOG(WebGL, "MTLSharedTextureHandle does not have a Metal device in attachIOSurfaceToTexture.");
+        return nullptr;
+    }
+
+    auto texture = adoptNS([handle.get().device newSharedTextureWithHandle:handle.get()]);
+    if (!texture) {
+        LOG(WebGL, "Unable to create a MTLSharedTexture from the texture handle in attachIOSurfaceToTexture.");
+        return nullptr;
+    }
+
+    // FIXME: Does the texture have the correct usage mode?
+
+    // Create an EGLImage out of the MTLTexture
+    auto display = platformDisplay();
+    auto eglImage = EGL_CreateImageKHR(display, EGL_NO_CONTEXT, EGL_METAL_TEXTURE_ANGLE, reinterpret_cast<EGLClientBuffer>(texture.get()), emptyAttributes);
+    if (!eglImage) {
+        LOG(WebGL, "Unable to create an EGLImage from the Metal handle in attachIOSurfaceToTexture.");
+        return nullptr;
+    }
+
+    // Tell the currently bound texture to use the EGLImage.
+    gl::EGLImageTargetTexture2DOES(target, eglImage);
+
+    return eglImage;
+}
+
+void GraphicsContextGLOpenGL::detachIOSurfaceFromSharedTexture(void* handle)
+{
+    auto display = platformDisplay();
+    EGL_DestroyImageKHR(display, handle);
+}
+
</ins><span class="cx"> bool GraphicsContextGLOpenGL::isGLES2Compliant() const
</span><span class="cx"> {
</span><span class="cx">     return m_isForWebGL2;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsopenglGraphicsContextGLOpenGLh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (279297 => 279298)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h  2021-06-25 20:50:25 UTC (rev 279297)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h     2021-06-25 22:06:49 UTC (rev 279298)
</span><span class="lines">@@ -536,6 +536,8 @@
</span><span class="cx">     // detach call below.
</span><span class="cx">     void* createPbufferAndAttachIOSurface(GCGLenum target, PbufferAttachmentUsage, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef, GCGLuint plane);
</span><span class="cx">     void destroyPbufferAndDetachIOSurface(void* handle);
</span><ins>+    void* attachIOSurfaceToSharedTexture(GCGLenum target, IOSurface*);
+    void detachIOSurfaceFromSharedTexture(void* handle);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformxrPlatformXRh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/xr/PlatformXR.h (279297 => 279298)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/xr/PlatformXR.h    2021-06-25 20:50:25 UTC (rev 279297)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.h       2021-06-25 22:06:49 UTC (rev 279298)
</span><span class="lines">@@ -173,6 +173,7 @@
</span><span class="cx">         struct LayerData {
</span><span class="cx"> #if USE(IOSURFACE_FOR_XR_LAYER_DATA)
</span><span class="cx">             std::unique_ptr<WebCore::IOSurface> surface;
</span><ins>+            bool isShared { false };
</ins><span class="cx"> #else
</span><span class="cx">             PlatformGLObject opaqueTexture { 0 };
</span><span class="cx"> #endif
</span><span class="lines">@@ -442,6 +443,7 @@
</span><span class="cx"> #if USE(IOSURFACE_FOR_XR_LAYER_DATA)
</span><span class="cx">     WTF::MachSendRight surfaceSendRight = surface ? surface->createSendRight() : WTF::MachSendRight();
</span><span class="cx">     encoder << surfaceSendRight;
</span><ins>+    encoder << isShared;
</ins><span class="cx"> #else
</span><span class="cx">     encoder << opaqueTexture;
</span><span class="cx"> #endif
</span><span class="lines">@@ -456,6 +458,8 @@
</span><span class="cx">     if (!decoder.decode(surfaceSendRight))
</span><span class="cx">         return std::nullopt;
</span><span class="cx">     layerData.surface = WebCore::IOSurface::createFromSendRight(WTFMove(surfaceSendRight), WebCore::DestinationColorSpace::SRGB());
</span><ins>+    if (!decoder.decode(layerData.isShared))
+        return std::nullopt;
</ins><span class="cx"> #else
</span><span class="cx">     if (!decoder.decode(layerData.opaqueTexture))
</span><span class="cx">         return std::nullopt;
</span></span></pre>
</div>
</div>

</body>
</html>