| Differences between
and this patch
- a/Source/WebCore/ChangeLog +42 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2020-07-02  Sergio Villar Senin  <svillar@igalia.com>
2
3
        [WebXR] Retrieve WebGL framebuffer resolution from XR devices
4
        https://bugs.webkit.org/show_bug.cgi?id=213886
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        The recommended WebGL framebuffer resolution should be retrieved from the actual XR device being used.
9
        Implemented the OpenXR machinery to retrieve it from the XR system. We are also moving the methods that
10
        call the platform code to the XRSession as specs define, instead of having them inside the XRWebGLLayer.
11
12
        Finally this patch is also removing a unused definition in OpenXR plaform code and properly initializing
13
        a OpenXR struct. The missing initialization was the source of errors when querying api layer properties.
14
        The patch is also properly setting the SessionMode::Inline when XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO
15
        is found. It used to set SessionMode::ImmersiveAr instead, but that's wrong, we should only care about
16
        ImmersiveAr session mode once the WebXR AR module is implemented.
17
18
        * Modules/webxr/WebXRRenderState.cpp:
19
        (WebCore::WebXRRenderState::outputCanvas const): Return render state's canvas.
20
        * Modules/webxr/WebXRRenderState.h: Added a m_outputCanvas member with its getter.
21
        * Modules/webxr/WebXRSession.cpp:
22
        (WebCore::WebXRSession::nativeWebGLFramebufferResolution const): Moved from WebXRWebGLLayer and reimplemented.
23
        (WebCore::WebXRSession::recommendedWebGLFramebufferResolution const): Ditto.
24
        * Modules/webxr/WebXRSession.h:
25
        * Modules/webxr/WebXRWebGLLayer.cpp:
26
        (WebCore::WebXRWebGLLayer::WebXRWebGLLayer):
27
        (WebCore::WebXRWebGLLayer::getNativeFramebufferScaleFactor): Call the session to get native and recommended
28
        resolutions.
29
        (WebCore::WebXRWebGLLayer::computeNativeWebGLFramebufferResolution): Deleted.
30
        (WebCore::WebXRWebGLLayer::computeRecommendedWebGLFramebufferResolution): Ditto.
31
        * platform/xr/PlatformXR.h:
32
        (PlatformXR::Device::recommendedResolution): New virtual method with default implementation.
33
        * platform/xr/openxr/PlatformXROpenXR.cpp:
34
        (PlatformXR::Instance::Impl::enumerateApiLayerProperties const): Added initialization of the XrApiLayerProperties
35
        objects. The call to xrEnumerateApiLayerProperties succeeds now.
36
        (PlatformXR::OpenXRDevice::OpenXRDevice): Call enumerateConfigurationViews().
37
        (PlatformXR::OpenXRDevice::collectSupportedSessionModes): Fill in the m_viewConfigurationProperties map.
38
        (PlatformXR::OpenXRDevice::enumerateConfigurationViews): New method that retrieves the XR device views for each
39
        supported configuration.
40
        (PlatformXR::OpenXRDevice::recommendedResolution): Return the recommended resolution for a given SessionMode.
41
        * platform/xr/openxr/PlatformXROpenXR.h: Added some new methods and attributes.
42
1
2020-07-02  Zalan Bujtas  <zalan@apple.com>
43
2020-07-02  Zalan Bujtas  <zalan@apple.com>
2
44
3
        [LFC][BFC] Remove redundant margin-border-padding when computing the intrinsic width
45
        [LFC][BFC] Remove redundant margin-border-padding when computing the intrinsic width
- a/Source/WebCore/Modules/webxr/WebXRRenderState.cpp +6 lines
Lines 28-33 a/Source/WebCore/Modules/webxr/WebXRRenderState.cpp_sec1
28
28
29
#if ENABLE(WEBXR)
29
#if ENABLE(WEBXR)
30
30
31
#include "HTMLCanvasElement.h"
31
#include "WebXRWebGLLayer.h"
32
#include "WebXRWebGLLayer.h"
32
#include "XRRenderStateInit.h"
33
#include "XRRenderStateInit.h"
33
#include <wtf/IsoMallocInlines.h>
34
#include <wtf/IsoMallocInlines.h>
Lines 75-80 RefPtr<WebXRWebGLLayer> WebXRRenderState::baseLayer() const a/Source/WebCore/Modules/webxr/WebXRRenderState.cpp_sec2
75
    return m_baseLayer;
76
    return m_baseLayer;
76
}
77
}
77
78
79
HTMLCanvasElement* WebXRRenderState::outputCanvas() const
80
{
81
    return m_outputCanvas.get();
82
}
83
78
} // namespace WebCore
84
} // namespace WebCore
79
85
80
#endif // ENABLE(WEBXR)
86
#endif // ENABLE(WEBXR)
- a/Source/WebCore/Modules/webxr/WebXRRenderState.h +4 lines
Lines 33-41 a/Source/WebCore/Modules/webxr/WebXRRenderState.h_sec1
33
#include <wtf/Ref.h>
33
#include <wtf/Ref.h>
34
#include <wtf/RefCounted.h>
34
#include <wtf/RefCounted.h>
35
#include <wtf/RefPtr.h>
35
#include <wtf/RefPtr.h>
36
#include <wtf/WeakPtr.h>
36
37
37
namespace WebCore {
38
namespace WebCore {
38
39
40
class HTMLCanvasElement;
39
class WebXRWebGLLayer;
41
class WebXRWebGLLayer;
40
struct XRRenderStateInit;
42
struct XRRenderStateInit;
41
43
Lines 49-54 public: a/Source/WebCore/Modules/webxr/WebXRRenderState.h_sec2
49
    double depthFar() const;
51
    double depthFar() const;
50
    Optional<double> inlineVerticalFieldOfView() const;
52
    Optional<double> inlineVerticalFieldOfView() const;
51
    RefPtr<WebXRWebGLLayer> baseLayer() const;
53
    RefPtr<WebXRWebGLLayer> baseLayer() const;
54
    HTMLCanvasElement* outputCanvas() const;
52
55
53
private:
56
private:
54
    explicit WebXRRenderState(Optional<double>&& fieldOfView);
57
    explicit WebXRRenderState(Optional<double>&& fieldOfView);
Lines 61-66 private: a/Source/WebCore/Modules/webxr/WebXRRenderState.h_sec3
61
    } m_depth;
64
    } m_depth;
62
    Optional<double> m_inlineVerticalFieldOfView; // in radians
65
    Optional<double> m_inlineVerticalFieldOfView; // in radians
63
    RefPtr<WebXRWebGLLayer> m_baseLayer;
66
    RefPtr<WebXRWebGLLayer> m_baseLayer;
67
    WeakPtr<HTMLCanvasElement> m_outputCanvas;
64
};
68
};
65
69
66
} // namespace WebCore
70
} // namespace WebCore
- a/Source/WebCore/Modules/webxr/WebXRSession.cpp +18 lines
Lines 238-243 void WebXRSession::cancelAnimationFrame(unsigned callbackId) a/Source/WebCore/Modules/webxr/WebXRSession.cpp_sec1
238
        m_runningCallbacks[position]->cancel();
238
        m_runningCallbacks[position]->cancel();
239
}
239
}
240
240
241
// https://immersive-web.github.io/webxr/#native-webgl-framebuffer-resolution
242
IntSize WebXRSession::nativeWebGLFramebufferResolution() const
243
{
244
    if (m_mode == XRSessionMode::Inline) {
245
        // FIXME: replace the conditional by ASSERTs once we properly initialize the outputCanvas.
246
        return m_activeRenderState && m_activeRenderState->outputCanvas() ? m_activeRenderState->outputCanvas()->size() : IntSize(1, 1);
247
    }
248
249
    return recommendedWebGLFramebufferResolution();
250
}
251
252
// https://immersive-web.github.io/webxr/#recommended-webgl-framebuffer-resolution
253
IntSize WebXRSession::recommendedWebGLFramebufferResolution() const
254
{
255
    ASSERT(m_device);
256
    return m_device->recommendedResolution(m_mode);
257
}
258
241
// https://immersive-web.github.io/webxr/#shut-down-the-session
259
// https://immersive-web.github.io/webxr/#shut-down-the-session
242
void WebXRSession::shutdown()
260
void WebXRSession::shutdown()
243
{
261
{
- a/Source/WebCore/Modules/webxr/WebXRSession.h -1 / +3 lines
Lines 76-86 public: a/Source/WebCore/Modules/webxr/WebXRSession.h_sec1
76
    unsigned requestAnimationFrame(Ref<XRFrameRequestCallback>&&);
76
    unsigned requestAnimationFrame(Ref<XRFrameRequestCallback>&&);
77
    void cancelAnimationFrame(unsigned callbackId);
77
    void cancelAnimationFrame(unsigned callbackId);
78
78
79
    IntSize nativeWebGLFramebufferResolution() const;
80
    IntSize recommendedWebGLFramebufferResolution() const;
81
79
    // EventTarget.
82
    // EventTarget.
80
    ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
83
    ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
81
84
82
    void end(EndPromise&&);
85
    void end(EndPromise&&);
83
84
    bool ended() const { return m_ended; }
86
    bool ended() const { return m_ended; }
85
87
86
    XRSessionMode mode() const { return m_mode; }
88
    XRSessionMode mode() const { return m_mode; }
- a/Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp -16 / +3 lines
Lines 91-109 ExceptionOr<Ref<WebXRWebGLLayer>> WebXRWebGLLayer::create(Ref<WebXRSession>&& se a/Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp_sec1
91
    );
91
    );
92
}
92
}
93
93
94
// https://immersive-web.github.io/webxr/#native-webgl-framebuffer-resolution
95
IntSize WebXRWebGLLayer::computeNativeWebGLFramebufferResolution()
96
{
97
    // FIXME: implement this
98
    return { 1, 1 };
99
}
100
101
// https://immersive-web.github.io/webxr/#recommended-webgl-framebuffer-resolution
102
IntSize WebXRWebGLLayer::computeRecommendedWebGLFramebufferResolution()
103
{
104
    return computeNativeWebGLFramebufferResolution();
105
}
106
107
WebXRWebGLLayer::WebXRWebGLLayer(Ref<WebXRSession>&& session, WebXRRenderingContext&& context, const XRWebGLLayerInit& init)
94
WebXRWebGLLayer::WebXRWebGLLayer(Ref<WebXRSession>&& session, WebXRRenderingContext&& context, const XRWebGLLayerInit& init)
108
    : WebXRLayer(session->scriptExecutionContext())
95
    : WebXRLayer(session->scriptExecutionContext())
109
    , m_session(WTFMove(session))
96
    , m_session(WTFMove(session))
Lines 127-133 WebXRWebGLLayer::WebXRWebGLLayer(Ref<WebXRSession>&& session, WebXRRenderingCont a/Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp_sec2
127
        m_antialias = init.antialias;
114
        m_antialias = init.antialias;
128
115
129
        //  2. Let framebufferSize be the recommended WebGL framebuffer resolution multiplied by layerInit's framebufferScaleFactor.
116
        //  2. Let framebufferSize be the recommended WebGL framebuffer resolution multiplied by layerInit's framebufferScaleFactor.
130
        IntSize recommendedSize = computeRecommendedWebGLFramebufferResolution();
117
        IntSize recommendedSize = m_session->recommendedWebGLFramebufferResolution();
131
        m_framebuffer.width = recommendedSize.width() * init.framebufferScaleFactor;
118
        m_framebuffer.width = recommendedSize.width() * init.framebufferScaleFactor;
132
        m_framebuffer.height = recommendedSize.height() * init.framebufferScaleFactor;
119
        m_framebuffer.height = recommendedSize.height() * init.framebufferScaleFactor;
133
120
Lines 204-211 double WebXRWebGLLayer::getNativeFramebufferScaleFactor(const WebXRSession& sess a/Source/WebCore/Modules/webxr/WebXRWebGLLayer.cpp_sec3
204
    if (session.ended())
191
    if (session.ended())
205
        return 0.0;
192
        return 0.0;
206
193
207
    IntSize nativeSize = computeNativeWebGLFramebufferResolution();
194
    IntSize nativeSize = session.nativeWebGLFramebufferResolution();
208
    IntSize recommendedSize = computeRecommendedWebGLFramebufferResolution();
195
    IntSize recommendedSize = session.recommendedWebGLFramebufferResolution();
209
196
210
    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!recommendedSize.isZero());
197
    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!recommendedSize.isZero());
211
    return (nativeSize / recommendedSize).width();
198
    return (nativeSize / recommendedSize).width();
- a/Source/WebCore/platform/xr/PlatformXR.h +3 lines
Lines 18-23 a/Source/WebCore/platform/xr/PlatformXR.h_sec1
18
 */
18
 */
19
#pragma once
19
#pragma once
20
20
21
#include "IntSize.h"
21
#include <memory>
22
#include <memory>
22
#include <wtf/HashMap.h>
23
#include <wtf/HashMap.h>
23
#include <wtf/UniqueRef.h>
24
#include <wtf/UniqueRef.h>
Lines 53-58 public: a/Source/WebCore/platform/xr/PlatformXR.h_sec2
53
    void setEnabledFeatures(SessionMode mode, const ListOfEnabledFeatures& features) { m_enabledFeaturesMap.set(mode, features); }
54
    void setEnabledFeatures(SessionMode mode, const ListOfEnabledFeatures& features) { m_enabledFeaturesMap.set(mode, features); }
54
    ListOfEnabledFeatures enabledFeatures(SessionMode mode) const { return m_enabledFeaturesMap.get(mode); }
55
    ListOfEnabledFeatures enabledFeatures(SessionMode mode) const { return m_enabledFeaturesMap.get(mode); }
55
56
57
    virtual WebCore::IntSize recommendedResolution(SessionMode) { return { 1, 1 }; }
58
56
    bool supportsOrientationTracking() const { return m_supportsOrientationTracking; }
59
    bool supportsOrientationTracking() const { return m_supportsOrientationTracking; }
57
60
58
protected:
61
protected:
- a/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp -6 / +51 lines
Lines 70-76 public: a/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp_sec1
70
    ~Impl();
70
    ~Impl();
71
71
72
#if USE_OPENXR
72
#if USE_OPENXR
73
    Optional<Vector<SessionMode>> collectSupportedSessionModes(OpenXRDevice&);
74
    XrInstance xrInstance() const { return m_instance; }
73
    XrInstance xrInstance() const { return m_instance; }
75
#endif
74
#endif
76
75
Lines 95-102 void Instance::Impl::enumerateApiLayerProperties() const a/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp_sec2
95
        return;
94
        return;
96
    }
95
    }
97
96
98
    Vector<XrApiLayerProperties> properties(propertyCountOutput);
97
    Vector<XrApiLayerProperties> properties(propertyCountOutput,
99
    result = xrEnumerateApiLayerProperties(propertyCountOutput, nullptr, properties.data());
98
        [] {
99
            XrApiLayerProperties object;
100
            std::memset(&object, 0, sizeof(XrApiLayerProperties));
101
            object.type = XR_TYPE_API_LAYER_PROPERTIES;
102
            return object;
103
        }());
104
    result = xrEnumerateApiLayerProperties(propertyCountOutput, &propertyCountOutput, properties.data());
105
100
    RETURN_IF_FAILED(result, "xrEnumerateApiLayerProperties()", m_instance);
106
    RETURN_IF_FAILED(result, "xrEnumerateApiLayerProperties()", m_instance);
101
    LOG(XR, "xrEnumerateApiLayerProperties(): %zu properties\n", properties.size());
107
    LOG(XR, "xrEnumerateApiLayerProperties(): %zu properties\n", properties.size());
102
}
108
}
Lines 213-218 OpenXRDevice::OpenXRDevice(XrSystemId id, XrInstance instance) a/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp_sec3
213
        LOG(XR, "xrGetSystemProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
219
        LOG(XR, "xrGetSystemProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
214
220
215
    collectSupportedSessionModes();
221
    collectSupportedSessionModes();
222
    enumerateConfigurationViews();
216
}
223
}
217
224
218
void OpenXRDevice::collectSupportedSessionModes()
225
void OpenXRDevice::collectSupportedSessionModes()
Lines 232-249 void OpenXRDevice::collectSupportedSessionModes() a/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.cpp_sec4
232
            LOG(XR, "xrGetViewConfigurationProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
239
            LOG(XR, "xrGetViewConfigurationProperties(): error %s\n", resultToString(result, m_instance).utf8().data());
233
            continue;
240
            continue;
234
        }
241
        }
235
        switch (viewConfigurationProperties.viewConfigurationType) {
242
        auto configType = viewConfigurationProperties.viewConfigurationType;
243
        switch (configType) {
236
        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
244
        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO:
237
            setEnabledFeatures(SessionMode::ImmersiveAr, { });
245
            setEnabledFeatures(SessionMode::Inline, { });
238
            break;
246
            break;
239
        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
247
        case XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO:
240
            setEnabledFeatures(SessionMode::ImmersiveVr, { });
248
            setEnabledFeatures(SessionMode::ImmersiveVr, { });
241
            break;
249
            break;
242
        default:
250
        default:
243
            break;
251
            continue;
244
        };
252
        };
253
        m_viewConfigurationProperties.add(configType, WTFMove(viewConfigurationProperties));
254
    }
255
}
256
257
void OpenXRDevice::enumerateConfigurationViews()
258
{
259
    for (auto& config : m_viewConfigurationProperties.values()) {
260
        uint32_t viewCount;
261
        auto configType = config.viewConfigurationType;
262
        auto result = xrEnumerateViewConfigurationViews(m_instance, m_systemId, configType, 0, &viewCount, nullptr);
263
        if (result != XR_SUCCESS) {
264
            LOG(XR, "%s %s: %s\n", __func__, "xrEnumerateViewConfigurationViews", resultToString(result, m_instance).utf8().data());
265
            continue;
266
        }
267
268
        Vector<XrViewConfigurationView> configViews(viewCount,
269
            [] {
270
                XrViewConfigurationView object;
271
                std::memset(&object, 0, sizeof(XrViewConfigurationView));
272
                object.type = XR_TYPE_VIEW_CONFIGURATION_VIEW;
273
                return object;
274
            }());
275
        result = xrEnumerateViewConfigurationViews(m_instance, m_systemId, configType, viewCount, &viewCount, configViews.data());
276
        if (result != XR_SUCCESS)
277
            continue;
278
        m_configurationViews.add(configType, WTFMove(configViews));
245
    }
279
    }
246
}
280
}
281
282
WebCore::IntSize OpenXRDevice::recommendedResolution(SessionMode mode)
283
{
284
    auto configType = mode == SessionMode::Inline ? XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO : XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
285
    auto viewsIterator = m_configurationViews.find(configType);
286
    if (viewsIterator != m_configurationViews.end())
287
        return { static_cast<int>(viewsIterator->value[0].recommendedImageRectWidth), static_cast<int>(viewsIterator->value[0].recommendedImageRectHeight) };
288
    return Device::recommendedResolution(mode);
289
}
290
291
247
#endif // USE_OPENXR
292
#endif // USE_OPENXR
248
293
249
} // namespace PlatformXR
294
} // namespace PlatformXR
- a/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h +11 lines
Lines 22-27 a/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h_sec1
22
#if ENABLE(WEBXR)
22
#if ENABLE(WEBXR)
23
#include "PlatformXR.h"
23
#include "PlatformXR.h"
24
24
25
#include <wtf/HashMap.h>
26
#include <wtf/Optional.h>
27
25
#if USE_OPENXR
28
#if USE_OPENXR
26
#include <openxr/openxr.h>
29
#include <openxr/openxr.h>
27
30
Lines 45-50 public: a/Source/WebCore/platform/xr/openxr/PlatformXROpenXR.h_sec2
45
    XrSystemId xrSystemId() const { return m_systemId; }
48
    XrSystemId xrSystemId() const { return m_systemId; }
46
private:
49
private:
47
    void collectSupportedSessionModes();
50
    void collectSupportedSessionModes();
51
    void enumerateConfigurationViews();
52
53
    WebCore::IntSize recommendedResolution(SessionMode) final;
54
55
    using ViewConfigurationPropertiesMap = HashMap<XrViewConfigurationType, XrViewConfigurationProperties, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
56
    ViewConfigurationPropertiesMap m_viewConfigurationProperties;
57
    using ViewConfigurationViewsMap = HashMap<XrViewConfigurationType, Vector<XrViewConfigurationView>, IntHash<XrViewConfigurationType>, WTF::StrongEnumHashTraits<XrViewConfigurationType>>;
58
    ViewConfigurationViewsMap m_configurationViews;
48
59
49
    XrSystemId m_systemId;
60
    XrSystemId m_systemId;
50
    XrInstance m_instance;
61
    XrInstance m_instance;

Return to Bug 213886