Changeset 278288 in webkit
- Timestamp:
- May 31, 2021, 5:08:20 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
-
ChangeLog (modified) (1 diff)
-
Modules/webaudio/AudioContext.cpp (modified) (6 diffs)
-
Modules/webaudio/AudioContext.h (modified) (1 diff)
-
Modules/webaudio/BaseAudioContext.cpp (modified) (2 diffs)
-
Modules/webaudio/BaseAudioContext.h (modified) (2 diffs)
-
Modules/webaudio/OfflineAudioContext.cpp (modified) (5 diffs)
-
Modules/webaudio/OfflineAudioContext.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r278287 r278288 1 2021-05-31 Chris Dumez <cdumez@apple.com> 2 3 Drop PendingActivity data member from BaseAudioContext 4 https://bugs.webkit.org/show_bug.cgi?id=226445 5 6 Reviewed by Darin Adler. 7 8 Drop PendingActivity data member from BaseAudioContext and instead have AudioContext / OfflineAudioContext 9 override virtualHasPendingActivity() to keep their JS wrapper alive. I find that PendingActivity data members 10 are too error prone and a frequent cause of leaks. 11 12 * Modules/webaudio/AudioContext.cpp: 13 (WebCore::AudioContext::AudioContext): 14 (WebCore::AudioContext::startRendering): 15 (WebCore::AudioContext::mayResumePlayback): 16 (WebCore::AudioContext::suspendPlayback): 17 (WebCore::AudioContext::virtualHasPendingActivity const): 18 * Modules/webaudio/AudioContext.h: 19 * Modules/webaudio/BaseAudioContext.cpp: 20 (WebCore::BaseAudioContext::clear): 21 (WebCore::BaseAudioContext::clearPendingActivity): Deleted. 22 (WebCore::BaseAudioContext::setPendingActivity): Deleted. 23 * Modules/webaudio/BaseAudioContext.h: 24 * Modules/webaudio/OfflineAudioContext.cpp: 25 (WebCore::OfflineAudioContext::startRendering): 26 (WebCore::OfflineAudioContext::resumeRendering): 27 (WebCore::OfflineAudioContext::didSuspendRendering): 28 (WebCore::OfflineAudioContext::finishedRendering): 29 (WebCore::OfflineAudioContext::virtualHasPendingActivity const): 30 (WebCore::OfflineAudioContext::dispatchEvent): Deleted. 31 * Modules/webaudio/OfflineAudioContext.h: 32 1 33 2021-05-31 Chris Dumez <cdumez@apple.com> 2 34 -
trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp
r278253 r278288 116 116 , m_mediaSession(PlatformMediaSession::create(PlatformMediaSessionManager::sharedManager(), *this)) 117 117 { 118 // According to spec AudioContext must die only after page navigate.119 // Lets mark it as ActiveDOMObject with pending activity and unmark it in clear method.120 setPendingActivity();121 122 118 constructCommon(); 123 119 … … 131 127 // Lazy initialization starts rendering so we schedule a task here to make sure lazy initialization 132 128 // ends up happening, even if no audio node gets constructed. 133 postTask([this ] {129 postTask([this, pendingActivity = makePendingActivity(*this)] { 134 130 if (!isStopped()) 135 131 lazyInitialize(); … … 310 306 return; 311 307 312 setPendingActivity(); 313 314 lazyInitialize(); 315 destination().startRendering([this, protectedThis = makeRef(*this)](std::optional<Exception>&& exception) { 308 lazyInitialize(); 309 destination().startRendering([this, protectedThis = makeRef(*this), pendingActivity = makePendingActivity(*this)](std::optional<Exception>&& exception) { 316 310 if (!exception) 317 311 setState(State::Running); … … 386 380 lazyInitialize(); 387 381 388 destination().resume([this, protectedThis = makeRef(*this) ](std::optional<Exception>&& exception) {382 destination().resume([this, protectedThis = makeRef(*this), pendingActivity = makePendingActivity(*this)](std::optional<Exception>&& exception) { 389 383 setState(exception ? State::Suspended : State::Running); 390 384 }); … … 472 466 lazyInitialize(); 473 467 474 destination().suspend([this, protectedThis = makeRef(*this) ](std::optional<Exception>&& exception) {468 destination().suspend([this, protectedThis = makeRef(*this), pendingActivity = makePendingActivity(*this)](std::optional<Exception>&& exception) { 475 469 if (exception) 476 470 return; … … 556 550 #endif 557 551 552 bool AudioContext::virtualHasPendingActivity() const 553 { 554 return !isClosed(); 555 } 556 558 557 } // namespace WebCore 559 558 -
trunk/Source/WebCore/Modules/webaudio/AudioContext.h
r278264 r278288 143 143 void suspend(ReasonForSuspension) final; 144 144 void resume() final; 145 bool virtualHasPendingActivity() const final; 145 146 146 147 UniqueRef<DefaultAudioDestinationNode> m_destinationNode; -
trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp
r278264 r278288 180 180 m_nodesToDelete = std::exchange(m_nodesMarkedForDeletion, { }); 181 181 } while (!m_nodesToDelete.isEmpty()); 182 183 clearPendingActivity();184 182 } 185 183 … … 878 876 } 879 877 880 void BaseAudioContext::clearPendingActivity()881 {882 m_pendingActivity = nullptr;883 }884 885 void BaseAudioContext::setPendingActivity()886 {887 if (!m_pendingActivity)888 m_pendingActivity = makePendingActivity(*this);889 }890 891 878 PeriodicWave& BaseAudioContext::periodicWave(OscillatorType type) 892 879 { -
trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h
r278264 r278288 228 228 protected: 229 229 explicit BaseAudioContext(Document&); 230 231 void clearPendingActivity();232 void setPendingActivity();233 230 234 231 virtual void uninitialize(); … … 347 344 std::unique_ptr<AsyncAudioDecoder> m_audioDecoder; 348 345 349 RefPtr<PendingActivity<BaseAudioContext>> m_pendingActivity;350 351 346 AudioIOPosition m_outputPosition; 352 347 -
trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp
r278253 r278288 114 114 } 115 115 116 setPendingActivity();117 116 m_pendingRenderingPromise = WTFMove(promise); 118 117 m_didStartRendering = true; … … 176 175 } 177 176 178 setPendingActivity();179 177 setState(State::Running); 180 178 promise->resolve(); … … 196 194 setState(State::Suspended); 197 195 198 clearPendingActivity();199 200 196 RefPtr<DeferredPromise> promise; 201 197 { … … 218 214 }); 219 215 216 // Make sure our JSwrapper stays alive long enough to resolve the promise and queue the completion event. 217 // Otherwise, setting the state to Closed may cause our JS wrapper to get collected early. 218 auto protectedJSWrapper = makePendingActivity(*this); 220 219 setState(State::Closed); 221 220 … … 247 246 } 248 247 249 void OfflineAudioContext::dispatchEvent(Event& event) 250 { 251 BaseAudioContext::dispatchEvent(event); 252 if (event.eventInterface() == OfflineAudioCompletionEventInterfaceType) 253 clearPendingActivity(); 248 bool OfflineAudioContext::virtualHasPendingActivity() const 249 { 250 return state() == State::Running; 254 251 } 255 252 -
trunk/Source/WebCore/Modules/webaudio/OfflineAudioContext.h
r277858 r278288 61 61 // ActiveDOMObject 62 62 const char* activeDOMObjectName() const final; 63 64 // EventTarget 65 void dispatchEvent(Event&) final; 63 bool virtualHasPendingActivity() const final; 66 64 67 65 void settleRenderingPromise(ExceptionOr<Ref<AudioBuffer>>&&);
Note:
See TracChangeset
for help on using the changeset viewer.