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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/numerics/safe_math.h" | 6 #include "base/numerics/safe_math.h" |
7 #include "third_party/mesa/src/include/GL/osmesa.h" | 7 #include "third_party/mesa/src/include/GL/osmesa.h" |
8 #include "ui/gl/gl_bindings.h" | 8 #include "ui/gl/gl_bindings.h" |
9 #include "ui/gl/gl_context.h" | 9 #include "ui/gl/gl_context.h" |
10 #include "ui/gl/gl_surface_osmesa.h" | 10 #include "ui/gl/gl_surface_osmesa.h" |
11 #include "ui/gl/scoped_make_current.h" | 11 #include "ui/gl/scoped_make_current.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 | 14 |
15 GLSurfaceOSMesa::GLSurfaceOSMesa(OSMesaSurfaceFormat format, | 15 GLSurfaceOSMesa::GLSurfaceOSMesa(OSMesaSurfaceFormat format, |
16 const gfx::Size& size) | 16 const gfx::Size& size, |
17 : size_(size) { | 17 SurfaceConfiguration requested_configuration) |
| 18 : GLSurface(requested_configuration), size_(size) { |
18 switch (format) { | 19 switch (format) { |
19 case OSMesaSurfaceFormatBGRA: | 20 case OSMesaSurfaceFormatBGRA: |
20 format_ = OSMESA_BGRA; | 21 format_ = OSMESA_BGRA; |
21 break; | 22 break; |
22 case OSMesaSurfaceFormatRGBA: | 23 case OSMesaSurfaceFormatRGBA: |
23 format_ = OSMESA_RGBA; | 24 format_ = OSMESA_RGBA; |
24 break; | 25 break; |
25 } | 26 } |
26 // Implementations of OSMesa surface do not support having a 0 size. In such | 27 // Implementations of OSMesa surface do not support having a 0 size. In such |
27 // cases use a (1, 1) surface. | 28 // cases use a (1, 1) surface. |
28 if (size_.GetArea() == 0) | 29 if (size_.GetArea() == 0) |
29 size_.SetSize(1, 1); | 30 size_.SetSize(1, 1); |
30 } | 31 } |
31 | 32 |
32 bool GLSurfaceOSMesa::Initialize() { | 33 bool GLSurfaceOSMesa::Initialize() { |
33 return Resize(size_); | 34 return Resize(size_); |
34 } | 35 } |
35 | 36 |
36 void GLSurfaceOSMesa::Destroy() { | 37 void GLSurfaceOSMesa::Destroy() { |
37 buffer_.reset(); | 38 buffer_.reset(); |
38 } | 39 } |
39 | 40 |
| 41 void* GLSurfaceOSMesa::GetConfig() { |
| 42 // TODO(iansf): Possibly choose a configuration in a manner similar to |
| 43 // NativeViewGLSurfaceEGL::GetConfig, using the gfx::SurfaceConfiguration |
| 44 // returned by GLSurface::GetSurfaceConfiguration. |
| 45 NOTIMPLEMENTED(); |
| 46 return NULL; |
| 47 } |
| 48 |
40 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) { | 49 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) { |
41 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; | 50 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
42 GLContext* current_context = GLContext::GetCurrent(); | 51 GLContext* current_context = GLContext::GetCurrent(); |
43 bool was_current = | 52 bool was_current = |
44 current_context && current_context->IsCurrent(this); | 53 current_context && current_context->IsCurrent(this); |
45 if (was_current) { | 54 if (was_current) { |
46 scoped_make_current.reset( | 55 scoped_make_current.reset( |
47 new ui::ScopedMakeCurrent(current_context, this)); | 56 new ui::ScopedMakeCurrent(current_context, this)); |
48 current_context->ReleaseCurrent(this); | 57 current_context->ReleaseCurrent(this); |
49 } | 58 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 111 } |
103 | 112 |
104 GLSurfaceOSMesa::~GLSurfaceOSMesa() { | 113 GLSurfaceOSMesa::~GLSurfaceOSMesa() { |
105 Destroy(); | 114 Destroy(); |
106 } | 115 } |
107 | 116 |
108 bool GLSurfaceOSMesaHeadless::IsOffscreen() { return false; } | 117 bool GLSurfaceOSMesaHeadless::IsOffscreen() { return false; } |
109 | 118 |
110 bool GLSurfaceOSMesaHeadless::SwapBuffers() { return true; } | 119 bool GLSurfaceOSMesaHeadless::SwapBuffers() { return true; } |
111 | 120 |
112 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() | 121 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless( |
113 : GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, gfx::Size(1, 1)) { | 122 SurfaceConfiguration requested_configuration) |
| 123 : GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, |
| 124 gfx::Size(1, 1), |
| 125 requested_configuration) { |
| 126 } |
| 127 |
| 128 void* GLSurfaceOSMesaHeadless::GetConfig() { |
| 129 // TODO(iansf): Possibly choose a configuration in a manner similar to |
| 130 // NativeViewGLSurfaceEGL::GetConfig, using the gfx::SurfaceConfiguration |
| 131 // returned by GLSurface::GetSurfaceConfiguration. |
| 132 NOTIMPLEMENTED(); |
| 133 return NULL; |
114 } | 134 } |
115 | 135 |
116 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } | 136 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } |
117 | 137 |
118 } // namespace gfx | 138 } // namespace gfx |
OLD | NEW |