2012-02-15 04:35:01 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "VideoFrameContainer.h"
|
|
|
|
|
2013-03-19 12:23:54 +00:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2012-02-15 04:35:01 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsSVGEffects.h"
|
2012-08-21 04:06:46 +00:00
|
|
|
#include "ImageContainer.h"
|
2012-02-15 04:35:01 +00:00
|
|
|
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-03-19 12:23:54 +00:00
|
|
|
VideoFrameContainer::VideoFrameContainer(dom::HTMLMediaElement* aElement,
|
2012-08-21 04:06:46 +00:00
|
|
|
already_AddRefed<ImageContainer> aContainer)
|
|
|
|
: mElement(aElement),
|
|
|
|
mImageContainer(aContainer), mMutex("nsVideoFrameContainer"),
|
2013-10-02 03:05:49 +00:00
|
|
|
mIntrinsicSizeChanged(false), mImageSizeChanged(false)
|
2012-08-21 04:06:46 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aElement, "aElement must not be null");
|
|
|
|
NS_ASSERTION(mImageContainer, "aContainer must not be null");
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoFrameContainer::~VideoFrameContainer()
|
|
|
|
{}
|
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
void VideoFrameContainer::SetCurrentFrame(const gfxIntSize& aIntrinsicSize,
|
|
|
|
Image* aImage,
|
|
|
|
TimeStamp aTargetTime)
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
|
|
|
if (aIntrinsicSize != mIntrinsicSize) {
|
|
|
|
mIntrinsicSize = aIntrinsicSize;
|
|
|
|
mIntrinsicSizeChanged = true;
|
|
|
|
}
|
|
|
|
|
2013-12-13 17:32:02 +00:00
|
|
|
gfx::IntSize oldFrameSize = mImageContainer->GetCurrentSize();
|
2012-02-15 04:35:01 +00:00
|
|
|
TimeStamp lastPaintTime = mImageContainer->GetPaintTime();
|
|
|
|
if (!lastPaintTime.IsNull() && !mPaintTarget.IsNull()) {
|
|
|
|
mPaintDelay = lastPaintTime - mPaintTarget;
|
|
|
|
}
|
2012-09-27 04:33:43 +00:00
|
|
|
|
|
|
|
// When using the OMX decoder, destruction of the current image can indirectly
|
|
|
|
// block on main thread I/O. If we let this happen while holding onto
|
|
|
|
// |mImageContainer|'s lock, then when the main thread then tries to
|
|
|
|
// composite it can then block on |mImageContainer|'s lock, causing a
|
|
|
|
// deadlock. We use this hack to defer the destruction of the current image
|
|
|
|
// until it is safe.
|
|
|
|
nsRefPtr<Image> kungFuDeathGrip;
|
|
|
|
kungFuDeathGrip = mImageContainer->LockCurrentImage();
|
|
|
|
mImageContainer->UnlockCurrentImage();
|
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
mImageContainer->SetCurrentImage(aImage);
|
2013-12-13 17:32:02 +00:00
|
|
|
gfx::IntSize newFrameSize = mImageContainer->GetCurrentSize();
|
2012-02-15 04:35:01 +00:00
|
|
|
if (oldFrameSize != newFrameSize) {
|
|
|
|
mImageSizeChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPaintTarget = aTargetTime;
|
|
|
|
}
|
|
|
|
|
2012-12-27 15:21:30 +00:00
|
|
|
void VideoFrameContainer::Reset()
|
|
|
|
{
|
|
|
|
ClearCurrentFrame(true);
|
|
|
|
Invalidate();
|
2013-02-04 14:21:44 +00:00
|
|
|
mIntrinsicSize = gfxIntSize(-1, -1);
|
2013-01-31 14:41:05 +00:00
|
|
|
mPaintDelay = mozilla::TimeDuration();
|
|
|
|
mPaintTarget = mozilla::TimeStamp();
|
2012-12-27 15:21:30 +00:00
|
|
|
mImageContainer->ResetPaintCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoFrameContainer::ClearCurrentFrame(bool aResetSize)
|
2012-09-27 04:33:43 +00:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
|
|
|
// See comment in SetCurrentFrame for the reasoning behind
|
|
|
|
// using a kungFuDeathGrip here.
|
|
|
|
nsRefPtr<Image> kungFuDeathGrip;
|
|
|
|
kungFuDeathGrip = mImageContainer->LockCurrentImage();
|
|
|
|
mImageContainer->UnlockCurrentImage();
|
|
|
|
|
2013-10-17 15:09:15 +00:00
|
|
|
mImageContainer->ClearAllImages();
|
2012-12-27 15:21:30 +00:00
|
|
|
mImageSizeChanged = aResetSize;
|
2012-09-27 04:33:43 +00:00
|
|
|
}
|
|
|
|
|
2012-08-21 04:06:46 +00:00
|
|
|
ImageContainer* VideoFrameContainer::GetImageContainer() {
|
|
|
|
return mImageContainer;
|
|
|
|
}
|
|
|
|
|
Backout b3a8618f901c (bug 829042), 34a9ef8f929d (bug 822933), 4c1215cefbab (bug 826349), 70bb7f775178 (bug 825325), e9c8447fb197 (bug 828713), eb6ebf01eafe (bug 828901), f1f3ef647920 (bug 825329), f9d7b5722d4f (bug 825329), 5add564d4546 (bug 819377), 55e93d1fa972 (bug 804875), f14639a3461e (bug 804875), 23456fc21052 (bug 814308) for Windows pgo-only mochitest-1 media test timeouts on a CLOSED TREE
2013-01-16 15:16:23 +00:00
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
double VideoFrameContainer::GetFrameDelay()
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
return mPaintDelay.ToSeconds();
|
|
|
|
}
|
|
|
|
|
2013-10-02 03:05:34 +00:00
|
|
|
void VideoFrameContainer::InvalidateWithFlags(uint32_t aFlags)
|
2012-02-15 04:35:01 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Must call on main thread");
|
2012-08-10 15:42:53 +00:00
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
if (!mElement) {
|
|
|
|
// Element has been destroyed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame = mElement->GetPrimaryFrame();
|
|
|
|
bool invalidateFrame = false;
|
|
|
|
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
|
|
|
// Get mImageContainerSizeChanged while holding the lock.
|
|
|
|
invalidateFrame = mImageSizeChanged;
|
|
|
|
mImageSizeChanged = false;
|
|
|
|
|
|
|
|
if (mIntrinsicSizeChanged) {
|
|
|
|
mElement->UpdateMediaSize(mIntrinsicSize);
|
|
|
|
mIntrinsicSizeChanged = false;
|
|
|
|
|
|
|
|
if (frame) {
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
|
|
|
nsIPresShell *presShell = presContext->PresShell();
|
|
|
|
presShell->FrameNeedsReflow(frame,
|
|
|
|
nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-02 03:05:49 +00:00
|
|
|
bool asyncInvalidate = mImageContainer &&
|
|
|
|
mImageContainer->IsAsync() &&
|
|
|
|
!(aFlags & INVALIDATE_FORCE);
|
|
|
|
|
2012-02-15 04:35:01 +00:00
|
|
|
if (frame) {
|
|
|
|
if (invalidateFrame) {
|
2012-08-29 05:39:31 +00:00
|
|
|
frame->InvalidateFrame();
|
2012-02-15 04:35:01 +00:00
|
|
|
} else {
|
2015-02-11 09:11:41 +00:00
|
|
|
frame->InvalidateLayer(nsDisplayItem::TYPE_VIDEO, nullptr, nullptr,
|
2013-10-02 03:05:49 +00:00
|
|
|
asyncInvalidate ? nsIFrame::UPDATE_IS_ASYNC : 0);
|
2012-02-15 04:35:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(mElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|