OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GL_GL_SURFACE_H_ | 5 #ifndef UI_GL_GL_SURFACE_H_ |
6 #define UI_GL_GL_SURFACE_H_ | 6 #define UI_GL_GL_SURFACE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
14 #include "ui/gfx/geometry/rect_f.h" | 14 #include "ui/gfx/geometry/rect_f.h" |
15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/gfx/overlay_transform.h" | 17 #include "ui/gfx/overlay_transform.h" |
18 #include "ui/gl/gl_export.h" | 18 #include "ui/gl/gl_export.h" |
19 #include "ui/gl/gl_implementation.h" | 19 #include "ui/gl/gl_implementation.h" |
20 | 20 |
21 namespace gfx { | 21 namespace gfx { |
22 | 22 |
23 class GLContext; | 23 class GLContext; |
24 class GLImage; | 24 class GLImage; |
25 class VSyncProvider; | 25 class VSyncProvider; |
26 | 26 |
| 27 struct SurfaceConfiguration { |
| 28 uint8_t red_bits = 8; |
| 29 uint8_t green_bits = 8; |
| 30 uint8_t blue_bits = 8; |
| 31 uint8_t alpha_bits = 8; |
| 32 uint8_t depth_bits = 0; |
| 33 uint8_t stencil_bits = 0; |
| 34 }; |
| 35 |
27 // Encapsulates a surface that can be rendered to with GL, hiding platform | 36 // Encapsulates a surface that can be rendered to with GL, hiding platform |
28 // specific management. | 37 // specific management. |
29 class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> { | 38 class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> { |
30 public: | 39 public: |
31 GLSurface(); | 40 explicit GLSurface(const gfx::SurfaceConfiguration requested_configuration); |
32 | 41 |
33 // (Re)create the surface. TODO(apatrick): This is an ugly hack to allow the | 42 // (Re)create the surface. TODO(apatrick): This is an ugly hack to allow the |
34 // EGL surface associated to be recreated without destroying the associated | 43 // EGL surface associated to be recreated without destroying the associated |
35 // context. The implementation of this function for other GLSurface derived | 44 // context. The implementation of this function for other GLSurface derived |
36 // classes is in a pending changelist. | 45 // classes is in a pending changelist. |
37 virtual bool Initialize(); | 46 virtual bool Initialize(); |
38 | 47 |
39 // Destroys the surface. | 48 // Destroys the surface. |
40 virtual void Destroy() = 0; | 49 virtual void Destroy() = 0; |
41 | 50 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 virtual bool ScheduleOverlayPlane(int z_order, | 156 virtual bool ScheduleOverlayPlane(int z_order, |
148 OverlayTransform transform, | 157 OverlayTransform transform, |
149 GLImage* image, | 158 GLImage* image, |
150 const Rect& bounds_rect, | 159 const Rect& bounds_rect, |
151 const RectF& crop_rect); | 160 const RectF& crop_rect); |
152 | 161 |
153 virtual bool IsSurfaceless() const; | 162 virtual bool IsSurfaceless() const; |
154 | 163 |
155 // Create a GL surface that renders directly to a view. | 164 // Create a GL surface that renders directly to a view. |
156 static scoped_refptr<GLSurface> CreateViewGLSurface( | 165 static scoped_refptr<GLSurface> CreateViewGLSurface( |
157 gfx::AcceleratedWidget window); | 166 gfx::AcceleratedWidget window, |
| 167 const gfx::SurfaceConfiguration& requested_configuration); |
158 | 168 |
159 #if defined(USE_OZONE) | 169 #if defined(USE_OZONE) |
160 // Create a GL surface that renders directly into a window with surfaceless | 170 // Create a GL surface that renders directly into a window with surfaceless |
161 // semantics - there is no default framebuffer and the primary surface must | 171 // semantics - there is no default framebuffer and the primary surface must |
162 // be presented as an overlay. If surfaceless mode is not supported or | 172 // be presented as an overlay. If surfaceless mode is not supported or |
163 // enabled it will return a null pointer. | 173 // enabled it will return a null pointer. |
164 static scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( | 174 static scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( |
165 gfx::AcceleratedWidget window); | 175 gfx::AcceleratedWidget window, |
| 176 const gfx::SurfaceConfiguration& requested_configuration); |
166 #endif // defined(USE_OZONE) | 177 #endif // defined(USE_OZONE) |
167 | 178 |
168 // Create a GL surface used for offscreen rendering. | 179 // Create a GL surface used for offscreen rendering. |
169 static scoped_refptr<GLSurface> CreateOffscreenGLSurface( | 180 static scoped_refptr<GLSurface> CreateOffscreenGLSurface( |
170 const gfx::Size& size); | 181 const gfx::Size& size, |
| 182 const gfx::SurfaceConfiguration& requested_configuration); |
171 | 183 |
172 static GLSurface* GetCurrent(); | 184 static GLSurface* GetCurrent(); |
173 | 185 |
174 // Called when the swap interval for the associated context changes. | 186 // Called when the swap interval for the associated context changes. |
175 virtual void OnSetSwapInterval(int interval); | 187 virtual void OnSetSwapInterval(int interval); |
176 | 188 |
| 189 const gfx::SurfaceConfiguration get_surface_configuration() { |
| 190 return surface_configuration_; |
| 191 } |
| 192 |
177 protected: | 193 protected: |
178 virtual ~GLSurface(); | 194 virtual ~GLSurface(); |
179 static bool InitializeOneOffImplementation(GLImplementation impl, | 195 static bool InitializeOneOffImplementation(GLImplementation impl, |
180 bool fallback_to_osmesa, | 196 bool fallback_to_osmesa, |
181 bool gpu_service_logging, | 197 bool gpu_service_logging, |
182 bool disable_gl_drawing); | 198 bool disable_gl_drawing); |
183 static bool InitializeOneOffInternal(); | 199 static bool InitializeOneOffInternal(); |
184 static void SetCurrent(GLSurface* surface); | 200 static void SetCurrent(GLSurface* surface); |
185 | 201 |
186 static bool ExtensionsContain(const char* extensions, const char* name); | 202 static bool ExtensionsContain(const char* extensions, const char* name); |
187 | 203 |
188 private: | 204 private: |
189 friend class base::RefCounted<GLSurface>; | 205 friend class base::RefCounted<GLSurface>; |
190 friend class GLContext; | 206 friend class GLContext; |
191 | 207 |
| 208 gfx::SurfaceConfiguration surface_configuration_; |
| 209 |
192 DISALLOW_COPY_AND_ASSIGN(GLSurface); | 210 DISALLOW_COPY_AND_ASSIGN(GLSurface); |
193 }; | 211 }; |
194 | 212 |
195 // Implementation of GLSurface that forwards all calls through to another | 213 // Implementation of GLSurface that forwards all calls through to another |
196 // GLSurface. | 214 // GLSurface. |
197 class GL_EXPORT GLSurfaceAdapter : public GLSurface { | 215 class GL_EXPORT GLSurfaceAdapter : public GLSurface { |
198 public: | 216 public: |
199 explicit GLSurfaceAdapter(GLSurface* surface); | 217 explicit GLSurfaceAdapter(GLSurface* surface); |
200 | 218 |
201 bool Initialize() override; | 219 bool Initialize() override; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 256 |
239 private: | 257 private: |
240 scoped_refptr<GLSurface> surface_; | 258 scoped_refptr<GLSurface> surface_; |
241 | 259 |
242 DISALLOW_COPY_AND_ASSIGN(GLSurfaceAdapter); | 260 DISALLOW_COPY_AND_ASSIGN(GLSurfaceAdapter); |
243 }; | 261 }; |
244 | 262 |
245 } // namespace gfx | 263 } // namespace gfx |
246 | 264 |
247 #endif // UI_GL_GL_SURFACE_H_ | 265 #endif // UI_GL_GL_SURFACE_H_ |
OLD | NEW |