Title: [277099] trunk/Source
Revision
277099
Author
[email protected]
Date
2021-05-06 10:05:23 -0700 (Thu, 06 May 2021)

Log Message

[WebXR] Add IOSurface to FrameData::LayerData
https://bugs.webkit.org/show_bug.cgi?id=225428
<rdar://problem/77586270>

Reviewed by Tim Horton.

Source/WebCore:

Original patch by Ada Chan.

Cocoa platforms will use IOSurfaces on FrameData::LayerData.
Add this member, allow it to be encoded and decoded, and fix up
some places where we were copying a FrameData unnecessarily, or
where we have to explicitly copy.

* Modules/webxr/WebXRSession.cpp:
(WebCore::WebXRSession::onFrame): Use WTFMove instead of copying.
* platform/graphics/cocoa/IOSurface.h: Export createFromSurface.
* platform/xr/PlatformXR.h:
(PlatformXR::Device::FrameData::LayerData::encode const):
(PlatformXR::Device::FrameData::LayerData::decode):
(PlatformXR::Device::FrameData::decode):
(PlatformXR::Device::FrameData::copy const):
* testing/WebFakeXRDevice.cpp:
(WebCore::SimulatedXRDevice::frameTimerFired):

Source/WTF:

Add USE(IOSURFACE_FOR_XR_LAYER_DATA) and make it true
for Cocoa platforms.

* wtf/PlatformUse.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (277098 => 277099)


--- trunk/Source/WTF/ChangeLog	2021-05-06 16:57:12 UTC (rev 277098)
+++ trunk/Source/WTF/ChangeLog	2021-05-06 17:05:23 UTC (rev 277099)
@@ -1,3 +1,16 @@
+2021-05-06  Dean Jackson  <[email protected]>
+
+        [WebXR] Add IOSurface to FrameData::LayerData
+        https://bugs.webkit.org/show_bug.cgi?id=225428
+        <rdar://problem/77586270>
+
+        Reviewed by Tim Horton.
+
+        Add USE(IOSURFACE_FOR_XR_LAYER_DATA) and make it true
+        for Cocoa platforms.
+
+        * wtf/PlatformUse.h:
+
 2021-05-06  Darin Adler  <[email protected]>
 
         Streamline codec parsing, replacing uses of HashMap with SortedArrayMap

Modified: trunk/Source/WTF/wtf/PlatformUse.h (277098 => 277099)


--- trunk/Source/WTF/wtf/PlatformUse.h	2021-05-06 16:57:12 UTC (rev 277098)
+++ trunk/Source/WTF/wtf/PlatformUse.h	2021-05-06 17:05:23 UTC (rev 277099)
@@ -321,6 +321,7 @@
 
 #if PLATFORM(COCOA)
 #define USE_OPENXR 0
+#define USE_IOSURFACE_FOR_XR_LAYER_DATA 1
 #endif
 
 #if PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebCore/ChangeLog (277098 => 277099)


--- trunk/Source/WebCore/ChangeLog	2021-05-06 16:57:12 UTC (rev 277098)
+++ trunk/Source/WebCore/ChangeLog	2021-05-06 17:05:23 UTC (rev 277099)
@@ -1,3 +1,29 @@
+2021-05-06  Dean Jackson  <[email protected]>
+
+        [WebXR] Add IOSurface to FrameData::LayerData
+        https://bugs.webkit.org/show_bug.cgi?id=225428
+        <rdar://problem/77586270>
+
+        Reviewed by Tim Horton.
+
+        Original patch by Ada Chan.
+
+        Cocoa platforms will use IOSurfaces on FrameData::LayerData.
+        Add this member, allow it to be encoded and decoded, and fix up
+        some places where we were copying a FrameData unnecessarily, or
+        where we have to explicitly copy.
+
+        * Modules/webxr/WebXRSession.cpp:
+        (WebCore::WebXRSession::onFrame): Use WTFMove instead of copying.
+        * platform/graphics/cocoa/IOSurface.h: Export createFromSurface.
+        * platform/xr/PlatformXR.h:
+        (PlatformXR::Device::FrameData::LayerData::encode const):
+        (PlatformXR::Device::FrameData::LayerData::decode):
+        (PlatformXR::Device::FrameData::decode):
+        (PlatformXR::Device::FrameData::copy const):
+        * testing/WebFakeXRDevice.cpp:
+        (WebCore::SimulatedXRDevice::frameTimerFired):
+
 2021-05-06  Alicia Boya GarcĂ­a  <[email protected]>
 
         [MSE][GStreamer] Remove webKitMediaSrcFinalize

Modified: trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp (277098 => 277099)


--- trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp	2021-05-06 16:57:12 UTC (rev 277098)
+++ trunk/Source/WebCore/Modules/webxr/WebXRSession.cpp	2021-05-06 17:05:23 UTC (rev 277099)
@@ -522,7 +522,7 @@
         if (m_ended)
             return;
 
-        m_frameData = frameData;
+        m_frameData = WTFMove(frameData);
         //  1.Let now be the current high resolution time.
         auto now = (MonotonicTime::now() - m_timeOrigin).milliseconds();
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h (277098 => 277099)


--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2021-05-06 16:57:12 UTC (rev 277098)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.h	2021-05-06 17:05:23 UTC (rev 277099)
@@ -104,7 +104,7 @@
     WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, CGColorSpaceRef, Format = Format::BGRA);
     WEBCORE_EXPORT static std::unique_ptr<IOSurface> create(IntSize, IntSize contextSize, CGColorSpaceRef, Format = Format::BGRA);
     WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromSendRight(const WTF::MachSendRight&&, CGColorSpaceRef);
-    static std::unique_ptr<IOSurface> createFromSurface(IOSurfaceRef, CGColorSpaceRef);
+    WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromSurface(IOSurfaceRef, CGColorSpaceRef);
     WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromImage(CGImageRef);
     WEBCORE_EXPORT static std::unique_ptr<IOSurface> createFromPixelBuffer(CVPixelBufferRef);
     

Modified: trunk/Source/WebCore/platform/xr/PlatformXR.h (277098 => 277099)


--- trunk/Source/WebCore/platform/xr/PlatformXR.h	2021-05-06 16:57:12 UTC (rev 277098)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.h	2021-05-06 17:05:23 UTC (rev 277099)
@@ -31,6 +31,12 @@
 #include <wtf/Vector.h>
 #include <wtf/WeakPtr.h>
 
+#if PLATFORM(COCOA)
+#include <WebCore/ColorSpaceCG.h>
+#include <WebCore/IOSurface.h>
+#include <wtf/MachSendRight.h>
+#endif
+
 namespace PlatformXR {
 
 enum class SessionMode : uint8_t {
@@ -166,6 +172,9 @@
 
         struct LayerData {
             PlatformGLObject opaqueTexture { 0 };
+#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
+            std::unique_ptr<WebCore::IOSurface> surface;
+#endif
 
             template<class Encoder> void encode(Encoder&) const;
             template<class Decoder> static Optional<LayerData> decode(Decoder&);
@@ -205,6 +214,8 @@
         HashMap<LayerHandle, LayerData> layers;
         Vector<InputSource> inputSources;
 
+        FrameData copy() const;
+
         template<class Encoder> void encode(Encoder&) const;
         template<class Decoder> static Optional<FrameData> decode(Decoder&);
     };
@@ -419,6 +430,10 @@
 void Device::FrameData::LayerData::encode(Encoder& encoder) const
 {
     encoder << opaqueTexture;
+#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
+    WTF::MachSendRight surfaceSendRight = surface ? surface->createSendRight() : WTF::MachSendRight();
+    encoder << surfaceSendRight;
+#endif
 }
 
 template<class Decoder>
@@ -427,6 +442,12 @@
     PlatformXR::Device::FrameData::LayerData layerData;
     if (!decoder.decode(layerData.opaqueTexture))
         return WTF::nullopt;
+#if USE(IOSURFACE_FOR_XR_LAYER_DATA)
+    WTF::MachSendRight surfaceSendRight;
+    if (!decoder.decode(surfaceSendRight))
+        return WTF::nullopt;
+    layerData.surface = WebCore::IOSurface::createFromSendRight(WTFMove(surfaceSendRight), WebCore::sRGBColorSpaceRef());
+#endif
     return layerData;
 }
 
@@ -469,9 +490,25 @@
         return WTF::nullopt;
     if (!decoder.decode(frameData.layers))
         return WTF::nullopt;
+
     return frameData;
 }
 
+inline Device::FrameData Device::FrameData::copy() const
+{
+    PlatformXR::Device::FrameData frameData;
+    frameData.isTrackingValid = isTrackingValid;
+    frameData.isPositionValid = isPositionValid;
+    frameData.isPositionEmulated = isPositionEmulated;
+    frameData.shouldRender = shouldRender;
+    frameData.predictedDisplayTime = predictedDisplayTime;
+    frameData.origin = origin;
+    frameData.floorTransform = floorTransform;
+    frameData.stageParameters = stageParameters;
+    frameData.views = views;
+    return frameData;
+}
+
 #endif // ENABLE(WEBXR)
 
 } // namespace PlatformXR

Modified: trunk/Source/WebCore/testing/WebFakeXRDevice.cpp (277098 => 277099)


--- trunk/Source/WebCore/testing/WebFakeXRDevice.cpp	2021-05-06 16:57:12 UTC (rev 277098)
+++ trunk/Source/WebCore/testing/WebFakeXRDevice.cpp	2021-05-06 17:05:23 UTC (rev 277099)
@@ -141,7 +141,7 @@
 
 void SimulatedXRDevice::frameTimerFired()
 {
-    FrameData data = ""
+    FrameData data = ""
     data.shouldRender = true;
 
     for (auto& layer : m_layers)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to