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
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1305,32 +1305,56 @@ MediaDecoder::NotifyCompositor()
}
}
void
MediaDecoder::SetElementVisibility(bool aIsVisible)
{
MOZ_ASSERT(NS_IsMainThread());
mElementVisible = aIsVisible;
- mIsVisible = !mForcedHidden && mElementVisible;
+ UpdateVideoDecodeMode();
}
void
MediaDecoder::SetForcedHidden(bool aForcedHidden)
{
MOZ_ASSERT(NS_IsMainThread());
mForcedHidden = aForcedHidden;
- SetElementVisibility(mElementVisible);
+ UpdateVideoDecodeMode();
}
void
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
MediaDecoder::HasSuspendTaint() const
{
MOZ_ASSERT(NS_IsMainThread());
return mHasSuspendTaint;
}
@@ -1499,16 +1523,17 @@ MediaDecoder::DisconnectMirrors()
void
MediaDecoder::SetStateMachine(MediaDecoderStateMachine* aStateMachine)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT_IF(aStateMachine, !mDecoderStateMachine);
mDecoderStateMachine = aStateMachine;
if (aStateMachine) {
ConnectMirrors(aStateMachine);
+ UpdateVideoDecodeMode();
} else {
DisconnectMirrors();
}
}
ImageContainer*
MediaDecoder::GetImageContainer()
{
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -378,16 +378,18 @@ private:
void SetForcedHidden(bool aForcedHidden);
// Mark the decoder as tainted, meaning suspend-video-decoder is disabled.
void SetSuspendTaint(bool aTaint);
// 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.
******/
// Change to a new play state. This updates the mState variable and
// notifies any thread blocking on this object's monitor of the
// change. Call on the main thread only.