OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/gl/gl_surface.h" | 5 #include "ui/gfx/gl/gl_surface.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #if !defined(USE_WAYLAND) | 9 #if !defined(USE_WAYLAND) |
10 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" | 10 #include "third_party/mesa/MesaLib/include/GL/osmesa.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 static bool InitializeOneOff(); | 36 static bool InitializeOneOff(); |
37 | 37 |
38 // Initializes the GL context. | 38 // Initializes the GL context. |
39 bool Initialize(); | 39 bool Initialize(); |
40 | 40 |
41 // Implement a subset of GLSurface. | 41 // Implement a subset of GLSurface. |
42 virtual void Destroy(); | 42 virtual void Destroy(); |
43 virtual bool IsOffscreen(); | 43 virtual bool IsOffscreen(); |
44 virtual bool SwapBuffers(); | 44 virtual bool SwapBuffers(); |
| 45 virtual std::string GetExtensions(); |
| 46 virtual bool PostSubBuffer(int x, int y, int width, int height); |
45 | 47 |
46 private: | 48 private: |
47 bool UpdateSize(); | 49 bool UpdateSize(); |
48 | 50 |
49 GC window_graphics_context_; | 51 GC window_graphics_context_; |
50 gfx::PluginWindowHandle window_; | 52 gfx::PluginWindowHandle window_; |
51 GC pixmap_graphics_context_; | 53 GC pixmap_graphics_context_; |
52 Pixmap pixmap_; | 54 Pixmap pixmap_; |
53 | 55 |
54 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); | 56 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 pixmap_, | 189 pixmap_, |
188 window_, | 190 window_, |
189 window_graphics_context_, | 191 window_graphics_context_, |
190 0, 0, | 192 0, 0, |
191 size.width(), size.height(), | 193 size.width(), size.height(), |
192 0, 0); | 194 0, 0); |
193 | 195 |
194 return true; | 196 return true; |
195 } | 197 } |
196 | 198 |
| 199 std::string NativeViewGLSurfaceOSMesa::GetExtensions() { |
| 200 std::string extensions = gfx::GLSurfaceOSMesa::GetExtensions(); |
| 201 extensions += extensions.empty() ? "" : " "; |
| 202 extensions += "GL_CHROMIUM_post_sub_buffer"; |
| 203 return extensions; |
| 204 } |
| 205 |
| 206 bool NativeViewGLSurfaceOSMesa::PostSubBuffer( |
| 207 int x, int y, int width, int height) { |
| 208 // Update the size before blitting so that the blit size is exactly the same |
| 209 // as the window. |
| 210 if (!UpdateSize()) { |
| 211 LOG(ERROR) << "Failed to update size of GLContextOSMesa."; |
| 212 return false; |
| 213 } |
| 214 |
| 215 gfx::Size size = GetSize(); |
| 216 |
| 217 // Move (0,0) from lower-left to upper-left |
| 218 y = size.height() - y - height; |
| 219 |
| 220 XWindowAttributes attributes; |
| 221 if (!XGetWindowAttributes(g_osmesa_display, window_, &attributes)) { |
| 222 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
| 223 return false; |
| 224 } |
| 225 |
| 226 // Copy the frame into the pixmap. |
| 227 ui::PutARGBImage(g_osmesa_display, |
| 228 attributes.visual, |
| 229 attributes.depth, |
| 230 pixmap_, |
| 231 pixmap_graphics_context_, |
| 232 static_cast<const uint8*>(GetHandle()), |
| 233 size.width(), |
| 234 size.height(), |
| 235 x, y, |
| 236 x, y, |
| 237 width, |
| 238 height); |
| 239 |
| 240 // Copy the pixmap to the window. |
| 241 XCopyArea(g_osmesa_display, |
| 242 pixmap_, |
| 243 window_, |
| 244 window_graphics_context_, |
| 245 x, y, |
| 246 width, height, |
| 247 x, y); |
| 248 |
| 249 return true; |
| 250 } |
| 251 |
197 bool NativeViewGLSurfaceOSMesa::UpdateSize() { | 252 bool NativeViewGLSurfaceOSMesa::UpdateSize() { |
198 // Get the window size. | 253 // Get the window size. |
199 XWindowAttributes attributes; | 254 XWindowAttributes attributes; |
200 if (!XGetWindowAttributes(g_osmesa_display, window_, &attributes)) { | 255 if (!XGetWindowAttributes(g_osmesa_display, window_, &attributes)) { |
201 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; | 256 LOG(ERROR) << "XGetWindowAttributes failed for window " << window_ << "."; |
202 return false; | 257 return false; |
203 } | 258 } |
204 gfx::Size window_size = gfx::Size(std::max(1, attributes.width), | 259 gfx::Size window_size = gfx::Size(std::max(1, attributes.width), |
205 std::max(1, attributes.height)); | 260 std::max(1, attributes.height)); |
206 | 261 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 374 } |
320 case kGLImplementationMockGL: | 375 case kGLImplementationMockGL: |
321 return new GLSurfaceStub; | 376 return new GLSurfaceStub; |
322 default: | 377 default: |
323 NOTREACHED(); | 378 NOTREACHED(); |
324 return NULL; | 379 return NULL; |
325 } | 380 } |
326 } | 381 } |
327 | 382 |
328 } // namespace gfx | 383 } // namespace gfx |
OLD | NEW |