Bug 1347892 part 2 - pass the visibility state of media element to media decoder as a Visibility variable; r?jwwang draft
authorKaku Kuo <kaku@mozilla.com>
Fri, 17 Mar 2017 12:51:11 +0800
changeset 501351 cea676e9ef61c598cccb9ae7f45810b76f721b41
parent 501350 86d7f562ec5ffb6a7af553040952cc60a9b14acb
child 501352 9b392812ed3df92522b09357fc50b8419d9428b3
push id49941
push userbmo:kaku@mozilla.com
push dateMon, 20 Mar 2017 02:41:09 +0000
reviewersjwwang
bugs1347892
milestone55.0a1
Bug 1347892 part 2 - pass the visibility state of media element to media decoder as a Visibility variable; r?jwwang MozReview-Commit-ID: AbkJeIpYZlN
dom/html/HTMLMediaElement.cpp
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -7404,17 +7404,17 @@ HTMLMediaElement::GetEMEInfo(nsString& a
   aEMEInfo.Append(sessionsInfo);
 }
 
 void
 HTMLMediaElement::NotifyDecoderActivityChanges() const
 {
   if (mDecoder) {
     mDecoder->NotifyOwnerActivityChanged(!IsHidden(),
-                                         mVisibilityState == Visibility::APPROXIMATELY_VISIBLE,
+                                         mVisibilityState,
                                          IsInUncomposedDoc());
   }
 }
 
 nsIDocument*
 HTMLMediaElement::GetDocument() const
 {
   return OwnerDoc();
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -292,22 +292,22 @@ MediaDecoder::ResourceCallback::NotifyBy
       self->mDecoder->NotifyBytesConsumed(aBytes, aOffset);
     }
   });
   mAbstractMainThread->Dispatch(r.forget());
 }
 
 void
 MediaDecoder::NotifyOwnerActivityChanged(bool aIsDocumentVisible,
-                                         bool aIsElementVisible,
+                                         Visibility aElementVisibility,
                                          bool aIsElementInTree)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-  SetElementVisibility(aIsDocumentVisible, aIsElementVisible, aIsElementInTree);
+  SetElementVisibility(aIsDocumentVisible, aElementVisibility, aIsElementInTree);
 
   NotifyCompositor();
 }
 
 void
 MediaDecoder::Pause()
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -390,17 +390,17 @@ MediaDecoder::MediaDecoder(MediaDecoderO
   , mAbstractMainThread(aOwner->AbstractMainThread())
   , mFrameStats(new FrameStatistics())
   , mVideoFrameContainer(aOwner->GetVideoFrameContainer())
   , mPlaybackStatistics(new MediaChannelStatistics())
   , mPinnedForSeek(false)
   , mMinimizePreroll(false)
   , mFiredMetadataLoaded(false)
   , mIsDocumentVisible(false)
-  , mIsElementVisible(false)
+  , mElementVisibility(Visibility::UNTRACKED)
   , mIsElementInTree(false)
   , mForcedHidden(false)
   , mHasSuspendTaint(false)
   , INIT_MIRROR(mStateMachineIsShutdown, true)
   , INIT_MIRROR(mBuffered, TimeIntervals())
   , INIT_MIRROR(mNextFrameStatus, MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE)
   , INIT_MIRROR(mCurrentPosition, 0)
   , INIT_MIRROR(mStateMachineDuration, NullableTimeUnit())
@@ -1276,22 +1276,22 @@ MediaDecoder::NotifyCompositor()
   if (layerManager) {
     RefPtr<KnowsCompositor> knowsCompositor = layerManager->AsShadowForwarder();
     mCompositorUpdatedEvent.Notify(knowsCompositor);
   }
 }
 
 void
 MediaDecoder::SetElementVisibility(bool aIsDocumentVisible,
-                                   bool aIsElementVisible,
+                                   Visibility aElementVisibility,
                                    bool aIsElementInTree)
 {
   MOZ_ASSERT(NS_IsMainThread());
   mIsDocumentVisible = aIsDocumentVisible;
-  mIsElementVisible = aIsElementVisible;
+  mElementVisibility = aElementVisibility;
   mIsElementInTree = aIsElementInTree;
   UpdateVideoDecodeMode();
 }
 
 void
 MediaDecoder::SetForcedHidden(bool aForcedHidden)
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -1331,17 +1331,18 @@ MediaDecoder::UpdateVideoDecodeMode()
   if (mForcedHidden) {
     mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Suspend);
     return;
   }
 
   // Otherwise, depends on the owner's visibility state.
   // A element is visible only if its document is visible and the element
   // itself is visible.
-  if (mIsDocumentVisible && mIsElementVisible) {
+  if (mIsDocumentVisible &&
+      mElementVisibility == Visibility::APPROXIMATELY_VISIBLE) {
     mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Normal);
   } else {
     mDecoderStateMachine->SetVideoDecodeMode(VideoDecodeMode::Suspend);
   }
 }
 
 bool
 MediaDecoder::HasSuspendTaint() const
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -45,16 +45,17 @@ class Promise;
 class HTMLMediaElement;
 }
 
 class AbstractThread;
 class VideoFrameContainer;
 class MediaDecoderStateMachine;
 
 enum class MediaEventType : int8_t;
+enum class Visibility : uint8_t;
 
 // GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
 // GetTickCount() and conflicts with MediaDecoder::GetCurrentTime implementation.
 #ifdef GetCurrentTime
 #undef GetCurrentTime
 #endif
 
 class MediaDecoder : public AbstractMediaDecoder
@@ -185,17 +186,17 @@ public:
   nsresult InitializeStateMachine();
 
   // Start playback of a video. 'Load' must have previously been
   // called.
   virtual nsresult Play();
 
   // Notify activity of the decoder owner is changed.
   virtual void NotifyOwnerActivityChanged(bool aIsDocumentVisible,
-                                          bool aIsElementVisible,
+                                          Visibility aElementVisibility,
                                           bool aIsElementInTree);
 
   // Pause video playback.
   virtual void Pause();
   // Adjust the speed of the playback, optionally with pitch correction,
   virtual void SetVolume(double aVolume);
 
   virtual void SetPlaybackRate(double aPlaybackRate);
@@ -369,17 +370,17 @@ private:
   // to buffer, given the current download and playback rates.
   virtual bool CanPlayThrough();
 
   void SetAudioChannel(dom::AudioChannel aChannel) { mAudioChannel = aChannel; }
   dom::AudioChannel GetAudioChannel() { return mAudioChannel; }
 
   // Called from HTMLMediaElement when owner document activity changes
   virtual void SetElementVisibility(bool aIsDocumentVisible,
-                                    bool aIsElementVisible,
+                                    Visibility aElementVisibility,
                                     bool aIsElementInTree);
 
   // Force override the visible state to hidden.
   // Called from HTMLMediaElement when testing of video decode suspend from mochitests.
   void SetForcedHidden(bool aForcedHidden);
 
   // Mark the decoder as tainted, meaning suspend-video-decoder is disabled.
   void SetSuspendTaint(bool aTaint);
@@ -706,17 +707,17 @@ protected:
   // Stores media info, including info of audio tracks and video tracks, should
   // only be accessed from main thread.
   nsAutoPtr<MediaInfo> mInfo;
 
   // Tracks the visibility status of owner element's document.
   bool mIsDocumentVisible;
 
   // Tracks the visibility status of owner element.
-  bool mIsElementVisible;
+  Visibility mElementVisibility;
 
   // Tracks the owner is in-tree or not.
   bool mIsElementInTree;
 
   // If true, forces the decoder to be considered hidden.
   bool mForcedHidden;
 
   // True if the decoder has a suspend taint - meaning suspend-video-decoder is