2012-08-19 23:33:25 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef GFX_IMAGECONTAINER_H
|
|
|
|
#define GFX_IMAGECONTAINER_H
|
|
|
|
|
2013-08-12 03:17:23 +04:00
|
|
|
#include <stdint.h> // for uint32_t, uint8_t, uint64_t
|
|
|
|
#include <sys/types.h> // for int32_t
|
2014-04-16 04:41:40 +04:00
|
|
|
#include "gfxTypes.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "ImageTypes.h" // for ImageFormat, etc
|
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2
|
|
|
|
#include "mozilla/Mutex.h" // for Mutex
|
|
|
|
#include "mozilla/ReentrantMonitor.h" // for ReentrantMonitorAutoEnter, etc
|
|
|
|
#include "mozilla/TimeStamp.h" // for TimeStamp
|
2013-12-13 21:32:02 +04:00
|
|
|
#include "mozilla/gfx/Point.h" // For IntSize
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/LayersTypes.h" // for LayersBackend, etc
|
|
|
|
#include "mozilla/mozalloc.h" // for operator delete, etc
|
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr, nsAutoArrayPtr, etc
|
|
|
|
#include "nsAutoRef.h" // for nsCountedRef
|
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed
|
|
|
|
#include "nsDebug.h" // for NS_ASSERTION
|
|
|
|
#include "nsISupportsImpl.h" // for Image::Release, etc
|
2015-05-07 12:07:53 +03:00
|
|
|
#include "nsRect.h" // for mozilla::gfx::IntRect
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsTArray.h" // for nsTArray
|
2013-08-12 13:51:49 +04:00
|
|
|
#include "mozilla/Atomics.h"
|
2014-02-25 07:37:51 +04:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2013-09-25 00:45:13 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2014-01-15 19:06:43 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-02-17 02:23:39 +04:00
|
|
|
#include "nsDataHashtable.h"
|
2014-04-26 06:34:06 +04:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2015-10-20 20:16:04 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
|
2013-09-25 00:45:13 +04:00
|
|
|
#ifndef XPCOM_GLUE_AVOID_NSPR
|
|
|
|
/**
|
2014-04-10 12:49:53 +04:00
|
|
|
* We need to be able to hold a reference to a Moz2D SourceSurface from Image
|
2013-09-25 00:45:13 +04:00
|
|
|
* subclasses. This is potentially a problem since Images can be addrefed
|
|
|
|
* or released off the main thread. We can ensure that we never AddRef
|
2014-04-10 12:49:53 +04:00
|
|
|
* a SourceSurface off the main thread, but we might want to Release due
|
2013-09-25 00:45:13 +04:00
|
|
|
* to an Image being destroyed off the main thread.
|
|
|
|
*
|
2014-04-10 12:49:53 +04:00
|
|
|
* We use nsCountedRef<nsMainThreadSourceSurfaceRef> to reference the
|
|
|
|
* SourceSurface. When AddRefing, we assert that we're on the main thread.
|
2013-09-25 00:45:13 +04:00
|
|
|
* When Releasing, if we're not on the main thread, we post an event to
|
|
|
|
* the main thread to do the actual release.
|
2014-01-17 20:22:09 +04:00
|
|
|
*/
|
|
|
|
class nsMainThreadSourceSurfaceRef;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class nsAutoRefTraits<nsMainThreadSourceSurfaceRef> {
|
|
|
|
public:
|
|
|
|
typedef mozilla::gfx::SourceSurface* RawRef;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The XPCOM event that will do the actual release on the main thread.
|
|
|
|
*/
|
|
|
|
class SurfaceReleaser : public nsRunnable {
|
|
|
|
public:
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit SurfaceReleaser(RawRef aRef) : mRef(aRef) {}
|
2014-01-17 20:22:09 +04:00
|
|
|
NS_IMETHOD Run() {
|
|
|
|
mRef->Release();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
RawRef mRef;
|
|
|
|
};
|
|
|
|
|
|
|
|
static RawRef Void() { return nullptr; }
|
|
|
|
static void Release(RawRef aRawRef)
|
|
|
|
{
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
aRawRef->Release();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIRunnable> runnable = new SurfaceReleaser(aRawRef);
|
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
static void AddRef(RawRef aRawRef)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(),
|
|
|
|
"Can only add a reference on the main thread");
|
|
|
|
aRawRef->AddRef();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-25 00:45:13 +04:00
|
|
|
#endif
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
struct ID3D10Texture2D;
|
|
|
|
struct ID3D10Device;
|
|
|
|
struct ID3D10ShaderResourceView;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef void* HANDLE;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
namespace layers {
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
class ImageClient;
|
2015-07-06 06:02:26 +03:00
|
|
|
class ImageCompositeNotification;
|
|
|
|
class ImageContainerChild;
|
|
|
|
class PImageContainerChild;
|
2012-11-05 14:38:03 +04:00
|
|
|
class SharedPlanarYCbCrImage;
|
2013-07-30 13:59:51 +04:00
|
|
|
class TextureClient;
|
2014-02-17 02:23:39 +04:00
|
|
|
class CompositableClient;
|
2014-12-18 07:42:00 +03:00
|
|
|
class GrallocImage;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
struct ImageBackendData
|
|
|
|
{
|
|
|
|
virtual ~ImageBackendData() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ImageBackendData() {}
|
|
|
|
};
|
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
/* Forward declarations for Image derivatives. */
|
|
|
|
class EGLImageImage;
|
2015-11-17 11:09:00 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
class SurfaceTextureImage;
|
|
|
|
#endif
|
2015-11-17 11:09:00 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
class MacIOSurfaceImage;
|
|
|
|
#endif
|
2015-11-17 11:09:00 +03:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
|
|
|
* A class representing a buffer of pixel data. The data can be in one
|
|
|
|
* of various formats including YCbCr.
|
|
|
|
*
|
|
|
|
* Create an image using an ImageContainer. Fill the image with data, and
|
|
|
|
* then call ImageContainer::SetImage to display it. An image must not be
|
|
|
|
* modified after calling SetImage. Image implementations do not need to
|
|
|
|
* perform locking; when filling an Image, the Image client is responsible
|
|
|
|
* for ensuring only one thread accesses the Image at a time, and after
|
|
|
|
* SetImage the image is immutable.
|
|
|
|
*
|
|
|
|
* When resampling an Image, only pixels within the buffer should be
|
|
|
|
* sampled. For example, cairo images should be sampled in EXTEND_PAD mode.
|
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class Image {
|
2012-08-19 23:33:25 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Image)
|
|
|
|
|
|
|
|
public:
|
|
|
|
ImageFormat GetFormat() { return mFormat; }
|
|
|
|
void* GetImplData() { return mImplData; }
|
|
|
|
|
2013-12-13 21:32:02 +04:00
|
|
|
virtual gfx::IntSize GetSize() = 0;
|
2015-05-07 12:07:53 +03:00
|
|
|
virtual gfx::IntRect GetPictureRect()
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2015-05-07 12:07:53 +03:00
|
|
|
return gfx::IntRect(0, 0, GetSize().width, GetSize().height);
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
ImageBackendData* GetBackendData(LayersBackend aBackend)
|
2014-04-26 06:34:06 +04:00
|
|
|
{ return mBackendData[aBackend]; }
|
2012-08-19 23:33:25 +04:00
|
|
|
void SetBackendData(LayersBackend aBackend, ImageBackendData* aData)
|
2014-04-26 06:34:06 +04:00
|
|
|
{ mBackendData[aBackend] = aData; }
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2012-08-23 06:02:51 +04:00
|
|
|
int32_t GetSerial() { return mSerial; }
|
2012-08-23 04:08:26 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() = 0;
|
2014-01-15 19:06:43 +04:00
|
|
|
|
2014-12-18 07:42:00 +03:00
|
|
|
virtual GrallocImage* AsGrallocImage()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-12 12:13:23 +03:00
|
|
|
virtual bool IsValid() { return true; }
|
|
|
|
|
2015-03-19 00:15:38 +03:00
|
|
|
virtual uint8_t* GetBuffer() { return nullptr; }
|
|
|
|
|
|
|
|
/**
|
2015-11-17 11:09:00 +03:00
|
|
|
* For use with the CompositableClient only (so that the later can
|
|
|
|
* synchronize the TextureClient with the TextureHost).
|
|
|
|
*/
|
2015-03-19 00:15:38 +03:00
|
|
|
virtual TextureClient* GetTextureClient(CompositableClient* aClient) { return nullptr; }
|
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
/* Access to derived classes. */
|
|
|
|
virtual EGLImageImage* AsEGLImageImage() { return nullptr; }
|
2015-11-17 11:09:00 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
virtual SurfaceTextureImage* AsSurfaceTextureImage() { return nullptr; }
|
|
|
|
#endif
|
2015-11-17 11:09:00 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
virtual MacIOSurfaceImage* AsMacIOSurfaceImage() { return nullptr; }
|
|
|
|
#endif
|
2015-11-17 11:09:00 +03:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
protected:
|
|
|
|
Image(void* aImplData, ImageFormat aFormat) :
|
|
|
|
mImplData(aImplData),
|
2013-08-12 13:51:49 +04:00
|
|
|
mSerial(++sSerialCounter),
|
2015-03-20 06:13:46 +03:00
|
|
|
mFormat(aFormat)
|
2012-08-19 23:33:25 +04:00
|
|
|
{}
|
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
|
|
|
virtual ~Image() {}
|
|
|
|
|
2014-04-26 06:34:06 +04:00
|
|
|
mozilla::EnumeratedArray<mozilla::layers::LayersBackend,
|
|
|
|
mozilla::layers::LayersBackend::LAYERS_LAST,
|
|
|
|
nsAutoPtr<ImageBackendData>>
|
|
|
|
mBackendData;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
void* mImplData;
|
2012-08-23 06:02:51 +04:00
|
|
|
int32_t mSerial;
|
2012-08-19 23:33:25 +04:00
|
|
|
ImageFormat mFormat;
|
2012-11-05 14:38:03 +04:00
|
|
|
bool mSent;
|
2015-05-12 03:56:09 +03:00
|
|
|
|
|
|
|
static mozilla::Atomic<int32_t> sSerialCounter;
|
2012-08-19 23:33:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A RecycleBin is owned by an ImageContainer. We store buffers in it that we
|
|
|
|
* want to recycle from one image to the next.It's a separate object from
|
|
|
|
* ImageContainer because images need to store a strong ref to their RecycleBin
|
|
|
|
* and we must avoid creating a reference loop between an ImageContainer and
|
|
|
|
* its active image.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class BufferRecycleBin final {
|
2014-06-19 06:28:59 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(BufferRecycleBin)
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
//typedef mozilla::gl::GLContext GLContext;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BufferRecycleBin();
|
|
|
|
|
2015-10-20 20:16:04 +03:00
|
|
|
void RecycleBuffer(mozilla::UniquePtr<uint8_t[]> aBuffer, uint32_t aSize);
|
2012-08-19 23:33:25 +04:00
|
|
|
// Returns a recycled buffer of the right size, or allocates a new buffer.
|
2015-10-20 20:16:04 +03:00
|
|
|
mozilla::UniquePtr<uint8_t[]> GetBuffer(uint32_t aSize);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
|
|
|
~BufferRecycleBin()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
// This protects mRecycledBuffers, mRecycledBufferSize, mRecycledTextures
|
|
|
|
// and mRecycledTextureSizes
|
|
|
|
Mutex mLock;
|
|
|
|
|
|
|
|
// We should probably do something to prune this list on a timer so we don't
|
|
|
|
// eat excess memory while video is paused...
|
2015-10-20 20:16:04 +03:00
|
|
|
nsTArray<mozilla::UniquePtr<uint8_t[]>> mRecycledBuffers;
|
2012-08-19 23:33:25 +04:00
|
|
|
// This is only valid if mRecycledBuffers is non-empty
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mRecycledBufferSize;
|
2012-08-19 23:33:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class that manages Image creation for a LayerManager. The only reason
|
2013-05-30 08:44:43 +04:00
|
|
|
* we need a separate class here is that LayerManagers aren't threadsafe
|
2012-08-19 23:33:25 +04:00
|
|
|
* (because layers can only be used on the main thread) and we want to
|
|
|
|
* be able to create images from any thread, to facilitate video playback
|
|
|
|
* without involving the main thread, for example.
|
|
|
|
* Different layer managers can implement child classes of this making it
|
|
|
|
* possible to create layer manager specific images.
|
|
|
|
* This class is not meant to be used directly but rather can be set on an
|
|
|
|
* image container. This is usually done by the layer system internally and
|
|
|
|
* not explicitly by users. For PlanarYCbCr or Cairo images the default
|
|
|
|
* implementation will creates images whose data lives in system memory, for
|
|
|
|
* MacIOSurfaces the default implementation will be a simple MacIOSurface
|
|
|
|
* wrapper.
|
|
|
|
*/
|
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
class ImageFactory
|
2012-08-19 23:33:25 +04:00
|
|
|
{
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageFactory)
|
|
|
|
protected:
|
|
|
|
friend class ImageContainer;
|
|
|
|
|
|
|
|
ImageFactory() {}
|
|
|
|
virtual ~ImageFactory() {}
|
|
|
|
|
2014-01-31 02:58:51 +04:00
|
|
|
virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat,
|
2013-12-13 21:32:02 +04:00
|
|
|
const gfx::IntSize &aScaleHint,
|
2012-08-19 23:33:25 +04:00
|
|
|
BufferRecycleBin *aRecycleBin);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class that manages Images for an ImageLayer. The only reason
|
|
|
|
* we need a separate class here is that ImageLayers aren't threadsafe
|
|
|
|
* (because layers can only be used on the main thread) and we want to
|
|
|
|
* be able to set the current Image from any thread, to facilitate
|
|
|
|
* video playback without involving the main thread, for example.
|
|
|
|
*
|
2014-09-25 00:35:06 +04:00
|
|
|
* An ImageContainer can operate in one of these modes:
|
2012-08-19 23:33:25 +04:00
|
|
|
* 1) Normal. Triggered by constructing the ImageContainer with
|
|
|
|
* DISABLE_ASYNC or when compositing is happening on the main thread.
|
2015-07-07 00:58:18 +03:00
|
|
|
* SetCurrentImages changes ImageContainer state but nothing is sent to the
|
2012-08-19 23:33:25 +04:00
|
|
|
* compositor until the next layer transaction.
|
|
|
|
* 2) Asynchronous. Initiated by constructing the ImageContainer with
|
|
|
|
* ENABLE_ASYNC when compositing is happening on the main thread.
|
2015-07-07 00:58:18 +03:00
|
|
|
* SetCurrentImages sends a message through the ImageBridge to the compositor
|
2012-08-19 23:33:25 +04:00
|
|
|
* thread to update the image, without going through the main thread or
|
|
|
|
* a layer transaction.
|
|
|
|
* The ImageContainer uses a shared memory block containing a cross-process mutex
|
|
|
|
* to communicate with the compositor thread. SetCurrentImage synchronously
|
|
|
|
* updates the shared state to point to the new image and the old image
|
|
|
|
* is immediately released (not true in Normal or Asynchronous modes).
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class ImageContainer final : public SupportsWeakPtr<ImageContainer> {
|
2012-08-19 23:33:25 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageContainer)
|
|
|
|
public:
|
2015-04-24 19:43:01 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ImageContainer)
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-05-28 02:35:00 +03:00
|
|
|
enum Mode { SYNCHRONOUS = 0x0, ASYNCHRONOUS = 0x01, ASYNCHRONOUS_OVERLAY = 0x02 };
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-05-28 02:35:00 +03:00
|
|
|
explicit ImageContainer(ImageContainer::Mode flag = SYNCHRONOUS);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-08-12 02:02:41 +03:00
|
|
|
typedef uint32_t FrameID;
|
|
|
|
typedef uint32_t ProducerID;
|
2015-07-06 06:02:26 +03:00
|
|
|
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
|
|
|
* Create an Image in one of the given formats.
|
|
|
|
* Picks the "best" format from the list and creates an Image of that
|
|
|
|
* format.
|
|
|
|
* Returns null if this backend does not support any of the formats.
|
|
|
|
* Can be called on any thread. This method takes mReentrantMonitor
|
|
|
|
* when accessing thread-shared state.
|
|
|
|
*/
|
2015-07-03 01:19:35 +03:00
|
|
|
B2G_ACL_EXPORT already_AddRefed<Image> CreateImage(ImageFormat aFormat);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-07-07 00:58:18 +03:00
|
|
|
struct NonOwningImage {
|
2015-07-03 13:13:48 +03:00
|
|
|
explicit NonOwningImage(Image* aImage = nullptr,
|
|
|
|
TimeStamp aTimeStamp = TimeStamp(),
|
2015-05-25 05:33:35 +03:00
|
|
|
FrameID aFrameID = 0,
|
|
|
|
ProducerID aProducerID = 0)
|
|
|
|
: mImage(aImage), mTimeStamp(aTimeStamp), mFrameID(aFrameID),
|
|
|
|
mProducerID(aProducerID) {}
|
2015-07-07 00:58:18 +03:00
|
|
|
Image* mImage;
|
|
|
|
TimeStamp mTimeStamp;
|
2015-07-03 13:13:48 +03:00
|
|
|
FrameID mFrameID;
|
2015-05-25 05:33:35 +03:00
|
|
|
ProducerID mProducerID;
|
2015-07-07 00:58:18 +03:00
|
|
|
};
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
2015-07-07 00:58:18 +03:00
|
|
|
* Set aImages as the list of timestamped to display. The Images must have
|
2012-08-19 23:33:25 +04:00
|
|
|
* been created by this ImageContainer.
|
|
|
|
* Can be called on any thread. This method takes mReentrantMonitor
|
|
|
|
* when accessing thread-shared state.
|
2015-07-07 00:58:18 +03:00
|
|
|
* aImages must be non-empty. The first timestamp in the list may be
|
|
|
|
* null but the others must not be, and the timestamps must increase.
|
|
|
|
* Every element of aImages must have non-null mImage.
|
2015-07-03 13:13:48 +03:00
|
|
|
* mFrameID can be zero, in which case you won't get meaningful
|
|
|
|
* painted/dropped frame counts. Otherwise you should use a unique and
|
|
|
|
* increasing ID for each decoded and submitted frame (but it's OK to
|
|
|
|
* pass the same frame to SetCurrentImages).
|
2015-05-25 05:33:35 +03:00
|
|
|
* mProducerID is a unique ID for the stream of images. A change in the
|
|
|
|
* mProducerID means changing to a new mFrameID namespace. All frames in
|
|
|
|
* aImages must have the same mProducerID.
|
2012-08-19 23:33:25 +04:00
|
|
|
*
|
|
|
|
* The Image data must not be modified after this method is called!
|
|
|
|
* Note that this must not be called if ENABLE_ASYNC has not been set.
|
|
|
|
*
|
2015-07-07 00:58:18 +03:00
|
|
|
* The implementation calls CurrentImageChanged() while holding
|
2012-08-19 23:33:25 +04:00
|
|
|
* mReentrantMonitor.
|
|
|
|
*
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
* If this ImageContainer has an ImageClient for async video:
|
2015-03-16 13:23:50 +03:00
|
|
|
* Schedule a task to send the image to the compositor using the
|
2012-08-19 23:33:25 +04:00
|
|
|
* PImageBridge protcol without using the main thread.
|
|
|
|
*/
|
2015-07-07 00:58:18 +03:00
|
|
|
void SetCurrentImages(const nsTArray<NonOwningImage>& aImages);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2013-10-17 19:09:15 +04:00
|
|
|
/**
|
|
|
|
* Clear all images. Let ImageClient release all TextureClients.
|
|
|
|
*/
|
|
|
|
void ClearAllImages();
|
|
|
|
|
2013-09-12 18:50:28 +04:00
|
|
|
/**
|
2015-03-26 04:17:13 +03:00
|
|
|
* Clear the current images.
|
2013-09-12 18:50:28 +04:00
|
|
|
* This function is expect to be called only from a CompositableClient
|
|
|
|
* that belongs to ImageBridgeChild. Created to prevent dead lock.
|
|
|
|
* See Bug 901224.
|
|
|
|
*/
|
2015-03-26 04:17:13 +03:00
|
|
|
void ClearImagesFromImageBridge();
|
2013-09-12 18:50:28 +04:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
|
|
|
* Set an Image as the current image to display. The Image must have
|
|
|
|
* been created by this ImageContainer.
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
* Must be called on the main thread, within a layers transaction.
|
2012-08-19 23:33:25 +04:00
|
|
|
*
|
|
|
|
* This method takes mReentrantMonitor
|
|
|
|
* when accessing thread-shared state.
|
|
|
|
* aImage can be null. While it's null, nothing will be painted.
|
|
|
|
*
|
|
|
|
* The Image data must not be modified after this method is called!
|
|
|
|
* Note that this must not be called if ENABLE_ASYNC been set.
|
|
|
|
*
|
2015-07-03 13:13:48 +03:00
|
|
|
* You won't get meaningful painted/dropped counts when using this method.
|
2012-08-19 23:33:25 +04:00
|
|
|
*/
|
|
|
|
void SetCurrentImageInTransaction(Image* aImage);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this ImageContainer uses the ImageBridge IPDL protocol.
|
|
|
|
*
|
|
|
|
* Can be called from any thread.
|
|
|
|
*/
|
|
|
|
bool IsAsync() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If this ImageContainer uses ImageBridge, returns the ID associated to
|
|
|
|
* this container, for use in the ImageBridge protocol.
|
|
|
|
* Returns 0 if this ImageContainer does not use ImageBridge. Note that
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
* 0 is always an invalid ID for asynchronous image containers.
|
2012-08-19 23:33:25 +04:00
|
|
|
*
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
* Can be called from any thread.
|
2012-08-19 23:33:25 +04:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t GetAsyncContainerID() const;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the container currently has an image.
|
|
|
|
* Can be called on any thread. This method takes mReentrantMonitor
|
|
|
|
* when accessing thread-shared state.
|
|
|
|
*/
|
|
|
|
bool HasCurrentImage();
|
|
|
|
|
2015-03-27 02:07:53 +03:00
|
|
|
struct OwningImage {
|
2015-05-25 05:33:35 +03:00
|
|
|
OwningImage() : mFrameID(0), mProducerID(0), mComposited(false) {}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Image> mImage;
|
2015-07-03 13:37:03 +03:00
|
|
|
TimeStamp mTimeStamp;
|
2015-07-06 06:02:26 +03:00
|
|
|
FrameID mFrameID;
|
|
|
|
ProducerID mProducerID;
|
2015-05-25 05:33:35 +03:00
|
|
|
bool mComposited;
|
2015-03-27 02:07:53 +03:00
|
|
|
};
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
2015-03-27 02:07:53 +03:00
|
|
|
* Copy the current Image list to aImages.
|
|
|
|
* This has to add references since otherwise there are race conditions
|
2012-08-19 23:33:25 +04:00
|
|
|
* where the current image is destroyed before the caller can add
|
2015-05-12 03:56:09 +03:00
|
|
|
* a reference.
|
2015-03-27 02:07:53 +03:00
|
|
|
* Can be called on any thread.
|
|
|
|
* May return an empty list to indicate there is no current image.
|
2015-05-12 03:56:09 +03:00
|
|
|
* If aGenerationCounter is non-null, sets *aGenerationCounter to a value
|
|
|
|
* that's unique for this ImageContainer state.
|
2014-01-15 19:06:43 +04:00
|
|
|
*/
|
2015-05-12 03:56:09 +03:00
|
|
|
void GetCurrentImages(nsTArray<OwningImage>* aImages,
|
|
|
|
uint32_t* aGenerationCounter = nullptr);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the size of the image in pixels.
|
|
|
|
* Can be called on any thread. This method takes mReentrantMonitor when accessing
|
|
|
|
* thread-shared state.
|
|
|
|
*/
|
2013-12-13 21:32:02 +04:00
|
|
|
gfx::IntSize GetCurrentSize();
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a size that the image is expected to be rendered at.
|
|
|
|
* This is a hint for image backends to optimize scaling.
|
|
|
|
* Default implementation in this class is to ignore the hint.
|
|
|
|
* Can be called on any thread. This method takes mReentrantMonitor
|
|
|
|
* when accessing thread-shared state.
|
|
|
|
*/
|
2013-12-20 20:46:29 +04:00
|
|
|
void SetScaleHint(const gfx::IntSize& aScaleHint)
|
2012-08-19 23:33:25 +04:00
|
|
|
{ mScaleHint = aScaleHint; }
|
|
|
|
|
|
|
|
void SetImageFactory(ImageFactory *aFactory)
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
mImageFactory = aFactory ? aFactory : new ImageFactory();
|
|
|
|
}
|
|
|
|
|
2014-06-21 16:32:30 +04:00
|
|
|
ImageFactory* GetImageFactory() const
|
|
|
|
{
|
|
|
|
return mImageFactory;
|
|
|
|
}
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
2015-07-03 10:39:09 +03:00
|
|
|
* Returns the delay between the last composited image's presentation
|
|
|
|
* timestamp and when it was first composited. It's possible for the delay
|
|
|
|
* to be negative if the first image in the list passed to SetCurrentImages
|
|
|
|
* has a presentation timestamp greater than "now".
|
|
|
|
* Returns 0 if the composited image had a null timestamp, or if no
|
|
|
|
* image has been composited yet.
|
2012-08-19 23:33:25 +04:00
|
|
|
*/
|
2015-07-03 10:39:09 +03:00
|
|
|
TimeDuration GetPaintDelay()
|
|
|
|
{
|
2012-08-19 23:33:25 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2015-07-03 10:39:09 +03:00
|
|
|
return mPaintDelay;
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of images which have been contained in this container
|
|
|
|
* and painted at least once. Can be called from any thread.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetPaintCount() {
|
2012-08-19 23:33:25 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
return mPaintCount;
|
|
|
|
}
|
|
|
|
|
2015-05-11 05:07:07 +03:00
|
|
|
/**
|
2015-05-25 05:33:35 +03:00
|
|
|
* An entry in the current image list "expires" when the entry has an
|
|
|
|
* non-null timestamp, and in a SetCurrentImages call the new image list is
|
|
|
|
* non-empty, the timestamp of the first new image is non-null and greater
|
|
|
|
* than the timestamp associated with the image, and the first new image's
|
|
|
|
* frameID is not the same as the entry's.
|
|
|
|
* Every expired image that is never composited is counted as dropped.
|
2015-05-11 05:07:07 +03:00
|
|
|
*/
|
|
|
|
uint32_t GetDroppedImageCount()
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
return mDroppedImageCount;
|
|
|
|
}
|
|
|
|
|
2015-07-06 06:02:26 +03:00
|
|
|
PImageContainerChild* GetPImageContainerChild();
|
|
|
|
static void NotifyComposite(const ImageCompositeNotification& aNotification);
|
|
|
|
|
2015-05-25 05:33:35 +03:00
|
|
|
/**
|
|
|
|
* Main thread only.
|
|
|
|
*/
|
|
|
|
static ProducerID AllocateProducerID();
|
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
private:
|
2012-08-19 23:33:25 +04:00
|
|
|
typedef mozilla::ReentrantMonitor ReentrantMonitor;
|
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2015-07-03 01:19:35 +03:00
|
|
|
B2G_ACL_EXPORT ~ImageContainer();
|
2014-04-04 20:27:02 +04:00
|
|
|
|
2015-05-25 05:33:35 +03:00
|
|
|
void SetCurrentImageInternal(const nsTArray<NonOwningImage>& aImages);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
// This is called to ensure we have an active image, this may not be true
|
|
|
|
// when we're storing image information in a RemoteImageData structure.
|
|
|
|
// NOTE: If we have remote data mRemoteDataMutex should be locked when
|
|
|
|
// calling this function!
|
|
|
|
void EnsureActiveImage();
|
|
|
|
|
2015-07-03 10:39:09 +03:00
|
|
|
void NotifyCompositeInternal(const ImageCompositeNotification& aNotification);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-07-03 10:39:09 +03:00
|
|
|
// ReentrantMonitor to protect thread safe access to the "current
|
|
|
|
// image", and any other state which is shared between threads.
|
|
|
|
ReentrantMonitor mReentrantMonitor;
|
2015-07-06 06:02:26 +03:00
|
|
|
|
2015-05-25 05:33:35 +03:00
|
|
|
nsTArray<OwningImage> mCurrentImages;
|
2015-05-11 05:07:07 +03:00
|
|
|
|
2015-05-12 03:56:09 +03:00
|
|
|
// Updates every time mActiveImage changes
|
|
|
|
uint32_t mGenerationCounter;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
// Number of contained images that have been painted at least once. It's up
|
|
|
|
// to the ImageContainer implementation to ensure accesses to this are
|
|
|
|
// threadsafe.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mPaintCount;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-07-03 10:39:09 +03:00
|
|
|
// See GetPaintDelay. Accessed only with mReentrantMonitor held.
|
|
|
|
TimeDuration mPaintDelay;
|
|
|
|
|
2015-05-11 05:07:07 +03:00
|
|
|
// See GetDroppedImageCount. Accessed only with mReentrantMonitor held.
|
|
|
|
uint32_t mDroppedImageCount;
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
// This is the image factory used by this container, layer managers using
|
|
|
|
// this container can set an alternative image factory that will be used to
|
|
|
|
// create images for this container.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageFactory> mImageFactory;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2013-12-20 20:46:29 +04:00
|
|
|
gfx::IntSize mScaleHint;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BufferRecycleBin> mRecycleBin;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
// This member points to an ImageClient if this ImageContainer was
|
2012-08-19 23:33:25 +04:00
|
|
|
// sucessfully created with ENABLE_ASYNC, or points to null otherwise.
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
// 'unsuccessful' in this case only means that the ImageClient could not
|
2012-08-19 23:33:25 +04:00
|
|
|
// be created, most likely because off-main-thread compositing is not enabled.
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
// In this case the ImageContainer is perfectly usable, but it will forward
|
|
|
|
// frames to the compositor through transactions in the main thread rather than
|
2012-08-19 23:33:25 +04:00
|
|
|
// asynchronusly using the ImageBridge IPDL protocol.
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
ImageClient* mImageClient;
|
2015-05-12 03:56:09 +03:00
|
|
|
|
2015-05-11 05:07:07 +03:00
|
|
|
nsTArray<FrameID> mFrameIDsNotYetComposited;
|
2015-05-25 05:33:35 +03:00
|
|
|
// ProducerID for last current image(s), including the frames in
|
|
|
|
// mFrameIDsNotYetComposited
|
|
|
|
ProducerID mCurrentProducerID;
|
2015-05-11 05:07:07 +03:00
|
|
|
|
2015-07-06 06:02:26 +03:00
|
|
|
// Object must be released on the ImageBridge thread. Field is immutable
|
|
|
|
// after creation of the ImageContainer.
|
|
|
|
ImageContainerChild* mIPDLChild;
|
|
|
|
|
2015-05-12 03:56:09 +03:00
|
|
|
static mozilla::Atomic<uint32_t> sGenerationCounter;
|
2012-08-19 23:33:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class AutoLockImage
|
|
|
|
{
|
|
|
|
public:
|
2015-03-27 02:07:53 +03:00
|
|
|
explicit AutoLockImage(ImageContainer *aContainer)
|
|
|
|
{
|
|
|
|
aContainer->GetCurrentImages(&mImages);
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
|
2015-03-27 02:07:53 +03:00
|
|
|
bool HasImage() const { return !mImages.IsEmpty(); }
|
|
|
|
Image* GetImage() const
|
|
|
|
{
|
|
|
|
return mImages.IsEmpty() ? nullptr : mImages[0].mImage.get();
|
2012-08-19 23:33:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-03-27 02:07:53 +03:00
|
|
|
nsAutoTArray<ImageContainer::OwningImage,4> mImages;
|
2012-08-19 23:33:25 +04:00
|
|
|
};
|
|
|
|
|
2013-10-02 04:57:50 +04:00
|
|
|
struct PlanarYCbCrData {
|
|
|
|
// Luminance buffer
|
|
|
|
uint8_t* mYChannel;
|
|
|
|
int32_t mYStride;
|
2013-12-20 20:46:29 +04:00
|
|
|
gfx::IntSize mYSize;
|
2013-10-02 04:57:50 +04:00
|
|
|
int32_t mYSkip;
|
|
|
|
// Chroma buffers
|
|
|
|
uint8_t* mCbChannel;
|
|
|
|
uint8_t* mCrChannel;
|
|
|
|
int32_t mCbCrStride;
|
2013-12-20 20:46:29 +04:00
|
|
|
gfx::IntSize mCbCrSize;
|
2013-10-02 04:57:50 +04:00
|
|
|
int32_t mCbSkip;
|
|
|
|
int32_t mCrSkip;
|
|
|
|
// Picture region
|
|
|
|
uint32_t mPicX;
|
|
|
|
uint32_t mPicY;
|
2013-12-20 20:46:29 +04:00
|
|
|
gfx::IntSize mPicSize;
|
2013-10-02 04:57:50 +04:00
|
|
|
StereoMode mStereoMode;
|
|
|
|
|
2015-05-07 12:07:53 +03:00
|
|
|
gfx::IntRect GetPictureRect() const {
|
|
|
|
return gfx::IntRect(mPicX, mPicY,
|
2013-10-02 04:57:50 +04:00
|
|
|
mPicSize.width,
|
|
|
|
mPicSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
PlanarYCbCrData()
|
|
|
|
: mYChannel(nullptr), mYStride(0), mYSize(0, 0), mYSkip(0)
|
|
|
|
, mCbChannel(nullptr), mCrChannel(nullptr)
|
|
|
|
, mCbCrStride(0), mCbCrSize(0, 0) , mCbSkip(0), mCrSkip(0)
|
2014-01-31 02:58:49 +04:00
|
|
|
, mPicX(0), mPicY(0), mPicSize(0, 0), mStereoMode(StereoMode::MONO)
|
2013-10-02 04:57:50 +04:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
/****** Image subtypes for the different formats ******/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We assume that the image data is in the REC 470M color space (see
|
|
|
|
* Theora specification, section 4.3.1).
|
|
|
|
*
|
|
|
|
* The YCbCr format can be:
|
|
|
|
*
|
|
|
|
* 4:4:4 - CbCr width/height are the same as Y.
|
|
|
|
* 4:2:2 - CbCr width is half that of Y. Height is the same.
|
|
|
|
* 4:2:0 - CbCr width and height is half that of Y.
|
|
|
|
*
|
|
|
|
* The color format is detected based on the height/width ratios
|
|
|
|
* defined above.
|
|
|
|
*
|
|
|
|
* The Image that is rendered is the picture region defined by
|
|
|
|
* mPicX, mPicY and mPicSize. The size of the rendered image is
|
|
|
|
* mPicSize, not mYSize or mCbCrSize.
|
2012-08-21 14:18:20 +04:00
|
|
|
*
|
2012-08-26 07:22:51 +04:00
|
|
|
* mYSkip, mCbSkip, mCrSkip are added to support various output
|
|
|
|
* formats from hardware decoder. They are per-pixel skips in the
|
2012-08-21 14:18:20 +04:00
|
|
|
* source image.
|
2012-08-26 07:22:51 +04:00
|
|
|
*
|
|
|
|
* For example when image width is 640, mYStride is 670, mYSkip is 3,
|
|
|
|
* the mYChannel buffer looks like:
|
|
|
|
*
|
|
|
|
* |<----------------------- mYStride ----------------------------->|
|
|
|
|
* |<----------------- mYSize.width --------------->|
|
|
|
|
* 0 3 6 9 12 15 18 21 659 669
|
|
|
|
* |----------------------------------------------------------------|
|
|
|
|
* |Y___Y___Y___Y___Y___Y___Y___Y... |%%%%%%%%%|
|
|
|
|
* |Y___Y___Y___Y___Y___Y___Y___Y... |%%%%%%%%%|
|
|
|
|
* |Y___Y___Y___Y___Y___Y___Y___Y... |%%%%%%%%%|
|
|
|
|
* | |<->|
|
|
|
|
* mYSkip
|
2012-08-19 23:33:25 +04:00
|
|
|
*/
|
2013-05-30 01:59:24 +04:00
|
|
|
class PlanarYCbCrImage : public Image {
|
2012-08-19 23:33:25 +04:00
|
|
|
public:
|
2013-10-02 04:57:50 +04:00
|
|
|
typedef PlanarYCbCrData Data;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
enum {
|
|
|
|
MAX_DIMENSION = 16384
|
|
|
|
};
|
|
|
|
|
2015-11-06 21:55:31 +03:00
|
|
|
virtual ~PlanarYCbCrImage() {}
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
/**
|
2012-08-23 21:01:14 +04:00
|
|
|
* This makes a copy of the data buffers, in order to support functioning
|
|
|
|
* in all different layer managers.
|
2012-08-19 23:33:25 +04:00
|
|
|
*/
|
2015-11-06 21:55:31 +03:00
|
|
|
virtual bool SetData(const Data& aData) = 0;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2013-03-14 00:11:15 +04:00
|
|
|
/**
|
|
|
|
* This doesn't make a copy of the data buffers. Can be used when mBuffer is
|
|
|
|
* pre allocated with AllocateAndGetNewBuffer(size) and then SetDataNoCopy is
|
|
|
|
* called to only update the picture size, planes etc. fields in mData.
|
|
|
|
* The GStreamer media backend uses this to decode into PlanarYCbCrImage(s)
|
|
|
|
* directly.
|
|
|
|
*/
|
2015-11-03 14:24:26 +03:00
|
|
|
virtual bool SetDataNoCopy(const Data &aData);
|
2013-03-14 00:11:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This allocates and returns a new buffer
|
|
|
|
*/
|
2015-11-06 21:55:31 +03:00
|
|
|
virtual uint8_t* AllocateAndGetNewBuffer(uint32_t aSize) = 0;
|
2013-03-14 00:11:15 +04:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
|
|
|
* Ask this Image to not convert YUV to RGB during SetData, and make
|
|
|
|
* the original data available through GetData. This is optional,
|
|
|
|
* and not all PlanarYCbCrImages will support it.
|
|
|
|
*/
|
|
|
|
virtual void SetDelayedConversion(bool aDelayed) { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Grab the original YUV data. This is optional.
|
|
|
|
*/
|
|
|
|
virtual const Data* GetData() { return &mData; }
|
|
|
|
|
2012-08-21 14:18:20 +04:00
|
|
|
/**
|
|
|
|
* Return the number of bytes of heap memory used to store this image.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual uint32_t GetDataSize() { return mBufferSize; }
|
2012-08-21 14:18:20 +04:00
|
|
|
|
|
|
|
virtual bool IsValid() { return !!mBufferSize; }
|
|
|
|
|
2013-12-13 21:32:02 +04:00
|
|
|
virtual gfx::IntSize GetSize() { return mSize; }
|
2012-08-21 14:18:20 +04:00
|
|
|
|
2015-11-06 21:55:31 +03:00
|
|
|
explicit PlanarYCbCrImage();
|
2012-08-21 14:18:20 +04:00
|
|
|
|
2012-11-05 14:38:03 +04:00
|
|
|
virtual SharedPlanarYCbCrImage *AsSharedPlanarYCbCrImage() { return nullptr; }
|
|
|
|
|
2014-03-20 01:33:12 +04:00
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2015-11-06 21:55:31 +03:00
|
|
|
virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const = 0;
|
2014-03-20 01:33:12 +04:00
|
|
|
|
2015-11-06 21:55:31 +03:00
|
|
|
protected:
|
|
|
|
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface();
|
|
|
|
|
|
|
|
void SetOffscreenFormat(gfxImageFormat aFormat) { mOffscreenFormat = aFormat; }
|
|
|
|
gfxImageFormat GetOffscreenFormat();
|
|
|
|
|
|
|
|
Data mData;
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
gfxImageFormat mOffscreenFormat;
|
|
|
|
nsCountedRef<nsMainThreadSourceSurfaceRef> mSourceSurface;
|
|
|
|
uint32_t mBufferSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RecyclingPlanarYCbCrImage: public PlanarYCbCrImage {
|
|
|
|
public:
|
|
|
|
explicit RecyclingPlanarYCbCrImage(BufferRecycleBin *aRecycleBin) : mRecycleBin(aRecycleBin) {}
|
|
|
|
virtual ~RecyclingPlanarYCbCrImage() override;
|
|
|
|
virtual bool SetData(const Data& aData) override;
|
|
|
|
virtual uint8_t* AllocateAndGetNewBuffer(uint32_t aSize) override;
|
|
|
|
virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
|
2012-08-21 14:18:20 +04:00
|
|
|
protected:
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
|
|
|
* Make a copy of the YCbCr data into local storage.
|
|
|
|
*
|
|
|
|
* @param aData Input image data.
|
|
|
|
*/
|
2015-11-03 14:24:26 +03:00
|
|
|
bool CopyData(const Data& aData);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a buffer to store image data in.
|
|
|
|
*/
|
2015-10-20 20:16:04 +03:00
|
|
|
mozilla::UniquePtr<uint8_t[]> AllocateBuffer(uint32_t aSize);
|
2015-11-05 02:39:35 +03:00
|
|
|
|
|
|
|
RefPtr<BufferRecycleBin> mRecycleBin;
|
2015-10-20 20:16:04 +03:00
|
|
|
mozilla::UniquePtr<uint8_t[]> mBuffer;
|
2012-08-19 23:33:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Currently, the data in a CairoImage surface is treated as being in the
|
|
|
|
* device output color space. This class is very simple as all backends
|
|
|
|
* have to know about how to deal with drawing a cairo image.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class CairoImage final : public Image {
|
2012-08-19 23:33:25 +04:00
|
|
|
public:
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override
|
2014-01-17 20:22:09 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfx::SourceSurface> surface(mSourceSurface);
|
2015-04-30 22:20:30 +03:00
|
|
|
return surface.forget();
|
2014-01-17 20:22:09 +04:00
|
|
|
}
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual TextureClient* GetTextureClient(CompositableClient* aClient) override;
|
2014-02-17 02:23:39 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual gfx::IntSize GetSize() override { return mSize; }
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
CairoImage(const gfx::IntSize& aSize, gfx::SourceSurface* aSourceSurface);
|
2014-02-17 02:23:39 +04:00
|
|
|
~CairoImage();
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
private:
|
2013-12-20 20:46:29 +04:00
|
|
|
gfx::IntSize mSize;
|
2014-01-17 20:22:09 +04:00
|
|
|
nsCountedRef<nsMainThreadSourceSurfaceRef> mSourceSurface;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsDataHashtable<nsUint32HashKey, RefPtr<TextureClient> > mTextureClients;
|
2012-08-19 23:33:25 +04:00
|
|
|
};
|
|
|
|
|
2014-08-19 06:14:00 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
class OverlayImage : public Image {
|
|
|
|
/**
|
|
|
|
* OverlayImage is a special Image type that does not hold any buffer.
|
|
|
|
* It only hold an Id as identifier to the real content of the Image.
|
|
|
|
* Therefore, OverlayImage must be handled by some specialized hardware(e.g. HWC)
|
|
|
|
* to show its content.
|
|
|
|
*/
|
|
|
|
public:
|
|
|
|
struct Data {
|
|
|
|
int32_t mOverlayId;
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
OverlayImage() : Image(nullptr, ImageFormat::OVERLAY_IMAGE) { mOverlayId = INVALID_OVERLAY; }
|
|
|
|
|
|
|
|
void SetData(const Data& aData)
|
|
|
|
{
|
|
|
|
mOverlayId = aData.mOverlayId;
|
|
|
|
mSize = aData.mSize;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() { return nullptr; } ;
|
2014-08-19 06:14:00 +04:00
|
|
|
int32_t GetOverlayId() { return mOverlayId; }
|
|
|
|
|
|
|
|
gfx::IntSize GetSize() { return mSize; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t mOverlayId;
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-05-07 12:07:53 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2012-08-21 14:18:20 +04:00
|
|
|
#endif
|