Changeset 252178 in webkit


Ignore:
Timestamp:
Nov 7, 2019 12:06:07 AM (4 years ago)
Author:
svillar@igalia.com
Message:

VRDisplay should not prevent entering the back/forward cache
https://bugs.webkit.org/show_bug.cgi?id=203105

Reviewed by Chris Dumez.

VRDisplay schedules asynchronous execution of events using the WindowEventLoop instead of
synchronously firing them. WindowEventLoop does correctly suspend while in cache.

Apart from that suspend()/resume() were implemented by forcing m_scriptedAnimationController
to suspend the VR request animation frame machinery while in cache.

Last but not least, stopPresenting() is now also called on suspension.

No new tests were added as there is no testing machinery for WebVR so far. It's unclear how
this unreleased feature will evolve as it's being replaced by WebXR.

  • Modules/webvr/VRDisplay.cpp:

(WebCore::VRDisplay::dispatchVRDisplayEventInWindowEventLoop):
(WebCore::VRDisplay::platformDisplayConnected): Use dispatchVRDisplayEventInWindowEventLoop.
(WebCore::VRDisplay::platformDisplayDisconnected): Ditto.
(WebCore::VRDisplay::platformDisplayMounted): Ditto.
(WebCore::VRDisplay::platformDisplayUnmounted): Ditto.
(WebCore::VRDisplay::suspend): Added.
(WebCore::VRDisplay::resume): Added.
(WebCore::VRDisplay::stop): Call stopPresenting().
(WebCore::VRDisplay::shouldPreventEnteringBackForwardCache_DEPRECATED const): Deleted.

  • Modules/webvr/VRDisplay.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252176 r252178  
     12019-11-05  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        VRDisplay should not prevent entering the back/forward cache
     4        https://bugs.webkit.org/show_bug.cgi?id=203105
     5
     6        Reviewed by Chris Dumez.
     7
     8        VRDisplay schedules asynchronous execution of events using the WindowEventLoop instead of
     9        synchronously firing them. WindowEventLoop does correctly suspend while in cache.
     10
     11        Apart from that suspend()/resume() were implemented by forcing m_scriptedAnimationController
     12        to suspend the VR request animation frame machinery while in cache.
     13
     14        Last but not least, stopPresenting() is now also called on suspension.
     15
     16        No new tests were added as there is no testing machinery for WebVR so far. It's unclear how
     17        this unreleased feature will evolve as it's being replaced by WebXR.
     18
     19        * Modules/webvr/VRDisplay.cpp:
     20        (WebCore::VRDisplay::dispatchVRDisplayEventInWindowEventLoop):
     21        (WebCore::VRDisplay::platformDisplayConnected): Use dispatchVRDisplayEventInWindowEventLoop.
     22        (WebCore::VRDisplay::platformDisplayDisconnected): Ditto.
     23        (WebCore::VRDisplay::platformDisplayMounted): Ditto.
     24        (WebCore::VRDisplay::platformDisplayUnmounted): Ditto.
     25        (WebCore::VRDisplay::suspend): Added.
     26        (WebCore::VRDisplay::resume): Added.
     27        (WebCore::VRDisplay::stop): Call stopPresenting().
     28        (WebCore::VRDisplay::shouldPreventEnteringBackForwardCache_DEPRECATED const): Deleted.
     29        * Modules/webvr/VRDisplay.h:
     30
    1312019-11-06  Devin Rousso  <drousso@apple.com>
    232
  • trunk/Source/WebCore/Modules/webvr/VRDisplay.cpp

    r251244 r252178  
    4444#include "VRPose.h"
    4545#include "VRStageParameters.h"
     46#include "WindowEventLoop.h"
    4647#include <wtf/IsoMallocInlines.h>
    4748
     
    210211}
    211212
     213// Use a EventLoop instead of dispatching events synchronously because the
     214// EventLoop correctly suspends when in the cache. This way VRDisplay does no
     215// longer prevent caching in the back/forward cache.
     216void VRDisplay::dispatchVRDisplayEventInEventLoop(const AtomString& eventName, Optional<VRDisplayEventReason>&& reason)
     217{
     218    auto event = VRDisplayEvent::create(eventName, makeRefPtr(this), WTFMove(reason));
     219    queueTaskKeepingObjectAlive(*this, TaskSource::UserInteraction, [this, event = WTFMove(event)]() mutable {
     220        if (!document())
     221            return;
     222        if (auto* window = document()->domWindow())
     223            window->dispatchEvent(event);
     224    });
     225}
     226
    212227void VRDisplay::platformDisplayConnected()
    213228{
    214     document()->domWindow()->dispatchEvent(VRDisplayEvent::create(eventNames().vrdisplayconnectEvent, makeRefPtr(this), WTF::nullopt));
     229    dispatchVRDisplayEventInEventLoop(eventNames().vrdisplayconnectEvent, WTF::nullopt);
    215230}
    216231
    217232void VRDisplay::platformDisplayDisconnected()
    218233{
    219     document()->domWindow()->dispatchEvent(VRDisplayEvent::create(eventNames().vrdisplaydisconnectEvent, makeRefPtr(this), WTF::nullopt));
     234    dispatchVRDisplayEventInEventLoop(eventNames().vrdisplaydisconnectEvent, WTF::nullopt);
    220235}
    221236
    222237void VRDisplay::platformDisplayMounted()
    223238{
    224     document()->domWindow()->dispatchEvent(VRDisplayEvent::create(eventNames().vrdisplayactivateEvent, makeRefPtr(this), VRDisplayEventReason::Mounted));
     239    dispatchVRDisplayEventInEventLoop(eventNames().vrdisplayactivateEvent, VRDisplayEventReason::Mounted);
    225240}
    226241
    227242void VRDisplay::platformDisplayUnmounted()
    228243{
    229     document()->domWindow()->dispatchEvent(VRDisplayEvent::create(eventNames().vrdisplaydeactivateEvent, makeRefPtr(this), VRDisplayEventReason::Unmounted));
     244    dispatchVRDisplayEventInEventLoop(eventNames().vrdisplaydeactivateEvent, VRDisplayEventReason::Unmounted);
    230245}
    231246
     
    240255}
    241256
    242 // FIXME: This should never prevent entering the back/forward cache.
    243 bool VRDisplay::shouldPreventEnteringBackForwardCache_DEPRECATED() const
    244 {
    245     return true;
     257void VRDisplay::suspend(ReasonForSuspension reason)
     258{
     259    if (m_scriptedAnimationController)
     260        m_scriptedAnimationController->suspend();
     261    if (reason == ReasonForSuspension::BackForwardCache)
     262        stopPresenting();
     263}
     264
     265void VRDisplay::resume()
     266{
     267    if (m_scriptedAnimationController)
     268        m_scriptedAnimationController->resume();
    246269}
    247270
    248271void VRDisplay::stop()
    249272{
     273    m_scriptedAnimationController = nullptr;
     274    stopPresenting();
    250275}
    251276
  • trunk/Source/WebCore/Modules/webvr/VRDisplay.h

    r251244 r252178  
    2828#include "ActiveDOMObject.h"
    2929#include "EventTarget.h"
     30#include "VRDisplayEventReason.h"
    3031#include "VREye.h"
    3132#include "VRLayerInit.h"
    3233#include "VRPlatformDisplayClient.h"
     34#include <wtf/Optional.h>
    3335#include <wtf/RefCounted.h>
    3436
     
    107109    // ActiveDOMObject
    108110    const char* activeDOMObjectName() const override;
    109     bool shouldPreventEnteringBackForwardCache_DEPRECATED() const override;
     111    void suspend(ReasonForSuspension) override;
     112    void resume() override;
    110113    void stop() override;
    111114
     
    113116
    114117    Document* document() { return downcast<Document>(scriptExecutionContext()); }
     118
     119    void dispatchVRDisplayEventInEventLoop(const AtomString& eventName, Optional<VRDisplayEventReason>&&);
    115120
    116121    WeakPtr<VRPlatformDisplay> m_display;
Note: See TracChangeset for help on using the changeset viewer.