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 #include "ui/gl/gl_surface.h" | 5 #include "ui/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 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" | 10 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" |
11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
12 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" |
13 #include "ui/gl/gl_surface_egl.h" | 13 #include "ui/gl/gl_surface_egl.h" |
14 #include "ui/gl/gl_surface_glx.h" | 14 #include "ui/gl/gl_surface_glx.h" |
15 #include "ui/gl/gl_surface_osmesa.h" | 15 #include "ui/gl/gl_surface_osmesa.h" |
16 #include "ui/gl/gl_surface_stub.h" | 16 #include "ui/gl/gl_surface_stub.h" |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 | 19 |
20 namespace { | 20 namespace { |
21 Display* g_osmesa_display; | 21 Display* g_osmesa_display; |
22 } // namespace anonymous | 22 } // namespace anonymous |
23 | 23 |
24 // This OSMesa GL surface can use XLib to swap the contents of the buffer to a | 24 // This OSMesa GL surface can use XLib to swap the contents of the buffer to a |
25 // view. | 25 // view. |
26 class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { | 26 class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { |
27 public: | 27 public: |
28 explicit NativeViewGLSurfaceOSMesa(gfx::AcceleratedWidget window); | 28 explicit NativeViewGLSurfaceOSMesa(gfx::AcceleratedWidget window); |
29 virtual ~NativeViewGLSurfaceOSMesa(); | |
30 | 29 |
31 static bool InitializeOneOff(); | 30 static bool InitializeOneOff(); |
32 | 31 |
33 // Implement a subset of GLSurface. | 32 // Implement a subset of GLSurface. |
34 virtual bool Initialize() OVERRIDE; | 33 virtual bool Initialize() OVERRIDE; |
35 virtual void Destroy() OVERRIDE; | 34 virtual void Destroy() OVERRIDE; |
36 virtual bool Resize(const gfx::Size& new_size) OVERRIDE; | 35 virtual bool Resize(const gfx::Size& new_size) OVERRIDE; |
37 virtual bool IsOffscreen() OVERRIDE; | 36 virtual bool IsOffscreen() OVERRIDE; |
38 virtual bool SwapBuffers() OVERRIDE; | 37 virtual bool SwapBuffers() OVERRIDE; |
39 virtual std::string GetExtensions() OVERRIDE; | 38 virtual std::string GetExtensions() OVERRIDE; |
40 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 39 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
41 | 40 |
| 41 protected: |
| 42 virtual ~NativeViewGLSurfaceOSMesa(); |
| 43 |
42 private: | 44 private: |
43 GC window_graphics_context_; | 45 GC window_graphics_context_; |
44 gfx::AcceleratedWidget window_; | 46 gfx::AcceleratedWidget window_; |
45 GC pixmap_graphics_context_; | 47 GC pixmap_graphics_context_; |
46 Pixmap pixmap_; | 48 Pixmap pixmap_; |
47 | 49 |
48 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); | 50 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); |
49 }; | 51 }; |
50 | 52 |
51 bool GLSurface::InitializeOneOffInternal() { | 53 bool GLSurface::InitializeOneOffInternal() { |
(...skipping 26 matching lines...) Expand all Loading... |
78 NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa( | 80 NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa( |
79 gfx::AcceleratedWidget window) | 81 gfx::AcceleratedWidget window) |
80 : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size(1, 1)), | 82 : GLSurfaceOSMesa(OSMESA_BGRA, gfx::Size(1, 1)), |
81 window_graphics_context_(0), | 83 window_graphics_context_(0), |
82 window_(window), | 84 window_(window), |
83 pixmap_graphics_context_(0), | 85 pixmap_graphics_context_(0), |
84 pixmap_(0) { | 86 pixmap_(0) { |
85 DCHECK(window); | 87 DCHECK(window); |
86 } | 88 } |
87 | 89 |
88 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { | |
89 Destroy(); | |
90 } | |
91 | |
92 bool NativeViewGLSurfaceOSMesa::InitializeOneOff() { | 90 bool NativeViewGLSurfaceOSMesa::InitializeOneOff() { |
93 static bool initialized = false; | 91 static bool initialized = false; |
94 if (initialized) | 92 if (initialized) |
95 return true; | 93 return true; |
96 | 94 |
97 g_osmesa_display = base::MessagePumpForUI::GetDefaultXDisplay(); | 95 g_osmesa_display = base::MessagePumpForUI::GetDefaultXDisplay(); |
98 if (!g_osmesa_display) { | 96 if (!g_osmesa_display) { |
99 LOG(ERROR) << "XOpenDisplay failed."; | 97 LOG(ERROR) << "XOpenDisplay failed."; |
100 return false; | 98 return false; |
101 } | 99 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 pixmap_, | 251 pixmap_, |
254 window_, | 252 window_, |
255 window_graphics_context_, | 253 window_graphics_context_, |
256 x, y, | 254 x, y, |
257 width, height, | 255 width, height, |
258 x, y); | 256 x, y); |
259 | 257 |
260 return true; | 258 return true; |
261 } | 259 } |
262 | 260 |
| 261 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { |
| 262 Destroy(); |
| 263 } |
| 264 |
263 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 265 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
264 bool software, | 266 bool software, |
265 gfx::AcceleratedWidget window) { | 267 gfx::AcceleratedWidget window) { |
266 if (software) | 268 if (software) |
267 return NULL; | 269 return NULL; |
268 | 270 |
269 switch (GetGLImplementation()) { | 271 switch (GetGLImplementation()) { |
270 case kGLImplementationOSMesaGL: { | 272 case kGLImplementationOSMesaGL: { |
271 scoped_refptr<GLSurface> surface( | 273 scoped_refptr<GLSurface> surface( |
272 new NativeViewGLSurfaceOSMesa(window)); | 274 new NativeViewGLSurfaceOSMesa(window)); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 332 } |
331 case kGLImplementationMockGL: | 333 case kGLImplementationMockGL: |
332 return new GLSurfaceStub; | 334 return new GLSurfaceStub; |
333 default: | 335 default: |
334 NOTREACHED(); | 336 NOTREACHED(); |
335 return NULL; | 337 return NULL; |
336 } | 338 } |
337 } | 339 } |
338 | 340 |
339 } // namespace gfx | 341 } // namespace gfx |
OLD | NEW |