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/. */
|
|
|
|
|
|
|
|
#include "mozilla/layers/TextureClient.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include <stdint.h> // for uint8_t, uint32_t, etc
|
|
|
|
#include "Layers.h" // for Layer, etc
|
2013-12-20 20:46:29 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "gfxPlatform.h" // for gfxPlatform
|
2018-11-28 23:44:27 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2015-10-16 15:46:33 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2019-05-26 17:30:14 +03:00
|
|
|
#include "mozilla/StaticPrefs.h"
|
2017-07-19 09:23:19 +03:00
|
|
|
#include "mozilla/SystemGroup.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
|
|
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
2016-06-15 14:28:10 +03:00
|
|
|
#include "mozilla/layers/ImageBridgeChild.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/ImageDataSerializer.h"
|
2017-08-05 21:54:11 +03:00
|
|
|
#include "mozilla/layers/PaintThread.h"
|
2015-12-02 22:31:17 +03:00
|
|
|
#include "mozilla/layers/TextureClientRecycleAllocator.h"
|
2018-12-02 17:19:11 +03:00
|
|
|
#include "mozilla/layers/TextureRecorded.h"
|
2016-06-15 14:28:10 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsDebug.h" // for NS_ASSERTION, NS_WARNING, etc
|
2014-02-27 01:36:35 +04:00
|
|
|
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
|
2014-07-15 11:59:34 +04:00
|
|
|
#include "ImageContainer.h" // for PlanarYCbCrData, etc
|
2013-10-16 05:00:30 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-12-09 21:19:29 +03:00
|
|
|
#include "mozilla/gfx/Logging.h" // for gfxDebug
|
2014-03-08 01:34:04 +04:00
|
|
|
#include "mozilla/layers/TextureClientOGL.h"
|
2014-04-28 15:29:13 +04:00
|
|
|
#include "mozilla/layers/PTextureChild.h"
|
2014-12-18 21:32:45 +03:00
|
|
|
#include "mozilla/gfx/DataSurfaceHelpers.h" // for CreateDataSourceSurfaceByCloning
|
|
|
|
#include "nsPrintfCString.h" // for nsPrintfCString
|
|
|
|
#include "LayersLogging.h" // for AppendToString
|
|
|
|
#include "gfxUtils.h" // for gfxUtils::GetAsLZ4Base64Str
|
2015-11-06 18:56:03 +03:00
|
|
|
#include "IPDLActor.h"
|
2015-10-15 18:53:33 +03:00
|
|
|
#include "BufferTexture.h"
|
2016-06-02 12:00:12 +03:00
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
2017-02-14 11:10:36 +03:00
|
|
|
#include "mozilla/ipc/CrossProcessSemaphore.h"
|
2014-03-08 01:34:04 +04:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2016-08-24 01:18:55 +03:00
|
|
|
# include "mozilla/gfx/DeviceManagerDx.h"
|
2014-03-08 01:34:04 +04:00
|
|
|
# include "mozilla/layers/TextureD3D11.h"
|
2014-07-11 01:29:40 +04:00
|
|
|
# include "mozilla/layers/TextureDIB.h"
|
2014-03-08 01:34:04 +04:00
|
|
|
# include "gfxWindowsPlatform.h"
|
|
|
|
# include "gfx2DGlue.h"
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
# include "mozilla/layers/TextureClientX11.h"
|
|
|
|
# include "GLXLibrary.h"
|
|
|
|
#endif
|
|
|
|
|
2016-06-27 18:25:13 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
# include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
|
|
|
|
#endif
|
|
|
|
|
2014-03-10 22:34:57 +04:00
|
|
|
#if 0
|
|
|
|
# define RECYCLE_LOG(...) printf_stderr(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
# define RECYCLE_LOG(...) \
|
|
|
|
do { \
|
|
|
|
} while (0)
|
|
|
|
#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 mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2014-05-22 14:11:45 +04:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::gl;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
struct TextureDeallocParams {
|
|
|
|
TextureData* data;
|
2016-04-13 20:55:08 +03:00
|
|
|
RefPtr<TextureChild> actor;
|
2016-09-27 06:22:20 +03:00
|
|
|
RefPtr<LayersIPCChannel> allocator;
|
2015-11-20 16:25:03 +03:00
|
|
|
bool clientDeallocation;
|
|
|
|
bool syncDeallocation;
|
|
|
|
bool workAroundSharedSurfaceOwnershipIssue;
|
2015-11-24 21:07:02 +03:00
|
|
|
};
|
2015-11-20 16:25:03 +03:00
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
void DeallocateTextureClient(TextureDeallocParams params);
|
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
/**
|
|
|
|
* TextureChild is the content-side incarnation of the PTexture IPDL actor.
|
|
|
|
*
|
|
|
|
* TextureChild is used to synchronize a texture client and its corresponding
|
|
|
|
* TextureHost if needed (a TextureClient that is not shared with the compositor
|
|
|
|
* does not have a TextureChild)
|
|
|
|
*
|
|
|
|
* During the deallocation phase, a TextureChild may hold its recently destroyed
|
|
|
|
* TextureClient's data until the compositor side confirmed that it is safe to
|
|
|
|
* deallocte or recycle the it.
|
|
|
|
*/
|
2016-09-22 08:40:20 +03:00
|
|
|
class TextureChild final : PTextureChild {
|
2015-03-26 03:05:25 +03:00
|
|
|
~TextureChild() {
|
2015-11-20 16:25:03 +03:00
|
|
|
// We should have deallocated mTextureData in ActorDestroy
|
|
|
|
MOZ_ASSERT(!mTextureData);
|
2016-11-10 05:25:27 +03:00
|
|
|
MOZ_ASSERT_IF(!mOwnerCalledDestroy, !mTextureClient);
|
2015-03-26 03:05:25 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
public:
|
2016-04-13 20:55:08 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureChild)
|
2014-04-14 23:04:25 +04:00
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
TextureChild()
|
2016-06-29 12:18:30 +03:00
|
|
|
: mCompositableForwarder(nullptr),
|
2016-05-13 01:00:04 +03:00
|
|
|
mTextureForwarder(nullptr),
|
2015-10-16 15:46:33 +03:00
|
|
|
mTextureClient(nullptr),
|
2015-11-20 16:25:03 +03:00
|
|
|
mTextureData(nullptr),
|
2016-04-13 20:55:08 +03:00
|
|
|
mDestroyed(false),
|
2015-10-16 16:22:06 +03:00
|
|
|
mMainThreadOnly(false),
|
2016-04-13 20:55:08 +03:00
|
|
|
mIPCOpen(false),
|
2015-11-20 16:25:03 +03:00
|
|
|
mOwnsTextureData(false),
|
2016-09-22 08:40:20 +03:00
|
|
|
mOwnerCalledDestroy(false) {}
|
2013-12-12 05:44:45 +04:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult Recv__delete__() override { return IPC_OK(); }
|
2013-12-12 05:44:45 +04:00
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
LayersIPCChannel* GetAllocator() { return mTextureForwarder; }
|
2013-12-12 05:44:45 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
void ActorDestroy(ActorDestroyReason why) override;
|
2013-12-12 05:44:55 +04:00
|
|
|
|
2016-04-13 20:55:08 +03:00
|
|
|
bool IPCOpen() const { return mIPCOpen; }
|
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
void Lock() const {
|
|
|
|
if (mCompositableForwarder &&
|
|
|
|
mCompositableForwarder->GetTextureForwarder()->UsesImageBridge()) {
|
|
|
|
mLock.Enter();
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 19:05:26 +03:00
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
void Unlock() const {
|
|
|
|
if (mCompositableForwarder &&
|
2016-04-13 20:55:08 +03:00
|
|
|
mCompositableForwarder->GetTextureForwarder()->UsesImageBridge()) {
|
2016-09-27 06:22:20 +03:00
|
|
|
mLock.Leave();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-13 20:55:08 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// AddIPDLReference and ReleaseIPDLReference are only to be called by
|
|
|
|
// CreateIPDLActor and DestroyIPDLActor, respectively. We intentionally make
|
|
|
|
// them private to prevent misuse. The purpose of these methods is to be aware
|
|
|
|
// of when the IPC system around this actor goes down: mIPCOpen is then set to
|
|
|
|
// false.
|
|
|
|
void AddIPDLReference() {
|
|
|
|
MOZ_ASSERT(mIPCOpen == false);
|
|
|
|
mIPCOpen = true;
|
|
|
|
AddRef();
|
|
|
|
}
|
|
|
|
void ReleaseIPDLReference() {
|
2017-05-31 17:18:13 +03:00
|
|
|
MOZ_ASSERT(mIPCOpen == false);
|
2016-04-13 20:55:08 +03:00
|
|
|
Release();
|
|
|
|
}
|
|
|
|
|
2016-09-22 08:40:20 +03:00
|
|
|
/// The normal way to destroy the actor.
|
|
|
|
///
|
|
|
|
/// This will asynchronously send a Destroy message to the parent actor, whom
|
|
|
|
/// will send the delete message.
|
2016-09-22 08:40:21 +03:00
|
|
|
void Destroy(const TextureDeallocParams& aParams);
|
2016-09-22 08:40:20 +03:00
|
|
|
|
2016-05-31 19:03:51 +03:00
|
|
|
// This lock is used order to prevent several threads to access the
|
|
|
|
// TextureClient's data concurrently. In particular, it prevents shutdown
|
|
|
|
// code to destroy a texture while another thread is reading or writing into
|
|
|
|
// it.
|
|
|
|
// In most places, the lock is held in short and bounded scopes in which we
|
|
|
|
// don't block on any other resource. There are few exceptions to this, which
|
|
|
|
// are discussed below.
|
|
|
|
//
|
|
|
|
// The locking pattern of TextureClient may in some case upset deadlock
|
|
|
|
// detection tools such as TSan. Typically our tile rendering code will lock
|
|
|
|
// all of its tiles, render into them and unlock them all right after that,
|
|
|
|
// which looks something like:
|
|
|
|
//
|
|
|
|
// Lock tile A
|
|
|
|
// Lock tile B
|
|
|
|
// Lock tile C
|
2017-04-12 08:58:47 +03:00
|
|
|
// Apply drawing commands to tiles A, B and C
|
2016-05-31 19:03:51 +03:00
|
|
|
// Unlock tile A
|
|
|
|
// Unlock tile B
|
|
|
|
// Unlock tile C
|
|
|
|
//
|
|
|
|
// And later, we may end up rendering a tile buffer that has the same tiles,
|
|
|
|
// in a different order, for example:
|
|
|
|
//
|
|
|
|
// Lock tile B
|
|
|
|
// Lock tile A
|
|
|
|
// Lock tile D
|
|
|
|
// Apply drawing commands to tiles A, B and D
|
|
|
|
// Unlock tile B
|
|
|
|
// Unlock tile A
|
|
|
|
// Unlock tile D
|
|
|
|
//
|
|
|
|
// This is because textures being expensive to create, we recycle them as much
|
|
|
|
// as possible and they may reappear in the tile buffer in a different order.
|
|
|
|
//
|
|
|
|
// Unfortunately this is not very friendly to TSan's analysis, which will see
|
|
|
|
// that B was once locked while A was locked, and then A locked while B was
|
|
|
|
// locked. TSan identifies this as a potential dead-lock which would be the
|
|
|
|
// case if this kind of inconsistent and dependent locking order was happening
|
|
|
|
// concurrently.
|
|
|
|
// In the case of TextureClient, dependent locking only ever happens on the
|
|
|
|
// thread that draws into the texture (let's call it the producer thread).
|
|
|
|
// Other threads may call into a method that can lock the texture in a short
|
|
|
|
// and bounded scope inside of which it is not allowed to do anything that
|
|
|
|
// could cause the thread to block. A given texture can only have one producer
|
|
|
|
// thread.
|
|
|
|
//
|
|
|
|
// Another example of TSan-unfriendly locking pattern is when copying a
|
|
|
|
// texture into another, which also never happens outside of the producer
|
|
|
|
// thread. Copying A into B looks like this:
|
|
|
|
//
|
|
|
|
// Lock texture B
|
|
|
|
// Lock texture A
|
|
|
|
// Copy A into B
|
|
|
|
// Unlock A
|
|
|
|
// Unlock B
|
|
|
|
//
|
|
|
|
// In a given frame we may need to copy A into B and in another frame copy
|
|
|
|
// B into A. For example A and B can be the Front and Back buffers,
|
|
|
|
// alternating roles and the copy is needed to avoid the cost of re-drawing
|
|
|
|
// the valid region.
|
|
|
|
//
|
|
|
|
// The important rule is that all of the dependent locking must occur only
|
|
|
|
// in the texture's producer thread to avoid deadlocks.
|
2016-04-22 19:05:26 +03:00
|
|
|
mutable gfx::CriticalSection mLock;
|
2016-04-13 20:55:08 +03:00
|
|
|
|
2016-06-29 12:18:30 +03:00
|
|
|
RefPtr<CompositableForwarder> mCompositableForwarder;
|
2016-05-13 01:00:04 +03:00
|
|
|
RefPtr<TextureForwarder> mTextureForwarder;
|
2015-10-16 15:46:33 +03:00
|
|
|
|
2013-12-12 05:44:55 +04:00
|
|
|
TextureClient* mTextureClient;
|
2015-11-20 16:25:03 +03:00
|
|
|
TextureData* mTextureData;
|
2016-04-13 20:55:08 +03:00
|
|
|
Atomic<bool> mDestroyed;
|
2015-03-26 03:05:25 +03:00
|
|
|
bool mMainThreadOnly;
|
2016-04-13 20:55:08 +03:00
|
|
|
bool mIPCOpen;
|
2015-11-20 16:25:03 +03:00
|
|
|
bool mOwnsTextureData;
|
2016-09-22 08:40:20 +03:00
|
|
|
bool mOwnerCalledDestroy;
|
2013-12-12 05:44:44 +04:00
|
|
|
|
2013-12-12 05:44:55 +04:00
|
|
|
friend class TextureClient;
|
2015-11-20 16:25:03 +03:00
|
|
|
friend void DeallocateTextureClient(TextureDeallocParams params);
|
2013-12-12 05:44:44 +04:00
|
|
|
};
|
|
|
|
|
2018-11-28 23:44:27 +03:00
|
|
|
static inline gfx::BackendType
|
|
|
|
BackendTypeForBackendSelector(LayersBackend aLayersBackend, BackendSelector aSelector)
|
|
|
|
{
|
|
|
|
switch (aSelector) {
|
|
|
|
case BackendSelector::Canvas:
|
|
|
|
return gfxPlatform::GetPlatform()->GetPreferredCanvasBackend();
|
|
|
|
case BackendSelector::Content:
|
|
|
|
return gfxPlatform::GetPlatform()->GetContentBackendFor(aLayersBackend);
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown backend selector");
|
|
|
|
return gfx::BackendType::NONE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static TextureType
|
|
|
|
GetTextureType(gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
|
|
|
|
LayersBackend aLayersBackend, gfx::BackendType aBackendType,
|
|
|
|
int32_t aMaxTextureSize, TextureAllocationFlags aAllocFlags)
|
|
|
|
{
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if ((aLayersBackend == LayersBackend::LAYERS_D3D11 ||
|
|
|
|
aLayersBackend == LayersBackend::LAYERS_WR) &&
|
|
|
|
(aBackendType == gfx::BackendType::DIRECT2D ||
|
|
|
|
aBackendType == gfx::BackendType::DIRECT2D1_1 ||
|
|
|
|
(!!(aAllocFlags & ALLOC_FOR_OUT_OF_BAND_CONTENT) &&
|
|
|
|
DeviceManagerDx::Get()->GetContentDevice())) &&
|
|
|
|
aSize.width <= aMaxTextureSize &&
|
|
|
|
aSize.height <= aMaxTextureSize &&
|
|
|
|
!(aAllocFlags & ALLOC_UPDATE_FROM_SURFACE)) {
|
|
|
|
return TextureType::D3D11;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aLayersBackend != LayersBackend::LAYERS_WR &&
|
|
|
|
aFormat == SurfaceFormat::B8G8R8X8 &&
|
|
|
|
aBackendType == gfx::BackendType::CAIRO &&
|
|
|
|
NS_IsMainThread()) {
|
|
|
|
return TextureType::DIB;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
gfxSurfaceType type =
|
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType();
|
|
|
|
|
|
|
|
if (aLayersBackend == LayersBackend::LAYERS_BASIC &&
|
|
|
|
aBackendType == gfx::BackendType::CAIRO &&
|
|
|
|
type == gfxSurfaceType::Xlib) {
|
|
|
|
return TextureType::X11;
|
|
|
|
}
|
|
|
|
if (aLayersBackend == LayersBackend::LAYERS_OPENGL &&
|
|
|
|
type == gfxSurfaceType::Xlib &&
|
|
|
|
aFormat != SurfaceFormat::A8 &&
|
|
|
|
gl::sGLXLibrary.UseTextureFromPixmap()) {
|
|
|
|
return TextureType::X11;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2019-06-26 03:38:09 +03:00
|
|
|
if (StaticPrefs::gfx_use_iosurface_textures()) {
|
2018-11-28 23:44:27 +03:00
|
|
|
return TextureType::MacIOSurface;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2019-06-26 03:38:09 +03:00
|
|
|
if (StaticPrefs::gfx_use_surfacetexture_textures()) {
|
2018-11-28 23:44:27 +03:00
|
|
|
return TextureType::AndroidNativeWindow;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return TextureType::Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ShouldRemoteTextureType(TextureType aTextureType, BackendSelector aSelector)
|
|
|
|
{
|
|
|
|
if (!XRE_IsContentProcess()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSelector != BackendSelector::Canvas || !gfxVars::RemoteCanvasEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aTextureType) {
|
|
|
|
case TextureType::D3D11:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
TextureData*
|
|
|
|
TextureData::Create(TextureForwarder* aAllocator, gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::IntSize aSize, LayersBackend aLayersBackend,
|
|
|
|
int32_t aMaxTextureSize, BackendSelector aSelector,
|
|
|
|
TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags)
|
|
|
|
{
|
|
|
|
gfx::BackendType moz2DBackend =
|
|
|
|
BackendTypeForBackendSelector(aLayersBackend, aSelector);
|
|
|
|
|
|
|
|
TextureType textureType = GetTextureType(aFormat, aSize, aLayersBackend,
|
|
|
|
moz2DBackend, aMaxTextureSize,
|
|
|
|
aAllocFlags);
|
|
|
|
|
|
|
|
if (ShouldRemoteTextureType(textureType, aSelector)) {
|
2018-12-02 17:19:11 +03:00
|
|
|
RefPtr<CanvasChild> canvasChild = aAllocator->GetCanvasChild();
|
|
|
|
if (canvasChild) {
|
|
|
|
return new RecordedTextureData(canvasChild.forget(), aSize, aFormat,
|
|
|
|
textureType);
|
|
|
|
}
|
2018-11-28 23:44:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(textureType) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
case TextureType::D3D11:
|
|
|
|
return D3D11TextureData::Create(aSize, aFormat, aAllocFlags);
|
|
|
|
case TextureType::DIB:
|
|
|
|
return DIBTextureData::Create(aSize, aFormat, aAllocator);
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
case TextureType::X11:
|
|
|
|
return X11TextureData::Create(aSize, aFormat, aTextureFlags, aAllocator);
|
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case TextureType::MacIOSurface:
|
|
|
|
return MacIOSurfaceTextureData::Create(aSize, aFormat, moz2DBackend);
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
case TextureType::AndroidNativeWindow:
|
|
|
|
return AndroidNativeWindowTextureData::Create(aSize, aFormat);
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
TextureData::IsRemote(LayersBackend aLayersBackend, BackendSelector aSelector)
|
|
|
|
{
|
|
|
|
gfx::BackendType moz2DBackend =
|
|
|
|
BackendTypeForBackendSelector(aLayersBackend, aSelector);
|
|
|
|
|
|
|
|
TextureType textureType =
|
|
|
|
GetTextureType(gfx::SurfaceFormat::UNKNOWN, gfx::IntSize(1,1),
|
|
|
|
aLayersBackend, moz2DBackend, INT32_MAX,
|
|
|
|
TextureAllocationFlags::ALLOC_DEFAULT);
|
|
|
|
|
|
|
|
return ShouldRemoteTextureType(textureType, aSelector);
|
|
|
|
}
|
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
static void DestroyTextureData(TextureData* aTextureData,
|
|
|
|
LayersIPCChannel* aAllocator, bool aDeallocate,
|
2015-11-20 16:25:03 +03:00
|
|
|
bool aMainThreadOnly) {
|
|
|
|
if (!aTextureData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMainThreadOnly && !NS_IsMainThread()) {
|
2016-09-27 06:22:20 +03:00
|
|
|
RefPtr<LayersIPCChannel> allocatorRef = aAllocator;
|
2017-07-26 11:13:35 +03:00
|
|
|
SystemGroup::Dispatch(
|
|
|
|
TaskCategory::Other,
|
|
|
|
NS_NewRunnableFunction(
|
2017-07-19 09:23:19 +03:00
|
|
|
"layers::DestroyTextureData",
|
|
|
|
[aTextureData, allocatorRef, aDeallocate]() -> void {
|
|
|
|
DestroyTextureData(aTextureData, allocatorRef, aDeallocate, true);
|
|
|
|
}));
|
2015-11-20 16:25:03 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDeallocate) {
|
|
|
|
aTextureData->Deallocate(aAllocator);
|
|
|
|
} else {
|
|
|
|
aTextureData->Forget(aAllocator);
|
|
|
|
}
|
|
|
|
delete aTextureData;
|
2015-10-13 19:48:48 +03:00
|
|
|
}
|
|
|
|
|
2015-11-24 21:07:02 +03:00
|
|
|
void TextureChild::ActorDestroy(ActorDestroyReason why) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL("TextureChild::ActorDestroy", GRAPHICS);
|
2017-05-31 17:18:13 +03:00
|
|
|
MOZ_ASSERT(mIPCOpen);
|
|
|
|
mIPCOpen = false;
|
2015-11-20 16:25:03 +03:00
|
|
|
|
|
|
|
if (mTextureData) {
|
|
|
|
DestroyTextureData(mTextureData, GetAllocator(), mOwnsTextureData,
|
|
|
|
mMainThreadOnly);
|
|
|
|
mTextureData = nullptr;
|
|
|
|
}
|
2015-10-15 18:53:37 +03:00
|
|
|
}
|
|
|
|
|
2016-09-22 08:40:21 +03:00
|
|
|
void TextureChild::Destroy(const TextureDeallocParams& aParams) {
|
2016-09-22 08:40:20 +03:00
|
|
|
MOZ_ASSERT(!mOwnerCalledDestroy);
|
2016-09-22 08:40:21 +03:00
|
|
|
if (mOwnerCalledDestroy) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOwnerCalledDestroy = true;
|
|
|
|
|
|
|
|
if (!IPCOpen()) {
|
2017-02-16 01:28:24 +03:00
|
|
|
DestroyTextureData(aParams.data, aParams.allocator,
|
|
|
|
aParams.clientDeallocation, mMainThreadOnly);
|
2016-09-22 08:40:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-16 01:28:24 +03:00
|
|
|
// DestroyTextureData will be called by TextureChild::ActorDestroy
|
|
|
|
mTextureData = aParams.data;
|
|
|
|
mOwnsTextureData = aParams.clientDeallocation;
|
|
|
|
|
2016-09-22 08:40:21 +03:00
|
|
|
if (!mCompositableForwarder ||
|
2017-02-16 01:28:24 +03:00
|
|
|
!mCompositableForwarder->DestroyInTransaction(this)) {
|
2016-09-22 08:40:21 +03:00
|
|
|
this->SendDestroy();
|
2016-09-22 08:40:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
Atomic<uint64_t> TextureClient::sSerialCounter(0);
|
2016-06-15 14:28:10 +03:00
|
|
|
|
2019-02-18 01:25:01 +03:00
|
|
|
static void DeallocateTextureClientSyncProxy(TextureDeallocParams params,
|
|
|
|
ReentrantMonitor* aBarrier,
|
|
|
|
bool* aDone) {
|
2015-11-20 16:25:03 +03:00
|
|
|
DeallocateTextureClient(params);
|
|
|
|
ReentrantMonitorAutoEnter autoMon(*aBarrier);
|
|
|
|
*aDone = true;
|
|
|
|
aBarrier->NotifyAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The logic for synchronizing a TextureClient's deallocation goes here.
|
|
|
|
///
|
|
|
|
/// This funciton takes care of dispatching work to the right thread using
|
|
|
|
/// a synchronous proxy if needed, and handles client/host deallocation.
|
|
|
|
void DeallocateTextureClient(TextureDeallocParams params) {
|
2016-01-12 18:00:24 +03:00
|
|
|
if (!params.actor && !params.data) {
|
|
|
|
// Nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
TextureChild* actor = params.actor;
|
|
|
|
MessageLoop* ipdlMsgLoop = nullptr;
|
|
|
|
|
|
|
|
if (params.allocator) {
|
2016-09-27 06:22:20 +03:00
|
|
|
ipdlMsgLoop = params.allocator->GetMessageLoop();
|
2015-11-20 16:25:03 +03:00
|
|
|
if (!ipdlMsgLoop) {
|
|
|
|
// An allocator with no message loop means we are too late in the shutdown
|
|
|
|
// sequence.
|
2016-04-13 20:55:08 +03:00
|
|
|
gfxCriticalError() << "Texture deallocated too late during shutdown";
|
2015-11-20 16:25:03 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// First make sure that the work is happening on the IPDL thread.
|
|
|
|
if (ipdlMsgLoop && MessageLoop::current() != ipdlMsgLoop) {
|
|
|
|
if (params.syncDeallocation) {
|
|
|
|
bool done = false;
|
|
|
|
ReentrantMonitor barrier("DeallocateTextureClient");
|
|
|
|
ReentrantMonitorAutoEnter autoMon(barrier);
|
2017-10-27 23:39:28 +03:00
|
|
|
ipdlMsgLoop->PostTask(NewRunnableFunction(
|
|
|
|
"DeallocateTextureClientSyncProxyRunnable",
|
|
|
|
DeallocateTextureClientSyncProxy, params, &barrier, &done));
|
2015-11-20 16:25:03 +03:00
|
|
|
while (!done) {
|
|
|
|
barrier.Wait();
|
|
|
|
}
|
|
|
|
} else {
|
2017-10-27 23:39:28 +03:00
|
|
|
ipdlMsgLoop->PostTask(NewRunnableFunction(
|
|
|
|
"DeallocateTextureClientRunnable", DeallocateTextureClient, params));
|
2015-11-20 16:25:03 +03:00
|
|
|
}
|
|
|
|
// The work has been forwarded to the IPDL thread, we are done.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Below this line, we are either in the IPDL thread or ther is no IPDL
|
|
|
|
// thread anymore.
|
|
|
|
|
|
|
|
if (!ipdlMsgLoop) {
|
|
|
|
// If we don't have a message loop we can't know for sure that we are in
|
2016-09-27 06:22:20 +03:00
|
|
|
// the IPDL thread and use the LayersIPCChannel.
|
2015-11-20 16:25:03 +03:00
|
|
|
// This should ideally not happen outside of gtest, but some shutdown
|
|
|
|
// raciness could put us in this situation.
|
|
|
|
params.allocator = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!actor) {
|
|
|
|
// We don't have an IPDL actor, probably because we destroyed the
|
|
|
|
// TextureClient before sharing it with the compositor. It means the data
|
|
|
|
// cannot be owned by the TextureHost since we never created the
|
|
|
|
// TextureHost...
|
|
|
|
// ..except if the lovely mWorkaroundAnnoyingSharedSurfaceOwnershipIssues
|
|
|
|
// member is set to true. In this case we are in a special situation where
|
|
|
|
// this TextureClient is in wrapped into another TextureClient which assumes
|
2016-11-16 09:01:30 +03:00
|
|
|
// it owns our data.
|
2015-11-20 16:25:03 +03:00
|
|
|
bool shouldDeallocate = !params.workAroundSharedSurfaceOwnershipIssue;
|
|
|
|
DestroyTextureData(params.data, params.allocator, shouldDeallocate,
|
|
|
|
false); // main-thread deallocation
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-16 01:28:24 +03:00
|
|
|
actor->Destroy(params);
|
2015-11-20 16:25:03 +03:00
|
|
|
}
|
|
|
|
|
2017-02-16 01:28:24 +03:00
|
|
|
void TextureClient::Destroy() {
|
2017-08-05 21:54:11 +03:00
|
|
|
// Async paints should have been flushed by now.
|
|
|
|
MOZ_RELEASE_ASSERT(mPaintThreadRefs == 0);
|
|
|
|
|
2016-07-26 13:56:38 +03:00
|
|
|
if (mActor && !mIsLocked) {
|
2016-04-22 19:05:26 +03:00
|
|
|
mActor->Lock();
|
|
|
|
}
|
2015-11-20 16:25:03 +03:00
|
|
|
|
2016-07-26 13:56:38 +03:00
|
|
|
mBorrowedDrawTarget = nullptr;
|
2016-07-01 11:58:18 +03:00
|
|
|
mReadLock = nullptr;
|
|
|
|
|
2016-04-13 20:55:08 +03:00
|
|
|
RefPtr<TextureChild> actor = mActor;
|
2015-11-20 16:25:03 +03:00
|
|
|
mActor = nullptr;
|
|
|
|
|
2016-04-13 20:55:08 +03:00
|
|
|
if (actor && !actor->mDestroyed.compareExchange(false, true)) {
|
2016-04-22 19:05:26 +03:00
|
|
|
actor->Unlock();
|
2015-11-20 16:25:03 +03:00
|
|
|
actor = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureData* data = mData;
|
|
|
|
if (!mWorkaroundAnnoyingSharedSurfaceLifetimeIssues) {
|
|
|
|
mData = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data || actor) {
|
|
|
|
TextureDeallocParams params;
|
|
|
|
params.actor = actor;
|
|
|
|
params.allocator = mAllocator;
|
|
|
|
params.clientDeallocation = !!(mFlags & TextureFlags::DEALLOCATE_CLIENT);
|
|
|
|
params.workAroundSharedSurfaceOwnershipIssue =
|
|
|
|
mWorkaroundAnnoyingSharedSurfaceOwnershipIssues;
|
|
|
|
if (mWorkaroundAnnoyingSharedSurfaceLifetimeIssues) {
|
|
|
|
params.data = nullptr;
|
|
|
|
} else {
|
|
|
|
params.data = data;
|
|
|
|
}
|
|
|
|
// At the moment we always deallocate synchronously when deallocating on the
|
|
|
|
// client side, but having asynchronous deallocate in some of the cases will
|
|
|
|
// be a worthwhile optimization.
|
2017-02-16 01:28:24 +03:00
|
|
|
params.syncDeallocation = !!(mFlags & TextureFlags::DEALLOCATE_CLIENT);
|
2016-04-22 19:05:26 +03:00
|
|
|
|
|
|
|
// Release the lock before calling DeallocateTextureClient because the
|
|
|
|
// latter may wait for the main thread which could create a dead-lock.
|
|
|
|
|
|
|
|
if (actor) {
|
|
|
|
actor->Unlock();
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
DeallocateTextureClient(params);
|
|
|
|
}
|
|
|
|
}
|
2015-10-15 18:53:33 +03:00
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
void TextureClient::LockActor() const {
|
|
|
|
if (mActor) {
|
|
|
|
mActor->Lock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureClient::UnlockActor() const {
|
|
|
|
if (mActor) {
|
|
|
|
mActor->Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 12:00:17 +03:00
|
|
|
bool TextureClient::IsReadLocked() const {
|
2017-02-04 13:19:11 +03:00
|
|
|
if (!mReadLock) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(mReadLock->AsNonBlockingLock(),
|
|
|
|
"Can only check locked for non-blocking locks!");
|
|
|
|
return mReadLock->AsNonBlockingLock()->GetReadCount() > 1;
|
2016-06-02 12:00:17 +03:00
|
|
|
}
|
|
|
|
|
2017-02-04 13:19:22 +03:00
|
|
|
bool TextureClient::TryReadLock() {
|
|
|
|
if (!mReadLock || mIsReadLocked) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mReadLock->AsNonBlockingLock()) {
|
|
|
|
if (IsReadLocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-14 11:10:36 +03:00
|
|
|
if (!mReadLock->TryReadLock(TimeDuration::FromMilliseconds(500))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-04 13:19:22 +03:00
|
|
|
mIsReadLocked = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureClient::ReadUnlock() {
|
|
|
|
if (!mIsReadLocked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(mReadLock);
|
|
|
|
mReadLock->ReadUnlock();
|
|
|
|
mIsReadLocked = false;
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
bool TextureClient::Lock(OpenMode aMode) {
|
2015-11-20 16:25:03 +03:00
|
|
|
MOZ_ASSERT(IsValid());
|
2015-10-13 19:48:48 +03:00
|
|
|
MOZ_ASSERT(!mIsLocked);
|
2016-08-10 15:30:42 +03:00
|
|
|
if (!IsValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-13 19:48:48 +03:00
|
|
|
if (mIsLocked) {
|
|
|
|
return mOpenMode == aMode;
|
|
|
|
}
|
|
|
|
|
2017-10-28 13:59:58 +03:00
|
|
|
if ((aMode & OpenMode::OPEN_WRITE || !mInfo.canConcurrentlyReadLock) &&
|
|
|
|
!TryReadLock()) {
|
|
|
|
// Only warn if attempting to write. Attempting to read is acceptable usage.
|
|
|
|
if (aMode & OpenMode::OPEN_WRITE) {
|
|
|
|
NS_WARNING(
|
|
|
|
"Attempt to Lock a texture that is being read by the compositor!");
|
|
|
|
}
|
2016-06-02 12:00:17 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
LockActor();
|
|
|
|
|
2016-10-27 11:02:09 +03:00
|
|
|
mIsLocked = mData->Lock(aMode);
|
2015-10-13 19:48:48 +03:00
|
|
|
mOpenMode = aMode;
|
|
|
|
|
2015-12-30 15:23:01 +03:00
|
|
|
auto format = GetFormat();
|
|
|
|
if (mIsLocked && CanExposeDrawTarget() &&
|
2017-07-26 08:38:33 +03:00
|
|
|
(aMode & OpenMode::OPEN_READ_WRITE) == OpenMode::OPEN_READ_WRITE &&
|
2015-12-30 15:23:01 +03:00
|
|
|
NS_IsMainThread() &&
|
|
|
|
// the formats that we apparently expect, in the cairo backend. Any other
|
|
|
|
// format will trigger an assertion in GfxFormatToCairoFormat.
|
|
|
|
(format == SurfaceFormat::A8R8G8B8_UINT32 ||
|
|
|
|
format == SurfaceFormat::X8R8G8B8_UINT32 ||
|
|
|
|
format == SurfaceFormat::A8 || format == SurfaceFormat::R5G6B5_UINT16)) {
|
|
|
|
if (!BorrowDrawTarget()) {
|
|
|
|
// Failed to get a DrawTarget, means we won't be able to write into the
|
|
|
|
// texture, might as well fail now.
|
|
|
|
Unlock();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
if (!mIsLocked) {
|
|
|
|
UnlockActor();
|
2017-02-04 13:19:22 +03:00
|
|
|
ReadUnlock();
|
2016-04-22 19:05:26 +03:00
|
|
|
}
|
|
|
|
|
2015-10-13 19:48:48 +03:00
|
|
|
return mIsLocked;
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
void TextureClient::Unlock() {
|
2015-11-20 16:25:03 +03:00
|
|
|
MOZ_ASSERT(IsValid());
|
2015-10-13 19:48:48 +03:00
|
|
|
MOZ_ASSERT(mIsLocked);
|
2016-08-10 15:30:42 +03:00
|
|
|
if (!IsValid() || !mIsLocked) {
|
2015-10-13 19:48:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mBorrowedDrawTarget) {
|
2017-11-30 03:00:50 +03:00
|
|
|
if (!(mOpenMode & OpenMode::OPEN_ASYNC)) {
|
2017-08-02 21:37:31 +03:00
|
|
|
if (mOpenMode & OpenMode::OPEN_WRITE) {
|
|
|
|
mBorrowedDrawTarget->Flush();
|
|
|
|
if (mReadbackSink && !mData->ReadBack(mReadbackSink)) {
|
|
|
|
// Fallback implementation for reading back, because mData does not
|
|
|
|
// have a backend-specific implementation and returned false.
|
|
|
|
RefPtr<SourceSurface> snapshot = mBorrowedDrawTarget->Snapshot();
|
|
|
|
RefPtr<DataSourceSurface> dataSurf = snapshot->GetDataSurface();
|
|
|
|
mReadbackSink->ProcessReadback(dataSurf);
|
|
|
|
}
|
2015-10-13 19:48:48 +03:00
|
|
|
}
|
2016-07-01 11:58:13 +03:00
|
|
|
|
2017-08-02 21:37:31 +03:00
|
|
|
mBorrowedDrawTarget->DetachAllSnapshots();
|
|
|
|
// If this assertion is hit, it means something is holding a strong
|
|
|
|
// reference to our DrawTarget externally, which is not allowed.
|
|
|
|
MOZ_ASSERT(mBorrowedDrawTarget->refCount() <= mExpectedDtRefs);
|
|
|
|
}
|
2016-07-01 11:58:13 +03:00
|
|
|
|
2015-10-13 19:48:48 +03:00
|
|
|
mBorrowedDrawTarget = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-06-02 12:00:21 +03:00
|
|
|
if (mOpenMode & OpenMode::OPEN_WRITE) {
|
2016-06-02 12:00:36 +03:00
|
|
|
mUpdated = true;
|
2016-06-02 12:00:21 +03:00
|
|
|
}
|
|
|
|
|
2016-07-26 13:56:38 +03:00
|
|
|
if (mData) {
|
|
|
|
mData->Unlock();
|
|
|
|
}
|
2015-10-13 19:48:48 +03:00
|
|
|
mIsLocked = false;
|
|
|
|
mOpenMode = OpenMode::OPEN_NONE;
|
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
UnlockActor();
|
2017-02-04 13:19:22 +03:00
|
|
|
ReadUnlock();
|
2015-10-13 19:48:48 +03:00
|
|
|
}
|
|
|
|
|
2016-06-02 12:00:21 +03:00
|
|
|
void TextureClient::EnableReadLock() {
|
|
|
|
if (!mReadLock) {
|
2018-03-13 09:39:56 +03:00
|
|
|
if (mAllocator->GetTileLockAllocator()) {
|
|
|
|
mReadLock = NonBlockingTextureReadLock::Create(mAllocator);
|
|
|
|
} else {
|
|
|
|
// IPC is down
|
|
|
|
gfxCriticalError() << "TextureClient::EnableReadLock IPC is down";
|
|
|
|
}
|
2016-06-02 12:00:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-12 16:10:13 +03:00
|
|
|
bool TextureClient::OnForwardedToHost() {
|
2017-10-28 13:59:58 +03:00
|
|
|
if (mData) {
|
|
|
|
mData->OnForwardedToHost();
|
|
|
|
}
|
|
|
|
|
2016-06-02 12:00:36 +03:00
|
|
|
if (mReadLock && mUpdated) {
|
|
|
|
// Take a read lock on behalf of the TextureHost. The latter will unlock
|
|
|
|
// after the shared data is available again for drawing.
|
|
|
|
mReadLock->ReadLock();
|
|
|
|
mUpdated = false;
|
2018-03-12 16:10:13 +03:00
|
|
|
return true;
|
2016-06-02 12:00:21 +03:00
|
|
|
}
|
2017-04-19 06:15:42 +03:00
|
|
|
|
|
|
|
return false;
|
2016-06-02 12:00:21 +03:00
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
TextureClient::~TextureClient() {
|
2017-08-05 21:54:11 +03:00
|
|
|
// TextureClients should be kept alive while there are references on the
|
|
|
|
// paint thread.
|
|
|
|
MOZ_ASSERT(mPaintThreadRefs == 0);
|
2016-06-02 12:00:36 +03:00
|
|
|
mReadLock = nullptr;
|
2017-02-16 01:28:24 +03:00
|
|
|
Destroy();
|
2015-10-15 18:53:37 +03:00
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
void TextureClient::UpdateFromSurface(gfx::SourceSurface* aSurface) {
|
2015-11-20 16:25:03 +03:00
|
|
|
MOZ_ASSERT(IsValid());
|
2015-10-13 19:48:48 +03:00
|
|
|
MOZ_ASSERT(mIsLocked);
|
2015-10-15 18:53:33 +03:00
|
|
|
MOZ_ASSERT(aSurface);
|
2015-12-30 15:23:01 +03:00
|
|
|
// If you run into this assertion, make sure the texture was locked write-only
|
|
|
|
// rather than read-write.
|
|
|
|
MOZ_ASSERT(!mBorrowedDrawTarget);
|
2015-10-15 18:53:33 +03:00
|
|
|
|
|
|
|
// XXX - It would be better to first try the DrawTarget approach and fallback
|
|
|
|
// to the backend-specific implementation because the latter will usually do
|
|
|
|
// an expensive read-back + cpu-side copy if the texture is on the gpu.
|
|
|
|
// There is a bug with the DrawTarget approach, though specific to reading
|
|
|
|
// back from WebGL (where R and B channel end up inverted) to figure out
|
|
|
|
// first.
|
|
|
|
if (mData->UpdateFromSurface(aSurface)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-13 19:48:48 +03:00
|
|
|
if (CanExposeDrawTarget() && NS_IsMainThread()) {
|
|
|
|
RefPtr<DrawTarget> dt = BorrowDrawTarget();
|
|
|
|
|
|
|
|
MOZ_ASSERT(dt);
|
2015-10-15 18:53:33 +03:00
|
|
|
if (dt) {
|
|
|
|
dt->CopySurface(aSurface,
|
|
|
|
gfx::IntRect(gfx::IntPoint(0, 0), aSurface->GetSize()),
|
|
|
|
gfx::IntPoint(0, 0));
|
2015-10-13 19:48:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-11-20 16:25:00 +03:00
|
|
|
NS_WARNING("TextureClient::UpdateFromSurface failed");
|
2015-10-13 19:48:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TextureClient> TextureClient::CreateSimilar(
|
2018-05-03 04:20:25 +03:00
|
|
|
LayersBackend aLayersBackend, TextureFlags aFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags) const {
|
2015-11-20 16:25:03 +03:00
|
|
|
MOZ_ASSERT(IsValid());
|
2016-04-22 19:05:26 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(!mIsLocked);
|
|
|
|
if (mIsLocked) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
LockActor();
|
2018-05-03 04:20:25 +03:00
|
|
|
TextureData* data =
|
|
|
|
mData->CreateSimilar(mAllocator, aLayersBackend, aFlags, aAllocFlags);
|
2016-04-22 19:05:26 +03:00
|
|
|
UnlockActor();
|
|
|
|
|
2015-10-13 19:48:48 +03:00
|
|
|
if (!data) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
return MakeAndAddRef<TextureClient>(data, aFlags, mAllocator);
|
2015-10-13 19:48:48 +03:00
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
gfx::DrawTarget* TextureClient::BorrowDrawTarget() {
|
2015-11-20 16:25:03 +03:00
|
|
|
MOZ_ASSERT(IsValid());
|
2015-10-13 19:48:48 +03:00
|
|
|
MOZ_ASSERT(mIsLocked);
|
|
|
|
// TODO- We can't really assert that at the moment because there is code that
|
|
|
|
// Borrows the DrawTarget, just to get a snapshot, which is legit in term of
|
|
|
|
// OpenMode but we should have a way to get a SourceSurface directly instead.
|
|
|
|
// MOZ_ASSERT(mOpenMode & OpenMode::OPEN_WRITE);
|
|
|
|
|
2016-08-10 15:30:42 +03:00
|
|
|
if (!IsValid() || !mIsLocked) {
|
2015-10-13 19:48:48 +03:00
|
|
|
return nullptr;
|
2017-11-03 15:32:46 +03:00
|
|
|
}
|
|
|
|
|
2015-10-13 19:48:48 +03:00
|
|
|
if (!mBorrowedDrawTarget) {
|
|
|
|
mBorrowedDrawTarget = mData->BorrowDrawTarget();
|
2015-10-15 18:53:33 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
mExpectedDtRefs = mBorrowedDrawTarget ? mBorrowedDrawTarget->refCount() : 0;
|
|
|
|
#endif
|
2015-10-13 19:48:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return mBorrowedDrawTarget;
|
|
|
|
}
|
|
|
|
|
2018-12-02 17:14:35 +03:00
|
|
|
already_AddRefed<gfx::SourceSurface> TextureClient::BorrowSnapshot() {
|
|
|
|
MOZ_ASSERT(mIsLocked);
|
|
|
|
|
|
|
|
RefPtr<gfx::SourceSurface> surface = mData->BorrowSnapshot();
|
|
|
|
if (!surface) {
|
|
|
|
surface = BorrowDrawTarget()->Snapshot();
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface.forget();
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
bool TextureClient::BorrowMappedData(MappedTextureData& aMap) {
|
2015-11-20 16:25:03 +03:00
|
|
|
MOZ_ASSERT(IsValid());
|
2015-10-15 18:53:33 +03:00
|
|
|
|
|
|
|
// TODO - SharedRGBImage just accesses the buffer without properly locking
|
|
|
|
// the texture. It's bad.
|
|
|
|
// MOZ_ASSERT(mIsLocked);
|
|
|
|
// if (!mIsLocked) {
|
|
|
|
// return nullptr;
|
|
|
|
//}
|
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
return mData ? mData->BorrowMappedData(aMap) : false;
|
2015-10-15 18:53:33 +03:00
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
bool TextureClient::BorrowMappedYCbCrData(MappedYCbCrTextureData& aMap) {
|
2015-11-20 16:25:03 +03:00
|
|
|
MOZ_ASSERT(IsValid());
|
2016-04-22 19:05:26 +03:00
|
|
|
|
|
|
|
return mData ? mData->BorrowMappedYCbCrData(aMap) : false;
|
2015-10-15 18:53:33 +03:00
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
bool TextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) {
|
2015-11-20 16:25:03 +03:00
|
|
|
MOZ_ASSERT(IsValid());
|
2016-04-22 19:05:26 +03:00
|
|
|
|
|
|
|
return mData ? mData->Serialize(aOutDescriptor) : false;
|
2015-10-13 19:48:48 +03:00
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
// static
|
|
|
|
PTextureChild* TextureClient::CreateIPDLActor() {
|
2016-04-13 20:55:08 +03:00
|
|
|
TextureChild* c = new TextureChild();
|
|
|
|
c->AddIPDLReference();
|
|
|
|
return c;
|
2013-12-12 05:44:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2016-04-13 20:55:08 +03:00
|
|
|
bool TextureClient::DestroyIPDLActor(PTextureChild* actor) {
|
|
|
|
static_cast<TextureChild*>(actor)->ReleaseIPDLReference();
|
2013-12-12 05:44:44 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-25 08:23:41 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<TextureClient> TextureClient::AsTextureClient(
|
|
|
|
PTextureChild* actor) {
|
2015-11-20 16:25:03 +03:00
|
|
|
if (!actor) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-04-22 19:05:26 +03:00
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
TextureChild* tc = static_cast<TextureChild*>(actor);
|
2016-04-22 19:05:26 +03:00
|
|
|
|
|
|
|
tc->Lock();
|
|
|
|
|
2016-09-22 08:40:21 +03:00
|
|
|
// Since TextureClient may be destroyed asynchronously with respect to its
|
|
|
|
// IPDL actor, we must acquire a reference within a lock. The mDestroyed bit
|
|
|
|
// tells us whether or not the main thread has disconnected the TextureClient
|
|
|
|
// from its actor.
|
2016-04-13 20:55:08 +03:00
|
|
|
if (tc->mDestroyed) {
|
2016-04-22 19:05:26 +03:00
|
|
|
tc->Unlock();
|
2015-11-20 16:25:03 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
RefPtr<TextureClient> texture = tc->mTextureClient;
|
|
|
|
tc->Unlock();
|
|
|
|
|
|
|
|
return texture.forget();
|
2014-03-10 22:34:57 +04:00
|
|
|
}
|
|
|
|
|
2015-09-30 19:17:30 +03:00
|
|
|
bool TextureClient::IsSharedWithCompositor() const {
|
2016-04-13 20:55:08 +03:00
|
|
|
return mActor && mActor->IPCOpen();
|
2015-09-30 19:17:30 +03:00
|
|
|
}
|
|
|
|
|
2014-11-13 18:53:49 +03:00
|
|
|
void TextureClient::AddFlags(TextureFlags aFlags) {
|
|
|
|
MOZ_ASSERT(
|
|
|
|
!IsSharedWithCompositor() ||
|
|
|
|
((GetFlags() & TextureFlags::RECYCLE) && !IsAddedToCompositableClient()));
|
|
|
|
mFlags |= aFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureClient::RemoveFlags(TextureFlags aFlags) {
|
|
|
|
MOZ_ASSERT(
|
|
|
|
!IsSharedWithCompositor() ||
|
|
|
|
((GetFlags() & TextureFlags::RECYCLE) && !IsAddedToCompositableClient()));
|
|
|
|
mFlags &= ~aFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureClient::RecycleTexture(TextureFlags aFlags) {
|
|
|
|
MOZ_ASSERT(GetFlags() & TextureFlags::RECYCLE);
|
2016-04-22 19:05:26 +03:00
|
|
|
MOZ_ASSERT(!mIsLocked);
|
2014-11-13 18:53:49 +03:00
|
|
|
|
|
|
|
mAddedToCompositableClient = false;
|
|
|
|
if (mFlags != aFlags) {
|
|
|
|
mFlags = aFlags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-15 14:28:10 +03:00
|
|
|
void TextureClient::SetAddedToCompositableClient() {
|
|
|
|
if (!mAddedToCompositableClient) {
|
|
|
|
mAddedToCompositableClient = true;
|
2016-06-30 05:12:31 +03:00
|
|
|
if (!(GetFlags() & TextureFlags::RECYCLE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(!mIsLocked);
|
|
|
|
LockActor();
|
|
|
|
if (IsValid() && mActor && !mActor->mDestroyed && mActor->IPCOpen()) {
|
|
|
|
mActor->SendRecycleTexture(mFlags);
|
|
|
|
}
|
|
|
|
UnlockActor();
|
2016-01-26 23:46:18 +03:00
|
|
|
}
|
2014-02-25 08:23:41 +04:00
|
|
|
}
|
|
|
|
|
2019-06-01 12:37:56 +03:00
|
|
|
static void CancelTextureClientNotifyNotUsed(uint64_t aTextureId,
|
|
|
|
LayersIPCChannel* aAllocator) {
|
2016-06-15 14:28:10 +03:00
|
|
|
if (!aAllocator) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MessageLoop* msgLoop = nullptr;
|
|
|
|
msgLoop = aAllocator->GetMessageLoop();
|
|
|
|
if (!msgLoop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (MessageLoop::current() == msgLoop) {
|
2019-06-01 12:37:56 +03:00
|
|
|
aAllocator->CancelWaitForNotifyNotUsed(aTextureId);
|
2016-06-15 14:28:10 +03:00
|
|
|
} else {
|
2019-06-01 12:37:56 +03:00
|
|
|
msgLoop->PostTask(NewRunnableFunction(
|
|
|
|
"CancelTextureClientNotifyNotUsedRunnable",
|
|
|
|
CancelTextureClientNotifyNotUsed, aTextureId, aAllocator));
|
2016-06-15 14:28:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-01 12:37:56 +03:00
|
|
|
void TextureClient::CancelWaitForNotifyNotUsed() {
|
2016-06-15 14:28:10 +03:00
|
|
|
if (GetFlags() & TextureFlags::RECYCLE) {
|
2019-06-01 12:37:56 +03:00
|
|
|
CancelTextureClientNotifyNotUsed(mSerial, GetAllocator());
|
2016-06-15 14:28:10 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-11-13 18:53:49 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
void TextureClient::TextureClientRecycleCallback(TextureClient* aClient,
|
|
|
|
void* aClosure) {
|
2015-08-13 22:18:53 +03:00
|
|
|
MOZ_ASSERT(aClient->GetRecycleAllocator());
|
|
|
|
aClient->GetRecycleAllocator()->RecycleTextureClient(aClient);
|
|
|
|
}
|
|
|
|
|
2016-01-08 14:24:00 +03:00
|
|
|
void TextureClient::SetRecycleAllocator(
|
|
|
|
ITextureClientRecycleAllocator* aAllocator) {
|
2015-08-13 22:18:53 +03:00
|
|
|
mRecycleAllocator = aAllocator;
|
|
|
|
if (aAllocator) {
|
|
|
|
SetRecycleCallback(TextureClientRecycleCallback, nullptr);
|
|
|
|
} else {
|
|
|
|
ClearRecycleCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
bool TextureClient::InitIPDLActor(CompositableForwarder* aForwarder) {
|
2016-09-27 06:22:20 +03:00
|
|
|
MOZ_ASSERT(aForwarder &&
|
|
|
|
aForwarder->GetTextureForwarder()->GetMessageLoop() ==
|
|
|
|
mAllocator->GetMessageLoop());
|
2016-11-16 00:04:59 +03:00
|
|
|
|
|
|
|
if (mActor && !mActor->IPCOpen()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-13 01:00:04 +03:00
|
|
|
if (mActor && !mActor->mDestroyed) {
|
2016-06-29 12:18:30 +03:00
|
|
|
CompositableForwarder* currentFwd = mActor->mCompositableForwarder;
|
|
|
|
TextureForwarder* currentTexFwd = mActor->mTextureForwarder;
|
|
|
|
if (currentFwd != aForwarder) {
|
|
|
|
// It's a bit iffy but right now ShadowLayerForwarder inherits
|
2016-09-27 06:22:20 +03:00
|
|
|
// TextureForwarder even though it should not.
|
|
|
|
// ShadowLayerForwarder::GetTextureForwarder actually returns a pointer to
|
2016-06-29 12:18:30 +03:00
|
|
|
// the CompositorBridgeChild. It's Ok for a texture to move from a
|
|
|
|
// ShadowLayerForwarder to another, but not form a CompositorBridgeChild
|
|
|
|
// to another (they use different channels).
|
2016-09-27 06:22:20 +03:00
|
|
|
if (currentTexFwd && currentTexFwd != aForwarder->GetTextureForwarder()) {
|
2016-09-02 18:34:45 +03:00
|
|
|
gfxCriticalError()
|
|
|
|
<< "Attempt to move a texture to a different channel CF.";
|
2016-06-29 12:18:30 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (currentFwd && currentFwd->GetCompositorBackendType() !=
|
|
|
|
aForwarder->GetCompositorBackendType()) {
|
|
|
|
gfxCriticalError()
|
|
|
|
<< "Attempt to move a texture to different compositor backend.";
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-21 06:57:56 +03:00
|
|
|
if (ShadowLayerForwarder* forwarder = aForwarder->AsLayerForwarder()) {
|
|
|
|
// Do the DOM labeling.
|
|
|
|
if (nsIEventTarget* target = forwarder->GetEventTarget()) {
|
|
|
|
forwarder->GetCompositorBridgeChild()->ReplaceEventTargetForActor(
|
|
|
|
mActor, target);
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 12:18:30 +03:00
|
|
|
mActor->mCompositableForwarder = aForwarder;
|
2016-05-13 01:00:04 +03:00
|
|
|
}
|
2014-02-10 06:24:27 +04:00
|
|
|
return true;
|
|
|
|
}
|
2016-04-13 20:55:08 +03:00
|
|
|
MOZ_ASSERT(!mActor || mActor->mDestroyed,
|
|
|
|
"Cannot use a texture on several IPC channels.");
|
2013-12-12 05:44:53 +04:00
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
SurfaceDescriptor desc;
|
|
|
|
if (!ToSurfaceDescriptor(desc)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-20 04:24:13 +03:00
|
|
|
// Try external image id allocation.
|
|
|
|
mExternalImageId =
|
|
|
|
aForwarder->GetTextureForwarder()->GetNextExternalImageId();
|
|
|
|
|
2017-03-21 06:57:56 +03:00
|
|
|
nsIEventTarget* target = nullptr;
|
|
|
|
// Get the layers id if the forwarder is a ShadowLayerForwarder.
|
|
|
|
if (ShadowLayerForwarder* forwarder = aForwarder->AsLayerForwarder()) {
|
|
|
|
target = forwarder->GetEventTarget();
|
|
|
|
}
|
|
|
|
|
2018-03-12 16:10:13 +03:00
|
|
|
ReadLockDescriptor readLockDescriptor = null_t();
|
|
|
|
if (mReadLock) {
|
|
|
|
mReadLock->Serialize(readLockDescriptor, GetAllocator()->GetParentPid());
|
|
|
|
}
|
|
|
|
|
2016-10-29 01:48:35 +03:00
|
|
|
PTextureChild* actor = aForwarder->GetTextureForwarder()->CreateTexture(
|
|
|
|
desc, readLockDescriptor, aForwarder->GetCompositorBackendType(),
|
2017-03-21 06:57:56 +03:00
|
|
|
GetFlags(), mSerial, mExternalImageId, target);
|
|
|
|
|
2016-10-29 01:48:35 +03:00
|
|
|
if (!actor) {
|
|
|
|
gfxCriticalNote << static_cast<int32_t>(desc.type()) << ", "
|
|
|
|
<< static_cast<int32_t>(
|
|
|
|
aForwarder->GetCompositorBackendType())
|
|
|
|
<< ", " << static_cast<uint32_t>(GetFlags()) << ", "
|
|
|
|
<< mSerial;
|
|
|
|
return false;
|
2016-08-24 19:59:28 +03:00
|
|
|
}
|
2016-10-29 01:48:35 +03:00
|
|
|
|
|
|
|
mActor = static_cast<TextureChild*>(actor);
|
2016-06-29 12:18:30 +03:00
|
|
|
mActor->mCompositableForwarder = aForwarder;
|
2016-09-27 06:22:20 +03:00
|
|
|
mActor->mTextureForwarder = aForwarder->GetTextureForwarder();
|
2016-04-13 20:55:08 +03:00
|
|
|
mActor->mTextureClient = this;
|
2015-11-20 16:25:03 +03:00
|
|
|
mActor->mMainThreadOnly = !!(mFlags & TextureFlags::DEALLOCATE_MAIN_THREAD);
|
2016-04-22 19:05:26 +03:00
|
|
|
|
|
|
|
// If the TextureClient is already locked, we have to lock TextureChild's
|
|
|
|
// mutex since it will be unlocked in TextureClient::Unlock.
|
|
|
|
if (mIsLocked) {
|
|
|
|
LockActor();
|
|
|
|
}
|
|
|
|
|
2016-04-13 20:55:08 +03:00
|
|
|
return mActor->IPCOpen();
|
2013-12-12 05:44:44 +04:00
|
|
|
}
|
|
|
|
|
2019-06-07 15:27:05 +03:00
|
|
|
bool TextureClient::InitIPDLActor(KnowsCompositor* aKnowsCompositor) {
|
|
|
|
MOZ_ASSERT(aKnowsCompositor &&
|
|
|
|
aKnowsCompositor->GetTextureForwarder()->GetMessageLoop() ==
|
2016-09-27 06:22:20 +03:00
|
|
|
mAllocator->GetMessageLoop());
|
2019-06-07 15:27:05 +03:00
|
|
|
TextureForwarder* fwd = aKnowsCompositor->GetTextureForwarder();
|
2016-05-27 23:49:30 +03:00
|
|
|
if (mActor && !mActor->mDestroyed) {
|
|
|
|
CompositableForwarder* currentFwd = mActor->mCompositableForwarder;
|
|
|
|
TextureForwarder* currentTexFwd = mActor->mTextureForwarder;
|
|
|
|
|
|
|
|
if (currentFwd) {
|
|
|
|
gfxCriticalError()
|
|
|
|
<< "Attempt to remove a texture from a CompositableForwarder.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
if (currentTexFwd && currentTexFwd != fwd) {
|
2016-09-02 18:34:45 +03:00
|
|
|
gfxCriticalError()
|
|
|
|
<< "Attempt to move a texture to a different channel TF.";
|
2016-05-27 23:49:30 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-27 06:22:20 +03:00
|
|
|
mActor->mTextureForwarder = fwd;
|
2016-05-27 23:49:30 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(!mActor || mActor->mDestroyed,
|
|
|
|
"Cannot use a texture on several IPC channels.");
|
|
|
|
|
|
|
|
SurfaceDescriptor desc;
|
|
|
|
if (!ToSurfaceDescriptor(desc)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-20 04:24:13 +03:00
|
|
|
// Try external image id allocation.
|
|
|
|
mExternalImageId =
|
2019-06-07 15:27:05 +03:00
|
|
|
aKnowsCompositor->GetTextureForwarder()->GetNextExternalImageId();
|
2017-04-20 04:24:13 +03:00
|
|
|
|
2018-03-12 16:10:13 +03:00
|
|
|
ReadLockDescriptor readLockDescriptor = null_t();
|
|
|
|
if (mReadLock) {
|
|
|
|
mReadLock->Serialize(readLockDescriptor, GetAllocator()->GetParentPid());
|
|
|
|
}
|
|
|
|
|
2016-11-10 05:25:27 +03:00
|
|
|
PTextureChild* actor = fwd->CreateTexture(
|
2019-06-07 15:27:05 +03:00
|
|
|
desc, readLockDescriptor, aKnowsCompositor->GetCompositorBackendType(),
|
2017-04-20 04:24:13 +03:00
|
|
|
GetFlags(), mSerial, mExternalImageId);
|
2016-11-10 05:25:27 +03:00
|
|
|
if (!actor) {
|
|
|
|
gfxCriticalNote << static_cast<int32_t>(desc.type()) << ", "
|
|
|
|
<< static_cast<int32_t>(
|
2019-06-07 15:27:05 +03:00
|
|
|
aKnowsCompositor->GetCompositorBackendType())
|
2016-11-10 05:25:27 +03:00
|
|
|
<< ", " << static_cast<uint32_t>(GetFlags()) << ", "
|
|
|
|
<< mSerial;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mActor = static_cast<TextureChild*>(actor);
|
2016-09-27 06:22:20 +03:00
|
|
|
mActor->mTextureForwarder = fwd;
|
2016-05-27 23:49:30 +03:00
|
|
|
mActor->mTextureClient = this;
|
|
|
|
mActor->mMainThreadOnly = !!(mFlags & TextureFlags::DEALLOCATE_MAIN_THREAD);
|
|
|
|
|
|
|
|
// If the TextureClient is already locked, we have to lock TextureChild's
|
|
|
|
// mutex since it will be unlocked in TextureClient::Unlock.
|
|
|
|
if (mIsLocked) {
|
|
|
|
LockActor();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mActor->IPCOpen();
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
PTextureChild* TextureClient::GetIPDLActor() { return mActor; }
|
|
|
|
|
2016-06-29 12:18:30 +03:00
|
|
|
// static
|
|
|
|
already_AddRefed<TextureClient> TextureClient::CreateForDrawing(
|
2016-09-27 06:22:20 +03:00
|
|
|
KnowsCompositor* aAllocator, gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
|
2016-06-29 12:18:30 +03:00
|
|
|
BackendSelector aSelector, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags) {
|
|
|
|
LayersBackend layersBackend = aAllocator->GetCompositorBackendType();
|
2018-07-23 06:27:48 +03:00
|
|
|
if (aAllocator->SupportsTextureDirectMapping() &&
|
|
|
|
std::max(aSize.width, aSize.height) <= aAllocator->GetMaxTextureSize()) {
|
2018-05-03 04:20:25 +03:00
|
|
|
aAllocFlags =
|
|
|
|
TextureAllocationFlags(aAllocFlags | ALLOC_ALLOW_DIRECT_MAPPING);
|
|
|
|
}
|
2016-09-27 06:22:20 +03:00
|
|
|
return TextureClient::CreateForDrawing(
|
|
|
|
aAllocator->GetTextureForwarder(), aFormat, aSize, layersBackend,
|
|
|
|
aAllocator->GetMaxTextureSize(), aSelector, aTextureFlags, aAllocFlags);
|
2016-06-29 12:18:30 +03:00
|
|
|
}
|
|
|
|
|
2014-07-29 15:16:57 +04:00
|
|
|
// static
|
2016-05-13 01:00:04 +03:00
|
|
|
already_AddRefed<TextureClient> TextureClient::CreateForDrawing(
|
2014-07-29 15:16:57 +04:00
|
|
|
TextureForwarder* aAllocator, gfx::SurfaceFormat aFormat,
|
2016-06-29 12:18:30 +03:00
|
|
|
gfx::IntSize aSize, LayersBackend aLayersBackend, int32_t aMaxTextureSize,
|
2014-07-29 15:16:57 +04:00
|
|
|
BackendSelector aSelector, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags) {
|
2016-06-29 12:18:30 +03:00
|
|
|
gfx::BackendType moz2DBackend =
|
|
|
|
BackendTypeForBackendSelector(aLayersBackend, aSelector);
|
|
|
|
|
2015-12-14 01:59:00 +03:00
|
|
|
// also test the validity of aAllocator
|
2015-10-30 15:25:29 +03:00
|
|
|
if (!aAllocator || !aAllocator->IPCOpen()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-11-18 18:59:11 +03:00
|
|
|
if (!gfx::Factory::AllowedSurfaceSize(aSize)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:44:27 +03:00
|
|
|
TextureData* data =
|
|
|
|
TextureData::Create(aAllocator, aFormat, aSize, aLayersBackend,
|
|
|
|
aMaxTextureSize, aSelector, aTextureFlags, aAllocFlags);
|
2017-10-28 13:59:58 +03:00
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
if (data) {
|
|
|
|
return MakeAndAddRef<TextureClient>(data, aTextureFlags, aAllocator);
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:16:57 +04:00
|
|
|
// Can't do any better than a buffer texture client.
|
2015-10-15 18:53:33 +03:00
|
|
|
return TextureClient::CreateForRawBufferAccess(aAllocator, aFormat, aSize,
|
2016-08-23 05:30:14 +03:00
|
|
|
moz2DBackend, aLayersBackend,
|
|
|
|
aTextureFlags, aAllocFlags);
|
2014-07-10 15:45:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2016-08-02 08:57:41 +03:00
|
|
|
already_AddRefed<TextureClient> 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) {
|
|
|
|
// also test the validity of aAllocator
|
2016-09-27 06:22:20 +03:00
|
|
|
if (!aAllocator || !aAllocator->GetTextureForwarder()->IPCOpen()) {
|
2016-08-02 08:57:41 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::IntSize size = aSurface->GetSize();
|
|
|
|
|
|
|
|
if (!gfx::Factory::AllowedSurfaceSize(size)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureData* data = nullptr;
|
|
|
|
#if defined(XP_WIN)
|
2016-09-27 06:22:20 +03:00
|
|
|
LayersBackend layersBackend = aAllocator->GetCompositorBackendType();
|
|
|
|
gfx::BackendType moz2DBackend =
|
|
|
|
BackendTypeForBackendSelector(layersBackend, aSelector);
|
2016-08-02 08:57:41 +03:00
|
|
|
|
|
|
|
int32_t maxTextureSize = aAllocator->GetMaxTextureSize();
|
|
|
|
|
2017-12-07 14:17:07 +03:00
|
|
|
if ((layersBackend == LayersBackend::LAYERS_D3D11 ||
|
|
|
|
layersBackend == LayersBackend::LAYERS_WR) &&
|
2016-08-02 08:57:41 +03:00
|
|
|
(moz2DBackend == gfx::BackendType::DIRECT2D ||
|
|
|
|
moz2DBackend == gfx::BackendType::DIRECT2D1_1 ||
|
|
|
|
(!!(aAllocFlags & ALLOC_FOR_OUT_OF_BAND_CONTENT) &&
|
2016-08-24 01:18:55 +03:00
|
|
|
DeviceManagerDx::Get()->GetContentDevice())) &&
|
2016-08-02 08:57:41 +03:00
|
|
|
size.width <= maxTextureSize && size.height <= maxTextureSize) {
|
|
|
|
data = D3D11TextureData::Create(aSurface, aAllocFlags);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (data) {
|
2016-09-27 06:22:20 +03:00
|
|
|
return MakeAndAddRef<TextureClient>(data, aTextureFlags,
|
|
|
|
aAllocator->GetTextureForwarder());
|
2016-08-02 08:57:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back to using UpdateFromSurface
|
2016-10-06 16:18:20 +03:00
|
|
|
|
2016-10-06 15:32:55 +03:00
|
|
|
TextureAllocationFlags allocFlags =
|
|
|
|
TextureAllocationFlags(aAllocFlags | ALLOC_UPDATE_FROM_SURFACE);
|
2016-08-02 08:57:41 +03:00
|
|
|
RefPtr<TextureClient> client =
|
|
|
|
CreateForDrawing(aAllocator, aSurface->GetFormat(), size, aSelector,
|
2016-10-06 15:32:55 +03:00
|
|
|
aTextureFlags, allocFlags);
|
2016-08-02 08:57:41 +03:00
|
|
|
if (!client) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureClientAutoLock autoLock(client, OpenMode::OPEN_WRITE_ONLY);
|
|
|
|
if (!autoLock.Succeeded()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
client->UpdateFromSurface(aSurface);
|
|
|
|
return client.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2016-09-27 06:22:20 +03:00
|
|
|
already_AddRefed<TextureClient> TextureClient::CreateForRawBufferAccess(
|
2014-07-10 15:45:40 +04:00
|
|
|
KnowsCompositor* aAllocator, gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
|
|
|
|
gfx::BackendType aMoz2DBackend, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags) {
|
2018-05-03 04:20:25 +03:00
|
|
|
// If we exceed the max texture size for the GPU, then just fall back to no
|
|
|
|
// texture direct mapping. If it becomes a problem we can implement tiling
|
|
|
|
// logic inside DirectMapTextureSource to allow this.
|
|
|
|
bool supportsTextureDirectMapping =
|
|
|
|
aAllocator->SupportsTextureDirectMapping() &&
|
|
|
|
std::max(aSize.width, aSize.height) <= aAllocator->GetMaxTextureSize();
|
|
|
|
if (supportsTextureDirectMapping) {
|
|
|
|
aAllocFlags =
|
|
|
|
TextureAllocationFlags(aAllocFlags | ALLOC_ALLOW_DIRECT_MAPPING);
|
|
|
|
} else {
|
|
|
|
aAllocFlags =
|
|
|
|
TextureAllocationFlags(aAllocFlags & ~ALLOC_ALLOW_DIRECT_MAPPING);
|
|
|
|
}
|
2016-09-27 06:22:20 +03:00
|
|
|
return CreateForRawBufferAccess(
|
|
|
|
aAllocator->GetTextureForwarder(), aFormat, aSize, aMoz2DBackend,
|
|
|
|
aAllocator->GetCompositorBackendType(), aTextureFlags, aAllocFlags);
|
2016-08-23 05:30:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2016-09-27 06:22:20 +03:00
|
|
|
already_AddRefed<TextureClient> TextureClient::CreateForRawBufferAccess(
|
2016-08-23 05:30:14 +03:00
|
|
|
LayersIPCChannel* aAllocator, gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::IntSize aSize, gfx::BackendType aMoz2DBackend,
|
|
|
|
LayersBackend aLayersBackend, TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags) {
|
2015-12-14 02:00:00 +03:00
|
|
|
// also test the validity of aAllocator
|
2015-10-30 15:25:29 +03:00
|
|
|
if (!aAllocator || !aAllocator->IPCOpen()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-11-20 16:25:03 +03:00
|
|
|
if (aAllocFlags & ALLOC_DISALLOW_BUFFERTEXTURECLIENT) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-11-18 18:59:11 +03:00
|
|
|
if (!gfx::Factory::AllowedSurfaceSize(aSize)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-09 03:57:25 +03:00
|
|
|
if (aFormat == SurfaceFormat::B8G8R8X8) {
|
|
|
|
// Skia doesn't support RGBX, so ensure we clear the buffer for the proper
|
|
|
|
// alpha values.
|
|
|
|
aAllocFlags = TextureAllocationFlags(aAllocFlags | ALLOC_CLEAR_BUFFER);
|
2016-05-12 15:58:13 +03:00
|
|
|
}
|
|
|
|
|
2017-11-09 03:57:25 +03:00
|
|
|
// Note that we ignore the backend type if we get here. It should only be D2D
|
|
|
|
// or Skia, and D2D does not support data surfaces. Therefore it is safe to
|
|
|
|
// force the buffer to be Skia.
|
2017-11-14 13:01:42 +03:00
|
|
|
NS_WARNING_ASSERTION(aMoz2DBackend == gfx::BackendType::SKIA ||
|
|
|
|
aMoz2DBackend == gfx::BackendType::DIRECT2D ||
|
|
|
|
aMoz2DBackend == gfx::BackendType::DIRECT2D1_1,
|
2017-11-09 03:57:25 +03:00
|
|
|
"Unsupported TextureClient backend type");
|
|
|
|
|
|
|
|
TextureData* texData = BufferTextureData::Create(
|
|
|
|
aSize, aFormat, gfx::BackendType::SKIA, aLayersBackend, aTextureFlags,
|
2016-08-23 05:30:14 +03:00
|
|
|
aAllocFlags, aAllocator);
|
2015-10-15 18:53:33 +03:00
|
|
|
if (!texData) {
|
|
|
|
return nullptr;
|
2014-07-10 15:45:40 +04:00
|
|
|
}
|
2015-10-15 18:53:33 +03:00
|
|
|
|
2015-11-20 16:25:00 +03:00
|
|
|
return MakeAndAddRef<TextureClient>(texData, aTextureFlags, aAllocator);
|
2014-07-10 15:45:40 +04:00
|
|
|
}
|
|
|
|
|
2014-07-10 15:48:29 +04:00
|
|
|
// static
|
2015-10-15 18:53:33 +03:00
|
|
|
already_AddRefed<TextureClient> 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) {
|
2016-11-08 06:40:24 +03:00
|
|
|
if (!aAllocator || !aAllocator->GetLayersIPCActor()->IPCOpen()) {
|
2015-10-30 15:25:29 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-11-18 18:59:11 +03:00
|
|
|
if (!gfx::Factory::AllowedSurfaceSize(aYSize)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-09-25 23:44:55 +03:00
|
|
|
TextureData* data = BufferTextureData::CreateForYCbCr(
|
|
|
|
aAllocator, aYSize, aYStride, aCbCrSize, aCbCrStride, aStereoMode,
|
|
|
|
aColorDepth, aYUVColorSpace, aTextureFlags);
|
2015-10-15 18:53:33 +03:00
|
|
|
if (!data) {
|
2014-07-10 15:48:29 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
return MakeAndAddRef<TextureClient>(data, aTextureFlags,
|
2016-11-08 06:40:24 +03:00
|
|
|
aAllocator->GetTextureForwarder());
|
2014-07-10 15:48:29 +04:00
|
|
|
}
|
|
|
|
|
2017-09-29 17:37:56 +03:00
|
|
|
TextureClient::TextureClient(TextureData* aData, TextureFlags aFlags,
|
|
|
|
LayersIPCChannel* aAllocator)
|
|
|
|
: AtomicRefCountedWithFinalize("TextureClient"),
|
|
|
|
mAllocator(aAllocator),
|
|
|
|
mActor(nullptr),
|
|
|
|
mData(aData),
|
|
|
|
mFlags(aFlags),
|
|
|
|
mOpenMode(OpenMode::OPEN_NONE)
|
2015-11-20 16:25:00 +03:00
|
|
|
#ifdef DEBUG
|
2017-09-29 17:37:56 +03:00
|
|
|
,
|
|
|
|
mExpectedDtRefs(0)
|
2015-11-20 16:25:00 +03:00
|
|
|
#endif
|
2017-09-29 17:37:56 +03:00
|
|
|
,
|
|
|
|
mIsLocked(false),
|
|
|
|
mIsReadLocked(false),
|
|
|
|
mUpdated(false),
|
|
|
|
mAddedToCompositableClient(false),
|
|
|
|
mWorkaroundAnnoyingSharedSurfaceLifetimeIssues(false),
|
|
|
|
mWorkaroundAnnoyingSharedSurfaceOwnershipIssues(false),
|
|
|
|
mFwdTransactionId(0),
|
|
|
|
mSerial(++sSerialCounter)
|
2014-11-25 22:54:29 +03:00
|
|
|
#ifdef GFX_DEBUG_TRACK_CLIENTS_IN_POOL
|
2017-09-29 17:37:56 +03:00
|
|
|
,
|
|
|
|
mPoolTracker(nullptr)
|
2014-11-25 22:54:29 +03:00
|
|
|
#endif
|
2015-11-20 18:55:26 +03:00
|
|
|
{
|
2016-04-22 19:05:26 +03:00
|
|
|
mData->FillInfo(mInfo);
|
2015-11-20 16:25:03 +03:00
|
|
|
mFlags |= mData->GetTextureFlags();
|
2018-03-12 16:10:13 +03:00
|
|
|
|
|
|
|
if (mFlags & TextureFlags::NON_BLOCKING_READ_LOCK) {
|
|
|
|
MOZ_ASSERT(!(mFlags & TextureFlags::BLOCKING_READ_LOCK));
|
|
|
|
EnableReadLock();
|
|
|
|
} else if (mFlags & TextureFlags::BLOCKING_READ_LOCK) {
|
|
|
|
MOZ_ASSERT(!(mFlags & TextureFlags::NON_BLOCKING_READ_LOCK));
|
|
|
|
EnableBlockingReadLock();
|
|
|
|
}
|
2013-12-12 05:44:45 +04:00
|
|
|
}
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
bool TextureClient::CopyToTextureClient(TextureClient* aTarget,
|
|
|
|
const gfx::IntRect* aRect,
|
|
|
|
const gfx::IntPoint* aPoint) {
|
|
|
|
MOZ_ASSERT(IsLocked());
|
|
|
|
MOZ_ASSERT(aTarget->IsLocked());
|
|
|
|
|
2014-04-10 12:14:28 +04:00
|
|
|
if (!aTarget->CanExposeDrawTarget() || !CanExposeDrawTarget()) {
|
2014-03-08 01:34:04 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> destinationTarget = aTarget->BorrowDrawTarget();
|
2015-03-09 22:48:20 +03:00
|
|
|
if (!destinationTarget) {
|
|
|
|
gfxWarning() << "TextureClient::CopyToTextureClient (dest) failed in "
|
|
|
|
"BorrowDrawTarget";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> sourceTarget = BorrowDrawTarget();
|
2015-03-09 22:48:20 +03:00
|
|
|
if (!sourceTarget) {
|
|
|
|
gfxWarning() << "TextureClient::CopyToTextureClient (src) failed in "
|
|
|
|
"BorrowDrawTarget";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfx::SourceSurface> source = sourceTarget->Snapshot();
|
2014-03-08 01:34:04 +04:00
|
|
|
destinationTarget->CopySurface(
|
|
|
|
source, aRect ? *aRect : gfx::IntRect(gfx::IntPoint(0, 0), GetSize()),
|
|
|
|
aPoint ? *aPoint : gfx::IntPoint(0, 0));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-22 19:05:26 +03:00
|
|
|
already_AddRefed<gfx::DataSourceSurface> TextureClient::GetAsSurface() {
|
2016-05-25 20:16:25 +03:00
|
|
|
if (!Lock(OpenMode::OPEN_READ)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-04-22 19:05:26 +03:00
|
|
|
RefPtr<gfx::DataSourceSurface> data;
|
2016-05-25 20:16:25 +03:00
|
|
|
{ // scope so that the DrawTarget is destroyed before Unlock()
|
|
|
|
RefPtr<gfx::DrawTarget> dt = BorrowDrawTarget();
|
|
|
|
if (dt) {
|
|
|
|
RefPtr<gfx::SourceSurface> surf = dt->Snapshot();
|
|
|
|
if (surf) {
|
|
|
|
data = surf->GetDataSurface();
|
|
|
|
}
|
2016-04-22 19:05:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Unlock();
|
|
|
|
return data.forget();
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:32:45 +03:00
|
|
|
void TextureClient::PrintInfo(std::stringstream& aStream, const char* aPrefix) {
|
|
|
|
aStream << aPrefix;
|
|
|
|
aStream << nsPrintfCString("TextureClient (0x%p)", this).get();
|
|
|
|
AppendToString(aStream, GetSize(), " [size=", "]");
|
|
|
|
AppendToString(aStream, GetFormat(), " [format=", "]");
|
|
|
|
AppendToString(aStream, mFlags, " [flags=", "]");
|
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2019-06-27 07:48:58 +03:00
|
|
|
if (StaticPrefs::layers_dump_texture()) {
|
2014-12-18 21:32:45 +03:00
|
|
|
nsAutoCString pfx(aPrefix);
|
|
|
|
pfx += " ";
|
|
|
|
|
|
|
|
aStream << "\n" << pfx.get() << "Surface: ";
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfx::DataSourceSurface> dSurf = GetAsSurface();
|
2014-12-18 21:32:45 +03:00
|
|
|
if (dSurf) {
|
|
|
|
aStream << gfxUtils::GetAsLZ4Base64Str(dSurf).get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2015-11-24 21:07:02 +03:00
|
|
|
|
2017-04-12 08:58:47 +03:00
|
|
|
void TextureClient::GPUVideoDesc(SurfaceDescriptorGPUVideo* const aOutDesc) {
|
|
|
|
const auto handle = GetSerial();
|
|
|
|
|
|
|
|
GPUVideoSubDescriptor subDesc = null_t();
|
|
|
|
MOZ_RELEASE_ASSERT(mData);
|
|
|
|
mData->GetSubDescriptor(&subDesc);
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
*aOutDesc = SurfaceDescriptorGPUVideo(handle, std::move(subDesc));
|
2017-04-12 08:58:47 +03:00
|
|
|
}
|
|
|
|
|
2017-02-04 13:19:11 +03:00
|
|
|
class MemoryTextureReadLock : public NonBlockingTextureReadLock {
|
2016-06-02 12:00:12 +03:00
|
|
|
public:
|
|
|
|
MemoryTextureReadLock();
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~MemoryTextureReadLock();
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool ReadLock() override;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
int32_t ReadUnlock() override;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
int32_t GetReadCount() override;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
LockType GetType() override { return TYPE_NONBLOCKING_MEMORY; }
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool IsValid() const override { return true; };
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Serialize(ReadLockDescriptor& aOutput, base::ProcessId aOther) override;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2018-08-21 04:00:40 +03:00
|
|
|
Atomic<int32_t> mReadCount;
|
2016-06-02 12:00:12 +03:00
|
|
|
};
|
|
|
|
|
2016-06-02 12:00:21 +03:00
|
|
|
// The cross-prcess implementation of TextureReadLock.
|
|
|
|
//
|
|
|
|
// Since we don't use cross-process reference counting for the ReadLock objects,
|
|
|
|
// we use the lock's internal counter as a way to know when to deallocate the
|
|
|
|
// underlying shmem section: when the counter is equal to 1, it means that the
|
|
|
|
// lock is not "held" (the texture is writable), when the counter is equal to 0
|
|
|
|
// it means that we can safely deallocate the shmem section without causing a
|
|
|
|
// race condition with the other process.
|
2017-02-04 13:19:11 +03:00
|
|
|
class ShmemTextureReadLock : public NonBlockingTextureReadLock {
|
2016-06-02 12:00:12 +03:00
|
|
|
public:
|
|
|
|
struct ShmReadLockInfo {
|
|
|
|
int32_t readCount;
|
|
|
|
};
|
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
explicit ShmemTextureReadLock(LayersIPCChannel* aAllocator);
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~ShmemTextureReadLock();
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool ReadLock() override;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
int32_t ReadUnlock() override;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
int32_t GetReadCount() override;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool IsValid() const override { return mAllocSuccess; };
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
LockType GetType() override { return TYPE_NONBLOCKING_SHMEM; }
|
2016-06-02 12:00:12 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Serialize(ReadLockDescriptor& aOutput, base::ProcessId aOther) override;
|
2016-06-02 12:00:12 +03:00
|
|
|
|
|
|
|
mozilla::layers::ShmemSection& GetShmemSection() { return mShmemSection; }
|
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
explicit ShmemTextureReadLock(
|
|
|
|
const mozilla::layers::ShmemSection& aShmemSection)
|
|
|
|
: mShmemSection(aShmemSection), mAllocSuccess(true) {
|
2016-06-02 12:00:12 +03:00
|
|
|
MOZ_COUNT_CTOR(ShmemTextureReadLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShmReadLockInfo* GetShmReadLockInfoPtr() {
|
|
|
|
return reinterpret_cast<ShmReadLockInfo*>(
|
|
|
|
mShmemSection.shmem().get<char>() + mShmemSection.offset());
|
|
|
|
}
|
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
RefPtr<LayersIPCChannel> mClientAllocator;
|
2016-06-02 12:00:12 +03:00
|
|
|
mozilla::layers::ShmemSection mShmemSection;
|
|
|
|
bool mAllocSuccess;
|
|
|
|
};
|
|
|
|
|
2017-02-14 11:10:36 +03:00
|
|
|
class CrossProcessSemaphoreReadLock : public TextureReadLock {
|
|
|
|
public:
|
|
|
|
CrossProcessSemaphoreReadLock()
|
2017-04-19 06:39:11 +03:00
|
|
|
: mSemaphore(CrossProcessSemaphore::Create("TextureReadLock", 1)),
|
2018-03-12 16:10:13 +03:00
|
|
|
mShared(false) {}
|
2017-02-14 11:10:36 +03:00
|
|
|
explicit CrossProcessSemaphoreReadLock(CrossProcessSemaphoreHandle aHandle)
|
2017-04-19 06:39:11 +03:00
|
|
|
: mSemaphore(CrossProcessSemaphore::Create(aHandle)), mShared(false) {}
|
2017-02-14 11:10:36 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool ReadLock() override {
|
2017-04-19 06:15:42 +03:00
|
|
|
if (!IsValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-19 06:39:11 +03:00
|
|
|
return mSemaphore->Wait();
|
2017-02-14 11:10:36 +03:00
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
bool TryReadLock(TimeDuration aTimeout) override {
|
2017-04-19 06:15:42 +03:00
|
|
|
if (!IsValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-19 06:39:11 +03:00
|
|
|
return mSemaphore->Wait(Some(aTimeout));
|
2017-02-14 11:10:36 +03:00
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
int32_t ReadUnlock() override {
|
2017-04-19 06:15:42 +03:00
|
|
|
if (!IsValid()) {
|
|
|
|
return 1;
|
|
|
|
}
|
2017-04-19 06:39:11 +03:00
|
|
|
mSemaphore->Signal();
|
2017-02-14 11:10:36 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
bool IsValid() const override { return !!mSemaphore; }
|
2017-02-14 11:10:36 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool Serialize(ReadLockDescriptor& aOutput, base::ProcessId aOther) override;
|
2017-02-14 11:10:36 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
LockType GetType() override { return TYPE_CROSS_PROCESS_SEMAPHORE; }
|
2017-02-14 11:10:36 +03:00
|
|
|
|
2017-04-19 06:39:11 +03:00
|
|
|
UniquePtr<CrossProcessSemaphore> mSemaphore;
|
2018-03-12 16:10:13 +03:00
|
|
|
bool mShared;
|
2017-02-14 11:10:36 +03:00
|
|
|
};
|
|
|
|
|
2016-06-02 12:00:12 +03:00
|
|
|
// static
|
|
|
|
already_AddRefed<TextureReadLock> TextureReadLock::Deserialize(
|
2016-06-02 12:00:21 +03:00
|
|
|
const ReadLockDescriptor& aDescriptor, ISurfaceAllocator* aAllocator) {
|
|
|
|
switch (aDescriptor.type()) {
|
|
|
|
case ReadLockDescriptor::TShmemSection: {
|
|
|
|
const ShmemSection& section = aDescriptor.get_ShmemSection();
|
|
|
|
MOZ_RELEASE_ASSERT(section.shmem().IsReadable());
|
2016-09-27 06:22:20 +03:00
|
|
|
return MakeAndAddRef<ShmemTextureReadLock>(section);
|
2016-06-02 12:00:21 +03:00
|
|
|
}
|
|
|
|
case ReadLockDescriptor::Tuintptr_t: {
|
|
|
|
if (!aAllocator->IsSameProcess()) {
|
|
|
|
// Trying to use a memory based lock instead of a shmem based one in
|
|
|
|
// the cross-process case is a bad security violation.
|
|
|
|
NS_ERROR(
|
|
|
|
"A client process may be trying to peek at the host's address "
|
|
|
|
"space!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
RefPtr<TextureReadLock> lock =
|
|
|
|
reinterpret_cast<MemoryTextureReadLock*>(aDescriptor.get_uintptr_t());
|
|
|
|
|
|
|
|
MOZ_ASSERT(lock);
|
|
|
|
if (lock) {
|
|
|
|
// The corresponding AddRef is in MemoryTextureReadLock::Serialize
|
|
|
|
lock.get()->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return lock.forget();
|
|
|
|
}
|
2017-02-14 11:10:36 +03:00
|
|
|
case ReadLockDescriptor::TCrossProcessSemaphoreDescriptor: {
|
|
|
|
return MakeAndAddRef<CrossProcessSemaphoreReadLock>(
|
|
|
|
aDescriptor.get_CrossProcessSemaphoreDescriptor().sem());
|
|
|
|
}
|
2016-06-02 12:00:21 +03:00
|
|
|
case ReadLockDescriptor::Tnull_t: {
|
2016-06-02 12:00:12 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2016-06-02 12:00:21 +03:00
|
|
|
default: {
|
|
|
|
// Invalid descriptor.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(false);
|
2016-06-02 12:00:12 +03:00
|
|
|
}
|
|
|
|
}
|
2016-06-02 12:00:21 +03:00
|
|
|
return nullptr;
|
2016-06-02 12:00:12 +03:00
|
|
|
}
|
|
|
|
// static
|
2017-02-04 13:19:11 +03:00
|
|
|
already_AddRefed<TextureReadLock> NonBlockingTextureReadLock::Create(
|
|
|
|
LayersIPCChannel* aAllocator) {
|
2016-06-02 12:00:12 +03:00
|
|
|
if (aAllocator->IsSameProcess()) {
|
|
|
|
// If our compositor is in the same process, we can save some cycles by not
|
|
|
|
// using shared memory.
|
|
|
|
return MakeAndAddRef<MemoryTextureReadLock>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return MakeAndAddRef<ShmemTextureReadLock>(aAllocator);
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryTextureReadLock::MemoryTextureReadLock() : mReadCount(1) {
|
|
|
|
MOZ_COUNT_CTOR(MemoryTextureReadLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryTextureReadLock::~MemoryTextureReadLock() {
|
|
|
|
// One read count that is added in constructor.
|
|
|
|
MOZ_ASSERT(mReadCount == 1);
|
|
|
|
MOZ_COUNT_DTOR(MemoryTextureReadLock);
|
|
|
|
}
|
|
|
|
|
2017-02-14 11:10:36 +03:00
|
|
|
bool MemoryTextureReadLock::Serialize(ReadLockDescriptor& aOutput,
|
|
|
|
base::ProcessId aOther) {
|
2016-06-02 12:00:12 +03:00
|
|
|
// AddRef here and Release when receiving on the host side to make sure the
|
|
|
|
// reference count doesn't go to zero before the host receives the message.
|
2016-06-02 12:00:21 +03:00
|
|
|
// see TextureReadLock::Deserialize
|
2016-06-02 12:00:12 +03:00
|
|
|
this->AddRef();
|
2016-06-02 12:00:21 +03:00
|
|
|
aOutput = ReadLockDescriptor(uintptr_t(this));
|
2016-06-02 12:00:12 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MemoryTextureReadLock::ReadLock() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(MemoryTextureReadLock);
|
|
|
|
|
2018-08-21 04:00:40 +03:00
|
|
|
++mReadCount;
|
2017-02-14 11:10:36 +03:00
|
|
|
return true;
|
2016-06-02 12:00:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t MemoryTextureReadLock::ReadUnlock() {
|
2018-08-21 04:00:40 +03:00
|
|
|
int32_t readCount = --mReadCount;
|
2016-06-02 12:00:12 +03:00
|
|
|
MOZ_ASSERT(readCount >= 0);
|
|
|
|
|
|
|
|
return readCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t MemoryTextureReadLock::GetReadCount() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(MemoryTextureReadLock);
|
|
|
|
return mReadCount;
|
|
|
|
}
|
|
|
|
|
2016-09-27 06:22:20 +03:00
|
|
|
ShmemTextureReadLock::ShmemTextureReadLock(LayersIPCChannel* aAllocator)
|
|
|
|
: mClientAllocator(aAllocator), mAllocSuccess(false) {
|
2016-06-02 12:00:12 +03:00
|
|
|
MOZ_COUNT_CTOR(ShmemTextureReadLock);
|
2016-09-27 06:22:20 +03:00
|
|
|
MOZ_ASSERT(mClientAllocator);
|
2018-03-13 09:39:56 +03:00
|
|
|
MOZ_ASSERT(mClientAllocator->GetTileLockAllocator());
|
2016-06-02 12:00:12 +03:00
|
|
|
#define MOZ_ALIGN_WORD(x) (((x) + 3) & ~3)
|
2016-09-27 06:22:20 +03:00
|
|
|
if (mClientAllocator->GetTileLockAllocator()->AllocShmemSection(
|
2016-05-13 01:00:04 +03:00
|
|
|
MOZ_ALIGN_WORD(sizeof(ShmReadLockInfo)), &mShmemSection)) {
|
|
|
|
ShmReadLockInfo* info = GetShmReadLockInfoPtr();
|
|
|
|
info->readCount = 1;
|
|
|
|
mAllocSuccess = true;
|
2016-06-02 12:00:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShmemTextureReadLock::~ShmemTextureReadLock() {
|
2016-09-27 06:22:20 +03:00
|
|
|
if (mClientAllocator) {
|
2016-06-02 12:00:12 +03:00
|
|
|
// Release one read count that is added in constructor.
|
|
|
|
// The count is kept for calling GetReadCount() by TextureClientPool.
|
|
|
|
ReadUnlock();
|
|
|
|
}
|
|
|
|
MOZ_COUNT_DTOR(ShmemTextureReadLock);
|
|
|
|
}
|
|
|
|
|
2017-02-14 11:10:36 +03:00
|
|
|
bool ShmemTextureReadLock::Serialize(ReadLockDescriptor& aOutput,
|
|
|
|
base::ProcessId aOther) {
|
2016-06-02 12:00:21 +03:00
|
|
|
aOutput = ReadLockDescriptor(GetShmemSection());
|
2016-06-02 12:00:12 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShmemTextureReadLock::ReadLock() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ShmemTextureReadLock);
|
|
|
|
if (!mAllocSuccess) {
|
2017-02-14 11:10:36 +03:00
|
|
|
return false;
|
2016-06-02 12:00:12 +03:00
|
|
|
}
|
|
|
|
ShmReadLockInfo* info = GetShmReadLockInfoPtr();
|
2017-02-14 11:10:36 +03:00
|
|
|
PR_ATOMIC_INCREMENT(&info->readCount);
|
|
|
|
return true;
|
2016-06-02 12:00:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ShmemTextureReadLock::ReadUnlock() {
|
|
|
|
if (!mAllocSuccess) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ShmReadLockInfo* info = GetShmReadLockInfoPtr();
|
|
|
|
int32_t readCount = PR_ATOMIC_DECREMENT(&info->readCount);
|
|
|
|
MOZ_ASSERT(readCount >= 0);
|
|
|
|
if (readCount <= 0) {
|
2017-02-16 06:09:18 +03:00
|
|
|
if (mClientAllocator && mClientAllocator->GetTileLockAllocator()) {
|
2016-09-27 06:22:20 +03:00
|
|
|
mClientAllocator->GetTileLockAllocator()->DeallocShmemSection(
|
|
|
|
mShmemSection);
|
2016-06-02 12:00:12 +03:00
|
|
|
} else {
|
2017-02-16 06:09:18 +03:00
|
|
|
// we are on the compositor process, or IPC is down.
|
2016-06-02 12:00:12 +03:00
|
|
|
FixedSizeSmallShmemSectionAllocator::FreeShmemSection(mShmemSection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return readCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ShmemTextureReadLock::GetReadCount() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ShmemTextureReadLock);
|
|
|
|
if (!mAllocSuccess) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ShmReadLockInfo* info = GetShmReadLockInfoPtr();
|
|
|
|
return info->readCount;
|
|
|
|
}
|
|
|
|
|
2017-02-14 11:10:36 +03:00
|
|
|
bool CrossProcessSemaphoreReadLock::Serialize(ReadLockDescriptor& aOutput,
|
|
|
|
base::ProcessId aOther) {
|
2018-03-12 16:10:13 +03:00
|
|
|
if (!mShared && IsValid()) {
|
2017-04-19 06:39:11 +03:00
|
|
|
aOutput = ReadLockDescriptor(
|
|
|
|
CrossProcessSemaphoreDescriptor(mSemaphore->ShareToProcess(aOther)));
|
2018-03-12 16:10:13 +03:00
|
|
|
mSemaphore->CloseHandle();
|
|
|
|
mShared = true;
|
2017-04-19 06:15:42 +03:00
|
|
|
return true;
|
|
|
|
} else {
|
2018-03-12 16:10:13 +03:00
|
|
|
return mShared;
|
2017-04-19 06:15:42 +03:00
|
|
|
}
|
2017-02-14 11:10:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextureClient::EnableBlockingReadLock() {
|
|
|
|
if (!mReadLock) {
|
|
|
|
mReadLock = new CrossProcessSemaphoreReadLock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 21:54:11 +03:00
|
|
|
void TextureClient::AddPaintThreadRef() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mPaintThreadRefs += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureClient::DropPaintThreadRef() {
|
2018-08-13 20:57:15 +03:00
|
|
|
MOZ_RELEASE_ASSERT(PaintThread::Get()->IsOnPaintWorkerThread());
|
2017-08-05 21:54:11 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mPaintThreadRefs >= 1);
|
|
|
|
mPaintThreadRefs -= 1;
|
|
|
|
}
|
|
|
|
|
2015-10-15 18:53:33 +03:00
|
|
|
bool UpdateYCbCrTextureClient(TextureClient* aTexture,
|
|
|
|
const PlanarYCbCrData& aData) {
|
|
|
|
MOZ_ASSERT(aTexture);
|
|
|
|
MOZ_ASSERT(aTexture->IsLocked());
|
|
|
|
MOZ_ASSERT(aTexture->GetFormat() == gfx::SurfaceFormat::YUV,
|
|
|
|
"This textureClient can only use YCbCr data");
|
|
|
|
MOZ_ASSERT(!aTexture->IsImmutable());
|
|
|
|
MOZ_ASSERT(aTexture->IsValid());
|
|
|
|
MOZ_ASSERT(aData.mCbSkip == aData.mCrSkip);
|
2015-11-24 21:07:02 +03:00
|
|
|
|
2015-10-15 18:53:33 +03:00
|
|
|
MappedYCbCrTextureData mapped;
|
|
|
|
if (!aTexture->BorrowMappedYCbCrData(mapped)) {
|
|
|
|
NS_WARNING("Failed to extract YCbCr info!");
|
2015-11-24 21:07:02 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-25 23:44:55 +03:00
|
|
|
uint32_t bytesPerPixel =
|
|
|
|
BytesPerPixel(SurfaceFormatForColorDepth(aData.mColorDepth));
|
2015-10-15 18:53:33 +03:00
|
|
|
MappedYCbCrTextureData srcData;
|
|
|
|
srcData.y.data = aData.mYChannel;
|
|
|
|
srcData.y.size = aData.mYSize;
|
|
|
|
srcData.y.stride = aData.mYStride;
|
|
|
|
srcData.y.skip = aData.mYSkip;
|
2018-09-25 23:44:55 +03:00
|
|
|
srcData.y.bytesPerPixel = bytesPerPixel;
|
2015-10-15 18:53:33 +03:00
|
|
|
srcData.cb.data = aData.mCbChannel;
|
|
|
|
srcData.cb.size = aData.mCbCrSize;
|
|
|
|
srcData.cb.stride = aData.mCbCrStride;
|
|
|
|
srcData.cb.skip = aData.mCbSkip;
|
2018-09-25 23:44:55 +03:00
|
|
|
srcData.cb.bytesPerPixel = bytesPerPixel;
|
2015-10-15 18:53:33 +03:00
|
|
|
srcData.cr.data = aData.mCrChannel;
|
|
|
|
srcData.cr.size = aData.mCbCrSize;
|
|
|
|
srcData.cr.stride = aData.mCbCrStride;
|
|
|
|
srcData.cr.skip = aData.mCrSkip;
|
2018-09-25 23:44:55 +03:00
|
|
|
srcData.cr.bytesPerPixel = bytesPerPixel;
|
2015-10-15 18:53:33 +03:00
|
|
|
srcData.metadata = nullptr;
|
|
|
|
|
|
|
|
if (!srcData.CopyInto(mapped)) {
|
2015-11-24 21:07:02 +03:00
|
|
|
NS_WARNING("Failed to copy image data!");
|
2015-10-15 18:53:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-15 18:53:33 +03:00
|
|
|
if (TextureRequiresLocking(aTexture->GetFlags())) {
|
2015-11-24 21:07:02 +03:00
|
|
|
// We don't have support for proper locking yet, so we'll
|
|
|
|
// have to be immutable instead.
|
2015-10-15 18:53:33 +03:00
|
|
|
aTexture->MarkImmutable();
|
2015-10-15 18:53:33 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-15 18:53:37 +03:00
|
|
|
already_AddRefed<TextureClient> TextureClient::CreateWithData(
|
2016-09-27 06:22:20 +03:00
|
|
|
TextureData* aData, TextureFlags aFlags, LayersIPCChannel* aAllocator) {
|
2015-10-15 18:53:37 +03:00
|
|
|
if (!aData) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-11-20 16:25:00 +03:00
|
|
|
return MakeAndAddRef<TextureClient>(aData, aFlags, aAllocator);
|
2015-10-15 18:53:37 +03:00
|
|
|
}
|
|
|
|
|
2017-11-28 18:29:49 +03:00
|
|
|
template <class PixelDataType>
|
|
|
|
static void copyData(PixelDataType* aDst,
|
|
|
|
const MappedYCbCrChannelData& aChannelDst,
|
|
|
|
PixelDataType* aSrc,
|
|
|
|
const MappedYCbCrChannelData& aChannelSrc) {
|
|
|
|
uint8_t* srcByte = reinterpret_cast<uint8_t*>(aSrc);
|
|
|
|
const int32_t srcSkip = aChannelSrc.skip + 1;
|
|
|
|
uint8_t* dstByte = reinterpret_cast<uint8_t*>(aDst);
|
|
|
|
const int32_t dstSkip = aChannelDst.skip + 1;
|
|
|
|
for (int32_t i = 0; i < aChannelSrc.size.height; ++i) {
|
|
|
|
for (int32_t j = 0; j < aChannelSrc.size.width; ++j) {
|
|
|
|
*aDst = *aSrc;
|
|
|
|
aSrc += srcSkip;
|
|
|
|
aDst += dstSkip;
|
|
|
|
}
|
|
|
|
srcByte += aChannelSrc.stride;
|
|
|
|
aSrc = reinterpret_cast<PixelDataType*>(srcByte);
|
|
|
|
dstByte += aChannelDst.stride;
|
|
|
|
aDst = reinterpret_cast<PixelDataType*>(dstByte);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 18:53:33 +03:00
|
|
|
bool MappedYCbCrChannelData::CopyInto(MappedYCbCrChannelData& aDst) {
|
|
|
|
if (!data || !aDst.data || size != aDst.size) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-28 16:53:16 +03:00
|
|
|
if (stride == aDst.stride && skip == aDst.skip) {
|
2015-10-15 18:53:33 +03:00
|
|
|
// fast path!
|
|
|
|
// We assume that the padding in the destination is there for alignment
|
|
|
|
// purposes and doesn't contain useful data.
|
|
|
|
memcpy(aDst.data, data, stride * size.height);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-28 18:29:49 +03:00
|
|
|
if (aDst.skip == 0 && skip == 0) {
|
|
|
|
// fast-ish path
|
|
|
|
for (int32_t i = 0; i < size.height; ++i) {
|
2015-10-15 18:53:33 +03:00
|
|
|
memcpy(aDst.data + i * aDst.stride, data + i * stride,
|
2017-09-29 17:37:56 +03:00
|
|
|
size.width * bytesPerPixel);
|
2015-10-15 18:53:33 +03:00
|
|
|
}
|
2017-11-28 18:29:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(bytesPerPixel == 1 || bytesPerPixel == 2);
|
|
|
|
// slow path
|
|
|
|
if (bytesPerPixel == 1) {
|
|
|
|
copyData(aDst.data, aDst, data, *this);
|
|
|
|
} else if (bytesPerPixel == 2) {
|
|
|
|
copyData(reinterpret_cast<uint16_t*>(aDst.data), aDst,
|
|
|
|
reinterpret_cast<uint16_t*>(data), *this);
|
2015-10-15 18:53:33 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|