OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "ui/gfx/gl/gl_surface.h" | 5 #include "ui/gfx/gl/gl_surface.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #if !defined(USE_WAYLAND) |
9 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" | 10 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" |
| 11 #endif |
10 #include "ui/gfx/gl/gl_bindings.h" | 12 #include "ui/gfx/gl/gl_bindings.h" |
11 #include "ui/gfx/gl/gl_implementation.h" | 13 #include "ui/gfx/gl/gl_implementation.h" |
12 #include "ui/gfx/gl/gl_surface_egl.h" | 14 #include "ui/gfx/gl/gl_surface_egl.h" |
| 15 #if !defined(USE_WAYLAND) |
13 #include "ui/gfx/gl/gl_surface_glx.h" | 16 #include "ui/gfx/gl/gl_surface_glx.h" |
14 #include "ui/gfx/gl/gl_surface_osmesa.h" | 17 #include "ui/gfx/gl/gl_surface_osmesa.h" |
| 18 #endif |
15 #include "ui/gfx/gl/gl_surface_stub.h" | 19 #include "ui/gfx/gl/gl_surface_stub.h" |
16 | 20 |
17 namespace gfx { | 21 namespace gfx { |
18 | 22 |
| 23 #if !defined(USE_WAYLAND) |
| 24 |
19 namespace { | 25 namespace { |
20 Display* g_osmesa_display; | 26 Display* g_osmesa_display; |
21 } // namespace anonymous | 27 } // namespace anonymous |
22 | 28 |
23 // This OSMesa GL surface can use XLib to swap the contents of the buffer to a | 29 // This OSMesa GL surface can use XLib to swap the contents of the buffer to a |
24 // view. | 30 // view. |
25 class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { | 31 class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { |
26 public: | 32 public: |
27 explicit NativeViewGLSurfaceOSMesa(gfx::PluginWindowHandle window); | 33 explicit NativeViewGLSurfaceOSMesa(gfx::PluginWindowHandle window); |
28 virtual ~NativeViewGLSurfaceOSMesa(); | 34 virtual ~NativeViewGLSurfaceOSMesa(); |
(...skipping 12 matching lines...) Expand all Loading... |
41 bool UpdateSize(); | 47 bool UpdateSize(); |
42 | 48 |
43 GC window_graphics_context_; | 49 GC window_graphics_context_; |
44 gfx::PluginWindowHandle window_; | 50 gfx::PluginWindowHandle window_; |
45 GC pixmap_graphics_context_; | 51 GC pixmap_graphics_context_; |
46 Pixmap pixmap_; | 52 Pixmap pixmap_; |
47 | 53 |
48 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); | 54 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); |
49 }; | 55 }; |
50 | 56 |
| 57 #endif // !USE_WAYLAND |
| 58 |
51 bool GLSurface::InitializeOneOffInternal() { | 59 bool GLSurface::InitializeOneOffInternal() { |
52 switch (GetGLImplementation()) { | 60 switch (GetGLImplementation()) { |
| 61 #if !defined(USE_WAYLAND) |
53 case kGLImplementationDesktopGL: | 62 case kGLImplementationDesktopGL: |
54 if (!GLSurfaceGLX::InitializeOneOff()) { | 63 if (!GLSurfaceGLX::InitializeOneOff()) { |
55 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; | 64 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; |
56 return false; | 65 return false; |
57 } | 66 } |
58 break; | 67 break; |
59 case kGLImplementationEGLGLES2: | |
60 if (!GLSurfaceEGL::InitializeOneOff()) { | |
61 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | |
62 return false; | |
63 } | |
64 break; | |
65 case kGLImplementationOSMesaGL: | 68 case kGLImplementationOSMesaGL: |
66 if (!NativeViewGLSurfaceOSMesa::InitializeOneOff()) { | 69 if (!NativeViewGLSurfaceOSMesa::InitializeOneOff()) { |
67 LOG(ERROR) << "NativeViewGLSurfaceOSMesa::InitializeOneOff failed."; | 70 LOG(ERROR) << "NativeViewGLSurfaceOSMesa::InitializeOneOff failed."; |
68 return false; | 71 return false; |
69 } | 72 } |
70 break; | 73 break; |
| 74 #endif |
| 75 case kGLImplementationEGLGLES2: |
| 76 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 77 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 78 return false; |
| 79 } |
| 80 break; |
71 default: | 81 default: |
72 break; | 82 break; |
73 } | 83 } |
74 | 84 |
75 return true; | 85 return true; |
76 } | 86 } |
77 | 87 |
| 88 #if !defined(USE_WAYLAND) |
| 89 |
78 NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa( | 90 NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa( |
79 gfx::PluginWindowHandle window) | 91 gfx::PluginWindowHandle window) |
80 : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size()), | 92 : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size()), |
81 window_graphics_context_(0), | 93 window_graphics_context_(0), |
82 window_(window), | 94 window_(window), |
83 pixmap_graphics_context_(0), | 95 pixmap_graphics_context_(0), |
84 pixmap_(0) { | 96 pixmap_(0) { |
85 DCHECK(window); | 97 DCHECK(window); |
86 } | 98 } |
87 | 99 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // Recreate a graphics context for the pixmap. | 236 // Recreate a graphics context for the pixmap. |
225 pixmap_graphics_context_ = XCreateGC(g_osmesa_display, pixmap_, 0, NULL); | 237 pixmap_graphics_context_ = XCreateGC(g_osmesa_display, pixmap_, 0, NULL); |
226 if (!pixmap_graphics_context_) { | 238 if (!pixmap_graphics_context_) { |
227 LOG(ERROR) << "XCreateGC failed"; | 239 LOG(ERROR) << "XCreateGC failed"; |
228 return false; | 240 return false; |
229 } | 241 } |
230 | 242 |
231 return true; | 243 return true; |
232 } | 244 } |
233 | 245 |
| 246 #endif // !USE_WAYLAND |
| 247 |
234 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 248 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
235 bool software, | 249 bool software, |
236 gfx::PluginWindowHandle window) { | 250 gfx::PluginWindowHandle window) { |
237 if (software) | 251 if (software) |
238 return NULL; | 252 return NULL; |
239 | 253 |
240 switch (GetGLImplementation()) { | 254 switch (GetGLImplementation()) { |
| 255 #if !defined(USE_WAYLAND) |
241 case kGLImplementationOSMesaGL: { | 256 case kGLImplementationOSMesaGL: { |
242 scoped_refptr<GLSurface> surface( | 257 scoped_refptr<GLSurface> surface( |
243 new NativeViewGLSurfaceOSMesa(window)); | 258 new NativeViewGLSurfaceOSMesa(window)); |
244 if (!surface->Initialize()) | 259 if (!surface->Initialize()) |
245 return NULL; | 260 return NULL; |
246 | 261 |
247 return surface; | 262 return surface; |
248 } | 263 } |
249 case kGLImplementationEGLGLES2: { | |
250 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGL( | |
251 false, window)); | |
252 if (!surface->Initialize()) | |
253 return NULL; | |
254 | |
255 return surface; | |
256 } | |
257 case kGLImplementationDesktopGL: { | 264 case kGLImplementationDesktopGL: { |
258 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLX( | 265 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLX( |
259 window)); | 266 window)); |
260 if (!surface->Initialize()) | 267 if (!surface->Initialize()) |
261 return NULL; | 268 return NULL; |
262 | 269 |
| 270 return surface; |
| 271 } |
| 272 #endif |
| 273 case kGLImplementationEGLGLES2: { |
| 274 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGL( |
| 275 false, window)); |
| 276 if (!surface->Initialize()) |
| 277 return NULL; |
| 278 |
263 return surface; | 279 return surface; |
264 } | 280 } |
265 case kGLImplementationMockGL: | 281 case kGLImplementationMockGL: |
266 return new GLSurfaceStub; | 282 return new GLSurfaceStub; |
267 default: | 283 default: |
268 NOTREACHED(); | 284 NOTREACHED(); |
269 return NULL; | 285 return NULL; |
270 } | 286 } |
271 } | 287 } |
272 | 288 |
273 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | 289 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
274 bool software, | 290 bool software, |
275 const gfx::Size& size) { | 291 const gfx::Size& size) { |
276 if (software) | 292 if (software) |
277 return NULL; | 293 return NULL; |
278 | 294 |
279 switch (GetGLImplementation()) { | 295 switch (GetGLImplementation()) { |
| 296 #if !defined(USE_WAYLAND) |
280 case kGLImplementationOSMesaGL: { | 297 case kGLImplementationOSMesaGL: { |
281 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA, | 298 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA, |
282 size)); | 299 size)); |
283 if (!surface->Initialize()) | 300 if (!surface->Initialize()) |
284 return NULL; | 301 return NULL; |
285 | 302 |
286 return surface; | 303 return surface; |
287 } | 304 } |
288 case kGLImplementationEGLGLES2: { | |
289 scoped_refptr<GLSurface> surface(new PbufferGLSurfaceEGL(false, size)); | |
290 if (!surface->Initialize()) | |
291 return NULL; | |
292 | |
293 return surface; | |
294 } | |
295 case kGLImplementationDesktopGL: { | 305 case kGLImplementationDesktopGL: { |
296 scoped_refptr<GLSurface> surface(new PbufferGLSurfaceGLX(size)); | 306 scoped_refptr<GLSurface> surface(new PbufferGLSurfaceGLX(size)); |
297 if (!surface->Initialize()) | 307 if (!surface->Initialize()) |
298 return NULL; | 308 return NULL; |
299 | 309 |
| 310 return surface; |
| 311 } |
| 312 #endif |
| 313 case kGLImplementationEGLGLES2: { |
| 314 scoped_refptr<GLSurface> surface(new PbufferGLSurfaceEGL(false, size)); |
| 315 if (!surface->Initialize()) |
| 316 return NULL; |
| 317 |
300 return surface; | 318 return surface; |
301 } | 319 } |
302 case kGLImplementationMockGL: | 320 case kGLImplementationMockGL: |
303 return new GLSurfaceStub; | 321 return new GLSurfaceStub; |
304 default: | 322 default: |
305 NOTREACHED(); | 323 NOTREACHED(); |
306 return NULL; | 324 return NULL; |
307 } | 325 } |
308 } | 326 } |
309 | 327 |
310 } // namespace gfx | 328 } // namespace gfx |
OLD | NEW |