2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-08-19 23:33:25 +04:00
|
|
|
* 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
|
2017-07-04 20:47:42 +03:00
|
|
|
#include "mozilla/RecursiveMutex.h" // for RecursiveMutex, etc
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/TimeStamp.h" // for TimeStamp
|
2013-12-13 21:32:02 +04:00
|
|
|
#include "mozilla/gfx/Point.h" // For IntSize
|
2018-09-25 23:44:55 +03:00
|
|
|
#include "mozilla/gfx/Types.h" // For ColorDepth
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/LayersTypes.h" // for LayersBackend, etc
|
2016-09-23 00:43:11 +03:00
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#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.
|
|
|
|
*/
|
2016-04-26 03:23:21 +03:00
|
|
|
class SurfaceReleaser : public mozilla::Runnable {
|
2014-01-17 20:22:09 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit SurfaceReleaser(RawRef aRef)
|
|
|
|
: mozilla::Runnable(
|
|
|
|
"nsAutoRefTraits<nsMainThreadSourceSurfaceRef>::SurfaceReleaser"),
|
|
|
|
mRef(aRef) {}
|
2017-11-30 21:03:02 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2014-01-17 20:22:09 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-18 09:52:16 +03:00
|
|
|
class nsOwningThreadSourceSurfaceRef;
|
|
|
|
|
|
|
|
template <>
|
2017-11-30 21:03:02 +03:00
|
|
|
class nsAutoRefTraits<nsOwningThreadSourceSurfaceRef> {
|
2015-12-18 09:52:16 +03:00
|
|
|
public:
|
|
|
|
typedef mozilla::gfx::SourceSurface* RawRef;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The XPCOM event that will do the actual release on the creation thread.
|
|
|
|
*/
|
2017-11-30 21:03:02 +03:00
|
|
|
class SurfaceReleaser : public mozilla::Runnable {
|
2015-12-18 09:52:16 +03:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit SurfaceReleaser(RawRef aRef)
|
|
|
|
: mozilla::Runnable(
|
|
|
|
"nsAutoRefTraits<nsOwningThreadSourceSurfaceRef>::"
|
|
|
|
"SurfaceReleaser"),
|
|
|
|
mRef(aRef) {}
|
2017-11-30 21:03:02 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-12-18 09:52:16 +03:00
|
|
|
mRef->Release();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
RawRef mRef;
|
|
|
|
};
|
|
|
|
|
|
|
|
static RawRef Void() { return nullptr; }
|
|
|
|
void Release(RawRef aRawRef) {
|
2017-06-01 23:43:00 +03:00
|
|
|
MOZ_ASSERT(mOwningEventTarget);
|
|
|
|
if (mOwningEventTarget->IsOnCurrentThread()) {
|
2015-12-18 09:52:16 +03:00
|
|
|
aRawRef->Release();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIRunnable> runnable = new SurfaceReleaser(aRawRef);
|
2017-06-01 23:43:00 +03:00
|
|
|
mOwningEventTarget->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
|
2015-12-18 09:52:16 +03:00
|
|
|
}
|
|
|
|
void AddRef(RawRef aRawRef) {
|
2017-06-01 23:43:00 +03:00
|
|
|
MOZ_ASSERT(!mOwningEventTarget);
|
|
|
|
mOwningEventTarget = mozilla::GetCurrentThreadSerialEventTarget();
|
2015-12-18 09:52:16 +03:00
|
|
|
aRawRef->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-06-01 23:43:00 +03:00
|
|
|
nsCOMPtr<nsISerialEventTarget> mOwningEventTarget;
|
2015-12-18 09:52:16 +03:00
|
|
|
};
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
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;
|
2017-01-14 01:51:40 +03:00
|
|
|
class ImageContainer;
|
2015-07-06 06:02:26 +03:00
|
|
|
class ImageContainerChild;
|
2012-11-05 14:38:03 +04:00
|
|
|
class SharedPlanarYCbCrImage;
|
2018-10-02 20:28:22 +03:00
|
|
|
class SharedSurfacesAnimation;
|
2015-11-17 11:09:01 +03:00
|
|
|
class PlanarYCbCrImage;
|
2013-07-30 13:59:51 +04:00
|
|
|
class TextureClient;
|
2016-09-27 06:22:20 +03:00
|
|
|
class KnowsCompositor;
|
2016-03-10 05:35:27 +03:00
|
|
|
class NVImage;
|
2017-05-04 00:23:45 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
class D3D11YCbCrRecycleAllocator;
|
|
|
|
#endif
|
2018-11-14 21:05:28 +03:00
|
|
|
class SurfaceDescriptorBuffer;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
struct ImageBackendData {
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~ImageBackendData() = default;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ImageBackendData() {}
|
|
|
|
};
|
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
/* Forward declarations for Image derivatives. */
|
2016-08-23 10:44:40 +03:00
|
|
|
class GLImage;
|
2015-11-17 11:09:01 +03:00
|
|
|
class SharedRGBImage;
|
2015-11-17 11:09:00 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
class SurfaceTextureImage;
|
2015-11-17 11:09:01 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
2015-11-17 11:09:00 +03:00
|
|
|
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.
|
2017-04-12 12:55:23 +03:00
|
|
|
*
|
2012-08-19 23:33:25 +04:00
|
|
|
* 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.
|
2017-04-12 12:55:23 +03:00
|
|
|
*
|
2012-08-19 23:33:25 +04:00
|
|
|
* When resampling an Image, only pixels within the buffer should be
|
|
|
|
* sampled. For example, cairo images should be sampled in EXTEND_PAD mode.
|
|
|
|
*/
|
2017-11-30 21:03:02 +03:00
|
|
|
class Image {
|
2012-08-19 23:33:25 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Image)
|
|
|
|
|
|
|
|
public:
|
2017-11-30 21:03:02 +03:00
|
|
|
ImageFormat GetFormat() const { return mFormat; }
|
|
|
|
void* GetImplData() const { return mImplData; }
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
virtual gfx::IntSize GetSize() const = 0;
|
|
|
|
virtual gfx::IntPoint GetOrigin() const { return gfx::IntPoint(0, 0); }
|
|
|
|
virtual gfx::IntRect GetPictureRect() const {
|
2016-05-23 03:37:43 +03:00
|
|
|
return gfx::IntRect(GetOrigin().x, GetOrigin().y, GetSize().width,
|
|
|
|
GetSize().height);
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
ImageBackendData* GetBackendData(LayersBackend aBackend) {
|
2017-11-30 21:03:02 +03:00
|
|
|
return mBackendData[aBackend];
|
|
|
|
}
|
2012-08-19 23:33:25 +04:00
|
|
|
void SetBackendData(LayersBackend aBackend, ImageBackendData* aData) {
|
2017-11-30 21:03:02 +03:00
|
|
|
mBackendData[aBackend] = aData;
|
|
|
|
}
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
int32_t GetSerial() const { 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
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
virtual bool IsValid() const { return true; }
|
2015-03-12 12:13:23 +03:00
|
|
|
|
2015-03-19 00:15:38 +03:00
|
|
|
/**
|
2016-09-23 00:43:11 +03:00
|
|
|
* For use with the TextureForwarder only (so that the later can
|
2015-11-17 11:09:00 +03:00
|
|
|
* synchronize the TextureClient with the TextureHost).
|
|
|
|
*/
|
2019-06-07 15:27:05 +03:00
|
|
|
virtual TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) {
|
2017-11-30 21:03:02 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-03-19 00:15:38 +03:00
|
|
|
|
2015-11-17 11:09:00 +03:00
|
|
|
/* Access to derived classes. */
|
2016-08-23 10:44:40 +03:00
|
|
|
virtual GLImage* AsGLImage() { 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:01 +03:00
|
|
|
virtual PlanarYCbCrImage* AsPlanarYCbCrImage() { return nullptr; }
|
2015-11-17 11:09:00 +03:00
|
|
|
|
2016-03-10 05:35:27 +03:00
|
|
|
virtual NVImage* AsNVImage() { return nullptr; }
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
protected:
|
|
|
|
Image(void* aImplData, ImageFormat aFormat)
|
2013-08-12 13:51:49 +04:00
|
|
|
: mImplData(aImplData), mSerial(++sSerialCounter), 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():
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~Image() = default;
|
2014-04-04 20:27:02 +04:00
|
|
|
|
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;
|
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
|
2017-04-12 12:55:23 +03:00
|
|
|
* want to recycle from one image to the next.It's a separate object from
|
2012-08-19 23:33:25 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2017-11-30 21:03:02 +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);
|
2016-06-28 04:25:01 +03:00
|
|
|
virtual void ClearRecycledBuffers();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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() {}
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~ImageFactory() = default;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-11-17 11:09:01 +03:00
|
|
|
virtual RefPtr<PlanarYCbCrImage> CreatePlanarYCbCrImage(
|
|
|
|
const gfx::IntSize& aScaleHint, BufferRecycleBin* aRecycleBin);
|
2012-08-19 23:33:25 +04:00
|
|
|
};
|
2017-01-14 01:51:40 +03:00
|
|
|
|
|
|
|
// Used to notify ImageContainer::NotifyComposite()
|
2017-11-30 21:03:02 +03:00
|
|
|
class ImageContainerListener final {
|
2017-01-14 01:51:40 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageContainerListener)
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ImageContainerListener(ImageContainer* aImageContainer);
|
|
|
|
|
|
|
|
void NotifyComposite(const ImageCompositeNotification& aNotification);
|
2018-07-17 00:19:09 +03:00
|
|
|
void NotifyDropped(uint32_t aDropped);
|
2017-01-14 01:51:40 +03:00
|
|
|
void ClearImageContainer();
|
2017-09-26 03:58:37 +03:00
|
|
|
void DropImageClient();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-01-14 01:51:40 +03:00
|
|
|
private:
|
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
|
|
|
~ImageContainerListener();
|
|
|
|
|
|
|
|
Mutex mLock;
|
|
|
|
ImageContainer* mImageContainer;
|
|
|
|
};
|
2017-04-12 12:55:23 +03:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
2016-09-07 01:19:35 +03:00
|
|
|
class ImageContainer final : public SupportsWeakPtr<ImageContainer> {
|
|
|
|
friend class ImageContainerChild;
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageContainer)
|
2016-09-07 01:19:35 +03:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
public:
|
2015-04-24 19:43:01 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ImageContainer)
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-12-29 12:07:33 +03:00
|
|
|
enum Mode { SYNCHRONOUS = 0x0, ASYNCHRONOUS = 0x01 };
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2016-07-18 11:54:01 +03:00
|
|
|
static const uint64_t sInvalidAsyncContainerId = 0;
|
|
|
|
|
2015-05-28 02:35:00 +03:00
|
|
|
explicit ImageContainer(ImageContainer::Mode flag = SYNCHRONOUS);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2016-07-18 11:54:01 +03:00
|
|
|
/**
|
|
|
|
* Create ImageContainer just to hold another ASYNCHRONOUS ImageContainer's
|
|
|
|
* async container ID.
|
|
|
|
* @param aAsyncContainerID async container ID for which we are a proxy
|
|
|
|
*/
|
2017-01-18 05:47:05 +03:00
|
|
|
explicit ImageContainer(const CompositableHandle& aHandle);
|
2016-07-18 11:54:01 +03:00
|
|
|
|
2019-02-13 22:13:55 +03:00
|
|
|
typedef ContainerFrameID FrameID;
|
|
|
|
typedef ContainerProducerID ProducerID;
|
2015-07-06 06:02:26 +03:00
|
|
|
|
2015-11-17 11:09:01 +03:00
|
|
|
RefPtr<PlanarYCbCrImage> CreatePlanarYCbCrImage();
|
|
|
|
|
|
|
|
// Factory methods for shared image types.
|
|
|
|
RefPtr<SharedRGBImage> CreateSharedRGBImage();
|
|
|
|
|
2017-11-30 21:03:02 +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.
|
2017-07-04 20:47:42 +03:00
|
|
|
* Can be called on any thread. This method takes mRecursiveMutex
|
2012-08-19 23:33:25 +04:00
|
|
|
* 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.
|
2017-04-12 12:55:23 +03:00
|
|
|
*
|
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
|
2017-07-04 20:47:42 +03:00
|
|
|
* mRecursiveMutex.
|
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
|
|
|
* 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();
|
|
|
|
|
2016-06-28 04:25:01 +03:00
|
|
|
/**
|
|
|
|
* Clear any resources that are not immediately necessary. This may be called
|
|
|
|
* in low-memory conditions.
|
|
|
|
*/
|
|
|
|
void ClearCachedResources();
|
|
|
|
|
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.
|
2017-04-12 12:55:23 +03:00
|
|
|
*
|
2017-07-04 20:47:42 +03:00
|
|
|
* This method takes mRecursiveMutex
|
2012-08-19 23:33:25 +04:00
|
|
|
* when accessing thread-shared state.
|
|
|
|
* aImage can be null. While it's null, nothing will be painted.
|
2017-04-12 12:55:23 +03:00
|
|
|
*
|
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 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);
|
2016-01-12 07:14:09 +03:00
|
|
|
void SetCurrentImagesInTransaction(const nsTArray<NonOwningImage>& aImages);
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2017-01-18 05:47:05 +03:00
|
|
|
CompositableHandle GetAsyncContainerHandle();
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the container currently has an image.
|
2017-07-04 20:47:42 +03:00
|
|
|
* Can be called on any thread. This method takes mRecursiveMutex
|
2012-08-19 23:33:25 +04:00
|
|
|
* 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.
|
2017-07-04 20:47:42 +03:00
|
|
|
* Can be called on any thread. This method takes mRecursiveMutex when
|
2012-08-19 23:33:25 +04:00
|
|
|
* 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.
|
2017-07-04 20:47:42 +03:00
|
|
|
* Can be called on any thread. This method takes mRecursiveMutex
|
2012-08-19 23:33:25 +04:00
|
|
|
* when accessing thread-shared state.
|
|
|
|
*/
|
2017-11-30 21:03:02 +03:00
|
|
|
void SetScaleHint(const gfx::IntSize& aScaleHint) { mScaleHint = aScaleHint; }
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
const gfx::IntSize& GetScaleHint() const { return mScaleHint; }
|
2017-08-07 05:09:50 +03:00
|
|
|
|
2018-06-13 20:40:23 +03:00
|
|
|
void SetTransformHint(const gfx::Matrix& aTransformHint) {
|
|
|
|
mTransformHint = aTransformHint;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gfx::Matrix& GetTransformHint() const { return mTransformHint; }
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
void SetImageFactory(ImageFactory* aFactory) {
|
2017-07-04 20:47:42 +03:00
|
|
|
RecursiveMutexAutoLock lock(mRecursiveMutex);
|
2012-08-19 23:33:25 +04:00
|
|
|
mImageFactory = aFactory ? aFactory : new ImageFactory();
|
|
|
|
}
|
|
|
|
|
2014-06-21 16:32:30 +04:00
|
|
|
ImageFactory* GetImageFactory() const { return mImageFactory; }
|
|
|
|
|
2017-05-04 00:23:45 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
D3D11YCbCrRecycleAllocator* GetD3D11YCbCrRecycleAllocator(
|
|
|
|
KnowsCompositor* aAllocator);
|
|
|
|
#endif
|
|
|
|
|
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() {
|
2017-07-04 20:47:42 +03:00
|
|
|
RecursiveMutexAutoLock lock(mRecursiveMutex);
|
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.
|
|
|
|
*/
|
2017-11-30 21:03:02 +03:00
|
|
|
uint32_t GetPaintCount() {
|
2017-07-04 20:47:42 +03:00
|
|
|
RecursiveMutexAutoLock lock(mRecursiveMutex);
|
2012-08-19 23:33:25 +04:00
|
|
|
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() { return mDroppedImageCount; }
|
|
|
|
|
2017-01-04 18:19:30 +03:00
|
|
|
void NotifyComposite(const ImageCompositeNotification& aNotification);
|
2018-07-17 00:19:09 +03:00
|
|
|
void NotifyDropped(uint32_t aDropped);
|
2017-01-04 18:19:30 +03:00
|
|
|
|
2017-01-14 01:51:40 +03:00
|
|
|
ImageContainerListener* GetImageContainerListener() {
|
|
|
|
return mNotifyCompositeListener;
|
|
|
|
}
|
|
|
|
|
2017-07-15 14:52:02 +03:00
|
|
|
/**
|
|
|
|
* Get the ImageClient associated with this container. Returns only after
|
|
|
|
* validating, and it will recreate the image client if that fails.
|
|
|
|
* Returns nullptr if not applicable.
|
|
|
|
*/
|
|
|
|
already_AddRefed<ImageClient> GetImageClient();
|
|
|
|
|
2015-05-25 05:33:35 +03:00
|
|
|
/**
|
|
|
|
* Main thread only.
|
|
|
|
*/
|
|
|
|
static ProducerID AllocateProducerID();
|
|
|
|
|
2017-09-22 02:21:09 +03:00
|
|
|
void DropImageClient();
|
|
|
|
|
2018-10-02 20:28:22 +03:00
|
|
|
SharedSurfacesAnimation* GetSharedSurfacesAnimation() const {
|
|
|
|
return mSharedAnimation;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedSurfacesAnimation* EnsureSharedSurfacesAnimation();
|
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
private:
|
2017-07-04 20:47:42 +03:00
|
|
|
typedef mozilla::RecursiveMutex RecursiveMutex;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2016-04-07 19:50:01 +03:00
|
|
|
~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();
|
|
|
|
|
2017-02-02 10:51:51 +03:00
|
|
|
void EnsureImageClient();
|
2016-10-03 11:20:42 +03:00
|
|
|
|
2017-07-04 20:47:42 +03:00
|
|
|
// RecursiveMutex to protect thread safe access to the "current
|
2015-07-03 10:39:09 +03:00
|
|
|
// image", and any other state which is shared between threads.
|
2017-07-04 20:47:42 +03:00
|
|
|
RecursiveMutex mRecursiveMutex;
|
2015-07-06 06:02:26 +03:00
|
|
|
|
2017-05-04 00:23:45 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
RefPtr<D3D11YCbCrRecycleAllocator> mD3D11YCbCrRecycleAllocator;
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2017-07-04 20:47:42 +03:00
|
|
|
// See GetPaintDelay. Accessed only with mRecursiveMutex held.
|
2015-07-03 10:39:09 +03:00
|
|
|
TimeDuration mPaintDelay;
|
|
|
|
|
2018-07-17 00:19:09 +03:00
|
|
|
// See GetDroppedImageCount.
|
|
|
|
mozilla::Atomic<uint32_t> mDroppedImageCount;
|
2015-05-11 05:07:07 +03:00
|
|
|
|
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
|
|
|
|
2018-06-13 20:40:23 +03:00
|
|
|
gfx::Matrix mTransformHint;
|
|
|
|
|
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
|
2012-08-19 23:33:25 +04:00
|
|
|
// than asynchronusly using the ImageBridge IPDL protocol.
|
2016-09-03 02:08:49 +03:00
|
|
|
RefPtr<ImageClient> mImageClient;
|
2015-05-12 03:56:09 +03:00
|
|
|
|
2018-10-03 15:19:14 +03:00
|
|
|
RefPtr<SharedSurfacesAnimation> mSharedAnimation;
|
2018-10-02 20:28:22 +03:00
|
|
|
|
2017-02-02 10:51:51 +03:00
|
|
|
bool mIsAsync;
|
2017-01-18 05:47:05 +03:00
|
|
|
CompositableHandle mAsyncContainerHandle;
|
2016-07-18 11:54:01 +03:00
|
|
|
|
2018-07-17 00:25:12 +03:00
|
|
|
// ProducerID for last current image(s)
|
2015-05-25 05:33:35 +03:00
|
|
|
ProducerID mCurrentProducerID;
|
2015-05-11 05:07:07 +03:00
|
|
|
|
2017-01-14 01:51:40 +03:00
|
|
|
RefPtr<ImageContainerListener> mNotifyCompositeListener;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-06-30 21:57:14 +03:00
|
|
|
Image* GetImage(TimeStamp aTimeStamp) const {
|
|
|
|
if (mImages.IsEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!aTimeStamp.IsNull());
|
|
|
|
uint32_t chosenIndex = 0;
|
|
|
|
|
|
|
|
while (chosenIndex + 1 < mImages.Length() &&
|
|
|
|
mImages[chosenIndex + 1].mTimeStamp <= aTimeStamp) {
|
|
|
|
++chosenIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mImages[chosenIndex].mImage.get();
|
|
|
|
}
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
private:
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<ImageContainer::OwningImage, 4> mImages;
|
2012-08-19 23:33:25 +04:00
|
|
|
};
|
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
struct PlanarYCbCrData {
|
2013-10-02 04:57:50 +04:00
|
|
|
// Luminance buffer
|
2019-07-26 11:40:33 +03:00
|
|
|
uint8_t* mYChannel;
|
|
|
|
int32_t mYStride;
|
|
|
|
gfx::IntSize mYSize;
|
|
|
|
int32_t mYSkip;
|
2013-10-02 04:57:50 +04:00
|
|
|
// Chroma buffers
|
2019-07-26 11:40:33 +03:00
|
|
|
uint8_t* mCbChannel;
|
|
|
|
uint8_t* mCrChannel;
|
|
|
|
int32_t mCbCrStride;
|
|
|
|
gfx::IntSize mCbCrSize;
|
|
|
|
int32_t mCbSkip;
|
|
|
|
int32_t mCrSkip;
|
2013-10-02 04:57:50 +04:00
|
|
|
// Picture region
|
2019-07-26 11:40:33 +03:00
|
|
|
uint32_t mPicX;
|
|
|
|
uint32_t mPicY;
|
|
|
|
gfx::IntSize mPicSize;
|
|
|
|
StereoMode mStereoMode;
|
|
|
|
gfx::YUVColorSpace mYUVColorSpace;
|
|
|
|
gfx::ColorDepth mColorDepth;
|
2013-10-02 04:57:50 +04:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
gfx::IntRect GetPictureRect() const {
|
2015-05-07 12:07:53 +03:00
|
|
|
return gfx::IntRect(mPicX, mPicY, mPicSize.width, mPicSize.height);
|
2013-10-02 04:57:50 +04:00
|
|
|
}
|
2019-07-26 11:40:33 +03:00
|
|
|
|
|
|
|
PlanarYCbCrData()
|
|
|
|
: mYChannel(nullptr),
|
|
|
|
mYStride(0),
|
|
|
|
mYSize(0, 0),
|
|
|
|
mYSkip(0),
|
|
|
|
mCbChannel(nullptr),
|
|
|
|
mCrChannel(nullptr),
|
|
|
|
mCbCrStride(0),
|
|
|
|
mCbCrSize(0, 0),
|
|
|
|
mCbSkip(0),
|
|
|
|
mCrSkip(0),
|
|
|
|
mPicX(0),
|
|
|
|
mPicY(0),
|
|
|
|
mPicSize(0, 0),
|
|
|
|
mStereoMode(StereoMode::MONO),
|
|
|
|
mYUVColorSpace(gfx::YUVColorSpace::BT601),
|
|
|
|
mColorDepth(gfx::ColorDepth::COLOR_8) {}
|
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.
|
2017-04-12 12:55:23 +03:00
|
|
|
*
|
2012-08-19 23:33:25 +04:00
|
|
|
* 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
|
|
|
*/
|
2017-11-30 21:03:02 +03: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 };
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~PlanarYCbCrImage() = default;
|
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
|
|
|
*/
|
2016-04-19 06:12:41 +03:00
|
|
|
virtual bool CopyData(const Data& aData) = 0;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2013-03-14 00:11:15 +04:00
|
|
|
/**
|
2017-10-04 04:26:45 +03:00
|
|
|
* This doesn't make a copy of the data buffers.
|
2013-03-14 00:11:15 +04:00
|
|
|
*/
|
2017-10-04 04:26:45 +03:00
|
|
|
virtual bool AdoptData(const Data& aData);
|
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.
|
|
|
|
*/
|
2017-11-30 21:03:02 +03:00
|
|
|
virtual void SetDelayedConversion(bool aDelayed) {}
|
2012-08-19 23:33:25 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Grab the original YUV data. This is optional.
|
|
|
|
*/
|
2017-11-30 21:03:02 +03:00
|
|
|
virtual const Data* GetData() const { return &mData; }
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2012-08-21 14:18:20 +04:00
|
|
|
/**
|
|
|
|
* Return the number of bytes of heap memory used to store this image.
|
|
|
|
*/
|
2017-11-30 21:03:02 +03:00
|
|
|
uint32_t GetDataSize() const { return mBufferSize; }
|
2012-08-21 14:18:20 +04:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
bool IsValid() const override { return !!mBufferSize; }
|
2012-08-21 14:18:20 +04:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
gfx::IntSize GetSize() const override { return mSize; }
|
2016-05-23 03:37:43 +03:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
gfx::IntPoint GetOrigin() const override { return mOrigin; }
|
2012-08-21 14:18:20 +04:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
PlanarYCbCrImage();
|
2012-11-05 14:38:03 +04:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
2014-03-20 01:33:12 +04:00
|
|
|
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
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
PlanarYCbCrImage* AsPlanarYCbCrImage() override { return this; }
|
2015-11-17 11:09:01 +03:00
|
|
|
|
2018-11-14 21:05:28 +03:00
|
|
|
/**
|
|
|
|
* Build a SurfaceDescriptorBuffer with this image. The provided
|
|
|
|
* SurfaceDescriptorBuffer must already have a valid MemoryOrShmem set
|
|
|
|
* with a capacity large enough to hold |GetDataSize|.
|
|
|
|
*/
|
|
|
|
virtual nsresult BuildSurfaceDescriptorBuffer(
|
|
|
|
SurfaceDescriptorBuffer& aSdBuffer);
|
|
|
|
|
2015-11-06 21:55:31 +03:00
|
|
|
protected:
|
2017-11-30 21:03:02 +03:00
|
|
|
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
|
2015-11-06 21:55:31 +03:00
|
|
|
|
|
|
|
void SetOffscreenFormat(gfxImageFormat aFormat) {
|
|
|
|
mOffscreenFormat = aFormat;
|
|
|
|
}
|
2017-11-30 21:03:02 +03:00
|
|
|
gfxImageFormat GetOffscreenFormat() const;
|
2015-11-06 21:55:31 +03:00
|
|
|
|
|
|
|
Data mData;
|
2016-05-23 03:37:43 +03:00
|
|
|
gfx::IntPoint mOrigin;
|
2015-11-06 21:55:31 +03:00
|
|
|
gfx::IntSize mSize;
|
|
|
|
gfxImageFormat mOffscreenFormat;
|
|
|
|
nsCountedRef<nsMainThreadSourceSurfaceRef> mSourceSurface;
|
|
|
|
uint32_t mBufferSize;
|
|
|
|
};
|
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
class RecyclingPlanarYCbCrImage : public PlanarYCbCrImage {
|
2015-11-06 21:55:31 +03:00
|
|
|
public:
|
|
|
|
explicit RecyclingPlanarYCbCrImage(BufferRecycleBin* aRecycleBin)
|
|
|
|
: mRecycleBin(aRecycleBin) {}
|
2017-11-30 21:03:02 +03:00
|
|
|
virtual ~RecyclingPlanarYCbCrImage();
|
|
|
|
bool CopyData(const Data& aData) override;
|
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2012-08-21 14:18:20 +04:00
|
|
|
protected:
|
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
|
|
|
};
|
|
|
|
|
2016-03-10 05:35:27 +03:00
|
|
|
/**
|
|
|
|
* NVImage is used to store YUV420SP_NV12 and YUV420SP_NV21 data natively, which
|
|
|
|
* are not supported by PlanarYCbCrImage. (PlanarYCbCrImage only stores YUV444P,
|
|
|
|
* YUV422P and YUV420P, it converts YUV420SP_NV12 and YUV420SP_NV21 data into
|
|
|
|
* YUV420P in its PlanarYCbCrImage::SetData() method.)
|
|
|
|
*
|
|
|
|
* PlanarYCbCrData is able to express all the YUV family and so we keep use it
|
|
|
|
* in NVImage.
|
|
|
|
*/
|
2017-11-30 21:03:02 +03:00
|
|
|
class NVImage final : public Image {
|
2016-03-10 05:35:27 +03:00
|
|
|
typedef PlanarYCbCrData Data;
|
|
|
|
|
|
|
|
public:
|
2017-11-30 21:03:02 +03:00
|
|
|
NVImage();
|
|
|
|
virtual ~NVImage();
|
2016-03-10 05:35:27 +03:00
|
|
|
|
|
|
|
// Methods inherited from layers::Image.
|
2017-11-30 21:03:02 +03:00
|
|
|
gfx::IntSize GetSize() const override;
|
|
|
|
gfx::IntRect GetPictureRect() const override;
|
|
|
|
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
|
|
|
|
bool IsValid() const override;
|
|
|
|
NVImage* AsNVImage() override;
|
2016-03-10 05:35:27 +03:00
|
|
|
|
|
|
|
// Methods mimic layers::PlanarYCbCrImage.
|
2017-11-30 21:03:02 +03:00
|
|
|
bool SetData(const Data& aData);
|
|
|
|
const Data* GetData() const;
|
|
|
|
uint32_t GetBufferSize() const;
|
2016-03-10 05:35:27 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Return a buffer to store image data in.
|
|
|
|
*/
|
|
|
|
mozilla::UniquePtr<uint8_t> AllocateBuffer(uint32_t aSize);
|
|
|
|
|
|
|
|
mozilla::UniquePtr<uint8_t> mBuffer;
|
|
|
|
uint32_t mBufferSize;
|
|
|
|
gfx::IntSize mSize;
|
|
|
|
Data mData;
|
|
|
|
nsCountedRef<nsMainThreadSourceSurfaceRef> mSourceSurface;
|
|
|
|
};
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
/**
|
2015-12-18 09:52:16 +03:00
|
|
|
* Currently, the data in a SourceSurfaceImage surface is treated as being in
|
2012-08-19 23:33:25 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2017-11-30 21:03:02 +03:00
|
|
|
class SourceSurfaceImage final : public Image {
|
2012-08-19 23:33:25 +04:00
|
|
|
public:
|
2017-11-30 21:03:02 +03:00
|
|
|
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override {
|
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
|
|
|
|
2016-09-23 00:43:11 +03:00
|
|
|
void SetTextureFlags(TextureFlags aTextureFlags) {
|
|
|
|
mTextureFlags = aTextureFlags;
|
|
|
|
}
|
2019-06-07 15:27:05 +03:00
|
|
|
TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override;
|
2014-02-17 02:23:39 +04:00
|
|
|
|
2017-11-30 21:03:02 +03:00
|
|
|
gfx::IntSize GetSize() const override { return mSize; }
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2015-12-18 09:52:16 +03:00
|
|
|
SourceSurfaceImage(const gfx::IntSize& aSize,
|
|
|
|
gfx::SourceSurface* aSourceSurface);
|
2016-02-27 08:25:08 +03:00
|
|
|
explicit SourceSurfaceImage(gfx::SourceSurface* aSourceSurface);
|
2017-11-30 21:03:02 +03:00
|
|
|
virtual ~SourceSurfaceImage();
|
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;
|
2015-12-18 09:52:16 +03:00
|
|
|
nsCountedRef<nsOwningThreadSourceSurfaceRef> mSourceSurface;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsDataHashtable<nsUint32HashKey, RefPtr<TextureClient>> mTextureClients;
|
2016-09-23 00:43:11 +03:00
|
|
|
TextureFlags mTextureFlags;
|
2012-08-19 23:33:25 +04:00
|
|
|
};
|
|
|
|
|
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
|