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
|
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
|
|
|
* 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 MOZILLA_GFX_TEXTURECLIENT_H
|
|
|
|
#define MOZILLA_GFX_TEXTURECLIENT_H
|
|
|
|
|
2013-08-12 03:17:23 +04:00
|
|
|
#include <stddef.h> // for size_t
|
|
|
|
#include <stdint.h> // for uint32_t, uint8_t, uint64_t
|
|
|
|
#include "GLTextureImage.h" // for TextureImage
|
|
|
|
#include "ImageTypes.h" // for StereoMode
|
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
2017-08-05 21:54:11 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2015-03-21 19:28:04 +03:00
|
|
|
#include "mozilla/Attributes.h" // for override
|
2015-11-11 10:58:21 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h" // for RefPtr, RefCounted
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/gfx/2D.h" // for DrawTarget
|
|
|
|
#include "mozilla/gfx/Point.h" // for IntSize
|
|
|
|
#include "mozilla/gfx/Types.h" // for SurfaceFormat
|
|
|
|
#include "mozilla/ipc/Shmem.h" // for Shmem
|
2014-01-21 22:53:48 +04:00
|
|
|
#include "mozilla/layers/AtomicRefCountedWithFinalize.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/CompositorTypes.h" // for TextureFlags, etc
|
2016-09-27 11:46:41 +03:00
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
2014-12-13 04:50:47 +03:00
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
|
|
|
|
#include "mozilla/mozalloc.h" // for operator delete
|
2016-04-22 19:05:26 +03:00
|
|
|
#include "mozilla/gfx/CriticalSection.h"
|
2017-04-20 04:24:13 +03:00
|
|
|
#include "mozilla/webrender/WebRenderTypes.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsCOMPtr.h" // for already_AddRefed
|
|
|
|
#include "nsISupportsImpl.h" // for TextureImage::AddRef, etc
|
2014-07-24 21:34:43 +04:00
|
|
|
#include "GfxTexturesReporter.h"
|
2016-06-02 12:00:12 +03:00
|
|
|
#include "pratom.h"
|
2016-06-15 14:28:10 +03:00
|
|
|
#include "nsThreadUtils.h"
|
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
|
|
|
|
2013-09-25 00:45:14 +04:00
|
|
|
class gfxImageSurface;
|
2017-03-07 23:55:19 +03:00
|
|
|
struct ID3D11Device;
|
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
|
|
|
|
|
|
|
namespace mozilla {
|
2014-06-19 04:04:06 +04:00
|
|
|
|
2014-11-25 22:54:29 +03:00
|
|
|
// When defined, we track which pool the tile came from and test for
|
|
|
|
// any inconsistencies. This can be defined in release build as well.
|
|
|
|
#ifdef DEBUG
|
|
|
|
# define GFX_DEBUG_TRACK_CLIENTS_IN_POOL 1
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
namespace layers {
|
|
|
|
|
2015-05-12 06:36:49 +03:00
|
|
|
class AsyncTransactionWaiter;
|
2016-06-30 05:12:31 +03:00
|
|
|
class BufferTextureData;
|
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 CompositableForwarder;
|
2016-09-27 06:22:20 +03:00
|
|
|
class KnowsCompositor;
|
|
|
|
class LayersIPCChannel;
|
2013-07-30 13:59:51 +04:00
|
|
|
class CompositableClient;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct PlanarYCbCrData;
|
2013-10-02 04:57:50 +04:00
|
|
|
class Image;
|
2013-12-12 05:44:44 +04:00
|
|
|
class PTextureChild;
|
|
|
|
class TextureChild;
|
2015-10-15 18:53:37 +03:00
|
|
|
class TextureData;
|
2016-11-04 03:28:28 +03:00
|
|
|
class GPUVideoTextureData;
|
2015-10-15 18:53:33 +03:00
|
|
|
struct RawTextureBuffer;
|
|
|
|
class RawYCbCrTextureBuffer;
|
2014-04-10 11:24:59 +04:00
|
|
|
class TextureClient;
|
2016-01-08 14:24:00 +03:00
|
|
|
class ITextureClientRecycleAllocator;
|
2014-11-25 22:54:29 +03:00
|
|
|
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
|
|
|
|
class TextureClientPool;
|
|
|
|
#endif
|
2016-05-13 01:00:04 +03:00
|
|
|
class TextureForwarder;
|
2014-07-22 19:49:05 +04:00
|
|
|
class KeepAlive;
|
2017-08-07 13:15:24 +03:00
|
|
|
class SyncObjectClient;
|
2013-07-30 13:59:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* TextureClient is the abstraction that allows us to share data between the
|
|
|
|
* content and the compositor side.
|
|
|
|
*/
|
|
|
|
|
2013-12-05 22:39:22 +04:00
|
|
|
enum TextureAllocationFlags {
|
2016-02-17 18:34:37 +03:00
|
|
|
ALLOC_DEFAULT = 0,
|
|
|
|
ALLOC_CLEAR_BUFFER =
|
|
|
|
1 << 1, // Clear the buffer to whatever is best for the draw target
|
|
|
|
ALLOC_CLEAR_BUFFER_WHITE = 1 << 2, // explicit all white
|
|
|
|
ALLOC_CLEAR_BUFFER_BLACK = 1 << 3, // explicit all black
|
|
|
|
ALLOC_DISALLOW_BUFFERTEXTURECLIENT = 1 << 4,
|
2015-12-02 22:31:17 +03:00
|
|
|
|
|
|
|
// Allocate the texture for out-of-band content updates. This is mostly for
|
|
|
|
// TextureClientD3D11, which may otherwise choose D3D10 or non-KeyedMutex
|
|
|
|
// surfaces when used on the main thread.
|
2016-02-17 18:34:37 +03:00
|
|
|
ALLOC_FOR_OUT_OF_BAND_CONTENT = 1 << 5,
|
2016-03-21 08:49:59 +03:00
|
|
|
|
|
|
|
// Disable any cross-device synchronization. This is also for
|
|
|
|
// TextureClientD3D11, and creates a texture without KeyedMutex.
|
|
|
|
ALLOC_MANUAL_SYNCHRONIZATION = 1 << 6,
|
2016-10-06 15:32:55 +03:00
|
|
|
|
|
|
|
// The texture is going to be updated using UpdateFromSurface and needs to
|
|
|
|
// support that call.
|
|
|
|
ALLOC_UPDATE_FROM_SURFACE = 1 << 7,
|
2018-05-03 04:20:25 +03:00
|
|
|
|
|
|
|
// In practice, this means we support the APPLE_client_storage extension,
|
|
|
|
// meaning the buffer will not be internally copied by the graphics driver.
|
|
|
|
ALLOC_ALLOW_DIRECT_MAPPING = 1 << 8,
|
2013-12-05 22:39:22 +04:00
|
|
|
};
|
|
|
|
|
2014-07-30 17:38:46 +04:00
|
|
|
/**
|
|
|
|
* This class may be used to asynchronously receive an update when the content
|
|
|
|
* drawn to this texture client is available for reading in CPU memory. This
|
|
|
|
* can only be used on texture clients that support draw target creation.
|
|
|
|
*/
|
|
|
|
class TextureReadbackSink {
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureReadbackSink)
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Callback function to implement in order to receive a DataSourceSurface
|
|
|
|
* containing the data read back from the texture client. This will always
|
|
|
|
* be called on the main thread, and this may not hold on to the
|
|
|
|
* DataSourceSurface beyond the execution of this function.
|
|
|
|
*/
|
|
|
|
virtual void ProcessReadback(gfx::DataSourceSurface* aSourceSurface) = 0;
|
|
|
|
|
|
|
|
protected:
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~TextureReadbackSink() = default;
|
2014-07-30 17:38:46 +04:00
|
|
|
};
|
|
|
|
|
2015-08-07 03:27:36 +03:00
|
|
|
enum class BackendSelector { Content, Canvas };
|
|
|
|
|
2015-10-15 18:53:33 +03:00
|
|
|
/// Temporary object providing direct access to a Texture's memory.
|
|
|
|
///
|
|
|
|
/// see TextureClient::CanExposeMappedData() and
|
|
|
|
/// TextureClient::BorrowMappedData().
|
|
|
|
struct MappedTextureData {
|
|
|
|
uint8_t* data;
|
|
|
|
gfx::IntSize size;
|
|
|
|
int32_t stride;
|
|
|
|
gfx::SurfaceFormat format;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MappedYCbCrChannelData {
|
|
|
|
uint8_t* data;
|
|
|
|
gfx::IntSize size;
|
|
|
|
int32_t stride;
|
|
|
|
int32_t skip;
|
2017-09-29 17:37:56 +03:00
|
|
|
uint32_t bytesPerPixel;
|
2015-10-15 18:53:33 +03:00
|
|
|
|
|
|
|
bool CopyInto(MappedYCbCrChannelData& aDst);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MappedYCbCrTextureData {
|
|
|
|
MappedYCbCrChannelData y;
|
|
|
|
MappedYCbCrChannelData cb;
|
|
|
|
MappedYCbCrChannelData cr;
|
|
|
|
// Sad but because of how SharedPlanarYCbCrData is used we have to expose this
|
|
|
|
// for now.
|
|
|
|
uint8_t* metadata;
|
|
|
|
StereoMode stereoMode;
|
|
|
|
|
|
|
|
bool CopyInto(MappedYCbCrTextureData& aDst) {
|
|
|
|
return y.CopyInto(aDst.y) && cb.CopyInto(aDst.cb) && cr.CopyInto(aDst.cr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-02 12:00:21 +03:00
|
|
|
class ReadLockDescriptor;
|
2017-02-04 13:19:11 +03:00
|
|
|
class NonBlockingTextureReadLock;
|
2016-06-02 12:00:21 +03:00
|
|
|
|
|
|
|
// A class to help implement copy-on-write semantics for shared textures.
|
|
|
|
//
|
|
|
|
// A TextureClient/Host pair can opt into using a ReadLock by calling
|
|
|
|
// TextureClient::EnableReadLock. This will equip the TextureClient with a
|
|
|
|
// ReadLock object that will be automatically ReadLock()'ed by the texture
|
|
|
|
// itself when it is written into (see TextureClient::Unlock). A
|
|
|
|
// TextureReadLock's counter starts at 1 and is expected to be equal to 1 when
|
|
|
|
// the lock is destroyed. See ShmemTextureReadLock for explanations about why we
|
|
|
|
// use 1 instead of 0 as the initial state. TextureReadLock is mostly internally
|
|
|
|
// managed by the TextureClient/Host pair, and the compositable only has to
|
|
|
|
// forward it during updates. If an update message contains a null_t lock, it
|
|
|
|
// means that the texture was not written into on the content side, and there is
|
|
|
|
// no synchronization required on the compositor side (or it means that the
|
|
|
|
// texture pair did not opt into using ReadLocks). On the compositor side, the
|
|
|
|
// TextureHost can receive a ReadLock during a transaction, and will both
|
|
|
|
// ReadUnlock() it and drop it as soon as the shared data is available again for
|
|
|
|
// writing (the texture upload is done, or the compositor not reading the
|
|
|
|
// texture anymore). The lock is dropped to make sure it is ReadUnlock()'ed only
|
|
|
|
// once.
|
2016-06-02 12:00:12 +03:00
|
|
|
class TextureReadLock {
|
|
|
|
protected:
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~TextureReadLock() = default;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureReadLock)
|
|
|
|
|
2017-02-14 11:10:36 +03:00
|
|
|
virtual bool ReadLock() = 0;
|
|
|
|
virtual bool TryReadLock(TimeDuration aTimeout) { return ReadLock(); }
|
2016-06-02 12:00:12 +03:00
|
|
|
virtual int32_t ReadUnlock() = 0;
|
|
|
|
virtual bool IsValid() const = 0;
|
|
|
|
|
|
|
|
static already_AddRefed<TextureReadLock> Deserialize(
|
2016-06-02 12:00:21 +03:00
|
|
|
const ReadLockDescriptor& aDescriptor, ISurfaceAllocator* aAllocator);
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2017-02-14 11:10:36 +03:00
|
|
|
virtual bool Serialize(ReadLockDescriptor& aOutput,
|
|
|
|
base::ProcessId aOther) = 0;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
|
|
|
enum LockType {
|
2017-02-04 13:19:11 +03:00
|
|
|
TYPE_NONBLOCKING_MEMORY,
|
2017-02-14 11:10:36 +03:00
|
|
|
TYPE_NONBLOCKING_SHMEM,
|
|
|
|
TYPE_CROSS_PROCESS_SEMAPHORE
|
2016-06-02 12:00:12 +03:00
|
|
|
};
|
|
|
|
virtual LockType GetType() = 0;
|
|
|
|
|
2017-02-04 13:19:11 +03:00
|
|
|
virtual NonBlockingTextureReadLock* AsNonBlockingLock() { return nullptr; }
|
|
|
|
|
2016-06-02 12:00:12 +03:00
|
|
|
protected:
|
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
};
|
|
|
|
|
2017-02-04 13:19:11 +03:00
|
|
|
class NonBlockingTextureReadLock : public TextureReadLock {
|
|
|
|
public:
|
|
|
|
virtual int32_t GetReadCount() = 0;
|
|
|
|
|
|
|
|
static already_AddRefed<TextureReadLock> Create(LayersIPCChannel* aAllocator);
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
NonBlockingTextureReadLock* AsNonBlockingLock() override { return this; }
|
2017-02-04 13:19:11 +03:00
|
|
|
};
|
|
|
|
|
2015-12-02 22:31:17 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
class D3D11TextureData;
|
2017-11-10 12:15:54 +03:00
|
|
|
class DXGIYCbCrTextureData;
|
2015-12-02 22:31:17 +03:00
|
|
|
#endif
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
class TextureData {
|
|
|
|
public:
|
2016-04-22 19:05:26 +03:00
|
|
|
struct Info {
|
|
|
|
gfx::IntSize size;
|
|
|
|
gfx::SurfaceFormat format;
|
|
|
|
bool hasIntermediateBuffer;
|
|
|
|
bool hasSynchronization;
|
|
|
|
bool supportsMoz2D;
|
|
|
|
bool canExposeMappedData;
|
2017-10-28 13:59:58 +03:00
|
|
|
bool canConcurrentlyReadLock;
|
2016-04-22 19:05:26 +03:00
|
|
|
|
|
|
|
Info()
|
|
|
|
: format(gfx::SurfaceFormat::UNKNOWN),
|
|
|
|
hasIntermediateBuffer(false),
|
|
|
|
hasSynchronization(false),
|
|
|
|
supportsMoz2D(false),
|
|
|
|
canExposeMappedData(false),
|
2017-10-28 13:59:58 +03:00
|
|
|
canConcurrentlyReadLock(true) {}
|
2016-04-22 19:05:26 +03:00
|
|
|
};
|
|
|
|
|
2018-11-28 23:44:27 +03:00
|
|
|
static TextureData* Create(TextureForwarder* aAllocator,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::IntSize aSize,
|
|
|
|
LayersBackend aLayersBackend,
|
|
|
|
int32_t aMaxTextureSize,
|
|
|
|
BackendSelector aSelector,
|
|
|
|
TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags);
|
|
|
|
|
|
|
|
static bool IsRemote(LayersBackend aLayersBackend, BackendSelector aSelector);
|
2015-11-20 16:25:00 +03:00
|
|
|
|
|
|
|
virtual ~TextureData() { MOZ_COUNT_DTOR(TextureData); }
|
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
virtual void FillInfo(TextureData::Info& aInfo) const = 0;
|
2015-11-20 16:25:00 +03:00
|
|
|
|
2016-10-27 11:02:09 +03:00
|
|
|
virtual bool Lock(OpenMode aMode) = 0;
|
2015-11-20 16:25:00 +03:00
|
|
|
|
|
|
|
virtual void Unlock() = 0;
|
|
|
|
|
|
|
|
virtual already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool BorrowMappedData(MappedTextureData&) { return false; }
|
|
|
|
|
|
|
|
virtual bool BorrowMappedYCbCrData(MappedYCbCrTextureData&) { return false; }
|
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
virtual void Deallocate(LayersIPCChannel* aAllocator) = 0;
|
2015-11-20 16:25:00 +03:00
|
|
|
|
|
|
|
/// Depending on the texture's flags either Deallocate or Forget is called.
|
2016-09-27 06:22:20 +03:00
|
|
|
virtual void Forget(LayersIPCChannel* aAllocator) {}
|
2015-11-20 16:25:00 +03:00
|
|
|
|
|
|
|
virtual bool Serialize(SurfaceDescriptor& aDescriptor) = 0;
|
2017-04-12 08:58:47 +03:00
|
|
|
virtual void GetSubDescriptor(GPUVideoSubDescriptor* aOutDesc) {}
|
2015-11-20 16:25:00 +03:00
|
|
|
|
2017-10-28 13:59:58 +03:00
|
|
|
virtual void OnForwardedToHost() {}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
virtual TextureData* CreateSimilar(
|
2016-09-27 06:22:20 +03:00
|
|
|
LayersIPCChannel* aAllocator, LayersBackend aLayersBackend,
|
2015-11-20 16:25:00 +03:00
|
|
|
TextureFlags aFlags = TextureFlags::DEFAULT,
|
|
|
|
TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool UpdateFromSurface(gfx::SourceSurface* aSurface) {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual bool ReadBack(TextureReadbackSink* aReadbackSink) { return false; }
|
|
|
|
|
2017-08-07 13:15:24 +03:00
|
|
|
virtual void SyncWithObject(SyncObjectClient* aSyncObject){};
|
2015-11-20 16:25:00 +03:00
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
virtual TextureFlags GetTextureFlags() const {
|
|
|
|
return TextureFlags::NO_FLAGS;
|
|
|
|
}
|
2015-12-02 22:31:17 +03:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
virtual D3D11TextureData* AsD3D11TextureData() { return nullptr; }
|
2017-11-10 12:15:54 +03:00
|
|
|
virtual DXGIYCbCrTextureData* AsDXGIYCbCrTextureData() { return nullptr; }
|
2015-12-02 22:31:17 +03:00
|
|
|
#endif
|
2016-02-25 11:23:23 +03:00
|
|
|
|
2016-06-30 05:12:31 +03:00
|
|
|
virtual BufferTextureData* AsBufferTextureData() { return nullptr; }
|
2016-11-04 03:28:28 +03:00
|
|
|
|
|
|
|
virtual GPUVideoTextureData* AsGPUVideoTextureData() { return nullptr; }
|
2018-11-28 23:44:27 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
TextureData() { MOZ_COUNT_CTOR(TextureData); }
|
2015-11-20 16:25:00 +03:00
|
|
|
};
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
/**
|
|
|
|
* TextureClient is a thin abstraction over texture data that need to be shared
|
|
|
|
* between the content process and the compositor process. It is the
|
|
|
|
* content-side half of a TextureClient/TextureHost pair. A corresponding
|
|
|
|
* TextureHost lives on the compositor-side.
|
|
|
|
*
|
|
|
|
* TextureClient's primary purpose is to present texture data in a way that is
|
|
|
|
* understood by the IPC system. There are two ways to use it:
|
|
|
|
* - Use it to serialize image data that is not IPC-friendly (most likely
|
|
|
|
* involving a copy into shared memory)
|
|
|
|
* - preallocate it and paint directly into it, which avoids copy but requires
|
2013-08-08 16:53:12 +04:00
|
|
|
* the painting code to be aware of TextureClient (or at least the underlying
|
|
|
|
* shared memory).
|
2013-07-30 13:59:51 +04:00
|
|
|
*
|
|
|
|
* There is always one and only one TextureClient per TextureHost, and the
|
|
|
|
* TextureClient/Host pair only owns one buffer of image data through its
|
2013-08-08 16:53:12 +04:00
|
|
|
* lifetime. This means that the lifetime of the underlying shared data
|
2013-07-30 13:59:51 +04:00
|
|
|
* matches the lifetime of the TextureClient/Host pair. It also means
|
|
|
|
* TextureClient/Host do not implement double buffering, which is the
|
|
|
|
* responsibility of the compositable (which would use two Texture pairs).
|
|
|
|
* In order to send several different buffers to the compositor side, use
|
|
|
|
* several TextureClients.
|
|
|
|
*/
|
2013-12-12 05:45:11 +04:00
|
|
|
class TextureClient : public AtomicRefCountedWithFinalize<TextureClient> {
|
2013-07-30 13:59:51 +04:00
|
|
|
public:
|
2019-04-11 15:36:51 +03:00
|
|
|
TextureClient(TextureData* aData, TextureFlags aFlags,
|
|
|
|
LayersIPCChannel* aAllocator);
|
2015-11-20 16:25:00 +03:00
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
virtual ~TextureClient();
|
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
static already_AddRefed<TextureClient> CreateWithData(
|
2016-09-27 06:22:20 +03:00
|
|
|
TextureData* aData, TextureFlags aFlags, LayersIPCChannel* aAllocator);
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2014-07-10 15:45:40 +04:00
|
|
|
// Creates and allocates a TextureClient usable with Moz2D.
|
2015-06-17 17:00:52 +03:00
|
|
|
static already_AddRefed<TextureClient> CreateForDrawing(
|
2016-09-27 06:22:20 +03:00
|
|
|
KnowsCompositor* aAllocator, gfx::SurfaceFormat aFormat,
|
2014-07-10 15:45:40 +04:00
|
|
|
gfx::IntSize aSize, BackendSelector aSelector, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags flags = ALLOC_DEFAULT);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-02 08:57:41 +03:00
|
|
|
static already_AddRefed<TextureClient> CreateFromSurface(
|
2016-09-27 06:22:20 +03:00
|
|
|
KnowsCompositor* aAllocator, gfx::SourceSurface* aSurface,
|
2016-08-02 08:57:41 +03:00
|
|
|
BackendSelector aSelector, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags);
|
|
|
|
|
2015-10-15 18:53:33 +03:00
|
|
|
// Creates and allocates a TextureClient supporting the YCbCr format.
|
|
|
|
static already_AddRefed<TextureClient> CreateForYCbCr(
|
2016-09-27 06:22:20 +03:00
|
|
|
KnowsCompositor* aAllocator, gfx::IntSize aYSize, uint32_t aYStride,
|
2014-07-10 15:48:29 +04:00
|
|
|
gfx::IntSize aCbCrSize, uint32_t aCbCrStride, StereoMode aStereoMode,
|
2019-04-11 15:41:33 +03:00
|
|
|
gfx::ColorDepth aColorDepth, gfx::YUVColorSpace aYUVColorSpace,
|
2014-07-10 15:48:29 +04:00
|
|
|
TextureFlags aTextureFlags);
|
|
|
|
|
2015-10-15 18:53:33 +03:00
|
|
|
// Creates and allocates a TextureClient (can be accessed through raw
|
2014-07-10 15:45:40 +04:00
|
|
|
// pointers).
|
2015-10-15 18:53:33 +03:00
|
|
|
static already_AddRefed<TextureClient> CreateForRawBufferAccess(
|
2016-09-27 06:22:20 +03:00
|
|
|
KnowsCompositor* aAllocator, gfx::SurfaceFormat aFormat,
|
2014-07-10 15:45:40 +04:00
|
|
|
gfx::IntSize aSize, gfx::BackendType aMoz2dBackend,
|
|
|
|
TextureFlags aTextureFlags, TextureAllocationFlags flags = ALLOC_DEFAULT);
|
2014-03-08 01:34:04 +04:00
|
|
|
|
2014-07-25 13:24:46 +04:00
|
|
|
// Creates and allocates a TextureClient of the same type.
|
2015-11-20 16:25:00 +03:00
|
|
|
already_AddRefed<TextureClient> CreateSimilar(
|
2016-09-27 06:22:20 +03:00
|
|
|
LayersBackend aLayersBackend = LayersBackend::LAYERS_NONE,
|
|
|
|
TextureFlags aFlags = TextureFlags::DEFAULT,
|
2015-11-20 16:25:00 +03:00
|
|
|
TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const;
|
2015-11-24 21:07:02 +03:00
|
|
|
|
2013-09-30 16:42:47 +04:00
|
|
|
/**
|
|
|
|
* Locks the shared data, allowing the caller to get access to it.
|
|
|
|
*
|
|
|
|
* Please always lock/unlock when accessing the shared data.
|
|
|
|
* If Lock() returns false, you should not attempt to access the shared data.
|
|
|
|
*/
|
2015-11-20 16:25:00 +03:00
|
|
|
bool Lock(OpenMode aMode);
|
2014-01-24 18:25:04 +04:00
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
void Unlock();
|
2014-04-10 12:14:28 +04:00
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
bool IsLocked() const { return mIsLocked; }
|
2015-10-15 18:53:33 +03:00
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
gfx::IntSize GetSize() const { return mInfo.size; }
|
2015-10-15 18:53:33 +03:00
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
gfx::SurfaceFormat GetFormat() const { return mInfo.format; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this texture has a synchronization mechanism (mutex, fence,
|
|
|
|
* etc.). Textures that do not implement synchronization should be immutable
|
|
|
|
* or should use immediate uploads (see TextureFlags in CompositorTypes.h)
|
|
|
|
* Even if a texture does not implement synchronization, Lock and Unlock need
|
|
|
|
* to be used appropriately since the latter are also there to map/numap data.
|
|
|
|
*/
|
|
|
|
bool HasSynchronization() const { return mInfo.hasSynchronization; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether the TextureClient implementation is backed by an
|
|
|
|
* in-memory buffer. The consequence of this is that locking the
|
|
|
|
* TextureClient does not contend with locking the texture on the host side.
|
|
|
|
*/
|
|
|
|
bool HasIntermediateBuffer() const { return mInfo.hasIntermediateBuffer; }
|
|
|
|
|
|
|
|
bool CanExposeDrawTarget() const { return mInfo.supportsMoz2D; }
|
|
|
|
|
|
|
|
bool CanExposeMappedData() const { return mInfo.canExposeMappedData; }
|
2015-10-15 18:53:33 +03:00
|
|
|
|
2014-04-10 12:14:28 +04:00
|
|
|
/**
|
|
|
|
* Returns a DrawTarget to draw into the TextureClient.
|
2015-07-27 18:47:29 +03:00
|
|
|
* This function should never be called when not on the main thread!
|
2014-04-10 12:14:28 +04:00
|
|
|
*
|
|
|
|
* This must never be called on a TextureClient that is not sucessfully
|
|
|
|
* locked. When called several times within one Lock/Unlock pair, this method
|
|
|
|
* should return the same DrawTarget. The DrawTarget is automatically flushed
|
|
|
|
* by the TextureClient when the latter is unlocked, and the DrawTarget that
|
|
|
|
* will be returned within the next lock/unlock pair may or may not be the
|
|
|
|
* same object. Do not keep references to the DrawTarget outside of the
|
|
|
|
* lock/unlock pair.
|
|
|
|
*
|
|
|
|
* This is typically used as follows:
|
|
|
|
*
|
2014-04-26 06:34:06 +04:00
|
|
|
* if (!texture->Lock(OpenMode::OPEN_READ_WRITE)) {
|
2014-04-10 12:14:28 +04:00
|
|
|
* return false;
|
|
|
|
* }
|
|
|
|
* {
|
|
|
|
* // Restrict this code's scope to ensure all references to dt are gone
|
|
|
|
* // when Unlock is called.
|
2014-06-11 22:57:58 +04:00
|
|
|
* DrawTarget* dt = texture->BorrowDrawTarget();
|
2014-04-10 12:14:28 +04:00
|
|
|
* // use the draw target ...
|
|
|
|
* }
|
|
|
|
* texture->Unlock();
|
|
|
|
*
|
|
|
|
*/
|
2015-11-20 16:25:00 +03:00
|
|
|
gfx::DrawTarget* BorrowDrawTarget();
|
2015-10-15 18:53:33 +03:00
|
|
|
|
2015-10-15 18:53:33 +03:00
|
|
|
/**
|
|
|
|
* Similar to BorrowDrawTarget but provides direct access to the texture's
|
|
|
|
* bits instead of a DrawTarget.
|
|
|
|
*/
|
2015-11-20 16:25:00 +03:00
|
|
|
bool BorrowMappedData(MappedTextureData&);
|
|
|
|
bool BorrowMappedYCbCrData(MappedYCbCrTextureData&);
|
2015-10-15 18:53:33 +03:00
|
|
|
|
2015-07-27 18:47:29 +03:00
|
|
|
/**
|
|
|
|
* This function can be used to update the contents of the TextureClient
|
|
|
|
* off the main thread.
|
|
|
|
*/
|
2015-11-20 16:25:00 +03:00
|
|
|
void UpdateFromSurface(gfx::SourceSurface* aSurface);
|
2015-07-27 18:47:29 +03:00
|
|
|
|
2015-01-13 00:51:02 +03:00
|
|
|
/**
|
|
|
|
* This method is strictly for debugging. It causes locking and
|
|
|
|
* needless copies.
|
|
|
|
*/
|
2016-04-22 19:05:26 +03:00
|
|
|
already_AddRefed<gfx::DataSourceSurface> GetAsSurface();
|
2014-12-18 21:32:45 +03:00
|
|
|
|
|
|
|
virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix);
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
/**
|
|
|
|
* Copies a rectangle from this texture client to a position in aTarget.
|
|
|
|
* It is assumed that the necessary locks are in place; so this should at
|
|
|
|
* least have a read lock and aTarget should at least have a write lock.
|
|
|
|
*/
|
2015-11-20 16:25:00 +03:00
|
|
|
bool CopyToTextureClient(TextureClient* aTarget, const gfx::IntRect* aRect,
|
|
|
|
const gfx::IntPoint* aPoint);
|
2014-03-08 01:34:04 +04:00
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
/**
|
|
|
|
* Allocate and deallocate a TextureChild actor.
|
|
|
|
*
|
2014-04-24 22:13:59 +04:00
|
|
|
* TextureChild is an implementation detail of TextureClient that is not
|
2013-12-12 05:44:44 +04:00
|
|
|
* exposed to the rest of the code base. CreateIPDLActor and DestroyIPDLActor
|
2014-04-24 22:13:59 +04:00
|
|
|
* are for use with the managing IPDL protocols only (so that they can
|
2013-12-12 05:44:44 +04:00
|
|
|
* implement AllocPextureChild and DeallocPTextureChild).
|
|
|
|
*/
|
|
|
|
static PTextureChild* CreateIPDLActor();
|
2016-04-13 20:55:08 +03:00
|
|
|
static bool DestroyIPDLActor(PTextureChild* actor);
|
2013-12-12 05:44:44 +04:00
|
|
|
|
2014-02-25 08:23:41 +04:00
|
|
|
/**
|
|
|
|
* Get the TextureClient corresponding to the actor passed in parameter.
|
|
|
|
*/
|
2016-04-22 19:05:26 +03:00
|
|
|
static already_AddRefed<TextureClient> AsTextureClient(PTextureChild* actor);
|
2013-08-03 21:29:18 +04:00
|
|
|
|
2013-09-30 16:42:47 +04:00
|
|
|
/**
|
|
|
|
* TextureFlags contain important information about various aspects
|
|
|
|
* of the texture, like how its liferime is managed, and how it
|
|
|
|
* should be displayed.
|
|
|
|
* See TextureFlags in CompositorTypes.h.
|
|
|
|
*/
|
2013-07-30 13:59:51 +04:00
|
|
|
TextureFlags GetFlags() const { return mFlags; }
|
|
|
|
|
2014-10-08 08:01:51 +04:00
|
|
|
bool HasFlags(TextureFlags aFlags) const {
|
|
|
|
return (mFlags & aFlags) == aFlags;
|
|
|
|
}
|
|
|
|
|
2014-11-13 18:53:49 +03:00
|
|
|
void AddFlags(TextureFlags aFlags);
|
2014-11-13 04:47:10 +03:00
|
|
|
|
2014-11-13 18:53:49 +03:00
|
|
|
void RemoveFlags(TextureFlags aFlags);
|
|
|
|
|
2016-06-30 05:12:31 +03:00
|
|
|
// Must not be called when TextureClient is in use by CompositableClient.
|
2014-11-13 18:53:49 +03:00
|
|
|
void RecycleTexture(TextureFlags aFlags);
|
2014-10-08 08:01:51 +04:00
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
/**
|
2013-08-08 16:53:12 +04:00
|
|
|
* After being shared with the compositor side, an immutable texture is never
|
2013-07-30 13:59:51 +04:00
|
|
|
* modified, it can only be read. It is safe to not Lock/Unlock immutable
|
|
|
|
* textures.
|
|
|
|
*/
|
2014-04-26 06:34:05 +04:00
|
|
|
bool IsImmutable() const { return !!(mFlags & TextureFlags::IMMUTABLE); }
|
2013-07-30 13:59:51 +04:00
|
|
|
|
2014-04-26 06:34:05 +04:00
|
|
|
void MarkImmutable() { AddFlags(TextureFlags::IMMUTABLE); }
|
2013-07-30 13:59:51 +04:00
|
|
|
|
2015-09-30 19:17:30 +03:00
|
|
|
bool IsSharedWithCompositor() const;
|
2013-07-30 13:59:51 +04:00
|
|
|
|
2013-09-06 13:04:50 +04:00
|
|
|
/**
|
|
|
|
* If this method returns false users of TextureClient are not allowed
|
|
|
|
* to access the shared data.
|
|
|
|
*/
|
2015-11-20 16:25:03 +03:00
|
|
|
bool IsValid() const { return !!mData; }
|
2013-09-06 13:04:50 +04:00
|
|
|
|
2014-11-13 18:53:49 +03:00
|
|
|
/**
|
|
|
|
* Called when TextureClient is added to CompositableClient.
|
|
|
|
*/
|
|
|
|
void SetAddedToCompositableClient();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If this method retuns false, TextureClient is already added to
|
|
|
|
* CompositableClient, since its creation or recycling.
|
|
|
|
*/
|
|
|
|
bool IsAddedToCompositableClient() const {
|
|
|
|
return mAddedToCompositableClient;
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
/**
|
2016-05-27 23:49:30 +03:00
|
|
|
* Create and init the TextureChild/Parent IPDL actor pair
|
|
|
|
* with a CompositableForwarder.
|
|
|
|
*
|
|
|
|
* Should be called only once per TextureClient.
|
|
|
|
* The TextureClient must not be locked when calling this method.
|
|
|
|
*/
|
|
|
|
bool InitIPDLActor(CompositableForwarder* aForwarder);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and init the TextureChild/Parent IPDL actor pair
|
|
|
|
* with a TextureForwarder.
|
2013-12-12 05:44:44 +04:00
|
|
|
*
|
|
|
|
* Should be called only once per TextureClient.
|
2016-04-22 19:05:26 +03:00
|
|
|
* The TextureClient must not be locked when calling this method.
|
2013-12-12 05:44:44 +04:00
|
|
|
*/
|
2016-09-27 06:22:20 +03:00
|
|
|
bool InitIPDLActor(KnowsCompositor* aForwarder);
|
2013-12-12 05:44:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a pointer to the IPDLActor.
|
|
|
|
*
|
|
|
|
* This is to be used with IPDL messages only. Do not store the returned
|
|
|
|
* pointer.
|
|
|
|
*/
|
|
|
|
PTextureChild* GetIPDLActor();
|
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
/**
|
2014-02-05 00:32:02 +04:00
|
|
|
* Triggers the destruction of the shared data and the corresponding
|
|
|
|
* TextureHost.
|
|
|
|
*
|
2014-04-26 06:34:05 +04:00
|
|
|
* If the texture flags contain TextureFlags::DEALLOCATE_CLIENT, the
|
2014-02-05 00:32:02 +04:00
|
|
|
* destruction will be synchronously coordinated with the compositor side,
|
|
|
|
* otherwise it will be done asynchronously.
|
2013-12-12 05:44:45 +04:00
|
|
|
*/
|
2017-02-16 01:28:24 +03:00
|
|
|
void Destroy();
|
2013-12-12 05:44:45 +04:00
|
|
|
|
2014-07-24 21:34:43 +04:00
|
|
|
/**
|
|
|
|
* Track how much of this texture is wasted.
|
|
|
|
* For example we might allocate a 256x256 tile but only use 10x10.
|
|
|
|
*/
|
2015-12-02 22:31:17 +03:00
|
|
|
void SetWaste(int aWasteArea) {
|
|
|
|
mWasteTracker.Update(aWasteArea, BytesPerPixel(GetFormat()));
|
|
|
|
}
|
2014-07-24 21:34:43 +04:00
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
/**
|
|
|
|
* This sets the readback sink that this texture is to use. This will
|
|
|
|
* receive the data for this texture as soon as it becomes available after
|
|
|
|
* texture unlock.
|
|
|
|
*/
|
|
|
|
virtual void SetReadbackSink(TextureReadbackSink* aReadbackSink) {
|
|
|
|
mReadbackSink = aReadbackSink;
|
|
|
|
}
|
2015-06-05 03:15:38 +03:00
|
|
|
|
2017-08-07 13:15:24 +03:00
|
|
|
void SyncWithObject(SyncObjectClient* aSyncObject) {
|
|
|
|
mData->SyncWithObject(aSyncObject);
|
|
|
|
}
|
2014-07-30 17:38:46 +04:00
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
LayersIPCChannel* GetAllocator() { return mAllocator; }
|
2015-08-11 17:15:34 +03:00
|
|
|
|
2016-01-08 14:24:00 +03:00
|
|
|
ITextureClientRecycleAllocator* GetRecycleAllocator() {
|
|
|
|
return mRecycleAllocator;
|
|
|
|
}
|
|
|
|
void SetRecycleAllocator(ITextureClientRecycleAllocator* aAllocator);
|
2015-08-13 22:18:53 +03:00
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
/// If you add new code that uses this method, you are probably doing
|
|
|
|
/// something wrong.
|
|
|
|
TextureData* GetInternalData() { return mData; }
|
|
|
|
const TextureData* GetInternalData() const { return mData; }
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2016-06-15 14:28:10 +03:00
|
|
|
uint64_t GetSerial() const { return mSerial; }
|
2017-04-12 08:58:47 +03:00
|
|
|
void GPUVideoDesc(SurfaceDescriptorGPUVideo* aOutDesc);
|
2016-02-25 11:23:23 +03:00
|
|
|
|
2019-06-01 12:37:56 +03:00
|
|
|
void CancelWaitForNotifyNotUsed();
|
2016-06-15 14:28:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set last transaction id of CompositableForwarder.
|
2017-04-12 08:58:47 +03:00
|
|
|
*
|
2016-06-15 14:28:10 +03:00
|
|
|
* Called when TextureClient has TextureFlags::RECYCLE flag.
|
|
|
|
* When CompositableForwarder forwards the TextureClient with
|
|
|
|
* TextureFlags::RECYCLE, it holds TextureClient's ref until host side
|
|
|
|
* releases it. The host side sends TextureClient release message.
|
|
|
|
* The id is used to check if the message is for the last TextureClient
|
|
|
|
* forwarding.
|
|
|
|
*/
|
|
|
|
void SetLastFwdTransactionId(uint64_t aTransactionId) {
|
2016-07-17 18:54:33 +03:00
|
|
|
MOZ_ASSERT(mFwdTransactionId <= aTransactionId);
|
2016-06-15 14:28:10 +03:00
|
|
|
mFwdTransactionId = aTransactionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t GetLastFwdTransactionId() { return mFwdTransactionId; }
|
2016-06-02 12:00:21 +03:00
|
|
|
|
2016-06-02 12:00:17 +03:00
|
|
|
TextureReadLock* GetReadLock() { return mReadLock; }
|
|
|
|
|
|
|
|
bool IsReadLocked() const;
|
|
|
|
|
2017-02-04 13:19:22 +03:00
|
|
|
bool TryReadLock();
|
|
|
|
void ReadUnlock();
|
|
|
|
|
2018-03-12 16:10:13 +03:00
|
|
|
bool OnForwardedToHost();
|
2016-06-02 12:00:21 +03:00
|
|
|
|
2017-08-05 21:54:11 +03:00
|
|
|
// Mark that the TextureClient will be used by the paint thread, and should
|
|
|
|
// not free its underlying texture data. This must only be called from the
|
|
|
|
// main thread.
|
|
|
|
void AddPaintThreadRef();
|
|
|
|
|
|
|
|
// Mark that the TextureClient is no longer in use by the PaintThread. This
|
|
|
|
// must only be called from the PaintThread.
|
|
|
|
void DropPaintThreadRef();
|
|
|
|
|
2018-07-06 15:25:33 +03:00
|
|
|
wr::MaybeExternalImageId GetExternalImageKey() { return mExternalImageId; }
|
|
|
|
|
2013-12-12 05:44:40 +04:00
|
|
|
private:
|
2015-08-13 22:18:53 +03:00
|
|
|
static void TextureClientRecycleCallback(TextureClient* aClient,
|
|
|
|
void* aClosure);
|
2017-04-12 08:58:47 +03:00
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
// Internal helpers for creating texture clients using the actual forwarder
|
|
|
|
// instead of KnowsCompositor. TextureClientPool uses these to let it cache
|
|
|
|
// texture clients per-process instead of per ShadowLayerForwarder, but
|
|
|
|
// everyone else should use the public functions instead.
|
|
|
|
friend class TextureClientPool;
|
|
|
|
static already_AddRefed<TextureClient> CreateForDrawing(
|
|
|
|
TextureForwarder* aAllocator, gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::IntSize aSize, LayersBackend aLayersBackend, int32_t aMaxTextureSize,
|
|
|
|
BackendSelector aSelector, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
static already_AddRefed<TextureClient> CreateForRawBufferAccess(
|
|
|
|
LayersIPCChannel* aAllocator, gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::IntSize aSize, gfx::BackendType aMoz2dBackend,
|
|
|
|
LayersBackend aLayersBackend, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags flags = ALLOC_DEFAULT);
|
2015-08-13 22:18:53 +03:00
|
|
|
|
2018-03-12 16:10:13 +03:00
|
|
|
void EnableReadLock();
|
|
|
|
void EnableBlockingReadLock();
|
|
|
|
|
2013-12-12 05:44:40 +04:00
|
|
|
/**
|
2015-09-21 17:54:40 +03:00
|
|
|
* Called once, during the destruction of the Texture, on the thread in which
|
|
|
|
* texture's reference count reaches 0 (could be any thread).
|
2013-12-12 05:44:40 +04:00
|
|
|
*
|
|
|
|
* Here goes the shut-down code that uses virtual methods.
|
|
|
|
* Must only be called by Release().
|
|
|
|
*/
|
2016-04-07 19:50:01 +03:00
|
|
|
void Finalize() {}
|
2015-09-21 17:54:40 +03:00
|
|
|
|
2013-12-12 05:45:11 +04:00
|
|
|
friend class AtomicRefCountedWithFinalize<TextureClient>;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
protected:
|
2014-04-10 11:24:59 +04:00
|
|
|
/**
|
|
|
|
* Should only be called *once* per texture, in TextureClient::InitIPDLActor.
|
|
|
|
* Some texture implementations rely on the fact that the descriptor will be
|
|
|
|
* deserialized.
|
|
|
|
* Calling ToSurfaceDescriptor again after it has already returned true,
|
|
|
|
* or never constructing a TextureHost with aDescriptor may result in a memory
|
2015-07-03 18:54:35 +03:00
|
|
|
* leak (see TextureClientD3D9 for example).
|
2014-04-10 11:24:59 +04:00
|
|
|
*/
|
2015-11-20 16:25:00 +03:00
|
|
|
bool ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor);
|
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
void LockActor() const;
|
|
|
|
void UnlockActor() const;
|
|
|
|
|
|
|
|
TextureData::Info mInfo;
|
2015-11-20 16:25:00 +03:00
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
RefPtr<LayersIPCChannel> mAllocator;
|
2016-04-13 20:55:08 +03:00
|
|
|
RefPtr<TextureChild> mActor;
|
2016-01-08 14:24:00 +03:00
|
|
|
RefPtr<ITextureClientRecycleAllocator> mRecycleAllocator;
|
2016-06-02 12:00:17 +03:00
|
|
|
RefPtr<TextureReadLock> mReadLock;
|
2015-10-15 18:53:37 +03:00
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
TextureData* mData;
|
|
|
|
RefPtr<gfx::DrawTarget> mBorrowedDrawTarget;
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
TextureFlags mFlags;
|
2016-06-15 14:28:10 +03:00
|
|
|
|
2014-07-24 21:34:43 +04:00
|
|
|
gl::GfxTextureWasteTracker mWasteTracker;
|
2015-11-20 16:25:00 +03:00
|
|
|
|
|
|
|
OpenMode mOpenMode;
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
uint32_t mExpectedDtRefs;
|
|
|
|
#endif
|
2015-11-20 16:25:00 +03:00
|
|
|
bool mIsLocked;
|
2017-02-04 13:19:22 +03:00
|
|
|
bool mIsReadLocked;
|
2016-06-02 12:00:36 +03:00
|
|
|
// This member tracks that the texture was written into until the update
|
|
|
|
// is sent to the compositor. We need this remember to lock mReadLock on
|
|
|
|
// behalf of the compositor just before sending the notification.
|
|
|
|
bool mUpdated;
|
2015-11-20 16:25:00 +03:00
|
|
|
|
2016-06-30 05:12:31 +03:00
|
|
|
// Used when TextureClient is recycled with TextureFlags::RECYCLE flag.
|
2014-11-13 18:53:49 +03:00
|
|
|
bool mAddedToCompositableClient;
|
2016-06-30 05:12:31 +03:00
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
bool mWorkaroundAnnoyingSharedSurfaceLifetimeIssues;
|
|
|
|
bool mWorkaroundAnnoyingSharedSurfaceOwnershipIssues;
|
2013-12-12 05:44:55 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextureReadbackSink> mReadbackSink;
|
2014-07-30 17:38:46 +04:00
|
|
|
|
2016-06-15 14:28:10 +03:00
|
|
|
uint64_t mFwdTransactionId;
|
|
|
|
|
|
|
|
// Serial id of TextureClient. It is unique in current process.
|
|
|
|
const uint64_t mSerial;
|
2017-04-20 04:24:13 +03:00
|
|
|
|
2017-08-05 21:54:11 +03:00
|
|
|
// When non-zero, texture data must not be freed.
|
|
|
|
mozilla::Atomic<uintptr_t> mPaintThreadRefs;
|
|
|
|
|
2017-04-20 04:24:13 +03:00
|
|
|
// External image id. It is unique if it is allocated.
|
|
|
|
// The id is allocated in TextureClient::InitIPDLActor().
|
|
|
|
// Its allocation is supported by
|
|
|
|
// CompositorBridgeChild and ImageBridgeChild for now.
|
|
|
|
wr::MaybeExternalImageId mExternalImageId;
|
|
|
|
|
2016-06-15 14:28:10 +03:00
|
|
|
// Used to assign serial ids of TextureClient.
|
|
|
|
static mozilla::Atomic<uint64_t> sSerialCounter;
|
|
|
|
|
2013-12-12 05:44:55 +04:00
|
|
|
friend class TextureChild;
|
2014-04-10 11:24:59 +04:00
|
|
|
friend void TestTextureClientSurface(TextureClient*, gfxImageSurface*);
|
|
|
|
friend void TestTextureClientYCbCr(TextureClient*, PlanarYCbCrData&);
|
2017-02-13 19:51:00 +03:00
|
|
|
friend already_AddRefed<TextureHost> CreateTextureHostWithBackend(
|
2018-02-07 17:33:12 +03:00
|
|
|
TextureClient*, ISurfaceAllocator*, LayersBackend&);
|
2014-11-25 22:54:29 +03:00
|
|
|
|
|
|
|
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
|
|
|
|
public:
|
|
|
|
// Pointer to the pool this tile came from.
|
|
|
|
TextureClientPool* mPoolTracker;
|
|
|
|
#endif
|
2013-07-30 13:59:51 +04:00
|
|
|
};
|
|
|
|
|
2014-06-27 17:26:51 +04:00
|
|
|
/**
|
|
|
|
* Task that releases TextureClient pointer on a specified thread.
|
|
|
|
*/
|
2016-04-28 03:06:05 +03:00
|
|
|
class TextureClientReleaseTask : public Runnable {
|
2014-06-27 17:26:51 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit TextureClientReleaseTask(TextureClient* aClient)
|
|
|
|
: Runnable("layers::TextureClientReleaseTask"), mTextureClient(aClient) {}
|
2014-06-27 17:26:51 +04:00
|
|
|
|
2016-04-28 03:06:05 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2014-06-27 17:26:51 +04:00
|
|
|
mTextureClient = nullptr;
|
2016-04-28 03:06:05 +03:00
|
|
|
return NS_OK;
|
2014-06-27 17:26:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextureClient> mTextureClient;
|
2014-06-27 17:26:51 +04:00
|
|
|
};
|
|
|
|
|
2015-11-11 10:58:21 +03:00
|
|
|
// Automatically lock and unlock a texture. Since texture locking is fallible,
|
|
|
|
// Succeeded() must be checked on the guard object before proceeding.
|
|
|
|
class MOZ_RAII TextureClientAutoLock {
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER;
|
2013-07-30 13:59:51 +04:00
|
|
|
|
2015-11-11 10:58:21 +03:00
|
|
|
public:
|
|
|
|
TextureClientAutoLock(TextureClient* aTexture,
|
|
|
|
OpenMode aMode MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: mTexture(aTexture), mSucceeded(false) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
|
|
|
|
mSucceeded = mTexture->Lock(aMode);
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2015-11-11 10:58:21 +03:00
|
|
|
mChecked = false;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2015-11-11 10:58:21 +03:00
|
|
|
}
|
|
|
|
~TextureClientAutoLock() {
|
|
|
|
MOZ_ASSERT(mChecked);
|
|
|
|
if (mSucceeded) {
|
|
|
|
mTexture->Unlock();
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
2015-11-11 10:58:21 +03:00
|
|
|
|
|
|
|
bool Succeeded() {
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
2015-11-11 10:58:21 +03:00
|
|
|
mChecked = true;
|
2016-02-26 18:52:07 +03:00
|
|
|
#endif
|
2015-11-11 10:58:21 +03:00
|
|
|
return mSucceeded;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TextureClient* mTexture;
|
2016-02-26 18:52:07 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mChecked;
|
|
|
|
#endif
|
2015-11-11 10:58:21 +03:00
|
|
|
bool mSucceeded;
|
2013-07-30 13:59:51 +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
|
|
|
|
2018-08-01 20:46:35 +03:00
|
|
|
// Automatically locks and unlocks two texture clients, and exposes them as a
|
|
|
|
// a single draw target dual. Since texture locking is fallible, Succeeded()
|
|
|
|
// must be checked on the guard object before proceeding.
|
|
|
|
class MOZ_RAII DualTextureClientAutoLock {
|
|
|
|
public:
|
|
|
|
DualTextureClientAutoLock(TextureClient* aTexture,
|
|
|
|
TextureClient* aTextureOnWhite, OpenMode aMode)
|
|
|
|
: mTarget(nullptr), mTexture(aTexture), mTextureOnWhite(aTextureOnWhite) {
|
|
|
|
if (!mTexture->Lock(aMode)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTarget = mTexture->BorrowDrawTarget();
|
|
|
|
|
|
|
|
if (!mTarget) {
|
|
|
|
mTexture->Unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTextureOnWhite) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTextureOnWhite->Lock(aMode)) {
|
|
|
|
mTarget = nullptr;
|
|
|
|
mTexture->Unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<gfx::DrawTarget> targetOnWhite = mTextureOnWhite->BorrowDrawTarget();
|
|
|
|
|
|
|
|
if (!targetOnWhite) {
|
|
|
|
mTarget = nullptr;
|
|
|
|
mTexture->Unlock();
|
|
|
|
mTextureOnWhite->Unlock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTarget = gfx::Factory::CreateDualDrawTarget(mTarget, targetOnWhite);
|
|
|
|
|
|
|
|
if (!mTarget) {
|
|
|
|
mTarget = nullptr;
|
|
|
|
mTexture->Unlock();
|
|
|
|
mTextureOnWhite->Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~DualTextureClientAutoLock() {
|
|
|
|
if (Succeeded()) {
|
|
|
|
mTarget = nullptr;
|
|
|
|
|
|
|
|
mTexture->Unlock();
|
|
|
|
if (mTextureOnWhite) {
|
|
|
|
mTextureOnWhite->Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Succeeded() const { return !!mTarget; }
|
|
|
|
|
|
|
|
operator gfx::DrawTarget*() const { return mTarget; }
|
|
|
|
gfx::DrawTarget* operator->() const { return mTarget; }
|
|
|
|
|
|
|
|
RefPtr<gfx::DrawTarget> mTarget;
|
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<TextureClient> mTexture;
|
|
|
|
RefPtr<TextureClient> mTextureOnWhite;
|
|
|
|
};
|
|
|
|
|
2014-07-22 19:49:05 +04:00
|
|
|
class KeepAlive {
|
|
|
|
public:
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~KeepAlive() = default;
|
2014-07-22 19:49:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class TKeepAlive : public KeepAlive {
|
|
|
|
public:
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit TKeepAlive(T* aData) : mData(aData) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-22 19:49:05 +04:00
|
|
|
protected:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<T> mData;
|
2014-07-22 19:49:05 +04:00
|
|
|
};
|
|
|
|
|
2015-10-15 18:53:33 +03:00
|
|
|
/// Convenience function to set the content of ycbcr texture.
|
|
|
|
bool UpdateYCbCrTextureClient(TextureClient* aTexture,
|
|
|
|
const PlanarYCbCrData& aData);
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // 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
|
|
|
#endif
|