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