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 02:20:52 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-06-18 17:04:06 -07:00
|
|
|
#include "TextureHost.h"
|
|
|
|
|
2013-09-12 19:39:26 -07:00
|
|
|
#include "CompositableHost.h" // for CompositableHost
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "LayersLogging.h" // for AppendToString
|
|
|
|
#include "mozilla/gfx/2D.h" // for DataSourceSurface, Factory
|
|
|
|
#include "mozilla/ipc/Shmem.h" // for Shmem
|
2014-05-05 18:56:40 -07:00
|
|
|
#include "mozilla/layers/CompositableTransactionParent.h" // for CompositableParentManager
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "mozilla/layers/Compositor.h" // for Compositor
|
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator
|
2013-07-30 02:59:51 -07:00
|
|
|
#include "mozilla/layers/ImageDataSerializer.h"
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
|
2014-03-26 18:01:15 -07:00
|
|
|
#include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL
|
2013-07-30 02:59:51 -07:00
|
|
|
#include "mozilla/layers/YCbCrImageDataSerializer.h"
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "nsAString.h"
|
2015-03-10 17:48:09 -07:00
|
|
|
#include "nsRefPtr.h" // for nsRefPtr
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "nsPrintfCString.h" // for nsPrintfCString
|
2013-12-11 17:44:44 -08:00
|
|
|
#include "mozilla/layers/PTextureParent.h"
|
2014-03-10 11:34:57 -07:00
|
|
|
#include "mozilla/unused.h"
|
2014-02-20 13:04:11 -08:00
|
|
|
#include <limits>
|
2014-06-18 17:04:06 -07:00
|
|
|
#include "SharedSurface.h"
|
|
|
|
#include "SharedSurfaceEGL.h"
|
|
|
|
#include "SharedSurfaceGL.h"
|
|
|
|
#include "../opengl/CompositorOGL.h"
|
2014-11-28 14:41:47 -08:00
|
|
|
#include "gfxUtils.h"
|
2014-06-18 17:04:06 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_ENABLE_D3D10_LAYER
|
|
|
|
#include "../d3d11/CompositorD3D11.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "../opengl/GrallocTextureClient.h"
|
|
|
|
#include "../opengl/GrallocTextureHost.h"
|
|
|
|
#include "SharedSurfaceGralloc.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "mozilla/layers/X11TextureHost.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "SharedSurfaceIO.h"
|
|
|
|
#include "../opengl/MacIOSurfaceTextureHostOGL.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "SharedSurfaceANGLE.h"
|
2014-07-10 14:29:40 -07:00
|
|
|
#include "mozilla/layers/TextureDIB.h"
|
2014-06-18 17:04:06 -07:00
|
|
|
#endif
|
2013-07-30 02:59:51 -07:00
|
|
|
|
2014-03-10 11:34:57 -07:00
|
|
|
#if 0
|
|
|
|
#define RECYCLE_LOG(...) printf_stderr(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define RECYCLE_LOG(...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2013-08-11 16:17:23 -07:00
|
|
|
struct nsIntPoint;
|
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 02:20:52 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-12-11 17:44:44 -08:00
|
|
|
/**
|
|
|
|
* TextureParent is the host-side IPDL glue between TextureClient and TextureHost.
|
|
|
|
* It is an IPDL actor just like LayerParent, CompositableParent, etc.
|
|
|
|
*/
|
|
|
|
class TextureParent : public PTextureParent
|
|
|
|
{
|
|
|
|
public:
|
2014-08-19 21:55:14 -07:00
|
|
|
explicit TextureParent(CompositableParentManager* aManager);
|
2013-12-11 17:44:44 -08:00
|
|
|
|
|
|
|
~TextureParent();
|
|
|
|
|
2014-01-21 14:06:18 -08:00
|
|
|
bool Init(const SurfaceDescriptor& aSharedData,
|
|
|
|
const TextureFlags& aFlags);
|
2013-12-11 17:44:44 -08:00
|
|
|
|
2014-03-10 11:34:57 -07:00
|
|
|
void CompositorRecycle();
|
2014-05-12 07:39:25 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool RecvClientRecycle() override;
|
2014-03-10 11:34:57 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool RecvClearTextureHostSync() override;
|
2013-12-11 17:44:45 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool RecvRemoveTexture() override;
|
2013-12-11 17:44:45 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool RecvRecycleTexture(const TextureFlags& aTextureFlags) override;
|
2014-11-13 07:53:49 -08:00
|
|
|
|
2013-12-11 17:44:44 -08:00
|
|
|
TextureHost* GetTextureHost() { return mTextureHost; }
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
void ActorDestroy(ActorDestroyReason why) override;
|
2013-12-11 17:45:01 -08:00
|
|
|
|
2014-05-12 18:18:22 -07:00
|
|
|
void ClearTextureHost();
|
|
|
|
|
2014-05-05 18:56:40 -07:00
|
|
|
CompositableParentManager* mCompositableManager;
|
2014-03-10 11:34:57 -07:00
|
|
|
RefPtr<TextureHost> mWaitForClientRecycle;
|
2013-12-11 17:44:44 -08:00
|
|
|
RefPtr<TextureHost> mTextureHost;
|
|
|
|
};
|
|
|
|
|
|
|
|
// static
|
|
|
|
PTextureParent*
|
2014-05-05 18:56:40 -07:00
|
|
|
TextureHost::CreateIPDLActor(CompositableParentManager* aManager,
|
2014-01-21 14:06:18 -08:00
|
|
|
const SurfaceDescriptor& aSharedData,
|
|
|
|
TextureFlags aFlags)
|
2013-12-11 17:44:44 -08:00
|
|
|
{
|
2014-02-25 05:12:49 -08:00
|
|
|
if (aSharedData.type() == SurfaceDescriptor::TSurfaceDescriptorMemory &&
|
2014-05-05 18:56:40 -07:00
|
|
|
!aManager->IsSameProcess())
|
2014-02-25 05:12:49 -08:00
|
|
|
{
|
|
|
|
NS_ERROR("A client process is trying to peek at our address space using a MemoryTexture!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-05-05 18:56:40 -07:00
|
|
|
TextureParent* actor = new TextureParent(aManager);
|
2014-02-25 05:12:50 -08:00
|
|
|
if (!actor->Init(aSharedData, aFlags)) {
|
|
|
|
delete actor;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-01-21 14:06:18 -08:00
|
|
|
return actor;
|
2013-12-11 17:44:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
TextureHost::DestroyIPDLActor(PTextureParent* actor)
|
|
|
|
{
|
|
|
|
delete actor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
TextureHost::SendDeleteIPDLActor(PTextureParent* actor)
|
|
|
|
{
|
|
|
|
return PTextureParent::Send__delete__(actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
TextureHost*
|
|
|
|
TextureHost::AsTextureHost(PTextureParent* actor)
|
|
|
|
{
|
|
|
|
return actor? static_cast<TextureParent*>(actor)->mTextureHost : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-02-24 20:23:41 -08:00
|
|
|
PTextureParent*
|
|
|
|
TextureHost::GetIPDLActor()
|
|
|
|
{
|
|
|
|
return mActor;
|
|
|
|
}
|
|
|
|
|
2014-05-24 09:14:45 -07:00
|
|
|
FenceHandle
|
|
|
|
TextureHost::GetAndResetReleaseFenceHandle()
|
|
|
|
{
|
|
|
|
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
|
|
|
|
TextureHostOGL* hostOGL = this->AsHostOGL();
|
|
|
|
if (!hostOGL) {
|
|
|
|
return FenceHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
android::sp<android::Fence> fence = hostOGL->GetAndResetReleaseFence();
|
|
|
|
if (fence.get() && fence->isValid()) {
|
|
|
|
FenceHandle handle = FenceHandle(fence);
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return FenceHandle();
|
|
|
|
}
|
|
|
|
|
2013-12-03 16:20:04 -08:00
|
|
|
// implemented in TextureHostOGL.cpp
|
2013-12-11 17:44:47 -08:00
|
|
|
TemporaryRef<TextureHost> CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
|
2013-07-30 02:59:51 -07:00
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags);
|
|
|
|
|
2013-12-03 16:20:04 -08:00
|
|
|
// implemented in TextureHostBasic.cpp
|
2013-12-11 17:44:47 -08:00
|
|
|
TemporaryRef<TextureHost> CreateTextureHostBasic(const SurfaceDescriptor& aDesc,
|
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags);
|
2013-12-03 16:20:04 -08:00
|
|
|
|
2014-01-07 08:19:52 -08:00
|
|
|
// implemented in TextureD3D11.cpp
|
|
|
|
TemporaryRef<TextureHost> CreateTextureHostD3D11(const SurfaceDescriptor& aDesc,
|
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags);
|
|
|
|
|
2014-01-07 08:20:03 -08:00
|
|
|
// implemented in TextureD3D9.cpp
|
|
|
|
TemporaryRef<TextureHost> CreateTextureHostD3D9(const SurfaceDescriptor& aDesc,
|
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags);
|
|
|
|
|
2013-07-30 02:59:51 -07:00
|
|
|
// static
|
|
|
|
TemporaryRef<TextureHost>
|
2013-12-11 17:44:47 -08:00
|
|
|
TextureHost::Create(const SurfaceDescriptor& aDesc,
|
2013-07-30 02:59:51 -07:00
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags)
|
|
|
|
{
|
2014-02-05 05:34:16 -08:00
|
|
|
switch (aDesc.type()) {
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorShmem:
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMemory:
|
2014-07-10 14:29:40 -07:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorDIB:
|
2014-02-05 05:34:16 -08:00
|
|
|
return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
|
2014-06-18 17:04:06 -07:00
|
|
|
|
2014-09-17 06:13:29 -07:00
|
|
|
case SurfaceDescriptor::TEGLImageDescriptor:
|
2014-02-05 05:34:16 -08:00
|
|
|
case SurfaceDescriptor::TNewSurfaceDescriptorGralloc:
|
2014-09-17 06:13:29 -07:00
|
|
|
case SurfaceDescriptor::TSurfaceTextureDescriptor:
|
2014-06-04 18:27:22 -07:00
|
|
|
return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
|
2014-06-18 17:04:06 -07:00
|
|
|
|
2014-10-07 21:11:54 -07:00
|
|
|
case SurfaceDescriptor::TSharedSurfaceDescriptor:
|
|
|
|
return new SharedSurfaceTextureHost(aFlags, aDesc.get_SharedSurfaceDescriptor());
|
2014-10-07 21:01:51 -07:00
|
|
|
|
2014-02-05 05:34:16 -08:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface:
|
|
|
|
if (Compositor::GetBackend() == LayersBackend::LAYERS_OPENGL) {
|
|
|
|
return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
|
|
|
|
} else {
|
|
|
|
return CreateTextureHostBasic(aDesc, aDeallocator, aFlags);
|
|
|
|
}
|
2014-06-18 17:04:06 -07:00
|
|
|
|
2014-02-05 08:39:02 -08:00
|
|
|
#ifdef MOZ_X11
|
2014-02-17 16:30:05 -08:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorX11: {
|
|
|
|
const SurfaceDescriptorX11& desc = aDesc.get_SurfaceDescriptorX11();
|
|
|
|
RefPtr<TextureHost> result = new X11TextureHost(aFlags, desc);
|
|
|
|
return result;
|
|
|
|
}
|
2014-02-05 08:39:02 -08:00
|
|
|
#endif
|
2014-06-18 17:04:06 -07:00
|
|
|
|
2013-07-30 02:59:51 -07:00
|
|
|
#ifdef XP_WIN
|
2014-02-05 05:34:16 -08:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorD3D9:
|
2014-02-05 12:45:03 -08:00
|
|
|
return CreateTextureHostD3D9(aDesc, aDeallocator, aFlags);
|
2014-06-18 17:04:06 -07:00
|
|
|
|
2014-02-05 05:34:16 -08:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorD3D10:
|
2015-03-18 14:17:13 -07:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorDXGIYCbCr:
|
2014-04-06 20:23:06 -07:00
|
|
|
if (Compositor::GetBackend() == LayersBackend::LAYERS_D3D9) {
|
|
|
|
return CreateTextureHostD3D9(aDesc, aDeallocator, aFlags);
|
|
|
|
} else {
|
|
|
|
return CreateTextureHostD3D11(aDesc, aDeallocator, aFlags);
|
|
|
|
}
|
2013-07-30 02:59:51 -07:00
|
|
|
#endif
|
|
|
|
default:
|
2014-02-05 05:34:16 -08:00
|
|
|
MOZ_CRASH("Unsupported Surface type");
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<TextureHost>
|
2013-12-11 17:44:47 -08:00
|
|
|
CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
|
2013-07-30 02:59:51 -07:00
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags)
|
|
|
|
{
|
|
|
|
RefPtr<TextureHost> result;
|
|
|
|
switch (aDesc.type()) {
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorShmem: {
|
|
|
|
const SurfaceDescriptorShmem& descriptor = aDesc.get_SurfaceDescriptorShmem();
|
2013-12-11 17:44:47 -08:00
|
|
|
result = new ShmemTextureHost(descriptor.data(),
|
2013-07-30 02:59:51 -07:00
|
|
|
descriptor.format(),
|
|
|
|
aDeallocator,
|
|
|
|
aFlags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMemory: {
|
|
|
|
const SurfaceDescriptorMemory& descriptor = aDesc.get_SurfaceDescriptorMemory();
|
2013-12-11 17:44:47 -08:00
|
|
|
result = new MemoryTextureHost(reinterpret_cast<uint8_t*>(descriptor.data()),
|
2013-07-30 02:59:51 -07:00
|
|
|
descriptor.format(),
|
|
|
|
aFlags);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-10 14:29:40 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorDIB: {
|
|
|
|
result = new DIBTextureHost(aFlags, aDesc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2013-07-30 02:59:51 -07:00
|
|
|
default: {
|
|
|
|
NS_WARNING("No backend independent TextureHost for this descriptor type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
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 02:20:52 -07:00
|
|
|
|
2014-03-26 18:01:15 -07:00
|
|
|
void
|
|
|
|
TextureHost::CompositorRecycle()
|
|
|
|
{
|
|
|
|
if (!mActor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
static_cast<TextureParent*>(mActor)->CompositorRecycle();
|
|
|
|
}
|
|
|
|
|
2013-12-11 17:44:47 -08:00
|
|
|
TextureHost::TextureHost(TextureFlags aFlags)
|
2014-02-24 20:23:41 -08:00
|
|
|
: mActor(nullptr)
|
|
|
|
, mFlags(aFlags)
|
2014-11-17 02:06:25 -08:00
|
|
|
, mCompositableCount(0)
|
2013-09-12 19:39:26 -07:00
|
|
|
{}
|
|
|
|
|
|
|
|
TextureHost::~TextureHost()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-11 17:45:01 -08:00
|
|
|
void TextureHost::Finalize()
|
|
|
|
{
|
2014-04-25 19:34:05 -07:00
|
|
|
if (!(GetFlags() & TextureFlags::DEALLOCATE_CLIENT)) {
|
2013-12-11 17:45:01 -08:00
|
|
|
DeallocateSharedData();
|
|
|
|
DeallocateDeviceData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 07:53:49 -08:00
|
|
|
void
|
|
|
|
TextureHost::RecycleTexture(TextureFlags aFlags)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(GetFlags() & TextureFlags::RECYCLE);
|
|
|
|
MOZ_ASSERT(aFlags & TextureFlags::RECYCLE);
|
|
|
|
MOZ_ASSERT(!HasRecycleCallback());
|
|
|
|
mFlags = aFlags;
|
|
|
|
}
|
|
|
|
|
2013-09-23 04:28:40 -07:00
|
|
|
void
|
2014-06-19 15:36:25 -07:00
|
|
|
TextureHost::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
2013-09-23 04:28:40 -07:00
|
|
|
{
|
2014-06-19 15:36:25 -07:00
|
|
|
aStream << aPrefix;
|
|
|
|
aStream << nsPrintfCString("%s (0x%p)", Name(), this).get();
|
2014-01-21 13:27:01 -08:00
|
|
|
// Note: the TextureHost needs to be locked before it is safe to call
|
|
|
|
// GetSize() and GetFormat() on it.
|
|
|
|
if (Lock()) {
|
2014-06-19 15:36:25 -07:00
|
|
|
AppendToString(aStream, GetSize(), " [size=", "]");
|
|
|
|
AppendToString(aStream, GetFormat(), " [format=", "]");
|
2014-01-21 13:27:01 -08:00
|
|
|
Unlock();
|
|
|
|
}
|
2014-06-19 15:36:25 -07:00
|
|
|
AppendToString(aStream, mFlags, " [flags=", "]");
|
2014-11-28 14:41:47 -08:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2014-12-12 13:11:57 -08:00
|
|
|
if (gfxPrefs::LayersDumpTexture() || profiler_feature_active("layersdump")) {
|
2014-11-28 14:41:47 -08:00
|
|
|
nsAutoCString pfx(aPrefix);
|
|
|
|
pfx += " ";
|
|
|
|
|
|
|
|
aStream << "\n" << pfx.get() << "Surface: ";
|
|
|
|
RefPtr<gfx::DataSourceSurface> dSurf = GetAsSurface();
|
|
|
|
if (dSurf) {
|
2014-12-08 11:42:33 -08:00
|
|
|
aStream << gfxUtils::GetAsLZ4Base64Str(dSurf).get();
|
2014-11-28 14:41:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-09-23 04:28:40 -07:00
|
|
|
}
|
|
|
|
|
2013-09-12 19:39:26 -07:00
|
|
|
TextureSource::TextureSource()
|
2014-10-16 10:08:32 -07:00
|
|
|
: mCompositableCount(0)
|
2013-09-12 19:39:26 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(TextureSource);
|
|
|
|
}
|
2014-10-16 10:08:32 -07:00
|
|
|
|
2013-09-12 19:39:26 -07:00
|
|
|
TextureSource::~TextureSource()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(TextureSource);
|
|
|
|
}
|
|
|
|
|
2013-12-11 17:44:47 -08:00
|
|
|
BufferTextureHost::BufferTextureHost(gfx::SurfaceFormat aFormat,
|
2013-07-30 02:59:51 -07:00
|
|
|
TextureFlags aFlags)
|
2013-12-11 17:44:47 -08:00
|
|
|
: TextureHost(aFlags)
|
2013-07-30 02:59:51 -07:00
|
|
|
, mCompositor(nullptr)
|
|
|
|
, mFormat(aFormat)
|
|
|
|
, mUpdateSerial(1)
|
|
|
|
, mLocked(false)
|
2014-08-28 20:06:26 -07:00
|
|
|
, mNeedsFullUpdate(false)
|
2015-03-05 17:37:12 -08:00
|
|
|
{
|
|
|
|
if (aFlags & TextureFlags::COMPONENT_ALPHA) {
|
|
|
|
// One texture of a component alpha texture pair will start out all white.
|
|
|
|
// This hack allows us to easily make sure that white will be uploaded.
|
|
|
|
// See bug 1138934
|
|
|
|
mNeedsFullUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
2013-07-30 02:59:51 -07:00
|
|
|
|
2014-11-12 13:44:42 -08:00
|
|
|
void
|
|
|
|
BufferTextureHost::InitSize()
|
|
|
|
{
|
|
|
|
if (mFormat == gfx::SurfaceFormat::YUV) {
|
|
|
|
YCbCrImageDataDeserializer yuvDeserializer(GetBuffer(), GetBufferSize());
|
|
|
|
if (yuvDeserializer.IsValid()) {
|
|
|
|
mSize = yuvDeserializer.GetYSize();
|
|
|
|
}
|
|
|
|
} else if (mFormat != gfx::SurfaceFormat::UNKNOWN) {
|
|
|
|
ImageDataDeserializer deserializer(GetBuffer(), GetBufferSize());
|
|
|
|
if (deserializer.IsValid()) {
|
|
|
|
mSize = deserializer.GetSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:59:51 -07:00
|
|
|
BufferTextureHost::~BufferTextureHost()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferTextureHost::Updated(const nsIntRegion* aRegion)
|
|
|
|
{
|
|
|
|
++mUpdateSerial;
|
2014-08-26 06:06:17 -07:00
|
|
|
// If the last frame wasn't uploaded yet, and we -don't- have a partial update,
|
|
|
|
// we still need to update the full surface.
|
2014-08-28 20:06:26 -07:00
|
|
|
if (aRegion && !mNeedsFullUpdate) {
|
2014-08-26 06:06:17 -07:00
|
|
|
mMaybeUpdatedRegion = mMaybeUpdatedRegion.Or(mMaybeUpdatedRegion, *aRegion);
|
2013-07-30 02:59:51 -07:00
|
|
|
} else {
|
2014-08-28 20:06:26 -07:00
|
|
|
mNeedsFullUpdate = true;
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
2014-04-25 19:34:05 -07:00
|
|
|
if (GetFlags() & TextureFlags::IMMEDIATE_UPLOAD) {
|
2014-08-28 20:06:26 -07:00
|
|
|
DebugOnly<bool> result = MaybeUpload(!mNeedsFullUpdate ? &mMaybeUpdatedRegion : nullptr);
|
2014-01-07 08:20:11 -08:00
|
|
|
NS_WARN_IF_FALSE(result, "Failed to upload a texture");
|
2013-08-03 10:30:28 -07:00
|
|
|
}
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferTextureHost::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
2015-03-27 03:16:18 -07:00
|
|
|
MOZ_ASSERT(aCompositor);
|
2013-07-30 02:59:51 -07:00
|
|
|
if (mCompositor == aCompositor) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-07 06:58:59 -07:00
|
|
|
RefPtr<TextureSource> it = mFirstSource;
|
2014-01-07 08:20:11 -08:00
|
|
|
while (it) {
|
|
|
|
it->SetCompositor(aCompositor);
|
|
|
|
it = it->GetNextSibling();
|
|
|
|
}
|
2014-10-14 15:11:38 -07:00
|
|
|
mFirstSource = nullptr;
|
2013-07-30 02:59:51 -07:00
|
|
|
mCompositor = aCompositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferTextureHost::DeallocateDeviceData()
|
|
|
|
{
|
2014-10-07 06:58:59 -07:00
|
|
|
RefPtr<TextureSource> it = mFirstSource;
|
2013-07-30 02:59:51 -07:00
|
|
|
while (it) {
|
|
|
|
it->DeallocateDeviceData();
|
|
|
|
it = it->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BufferTextureHost::Lock()
|
|
|
|
{
|
2014-07-28 05:58:38 -07:00
|
|
|
MOZ_ASSERT(!mLocked);
|
2014-08-28 20:06:26 -07:00
|
|
|
if (!MaybeUpload(!mNeedsFullUpdate ? &mMaybeUpdatedRegion : nullptr)) {
|
2014-07-28 05:58:38 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mLocked = !!mFirstSource;
|
|
|
|
return mLocked;
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferTextureHost::Unlock()
|
|
|
|
{
|
2014-07-28 05:58:38 -07:00
|
|
|
MOZ_ASSERT(mLocked);
|
2013-07-30 02:59:51 -07:00
|
|
|
mLocked = false;
|
|
|
|
}
|
|
|
|
|
2015-03-27 03:16:34 -07:00
|
|
|
bool
|
|
|
|
BufferTextureHost::BindTextureSource(CompositableTextureSourceRef& aTexture)
|
2013-07-30 02:59:51 -07:00
|
|
|
{
|
2014-07-28 05:58:38 -07:00
|
|
|
MOZ_ASSERT(mLocked);
|
|
|
|
MOZ_ASSERT(mFirstSource);
|
2015-03-27 03:16:34 -07:00
|
|
|
aTexture = mFirstSource;
|
|
|
|
return !!aTexture;
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat
|
|
|
|
BufferTextureHost::GetFormat() const
|
|
|
|
{
|
|
|
|
// mFormat is the format of the data that we share with the content process.
|
|
|
|
// GetFormat, on the other hand, expects the format that we present to the
|
|
|
|
// Compositor (it is used to choose the effect type).
|
|
|
|
// if the compositor does not support YCbCr effects, we give it a RGBX texture
|
|
|
|
// instead (see BufferTextureHost::Upload)
|
2014-01-10 11:06:16 -08:00
|
|
|
if (mFormat == gfx::SurfaceFormat::YUV &&
|
2013-07-30 02:59:51 -07:00
|
|
|
mCompositor &&
|
2014-04-25 19:34:06 -07:00
|
|
|
!mCompositor->SupportsEffect(EffectTypes::YCBCR)) {
|
2014-01-10 11:06:16 -08:00
|
|
|
return gfx::SurfaceFormat::R8G8B8X8;
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
return mFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-08-03 10:30:28 -07:00
|
|
|
BufferTextureHost::MaybeUpload(nsIntRegion *aRegion)
|
|
|
|
{
|
|
|
|
if (mFirstSource && mFirstSource->GetUpdateSerial() == mUpdateSerial) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!Upload(aRegion)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-26 06:06:17 -07:00
|
|
|
|
|
|
|
// We no longer have an invalid region.
|
2014-08-28 20:06:26 -07:00
|
|
|
mNeedsFullUpdate = false;
|
2014-08-26 06:06:17 -07:00
|
|
|
mMaybeUpdatedRegion.SetEmpty();
|
|
|
|
|
2014-07-28 05:58:38 -07:00
|
|
|
// If upload returns true we know mFirstSource is not null
|
2013-08-03 10:30:28 -07:00
|
|
|
mFirstSource->SetUpdateSerial(mUpdateSerial);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-30 02:59:51 -07:00
|
|
|
BufferTextureHost::Upload(nsIntRegion *aRegion)
|
|
|
|
{
|
2013-12-11 17:44:59 -08:00
|
|
|
if (!GetBuffer()) {
|
|
|
|
// We don't have a buffer; a possible cause is that the IPDL actor
|
|
|
|
// is already dead. This inevitably happens as IPDL actors can die
|
|
|
|
// at any time, so we want to silently return in this case.
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-11 17:44:41 -08:00
|
|
|
if (!mCompositor) {
|
2015-03-27 03:16:27 -07:00
|
|
|
// This can happen if we send textures to a compositable that isn't yet
|
|
|
|
// attached to a layer.
|
2013-12-11 17:44:41 -08:00
|
|
|
return false;
|
|
|
|
}
|
2014-01-10 11:06:16 -08:00
|
|
|
if (mFormat == gfx::SurfaceFormat::UNKNOWN) {
|
2013-07-30 02:59:51 -07:00
|
|
|
NS_WARNING("BufferTextureHost: unsupported format!");
|
|
|
|
return false;
|
2014-01-10 11:06:16 -08:00
|
|
|
} else if (mFormat == gfx::SurfaceFormat::YUV) {
|
2014-02-20 13:04:13 -08:00
|
|
|
YCbCrImageDataDeserializer yuvDeserializer(GetBuffer(), GetBufferSize());
|
2013-07-30 02:59:51 -07:00
|
|
|
MOZ_ASSERT(yuvDeserializer.IsValid());
|
|
|
|
|
2014-04-25 19:34:06 -07:00
|
|
|
if (!mCompositor->SupportsEffect(EffectTypes::YCBCR)) {
|
2013-07-30 02:59:51 -07:00
|
|
|
RefPtr<gfx::DataSourceSurface> surf = yuvDeserializer.ToDataSourceSurface();
|
2014-08-27 08:57:43 -07:00
|
|
|
if (NS_WARN_IF(!surf)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-30 02:59:51 -07:00
|
|
|
if (!mFirstSource) {
|
|
|
|
mFirstSource = mCompositor->CreateDataTextureSource(mFlags);
|
|
|
|
}
|
2014-01-07 08:20:11 -08:00
|
|
|
mFirstSource->Update(surf, aRegion);
|
2013-07-30 02:59:51 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<DataTextureSource> srcY;
|
|
|
|
RefPtr<DataTextureSource> srcU;
|
|
|
|
RefPtr<DataTextureSource> srcV;
|
|
|
|
if (!mFirstSource) {
|
2013-08-01 16:02:06 -07:00
|
|
|
// We don't support BigImages for YCbCr compositing.
|
2014-04-25 19:34:05 -07:00
|
|
|
srcY = mCompositor->CreateDataTextureSource(mFlags|TextureFlags::DISALLOW_BIGIMAGE);
|
|
|
|
srcU = mCompositor->CreateDataTextureSource(mFlags|TextureFlags::DISALLOW_BIGIMAGE);
|
|
|
|
srcV = mCompositor->CreateDataTextureSource(mFlags|TextureFlags::DISALLOW_BIGIMAGE);
|
2013-07-30 02:59:51 -07:00
|
|
|
mFirstSource = srcY;
|
|
|
|
srcY->SetNextSibling(srcU);
|
|
|
|
srcU->SetNextSibling(srcV);
|
|
|
|
} else {
|
|
|
|
// mFormat never changes so if this was created as a YCbCr host and already
|
|
|
|
// contains a source it should already have 3 sources.
|
|
|
|
// BufferTextureHost only uses DataTextureSources so it is safe to assume
|
|
|
|
// all 3 sources are DataTextureSource.
|
|
|
|
MOZ_ASSERT(mFirstSource->GetNextSibling());
|
|
|
|
MOZ_ASSERT(mFirstSource->GetNextSibling()->GetNextSibling());
|
|
|
|
srcY = mFirstSource;
|
|
|
|
srcU = mFirstSource->GetNextSibling()->AsDataTextureSource();
|
|
|
|
srcV = mFirstSource->GetNextSibling()->GetNextSibling()->AsDataTextureSource();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RefPtr<gfx::DataSourceSurface> tempY =
|
|
|
|
gfx::Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetYData(),
|
|
|
|
yuvDeserializer.GetYStride(),
|
2013-12-20 08:46:30 -08:00
|
|
|
yuvDeserializer.GetYSize(),
|
2014-01-10 11:06:16 -08:00
|
|
|
gfx::SurfaceFormat::A8);
|
2013-07-30 02:59:51 -07:00
|
|
|
RefPtr<gfx::DataSourceSurface> tempCb =
|
|
|
|
gfx::Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetCbData(),
|
|
|
|
yuvDeserializer.GetCbCrStride(),
|
2013-12-20 08:46:30 -08:00
|
|
|
yuvDeserializer.GetCbCrSize(),
|
2014-01-10 11:06:16 -08:00
|
|
|
gfx::SurfaceFormat::A8);
|
2013-07-30 02:59:51 -07:00
|
|
|
RefPtr<gfx::DataSourceSurface> tempCr =
|
|
|
|
gfx::Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetCrData(),
|
|
|
|
yuvDeserializer.GetCbCrStride(),
|
2013-12-20 08:46:30 -08:00
|
|
|
yuvDeserializer.GetCbCrSize(),
|
2014-01-10 11:06:16 -08:00
|
|
|
gfx::SurfaceFormat::A8);
|
2013-07-30 02:59:51 -07:00
|
|
|
// We don't support partial updates for Y U V textures
|
|
|
|
NS_ASSERTION(!aRegion, "Unsupported partial updates for YCbCr textures");
|
2014-12-12 11:56:06 -08:00
|
|
|
if (!tempY ||
|
|
|
|
!tempCb ||
|
|
|
|
!tempCr ||
|
|
|
|
!srcY->Update(tempY) ||
|
2014-01-07 08:20:11 -08:00
|
|
|
!srcU->Update(tempCb) ||
|
|
|
|
!srcV->Update(tempCr)) {
|
2013-07-30 02:59:51 -07:00
|
|
|
NS_WARNING("failed to update the DataTextureSource");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// non-YCbCr case
|
|
|
|
if (!mFirstSource) {
|
|
|
|
mFirstSource = mCompositor->CreateDataTextureSource();
|
|
|
|
}
|
2014-02-20 13:04:11 -08:00
|
|
|
ImageDataDeserializer deserializer(GetBuffer(), GetBufferSize());
|
2013-07-30 02:59:51 -07:00
|
|
|
if (!deserializer.IsValid()) {
|
2014-02-20 13:04:11 -08:00
|
|
|
NS_ERROR("Failed to deserialize image!");
|
2013-07-30 02:59:51 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<gfx::DataSourceSurface> surf = deserializer.GetAsSurface();
|
2013-08-19 16:39:55 -07:00
|
|
|
if (!surf) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-30 02:59:51 -07:00
|
|
|
|
2014-01-07 08:20:11 -08:00
|
|
|
if (!mFirstSource->Update(surf.get(), aRegion)) {
|
2013-07-30 02:59:51 -07:00
|
|
|
NS_WARNING("failed to update the DataTextureSource");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-07-28 05:58:38 -07:00
|
|
|
MOZ_ASSERT(mFirstSource);
|
2013-07-30 02:59:51 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-27 01:59:01 -08:00
|
|
|
TemporaryRef<gfx::DataSourceSurface>
|
2013-07-30 02:59:51 -07:00
|
|
|
BufferTextureHost::GetAsSurface()
|
|
|
|
{
|
2013-11-27 01:59:01 -08:00
|
|
|
RefPtr<gfx::DataSourceSurface> result;
|
2014-01-10 11:06:16 -08:00
|
|
|
if (mFormat == gfx::SurfaceFormat::UNKNOWN) {
|
2013-07-30 02:59:51 -07:00
|
|
|
NS_WARNING("BufferTextureHost: unsupported format!");
|
|
|
|
return nullptr;
|
2014-01-10 11:06:16 -08:00
|
|
|
} else if (mFormat == gfx::SurfaceFormat::YUV) {
|
2014-02-20 13:04:13 -08:00
|
|
|
YCbCrImageDataDeserializer yuvDeserializer(GetBuffer(), GetBufferSize());
|
2013-07-30 02:59:51 -07:00
|
|
|
if (!yuvDeserializer.IsValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-27 01:59:01 -08:00
|
|
|
result = yuvDeserializer.ToDataSourceSurface();
|
2014-08-27 08:57:43 -07:00
|
|
|
if (NS_WARN_IF(!result)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-07-30 02:59:51 -07:00
|
|
|
} else {
|
2014-02-20 13:04:11 -08:00
|
|
|
ImageDataDeserializer deserializer(GetBuffer(), GetBufferSize());
|
2013-07-30 02:59:51 -07:00
|
|
|
if (!deserializer.IsValid()) {
|
2014-02-20 13:04:11 -08:00
|
|
|
NS_ERROR("Failed to deserialize image!");
|
2013-07-30 02:59:51 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-27 01:59:01 -08:00
|
|
|
result = deserializer.GetAsSurface();
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2013-12-11 17:44:47 -08:00
|
|
|
ShmemTextureHost::ShmemTextureHost(const ipc::Shmem& aShmem,
|
2013-07-30 02:59:51 -07:00
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags)
|
2013-12-11 17:44:47 -08:00
|
|
|
: BufferTextureHost(aFormat, aFlags)
|
2014-07-21 15:55:02 -07:00
|
|
|
, mShmem(MakeUnique<ipc::Shmem>(aShmem))
|
2013-07-30 02:59:51 -07:00
|
|
|
, mDeallocator(aDeallocator)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ShmemTextureHost);
|
2014-11-12 13:44:42 -08:00
|
|
|
InitSize();
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ShmemTextureHost::~ShmemTextureHost()
|
|
|
|
{
|
2014-08-25 06:45:26 -07:00
|
|
|
MOZ_ASSERT(!mShmem || (mFlags & TextureFlags::DEALLOCATE_CLIENT),
|
|
|
|
"Leaking our buffer");
|
2013-07-30 02:59:51 -07:00
|
|
|
DeallocateDeviceData();
|
|
|
|
MOZ_COUNT_DTOR(ShmemTextureHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShmemTextureHost::DeallocateSharedData()
|
|
|
|
{
|
|
|
|
if (mShmem) {
|
|
|
|
MOZ_ASSERT(mDeallocator,
|
|
|
|
"Shared memory would leak without a ISurfaceAllocator");
|
|
|
|
mDeallocator->DeallocShmem(*mShmem);
|
2013-12-11 17:44:45 -08:00
|
|
|
mShmem = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShmemTextureHost::ForgetSharedData()
|
|
|
|
{
|
|
|
|
if (mShmem) {
|
2013-12-11 10:05:11 -08:00
|
|
|
mShmem = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-12-11 17:45:01 -08:00
|
|
|
ShmemTextureHost::OnShutdown()
|
2013-09-27 02:48:42 -07:00
|
|
|
{
|
|
|
|
mShmem = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:59:51 -07:00
|
|
|
uint8_t* ShmemTextureHost::GetBuffer()
|
|
|
|
{
|
|
|
|
return mShmem ? mShmem->get<uint8_t>() : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-02-20 13:04:11 -08:00
|
|
|
size_t ShmemTextureHost::GetBufferSize()
|
|
|
|
{
|
|
|
|
return mShmem ? mShmem->Size<uint8_t>() : 0;
|
|
|
|
}
|
|
|
|
|
2013-12-11 17:44:47 -08:00
|
|
|
MemoryTextureHost::MemoryTextureHost(uint8_t* aBuffer,
|
2013-07-30 02:59:51 -07:00
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
TextureFlags aFlags)
|
2013-12-11 17:44:47 -08:00
|
|
|
: BufferTextureHost(aFormat, aFlags)
|
2013-07-30 02:59:51 -07:00
|
|
|
, mBuffer(aBuffer)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(MemoryTextureHost);
|
2014-11-12 13:44:42 -08:00
|
|
|
InitSize();
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
MemoryTextureHost::~MemoryTextureHost()
|
|
|
|
{
|
2014-08-25 06:45:26 -07:00
|
|
|
MOZ_ASSERT(!mBuffer || (mFlags & TextureFlags::DEALLOCATE_CLIENT),
|
|
|
|
"Leaking our buffer");
|
2013-07-30 02:59:51 -07:00
|
|
|
DeallocateDeviceData();
|
2013-08-01 18:12:16 -07:00
|
|
|
MOZ_COUNT_DTOR(MemoryTextureHost);
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MemoryTextureHost::DeallocateSharedData()
|
|
|
|
{
|
2013-11-14 13:54:25 -08:00
|
|
|
if (mBuffer) {
|
|
|
|
GfxMemoryImageReporter::WillFree(mBuffer);
|
|
|
|
}
|
2013-07-30 02:59:51 -07:00
|
|
|
delete[] mBuffer;
|
2013-12-05 10:39:22 -08:00
|
|
|
mBuffer = nullptr;
|
2013-07-30 02:59:51 -07:00
|
|
|
}
|
|
|
|
|
2013-12-11 17:44:45 -08:00
|
|
|
void
|
|
|
|
MemoryTextureHost::ForgetSharedData()
|
|
|
|
{
|
|
|
|
mBuffer = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-30 02:59:51 -07:00
|
|
|
uint8_t* MemoryTextureHost::GetBuffer()
|
|
|
|
{
|
|
|
|
return mBuffer;
|
|
|
|
}
|
|
|
|
|
2014-02-20 13:04:11 -08:00
|
|
|
size_t MemoryTextureHost::GetBufferSize()
|
|
|
|
{
|
|
|
|
// MemoryTextureHost just trusts that the buffer size is large enough to read
|
|
|
|
// anything we need to. That's because MemoryTextureHost has to trust the buffer
|
|
|
|
// pointer anyway, so the security model here is just that MemoryTexture's
|
|
|
|
// are restricted to same-process clients.
|
|
|
|
return std::numeric_limits<size_t>::max();
|
|
|
|
}
|
|
|
|
|
2014-05-05 18:56:40 -07:00
|
|
|
TextureParent::TextureParent(CompositableParentManager* aCompositableManager)
|
|
|
|
: mCompositableManager(aCompositableManager)
|
2013-12-11 17:44:44 -08:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(TextureParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureParent::~TextureParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(TextureParent);
|
2014-03-10 11:34:57 -07:00
|
|
|
if (mTextureHost) {
|
|
|
|
mTextureHost->ClearRecycleCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RecycleCallback(TextureHost* textureHost, void* aClosure) {
|
|
|
|
TextureParent* tp = reinterpret_cast<TextureParent*>(aClosure);
|
|
|
|
tp->CompositorRecycle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextureParent::CompositorRecycle()
|
|
|
|
{
|
|
|
|
mTextureHost->ClearRecycleCallback();
|
2014-05-12 07:39:25 -07:00
|
|
|
|
|
|
|
if (mTextureHost->GetFlags() & TextureFlags::RECYCLE) {
|
|
|
|
mozilla::unused << SendCompositorRecycle();
|
|
|
|
// Don't forget to prepare for the next reycle
|
|
|
|
// if TextureClient request it.
|
|
|
|
mWaitForClientRecycle = mTextureHost;
|
|
|
|
}
|
|
|
|
}
|
2014-03-26 18:01:15 -07:00
|
|
|
|
2014-03-10 11:34:57 -07:00
|
|
|
bool
|
|
|
|
TextureParent::RecvClientRecycle()
|
|
|
|
{
|
|
|
|
// This will allow the RecycleCallback to be called once the compositor
|
|
|
|
// releases any external references to TextureHost.
|
|
|
|
mTextureHost->SetRecycleCallback(RecycleCallback, this);
|
|
|
|
if (!mWaitForClientRecycle) {
|
|
|
|
RECYCLE_LOG("Not a recycable tile");
|
|
|
|
}
|
|
|
|
mWaitForClientRecycle = nullptr;
|
|
|
|
return true;
|
2013-12-11 17:44:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-01-21 14:06:18 -08:00
|
|
|
TextureParent::Init(const SurfaceDescriptor& aSharedData,
|
|
|
|
const TextureFlags& aFlags)
|
2013-12-11 17:44:44 -08:00
|
|
|
{
|
2013-12-11 17:44:47 -08:00
|
|
|
mTextureHost = TextureHost::Create(aSharedData,
|
2014-05-05 18:56:40 -07:00
|
|
|
mCompositableManager,
|
2013-12-11 17:44:44 -08:00
|
|
|
aFlags);
|
2014-03-10 11:34:57 -07:00
|
|
|
if (mTextureHost) {
|
|
|
|
mTextureHost->mActor = this;
|
2014-04-25 19:34:05 -07:00
|
|
|
if (aFlags & TextureFlags::RECYCLE) {
|
2014-03-10 11:34:57 -07:00
|
|
|
mWaitForClientRecycle = mTextureHost;
|
|
|
|
RECYCLE_LOG("Setup recycling for tile %p\n", this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-11 17:44:44 -08:00
|
|
|
return !!mTextureHost;
|
|
|
|
}
|
|
|
|
|
2013-12-11 17:44:45 -08:00
|
|
|
bool
|
|
|
|
TextureParent::RecvRemoveTexture()
|
|
|
|
{
|
|
|
|
return PTextureParent::Send__delete__(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-05-12 18:18:22 -07:00
|
|
|
TextureParent::RecvClearTextureHostSync()
|
2013-12-11 17:44:45 -08:00
|
|
|
{
|
2014-05-12 18:18:22 -07:00
|
|
|
ClearTextureHost();
|
|
|
|
return true;
|
2013-12-11 17:44:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextureParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
switch (why) {
|
|
|
|
case AncestorDeletion:
|
|
|
|
case Deletion:
|
|
|
|
case NormalShutdown:
|
|
|
|
case AbnormalShutdown:
|
|
|
|
break;
|
|
|
|
case FailedConstructor:
|
|
|
|
NS_RUNTIMEABORT("FailedConstructor isn't possible in PTexture");
|
|
|
|
}
|
2014-01-23 07:26:59 -08:00
|
|
|
|
2014-05-12 18:18:22 -07:00
|
|
|
ClearTextureHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextureParent::ClearTextureHost()
|
|
|
|
{
|
|
|
|
if (!mTextureHost) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-25 19:34:05 -07:00
|
|
|
if (mTextureHost->GetFlags() & TextureFlags::RECYCLE) {
|
2014-03-10 11:34:57 -07:00
|
|
|
RECYCLE_LOG("clear recycling for tile %p\n", this);
|
|
|
|
mTextureHost->ClearRecycleCallback();
|
|
|
|
}
|
2014-04-25 19:34:05 -07:00
|
|
|
if (mTextureHost->GetFlags() & TextureFlags::DEALLOCATE_CLIENT) {
|
2014-01-23 07:26:59 -08:00
|
|
|
mTextureHost->ForgetSharedData();
|
|
|
|
}
|
2014-02-24 20:23:41 -08:00
|
|
|
|
2014-03-31 20:24:55 -07:00
|
|
|
// Clear recycle callback.
|
|
|
|
mTextureHost->ClearRecycleCallback();
|
|
|
|
mWaitForClientRecycle = nullptr;
|
|
|
|
|
2014-02-24 20:23:41 -08:00
|
|
|
mTextureHost->mActor = nullptr;
|
2013-12-11 17:44:45 -08:00
|
|
|
mTextureHost = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-13 07:53:49 -08:00
|
|
|
bool
|
|
|
|
TextureParent::RecvRecycleTexture(const TextureFlags& aTextureFlags)
|
|
|
|
{
|
|
|
|
if (!mTextureHost) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
mTextureHost->RecycleTexture(aTextureFlags);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-07 21:01:51 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-06-18 17:04:06 -07:00
|
|
|
|
2014-10-08 13:04:19 -07:00
|
|
|
static RefPtr<TextureSource>
|
|
|
|
SharedSurfaceToTexSource(gl::SharedSurface* abstractSurf, Compositor* compositor)
|
2014-10-07 21:01:51 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(abstractSurf);
|
|
|
|
MOZ_ASSERT(abstractSurf->mType != gl::SharedSurfaceType::Basic);
|
|
|
|
MOZ_ASSERT(abstractSurf->mType != gl::SharedSurfaceType::Gralloc);
|
|
|
|
|
|
|
|
if (!compositor) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat format = abstractSurf->mHasAlpha ? gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
: gfx::SurfaceFormat::R8G8B8X8;
|
|
|
|
|
2014-10-08 13:04:19 -07:00
|
|
|
RefPtr<TextureSource> texSource;
|
2014-10-07 21:01:51 -07:00
|
|
|
switch (abstractSurf->mType) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
case gl::SharedSurfaceType::EGLSurfaceANGLE: {
|
|
|
|
auto surf = gl::SharedSurface_ANGLEShareHandle::Cast(abstractSurf);
|
|
|
|
|
|
|
|
MOZ_ASSERT(compositor->GetBackendType() == LayersBackend::LAYERS_D3D11);
|
|
|
|
CompositorD3D11* compositorD3D11 = static_cast<CompositorD3D11*>(compositor);
|
2014-10-31 07:57:32 -07:00
|
|
|
RefPtr<ID3D11Texture2D> tex = surf->GetConsumerTexture();
|
2014-10-07 21:01:51 -07:00
|
|
|
|
2014-10-31 07:57:32 -07:00
|
|
|
if (!tex) {
|
2014-10-07 21:01:51 -07:00
|
|
|
NS_WARNING("Failed to open shared resource.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
texSource = new DataTextureSourceD3D11(format, compositorD3D11, tex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case gl::SharedSurfaceType::GLTextureShare: {
|
|
|
|
auto surf = gl::SharedSurface_GLTexture::Cast(abstractSurf);
|
|
|
|
|
|
|
|
MOZ_ASSERT(compositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
|
|
|
|
CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(compositor);
|
|
|
|
gl::GLContext* gl = compositorOGL->gl();
|
|
|
|
|
|
|
|
GLenum target = surf->ConsTextureTarget();
|
|
|
|
GLuint tex = surf->ConsTexture(gl);
|
2014-10-16 10:08:32 -07:00
|
|
|
texSource = new GLTextureSource(compositorOGL, tex, target,
|
|
|
|
surf->mSize, format,
|
|
|
|
true/*externally owned*/);
|
2014-10-07 21:01:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gl::SharedSurfaceType::EGLImageShare: {
|
|
|
|
auto surf = gl::SharedSurface_EGLImage::Cast(abstractSurf);
|
|
|
|
|
|
|
|
MOZ_ASSERT(compositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
|
|
|
|
CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(compositor);
|
|
|
|
gl::GLContext* gl = compositorOGL->gl();
|
|
|
|
MOZ_ASSERT(gl->IsCurrent());
|
|
|
|
|
|
|
|
GLenum target = 0;
|
|
|
|
GLuint tex = 0;
|
|
|
|
surf->AcquireConsumerTexture(gl, &tex, &target);
|
|
|
|
|
2014-10-16 10:08:32 -07:00
|
|
|
texSource = new GLTextureSource(compositorOGL, tex, target,
|
|
|
|
surf->mSize, format,
|
|
|
|
true/*externally owned*/);
|
2014-10-07 21:01:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case gl::SharedSurfaceType::IOSurface: {
|
|
|
|
auto surf = gl::SharedSurface_IOSurface::Cast(abstractSurf);
|
|
|
|
MacIOSurface* ioSurf = surf->GetIOSurface();
|
|
|
|
|
|
|
|
MOZ_ASSERT(compositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
|
|
|
|
CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(compositor);
|
|
|
|
|
|
|
|
texSource = new MacIOSurfaceTextureSourceOGL(compositorOGL, ioSurf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(texSource.get(), "TextureSource creation failed.");
|
|
|
|
return texSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-10-07 21:11:54 -07:00
|
|
|
// SharedSurfaceTextureHost
|
2014-10-07 21:01:51 -07:00
|
|
|
|
2014-10-07 21:11:54 -07:00
|
|
|
SharedSurfaceTextureHost::SharedSurfaceTextureHost(TextureFlags aFlags,
|
|
|
|
const SharedSurfaceDescriptor& aDesc)
|
2014-10-07 21:01:51 -07:00
|
|
|
: TextureHost(aFlags)
|
|
|
|
, mIsLocked(false)
|
|
|
|
, mSurf((gl::SharedSurface*)aDesc.surf())
|
|
|
|
, mCompositor(nullptr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mSurf);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat
|
2014-10-07 21:11:54 -07:00
|
|
|
SharedSurfaceTextureHost::GetFormat() const
|
2014-10-07 21:01:51 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTexSource);
|
|
|
|
return mTexSource->GetFormat();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::IntSize
|
2014-10-07 21:11:54 -07:00
|
|
|
SharedSurfaceTextureHost::GetSize() const
|
2014-10-07 21:01:51 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTexSource);
|
|
|
|
return mTexSource->GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-07 21:11:54 -07:00
|
|
|
SharedSurfaceTextureHost::EnsureTexSource()
|
2014-10-07 21:01:51 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsLocked);
|
|
|
|
|
|
|
|
if (mTexSource)
|
|
|
|
return;
|
|
|
|
|
2014-10-08 13:04:19 -07:00
|
|
|
mTexSource = SharedSurfaceToTexSource(mSurf, mCompositor);
|
2014-10-07 21:01:51 -07:00
|
|
|
MOZ_ASSERT(mTexSource);
|
|
|
|
}
|
|
|
|
|
2014-10-09 13:33:22 -07:00
|
|
|
bool
|
|
|
|
SharedSurfaceTextureHost::Lock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mIsLocked);
|
|
|
|
|
|
|
|
mSurf->ConsumerAcquire();
|
|
|
|
|
|
|
|
mIsLocked = true;
|
|
|
|
|
|
|
|
EnsureTexSource();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SharedSurfaceTextureHost::Unlock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsLocked);
|
|
|
|
mSurf->ConsumerRelease();
|
|
|
|
mIsLocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-07 21:01:51 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-06-18 17:04:06 -07: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 02:20:52 -07:00
|
|
|
} // namespace
|
|
|
|
} // namespace
|