Bug 973227 - Split up TextureHostX11 into TextureSource and TextureHost file, make it backend independent. r=nical

--HG--
rename : gfx/layers/basic/TextureHostX11.cpp => gfx/layers/basic/X11TextureSourceBasic.cpp
rename : gfx/layers/basic/TextureHostX11.h => gfx/layers/basic/X11TextureSourceBasic.h
rename : gfx/layers/basic/TextureHostX11.cpp => gfx/layers/composite/X11TextureHost.cpp
rename : gfx/layers/basic/TextureHostX11.h => gfx/layers/composite/X11TextureHost.h
This commit is contained in:
Tom Schuster 2014-02-18 01:30:05 +01:00
parent 7180283dc9
commit 4427acfe3d
9 changed files with 246 additions and 203 deletions

View File

@ -4,9 +4,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "TextureHostBasic.h"
#ifdef MOZ_X11
#include "TextureHostX11.h"
#endif
#include "MacIOSurfaceTextureHostBasic.h"
using namespace mozilla::gl;
@ -28,14 +25,6 @@ CreateTextureHostBasic(const SurfaceDescriptor& aDesc,
return result;
}
#endif
#ifdef MOZ_X11
if (aDesc.type() == SurfaceDescriptor::TSurfaceDescriptorX11) {
const SurfaceDescriptorX11& desc = aDesc.get_SurfaceDescriptorX11();
RefPtr<TextureHost> result = new TextureHostX11(aFlags, desc);
return result;
}
#endif
return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
}

View File

@ -1,111 +0,0 @@
/* -*- 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 "TextureHostX11.h"
#include "mozilla/layers/BasicCompositor.h"
#include "gfxXlibSurface.h"
#include "gfx2DGlue.h"
using namespace mozilla;
using namespace mozilla::layers;
using namespace mozilla::gfx;
static inline SurfaceFormat
ContentTypeToSurfaceFormat(gfxContentType type)
{
switch (type) {
case gfxContentType::COLOR:
return SurfaceFormat::B8G8R8X8;
case gfxContentType::ALPHA:
return SurfaceFormat::A8;
case gfxContentType::COLOR_ALPHA:
return SurfaceFormat::B8G8R8A8;
default:
return SurfaceFormat::UNKNOWN;
}
}
TextureSourceX11::TextureSourceX11(BasicCompositor* aCompositor, gfxXlibSurface* aSurface)
: mCompositor(aCompositor),
mSurface(aSurface)
{
}
IntSize
TextureSourceX11::GetSize() const
{
return ToIntSize(mSurface->GetSize());
}
SurfaceFormat
TextureSourceX11::GetFormat() const
{
return ContentTypeToSurfaceFormat(mSurface->GetContentType());
}
SourceSurface*
TextureSourceX11::GetSurface()
{
if (!mSourceSurface) {
mSourceSurface =
Factory::CreateSourceSurfaceForCairoSurface(mSurface->CairoSurface(), GetFormat());
}
return mSourceSurface;
}
void
TextureSourceX11::SetCompositor(Compositor* aCompositor)
{
BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
mCompositor = compositor;
}
TextureHostX11::TextureHostX11(TextureFlags aFlags,
const SurfaceDescriptorX11& aDescriptor)
: TextureHost(aFlags)
{
nsRefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign();
mSurface = surface.get();
// The host always frees the pixmap.
MOZ_ASSERT(!(aFlags & TEXTURE_DEALLOCATE_CLIENT));
mSurface->TakePixmap();
}
bool
TextureHostX11::Lock()
{
if (!mCompositor) {
return false;
}
if (!mTextureSource) {
mTextureSource = new TextureSourceX11(mCompositor, mSurface);
}
return true;
}
void
TextureHostX11::SetCompositor(Compositor* aCompositor)
{
BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
mCompositor = compositor;
if (mTextureSource) {
mTextureSource->SetCompositor(compositor);
}
}
SurfaceFormat
TextureHostX11::GetFormat() const
{
return ContentTypeToSurfaceFormat(mSurface->GetContentType());
}
IntSize
TextureHostX11::GetSize() const
{
return ToIntSize(mSurface->GetSize());
}

View File

@ -1,76 +0,0 @@
/* -*- 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/. */
#ifndef MOZILLA_GFX_TEXTUREHOSTX11__H
#define MOZILLA_GFX_TEXTUREHOSTX11__H
#include "mozilla/layers/TextureHostBasic.h"
#include "mozilla/gfx/2D.h"
namespace mozilla {
namespace layers {
class BasicCompositor;
// TextureSource for Xlib-backed surfaces.
class TextureSourceX11
: public TextureSourceBasic,
public NewTextureSource
{
public:
TextureSourceX11(BasicCompositor* aCompositor, gfxXlibSurface* aSurface);
virtual TextureSourceX11* AsSourceBasic() MOZ_OVERRIDE { return this; }
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
virtual gfx::SourceSurface* GetSurface() MOZ_OVERRIDE;
virtual void DeallocateDeviceData() MOZ_OVERRIDE { }
virtual void SetCompositor(Compositor* aCompositor);
protected:
BasicCompositor* mCompositor;
RefPtr<gfxXlibSurface> mSurface;
RefPtr<gfx::SourceSurface> mSourceSurface;
};
// TextureSource for Xlib-backed TextureSources.
class TextureHostX11 : public TextureHost
{
public:
TextureHostX11(TextureFlags aFlags,
const SurfaceDescriptorX11& aDescriptor);
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual bool Lock() MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
{
return mTextureSource;
}
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
}
#ifdef MOZ_LAYERS_HAVE_LOG
virtual const char* Name() { return "TextureHostX11"; }
#endif
protected:
BasicCompositor* mCompositor;
RefPtr<TextureSourceX11> mTextureSource;
RefPtr<gfxXlibSurface> mSurface;
};
} // namespace layers
} // namespace mozilla
#endif // MOZILLA_GFX_TEXTUREHOSTX11__H

View File

@ -0,0 +1,65 @@
/* -*- 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 "X11TextureSourceBasic.h"
#include "mozilla/layers/BasicCompositor.h"
#include "gfxXlibSurface.h"
#include "gfx2DGlue.h"
using namespace mozilla;
using namespace mozilla::layers;
using namespace mozilla::gfx;
X11TextureSourceBasic::X11TextureSourceBasic(BasicCompositor* aCompositor, gfxXlibSurface* aSurface)
: mCompositor(aCompositor),
mSurface(aSurface)
{
}
IntSize
X11TextureSourceBasic::GetSize() const
{
return ToIntSize(mSurface->GetSize());
}
SurfaceFormat
X11TextureSourceBasic::GetFormat() const
{
gfxContentType type = mSurface->GetContentType();
return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type);
}
SourceSurface*
X11TextureSourceBasic::GetSurface()
{
if (!mSourceSurface) {
mSourceSurface =
Factory::CreateSourceSurfaceForCairoSurface(mSurface->CairoSurface(), GetFormat());
}
return mSourceSurface;
}
void
X11TextureSourceBasic::SetCompositor(Compositor* aCompositor)
{
MOZ_ASSERT(aCompositor->GetBackendType() == LayersBackend::LAYERS_BASIC);
BasicCompositor* compositor = static_cast<BasicCompositor*>(aCompositor);
mCompositor = compositor;
}
SurfaceFormat
X11TextureSourceBasic::ContentTypeToSurfaceFormat(gfxContentType aType)
{
switch (aType) {
case gfxContentType::COLOR:
return SurfaceFormat::B8G8R8X8;
case gfxContentType::ALPHA:
return SurfaceFormat::A8;
case gfxContentType::COLOR_ALPHA:
return SurfaceFormat::B8G8R8A8;
default:
return SurfaceFormat::UNKNOWN;
}
}

View File

@ -0,0 +1,46 @@
/* -*- 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/. */
#ifndef MOZILLA_GFX_X11TEXTURESOURCEBASIC__H
#define MOZILLA_GFX_X11TEXTURESOURCEBASIC__H
#include "mozilla/layers/TextureHostBasic.h"
#include "mozilla/gfx/2D.h"
namespace mozilla {
namespace layers {
class BasicCompositor;
// TextureSource for Xlib-backed surfaces.
class X11TextureSourceBasic
: public TextureSourceBasic,
public NewTextureSource
{
public:
X11TextureSourceBasic(BasicCompositor* aCompositor, gfxXlibSurface* aSurface);
virtual X11TextureSourceBasic* AsSourceBasic() MOZ_OVERRIDE { return this; }
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
virtual gfx::SourceSurface* GetSurface() MOZ_OVERRIDE;
virtual void DeallocateDeviceData() MOZ_OVERRIDE { }
virtual void SetCompositor(Compositor* aCompositor);
static gfx::SurfaceFormat ContentTypeToSurfaceFormat(gfxContentType aType);
protected:
BasicCompositor* mCompositor;
RefPtr<gfxXlibSurface> mSurface;
RefPtr<gfx::SourceSurface> mSourceSurface;
};
} // namespace layers
} // namespace mozilla
#endif // MOZILLA_GFX_X11TEXTURESOURCEBASIC__H

View File

@ -14,6 +14,9 @@
#include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator
#include "mozilla/layers/ImageDataSerializer.h"
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
#ifdef MOZ_X11
#include "mozilla/layers/X11TextureHost.h"
#endif
#include "mozilla/layers/YCbCrImageDataSerializer.h"
#include "nsAString.h"
#include "nsAutoPtr.h" // for nsRefPtr
@ -183,8 +186,11 @@ TextureHost::Create(const SurfaceDescriptor& aDesc,
return CreateTextureHostBasic(aDesc, aDeallocator, aFlags);
}
#ifdef MOZ_X11
case SurfaceDescriptor::TSurfaceDescriptorX11:
return CreateTextureHostBasic(aDesc, aDeallocator, aFlags);
case SurfaceDescriptor::TSurfaceDescriptorX11: {
const SurfaceDescriptorX11& desc = aDesc.get_SurfaceDescriptorX11();
RefPtr<TextureHost> result = new X11TextureHost(aFlags, desc);
return result;
}
#endif
#ifdef XP_WIN
case SurfaceDescriptor::TSurfaceDescriptorD3D9:

View File

@ -0,0 +1,69 @@
/* -*- 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 "X11TextureHost.h"
#include "mozilla/layers/BasicCompositor.h"
#include "mozilla/layers/X11TextureSourceBasic.h"
#include "gfxXlibSurface.h"
#include "gfx2DGlue.h"
using namespace mozilla;
using namespace mozilla::layers;
using namespace mozilla::gfx;
X11TextureHost::X11TextureHost(TextureFlags aFlags,
const SurfaceDescriptorX11& aDescriptor)
: TextureHost(aFlags)
{
nsRefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign();
mSurface = surface.get();
// The host always frees the pixmap.
MOZ_ASSERT(!(aFlags & TEXTURE_DEALLOCATE_CLIENT));
mSurface->TakePixmap();
}
bool
X11TextureHost::Lock()
{
if (!mCompositor) {
return false;
}
if (!mTextureSource) {
switch (mCompositor->GetBackendType()) {
case LayersBackend::LAYERS_BASIC:
mTextureSource =
new X11TextureSourceBasic(static_cast<BasicCompositor*>(mCompositor),
mSurface);
break;
default:
return false;
}
}
return true;
}
void
X11TextureHost::SetCompositor(Compositor* aCompositor)
{
mCompositor = aCompositor;
if (mTextureSource) {
mTextureSource->SetCompositor(aCompositor);
}
}
SurfaceFormat
X11TextureHost::GetFormat() const
{
return X11TextureSourceBasic::ContentTypeToSurfaceFormat(mSurface->GetContentType());
}
IntSize
X11TextureHost::GetSize() const
{
return ToIntSize(mSurface->GetSize());
}

View File

@ -0,0 +1,53 @@
/* -*- 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/. */
#ifndef MOZILLA_GFX_X11TEXTUREHOST__H
#define MOZILLA_GFX_X11TEXTUREHOST__H
#include "mozilla/layers/TextureHost.h"
#include "mozilla/layers/LayersSurfaces.h"
#include "mozilla/gfx/2D.h"
class gfxXlibSurface;
namespace mozilla {
namespace layers {
// TextureSource for Xlib-backed TextureSources.
class X11TextureHost : public TextureHost
{
public:
X11TextureHost(TextureFlags aFlags,
const SurfaceDescriptorX11& aDescriptor);
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual bool Lock() MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
{
return mTextureSource;
}
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
}
#ifdef MOZ_LAYERS_HAVE_LOG
virtual const char* Name() { return "X11TextureHost"; }
#endif
protected:
Compositor* mCompositor;
RefPtr<NewTextureSource> mTextureSource;
RefPtr<gfxXlibSurface> mSurface;
};
} // namespace layers
} // namespace mozilla
#endif // MOZILLA_GFX_X11TEXTUREHOST__H

View File

@ -158,13 +158,15 @@ EXPORTS.mozilla.layers += [
if CONFIG['MOZ_X11']:
EXPORTS.mozilla.layers += [
'basic/TextureClientX11.h',
'basic/TextureHostX11.h',
'basic/X11TextureSourceBasic.h',
'composite/X11TextureHost.h',
'ipc/ShadowLayerUtilsX11.h',
]
SOURCES += [
'basic/TextureClientX11.cpp',
'basic/TextureHostX11.cpp',
'ipc/ShadowLayerUtilsX11.cpp'
'basic/X11TextureSourceBasic.cpp',
'composite/X11TextureHost.cpp',
'ipc/ShadowLayerUtilsX11.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':