| 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_osmesa.h" | 5 #include "ui/gl/gl_surface_osmesa.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/numerics/safe_math.h" | 10 #include "base/numerics/safe_math.h" |
| 11 #include "third_party/mesa/src/include/GL/osmesa.h" | 11 #include "third_party/mesa/src/include/GL/osmesa.h" |
| 12 #include "ui/gl/gl_bindings.h" | 12 #include "ui/gl/gl_bindings.h" |
| 13 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
| 14 #include "ui/gl/scoped_make_current.h" | 14 #include "ui/gl/scoped_make_current.h" |
| 15 | 15 |
| 16 namespace gl { | 16 namespace gl { |
| 17 | 17 |
| 18 GLSurfaceOSMesa::GLSurfaceOSMesa(GLSurface::Format format, | 18 GLSurfaceOSMesa::GLSurfaceOSMesa(GLSurfaceFormat format, |
| 19 const gfx::Size& size) | 19 const gfx::Size& size) |
| 20 : size_(size), | 20 : size_(size), |
| 21 format_(format) { | 21 format_(format) { |
| 22 // Implementations of OSMesa surface do not support having a 0 size. In such | 22 // Implementations of OSMesa surface do not support having a 0 size. In such |
| 23 // cases use a (1, 1) surface. | 23 // cases use a (1, 1) surface. |
| 24 if (size_.GetArea() == 0) | 24 if (size_.GetArea() == 0) |
| 25 size_.SetSize(1, 1); | 25 size_.SetSize(1, 1); |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool GLSurfaceOSMesa::Initialize(GLSurface::Format format) { | 28 bool GLSurfaceOSMesa::Initialize(GLSurfaceFormat format) { |
| 29 return Resize(size_, 1.f, true); | 29 return Resize(size_, 1.f, true); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void GLSurfaceOSMesa::Destroy() { | 32 void GLSurfaceOSMesa::Destroy() { |
| 33 buffer_.reset(); | 33 buffer_.reset(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size, | 36 bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size, |
| 37 float scale_factor, | 37 float scale_factor, |
| 38 bool has_alpha) { | 38 bool has_alpha) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 gfx::Size GLSurfaceOSMesa::GetSize() { | 90 gfx::Size GLSurfaceOSMesa::GetSize() { |
| 91 return size_; | 91 return size_; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void* GLSurfaceOSMesa::GetHandle() { | 94 void* GLSurfaceOSMesa::GetHandle() { |
| 95 return buffer_.get(); | 95 return buffer_.get(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 GLSurface::Format GLSurfaceOSMesa::GetFormat() { | 98 GLSurfaceFormat GLSurfaceOSMesa::GetFormat() { |
| 99 return format_; | 99 return format_; |
| 100 } | 100 } |
| 101 | 101 |
| 102 GLSurfaceOSMesa::~GLSurfaceOSMesa() { | 102 GLSurfaceOSMesa::~GLSurfaceOSMesa() { |
| 103 Destroy(); | 103 Destroy(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool GLSurfaceOSMesaHeadless::IsOffscreen() { return false; } | 106 bool GLSurfaceOSMesaHeadless::IsOffscreen() { return false; } |
| 107 | 107 |
| 108 gfx::SwapResult GLSurfaceOSMesaHeadless::SwapBuffers() { | 108 gfx::SwapResult GLSurfaceOSMesaHeadless::SwapBuffers() { |
| 109 return gfx::SwapResult::SWAP_ACK; | 109 return gfx::SwapResult::SWAP_ACK; |
| 110 } | 110 } |
| 111 | 111 |
| 112 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() | 112 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() |
| 113 : GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, gfx::Size(1, 1)) { | 113 : GLSurfaceOSMesa( |
| 114 GLSurfaceFormat(GLSurfaceFormat::PIXEL_LAYOUT_BGRA), |
| 115 gfx::Size(1, 1)) { |
| 114 } | 116 } |
| 115 | 117 |
| 116 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } | 118 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } |
| 117 | 119 |
| 118 } // namespace gl | 120 } // namespace gl |
| OLD | NEW |