Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1038)

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioListener.cpp

Issue 2012773005: Simplify notification of a dirty listener. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/AudioListener.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioListener.cpp b/third_party/WebKit/Source/modules/webaudio/AudioListener.cpp
index 6b09f3775aa86f43d38fc5af5f3c0b1153a862dd..5badcca371b220e0078916a509d058b47163e5d0 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioListener.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioListener.cpp
@@ -47,6 +47,7 @@ AudioListener::AudioListener(AbstractAudioContext& context)
, m_dopplerFactor(1)
, m_speedOfSound(343.3)
, m_lastUpdateTime(-1)
+ , m_isListenerDirty(false)
, m_positionXValues(AudioUtilities::kRenderQuantumFrames)
, m_positionYValues(AudioUtilities::kRenderQuantumFrames)
, m_positionZValues(AudioUtilities::kRenderQuantumFrames)
@@ -200,25 +201,31 @@ const float* AudioListener::getUpZValues(size_t framesToProcess)
void AudioListener::updateState()
{
- FloatPoint3D currentPosition = position();
- FloatPoint3D currentForward = orientation();
- FloatPoint3D currentUp = upVector();
-
- bool hasMoved = currentPosition != m_lastPosition
- || currentForward != m_lastForward
- || currentUp != m_lastUp;
-
- if (hasMoved) {
- m_lastPosition = currentPosition;
- m_lastForward = currentForward;
- m_lastUp = currentUp;
-
- markPannersAsDirty(PannerHandler::AzimuthElevationDirty | PannerHandler::DistanceConeGainDirty);
+ // This must be called from the audio thread in pre or post render phase of
+ // the graph processing. (AudioListener doesn't have access to the context
+ // to check for the audio thread.)
+ DCHECK(!isMainThread());
+
+ MutexTryLocker tryLocker(m_listenerLock);
+ if (tryLocker.locked()) {
+ FloatPoint3D currentPosition = position();
+ FloatPoint3D currentForward = orientation();
+ FloatPoint3D currentUp = upVector();
+
+ m_isListenerDirty = currentPosition != m_lastPosition
+ || currentForward != m_lastForward
+ || currentUp != m_lastUp;
+
+ if (m_isListenerDirty) {
+ m_lastPosition = currentPosition;
+ m_lastForward = currentForward;
+ m_lastUp = currentUp;
+ }
} else {
- // Tell each panner to check its dirty state in case the panner position/orientation
- // changed.
- for (PannerHandler* panner : m_panners)
- panner->updateDirtyState();
+ // Main thread must be updating the position, forward, or up vector;
+ // just assume the listener is dirty. At worst, we'll do a little more
+ // work than necessary for one rendering quantum.
+ m_isListenerDirty = true;
}
}
@@ -241,12 +248,15 @@ void AudioListener::waitForHRTFDatabaseLoaderThreadCompletion()
void AudioListener::markPannersAsDirty(unsigned type)
{
+ DCHECK(isMainThread());
for (PannerHandler* panner : m_panners)
panner->markPannerAsDirty(type);
}
void AudioListener::setPosition(const FloatPoint3D& position)
{
+ DCHECK(isMainThread());
+
// This synchronizes with panner's process().
MutexLocker listenerLocker(m_listenerLock);
m_positionX->setValue(position.x());
@@ -257,6 +267,8 @@ void AudioListener::setPosition(const FloatPoint3D& position)
void AudioListener::setOrientation(const FloatPoint3D& orientation)
{
+ DCHECK(isMainThread());
+
// This synchronizes with panner's process().
MutexLocker listenerLocker(m_listenerLock);
m_forwardX->setValue(orientation.x());
@@ -267,6 +279,8 @@ void AudioListener::setOrientation(const FloatPoint3D& orientation)
void AudioListener::setUpVector(const FloatPoint3D& upVector)
{
+ DCHECK(isMainThread());
+
// This synchronizes with panner's process().
MutexLocker listenerLocker(m_listenerLock);
m_upX->setValue(upVector.x());
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/AudioListener.h ('k') | third_party/WebKit/Source/modules/webaudio/PannerNode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698