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