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