author Hamzata Diallo <>
Thu, 02 Jul 2015 15:19:35 -0700
changeset 282901 8c09dc6015a37cf5293c75edbc4c2478b30d17e1
parent 236670 277005c35f059e79bbcf07cecb1523a484eae981
child 283319 5e6f54bca784e2b7bcb76963d94c26ef8d0b5e78
permissions -rw-r--r--
Bug 1178513 - Export libxul symbols needed by ACL. r=mattwoodrow

/* -*- 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 */


#include "mozilla/Mutex.h"
#include "mozilla/TimeStamp.h"
#include "gfxPoint.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"

namespace mozilla {

namespace dom {
class HTMLMediaElement;

namespace layers {
class Image;
class ImageContainer;

 * This object is used in the decoder backend threads and the main thread
 * to manage the "current video frame" state. This state includes timing data
 * and an intrinsic size (see below).
 * This has to be a thread-safe object since it's accessed by resource decoders
 * and other off-main-thread components. So we can't put this state in the media
 * element itself ... well, maybe we could, but it could be risky and/or
 * confusing.
class VideoFrameContainer {
  B2G_ACL_EXPORT ~VideoFrameContainer();

  typedef layers::ImageContainer ImageContainer;
  typedef layers::Image Image;


  VideoFrameContainer(dom::HTMLMediaElement* aElement,
                      already_AddRefed<ImageContainer> aContainer);

  // Call on any thread
  B2G_ACL_EXPORT void SetCurrentFrame(const gfxIntSize& aIntrinsicSize, Image* aImage,
                       TimeStamp aTargetTime);
  void ClearCurrentFrame(bool aResetSize = false);
  // Reset the VideoFrameContainer
  void Reset();
  // Time in seconds by which the last painted video frame was late by.
  // E.g. if the last painted frame should have been painted at time t,
  // but was actually painted at t+n, this returns n in seconds. Threadsafe.
  double GetFrameDelay();
  // Call on main thread
  enum {
  void Invalidate() { InvalidateWithFlags(INVALIDATE_DEFAULT); }
  B2G_ACL_EXPORT void InvalidateWithFlags(uint32_t aFlags);
  B2G_ACL_EXPORT ImageContainer* GetImageContainer();
  void ForgetElement() { mElement = nullptr; }

  // Non-addreffed pointer to the element. The element calls ForgetElement
  // to clear this reference when the element is destroyed.
  dom::HTMLMediaElement* mElement;
  nsRefPtr<ImageContainer> mImageContainer;

  // mMutex protects all the fields below.
  Mutex mMutex;
  // The intrinsic size is the ideal size which we should render the
  // ImageContainer's current Image at.
  // This can differ from the Image's actual size when the media resource
  // specifies that the Image should be stretched to have the correct aspect
  // ratio.
  gfxIntSize mIntrinsicSize;
  // The time at which the current video frame should have been painted.
  // Access protected by mVideoUpdateLock.
  TimeStamp mPaintTarget;
  // The delay between the last video frame being presented and it being
  // painted. This is time elapsed after mPaintTarget until the most recently
  // painted frame appeared on screen.
  TimeDuration mPaintDelay;
  // True when the intrinsic size has been changed by SetCurrentFrame() since
  // the last call to Invalidate().
  // The next call to Invalidate() will recalculate
  // and update the intrinsic size on the element, request a frame reflow and
  // then reset this flag.
  bool mIntrinsicSizeChanged;
  // True when the Image size has changed since the last time Invalidate() was
  // called. When set, the next call to Invalidate() will ensure that the
  // frame is fully invalidated instead of just invalidating for the image change
  // in the ImageLayer.
  bool mImageSizeChanged;