From c2f38bd02dfe89b307d9b3ac6ca52d1ca27c4376 Mon Sep 17 00:00:00 2001 From: Kaku Kuo Date: Fri, 10 Mar 2017 16:52:03 +0800 Subject: [PATCH] Bug 1346498 part 3 - implement the UpdateVideoDecodeMode() policy in MediaDecoder; r=jwwang So, the MediaDecoder is the one who rules out the policy of suspending video decoder. We also extract all the policy rules into one single method, MediaDecoder::UpdateVideoDecodeMode(). MozReview-Commit-ID: IOQq6kFfkIs --HG-- extra : rebase_source : 3d92c63aed2545391c45cdd7c1236d5df0b8d2f8 extra : source : 9c6c5f22d25171a206e828faa2c7c91d47f748f1 --- dom/media/MediaDecoder.cpp | 29 +++++++++++++++++++++++++++-- dom/media/MediaDecoder.h | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index 7c8d8609a264..e39ad5f7e0bc 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -1310,7 +1310,7 @@ MediaDecoder::SetElementVisibility(bool aIsVisible) { MOZ_ASSERT(NS_IsMainThread()); mElementVisible = aIsVisible; - mIsVisible = !mForcedHidden && mElementVisible; + UpdateVideoDecodeMode(); } void @@ -1318,7 +1318,7 @@ MediaDecoder::SetForcedHidden(bool aForcedHidden) { MOZ_ASSERT(NS_IsMainThread()); mForcedHidden = aForcedHidden; - SetElementVisibility(mElementVisible); + UpdateVideoDecodeMode(); } void @@ -1326,6 +1326,30 @@ MediaDecoder::SetSuspendTaint(bool aTainted) { MOZ_ASSERT(NS_IsMainThread()); mHasSuspendTaint = aTainted; + UpdateVideoDecodeMode(); +} + +void +MediaDecoder::UpdateVideoDecodeMode() +{ + // The MDSM may yet be set. + if (!mDecoderStateMachine) { + return; + } + + // If mHasSuspendTaint is set, never suspend the video decoder. + if (mHasSuspendTaint) { + mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Normal); + return; + } + + // If mForcedHidden is set, suspend the video decoder anyway. + // Otherwise, depends on the owner's visibility state. + if (!mForcedHidden && mElementVisible) { + mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Normal); + } else { + mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Suspend); + } } bool @@ -1504,6 +1528,7 @@ MediaDecoder::SetStateMachine(MediaDecoderStateMachine* aStateMachine) mDecoderStateMachine = aStateMachine; if (aStateMachine) { ConnectMirrors(aStateMachine); + UpdateVideoDecodeMode(); } else { DisconnectMirrors(); } diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index a30c2f8c5ea1..b6fd4203a8a6 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -383,6 +383,8 @@ private: // Returns true if the decoder can't participate in suspend-video-decoder. bool HasSuspendTaint() const; + void UpdateVideoDecodeMode(); + /****** * The following methods must only be called on the main * thread.