Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H |
michael@0 | 7 | #define MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H |
michael@0 | 8 | |
michael@0 | 9 | #include "GLContextTypes.h" // for GLContext |
michael@0 | 10 | #include "GLDefs.h" // for GLenum, LOCAL_GL_FRAMEBUFFER, etc |
michael@0 | 11 | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
michael@0 | 12 | #include "mozilla/Attributes.h" // for MOZ_OVERRIDE |
michael@0 | 13 | #include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef |
michael@0 | 14 | #include "mozilla/gfx/Point.h" // for IntSize, IntSizeTyped |
michael@0 | 15 | #include "mozilla/gfx/Types.h" // for SurfaceFormat, etc |
michael@0 | 16 | #include "mozilla/layers/Compositor.h" // for SurfaceInitMode, etc |
michael@0 | 17 | #include "mozilla/layers/TextureHost.h" // for CompositingRenderTarget |
michael@0 | 18 | #include "mozilla/layers/CompositorOGL.h" // for CompositorOGL |
michael@0 | 19 | #include "mozilla/mozalloc.h" // for operator new |
michael@0 | 20 | #include "nsAString.h" |
michael@0 | 21 | #include "nsCOMPtr.h" // for already_AddRefed |
michael@0 | 22 | #include "nsDebug.h" // for NS_ERROR, NS_WARNING |
michael@0 | 23 | #include "nsString.h" // for nsAutoCString |
michael@0 | 24 | |
michael@0 | 25 | |
michael@0 | 26 | namespace mozilla { |
michael@0 | 27 | namespace gl { |
michael@0 | 28 | class BindableTexture; |
michael@0 | 29 | } |
michael@0 | 30 | namespace gfx { |
michael@0 | 31 | class DataSourceSurface; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | namespace layers { |
michael@0 | 35 | |
michael@0 | 36 | class TextureSource; |
michael@0 | 37 | |
michael@0 | 38 | class CompositingRenderTargetOGL : public CompositingRenderTarget |
michael@0 | 39 | { |
michael@0 | 40 | typedef mozilla::gl::GLContext GLContext; |
michael@0 | 41 | |
michael@0 | 42 | // For lazy initialisation of the GL stuff |
michael@0 | 43 | struct InitParams |
michael@0 | 44 | { |
michael@0 | 45 | InitParams() : mStatus(NO_PARAMS) {} |
michael@0 | 46 | InitParams(const gfx::IntSize& aSize, |
michael@0 | 47 | GLenum aFBOTextureTarget, |
michael@0 | 48 | SurfaceInitMode aInit) |
michael@0 | 49 | : mStatus(READY) |
michael@0 | 50 | , mSize(aSize) |
michael@0 | 51 | , mFBOTextureTarget(aFBOTextureTarget) |
michael@0 | 52 | , mInit(aInit) |
michael@0 | 53 | {} |
michael@0 | 54 | |
michael@0 | 55 | enum { |
michael@0 | 56 | NO_PARAMS, |
michael@0 | 57 | READY, |
michael@0 | 58 | INITIALIZED |
michael@0 | 59 | } mStatus; |
michael@0 | 60 | gfx::IntSize mSize; |
michael@0 | 61 | GLenum mFBOTextureTarget; |
michael@0 | 62 | SurfaceInitMode mInit; |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | public: |
michael@0 | 66 | CompositingRenderTargetOGL(CompositorOGL* aCompositor, const gfx::IntPoint& aOrigin, |
michael@0 | 67 | GLuint aTexure, GLuint aFBO) |
michael@0 | 68 | : CompositingRenderTarget(aOrigin) |
michael@0 | 69 | , mInitParams() |
michael@0 | 70 | , mTransform() |
michael@0 | 71 | , mCompositor(aCompositor) |
michael@0 | 72 | , mGL(aCompositor->gl()) |
michael@0 | 73 | , mTextureHandle(aTexure) |
michael@0 | 74 | , mFBO(aFBO) |
michael@0 | 75 | {} |
michael@0 | 76 | |
michael@0 | 77 | ~CompositingRenderTargetOGL(); |
michael@0 | 78 | |
michael@0 | 79 | /** |
michael@0 | 80 | * Create a render target around the default FBO, for rendering straight to |
michael@0 | 81 | * the window. |
michael@0 | 82 | */ |
michael@0 | 83 | static TemporaryRef<CompositingRenderTargetOGL> |
michael@0 | 84 | RenderTargetForWindow(CompositorOGL* aCompositor, |
michael@0 | 85 | const gfx::IntSize& aSize, |
michael@0 | 86 | const gfx::Matrix& aTransform) |
michael@0 | 87 | { |
michael@0 | 88 | RefPtr<CompositingRenderTargetOGL> result |
michael@0 | 89 | = new CompositingRenderTargetOGL(aCompositor, gfx::IntPoint(0, 0), 0, 0); |
michael@0 | 90 | result->mTransform = aTransform; |
michael@0 | 91 | result->mInitParams = InitParams(aSize, 0, INIT_MODE_NONE); |
michael@0 | 92 | result->mInitParams.mStatus = InitParams::INITIALIZED; |
michael@0 | 93 | return result.forget(); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | /** |
michael@0 | 97 | * Some initialisation work on the backing FBO and texture. |
michael@0 | 98 | * We do this lazily so that when we first set this render target on the |
michael@0 | 99 | * compositor we do not have to re-bind the FBO after unbinding it, or |
michael@0 | 100 | * alternatively leave the FBO bound after creation. |
michael@0 | 101 | */ |
michael@0 | 102 | void Initialize(const gfx::IntSize& aSize, |
michael@0 | 103 | GLenum aFBOTextureTarget, |
michael@0 | 104 | SurfaceInitMode aInit) |
michael@0 | 105 | { |
michael@0 | 106 | MOZ_ASSERT(mInitParams.mStatus == InitParams::NO_PARAMS, "Initialized twice?"); |
michael@0 | 107 | // postpone initialization until we actually want to use this render target |
michael@0 | 108 | mInitParams = InitParams(aSize, aFBOTextureTarget, aInit); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | void BindTexture(GLenum aTextureUnit, GLenum aTextureTarget); |
michael@0 | 112 | |
michael@0 | 113 | /** |
michael@0 | 114 | * Call when we want to draw into our FBO |
michael@0 | 115 | */ |
michael@0 | 116 | void BindRenderTarget(); |
michael@0 | 117 | |
michael@0 | 118 | GLuint GetFBO() const |
michael@0 | 119 | { |
michael@0 | 120 | MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); |
michael@0 | 121 | return mFBO; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | GLuint GetTextureHandle() const |
michael@0 | 125 | { |
michael@0 | 126 | MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); |
michael@0 | 127 | return mTextureHandle; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | // TextureSourceOGL |
michael@0 | 131 | TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE |
michael@0 | 132 | { |
michael@0 | 133 | // XXX - Bug 900770 |
michael@0 | 134 | MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource"); |
michael@0 | 135 | return nullptr; |
michael@0 | 136 | } |
michael@0 | 137 | gfx::IntSize GetSize() const MOZ_OVERRIDE |
michael@0 | 138 | { |
michael@0 | 139 | // XXX - Bug 900770 |
michael@0 | 140 | MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource"); |
michael@0 | 141 | return gfx::IntSize(0, 0); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE |
michael@0 | 145 | { |
michael@0 | 146 | // XXX - Should it be implemented ? is the above assert true ? |
michael@0 | 147 | MOZ_ASSERT(false, "Not implemented"); |
michael@0 | 148 | return gfx::SurfaceFormat::UNKNOWN; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | const gfx::Matrix& GetTransform() { |
michael@0 | 152 | return mTransform; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | #ifdef MOZ_DUMP_PAINTING |
michael@0 | 156 | virtual TemporaryRef<gfx::DataSourceSurface> Dump(Compositor* aCompositor); |
michael@0 | 157 | #endif |
michael@0 | 158 | |
michael@0 | 159 | private: |
michael@0 | 160 | /** |
michael@0 | 161 | * Actually do the initialisation. Note that we leave our FBO bound, and so |
michael@0 | 162 | * calling this method is only suitable when about to use this render target. |
michael@0 | 163 | */ |
michael@0 | 164 | void InitializeImpl(); |
michael@0 | 165 | |
michael@0 | 166 | InitParams mInitParams; |
michael@0 | 167 | gfx::Matrix mTransform; |
michael@0 | 168 | CompositorOGL* mCompositor; |
michael@0 | 169 | GLContext* mGL; |
michael@0 | 170 | GLuint mTextureHandle; |
michael@0 | 171 | GLuint mFBO; |
michael@0 | 172 | }; |
michael@0 | 173 | |
michael@0 | 174 | } |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | #endif /* MOZILLA_GFX_SURFACEOGL_H */ |