Skip to content

Commit

Permalink
[WebXR] Remove IOSURFACE_FOR_XR_LAYER_DATA
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260004
rdar://113662633

Reviewed by Mike Wyrzykowski.

Deprecated code path can be removed.

* Source/WTF/wtf/PlatformUse.h:
* Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp:
(WebCore::WebXROpaqueFramebuffer::~WebXROpaqueFramebuffer):
(WebCore::WebXROpaqueFramebuffer::startFrame):
(WebCore::WebXROpaqueFramebuffer::endFrame):
* Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h:
* Source/WebCore/platform/xr/PlatformXR.h:
(PlatformXR::Device::FrameData::LayerData::encode const):
(PlatformXR::Device::FrameData::LayerData::decode):
* Source/WebCore/testing/WebFakeXRDevice.cpp:
(WebCore::SimulatedXRDevice::frameTimerFired):

Canonical link: https://commits.webkit.org/266805@main
  • Loading branch information
djg committed Aug 11, 2023
1 parent defd701 commit b045c96
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Source/WTF/wtf/PlatformUse.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
#if PLATFORM(COCOA)
#define USE_FONT_VARIANT_VIA_FEATURES 1
#define USE_OPENXR 0
#define USE_IOSURFACE_FOR_XR_LAYER_DATA 1
#define USE_MTLTEXTURE_FOR_XR_LAYER_DATA 1
#define USE_MTLSHAREDEVENT_FOR_XR_FRAME_COMPLETION 0
#if !defined(HAVE_WEBXR_INTERNALS) && !HAVE(WEBXR_INTERNALS)
#define USE_EMPTYXR 1
Expand Down
24 changes: 9 additions & 15 deletions Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
#include "WebGLRenderingContextBase.h"
#include <wtf/Scope.h>

#if USE(IOSURFACE_FOR_XR_LAYER_DATA) || USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#include "GraphicsContextGLCocoa.h"
#endif

namespace WebCore {

using GL = GraphicsContextGL;

#if USE(IOSURFACE_FOR_XR_LAYER_DATA) || USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
static std::optional<GL::EGLImageAttachResult> createAndBindCompositorTexture(GL& gl, GCGLenum target, GCGLOwnedTexture& texture, GL::EGLImageSource source)
{
texture.ensure(gl);
Expand Down Expand Up @@ -105,7 +105,7 @@ WebXROpaqueFramebuffer::WebXROpaqueFramebuffer(PlatformXR::LayerHandle handle, R
WebXROpaqueFramebuffer::~WebXROpaqueFramebuffer()
{
if (auto gl = m_context.graphicsContextGL()) {
#if USE(IOSURFACE_FOR_XR_LAYER_DATA) || USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
m_colorTexture.release(*gl);
#endif
m_depthStencilBuffer.release(*gl);
Expand All @@ -115,7 +115,7 @@ WebXROpaqueFramebuffer::~WebXROpaqueFramebuffer()
} else {
// The GraphicsContextGL is gone, so disarm the GCGLOwned objects so
// their destructors don't assert.
#if USE(IOSURFACE_FOR_XR_LAYER_DATA) || USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
m_colorTexture.release(*gl);
#endif
m_depthStencilBuffer.leakObject();
Expand Down Expand Up @@ -151,22 +151,16 @@ void WebXROpaqueFramebuffer::startFrame(const PlatformXR::Device::FrameData::Lay
// FIXME: Actually do the clearing (not using invalidateFramebuffer). This will have to be done after we've attached
// the textures/renderbuffers.

#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
// FIXME: This is temporary until Cocoa-specific platforms migrate to MTLTEXTURE_FOR_XR_LAYER_DATA.
auto colorTextureSource = makeEGLImageSource({ data.surface->createSendRight(), false });
auto depthStencilBufferSource = makeEGLImageSource({ MachSendRight(), false });
#elif USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
auto colorTextureSource = makeEGLImageSource(data.colorTexture);
auto depthStencilBufferSource = makeEGLImageSource(data.depthStencilBuffer);
#endif

#if USE(IOSURFACE_FOR_XR_LAYER_DATA) || USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
auto colorTextureAttachment = createAndBindCompositorTexture(gl, textureTarget, m_colorTexture, colorTextureSource);
auto depthStencilBufferAttachment = createAndBindCompositorBuffer(gl, m_depthStencilBuffer, depthStencilBufferSource);

if (!colorTextureAttachment)
return;

auto depthStencilBufferSource = makeEGLImageSource(data.depthStencilBuffer);
auto depthStencilBufferAttachment = createAndBindCompositorBuffer(gl, m_depthStencilBuffer, depthStencilBufferSource);

IntSize bufferSize;
std::tie(m_colorImage, bufferSize) = colorTextureAttachment.value();
if (depthStencilBufferAttachment)
Expand Down Expand Up @@ -258,7 +252,7 @@ void WebXROpaqueFramebuffer::endFrame()
gl.finish();
#endif

#if USE(IOSURFACE_FOR_XR_LAYER_DATA) || USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
if (m_colorImage) {
gl.destroyEGLImage(m_colorImage);
m_colorImage = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/webxr/WebXROpaqueFramebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class WebXROpaqueFramebuffer {
GCGLOwnedRenderbuffer m_multisampleColorBuffer;
GCGLOwnedRenderbuffer m_multisampleDepthStencilBuffer;
GCGLOwnedFramebuffer m_resolvedFBO;
#if USE(IOSURFACE_FOR_XR_LAYER_DATA) || USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
GCGLOwnedTexture m_colorTexture;
GCEGLImage m_colorImage { };
GCEGLImage m_depthStencilImage { };
Expand Down
20 changes: 3 additions & 17 deletions Source/WebCore/platform/xr/PlatformXR.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,7 @@ class Device : public ThreadSafeRefCounted<Device>, public CanMakeWeakPtr<Device
};

struct LayerData {
#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
std::unique_ptr<WebCore::IOSurface> surface;
bool isShared { false };
#elif USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
std::tuple<MachSendRight, bool> colorTexture = { MachSendRight(), false };
std::tuple<MachSendRight, bool> depthStencilBuffer = { MachSendRight(), false };
#else
Expand Down Expand Up @@ -580,11 +577,7 @@ std::optional<Device::FrameData::StageParameters> Device::FrameData::StageParame
template<class Encoder>
void Device::FrameData::LayerData::encode(Encoder& encoder) const
{
#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
MachSendRight surfaceSendRight = surface ? surface->createSendRight() : MachSendRight();
encoder << WTFMove(surfaceSendRight);
encoder << isShared;
#elif USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
encoder << std::tuple(colorTexture);
encoder << std::tuple(depthStencilBuffer);
#else
Expand All @@ -599,14 +592,7 @@ template<class Decoder>
std::optional<Device::FrameData::LayerData> Device::FrameData::LayerData::decode(Decoder& decoder)
{
PlatformXR::Device::FrameData::LayerData layerData;
#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
MachSendRight surfaceSendRight;
if (!decoder.decode(surfaceSendRight))
return std::nullopt;
layerData.surface = WebCore::IOSurface::createFromSendRight(WTFMove(surfaceSendRight));
if (!decoder.decode(layerData.isShared))
return std::nullopt;
#elif USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
if (!decoder.decode(layerData.colorTexture))
return std::nullopt;
if (!decoder.decode(layerData.depthStencilBuffer))
Expand Down
8 changes: 1 addition & 7 deletions Source/WebCore/testing/WebFakeXRDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
#include <wtf/CompletionHandler.h>
#include <wtf/MathExtras.h>

#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
#include "IOSurface.h"
#endif

namespace WebCore {

static constexpr Seconds FakeXRFrameTime = 15_ms;
Expand Down Expand Up @@ -156,9 +152,7 @@ void SimulatedXRDevice::frameTimerFired()
data.shouldRender = true;

for (auto& layer : m_layers) {
#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
data.layers.add(layer.key, FrameData::LayerData { .surface = IOSurface::create(nullptr, recommendedResolution(PlatformXR::SessionMode::ImmersiveVr), DestinationColorSpace::SRGB()) });
#elif USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
#if USE(MTLTEXTURE_FOR_XR_LAYER_DATA)
auto surface = IOSurface::create(nullptr, recommendedResolution(PlatformXR::SessionMode::ImmersiveVr), DestinationColorSpace::SRGB());
data.layers.add(layer.key, FrameData::LayerData { .colorTexture = std::make_tuple(surface->createSendRight(), false) });
#else
Expand Down

0 comments on commit b045c96

Please sign in to comment.