Title: [244771] trunk/Source/WebCore
Revision
244771
Author
[email protected]
Date
2019-04-30 08:03:38 -0700 (Tue, 30 Apr 2019)

Log Message

Refactor AudioContext to register/unregister itself at construction/destruction time
https://bugs.webkit.org/show_bug.cgi?id=197383

Reviewed by Eric Carlson.

Registering/Unregistering is cheap.
Instead of registering/unregistering in initialize/uninitialize,
move this code to constructor/destructor.
No observable change of behavior.

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::AudioContext):
(WebCore::AudioContext::~AudioContext):
(WebCore::AudioContext::lazyInitialize):
(WebCore::AudioContext::uninitialize):
(WebCore::AudioContext::visibilityStateChanged):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (244770 => 244771)


--- trunk/Source/WebCore/ChangeLog	2019-04-30 15:01:05 UTC (rev 244770)
+++ trunk/Source/WebCore/ChangeLog	2019-04-30 15:03:38 UTC (rev 244771)
@@ -1,3 +1,22 @@
+2019-04-30  Youenn Fablet  <[email protected]>
+
+        Refactor AudioContext to register/unregister itself at construction/destruction time
+        https://bugs.webkit.org/show_bug.cgi?id=197383
+
+        Reviewed by Eric Carlson.
+
+        Registering/Unregistering is cheap.
+        Instead of registering/unregistering in initialize/uninitialize,
+        move this code to constructor/destructor.
+        No observable change of behavior.
+
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::AudioContext):
+        (WebCore::AudioContext::~AudioContext):
+        (WebCore::AudioContext::lazyInitialize):
+        (WebCore::AudioContext::uninitialize):
+        (WebCore::AudioContext::visibilityStateChanged):
+
 2019-04-30  Michael Catanzaro  <[email protected]>
 
         WebCore::StyleColorScheme should not have explicitly-declared copy constructor

Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (244770 => 244771)


--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2019-04-30 15:01:05 UTC (rev 244770)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp	2019-04-30 15:03:38 UTC (rev 244771)
@@ -147,6 +147,11 @@
 
     // Initialize the destination node's muted state to match the page's current muted state.
     pageMutedStateDidChange();
+
+    if (!isOfflineContext()) {
+        document.addAudioProducer(*this);
+        document.registerForVisibilityStateChangedCallbacks(*this);
+    }
 }
 
 // Constructor for offline (non-realtime) rendering.
@@ -202,6 +207,11 @@
         m_renderingAutomaticPullNodes.resize(m_automaticPullNodes.size());
     ASSERT(m_renderingAutomaticPullNodes.isEmpty());
     // FIXME: Can we assert that m_deferredFinishDerefList is empty?
+
+    if (!isOfflineContext() && scriptExecutionContext()) {
+        document()->removeAudioProducer(*this);
+        document()->unregisterForVisibilityStateChangedCallbacks(*this);
+    }
 }
 
 void AudioContext::lazyInitialize()
@@ -218,9 +228,6 @@
         m_destinationNode->initialize();
 
         if (!isOfflineContext()) {
-            document()->addAudioProducer(*this);
-            document()->registerForVisibilityStateChangedCallbacks(*this);
-
             // This starts the audio thread. The destination node's provideInput() method will now be called repeatedly to render audio.
             // Each time provideInput() is called, a portion of the audio stream is rendered. Let's call this time period a "render quantum".
             // NOTE: for now default AudioContext does not need an explicit startRendering() call from _javascript_.
@@ -265,9 +272,6 @@
     m_isAudioThreadFinished = true;
 
     if (!isOfflineContext()) {
-        document()->removeAudioProducer(*this);
-        document()->unregisterForVisibilityStateChangedCallbacks(*this);
-
         ASSERT(s_hardwareContextCount);
         --s_hardwareContextCount;
 
@@ -378,7 +382,7 @@
 void AudioContext::visibilityStateChanged()
 {
     // Do not suspend if audio is audible.
-    if (mediaState() == MediaProducer::IsPlayingAudio)
+    if (mediaState() == MediaProducer::IsPlayingAudio || m_isStopScheduled)
         return;
 
     if (document()->hidden()) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to