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/. */
|
|
|
|
|
|
|
|
#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
|
|
|
|
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
|
|
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
|
|
|
#include "mozilla/layers/ISurfaceAllocator.h"
|
|
|
|
#include "mozilla/layers/ImageDataSerializer.h"
|
2013-05-23 11:17:10 +04:00
|
|
|
#include "mozilla/layers/YCbCrImageDataSerializer.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-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-06-19 04:04:06 +04:00
|
|
|
#include "SurfaceStream.h"
|
|
|
|
#include "GLContext.h"
|
2014-03-08 01:34:04 +04:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "mozilla/layers/TextureD3D9.h"
|
|
|
|
#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"
|
|
|
|
#ifdef GL_PROVIDER_GLX
|
|
|
|
#include "GLXLibrary.h"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include <cutils/properties.h>
|
|
|
|
#include "mozilla/layers/GrallocTextureClient.h"
|
|
|
|
#endif
|
2013-08-12 06:21:17 +04:00
|
|
|
|
2014-08-22 23:26:56 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2013-08-19 17:59:27 +04:00
|
|
|
# include "gfxReusableImageSurfaceWrapper.h"
|
|
|
|
#else
|
|
|
|
# include "gfxReusableSharedImageSurfaceWrapper.h"
|
|
|
|
# include "gfxSharedImageSurface.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;
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-04-14 23:04:25 +04:00
|
|
|
class TextureChild MOZ_FINAL : public PTextureChild
|
2013-12-12 05:44:44 +04:00
|
|
|
{
|
2014-06-19 06:28:59 +04:00
|
|
|
~TextureChild() {}
|
2013-12-12 05:44:44 +04:00
|
|
|
public:
|
2014-04-14 23:04:25 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureChild)
|
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
TextureChild()
|
|
|
|
: mForwarder(nullptr)
|
2013-12-12 05:44:55 +04:00
|
|
|
, mTextureClient(nullptr)
|
2014-07-22 19:49:05 +04:00
|
|
|
, mKeep(nullptr)
|
2013-12-21 01:44:30 +04:00
|
|
|
, mIPCOpen(false)
|
2013-12-12 05:44:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Recv__delete__() MOZ_OVERRIDE;
|
|
|
|
|
2014-05-06 05:56:40 +04:00
|
|
|
bool RecvCompositorRecycle()
|
2014-03-10 22:34:57 +04:00
|
|
|
{
|
|
|
|
RECYCLE_LOG("Receive recycle %p (%p)\n", mTextureClient, mWaitForRecycle.get());
|
|
|
|
mWaitForRecycle = nullptr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WaitForCompositorRecycle()
|
|
|
|
{
|
|
|
|
mWaitForRecycle = mTextureClient;
|
|
|
|
RECYCLE_LOG("Wait for recycle %p\n", mWaitForRecycle.get());
|
|
|
|
SendClientRecycle();
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
CompositableForwarder* GetForwarder() { return mForwarder; }
|
|
|
|
|
|
|
|
ISurfaceAllocator* GetAllocator() { return mForwarder; }
|
|
|
|
|
2013-12-12 05:44:55 +04:00
|
|
|
void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
|
|
|
|
|
2013-12-21 01:44:30 +04:00
|
|
|
bool IPCOpen() const { return mIPCOpen; }
|
|
|
|
|
2013-12-12 05:44:55 +04:00
|
|
|
private:
|
|
|
|
|
2013-12-21 01:44:30 +04:00
|
|
|
// 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() {
|
|
|
|
MOZ_ASSERT(mIPCOpen == true);
|
|
|
|
mIPCOpen = false;
|
|
|
|
Release();
|
|
|
|
}
|
|
|
|
|
2014-02-27 01:23:51 +04:00
|
|
|
RefPtr<CompositableForwarder> mForwarder;
|
2014-03-10 22:34:57 +04:00
|
|
|
RefPtr<TextureClient> mWaitForRecycle;
|
2013-12-12 05:44:55 +04:00
|
|
|
TextureClient* mTextureClient;
|
2014-07-22 19:49:05 +04:00
|
|
|
KeepAlive* mKeep;
|
2013-12-21 01:44:30 +04:00
|
|
|
bool mIPCOpen;
|
2013-12-12 05:44:44 +04:00
|
|
|
|
2013-12-12 05:44:55 +04:00
|
|
|
friend class TextureClient;
|
2013-12-12 05:44:44 +04:00
|
|
|
};
|
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
bool
|
|
|
|
TextureChild::Recv__delete__()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:55 +04:00
|
|
|
void
|
|
|
|
TextureChild::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
if (mTextureClient) {
|
|
|
|
mTextureClient->mActor = nullptr;
|
|
|
|
}
|
2014-03-10 22:34:57 +04:00
|
|
|
mWaitForRecycle = nullptr;
|
2014-07-22 19:49:05 +04:00
|
|
|
delete mKeep;
|
2013-12-12 05:44:55 +04:00
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
// static
|
|
|
|
PTextureChild*
|
|
|
|
TextureClient::CreateIPDLActor()
|
|
|
|
{
|
2013-12-21 01:44:30 +04:00
|
|
|
TextureChild* c = new TextureChild();
|
|
|
|
c->AddIPDLReference();
|
|
|
|
return c;
|
2013-12-12 05:44:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
TextureClient::DestroyIPDLActor(PTextureChild* actor)
|
|
|
|
{
|
2013-12-21 01:44:30 +04:00
|
|
|
static_cast<TextureChild*>(actor)->ReleaseIPDLReference();
|
2013-12-12 05:44:44 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-25 08:23:41 +04:00
|
|
|
// static
|
|
|
|
TextureClient*
|
|
|
|
TextureClient::AsTextureClient(PTextureChild* actor)
|
|
|
|
{
|
2014-03-10 22:34:57 +04:00
|
|
|
return actor ? static_cast<TextureChild*>(actor)->mTextureClient : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextureClient::WaitForCompositorRecycle()
|
|
|
|
{
|
|
|
|
mActor->WaitForCompositorRecycle();
|
2014-02-25 08:23:41 +04:00
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:44 +04:00
|
|
|
bool
|
|
|
|
TextureClient::InitIPDLActor(CompositableForwarder* aForwarder)
|
|
|
|
{
|
2013-12-12 05:44:53 +04:00
|
|
|
MOZ_ASSERT(aForwarder);
|
2014-02-10 06:24:27 +04:00
|
|
|
if (mActor && mActor->GetForwarder() == aForwarder) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(!mActor, "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;
|
|
|
|
}
|
|
|
|
|
2014-01-22 02:06:18 +04:00
|
|
|
mActor = static_cast<TextureChild*>(aForwarder->CreateTexture(desc, GetFlags()));
|
|
|
|
MOZ_ASSERT(mActor);
|
2013-12-12 05:44:45 +04:00
|
|
|
mActor->mForwarder = aForwarder;
|
2013-12-12 05:44:55 +04:00
|
|
|
mActor->mTextureClient = this;
|
2014-06-27 17:26:51 +04:00
|
|
|
mAllocator = aForwarder;
|
2013-12-12 05:44:44 +04:00
|
|
|
mShared = true;
|
2014-01-22 02:06:18 +04:00
|
|
|
return mActor->IPCOpen();
|
2013-12-12 05:44:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PTextureChild*
|
|
|
|
TextureClient::GetIPDLActor()
|
|
|
|
{
|
|
|
|
return mActor;
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
static bool
|
2014-03-28 18:35:21 +04:00
|
|
|
DisableGralloc(SurfaceFormat aFormat, const gfx::IntSize& aSizeHint)
|
2014-03-08 01:34:04 +04:00
|
|
|
{
|
|
|
|
if (aFormat == gfx::SurfaceFormat::A8) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-28 18:35:21 +04:00
|
|
|
#if ANDROID_VERSION <= 15
|
|
|
|
// Adreno 200 has a problem of drawing gralloc buffer width less than 64 and
|
|
|
|
// drawing gralloc buffer with a height 9px-16px.
|
|
|
|
// See Bug 983971.
|
|
|
|
if (aSizeHint.width < 64 || aSizeHint.height < 32) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-22 16:17:31 +04:00
|
|
|
static
|
|
|
|
TemporaryRef<BufferTextureClient>
|
|
|
|
CreateBufferTextureClient(ISurfaceAllocator* aAllocator,
|
|
|
|
SurfaceFormat aFormat,
|
|
|
|
TextureFlags aTextureFlags,
|
|
|
|
gfx::BackendType aMoz2DBackend)
|
|
|
|
{
|
|
|
|
if (aAllocator->IsSameProcess()) {
|
|
|
|
RefPtr<BufferTextureClient> result = new MemoryTextureClient(aAllocator, aFormat,
|
|
|
|
aMoz2DBackend,
|
|
|
|
aTextureFlags);
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
RefPtr<BufferTextureClient> result = new ShmemTextureClient(aAllocator, aFormat,
|
|
|
|
aMoz2DBackend,
|
|
|
|
aTextureFlags);
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:16:57 +04:00
|
|
|
// static
|
2014-03-08 01:34:04 +04:00
|
|
|
TemporaryRef<TextureClient>
|
2014-07-29 15:16:57 +04:00
|
|
|
TextureClient::CreateForDrawing(ISurfaceAllocator* aAllocator,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::IntSize aSize,
|
|
|
|
gfx::BackendType aMoz2DBackend,
|
|
|
|
TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags)
|
2014-03-08 01:34:04 +04:00
|
|
|
{
|
2014-03-18 01:35:20 +04:00
|
|
|
if (aMoz2DBackend == gfx::BackendType::NONE) {
|
|
|
|
aMoz2DBackend = gfxPlatform::GetPlatform()->GetContentBackend();
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:16:57 +04:00
|
|
|
RefPtr<TextureClient> texture;
|
2014-03-08 01:34:04 +04:00
|
|
|
|
2014-04-08 16:50:49 +04:00
|
|
|
#if defined(MOZ_WIDGET_GONK) || defined(XP_WIN)
|
|
|
|
int32_t maxTextureSize = aAllocator->GetMaxTextureSize();
|
|
|
|
#endif
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
LayersBackend parentBackend = aAllocator->GetCompositorBackendType();
|
2014-03-18 01:35:20 +04:00
|
|
|
if (parentBackend == LayersBackend::LAYERS_D3D11 &&
|
|
|
|
(aMoz2DBackend == gfx::BackendType::DIRECT2D ||
|
|
|
|
aMoz2DBackend == gfx::BackendType::DIRECT2D1_1) &&
|
|
|
|
gfxWindowsPlatform::GetPlatform()->GetD2DDevice() &&
|
2014-07-29 15:16:57 +04:00
|
|
|
aSize.width <= maxTextureSize &&
|
|
|
|
aSize.height <= maxTextureSize) {
|
|
|
|
texture = new TextureClientD3D11(aFormat, aTextureFlags);
|
2014-03-08 01:34:04 +04:00
|
|
|
}
|
|
|
|
if (parentBackend == LayersBackend::LAYERS_D3D9 &&
|
2014-03-18 01:35:20 +04:00
|
|
|
aMoz2DBackend == gfx::BackendType::CAIRO &&
|
2014-03-08 01:34:04 +04:00
|
|
|
aAllocator->IsSameProcess() &&
|
2014-07-29 15:16:57 +04:00
|
|
|
aSize.width <= maxTextureSize &&
|
|
|
|
aSize.height <= maxTextureSize) {
|
2014-07-11 01:29:40 +04:00
|
|
|
if (gfxWindowsPlatform::GetPlatform()->GetD3D9Device()) {
|
2014-07-29 15:16:57 +04:00
|
|
|
texture = new CairoTextureClientD3D9(aFormat, aTextureFlags);
|
2014-03-08 01:34:04 +04:00
|
|
|
}
|
|
|
|
}
|
2014-07-11 01:29:40 +04:00
|
|
|
|
2014-07-29 15:16:57 +04:00
|
|
|
if (!texture && aFormat == SurfaceFormat::B8G8R8X8 &&
|
2014-07-11 01:29:40 +04:00
|
|
|
aAllocator->IsSameProcess()) {
|
2014-07-29 15:16:57 +04:00
|
|
|
texture = new DIBTextureClient(aFormat, aTextureFlags);
|
2014-07-11 01:29:40 +04:00
|
|
|
}
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
LayersBackend parentBackend = aAllocator->GetCompositorBackendType();
|
|
|
|
gfxSurfaceType type =
|
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType();
|
|
|
|
|
|
|
|
if (parentBackend == LayersBackend::LAYERS_BASIC &&
|
2014-03-18 01:35:20 +04:00
|
|
|
aMoz2DBackend == gfx::BackendType::CAIRO &&
|
2014-07-29 15:16:57 +04:00
|
|
|
type == gfxSurfaceType::Xlib)
|
2014-03-08 01:34:04 +04:00
|
|
|
{
|
2014-07-29 15:16:57 +04:00
|
|
|
texture = new TextureClientX11(aAllocator, aFormat, aTextureFlags);
|
2014-03-08 01:34:04 +04:00
|
|
|
}
|
|
|
|
#ifdef GL_PROVIDER_GLX
|
|
|
|
if (parentBackend == LayersBackend::LAYERS_OPENGL &&
|
|
|
|
type == gfxSurfaceType::Xlib &&
|
|
|
|
aFormat != SurfaceFormat::A8 &&
|
|
|
|
gl::sGLXLibrary.UseTextureFromPixmap())
|
|
|
|
{
|
2014-07-29 15:16:57 +04:00
|
|
|
texture = new TextureClientX11(aAllocator, aFormat, aTextureFlags);
|
2014-03-08 01:34:04 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-07-29 15:16:57 +04:00
|
|
|
if (!DisableGralloc(aFormat, aSize)) {
|
2014-03-12 16:16:37 +04:00
|
|
|
// Don't allow Gralloc texture clients to exceed the maximum texture size.
|
|
|
|
// BufferTextureClients have code to handle tiling the surface client-side.
|
2014-07-29 15:16:57 +04:00
|
|
|
if (aSize.width <= maxTextureSize && aSize.height <= maxTextureSize) {
|
|
|
|
texture = new GrallocTextureClientOGL(aAllocator, aFormat, aMoz2DBackend,
|
2014-03-18 01:35:20 +04:00
|
|
|
aTextureFlags);
|
2014-03-12 16:16:37 +04:00
|
|
|
}
|
2014-03-08 01:34:04 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-29 15:16:57 +04:00
|
|
|
MOZ_ASSERT(!texture || texture->CanExposeDrawTarget(), "texture cannot expose a DrawTarget?");
|
2014-03-08 01:34:04 +04:00
|
|
|
|
2014-07-29 15:16:57 +04:00
|
|
|
if (texture && texture->AllocateForSurface(aSize, aAllocFlags)) {
|
|
|
|
return texture;
|
|
|
|
}
|
2014-03-08 01:34:04 +04:00
|
|
|
|
2014-07-10 15:45:40 +04:00
|
|
|
if (texture) {
|
2014-07-29 15:16:57 +04:00
|
|
|
NS_WARNING("Failed to allocate a TextureClient, falling back to BufferTextureClient.");
|
2014-07-10 15:45:40 +04:00
|
|
|
}
|
2014-07-29 15:16:57 +04:00
|
|
|
|
|
|
|
// Can't do any better than a buffer texture client.
|
|
|
|
texture = CreateBufferTextureClient(aAllocator, aFormat, aTextureFlags, aMoz2DBackend);
|
|
|
|
|
|
|
|
if (!texture->AllocateForSurface(aSize, aAllocFlags)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-10 15:45:40 +04:00
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
TemporaryRef<BufferTextureClient>
|
|
|
|
TextureClient::CreateForRawBufferAccess(ISurfaceAllocator* aAllocator,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
gfx::IntSize aSize,
|
|
|
|
gfx::BackendType aMoz2DBackend,
|
|
|
|
TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags)
|
|
|
|
{
|
|
|
|
RefPtr<BufferTextureClient> texture =
|
|
|
|
CreateBufferTextureClient(aAllocator, aFormat,
|
|
|
|
aTextureFlags, aMoz2DBackend);
|
|
|
|
if (texture) {
|
|
|
|
if (!texture->AllocateForSurface(aSize, aAllocFlags)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2014-07-10 15:48:29 +04:00
|
|
|
// static
|
|
|
|
TemporaryRef<BufferTextureClient>
|
|
|
|
TextureClient::CreateForYCbCr(ISurfaceAllocator* aAllocator,
|
|
|
|
gfx::IntSize aYSize,
|
|
|
|
gfx::IntSize aCbCrSize,
|
|
|
|
StereoMode aStereoMode,
|
|
|
|
TextureFlags aTextureFlags)
|
|
|
|
{
|
|
|
|
RefPtr<BufferTextureClient> texture;
|
|
|
|
if (aAllocator->IsSameProcess()) {
|
|
|
|
texture = new MemoryTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
|
|
|
gfx::BackendType::NONE,
|
|
|
|
aTextureFlags);
|
|
|
|
} else {
|
|
|
|
texture = new ShmemTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
|
|
|
gfx::BackendType::NONE,
|
|
|
|
aTextureFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!texture->AllocateForYCbCr(aYSize, aCbCrSize, aStereoMode)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
// static
|
|
|
|
TemporaryRef<BufferTextureClient>
|
2014-07-22 16:17:31 +04:00
|
|
|
TextureClient::CreateWithBufferSize(ISurfaceAllocator* aAllocator,
|
|
|
|
gfx::SurfaceFormat aFormat,
|
|
|
|
size_t aSize,
|
|
|
|
TextureFlags aTextureFlags)
|
2014-03-08 01:34:04 +04:00
|
|
|
{
|
2014-07-22 16:17:31 +04:00
|
|
|
RefPtr<BufferTextureClient> texture;
|
2014-06-11 17:52:19 +04:00
|
|
|
if (aAllocator->IsSameProcess()) {
|
2014-07-22 16:17:31 +04:00
|
|
|
texture = new MemoryTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
|
|
|
gfx::BackendType::NONE,
|
|
|
|
aTextureFlags);
|
|
|
|
} else {
|
|
|
|
texture = new ShmemTextureClient(aAllocator, gfx::SurfaceFormat::YUV,
|
|
|
|
gfx::BackendType::NONE,
|
|
|
|
aTextureFlags);
|
2014-03-08 01:34:04 +04:00
|
|
|
}
|
2014-07-22 16:17:31 +04:00
|
|
|
|
|
|
|
if (!texture->Allocate(aSize)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return texture;
|
2014-03-08 01:34:04 +04:00
|
|
|
}
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
TextureClient::TextureClient(TextureFlags aFlags)
|
2013-12-21 01:44:30 +04:00
|
|
|
: mFlags(aFlags)
|
2013-08-28 00:16:03 +04:00
|
|
|
, mShared(false)
|
2013-09-06 13:04:50 +04:00
|
|
|
, mValid(true)
|
2013-07-30 13:59:51 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
TextureClient::~TextureClient()
|
2013-12-12 05:44:45 +04:00
|
|
|
{
|
|
|
|
// All the destruction code that may lead to virtual method calls must
|
|
|
|
// be in Finalize() which is called just before the destructor.
|
|
|
|
}
|
|
|
|
|
2014-07-22 19:49:05 +04:00
|
|
|
void
|
|
|
|
TextureClient::KeepUntilFullDeallocation(KeepAlive* aKeep)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mActor);
|
|
|
|
MOZ_ASSERT(!mActor->mKeep);
|
|
|
|
mActor->mKeep = aKeep;
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
void TextureClient::ForceRemove()
|
|
|
|
{
|
|
|
|
if (mValid && mActor) {
|
2014-04-26 06:34:05 +04:00
|
|
|
if (GetFlags() & TextureFlags::DEALLOCATE_CLIENT) {
|
2013-12-21 01:44:30 +04:00
|
|
|
if (mActor->IPCOpen()) {
|
2014-05-13 05:18:22 +04:00
|
|
|
mActor->SendClearTextureHostSync();
|
|
|
|
mActor->SendRemoveTexture();
|
2013-12-21 01:44:30 +04:00
|
|
|
}
|
2013-12-12 05:44:45 +04:00
|
|
|
} else {
|
2013-12-21 01:44:30 +04:00
|
|
|
if (mActor->IPCOpen()) {
|
|
|
|
mActor->SendRemoveTexture();
|
|
|
|
}
|
2013-12-12 05:44:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
MarkInvalid();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-11 22:57:58 +04:00
|
|
|
DrawTarget* destinationTarget = aTarget->BorrowDrawTarget();
|
|
|
|
DrawTarget* sourceTarget = BorrowDrawTarget();
|
2014-03-08 01:34:04 +04:00
|
|
|
RefPtr<gfx::SourceSurface> source = sourceTarget->Snapshot();
|
|
|
|
destinationTarget->CopySurface(source,
|
|
|
|
aRect ? *aRect : gfx::IntRect(gfx::IntPoint(0, 0), GetSize()),
|
|
|
|
aPoint ? *aPoint : gfx::IntPoint(0, 0));
|
|
|
|
source = nullptr;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:44:45 +04:00
|
|
|
void
|
|
|
|
TextureClient::Finalize()
|
|
|
|
{
|
2014-03-21 21:03:20 +04:00
|
|
|
MOZ_ASSERT(!IsLocked());
|
2014-01-03 02:54:13 +04:00
|
|
|
// Always make a temporary strong reference to the actor before we use it,
|
|
|
|
// in case TextureChild::ActorDestroy might null mActor concurrently.
|
|
|
|
RefPtr<TextureChild> actor = mActor;
|
|
|
|
|
|
|
|
if (actor) {
|
2014-06-19 04:04:06 +04:00
|
|
|
// The actor has a raw pointer to us, actor->mTextureClient.
|
2014-04-07 06:02:31 +04:00
|
|
|
// Null it before RemoveTexture calls to avoid invalid actor->mTextureClient
|
|
|
|
// when calling TextureChild::ActorDestroy()
|
|
|
|
actor->mTextureClient = nullptr;
|
2013-12-12 05:44:45 +04:00
|
|
|
// this will call ForceRemove in the right thread, using a sync proxy if needed
|
2014-02-27 01:34:41 +04:00
|
|
|
if (actor->GetForwarder()) {
|
|
|
|
actor->GetForwarder()->RemoveTexture(this);
|
|
|
|
}
|
2013-12-12 05:44:45 +04:00
|
|
|
}
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
TextureClient::ShouldDeallocateInDestructor() const
|
|
|
|
{
|
2013-08-28 00:16:03 +04:00
|
|
|
if (!IsAllocated()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're meant to be deallocated by the host,
|
2014-05-29 00:37:13 +04:00
|
|
|
// but we haven't been shared yet or
|
|
|
|
// TextureFlags::DEALLOCATE_CLIENT is set, then we should
|
2013-08-28 00:16:03 +04:00
|
|
|
// deallocate on the client instead.
|
2014-05-29 00:37:13 +04:00
|
|
|
return !IsSharedWithCompositor() || (GetFlags() & TextureFlags::DEALLOCATE_CLIENT);
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ShmemTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor)
|
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2014-01-10 23:06:16 +04:00
|
|
|
if (!IsAllocated() || GetFormat() == gfx::SurfaceFormat::UNKNOWN) {
|
2013-07-30 13:59:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aDescriptor = SurfaceDescriptorShmem(mShmem, GetFormat());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ShmemTextureClient::Allocate(uint32_t aSize)
|
|
|
|
{
|
2014-01-07 20:20:11 +04:00
|
|
|
MOZ_ASSERT(mValid);
|
2014-05-22 14:11:45 +04:00
|
|
|
SharedMemory::SharedMemoryType memType = OptimalShmemType();
|
2013-07-30 13:59:51 +04:00
|
|
|
mAllocated = GetAllocator()->AllocUnsafeShmem(aSize, memType, &mShmem);
|
|
|
|
return mAllocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t*
|
|
|
|
ShmemTextureClient::GetBuffer() const
|
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2013-07-30 13:59:51 +04:00
|
|
|
if (mAllocated) {
|
|
|
|
return mShmem.get<uint8_t>();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ShmemTextureClient::GetBufferSize() const
|
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2013-07-30 13:59:51 +04:00
|
|
|
return mShmem.Size<uint8_t>();
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
ShmemTextureClient::ShmemTextureClient(ISurfaceAllocator* aAllocator,
|
2013-08-03 21:30:28 +04:00
|
|
|
gfx::SurfaceFormat aFormat,
|
2014-03-18 01:35:20 +04:00
|
|
|
gfx::BackendType aMoz2DBackend,
|
2013-08-03 21:30:28 +04:00
|
|
|
TextureFlags aFlags)
|
2014-03-18 01:35:20 +04:00
|
|
|
: BufferTextureClient(aAllocator, aFormat, aMoz2DBackend, aFlags)
|
2013-07-30 13:59:51 +04:00
|
|
|
, mAllocated(false)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ShmemTextureClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShmemTextureClient::~ShmemTextureClient()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ShmemTextureClient);
|
2013-09-28 00:12:28 +04:00
|
|
|
if (ShouldDeallocateInDestructor()) {
|
2013-07-30 13:59:51 +04:00
|
|
|
// if the buffer has never been shared we must deallocate it or ir would
|
|
|
|
// leak.
|
2014-03-08 01:34:04 +04:00
|
|
|
GetAllocator()->DeallocShmem(mShmem);
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MemoryTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor)
|
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2014-01-10 23:06:16 +04:00
|
|
|
if (!IsAllocated() || GetFormat() == gfx::SurfaceFormat::UNKNOWN) {
|
2013-07-30 13:59:51 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aDescriptor = SurfaceDescriptorMemory(reinterpret_cast<uintptr_t>(mBuffer),
|
|
|
|
GetFormat());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MemoryTextureClient::Allocate(uint32_t aSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mBuffer);
|
2013-12-06 19:30:50 +04:00
|
|
|
static const fallible_t fallible = fallible_t();
|
|
|
|
mBuffer = new(fallible) uint8_t[aSize];
|
|
|
|
if (!mBuffer) {
|
|
|
|
NS_WARNING("Failed to allocate buffer");
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-15 01:54:25 +04:00
|
|
|
GfxMemoryImageReporter::DidAlloc(mBuffer);
|
2013-07-30 13:59:51 +04:00
|
|
|
mBufSize = aSize;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
MemoryTextureClient::MemoryTextureClient(ISurfaceAllocator* aAllocator,
|
2013-08-03 21:30:28 +04:00
|
|
|
gfx::SurfaceFormat aFormat,
|
2014-03-18 01:35:20 +04:00
|
|
|
gfx::BackendType aMoz2DBackend,
|
2013-08-03 21:30:28 +04:00
|
|
|
TextureFlags aFlags)
|
2014-03-18 01:35:20 +04:00
|
|
|
: BufferTextureClient(aAllocator, aFormat, aMoz2DBackend, aFlags)
|
2013-07-30 13:59:51 +04:00
|
|
|
, mBuffer(nullptr)
|
|
|
|
, mBufSize(0)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(MemoryTextureClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryTextureClient::~MemoryTextureClient()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(MemoryTextureClient);
|
2013-12-12 05:44:51 +04:00
|
|
|
if (mBuffer && ShouldDeallocateInDestructor()) {
|
|
|
|
// if the buffer has never been shared we must deallocate it or it would
|
2013-07-30 13:59:51 +04:00
|
|
|
// leak.
|
2013-11-15 01:54:25 +04:00
|
|
|
GfxMemoryImageReporter::WillFree(mBuffer);
|
2014-03-20 04:28:41 +04:00
|
|
|
delete [] mBuffer;
|
2013-07-30 13:59:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
BufferTextureClient::BufferTextureClient(ISurfaceAllocator* aAllocator,
|
2013-08-03 21:30:28 +04:00
|
|
|
gfx::SurfaceFormat aFormat,
|
2014-03-18 01:35:20 +04:00
|
|
|
gfx::BackendType aMoz2DBackend,
|
2013-08-03 21:30:28 +04:00
|
|
|
TextureFlags aFlags)
|
|
|
|
: TextureClient(aFlags)
|
2014-03-08 01:34:04 +04:00
|
|
|
, mAllocator(aAllocator)
|
2013-07-30 13:59:51 +04:00
|
|
|
, mFormat(aFormat)
|
2014-03-18 01:35:20 +04:00
|
|
|
, mBackend(aMoz2DBackend)
|
2014-04-26 06:34:06 +04:00
|
|
|
, mOpenMode(OpenMode::OPEN_NONE)
|
2014-01-07 20:20:11 +04:00
|
|
|
, mLocked(false)
|
2013-07-30 13:59:51 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
BufferTextureClient::~BufferTextureClient()
|
|
|
|
{}
|
|
|
|
|
2014-07-25 13:24:46 +04:00
|
|
|
TemporaryRef<TextureClient>
|
|
|
|
BufferTextureClient::CreateSimilar(TextureFlags aFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags) const
|
|
|
|
{
|
|
|
|
// This may return null
|
|
|
|
RefPtr<BufferTextureClient> newBufferTex = TextureClient::CreateForRawBufferAccess(
|
|
|
|
mAllocator, mFormat, mSize, mBackend, mFlags | aFlags, aAllocFlags
|
|
|
|
);
|
|
|
|
|
|
|
|
RefPtr<TextureClient> newTex = newBufferTex.get();
|
|
|
|
return newTex;
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:34:04 +04:00
|
|
|
ISurfaceAllocator*
|
|
|
|
BufferTextureClient::GetAllocator() const
|
|
|
|
{
|
|
|
|
return mAllocator;
|
|
|
|
}
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
bool
|
2013-12-05 22:39:22 +04:00
|
|
|
BufferTextureClient::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags)
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2014-01-10 23:06:16 +04:00
|
|
|
MOZ_ASSERT(mFormat != gfx::SurfaceFormat::YUV, "This textureClient cannot use YCbCr data");
|
2014-01-07 20:20:11 +04:00
|
|
|
MOZ_ASSERT(aSize.width * aSize.height);
|
2013-07-30 13:59:51 +04:00
|
|
|
|
|
|
|
int bufSize
|
|
|
|
= ImageDataSerializer::ComputeMinBufferSize(aSize, mFormat);
|
|
|
|
if (!Allocate(bufSize)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-05 22:39:22 +04:00
|
|
|
|
|
|
|
if (aFlags & ALLOC_CLEAR_BUFFER) {
|
|
|
|
memset(GetBuffer(), 0, bufSize);
|
|
|
|
}
|
2014-06-18 02:55:31 +04:00
|
|
|
if (aFlags & ALLOC_CLEAR_BUFFER_WHITE) {
|
|
|
|
memset(GetBuffer(), 0xFF, bufSize);
|
|
|
|
}
|
2013-12-05 22:39:22 +04:00
|
|
|
|
2014-02-21 01:04:11 +04:00
|
|
|
ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
|
2013-07-30 13:59:51 +04:00
|
|
|
serializer.InitializeBufferInfo(aSize, mFormat);
|
2013-08-03 21:29:18 +04:00
|
|
|
mSize = aSize;
|
2013-07-30 13:59:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-11 22:57:58 +04:00
|
|
|
gfx::DrawTarget*
|
|
|
|
BufferTextureClient::BorrowDrawTarget()
|
2013-12-05 22:39:22 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsValid());
|
2014-06-11 22:57:58 +04:00
|
|
|
MOZ_ASSERT(mLocked, "BorrowDrawTarget should be called on locked textures only");
|
2014-01-07 20:20:11 +04:00
|
|
|
|
|
|
|
if (mDrawTarget) {
|
|
|
|
return mDrawTarget;
|
|
|
|
}
|
2013-12-05 22:39:22 +04:00
|
|
|
|
2014-02-21 01:04:11 +04:00
|
|
|
ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
|
2013-12-05 22:39:22 +04:00
|
|
|
if (!serializer.IsValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-18 01:35:20 +04:00
|
|
|
mDrawTarget = serializer.GetAsDrawTarget(mBackend);
|
2014-01-07 20:20:11 +04:00
|
|
|
if (mDrawTarget) {
|
|
|
|
return mDrawTarget;
|
|
|
|
}
|
|
|
|
|
2014-04-30 00:33:10 +04:00
|
|
|
mDrawTarget = serializer.GetAsDrawTarget(BackendType::CAIRO);
|
2014-01-07 20:20:11 +04:00
|
|
|
|
|
|
|
return mDrawTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BufferTextureClient::Lock(OpenMode aMode)
|
|
|
|
{
|
2014-03-21 21:03:20 +04:00
|
|
|
MOZ_ASSERT(!mLocked, "The TextureClient is already Locked!");
|
2014-01-07 20:20:11 +04:00
|
|
|
mOpenMode = aMode;
|
2014-02-14 13:20:41 +04:00
|
|
|
mLocked = IsValid() && IsAllocated();;
|
|
|
|
return mLocked;
|
2014-01-07 20:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BufferTextureClient::Unlock()
|
|
|
|
{
|
2014-03-21 21:03:20 +04:00
|
|
|
MOZ_ASSERT(mLocked, "The TextureClient is already Unlocked!");
|
2014-01-07 20:20:11 +04:00
|
|
|
mLocked = false;
|
|
|
|
if (!mDrawTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-11 22:57:58 +04:00
|
|
|
// see the comment on TextureClient::BorrowDrawTarget.
|
2014-03-21 21:03:20 +04:00
|
|
|
// This DrawTarget is internal to the TextureClient and is only exposed to the
|
|
|
|
// outside world between Lock() and Unlock(). This assertion checks that no outside
|
|
|
|
// reference remains by the time Unlock() is called.
|
|
|
|
MOZ_ASSERT(mDrawTarget->refCount() == 1);
|
|
|
|
|
2014-07-30 17:38:46 +04:00
|
|
|
if (mReadbackSink) {
|
|
|
|
RefPtr<SourceSurface> snapshot = mDrawTarget->Snapshot();
|
|
|
|
RefPtr<DataSourceSurface> dataSurf = snapshot->GetDataSurface();
|
|
|
|
mReadbackSink->ProcessReadback(dataSurf);
|
|
|
|
}
|
|
|
|
|
2014-01-07 20:20:11 +04:00
|
|
|
mDrawTarget->Flush();
|
2014-09-01 10:55:31 +04:00
|
|
|
mDrawTarget = nullptr;
|
2013-12-05 22:39:22 +04:00
|
|
|
}
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
bool
|
2013-10-02 04:57:50 +04:00
|
|
|
BufferTextureClient::UpdateYCbCr(const PlanarYCbCrData& aData)
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2014-03-21 21:03:20 +04:00
|
|
|
MOZ_ASSERT(mLocked);
|
2014-01-10 23:06:16 +04:00
|
|
|
MOZ_ASSERT(mFormat == gfx::SurfaceFormat::YUV, "This textureClient can only use YCbCr data");
|
2013-07-30 13:59:51 +04:00
|
|
|
MOZ_ASSERT(!IsImmutable());
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
2013-07-30 13:59:51 +04:00
|
|
|
MOZ_ASSERT(aData.mCbSkip == aData.mCrSkip);
|
|
|
|
|
2014-02-21 01:04:13 +04:00
|
|
|
YCbCrImageDataSerializer serializer(GetBuffer(), GetBufferSize());
|
2013-07-30 13:59:51 +04:00
|
|
|
MOZ_ASSERT(serializer.IsValid());
|
|
|
|
if (!serializer.CopyData(aData.mYChannel, aData.mCbChannel, aData.mCrChannel,
|
2013-12-31 13:06:12 +04:00
|
|
|
aData.mYSize, aData.mYStride,
|
|
|
|
aData.mCbCrSize, aData.mCbCrStride,
|
2013-07-30 13:59:51 +04:00
|
|
|
aData.mYSkip, aData.mCbSkip)) {
|
|
|
|
NS_WARNING("Failed to copy image data!");
|
|
|
|
return false;
|
|
|
|
}
|
2013-08-03 21:30:28 +04:00
|
|
|
|
|
|
|
if (TextureRequiresLocking(mFlags)) {
|
|
|
|
// We don't have support for proper locking yet, so we'll
|
|
|
|
// have to be immutable instead.
|
|
|
|
MarkImmutable();
|
|
|
|
}
|
2013-07-30 13:59:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-08-04 11:46:17 +04:00
|
|
|
BufferTextureClient::AllocateForYCbCr(gfx::IntSize aYSize,
|
|
|
|
gfx::IntSize aCbCrSize,
|
|
|
|
StereoMode aStereoMode)
|
2013-07-30 13:59:51 +04:00
|
|
|
{
|
2013-09-06 13:04:50 +04:00
|
|
|
MOZ_ASSERT(IsValid());
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
size_t bufSize = YCbCrImageDataSerializer::ComputeMinBufferSize(aYSize,
|
|
|
|
aCbCrSize);
|
|
|
|
if (!Allocate(bufSize)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-21 01:04:13 +04:00
|
|
|
YCbCrImageDataSerializer serializer(GetBuffer(), GetBufferSize());
|
2013-07-30 13:59:51 +04:00
|
|
|
serializer.InitializeBufferInfo(aYSize,
|
2013-08-04 11:46:17 +04:00
|
|
|
aCbCrSize,
|
|
|
|
aStereoMode);
|
2013-08-03 21:29:18 +04:00
|
|
|
mSize = aYSize;
|
2013-07-30 13:59:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-19 04:04:06 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// StreamTextureClient
|
|
|
|
StreamTextureClient::StreamTextureClient(TextureFlags aFlags)
|
|
|
|
: TextureClient(aFlags)
|
|
|
|
, mIsLocked(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamTextureClient::~StreamTextureClient()
|
|
|
|
{
|
|
|
|
// the data is owned externally.
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
StreamTextureClient::Lock(OpenMode mode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mIsLocked);
|
|
|
|
if (!IsValid() || !IsAllocated()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mIsLocked = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StreamTextureClient::Unlock()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsLocked);
|
|
|
|
mIsLocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
StreamTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
|
|
|
|
{
|
|
|
|
if (!IsAllocated()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-12 02:10:49 +04:00
|
|
|
aOutDescriptor = SurfaceStreamDescriptor((uintptr_t)mStream.get(), false);
|
2014-06-19 04:04:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-12 02:10:49 +04:00
|
|
|
StreamTextureClient::InitWith(gl::SurfaceStream* aStream)
|
2014-06-19 04:04:06 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!IsAllocated());
|
|
|
|
mStream = aStream;
|
|
|
|
mGL = mStream->GLContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
StreamTextureClient::IsAllocated() const
|
|
|
|
{
|
|
|
|
return mStream != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|