/work/obj-fuzz/dist/include/mozilla/layers/CompositingRenderTargetOGL.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H |
8 | | #define MOZILLA_GFX_COMPOSITINGRENDERTARGETOGL_H |
9 | | |
10 | | #include "GLContextTypes.h" // for GLContext |
11 | | #include "GLDefs.h" // for GLenum, LOCAL_GL_FRAMEBUFFER, etc |
12 | | #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc |
13 | | #include "mozilla/Attributes.h" // for override |
14 | | #include "mozilla/RefPtr.h" // for RefPtr, already_AddRefed |
15 | | #include "mozilla/gfx/Point.h" // for IntSize, IntSizeTyped |
16 | | #include "mozilla/gfx/Types.h" // for SurfaceFormat, etc |
17 | | #include "mozilla/layers/Compositor.h" // for SurfaceInitMode, etc |
18 | | #include "mozilla/layers/TextureHost.h" // for CompositingRenderTarget |
19 | | #include "mozilla/layers/CompositorOGL.h" // for CompositorOGL |
20 | | #include "mozilla/mozalloc.h" // for operator new |
21 | | #include "nsAString.h" |
22 | | #include "nsCOMPtr.h" // for already_AddRefed |
23 | | #include "nsDebug.h" // for NS_ERROR, NS_WARNING |
24 | | #include "nsString.h" // for nsAutoCString |
25 | | |
26 | | |
27 | | namespace mozilla { |
28 | | namespace gl { |
29 | | class BindableTexture; |
30 | | } // namespace gl |
31 | | namespace gfx { |
32 | | class DataSourceSurface; |
33 | | } // namespace gfx |
34 | | |
35 | | namespace layers { |
36 | | |
37 | | class TextureSource; |
38 | | |
39 | | class CompositingRenderTargetOGL : public CompositingRenderTarget |
40 | | { |
41 | | typedef mozilla::gl::GLContext GLContext; |
42 | | |
43 | | friend class CompositorOGL; |
44 | | |
45 | | // For lazy initialisation of the GL stuff |
46 | | struct InitParams |
47 | | { |
48 | | InitParams() |
49 | | : mStatus(NO_PARAMS) |
50 | | , mFBOTextureTarget(0) |
51 | | , mInit(INIT_MODE_NONE) |
52 | 0 | {} |
53 | | InitParams(const gfx::IntSize& aSize, |
54 | | const gfx::IntSize& aPhySize, |
55 | | GLenum aFBOTextureTarget, |
56 | | SurfaceInitMode aInit) |
57 | | : mStatus(READY) |
58 | | , mSize(aSize) |
59 | | , mPhySize(aPhySize) |
60 | | , mFBOTextureTarget(aFBOTextureTarget) |
61 | | , mInit(aInit) |
62 | 0 | {} |
63 | | |
64 | | enum { |
65 | | NO_PARAMS, |
66 | | READY, |
67 | | INITIALIZED |
68 | | } mStatus; |
69 | | /* |
70 | | * Users of render target would draw in logical size, but it is |
71 | | * actually drawn to a surface in physical size. GL surfaces have |
72 | | * a limitation on their size, a smaller surface would be |
73 | | * allocated for the render target if the caller requests in a |
74 | | * size too big. |
75 | | */ |
76 | | gfx::IntSize mSize; // Logical size, the expected by callers. |
77 | | gfx::IntSize mPhySize; // Physical size, the real size of the surface. |
78 | | GLenum mFBOTextureTarget; |
79 | | SurfaceInitMode mInit; |
80 | | }; |
81 | | |
82 | | public: |
83 | | CompositingRenderTargetOGL(CompositorOGL* aCompositor, const gfx::IntPoint& aOrigin, |
84 | | GLuint aTexure, GLuint aFBO) |
85 | | : CompositingRenderTarget(aOrigin) |
86 | | , mInitParams() |
87 | | , mCompositor(aCompositor) |
88 | | , mGL(aCompositor->gl()) |
89 | | , mTextureHandle(aTexure) |
90 | | , mFBO(aFBO) |
91 | 0 | { |
92 | 0 | MOZ_ASSERT(mGL); |
93 | 0 | } |
94 | | |
95 | | ~CompositingRenderTargetOGL(); |
96 | | |
97 | 0 | virtual const char* Name() const override { return "CompositingRenderTargetOGL"; } |
98 | | |
99 | | /** |
100 | | * Create a render target around the default FBO, for rendering straight to |
101 | | * the window. |
102 | | */ |
103 | | static already_AddRefed<CompositingRenderTargetOGL> |
104 | | RenderTargetForWindow(CompositorOGL* aCompositor, |
105 | | const gfx::IntSize& aSize) |
106 | 0 | { |
107 | 0 | RefPtr<CompositingRenderTargetOGL> result |
108 | 0 | = new CompositingRenderTargetOGL(aCompositor, gfx::IntPoint(), 0, 0); |
109 | 0 | result->mInitParams = InitParams(aSize, aSize, 0, INIT_MODE_NONE); |
110 | 0 | result->mInitParams.mStatus = InitParams::INITIALIZED; |
111 | 0 | return result.forget(); |
112 | 0 | } |
113 | | |
114 | | /** |
115 | | * Some initialisation work on the backing FBO and texture. |
116 | | * We do this lazily so that when we first set this render target on the |
117 | | * compositor we do not have to re-bind the FBO after unbinding it, or |
118 | | * alternatively leave the FBO bound after creation. |
119 | | */ |
120 | | void Initialize(const gfx::IntSize& aSize, |
121 | | const gfx::IntSize& aPhySize, |
122 | | GLenum aFBOTextureTarget, |
123 | | SurfaceInitMode aInit) |
124 | 0 | { |
125 | 0 | MOZ_ASSERT(mInitParams.mStatus == InitParams::NO_PARAMS, "Initialized twice?"); |
126 | 0 | // postpone initialization until we actually want to use this render target |
127 | 0 | mInitParams = InitParams(aSize, aPhySize, aFBOTextureTarget, aInit); |
128 | 0 | } |
129 | | |
130 | | void BindTexture(GLenum aTextureUnit, GLenum aTextureTarget); |
131 | | |
132 | | /** |
133 | | * Call when we want to draw into our FBO |
134 | | */ |
135 | | void BindRenderTarget(); |
136 | | |
137 | 0 | bool IsWindow() { return GetFBO() == 0; } |
138 | | |
139 | | GLuint GetFBO() const |
140 | 0 | { |
141 | 0 | MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); |
142 | 0 | return mFBO; |
143 | 0 | } |
144 | | |
145 | | GLuint GetTextureHandle() const |
146 | 0 | { |
147 | 0 | MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED); |
148 | 0 | return mTextureHandle; |
149 | 0 | } |
150 | | |
151 | | // TextureSourceOGL |
152 | | TextureSourceOGL* AsSourceOGL() override |
153 | 0 | { |
154 | 0 | // XXX - Bug 900770 |
155 | 0 | MOZ_ASSERT(false, "CompositingRenderTargetOGL should not be used as a TextureSource"); |
156 | 0 | return nullptr; |
157 | 0 | } |
158 | | gfx::IntSize GetSize() const override |
159 | 0 | { |
160 | 0 | return mInitParams.mSize; |
161 | 0 | } |
162 | | |
163 | | gfx::SurfaceFormat GetFormat() const override |
164 | 0 | { |
165 | 0 | // XXX - Should it be implemented ? is the above assert true ? |
166 | 0 | MOZ_ASSERT(false, "Not implemented"); |
167 | 0 | return gfx::SurfaceFormat::UNKNOWN; |
168 | 0 | } |
169 | | |
170 | | #ifdef MOZ_DUMP_PAINTING |
171 | | virtual already_AddRefed<gfx::DataSourceSurface> Dump(Compositor* aCompositor) override; |
172 | | #endif |
173 | | |
174 | 0 | const gfx::IntSize& GetInitSize() const { |
175 | 0 | return mInitParams.mSize; |
176 | 0 | } |
177 | | |
178 | | private: |
179 | | /** |
180 | | * Actually do the initialisation. Note that we leave our FBO bound, and so |
181 | | * calling this method is only suitable when about to use this render target. |
182 | | */ |
183 | | void InitializeImpl(); |
184 | | |
185 | | InitParams mInitParams; |
186 | | /** |
187 | | * There is temporary a cycle between the compositor and the render target, |
188 | | * each having a strong ref to the other. The compositor's reference to |
189 | | * the target is always cleared at the end of a frame. |
190 | | */ |
191 | | RefPtr<CompositorOGL> mCompositor; |
192 | | RefPtr<GLContext> mGL; |
193 | | GLuint mTextureHandle; |
194 | | GLuint mFBO; |
195 | | }; |
196 | | |
197 | | } // namespace layers |
198 | | } // namespace mozilla |
199 | | |
200 | | #endif /* MOZILLA_GFX_SURFACEOGL_H */ |