| 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 gfx { | 16 namespace gfx { |
| 17 | 17 |
| 18 GLSurfaceOSMesa::GLSurfaceOSMesa(OSMesaSurfaceFormat format, | 18 GLSurfaceOSMesa::GLSurfaceOSMesa(GLSurface::Format format, |
| 19 const gfx::Size& size) | 19 const gfx::Size& size) |
| 20 : size_(size) { | 20 : size_(size), |
| 21 switch (format) { | 21 format_(format) { |
| 22 case OSMesaSurfaceFormatBGRA: | |
| 23 format_ = OSMESA_BGRA; | |
| 24 break; | |
| 25 case OSMesaSurfaceFormatRGBA: | |
| 26 format_ = OSMESA_RGBA; | |
| 27 break; | |
| 28 } | |
| 29 // 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 |
| 30 // cases use a (1, 1) surface. | 23 // cases use a (1, 1) surface. |
| 31 if (size_.GetArea() == 0) | 24 if (size_.GetArea() == 0) |
| 32 size_.SetSize(1, 1); | 25 size_.SetSize(1, 1); |
| 33 } | 26 } |
| 34 | 27 |
| 35 bool GLSurfaceOSMesa::Initialize(GLSurface::Format format) { | 28 bool GLSurfaceOSMesa::Initialize(GLSurface::Format format) { |
| 36 return Resize(size_, 1.f, true); | 29 return Resize(size_, 1.f, true); |
| 37 } | 30 } |
| 38 | 31 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 88 } |
| 96 | 89 |
| 97 gfx::Size GLSurfaceOSMesa::GetSize() { | 90 gfx::Size GLSurfaceOSMesa::GetSize() { |
| 98 return size_; | 91 return size_; |
| 99 } | 92 } |
| 100 | 93 |
| 101 void* GLSurfaceOSMesa::GetHandle() { | 94 void* GLSurfaceOSMesa::GetHandle() { |
| 102 return buffer_.get(); | 95 return buffer_.get(); |
| 103 } | 96 } |
| 104 | 97 |
| 105 unsigned GLSurfaceOSMesa::GetFormat() { | 98 GLSurface::Format GLSurfaceOSMesa::GetFormat() { |
| 106 return format_; | 99 return format_; |
| 107 } | 100 } |
| 108 | 101 |
| 109 GLSurfaceOSMesa::~GLSurfaceOSMesa() { | 102 GLSurfaceOSMesa::~GLSurfaceOSMesa() { |
| 110 Destroy(); | 103 Destroy(); |
| 111 } | 104 } |
| 112 | 105 |
| 113 bool GLSurfaceOSMesaHeadless::IsOffscreen() { return false; } | 106 bool GLSurfaceOSMesaHeadless::IsOffscreen() { return false; } |
| 114 | 107 |
| 115 gfx::SwapResult GLSurfaceOSMesaHeadless::SwapBuffers() { | 108 gfx::SwapResult GLSurfaceOSMesaHeadless::SwapBuffers() { |
| 116 return gfx::SwapResult::SWAP_ACK; | 109 return gfx::SwapResult::SWAP_ACK; |
| 117 } | 110 } |
| 118 | 111 |
| 119 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() | 112 GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless() |
| 120 : GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, gfx::Size(1, 1)) { | 113 : GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, gfx::Size(1, 1)) { |
| 121 } | 114 } |
| 122 | 115 |
| 123 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } | 116 GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); } |
| 124 | 117 |
| 125 } // namespace gfx | 118 } // namespace gfx |
| OLD | NEW |