| 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_egl.h" | 5 #include "ui/gl/gl_surface_egl.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 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 EGLConfig g_config; | 35 EGLConfig g_config; |
| 36 EGLDisplay g_display; | 36 EGLDisplay g_display; |
| 37 EGLNativeDisplayType g_native_display; | 37 EGLNativeDisplayType g_native_display; |
| 38 EGLConfig g_software_config; | 38 EGLConfig g_software_config; |
| 39 EGLDisplay g_software_display; | 39 EGLDisplay g_software_display; |
| 40 EGLNativeDisplayType g_software_native_display; | 40 EGLNativeDisplayType g_software_native_display; |
| 41 } | 41 } |
| 42 | 42 |
| 43 GLSurfaceEGL::GLSurfaceEGL() : software_(false) { | 43 GLSurfaceEGL::GLSurfaceEGL() : software_(false) {} |
| 44 } | |
| 45 | |
| 46 GLSurfaceEGL::~GLSurfaceEGL() { | |
| 47 } | |
| 48 | 44 |
| 49 bool GLSurfaceEGL::InitializeOneOff() { | 45 bool GLSurfaceEGL::InitializeOneOff() { |
| 50 static bool initialized = false; | 46 static bool initialized = false; |
| 51 if (initialized) | 47 if (initialized) |
| 52 return true; | 48 return true; |
| 53 | 49 |
| 54 #if defined(USE_X11) | 50 #if defined(USE_X11) |
| 55 g_native_display = base::MessagePumpForUI::GetDefaultXDisplay(); | 51 g_native_display = base::MessagePumpForUI::GetDefaultXDisplay(); |
| 56 #else | 52 #else |
| 57 g_native_display = EGL_DEFAULT_DISPLAY; | 53 g_native_display = EGL_DEFAULT_DISPLAY; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 153 } |
| 158 | 154 |
| 159 EGLDisplay GLSurfaceEGL::GetSoftwareDisplay() { | 155 EGLDisplay GLSurfaceEGL::GetSoftwareDisplay() { |
| 160 return g_software_display; | 156 return g_software_display; |
| 161 } | 157 } |
| 162 | 158 |
| 163 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { | 159 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { |
| 164 return g_native_display; | 160 return g_native_display; |
| 165 } | 161 } |
| 166 | 162 |
| 163 GLSurfaceEGL::~GLSurfaceEGL() {} |
| 164 |
| 167 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(bool software, | 165 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(bool software, |
| 168 gfx::AcceleratedWidget window) | 166 gfx::AcceleratedWidget window) |
| 169 : window_(window), | 167 : window_(window), |
| 170 surface_(NULL), | 168 surface_(NULL), |
| 171 supports_post_sub_buffer_(false), | 169 supports_post_sub_buffer_(false), |
| 172 config_(NULL) { | 170 config_(NULL) { |
| 173 software_ = software; | 171 software_ = software; |
| 174 } | 172 } |
| 175 | 173 |
| 176 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { | |
| 177 Destroy(); | |
| 178 } | |
| 179 | |
| 180 bool NativeViewGLSurfaceEGL::Initialize() { | 174 bool NativeViewGLSurfaceEGL::Initialize() { |
| 181 #if defined(OS_ANDROID) | 175 #if defined(OS_ANDROID) |
| 182 NOTREACHED(); | 176 NOTREACHED(); |
| 183 return false; | 177 return false; |
| 184 #else | 178 #else |
| 185 DCHECK(!surface_); | 179 DCHECK(!surface_); |
| 186 | 180 |
| 187 if (!GetDisplay()) { | 181 if (!GetDisplay()) { |
| 188 LOG(ERROR) << "Trying to create surface with invalid display."; | 182 LOG(ERROR) << "Trying to create surface with invalid display."; |
| 189 return false; | 183 return false; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 int x, int y, int width, int height) { | 345 int x, int y, int width, int height) { |
| 352 DCHECK(supports_post_sub_buffer_); | 346 DCHECK(supports_post_sub_buffer_); |
| 353 if (!eglPostSubBufferNV(GetDisplay(), surface_, x, y, width, height)) { | 347 if (!eglPostSubBufferNV(GetDisplay(), surface_, x, y, width, height)) { |
| 354 DVLOG(1) << "eglPostSubBufferNV failed with error " | 348 DVLOG(1) << "eglPostSubBufferNV failed with error " |
| 355 << GetLastEGLErrorString(); | 349 << GetLastEGLErrorString(); |
| 356 return false; | 350 return false; |
| 357 } | 351 } |
| 358 return true; | 352 return true; |
| 359 } | 353 } |
| 360 | 354 |
| 355 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { |
| 356 Destroy(); |
| 357 } |
| 358 |
| 361 void NativeViewGLSurfaceEGL::SetHandle(EGLSurface surface) { | 359 void NativeViewGLSurfaceEGL::SetHandle(EGLSurface surface) { |
| 362 surface_ = surface; | 360 surface_ = surface; |
| 363 } | 361 } |
| 364 | 362 |
| 365 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(bool software, const gfx::Size& size) | 363 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(bool software, const gfx::Size& size) |
| 366 : size_(size), | 364 : size_(size), |
| 367 surface_(NULL) { | 365 surface_(NULL) { |
| 368 software_ = software; | 366 software_ = software; |
| 369 } | 367 } |
| 370 | 368 |
| 371 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { | |
| 372 Destroy(); | |
| 373 } | |
| 374 | |
| 375 bool PbufferGLSurfaceEGL::Initialize() { | 369 bool PbufferGLSurfaceEGL::Initialize() { |
| 376 DCHECK(!surface_); | 370 DCHECK(!surface_); |
| 377 | 371 |
| 378 if (!GetDisplay()) { | 372 if (!GetDisplay()) { |
| 379 LOG(ERROR) << "Trying to create surface with invalid display."; | 373 LOG(ERROR) << "Trying to create surface with invalid display."; |
| 380 return false; | 374 return false; |
| 381 } | 375 } |
| 382 | 376 |
| 383 const EGLint pbuffer_attribs[] = { | 377 const EGLint pbuffer_attribs[] = { |
| 384 EGL_WIDTH, size_.width(), | 378 EGL_WIDTH, size_.width(), |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 GetHandle(), | 460 GetHandle(), |
| 467 EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, | 461 EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, |
| 468 &handle)) { | 462 &handle)) { |
| 469 return NULL; | 463 return NULL; |
| 470 } | 464 } |
| 471 | 465 |
| 472 return handle; | 466 return handle; |
| 473 #endif | 467 #endif |
| 474 } | 468 } |
| 475 | 469 |
| 470 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { |
| 471 Destroy(); |
| 472 } |
| 473 |
| 476 } // namespace gfx | 474 } // namespace gfx |
| OLD | NEW |