Bug 938970 - 1/5. Move MacIOSurfaceTexture* classes to separate files, minimize the number of cpp files including MacIOSurface.h - r=mattwoodrow

This commit is contained in:
Benoit Jacob 2013-11-17 21:04:38 -05:00
Родитель ecc7b724b3
Коммит bdd8f93313
10 изменённых файлов: 319 добавлений и 217 удалений

Просмотреть файл

@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MacIOSurfaceImage.h"
#include "mozilla/layers/TextureClientOGL.h"
#include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
using namespace mozilla::layers;

Просмотреть файл

@ -143,6 +143,8 @@ EXPORTS.mozilla.layers += [
'opengl/CompositorOGL.h',
'opengl/GrallocTextureClient.h',
'opengl/GrallocTextureHost.h',
'opengl/MacIOSurfaceTextureClientOGL.h',
'opengl/MacIOSurfaceTextureHostOGL.h',
'opengl/TextureClientOGL.h',
'opengl/TextureHostOGL.h',
'RenderTrace.h',
@ -267,6 +269,12 @@ SOURCES += [
'YCbCrImageDataSerializer.cpp',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
SOURCES += [
'opengl/MacIOSurfaceTextureClientOGL.cpp',
'opengl/MacIOSurfaceTextureHostOGL.cpp',
]
IPDL_SOURCES = [
'ipc/LayersMessages.ipdlh',
'ipc/LayersSurfaces.ipdlh',

Просмотреть файл

@ -0,0 +1,58 @@
/* -*- 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 "MacIOSurfaceTextureClientOGL.h"
#include "mozilla/gfx/MacIOSurface.h"
namespace mozilla {
namespace layers {
MacIOSurfaceTextureClientOGL::MacIOSurfaceTextureClientOGL(TextureFlags aFlags)
: TextureClient(aFlags)
{}
MacIOSurfaceTextureClientOGL::~MacIOSurfaceTextureClientOGL()
{}
void
MacIOSurfaceTextureClientOGL::InitWith(MacIOSurface* aSurface)
{
MOZ_ASSERT(IsValid());
MOZ_ASSERT(!IsAllocated());
mSurface = aSurface;
}
bool
MacIOSurfaceTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
{
MOZ_ASSERT(IsValid());
if (!IsAllocated()) {
return false;
}
aOutDescriptor = SurfaceDescriptorMacIOSurface(mSurface->GetIOSurfaceID(),
mSurface->GetContentsScaleFactor(),
mSurface->HasAlpha());
return true;
}
gfx::IntSize
MacIOSurfaceTextureClientOGL::GetSize() const
{
return gfx::IntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight());
}
TextureClientData*
MacIOSurfaceTextureClientOGL::DropTextureData()
{
// MacIOSurface has proper cross-process refcounting so we can just drop
// our reference now, and the data will stay alive (at least) until the host
// has also been torn down.
mSurface = nullptr;
MarkInvalid();
return nullptr;
}
}
}

Просмотреть файл

@ -0,0 +1,40 @@
/* -*- 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_MACIOSURFACETEXTURECLIENTOGL_H
#define MOZILLA_GFX_MACIOSURFACETEXTURECLIENTOGL_H
#include "mozilla/layers/TextureClientOGL.h"
class MacIOSurface;
namespace mozilla {
namespace layers {
class MacIOSurfaceTextureClientOGL : public TextureClient
{
public:
MacIOSurfaceTextureClientOGL(TextureFlags aFlags);
virtual ~MacIOSurfaceTextureClientOGL();
void InitWith(MacIOSurface* aSurface);
virtual bool IsAllocated() const MOZ_OVERRIDE { return !!mSurface; }
virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
virtual gfx::IntSize GetSize() const;
virtual TextureClientData* DropTextureData() MOZ_OVERRIDE;
protected:
RefPtr<MacIOSurface> mSurface;
};
}
}
#endif // MOZILLA_GFX_MACIOSURFACETEXTURECLIENTOGL_H

Просмотреть файл

@ -0,0 +1,103 @@
/* -*- 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 "MacIOSurfaceTextureHostOGL.h"
#include "mozilla/gfx/MacIOSurface.h"
#include "mozilla/layers/CompositorOGL.h"
#include "GLContext.h"
namespace mozilla {
namespace layers {
MacIOSurfaceTextureSourceOGL::MacIOSurfaceTextureSourceOGL(
CompositorOGL* aCompositor,
MacIOSurface* aSurface)
: mCompositor(aCompositor)
, mSurface(aSurface)
{}
MacIOSurfaceTextureSourceOGL::~MacIOSurfaceTextureSourceOGL()
{}
gfx::IntSize
MacIOSurfaceTextureSourceOGL::GetSize() const
{
return gfx::IntSize(mSurface->GetDevicePixelWidth(),
mSurface->GetDevicePixelHeight());
}
gfx::SurfaceFormat
MacIOSurfaceTextureSourceOGL::GetFormat() const
{
return mSurface->HasAlpha() ? gfx::FORMAT_R8G8B8A8 : gfx::FORMAT_B8G8R8X8;
}
MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
const SurfaceDescriptorMacIOSurface& aDescriptor)
: TextureHost(aID, aFlags)
{
mSurface = MacIOSurface::LookupSurface(aDescriptor.surface(),
aDescriptor.scaleFactor(),
aDescriptor.hasAlpha());
}
bool
MacIOSurfaceTextureHostOGL::Lock()
{
if (!mCompositor) {
return false;
}
if (!mTextureSource) {
mTextureSource = new MacIOSurfaceTextureSourceOGL(mCompositor, mSurface);
}
return true;
}
void
MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor)
{
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
mCompositor = glCompositor;
if (mTextureSource) {
mTextureSource->SetCompositor(glCompositor);
}
}
void
MacIOSurfaceTextureSourceOGL::BindTexture(GLenum aTextureUnit)
{
if (!gl()) {
NS_WARNING("Trying to bind a texture without a GLContext");
return;
}
GLuint tex = mCompositor->GetTemporaryTexture(aTextureUnit);
gl()->fActiveTexture(aTextureUnit);
gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, tex);
mSurface->CGLTexImageIOSurface2D(static_cast<CGLContextObj>(gl()->GetNativeData(gl::GLContext::NativeCGLContext)));
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
}
gl::GLContext*
MacIOSurfaceTextureSourceOGL::gl() const
{
return mCompositor ? mCompositor->gl() : nullptr;
}
gfx::SurfaceFormat
MacIOSurfaceTextureHostOGL::GetFormat() const {
return mSurface->HasAlpha() ? gfx::FORMAT_R8G8B8A8 : gfx::FORMAT_B8G8R8X8;
}
gfx::IntSize
MacIOSurfaceTextureHostOGL::GetSize() const {
return gfx::IntSize(mSurface->GetDevicePixelWidth(),
mSurface->GetDevicePixelHeight());
}
}
}

Просмотреть файл

@ -0,0 +1,108 @@
/* -*- 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_MACIOSURFACETEXTUREHOSTOGL_H
#define MOZILLA_GFX_MACIOSURFACETEXTUREHOSTOGL_H
#include "mozilla/layers/TextureHostOGL.h"
class MacIOSurface;
namespace mozilla {
namespace layers {
/**
* A texture source meant for use with MacIOSurfaceTextureHostOGL.
*
* It does not own any GL texture, and attaches its shared handle to one of
* the compositor's temporary textures when binding.
*/
class MacIOSurfaceTextureSourceOGL : public NewTextureSource
, public TextureSourceOGL
{
public:
MacIOSurfaceTextureSourceOGL(CompositorOGL* aCompositor,
MacIOSurface* aSurface);
virtual ~MacIOSurfaceTextureSourceOGL();
virtual TextureSourceOGL* AsSourceOGL() { return this; }
virtual void BindTexture(GLenum activetex) MOZ_OVERRIDE;
virtual bool IsValid() const MOZ_OVERRIDE { return !!gl(); }
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
virtual GLenum GetTextureTarget() const { return LOCAL_GL_TEXTURE_RECTANGLE_ARB; }
virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return LOCAL_GL_CLAMP_TO_EDGE; }
virtual void UnbindTexture() MOZ_OVERRIDE {}
// MacIOSurfaceTextureSourceOGL doesn't own any gl texture
virtual void DeallocateDeviceData() {}
void SetCompositor(CompositorOGL* aCompositor) {
mCompositor = aCompositor;
}
gl::GLContext* gl() const;
protected:
CompositorOGL* mCompositor;
RefPtr<MacIOSurface> mSurface;
};
/**
* A TextureHost for shared MacIOSurface
*
* Most of the logic actually happens in MacIOSurfaceTextureSourceOGL.
*/
class MacIOSurfaceTextureHostOGL : public TextureHost
{
public:
MacIOSurfaceTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
const SurfaceDescriptorMacIOSurface& aDescriptor);
// SharedTextureHostOGL doesn't own any GL texture
virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual bool Lock() MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE;
virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
{
return mTextureSource;
}
virtual already_AddRefed<gfxImageSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
}
gl::GLContext* gl() const;
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
#ifdef MOZ_LAYERS_HAVE_LOG
virtual const char* Name() { return "MacIOSurfaceTextureHostOGL"; }
#endif
protected:
CompositorOGL* mCompositor;
RefPtr<MacIOSurfaceTextureSourceOGL> mTextureSource;
RefPtr<MacIOSurface> mSurface;
};
}
}
#endif // MOZILLA_GFX_MACIOSURFACETEXTUREHOSTOGL_H

Просмотреть файл

@ -66,21 +66,6 @@ SharedTextureClientOGL::IsAllocated() const
return mHandle != 0;
}
#ifdef XP_MACOSX
bool
MacIOSurfaceTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
{
MOZ_ASSERT(IsValid());
if (!IsAllocated()) {
return false;
}
aOutDescriptor = SurfaceDescriptorMacIOSurface(mSurface->GetIOSurfaceID(),
mSurface->GetContentsScaleFactor(),
mSurface->HasAlpha());
return true;
}
#endif
DeprecatedTextureClientSharedOGL::DeprecatedTextureClientSharedOGL(CompositableForwarder* aForwarder,
const TextureInfo& aTextureInfo)
: DeprecatedTextureClient(aForwarder, aTextureInfo)

Просмотреть файл

@ -13,9 +13,6 @@
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
#include "mozilla/layers/TextureClient.h" // for DeprecatedTextureClient, etc
#ifdef XP_MACOSX
#include "mozilla/gfx/MacIOSurface.h"
#endif
namespace mozilla {
namespace layers {
@ -60,45 +57,6 @@ protected:
bool mInverted;
};
#ifdef XP_MACOSX
class MacIOSurfaceTextureClientOGL : public TextureClient
{
public:
MacIOSurfaceTextureClientOGL(TextureFlags aFlags)
: TextureClient(aFlags)
{}
virtual bool IsAllocated() const MOZ_OVERRIDE { return !!mSurface; }
virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
void InitWith(MacIOSurface* aSurface)
{
MOZ_ASSERT(IsValid());
MOZ_ASSERT(!IsAllocated());
mSurface = aSurface;
}
virtual gfx::IntSize GetSize() const
{
return gfx::IntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight());
}
virtual TextureClientData* DropTextureData() MOZ_OVERRIDE
{
// MacIOSurface has proper cross-process refcounting so we can just drop
// our reference now, and the data will stay alive (at least) until the host
// has also been torn down.
mSurface = nullptr;
MarkInvalid();
return nullptr;
}
protected:
RefPtr<MacIOSurface> mSurface;
};
#endif
class DeprecatedTextureClientSharedOGL : public DeprecatedTextureClient
{
public:

Просмотреть файл

@ -30,6 +30,7 @@
#include "GfxTexturesReporter.h" // for GfxTexturesReporter
#ifdef XP_MACOSX
#include "SharedSurfaceIO.h"
#include "mozilla/layers/MacIOSurfaceTextureHostOGL.h"
#endif
#include "GeckoProfiler.h"
@ -437,62 +438,6 @@ SharedTextureHostOGL::GetFormat() const
return mTextureSource->GetFormat();
}
#ifdef XP_MACOSX
MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
const SurfaceDescriptorMacIOSurface& aDescriptor)
: TextureHost(aID, aFlags)
{
mSurface = MacIOSurface::LookupSurface(aDescriptor.surface(),
aDescriptor.scaleFactor(),
aDescriptor.hasAlpha());
}
bool
MacIOSurfaceTextureHostOGL::Lock()
{
if (!mCompositor) {
return false;
}
if (!mTextureSource) {
mTextureSource = new MacIOSurfaceTextureSourceOGL(mCompositor, mSurface);
}
return true;
}
void
MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor)
{
CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
mCompositor = glCompositor;
if (mTextureSource) {
mTextureSource->SetCompositor(glCompositor);
}
}
void
MacIOSurfaceTextureSourceOGL::BindTexture(GLenum aTextureUnit)
{
if (!gl()) {
NS_WARNING("Trying to bind a texture without a GLContext");
return;
}
GLuint tex = mCompositor->GetTemporaryTexture(aTextureUnit);
gl()->fActiveTexture(aTextureUnit);
gl()->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, tex);
mSurface->CGLTexImageIOSurface2D(static_cast<CGLContextObj>(gl()->GetNativeData(GLContext::NativeCGLContext)));
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
}
gl::GLContext*
MacIOSurfaceTextureSourceOGL::gl() const
{
return mCompositor ? mCompositor->gl() : nullptr;
}
#endif
TextureImageDeprecatedTextureHostOGL::~TextureImageDeprecatedTextureHostOGL()
{
MOZ_COUNT_DTOR(TextureImageDeprecatedTextureHostOGL);

Просмотреть файл

@ -33,9 +33,6 @@
#ifdef MOZ_WIDGET_GONK
#include <ui/GraphicBuffer.h>
#endif
#ifdef XP_MACOSX
#include "mozilla/gfx/MacIOSurface.h"
#endif
class gfxImageSurface;
class gfxReusableSurfaceWrapper;
@ -348,106 +345,6 @@ protected:
RefPtr<SharedTextureSourceOGL> mTextureSource;
};
#ifdef XP_MACOSX
/**
* A texture source meant for use with MacIOSurfaceTextureHostOGL.
*
* It does not own any GL texture, and attaches its shared handle to one of
* the compositor's temporary textures when binding.
*/
class MacIOSurfaceTextureSourceOGL : public NewTextureSource
, public TextureSourceOGL
{
public:
MacIOSurfaceTextureSourceOGL(CompositorOGL* aCompositor,
MacIOSurface* aSurface)
: mCompositor(aCompositor)
, mSurface(aSurface)
{}
virtual TextureSourceOGL* AsSourceOGL() { return this; }
virtual void BindTexture(GLenum activetex) MOZ_OVERRIDE;
virtual bool IsValid() const MOZ_OVERRIDE { return !!gl(); }
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE {
return gfx::IntSize(mSurface->GetDevicePixelWidth(),
mSurface->GetDevicePixelHeight());
}
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE {
return mSurface->HasAlpha() ? gfx::FORMAT_R8G8B8A8 : gfx::FORMAT_B8G8R8X8; }
virtual GLenum GetTextureTarget() const { return LOCAL_GL_TEXTURE_RECTANGLE_ARB; }
virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return LOCAL_GL_CLAMP_TO_EDGE; }
virtual void UnbindTexture() MOZ_OVERRIDE {}
// MacIOSurfaceTextureSourceOGL doesn't own any gl texture
virtual void DeallocateDeviceData() {}
void SetCompositor(CompositorOGL* aCompositor) {
mCompositor = aCompositor;
}
gl::GLContext* gl() const;
protected:
CompositorOGL* mCompositor;
RefPtr<MacIOSurface> mSurface;
};
/**
* A TextureHost for shared MacIOSurface
*
* Most of the logic actually happens in MacIOSurfaceTextureSourceOGL.
*/
class MacIOSurfaceTextureHostOGL : public TextureHost
{
public:
MacIOSurfaceTextureHostOGL(uint64_t aID,
TextureFlags aFlags,
const SurfaceDescriptorMacIOSurface& aDescriptor);
// SharedTextureHostOGL doesn't own any GL texture
virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual bool Lock() MOZ_OVERRIDE;
virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE {
return mSurface->HasAlpha() ? gfx::FORMAT_R8G8B8A8 : gfx::FORMAT_B8G8R8X8;
}
virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE
{
return mTextureSource;
}
virtual already_AddRefed<gfxImageSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
}
gl::GLContext* gl() const;
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE {
return gfx::IntSize(mSurface->GetDevicePixelWidth(),
mSurface->GetDevicePixelHeight());
}
virtual const char* Name() { return "MacIOSurfaceTextureHostOGL"; }
protected:
CompositorOGL* mCompositor;
RefPtr<MacIOSurfaceTextureSourceOGL> mTextureSource;
RefPtr<MacIOSurface> mSurface;
};
#endif
/**
* DeprecatedTextureHost implementation using a TextureImage as the underlying texture.
*/