gecko-dev/gfx/layers/opengl/CompositingRenderTargetOGL.h

185 строки
5.5 KiB
C
Исходник Обычный вид История

/* -*- 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_COMPOSITINGRENDERTARGETOGL_H
#define MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H
#include "GLContextTypes.h" // for GLContext
#include "GLDefs.h" // for GLenum, LOCAL_GL_FRAMEBUFFER, etc
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/Attributes.h" // for override
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
#include "mozilla/RefPtr.h" // for RefPtr, already_AddRefed
#include "mozilla/gfx/Point.h" // for IntSize, IntSizeTyped
#include "mozilla/gfx/Types.h" // for SurfaceFormat, etc
#include "mozilla/layers/Compositor.h" // for SurfaceInitMode, etc
#include "mozilla/layers/TextureHost.h" // for CompositingRenderTarget
#include "mozilla/layers/CompositorOGL.h" // for CompositorOGL
#include "mozilla/mozalloc.h" // for operator new
#include "nsAString.h"
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsDebug.h" // for NS_ERROR, NS_WARNING
#include "nsString.h" // for nsAutoCString
namespace mozilla {
namespace gl {
class BindableTexture;
} // namespace gl
namespace gfx {
class DataSourceSurface;
} // namespace gfx
namespace layers {
class TextureSource;
class CompositingRenderTargetOGL : public CompositingRenderTarget
{
typedef mozilla::gl::GLContext GLContext;
friend class CompositorOGL;
// For lazy initialisation of the GL stuff
struct InitParams
{
InitParams() : mStatus(NO_PARAMS) {}
InitParams(const gfx::IntSize& aSize,
GLenum aFBOTextureTarget,
SurfaceInitMode aInit)
: mStatus(READY)
, mSize(aSize)
, mFBOTextureTarget(aFBOTextureTarget)
, mInit(aInit)
{}
enum {
NO_PARAMS,
READY,
INITIALIZED
} mStatus;
gfx::IntSize mSize;
GLenum mFBOTextureTarget;
SurfaceInitMode mInit;
};
public:
CompositingRenderTargetOGL(CompositorOGL* aCompositor, const gfx::IntPoint& aOrigin,
GLuint aTexure, GLuint aFBO)
: CompositingRenderTarget(aOrigin)
, mInitParams()
, mCompositor(aCompositor)
, mGL(aCompositor->gl())
, mTextureHandle(aTexure)
, mFBO(aFBO)
{
MOZ_ASSERT(mGL);
}
~CompositingRenderTargetOGL();
virtual const char* Name() const override { return "CompositingRenderTargetOGL"; }
/**
* Create a render target around the default FBO, for rendering straight to
* the window.
*/
static already_AddRefed<CompositingRenderTargetOGL>
RenderTargetForWindow(CompositorOGL* aCompositor,
const gfx::IntSize& aSize)
{
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<CompositingRenderTargetOGL> result
= new CompositingRenderTargetOGL(aCompositor, gfx::IntPoint(), 0, 0);
result->mInitParams = InitParams(aSize, 0, INIT_MODE_NONE);
result->mInitParams.mStatus = InitParams::INITIALIZED;
return result.forget();
}
/**
* Some initialisation work on the backing FBO and texture.
* We do this lazily so that when we first set this render target on the
* compositor we do not have to re-bind the FBO after unbinding it, or
* alternatively leave the FBO bound after creation.
*/
void Initialize(const gfx::IntSize& aSize,
GLenum aFBOTextureTarget,
SurfaceInitMode aInit)
{
MOZ_ASSERT(mInitParams.mStatus == InitParams::NO_PARAMS, "Initialized twice?");
// postpone initialization until we actually want to use this render target
mInitParams = InitParams(aSize, aFBOTextureTarget, aInit);
}
void BindTexture(GLenum aTextureUnit, GLenum aTextureTarget);
/**
* Call when we want to draw into our FBO
*/
void BindRenderTarget();
bool IsWindow() { return GetFBO() == 0; }
GLuint GetFBO() const
{
MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
return mFBO;
}
GLuint GetTextureHandle() const
{
MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
return mTextureHandle;
}
// TextureSourceOGL
TextureSourceOGL* AsSourceOGL() override
{
// XXX - Bug 900770
MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource");
return nullptr;
}
gfx::IntSize GetSize() const override
{
return mInitParams.mSize;
}
gfx::SurfaceFormat GetFormat() const override
{
// XXX - Should it be implemented ? is the above assert true ?
MOZ_ASSERT(false, "Not implemented");
return gfx::SurfaceFormat::UNKNOWN;
}
#ifdef MOZ_DUMP_PAINTING
virtual already_AddRefed<gfx::DataSourceSurface> Dump(Compositor* aCompositor) override;
#endif
const gfx::IntSize& GetInitSize() const {
return mInitParams.mSize;
}
private:
/**
* Actually do the initialisation. Note that we leave our FBO bound, and so
* calling this method is only suitable when about to use this render target.
*/
void InitializeImpl();
InitParams mInitParams;
/**
* There is temporary a cycle between the compositor and the render target,
* each having a strong ref to the other. The compositor's reference to
* the target is always cleared at the end of a frame.
*/
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<CompositorOGL> mCompositor;
GLContext* mGL;
GLuint mTextureHandle;
GLuint mFBO;
};
} // namespace layers
} // namespace mozilla
#endif /* MOZILLA_GFX_SURFACEOGL_H */