1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "VideoFrameContainer.h"
8 :
9 : #include "nsHTMLMediaElement.h"
10 : #include "nsIFrame.h"
11 : #include "nsDisplayList.h"
12 : #include "nsSVGEffects.h"
13 :
14 : using namespace mozilla::layers;
15 :
16 : namespace mozilla {
17 :
18 0 : void VideoFrameContainer::SetCurrentFrame(const gfxIntSize& aIntrinsicSize,
19 : Image* aImage,
20 : TimeStamp aTargetTime)
21 : {
22 0 : MutexAutoLock lock(mMutex);
23 :
24 0 : if (aIntrinsicSize != mIntrinsicSize) {
25 0 : mIntrinsicSize = aIntrinsicSize;
26 0 : mIntrinsicSizeChanged = true;
27 : }
28 :
29 0 : gfxIntSize oldFrameSize = mImageContainer->GetCurrentSize();
30 0 : TimeStamp lastPaintTime = mImageContainer->GetPaintTime();
31 0 : if (!lastPaintTime.IsNull() && !mPaintTarget.IsNull()) {
32 0 : mPaintDelay = lastPaintTime - mPaintTarget;
33 : }
34 0 : mImageContainer->SetCurrentImage(aImage);
35 0 : gfxIntSize newFrameSize = mImageContainer->GetCurrentSize();
36 0 : if (oldFrameSize != newFrameSize) {
37 0 : mImageSizeChanged = true;
38 : }
39 :
40 0 : mPaintTarget = aTargetTime;
41 0 : }
42 :
43 0 : double VideoFrameContainer::GetFrameDelay()
44 : {
45 0 : MutexAutoLock lock(mMutex);
46 0 : return mPaintDelay.ToSeconds();
47 : }
48 :
49 0 : void VideoFrameContainer::Invalidate()
50 : {
51 0 : NS_ASSERTION(NS_IsMainThread(), "Must call on main thread");
52 0 : if (!mElement) {
53 : // Element has been destroyed
54 0 : return;
55 : }
56 :
57 0 : nsIFrame* frame = mElement->GetPrimaryFrame();
58 0 : bool invalidateFrame = false;
59 :
60 : {
61 0 : MutexAutoLock lock(mMutex);
62 :
63 : // Get mImageContainerSizeChanged while holding the lock.
64 0 : invalidateFrame = mImageSizeChanged;
65 0 : mImageSizeChanged = false;
66 :
67 0 : if (mIntrinsicSizeChanged) {
68 0 : mElement->UpdateMediaSize(mIntrinsicSize);
69 0 : mIntrinsicSizeChanged = false;
70 :
71 0 : if (frame) {
72 0 : nsPresContext* presContext = frame->PresContext();
73 0 : nsIPresShell *presShell = presContext->PresShell();
74 : presShell->FrameNeedsReflow(frame,
75 : nsIPresShell::eStyleChange,
76 0 : NS_FRAME_IS_DIRTY);
77 : }
78 : }
79 : }
80 :
81 0 : if (frame) {
82 0 : nsRect contentRect = frame->GetContentRect() - frame->GetPosition();
83 0 : if (invalidateFrame) {
84 0 : frame->Invalidate(contentRect);
85 : } else {
86 0 : frame->InvalidateLayer(contentRect, nsDisplayItem::TYPE_VIDEO);
87 : }
88 : }
89 :
90 0 : nsSVGEffects::InvalidateDirectRenderingObservers(mElement);
91 : }
92 :
93 : }
|