Bug 1345403 part 2 - Mark element tainted when DrawImage is used; r=jwwang,mattwoodrow

Mark video element as tainted (stored on the decoder owned by video element) when the video is used as source to drawImage() on canvas.

MozReview-Commit-ID: HdciVwhqPu3

--HG--
extra : rebase_source : b26c257afaaabdd6346a5421988d95e82281d7ef
extra : source : 149234329b62015dfd2e954030c23bf9c6b1d55e
This commit is contained in:
Kaku Kuo 2017-03-08 19:41:08 +08:00
Родитель af6e44d1d0
Коммит fe566c1222
3 изменённых файлов: 36 добавлений и 6 удалений

Просмотреть файл

@ -1527,6 +1527,26 @@ HTMLMediaElement::SetVisible(bool aVisible)
mDecoder->SetForcedHidden(!aVisible);
}
layers::Image*
HTMLMediaElement::GetCurrentImage()
{
// Mark the decoder owned by the element as tainted so that the
// suspend-vide-decoder is suspended.
mHasSuspendTaint = true;
if (mDecoder) {
mDecoder->SetSuspendTaint(true);
}
// TODO: In bug 1345404, handle case when video decoder is already suspended.
ImageContainer* container = GetImageContainer();
if (!container) {
return nullptr;
}
AutoLockImage lockImage(container);
return lockImage.GetImage();
}
already_AddRefed<DOMMediaStream>
HTMLMediaElement::GetSrcObject() const
{
@ -3692,6 +3712,7 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
mFirstFrameLoaded(false),
mDefaultPlaybackStartPosition(0.0),
mIsAudioTrackAudible(false),
mHasSuspendTaint(false),
mVisibilityState(Visibility::APPROXIMATELY_NONVISIBLE),
mErrorSink(new ErrorSink(this)),
mAudioChannelWrapper(new AudioChannelAgentCallback(this, mAudioChannel))
@ -4689,6 +4710,8 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder,
if (mPreloadAction == HTMLMediaElement::PRELOAD_METADATA) {
mDecoder->SetMinimizePrerollUntilPlaybackStarts();
}
// Notify the decoder of suspend taint.
mDecoder->SetSuspendTaint(mHasSuspendTaint);
// Update decoder principal before we start decoding, since it
// can affect how we feed data to MediaStreams

Просмотреть файл

@ -619,6 +619,14 @@ public:
void SetVisible(bool aVisible);
// Synchronously, return the next video frame and mark the element unable to
// participate in decode suspending.
//
// This function is synchronous for cases where decoding has been suspended
// and JS needs a frame to use in, eg., nsLayoutUtils::SurfaceFromElement()
// via drawImage().
layers::Image* GetCurrentImage();
already_AddRefed<DOMMediaStream> GetSrcObject() const;
void SetSrcObject(DOMMediaStream& aValue);
void SetSrcObject(DOMMediaStream* aValue);
@ -1714,6 +1722,10 @@ private:
// True if the audio track is not silent.
bool mIsAudioTrackAudible;
// True if media element has been marked as 'tainted' and can't
// participate in video decoder suspending.
bool mHasSuspendTaint;
Visibility mVisibilityState;
UniquePtr<ErrorSink> mErrorSink;

Просмотреть файл

@ -7337,13 +7337,8 @@ nsLayoutUtils::SurfaceFromElement(HTMLVideoElement* aElement,
if (!principal)
return result;
ImageContainer* container = aElement->GetImageContainer();
if (!container)
return result;
result.mLayersImage = aElement->GetCurrentImage();
AutoLockImage lockImage(container);
result.mLayersImage = lockImage.GetImage();
if (!result.mLayersImage)
return result;