Bug 1042696 - Set allocator to TextureClient from constructor. r=nical

This commit is contained in:
Ethan Lin 2014-12-22 03:49:00 -05:00
parent a7beaba91a
commit 81f7e51dc6
18 changed files with 86 additions and 60 deletions

View File

@ -6,6 +6,8 @@
#include "D3D9SurfaceImage.h"
#include "gfx2DGlue.h"
#include "mozilla/layers/TextureD3D9.h"
#include "mozilla/layers/CompositableClient.h"
#include "mozilla/layers/CompositableForwarder.h"
#include "mozilla/gfx/Types.h"
namespace mozilla {
@ -132,7 +134,9 @@ D3D9SurfaceImage::GetTextureClient(CompositableClient* aClient)
EnsureSynchronized();
if (!mTextureClient) {
RefPtr<SharedTextureClientD3D9> textureClient =
new SharedTextureClientD3D9(gfx::SurfaceFormat::B8G8R8X8, TextureFlags::DEFAULT);
new SharedTextureClientD3D9(aClient->GetForwarder(),
gfx::SurfaceFormat::B8G8R8X8,
TextureFlags::DEFAULT);
textureClient->InitWith(mTexture, mShareHandle, mDesc);
mTextureClient = textureClient;
}

View File

@ -4,6 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MacIOSurfaceImage.h"
#include "mozilla/layers/CompositableClient.h"
#include "mozilla/layers/CompositableForwarder.h"
#include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
using namespace mozilla;
@ -14,7 +16,7 @@ MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient)
{
if (!mTextureClient) {
RefPtr<MacIOSurfaceTextureClientOGL> buffer =
new MacIOSurfaceTextureClientOGL(TextureFlags::DEFAULT);
new MacIOSurfaceTextureClientOGL(aClient->GetForwarder(), TextureFlags::DEFAULT);
buffer->InitWith(mSurface);
mTextureClient = buffer;
}

View File

@ -12,8 +12,10 @@ using namespace gfx;
namespace layers {
DIBTextureClient::DIBTextureClient(gfx::SurfaceFormat aFormat, TextureFlags aFlags)
: TextureClient(aFlags)
DIBTextureClient::DIBTextureClient(ISurfaceAllocator* aAllocator,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags)
: TextureClient(aAllocator, aFlags)
, mFormat(aFormat)
, mIsLocked(false)
{
@ -29,7 +31,8 @@ TemporaryRef<TextureClient>
DIBTextureClient::CreateSimilar(TextureFlags aFlags,
TextureAllocationFlags aAllocFlags) const
{
RefPtr<TextureClient> tex = new DIBTextureClient(mFormat, mFlags | aFlags);
RefPtr<TextureClient> tex = new DIBTextureClient(mAllocator, mFormat,
mFlags | aFlags);
if (!tex->AllocateForSurface(mSize, aAllocFlags)) {
return nullptr;

View File

@ -23,7 +23,9 @@ namespace layers {
class DIBTextureClient : public TextureClient
{
public:
DIBTextureClient(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
DIBTextureClient(ISurfaceAllocator* aAllocator,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags);
virtual ~DIBTextureClient();

View File

@ -19,10 +19,11 @@ using namespace mozilla;
using namespace mozilla::gfx;
using namespace mozilla::layers;
TextureClientX11::TextureClientX11(ISurfaceAllocator* aAllocator, SurfaceFormat aFormat, TextureFlags aFlags)
: TextureClient(aFlags),
TextureClientX11::TextureClientX11(ISurfaceAllocator* aAllocator,
SurfaceFormat aFormat,
TextureFlags aFlags)
: TextureClient(aAllocator, aFlags),
mFormat(aFormat),
mAllocator(aAllocator),
mLocked(false)
{
MOZ_COUNT_CTOR(TextureClientX11);

View File

@ -55,7 +55,6 @@ class TextureClientX11 : public TextureClient
gfx::SurfaceFormat mFormat;
gfx::IntSize mSize;
RefPtr<gfxXlibSurface> mSurface;
RefPtr<ISurfaceAllocator> mAllocator;
RefPtr<gfx::DrawTarget> mDrawTarget;
bool mLocked;
};

View File

@ -155,7 +155,8 @@ CanvasClientSharedSurface::CanvasClientSharedSurface(CompositableForwarder* aLay
// Accelerated backends
static TemporaryRef<TextureClient>
TexClientFromShSurf(SharedSurface* surf, TextureFlags flags)
TexClientFromShSurf(ISurfaceAllocator* aAllocator, SharedSurface* surf,
TextureFlags flags)
{
switch (surf->mType) {
case SharedSurfaceType::Basic:
@ -167,7 +168,7 @@ TexClientFromShSurf(SharedSurface* surf, TextureFlags flags)
#endif
default:
return new SharedSurfaceTextureClient(flags, surf);
return new SharedSurfaceTextureClient(aAllocator, flags, surf);
}
}
@ -364,7 +365,7 @@ CanvasClientSharedSurface::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer)
auto flags = GetTextureFlags() | TextureFlags::IMMUTABLE;
// Get a TexClient from our surf.
RefPtr<TextureClient> newTex = TexClientFromShSurf(surf, flags);
RefPtr<TextureClient> newTex = TexClientFromShSurf(GetForwarder(), surf, flags);
if (!newTex) {
auto manager = aLayer->ClientManager();
auto shadowForwarder = manager->AsShadowForwarder();

View File

@ -192,15 +192,17 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag
if (image->GetFormat() == ImageFormat::EGLIMAGE) {
EGLImageImage* typedImage = static_cast<EGLImageImage*>(image);
texture = new EGLImageTextureClient(mTextureFlags,
typedImage,
size);
texture = new EGLImageTextureClient(GetForwarder(),
mTextureFlags,
typedImage,
size);
#ifdef MOZ_WIDGET_ANDROID
} else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE) {
SurfaceTextureImage* typedImage = static_cast<SurfaceTextureImage*>(image);
const SurfaceTextureImage::Data* data = typedImage->GetData();
texture = new SurfaceTextureClient(mTextureFlags, data->mSurfTex,
size, data->mInverted);
texture = new SurfaceTextureClient(GetForwarder(), mTextureFlags,
data->mSurfTex, size,
data->mInverted);
#endif
} else {
MOZ_ASSERT(false, "Bad ImageFormat.");

View File

@ -235,7 +235,7 @@ TextureClient::SetAddedToCompositableClient()
bool
TextureClient::InitIPDLActor(CompositableForwarder* aForwarder)
{
MOZ_ASSERT(aForwarder);
MOZ_ASSERT(aForwarder && aForwarder == mAllocator);
if (mActor && mActor->GetForwarder() == aForwarder) {
return true;
}
@ -250,7 +250,6 @@ TextureClient::InitIPDLActor(CompositableForwarder* aForwarder)
MOZ_ASSERT(mActor);
mActor->mForwarder = aForwarder;
mActor->mTextureClient = this;
mAllocator = aForwarder;
mShared = true;
return mActor->IPCOpen();
}
@ -331,7 +330,7 @@ TextureClient::CreateForDrawing(ISurfaceAllocator* aAllocator,
gfxWindowsPlatform::GetPlatform()->GetD2DDevice() &&
aSize.width <= maxTextureSize &&
aSize.height <= maxTextureSize) {
texture = new TextureClientD3D11(aFormat, aTextureFlags);
texture = new TextureClientD3D11(aAllocator, aFormat, aTextureFlags);
}
if (parentBackend == LayersBackend::LAYERS_D3D9 &&
aMoz2DBackend == gfx::BackendType::CAIRO &&
@ -339,14 +338,14 @@ TextureClient::CreateForDrawing(ISurfaceAllocator* aAllocator,
aSize.width <= maxTextureSize &&
aSize.height <= maxTextureSize) {
if (gfxWindowsPlatform::GetPlatform()->GetD3D9Device()) {
texture = new CairoTextureClientD3D9(aFormat, aTextureFlags);
texture = new CairoTextureClientD3D9(aAllocator, aFormat, aTextureFlags);
}
}
if (!texture && aFormat == SurfaceFormat::B8G8R8X8 &&
aAllocator->IsSameProcess() &&
aMoz2DBackend == gfx::BackendType::CAIRO) {
texture = new DIBTextureClient(aFormat, aTextureFlags);
texture = new DIBTextureClient(aAllocator, aFormat, aTextureFlags);
}
#endif
@ -479,8 +478,9 @@ TextureClient::CreateWithBufferSize(ISurfaceAllocator* aAllocator,
return texture;
}
TextureClient::TextureClient(TextureFlags aFlags)
: mFlags(aFlags)
TextureClient::TextureClient(ISurfaceAllocator* aAllocator, TextureFlags aFlags)
: mAllocator(aAllocator)
, mFlags(aFlags)
, mShared(false)
, mValid(true)
, mAddedToCompositableClient(false)
@ -710,8 +710,7 @@ BufferTextureClient::BufferTextureClient(ISurfaceAllocator* aAllocator,
gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend,
TextureFlags aFlags)
: TextureClient(aFlags)
, mAllocator(aAllocator)
: TextureClient(aAllocator, aFlags)
, mFormat(aFormat)
, mBackend(aMoz2DBackend)
, mOpenMode(OpenMode::OPEN_NONE)
@ -734,12 +733,6 @@ BufferTextureClient::CreateSimilar(TextureFlags aFlags,
return newTex;
}
ISurfaceAllocator*
BufferTextureClient::GetAllocator() const
{
return mAllocator;
}
bool
BufferTextureClient::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags)
{
@ -907,9 +900,10 @@ BufferTextureClient::GetAsSurface()
////////////////////////////////////////////////////////////////////////
// SharedSurfaceTextureClient
SharedSurfaceTextureClient::SharedSurfaceTextureClient(TextureFlags aFlags,
SharedSurfaceTextureClient::SharedSurfaceTextureClient(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
gl::SharedSurface* surf)
: TextureClient(aFlags)
: TextureClient(aAllocator, aFlags)
, mIsLocked(false)
, mSurf(surf)
, mGL(mSurf->mGL)

View File

@ -173,7 +173,8 @@ class TextureClient
: public AtomicRefCountedWithFinalize<TextureClient>
{
public:
explicit TextureClient(TextureFlags aFlags = TextureFlags::DEFAULT);
explicit TextureClient(ISurfaceAllocator* aAllocator,
TextureFlags aFlags = TextureFlags::DEFAULT);
virtual ~TextureClient();
// Creates and allocates a TextureClient usable with Moz2D.
@ -602,15 +603,12 @@ public:
virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return true; }
ISurfaceAllocator* GetAllocator() const;
virtual TemporaryRef<TextureClient>
CreateSimilar(TextureFlags aFlags = TextureFlags::DEFAULT,
TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const MOZ_OVERRIDE;
protected:
RefPtr<gfx::DrawTarget> mDrawTarget;
RefPtr<ISurfaceAllocator> mAllocator;
gfx::SurfaceFormat mFormat;
gfx::IntSize mSize;
gfx::BackendType mBackend;
@ -689,7 +687,8 @@ protected:
class SharedSurfaceTextureClient : public TextureClient
{
public:
SharedSurfaceTextureClient(TextureFlags aFlags, gl::SharedSurface* surf);
SharedSurfaceTextureClient(ISurfaceAllocator* aAllocator, TextureFlags aFlags,
gl::SharedSurface* surf);
protected:
~SharedSurfaceTextureClient();

View File

@ -161,8 +161,10 @@ CreateTextureHostD3D11(const SurfaceDescriptor& aDesc,
return result;
}
TextureClientD3D11::TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags aFlags)
: TextureClient(aFlags)
TextureClientD3D11::TextureClientD3D11(ISurfaceAllocator* aAllocator,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags)
: TextureClient(aAllocator, aFlags)
, mFormat(aFormat)
, mIsLocked(false)
, mNeedsClear(false)
@ -205,7 +207,8 @@ TemporaryRef<TextureClient>
TextureClientD3D11::CreateSimilar(TextureFlags aFlags,
TextureAllocationFlags aAllocFlags) const
{
RefPtr<TextureClient> tex = new TextureClientD3D11(mFormat, mFlags | aFlags);
RefPtr<TextureClient> tex = new TextureClientD3D11(mAllocator, mFormat,
mFlags | aFlags);
if (!tex->AllocateForSurface(mSize, aAllocFlags)) {
return nullptr;

View File

@ -28,7 +28,9 @@ class CompositorD3D11;
class TextureClientD3D11 : public TextureClient
{
public:
TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
TextureClientD3D11(ISurfaceAllocator* aAllocator,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags);
virtual ~TextureClientD3D11();

View File

@ -550,8 +550,10 @@ DataTextureSourceD3D9::GetTileRect()
return ThebesIntRect(GetTileRect(mCurrentTile));
}
CairoTextureClientD3D9::CairoTextureClientD3D9(gfx::SurfaceFormat aFormat, TextureFlags aFlags)
: TextureClient(aFlags)
CairoTextureClientD3D9::CairoTextureClientD3D9(ISurfaceAllocator* aAllocator,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags)
: TextureClient(aAllocator, aFlags)
, mFormat(aFormat)
, mIsLocked(false)
, mNeedsClear(false)
@ -569,7 +571,8 @@ CairoTextureClientD3D9::~CairoTextureClientD3D9()
TemporaryRef<TextureClient>
CairoTextureClientD3D9::CreateSimilar(TextureFlags aFlags, TextureAllocationFlags aAllocFlags) const
{
RefPtr<TextureClient> tex = new CairoTextureClientD3D9(mFormat, mFlags | aFlags);
RefPtr<TextureClient> tex = new CairoTextureClientD3D9(mAllocator, mFormat,
mFlags | aFlags);
if (!tex->AllocateForSurface(mSize, aAllocFlags)) {
return nullptr;
@ -722,8 +725,10 @@ CairoTextureClientD3D9::AllocateForSurface(gfx::IntSize aSize, TextureAllocation
return true;
}
SharedTextureClientD3D9::SharedTextureClientD3D9(gfx::SurfaceFormat aFormat, TextureFlags aFlags)
: TextureClient(aFlags)
SharedTextureClientD3D9::SharedTextureClientD3D9(ISurfaceAllocator* aAllocator,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags)
: TextureClient(aAllocator, aFlags)
, mFormat(aFormat)
, mHandle(0)
, mIsLocked(false)

View File

@ -187,7 +187,8 @@ protected:
class CairoTextureClientD3D9 : public TextureClient
{
public:
CairoTextureClientD3D9(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
CairoTextureClientD3D9(ISurfaceAllocator* aAllocator, gfx::SurfaceFormat aFormat,
TextureFlags aFlags);
virtual ~CairoTextureClientD3D9();
@ -241,7 +242,9 @@ private:
class SharedTextureClientD3D9 : public TextureClient
{
public:
SharedTextureClientD3D9(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
SharedTextureClientD3D9(ISurfaceAllocator* aAllocator,
gfx::SurfaceFormat aFormat,
TextureFlags aFlags);
virtual ~SharedTextureClientD3D9();

View File

@ -9,8 +9,9 @@
namespace mozilla {
namespace layers {
MacIOSurfaceTextureClientOGL::MacIOSurfaceTextureClientOGL(TextureFlags aFlags)
: TextureClient(aFlags)
MacIOSurfaceTextureClientOGL::MacIOSurfaceTextureClientOGL(ISurfaceAllocator* aAllcator,
TextureFlags aFlags)
: TextureClient(aAllcator, aFlags)
, mIsLocked(false)
{}

View File

@ -16,7 +16,8 @@ namespace layers {
class MacIOSurfaceTextureClientOGL : public TextureClient
{
public:
explicit MacIOSurfaceTextureClientOGL(TextureFlags aFlags);
explicit MacIOSurfaceTextureClientOGL(ISurfaceAllocator* aAllcator,
TextureFlags aFlags);
virtual ~MacIOSurfaceTextureClientOGL();

View File

@ -20,10 +20,11 @@ class CompositableForwarder;
////////////////////////////////////////////////////////////////////////
// EGLImageTextureClient
EGLImageTextureClient::EGLImageTextureClient(TextureFlags aFlags,
EGLImageTextureClient::EGLImageTextureClient(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
EGLImageImage* aImage,
gfx::IntSize aSize)
: TextureClient(aFlags)
: TextureClient(aAllocator, aFlags)
, mImage(aImage)
, mSize(aSize)
, mIsLocked(false)
@ -72,11 +73,12 @@ EGLImageTextureClient::Unlock()
#ifdef MOZ_WIDGET_ANDROID
SurfaceTextureClient::SurfaceTextureClient(TextureFlags aFlags,
SurfaceTextureClient::SurfaceTextureClient(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
AndroidSurfaceTexture* aSurfTex,
gfx::IntSize aSize,
bool aInverted)
: TextureClient(aFlags)
: TextureClient(aAllocator, aFlags)
, mSurfTex(aSurfTex)
, mSize(aSize)
, mIsLocked(false)

View File

@ -25,7 +25,8 @@ class CompositableForwarder;
class EGLImageTextureClient : public TextureClient
{
public:
EGLImageTextureClient(TextureFlags aFlags,
EGLImageTextureClient(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
EGLImageImage* aImage,
gfx::IntSize aSize);
@ -72,7 +73,8 @@ protected:
class SurfaceTextureClient : public TextureClient
{
public:
SurfaceTextureClient(TextureFlags aFlags,
SurfaceTextureClient(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
gl::AndroidSurfaceTexture* aSurfTex,
gfx::IntSize aSize,
bool aInverted);