michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H michael@0: #define MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H michael@0: michael@0: #include "GLContextTypes.h" // for GLContext michael@0: #include "GLDefs.h" // for GLenum, LOCAL_GL_FRAMEBUFFER, etc michael@0: #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc michael@0: #include "mozilla/Attributes.h" // for MOZ_OVERRIDE michael@0: #include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef michael@0: #include "mozilla/gfx/Point.h" // for IntSize, IntSizeTyped michael@0: #include "mozilla/gfx/Types.h" // for SurfaceFormat, etc michael@0: #include "mozilla/layers/Compositor.h" // for SurfaceInitMode, etc michael@0: #include "mozilla/layers/TextureHost.h" // for CompositingRenderTarget michael@0: #include "mozilla/layers/CompositorOGL.h" // for CompositorOGL michael@0: #include "mozilla/mozalloc.h" // for operator new michael@0: #include "nsAString.h" michael@0: #include "nsCOMPtr.h" // for already_AddRefed michael@0: #include "nsDebug.h" // for NS_ERROR, NS_WARNING michael@0: #include "nsString.h" // for nsAutoCString michael@0: michael@0: michael@0: namespace mozilla { michael@0: namespace gl { michael@0: class BindableTexture; michael@0: } michael@0: namespace gfx { michael@0: class DataSourceSurface; michael@0: } michael@0: michael@0: namespace layers { michael@0: michael@0: class TextureSource; michael@0: michael@0: class CompositingRenderTargetOGL : public CompositingRenderTarget michael@0: { michael@0: typedef mozilla::gl::GLContext GLContext; michael@0: michael@0: // For lazy initialisation of the GL stuff michael@0: struct InitParams michael@0: { michael@0: InitParams() : mStatus(NO_PARAMS) {} michael@0: InitParams(const gfx::IntSize& aSize, michael@0: GLenum aFBOTextureTarget, michael@0: SurfaceInitMode aInit) michael@0: : mStatus(READY) michael@0: , mSize(aSize) michael@0: , mFBOTextureTarget(aFBOTextureTarget) michael@0: , mInit(aInit) michael@0: {} michael@0: michael@0: enum { michael@0: NO_PARAMS, michael@0: READY, michael@0: INITIALIZED michael@0: } mStatus; michael@0: gfx::IntSize mSize; michael@0: GLenum mFBOTextureTarget; michael@0: SurfaceInitMode mInit; michael@0: }; michael@0: michael@0: public: michael@0: CompositingRenderTargetOGL(CompositorOGL* aCompositor, const gfx::IntPoint& aOrigin, michael@0: GLuint aTexure, GLuint aFBO) michael@0: : CompositingRenderTarget(aOrigin) michael@0: , mInitParams() michael@0: , mTransform() michael@0: , mCompositor(aCompositor) michael@0: , mGL(aCompositor->gl()) michael@0: , mTextureHandle(aTexure) michael@0: , mFBO(aFBO) michael@0: {} michael@0: michael@0: ~CompositingRenderTargetOGL(); michael@0: michael@0: /** michael@0: * Create a render target around the default FBO, for rendering straight to michael@0: * the window. michael@0: */ michael@0: static TemporaryRef michael@0: RenderTargetForWindow(CompositorOGL* aCompositor, michael@0: const gfx::IntSize& aSize, michael@0: const gfx::Matrix& aTransform) michael@0: { michael@0: RefPtr result michael@0: = new CompositingRenderTargetOGL(aCompositor, gfx::IntPoint(0, 0), 0, 0); michael@0: result->mTransform = aTransform; michael@0: result->mInitParams = InitParams(aSize, 0, INIT_MODE_NONE); michael@0: result->mInitParams.mStatus = InitParams::INITIALIZED; michael@0: return result.forget(); michael@0: } michael@0: michael@0: /** michael@0: * Some initialisation work on the backing FBO and texture. michael@0: * We do this lazily so that when we first set this render target on the michael@0: * compositor we do not have to re-bind the FBO after unbinding it, or michael@0: * alternatively leave the FBO bound after creation. michael@0: */ michael@0: void Initialize(const gfx::IntSize& aSize, michael@0: GLenum aFBOTextureTarget, michael@0: SurfaceInitMode aInit) michael@0: { michael@0: MOZ_ASSERT(mInitParams.mStatus == InitParams::NO_PARAMS, "Initialized twice?"); michael@0: // postpone initialization until we actually want to use this render target michael@0: mInitParams = InitParams(aSize, aFBOTextureTarget, aInit); michael@0: } michael@0: michael@0: void BindTexture(GLenum aTextureUnit, GLenum aTextureTarget); michael@0: michael@0: /** michael@0: * Call when we want to draw into our FBO michael@0: */ michael@0: void BindRenderTarget(); michael@0: michael@0: GLuint GetFBO() const michael@0: { michael@0: MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); michael@0: return mFBO; michael@0: } michael@0: michael@0: GLuint GetTextureHandle() const michael@0: { michael@0: MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); michael@0: return mTextureHandle; michael@0: } michael@0: michael@0: // TextureSourceOGL michael@0: TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE michael@0: { michael@0: // XXX - Bug 900770 michael@0: MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource"); michael@0: return nullptr; michael@0: } michael@0: gfx::IntSize GetSize() const MOZ_OVERRIDE michael@0: { michael@0: // XXX - Bug 900770 michael@0: MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource"); michael@0: return gfx::IntSize(0, 0); michael@0: } michael@0: michael@0: gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE michael@0: { michael@0: // XXX - Should it be implemented ? is the above assert true ? michael@0: MOZ_ASSERT(false, "Not implemented"); michael@0: return gfx::SurfaceFormat::UNKNOWN; michael@0: } michael@0: michael@0: const gfx::Matrix& GetTransform() { michael@0: return mTransform; michael@0: } michael@0: michael@0: #ifdef MOZ_DUMP_PAINTING michael@0: virtual TemporaryRef Dump(Compositor* aCompositor); michael@0: #endif michael@0: michael@0: private: michael@0: /** michael@0: * Actually do the initialisation. Note that we leave our FBO bound, and so michael@0: * calling this method is only suitable when about to use this render target. michael@0: */ michael@0: void InitializeImpl(); michael@0: michael@0: InitParams mInitParams; michael@0: gfx::Matrix mTransform; michael@0: CompositorOGL* mCompositor; michael@0: GLContext* mGL; michael@0: GLuint mTextureHandle; michael@0: GLuint mFBO; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* MOZILLA_GFX_SURFACEOGL_H */