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
|
|
|
/* -*- 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-19 04:04:06 +04:00
|
|
|
#include "TextureHost.h"
|
|
|
|
|
2013-09-13 06:39:26 +04:00
|
|
|
#include "CompositableHost.h" // for CompositableHost
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "LayersLogging.h" // for AppendToString
|
|
|
|
#include "gfx2DGlue.h" // for ToIntSize
|
|
|
|
#include "mozilla/gfx/2D.h" // for DataSourceSurface, Factory
|
|
|
|
#include "mozilla/ipc/Shmem.h" // for Shmem
|
2014-05-06 05:56:40 +04:00
|
|
|
#include "mozilla/layers/CompositableTransactionParent.h" // for CompositableParentManager
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/Compositor.h" // for Compositor
|
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator
|
2013-07-30 13:59:51 +04:00
|
|
|
#include "mozilla/layers/ImageDataSerializer.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
|
2014-03-27 05:01:15 +04:00
|
|
|
#include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL
|
2013-07-30 13:59:51 +04:00
|
|
|
#include "mozilla/layers/YCbCrImageDataSerializer.h"
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr
|
|
|
|
#include "nsPrintfCString.h" // for nsPrintfCString
|
2013-12-12 05:44:44 +04:00
|
|
|
#include "mozilla/layers/PTextureParent.h"
|
2014-03-10 22:34:57 +04:00
|
|
|
#include "mozilla/unused.h"
|
2014-02-21 01:04:11 +04:00
|
|
|
#include <limits>
|
2014-06-19 04:04:06 +04:00
|
|
|
#include "SharedSurface.h"
|
|
|
|
#include "SharedSurfaceEGL.h"
|
|
|
|
#include "SharedSurfaceGL.h"
|
|
|
|
#include "SurfaceStream.h"
|
|
|
|
#include "../opengl/CompositorOGL.h"
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#endif
|
2013-07-30 13:59:51 +04:00
|
|
|
|
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
|
|
|
|
|
2013-08-12 03:17:23 +04: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 13:20:52 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2013-12-12 05:44:44 +04: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-05-06 05:56:40 +04:00
|
|
|
TextureParent(CompositableParentManager* aManager);
|
2013-12-12 05:44:44 +04:00
|
|
|
|
|
|
|
~TextureParent();
|
|
|
|
|
2014-01-22 02:06:18 +04:00
|
|
|
bool Init(const SurfaceDescriptor& aSharedData,
|
|
|
|
const TextureFlags& aFlags);
|
2013-12-12 05:44:44 +04:00
|
|
|
|
2014-03-10 22:34:57 +04:00
|
|
|
void CompositorRecycle();
|
2014-05-12 18:39:25 +04:00
|
|
|
|
|
|
|
void SendFenceHandleIfPresent();
|
|
|
|
|
2014-03-10 22:34:57 +04:00
|
|
|
virtual bool RecvClientRecycle() MOZ_OVERRIDE;
|
|
|
|
|
2014-05-13 05:18:22 +04:00
|
|
|
virtual bool RecvClearTextureHostSync() MOZ_OVERRIDE;
|
2013-12-12 05:44:45 +04:00
|
|
|
|
2014-05-13 05:18:22 +04:00
|
|
|
virtual bool RecvRemoveTexture() MOZ_OVERRIDE;
|
2013-12-12 05:44:45 +04:00
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
TextureHost* GetTextureHost() { return mTextureHost; }
|
|
|
|
|
2013-12-12 05:45:07 +04:00
|
|
|
void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
|
2013-12-12 05:45:01 +04:00
|
|
|
|
2014-05-13 05:18:22 +04:00
|
|
|
void ClearTextureHost();
|
|
|
|
|
2014-05-06 05:56:40 +04:00
|
|
|
CompositableParentManager* mCompositableManager;
|
2014-03-10 22:34:57 +04:00
|
|
|
RefPtr<TextureHost> mWaitForClientRecycle;
|
2013-12-12 05:44:44 +04:00
|
|
|
RefPtr<TextureHost> mTextureHost;
|
|
|
|
};
|
|
|
|
|
|
|
|
// static
|
|
|
|
PTextureParent*
|
2014-05-06 05:56:40 +04:00
|
|
|
TextureHost::CreateIPDLActor(CompositableParentManager* aManager,
|
2014-01-22 02:06:18 +04:00
|
|
|
const SurfaceDescriptor& aSharedData,
|
|
|
|
TextureFlags aFlags)
|
2013-12-12 05:44:44 +04:00
|
|
|
{
|
2014-02-25 17:12:49 +04:00
|
|
|
if (aSharedData.type() == SurfaceDescriptor::TSurfaceDescriptorMemory &&
|
2014-05-06 05:56:40 +04:00
|
|
|
!aManager->IsSameProcess())
|
2014-02-25 17:12:49 +04:00
|
|
|
{
|
|
|
|
NS_ERROR("A client process is trying to peek at our address space using a MemoryTexture!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-05-06 05:56:40 +04:00
|
|
|
TextureParent* actor = new TextureParent(aManager);
|
2014-02-25 17:12:50 +04:00
|
|
|
if (!actor->Init(aSharedData, aFlags)) {
|
|
|
|
delete actor;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-01-22 02:06:18 +04:00
|
|
|
return actor;
|
2013-12-12 05:44:44 +04: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-25 08:23:41 +04:00
|
|
|
PTextureParent*
|
|
|
|
TextureHost::GetIPDLActor()
|
|
|
|
{
|
|
|
|
return mActor;
|
|
|
|
}
|
|
|
|
|
2014-05-12 18:39:25 +04:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
TextureHost::SendFenceHandleIfPresent(PTextureParent* actor)
|
|
|
|
{
|
|
|
|
TextureParent* parent = static_cast<TextureParent*>(actor);
|
|
|
|
parent->SendFenceHandleIfPresent();
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:14:45 +04: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-04 04:20:04 +04:00
|
|
|
// implemented in TextureHostOGL.cpp
|
2013-12-12 05:44:47 +04:00
|
|
|
TemporaryRef<TextureHost> CreateTextureHostOGL(const SurfaceDescriptor& aDesc,
|
2013-07-30 13:59:51 +04:00
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags);
|
|
|
|
|
2013-12-04 04:20:04 +04:00
|
|
|
// implemented in TextureHostBasic.cpp
|
2013-12-12 05:44:47 +04:00
|
|
|
TemporaryRef<TextureHost> CreateTextureHostBasic(const SurfaceDescriptor& aDesc,
|
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags);
|
2013-12-04 04:20:04 +04:00
|
|
|
|
2014-01-07 20:19:52 +04:00
|
|
|
// implemented in TextureD3D11.cpp
|
|
|
|
TemporaryRef<TextureHost> CreateTextureHostD3D11(const SurfaceDescriptor& aDesc,
|
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags);
|
|
|
|
|
2014-01-07 20:20:03 +04:00
|
|
|
// implemented in TextureD3D9.cpp
|
|
|
|
TemporaryRef<TextureHost> CreateTextureHostD3D9(const SurfaceDescriptor& aDesc,
|
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags);
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
// static
|
|
|
|
TemporaryRef<TextureHost>
|
2013-12-12 05:44:47 +04:00
|
|
|
TextureHost::Create(const SurfaceDescriptor& aDesc,
|
2013-07-30 13:59:51 +04:00
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags)
|
|
|
|
{
|
2014-02-05 17:34:16 +04:00
|
|
|
switch (aDesc.type()) {
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorShmem:
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMemory:
|
|
|
|
return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
|
2014-06-19 04:04:06 +04:00
|
|
|
|
2014-02-05 17:34:16 +04:00
|
|
|
case SurfaceDescriptor::TSharedTextureDescriptor:
|
|
|
|
case SurfaceDescriptor::TNewSurfaceDescriptorGralloc:
|
2014-06-05 05:27:22 +04:00
|
|
|
return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
|
2014-06-19 04:04:06 +04:00
|
|
|
|
|
|
|
case SurfaceDescriptor::TSurfaceStreamDescriptor:
|
|
|
|
return new StreamTextureHost(aFlags, aDesc.get_SurfaceStreamDescriptor());
|
|
|
|
|
2014-02-05 17:34:16 +04:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface:
|
|
|
|
if (Compositor::GetBackend() == LayersBackend::LAYERS_OPENGL) {
|
|
|
|
return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
|
|
|
|
} else {
|
|
|
|
return CreateTextureHostBasic(aDesc, aDeallocator, aFlags);
|
|
|
|
}
|
2014-06-19 04:04:06 +04:00
|
|
|
|
2014-02-05 20:39:02 +04:00
|
|
|
#ifdef MOZ_X11
|
2014-02-18 04:30:05 +04:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorX11: {
|
|
|
|
const SurfaceDescriptorX11& desc = aDesc.get_SurfaceDescriptorX11();
|
|
|
|
RefPtr<TextureHost> result = new X11TextureHost(aFlags, desc);
|
|
|
|
return result;
|
|
|
|
}
|
2014-02-05 20:39:02 +04:00
|
|
|
#endif
|
2014-06-19 04:04:06 +04:00
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
#ifdef XP_WIN
|
2014-02-05 17:34:16 +04:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorD3D9:
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorDIB:
|
2014-02-06 00:45:03 +04:00
|
|
|
return CreateTextureHostD3D9(aDesc, aDeallocator, aFlags);
|
2014-06-19 04:04:06 +04:00
|
|
|
|
2014-02-05 17:34:16 +04:00
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorD3D10:
|
2014-04-07 07:23:06 +04:00
|
|
|
if (Compositor::GetBackend() == LayersBackend::LAYERS_D3D9) {
|
|
|
|
return CreateTextureHostD3D9(aDesc, aDeallocator, aFlags);
|
|
|
|
} else {
|
|
|
|
return CreateTextureHostD3D11(aDesc, aDeallocator, aFlags);
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
#endif
|
|
|
|
default:
|
2014-02-05 17:34:16 +04:00
|
|
|
MOZ_CRASH("Unsupported Surface type");
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryRef<TextureHost>
|
2013-12-12 05:44:47 +04:00
|
|
|
CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
|
2013-07-30 13:59:51 +04:00
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags)
|
|
|
|
{
|
|
|
|
RefPtr<TextureHost> result;
|
|
|
|
switch (aDesc.type()) {
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorShmem: {
|
|
|
|
const SurfaceDescriptorShmem& descriptor = aDesc.get_SurfaceDescriptorShmem();
|
2013-12-12 05:44:47 +04:00
|
|
|
result = new ShmemTextureHost(descriptor.data(),
|
2013-07-30 13:59:51 +04:00
|
|
|
descriptor.format(),
|
|
|
|
aDeallocator,
|
|
|
|
aFlags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SurfaceDescriptor::TSurfaceDescriptorMemory: {
|
|
|
|
const SurfaceDescriptorMemory& descriptor = aDesc.get_SurfaceDescriptorMemory();
|
2013-12-12 05:44:47 +04:00
|
|
|
result = new MemoryTextureHost(reinterpret_cast<uint8_t*>(descriptor.data()),
|
2013-07-30 13:59:51 +04:00
|
|
|
descriptor.format(),
|
|
|
|
aFlags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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 13:20:52 +04:00
|
|
|
|
2014-03-27 05:01:15 +04:00
|
|
|
void
|
|
|
|
TextureHost::CompositorRecycle()
|
|
|
|
{
|
|
|
|
if (!mActor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
static_cast<TextureParent*>(mActor)->CompositorRecycle();
|
|
|
|
}
|
|
|
|
|
2013-09-30 16:14:38 +04:00
|
|
|
void
|
|
|
|
TextureHost::SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData)
|
2013-09-13 06:39:26 +04:00
|
|
|
{
|
2013-09-30 16:14:38 +04:00
|
|
|
mCompositableBackendData = aBackendData;
|
2013-09-13 06:39:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-12 05:44:47 +04:00
|
|
|
TextureHost::TextureHost(TextureFlags aFlags)
|
2014-02-25 08:23:41 +04:00
|
|
|
: mActor(nullptr)
|
|
|
|
, mFlags(aFlags)
|
2013-09-13 06:39:26 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
TextureHost::~TextureHost()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:45:01 +04:00
|
|
|
void TextureHost::Finalize()
|
|
|
|
{
|
2014-04-26 06:34:05 +04:00
|
|
|
if (!(GetFlags() & TextureFlags::DEALLOCATE_CLIENT)) {
|
2013-12-12 05:45:01 +04:00
|
|
|
DeallocateSharedData();
|
|
|
|
DeallocateDeviceData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-23 15:28:40 +04:00
|
|
|
void
|
2014-06-20 02:36:25 +04:00
|
|
|
TextureHost::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
2013-09-23 15:28:40 +04:00
|
|
|
{
|
2014-06-20 02:36:25 +04:00
|
|
|
aStream << aPrefix;
|
|
|
|
aStream << nsPrintfCString("%s (0x%p)", Name(), this).get();
|
2014-01-22 01:27:01 +04:00
|
|
|
// Note: the TextureHost needs to be locked before it is safe to call
|
|
|
|
// GetSize() and GetFormat() on it.
|
|
|
|
if (Lock()) {
|
2014-06-20 02:36:25 +04:00
|
|
|
AppendToString(aStream, GetSize(), " [size=", "]");
|
|
|
|
AppendToString(aStream, GetFormat(), " [format=", "]");
|
2014-01-22 01:27:01 +04:00
|
|
|
Unlock();
|
|
|
|
}
|
2014-06-20 02:36:25 +04:00
|
|
|
AppendToString(aStream, mFlags, " [flags=", "]");
|
2013-09-23 15:28:40 +04:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:14:38 +04:00
|
|
|
void
|
|
|
|
TextureSource::SetCompositableBackendSpecificData(CompositableBackendSpecificData* aBackendData)
|
2013-09-13 06:39:26 +04:00
|
|
|
{
|
2013-09-30 16:14:38 +04:00
|
|
|
mCompositableBackendData = aBackendData;
|
2013-09-13 06:39:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TextureSource::TextureSource()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(TextureSource);
|
|
|
|
}
|
|
|
|
TextureSource::~TextureSource()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(TextureSource);
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:47 +04:00
|
|
|
BufferTextureHost::BufferTextureHost(gfx::SurfaceFormat aFormat,
|
2013-07-30 13:59:51 +04:00
|
|
|
TextureFlags aFlags)
|
2013-12-12 05:44:47 +04:00
|
|
|
: TextureHost(aFlags)
|
2013-07-30 13:59:51 +04:00
|
|
|
, mCompositor(nullptr)
|
|
|
|
, mFormat(aFormat)
|
|
|
|
, mUpdateSerial(1)
|
|
|
|
, mLocked(false)
|
|
|
|
, mPartialUpdate(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
BufferTextureHost::~BufferTextureHost()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferTextureHost::Updated(const nsIntRegion* aRegion)
|
|
|
|
{
|
|
|
|
++mUpdateSerial;
|
|
|
|
if (aRegion) {
|
|
|
|
mPartialUpdate = true;
|
|
|
|
mMaybeUpdatedRegion = *aRegion;
|
|
|
|
} else {
|
|
|
|
mPartialUpdate = false;
|
|
|
|
}
|
2014-04-26 06:34:05 +04:00
|
|
|
if (GetFlags() & TextureFlags::IMMEDIATE_UPLOAD) {
|
2013-08-20 03:39:56 +04:00
|
|
|
DebugOnly<bool> result = MaybeUpload(mPartialUpdate ? &mMaybeUpdatedRegion : nullptr);
|
2014-01-07 20:20:11 +04:00
|
|
|
NS_WARN_IF_FALSE(result, "Failed to upload a texture");
|
2013-08-03 21:30:28 +04:00
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferTextureHost::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
|
|
|
if (mCompositor == aCompositor) {
|
|
|
|
return;
|
|
|
|
}
|
2014-01-07 20:20:11 +04:00
|
|
|
RefPtr<NewTextureSource> it = mFirstSource;
|
|
|
|
while (it) {
|
|
|
|
it->SetCompositor(aCompositor);
|
|
|
|
it = it->GetNextSibling();
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
mCompositor = aCompositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferTextureHost::DeallocateDeviceData()
|
|
|
|
{
|
|
|
|
RefPtr<NewTextureSource> it = mFirstSource;
|
|
|
|
while (it) {
|
|
|
|
it->DeallocateDeviceData();
|
|
|
|
it = it->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BufferTextureHost::Lock()
|
|
|
|
{
|
|
|
|
mLocked = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferTextureHost::Unlock()
|
|
|
|
{
|
|
|
|
mLocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NewTextureSource*
|
|
|
|
BufferTextureHost::GetTextureSources()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mLocked, "should never be called while not locked");
|
2013-08-03 21:30:28 +04:00
|
|
|
if (!MaybeUpload(mPartialUpdate ? &mMaybeUpdatedRegion : nullptr)) {
|
2013-07-30 13:59:51 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mFirstSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 23:06:16 +04:00
|
|
|
if (mFormat == gfx::SurfaceFormat::YUV &&
|
2013-07-30 13:59:51 +04:00
|
|
|
mCompositor &&
|
2014-04-26 06:34:06 +04:00
|
|
|
!mCompositor->SupportsEffect(EffectTypes::YCBCR)) {
|
2014-01-10 23:06:16 +04:00
|
|
|
return gfx::SurfaceFormat::R8G8B8X8;
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
return mFormat;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-08-03 21:30:28 +04:00
|
|
|
BufferTextureHost::MaybeUpload(nsIntRegion *aRegion)
|
|
|
|
{
|
|
|
|
if (mFirstSource && mFirstSource->GetUpdateSerial() == mUpdateSerial) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!Upload(aRegion)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mFirstSource->SetUpdateSerial(mUpdateSerial);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-30 13:59:51 +04:00
|
|
|
BufferTextureHost::Upload(nsIntRegion *aRegion)
|
|
|
|
{
|
2013-12-12 05:44:59 +04: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-12 05:44:41 +04:00
|
|
|
if (!mCompositor) {
|
|
|
|
NS_WARNING("Tried to upload without a compositor. Skipping texture upload...");
|
|
|
|
// If we are in this situation it means we should have called SetCompositor
|
|
|
|
// earlier. It is conceivable that on certain rare conditions with async-video
|
|
|
|
// we may end up here for the first frame, but this should not happen repeatedly.
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-10 23:06:16 +04:00
|
|
|
if (mFormat == gfx::SurfaceFormat::UNKNOWN) {
|
2013-07-30 13:59:51 +04:00
|
|
|
NS_WARNING("BufferTextureHost: unsupported format!");
|
|
|
|
return false;
|
2014-01-10 23:06:16 +04:00
|
|
|
} else if (mFormat == gfx::SurfaceFormat::YUV) {
|
2014-02-21 01:04:13 +04:00
|
|
|
YCbCrImageDataDeserializer yuvDeserializer(GetBuffer(), GetBufferSize());
|
2013-07-30 13:59:51 +04:00
|
|
|
MOZ_ASSERT(yuvDeserializer.IsValid());
|
|
|
|
|
2014-04-26 06:34:06 +04:00
|
|
|
if (!mCompositor->SupportsEffect(EffectTypes::YCBCR)) {
|
2013-07-30 13:59:51 +04:00
|
|
|
RefPtr<gfx::DataSourceSurface> surf = yuvDeserializer.ToDataSourceSurface();
|
|
|
|
if (!mFirstSource) {
|
|
|
|
mFirstSource = mCompositor->CreateDataTextureSource(mFlags);
|
|
|
|
}
|
2014-01-07 20:20:11 +04:00
|
|
|
mFirstSource->Update(surf, aRegion);
|
2013-07-30 13:59:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<DataTextureSource> srcY;
|
|
|
|
RefPtr<DataTextureSource> srcU;
|
|
|
|
RefPtr<DataTextureSource> srcV;
|
|
|
|
if (!mFirstSource) {
|
2013-08-02 03:02:06 +04:00
|
|
|
// We don't support BigImages for YCbCr compositing.
|
2014-04-26 06:34:05 +04: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 13:59:51 +04: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 20:46:30 +04:00
|
|
|
yuvDeserializer.GetYSize(),
|
2014-01-10 23:06:16 +04:00
|
|
|
gfx::SurfaceFormat::A8);
|
2013-07-30 13:59:51 +04:00
|
|
|
RefPtr<gfx::DataSourceSurface> tempCb =
|
|
|
|
gfx::Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetCbData(),
|
|
|
|
yuvDeserializer.GetCbCrStride(),
|
2013-12-20 20:46:30 +04:00
|
|
|
yuvDeserializer.GetCbCrSize(),
|
2014-01-10 23:06:16 +04:00
|
|
|
gfx::SurfaceFormat::A8);
|
2013-07-30 13:59:51 +04:00
|
|
|
RefPtr<gfx::DataSourceSurface> tempCr =
|
|
|
|
gfx::Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetCrData(),
|
|
|
|
yuvDeserializer.GetCbCrStride(),
|
2013-12-20 20:46:30 +04:00
|
|
|
yuvDeserializer.GetCbCrSize(),
|
2014-01-10 23:06:16 +04:00
|
|
|
gfx::SurfaceFormat::A8);
|
2013-07-30 13:59:51 +04:00
|
|
|
// We don't support partial updates for Y U V textures
|
|
|
|
NS_ASSERTION(!aRegion, "Unsupported partial updates for YCbCr textures");
|
2014-01-07 20:20:11 +04:00
|
|
|
if (!srcY->Update(tempY) ||
|
|
|
|
!srcU->Update(tempCb) ||
|
|
|
|
!srcV->Update(tempCr)) {
|
2013-07-30 13:59:51 +04:00
|
|
|
NS_WARNING("failed to update the DataTextureSource");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// non-YCbCr case
|
|
|
|
if (!mFirstSource) {
|
|
|
|
mFirstSource = mCompositor->CreateDataTextureSource();
|
|
|
|
}
|
2014-02-21 01:04:11 +04:00
|
|
|
ImageDataDeserializer deserializer(GetBuffer(), GetBufferSize());
|
2013-07-30 13:59:51 +04:00
|
|
|
if (!deserializer.IsValid()) {
|
2014-02-21 01:04:11 +04:00
|
|
|
NS_ERROR("Failed to deserialize image!");
|
2013-07-30 13:59:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<gfx::DataSourceSurface> surf = deserializer.GetAsSurface();
|
2013-08-20 03:39:55 +04:00
|
|
|
if (!surf) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
|
2014-01-07 20:20:11 +04:00
|
|
|
if (!mFirstSource->Update(surf.get(), aRegion)) {
|
2013-07-30 13:59:51 +04:00
|
|
|
NS_WARNING("failed to update the DataTextureSource");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-27 13:59:01 +04:00
|
|
|
TemporaryRef<gfx::DataSourceSurface>
|
2013-07-30 13:59:51 +04:00
|
|
|
BufferTextureHost::GetAsSurface()
|
|
|
|
{
|
2013-11-27 13:59:01 +04:00
|
|
|
RefPtr<gfx::DataSourceSurface> result;
|
2014-01-10 23:06:16 +04:00
|
|
|
if (mFormat == gfx::SurfaceFormat::UNKNOWN) {
|
2013-07-30 13:59:51 +04:00
|
|
|
NS_WARNING("BufferTextureHost: unsupported format!");
|
|
|
|
return nullptr;
|
2014-01-10 23:06:16 +04:00
|
|
|
} else if (mFormat == gfx::SurfaceFormat::YUV) {
|
2014-02-21 01:04:13 +04:00
|
|
|
YCbCrImageDataDeserializer yuvDeserializer(GetBuffer(), GetBufferSize());
|
2013-07-30 13:59:51 +04:00
|
|
|
if (!yuvDeserializer.IsValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-27 13:59:01 +04:00
|
|
|
result = yuvDeserializer.ToDataSourceSurface();
|
2013-07-30 13:59:51 +04:00
|
|
|
} else {
|
2014-02-21 01:04:11 +04:00
|
|
|
ImageDataDeserializer deserializer(GetBuffer(), GetBufferSize());
|
2013-07-30 13:59:51 +04:00
|
|
|
if (!deserializer.IsValid()) {
|
2014-02-21 01:04:11 +04:00
|
|
|
NS_ERROR("Failed to deserialize image!");
|
2013-07-30 13:59:51 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-27 13:59:01 +04:00
|
|
|
result = deserializer.GetAsSurface();
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:47 +04:00
|
|
|
ShmemTextureHost::ShmemTextureHost(const ipc::Shmem& aShmem,
|
2013-07-30 13:59:51 +04:00
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
ISurfaceAllocator* aDeallocator,
|
|
|
|
TextureFlags aFlags)
|
2013-12-12 05:44:47 +04:00
|
|
|
: BufferTextureHost(aFormat, aFlags)
|
2013-07-30 13:59:51 +04:00
|
|
|
, mShmem(new ipc::Shmem(aShmem))
|
|
|
|
, mDeallocator(aDeallocator)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ShmemTextureHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShmemTextureHost::~ShmemTextureHost()
|
|
|
|
{
|
|
|
|
DeallocateDeviceData();
|
|
|
|
delete mShmem;
|
|
|
|
MOZ_COUNT_DTOR(ShmemTextureHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShmemTextureHost::DeallocateSharedData()
|
|
|
|
{
|
|
|
|
if (mShmem) {
|
|
|
|
MOZ_ASSERT(mDeallocator,
|
|
|
|
"Shared memory would leak without a ISurfaceAllocator");
|
|
|
|
mDeallocator->DeallocShmem(*mShmem);
|
2013-12-12 05:44:45 +04:00
|
|
|
delete mShmem;
|
|
|
|
mShmem = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShmemTextureHost::ForgetSharedData()
|
|
|
|
{
|
|
|
|
if (mShmem) {
|
|
|
|
delete mShmem;
|
2013-12-11 22:05:11 +04:00
|
|
|
mShmem = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-12-12 05:45:01 +04:00
|
|
|
ShmemTextureHost::OnShutdown()
|
2013-09-27 13:48:42 +04:00
|
|
|
{
|
|
|
|
delete mShmem;
|
|
|
|
mShmem = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
uint8_t* ShmemTextureHost::GetBuffer()
|
|
|
|
{
|
|
|
|
return mShmem ? mShmem->get<uint8_t>() : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-02-21 01:04:11 +04:00
|
|
|
size_t ShmemTextureHost::GetBufferSize()
|
|
|
|
{
|
|
|
|
return mShmem ? mShmem->Size<uint8_t>() : 0;
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:47 +04:00
|
|
|
MemoryTextureHost::MemoryTextureHost(uint8_t* aBuffer,
|
2013-07-30 13:59:51 +04:00
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
TextureFlags aFlags)
|
2013-12-12 05:44:47 +04:00
|
|
|
: BufferTextureHost(aFormat, aFlags)
|
2013-07-30 13:59:51 +04:00
|
|
|
, mBuffer(aBuffer)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(MemoryTextureHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryTextureHost::~MemoryTextureHost()
|
|
|
|
{
|
|
|
|
DeallocateDeviceData();
|
2014-04-26 06:34:05 +04:00
|
|
|
NS_ASSERTION(!mBuffer || (mFlags & TextureFlags::DEALLOCATE_CLIENT),
|
2013-12-05 07:03:29 +04:00
|
|
|
"Leaking our buffer");
|
2013-08-02 05:12:16 +04:00
|
|
|
MOZ_COUNT_DTOR(MemoryTextureHost);
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MemoryTextureHost::DeallocateSharedData()
|
|
|
|
{
|
2013-11-15 01:54:25 +04:00
|
|
|
if (mBuffer) {
|
|
|
|
GfxMemoryImageReporter::WillFree(mBuffer);
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
delete[] mBuffer;
|
2013-12-05 22:39:22 +04:00
|
|
|
mBuffer = nullptr;
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
void
|
|
|
|
MemoryTextureHost::ForgetSharedData()
|
|
|
|
{
|
|
|
|
mBuffer = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
uint8_t* MemoryTextureHost::GetBuffer()
|
|
|
|
{
|
|
|
|
return mBuffer;
|
|
|
|
}
|
|
|
|
|
2014-02-21 01:04:11 +04: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-06 05:56:40 +04:00
|
|
|
TextureParent::TextureParent(CompositableParentManager* aCompositableManager)
|
|
|
|
: mCompositableManager(aCompositableManager)
|
2013-12-12 05:44:44 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(TextureParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureParent::~TextureParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(TextureParent);
|
2014-03-10 22:34:57 +04: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 18:39:25 +04:00
|
|
|
SendFenceHandleIfPresent();
|
|
|
|
|
|
|
|
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-27 05:01:15 +04:00
|
|
|
|
2014-05-12 18:39:25 +04:00
|
|
|
void
|
|
|
|
TextureParent::SendFenceHandleIfPresent()
|
|
|
|
{
|
2014-03-27 05:01:15 +04:00
|
|
|
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
|
|
|
|
if (mTextureHost) {
|
|
|
|
TextureHostOGL* hostOGL = mTextureHost->AsHostOGL();
|
2014-05-26 21:09:25 +04:00
|
|
|
if (!hostOGL) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-27 05:01:15 +04:00
|
|
|
android::sp<android::Fence> fence = hostOGL->GetAndResetReleaseFence();
|
|
|
|
if (fence.get() && fence->isValid()) {
|
|
|
|
// HWC might not provide Fence.
|
|
|
|
// In this case, HWC implicitly handles buffer's fence.
|
2014-05-06 05:56:40 +04:00
|
|
|
|
|
|
|
FenceHandle handle = FenceHandle(fence);
|
2014-05-24 20:14:45 +04:00
|
|
|
RefPtr<FenceDeliveryTracker> tracker = new FenceDeliveryTracker(handle);
|
2014-05-06 05:56:40 +04:00
|
|
|
mCompositableManager->SendFenceHandle(tracker, this, handle);
|
2014-03-27 05:01:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-03-10 22:34:57 +04: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-12 05:44:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-01-22 02:06:18 +04:00
|
|
|
TextureParent::Init(const SurfaceDescriptor& aSharedData,
|
|
|
|
const TextureFlags& aFlags)
|
2013-12-12 05:44:44 +04:00
|
|
|
{
|
2013-12-12 05:44:47 +04:00
|
|
|
mTextureHost = TextureHost::Create(aSharedData,
|
2014-05-06 05:56:40 +04:00
|
|
|
mCompositableManager,
|
2013-12-12 05:44:44 +04:00
|
|
|
aFlags);
|
2014-03-10 22:34:57 +04:00
|
|
|
if (mTextureHost) {
|
|
|
|
mTextureHost->mActor = this;
|
2014-04-26 06:34:05 +04:00
|
|
|
if (aFlags & TextureFlags::RECYCLE) {
|
2014-03-10 22:34:57 +04:00
|
|
|
mWaitForClientRecycle = mTextureHost;
|
|
|
|
RECYCLE_LOG("Setup recycling for tile %p\n", this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
return !!mTextureHost;
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
bool
|
|
|
|
TextureParent::RecvRemoveTexture()
|
|
|
|
{
|
|
|
|
return PTextureParent::Send__delete__(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-05-13 05:18:22 +04:00
|
|
|
TextureParent::RecvClearTextureHostSync()
|
2013-12-12 05:44:45 +04:00
|
|
|
{
|
2014-05-13 05:18:22 +04:00
|
|
|
ClearTextureHost();
|
|
|
|
return true;
|
2013-12-12 05:44:45 +04: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 19:26:59 +04:00
|
|
|
|
2014-05-13 05:18:22 +04:00
|
|
|
ClearTextureHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextureParent::ClearTextureHost()
|
|
|
|
{
|
|
|
|
if (!mTextureHost) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-26 06:34:05 +04:00
|
|
|
if (mTextureHost->GetFlags() & TextureFlags::RECYCLE) {
|
2014-03-10 22:34:57 +04:00
|
|
|
RECYCLE_LOG("clear recycling for tile %p\n", this);
|
|
|
|
mTextureHost->ClearRecycleCallback();
|
|
|
|
}
|
2014-04-26 06:34:05 +04:00
|
|
|
if (mTextureHost->GetFlags() & TextureFlags::DEALLOCATE_CLIENT) {
|
2014-01-23 19:26:59 +04:00
|
|
|
mTextureHost->ForgetSharedData();
|
|
|
|
}
|
2014-02-25 08:23:41 +04:00
|
|
|
|
2014-04-01 07:24:55 +04:00
|
|
|
// Clear recycle callback.
|
|
|
|
mTextureHost->ClearRecycleCallback();
|
|
|
|
mWaitForClientRecycle = nullptr;
|
|
|
|
|
2014-02-25 08:23:41 +04:00
|
|
|
mTextureHost->mActor = nullptr;
|
2013-12-12 05:44:45 +04:00
|
|
|
mTextureHost = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-19 04:04:06 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// StreamTextureHost
|
|
|
|
|
|
|
|
StreamTextureHost::StreamTextureHost(TextureFlags aFlags,
|
|
|
|
const SurfaceStreamDescriptor& aDesc)
|
|
|
|
: TextureHost(aFlags)
|
|
|
|
{
|
|
|
|
mStream = gfx::SurfaceStream::FromHandle(aDesc.handle());
|
|
|
|
MOZ_ASSERT(mStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamTextureHost::~StreamTextureHost()
|
|
|
|
{
|
|
|
|
// If need to deallocate textures, call DeallocateSharedData() before
|
|
|
|
// the destructor
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
StreamTextureHost::Lock()
|
|
|
|
{
|
|
|
|
if (!mCompositor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SharedSurface* abstractSurf = mStream->SwapConsumer();
|
|
|
|
|
|
|
|
bool compositorSupportsShSurfType = false;
|
|
|
|
switch (mCompositor->GetBackendType()) {
|
|
|
|
case LayersBackend::LAYERS_BASIC:
|
|
|
|
case LayersBackend::LAYERS_D3D9:
|
|
|
|
case LayersBackend::LAYERS_D3D10:
|
|
|
|
switch (abstractSurf->Type()) {
|
|
|
|
case gfx::SharedSurfaceType::Basic:
|
|
|
|
compositorSupportsShSurfType = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LayersBackend::LAYERS_OPENGL:
|
|
|
|
switch (abstractSurf->Type()) {
|
|
|
|
case gfx::SharedSurfaceType::Basic:
|
|
|
|
case gfx::SharedSurfaceType::GLTextureShare:
|
|
|
|
case gfx::SharedSurfaceType::EGLImageShare:
|
|
|
|
case gfx::SharedSurfaceType::Gralloc:
|
|
|
|
case gfx::SharedSurfaceType::IOSurface:
|
|
|
|
compositorSupportsShSurfType = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LayersBackend::LAYERS_D3D11:
|
|
|
|
switch (abstractSurf->Type()) {
|
|
|
|
case gfx::SharedSurfaceType::Basic:
|
|
|
|
case gfx::SharedSurfaceType::EGLSurfaceANGLE:
|
|
|
|
compositorSupportsShSurfType = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<NewTextureSource> newTexSource;
|
|
|
|
if (compositorSupportsShSurfType) {
|
|
|
|
gfx::SurfaceFormat format = abstractSurf->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8
|
|
|
|
: gfx::SurfaceFormat::R8G8B8X8;
|
|
|
|
|
|
|
|
switch (abstractSurf->Type()) {
|
|
|
|
case gfx::SharedSurfaceType::Basic: {
|
|
|
|
gl::SharedSurface_Basic* surf = gl::SharedSurface_Basic::Cast(abstractSurf);
|
|
|
|
|
|
|
|
if (!this->mDataTextureSource) {
|
|
|
|
TextureFlags flags = TextureFlags::DEALLOCATE_CLIENT;
|
|
|
|
this->mDataTextureSource = mCompositor->CreateDataTextureSource(flags);
|
|
|
|
}
|
|
|
|
this->mDataTextureSource->Update(surf->GetData());
|
|
|
|
|
|
|
|
newTexSource = mDataTextureSource;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gfx::SharedSurfaceType::GLTextureShare: {
|
|
|
|
gl::SharedSurface_GLTexture* surf = gl::SharedSurface_GLTexture::Cast(abstractSurf);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
|
|
|
|
CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(mCompositor);
|
|
|
|
gl::GLContext* gl = compositorOGL->gl();
|
|
|
|
|
|
|
|
GLenum target = surf->ConsTextureTarget();
|
|
|
|
GLuint tex = surf->ConsTexture(gl);
|
|
|
|
newTexSource = new GLTextureSource(compositorOGL,
|
|
|
|
tex,
|
|
|
|
format,
|
|
|
|
target,
|
|
|
|
surf->Size());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef MOZ_ENABLE_D3D10_LAYER
|
|
|
|
case gfx::SharedSurfaceType::EGLSurfaceANGLE: {
|
|
|
|
gl::SharedSurface_ANGLEShareHandle* surf = gl::SharedSurface_ANGLEShareHandle::Cast(abstractSurf);
|
|
|
|
HANDLE shareHandle = surf->GetShareHandle();
|
|
|
|
|
|
|
|
MOZ_ASSERT(mCompositor->GetBackendType() == LayersBackend::LAYERS_D3D11);
|
|
|
|
CompositorD3D11* compositorD3D11 = static_cast<CompositorD3D11*>(mCompositor);
|
|
|
|
ID3D11Device* d3d = compositorD3D11->GetDevice();
|
|
|
|
|
|
|
|
nsRefPtr<ID3D11Texture2D> tex;
|
|
|
|
HRESULT hr = d3d->OpenSharedResource(shareHandle,
|
|
|
|
__uuidof(ID3D11Texture2D),
|
|
|
|
getter_AddRefs(tex));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to open shared resource.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
newTexSource = new DataTextureSourceD3D11(format, compositorD3D11, tex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case gfx::SharedSurfaceType::EGLImageShare: {
|
|
|
|
gl::SharedSurface_EGLImage* surf = gl::SharedSurface_EGLImage::Cast(abstractSurf);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
|
|
|
|
CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(mCompositor);
|
|
|
|
gl::GLContext* gl = compositorOGL->gl();
|
|
|
|
MOZ_ASSERT(gl->IsCurrent());
|
|
|
|
|
|
|
|
GLenum target = 0;
|
|
|
|
GLuint tex = 0;
|
|
|
|
surf->AcquireConsumerTexture(gl, &tex, &target);
|
|
|
|
|
|
|
|
newTexSource = new GLTextureSource(compositorOGL,
|
|
|
|
tex,
|
|
|
|
format,
|
|
|
|
target,
|
|
|
|
surf->Size());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gfx::SharedSurfaceType::Gralloc: {
|
2014-06-19 04:04:06 +04:00
|
|
|
MOZ_ASSERT(false, "WebGL in the Host process? Gralloc without E10S? Not yet supported.");
|
2014-06-19 04:04:06 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case gfx::SharedSurfaceType::IOSurface: {
|
|
|
|
gl::SharedSurface_IOSurface* surf = gl::SharedSurface_IOSurface::Cast(abstractSurf);
|
|
|
|
MacIOSurface* ioSurf = surf->GetIOSurface();
|
|
|
|
|
|
|
|
MOZ_ASSERT(mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL);
|
|
|
|
CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(mCompositor);
|
|
|
|
|
|
|
|
newTexSource = new MacIOSurfaceTextureSourceOGL(compositorOGL,
|
|
|
|
ioSurf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Do readback, and make a buffer view for it?
|
|
|
|
NS_WARNING("`!compositorSupportsShSurfType`.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(newTexSource.get(), "TextureSource creation failed.");
|
|
|
|
if (!newTexSource)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
mTextureSource = newTexSource;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StreamTextureHost::Unlock()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StreamTextureHost::SetCompositor(Compositor* aCompositor)
|
|
|
|
{
|
|
|
|
mCompositor = aCompositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::SurfaceFormat
|
|
|
|
StreamTextureHost::GetFormat() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTextureSource);
|
|
|
|
return mTextureSource->GetFormat();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::IntSize
|
|
|
|
StreamTextureHost::GetSize() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mTextureSource);
|
|
|
|
return mTextureSource->GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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
|
|
|
|
} // namespace
|