| 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 #if defined(OS_ANDROID) | 7 #if defined(OS_ANDROID) |
| 8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #endif | 47 #endif |
| 48 #if !defined(EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE) | 48 #if !defined(EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE) |
| 49 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE 0x3206 | 49 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE 0x3206 |
| 50 #endif | 50 #endif |
| 51 #endif // defined(OS_WIN) | 51 #endif // defined(OS_WIN) |
| 52 | 52 |
| 53 using ui::GetLastEGLErrorString; | 53 using ui::GetLastEGLErrorString; |
| 54 | 54 |
| 55 namespace gfx { | 55 namespace gfx { |
| 56 | 56 |
| 57 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; | |
| 58 | |
| 59 namespace { | 57 namespace { |
| 60 | 58 |
| 61 EGLConfig g_config; | 59 EGLConfig g_config; |
| 62 EGLDisplay g_display; | 60 EGLDisplay g_display; |
| 63 EGLNativeDisplayType g_native_display; | 61 EGLNativeDisplayType g_native_display; |
| 64 | 62 |
| 65 const char* g_egl_extensions = NULL; | 63 const char* g_egl_extensions = NULL; |
| 66 bool g_egl_create_context_robustness_supported = false; | 64 bool g_egl_create_context_robustness_supported = false; |
| 67 bool g_egl_sync_control_supported = false; | 65 bool g_egl_sync_control_supported = false; |
| 68 bool g_egl_window_fixed_size_supported = false; | 66 bool g_egl_window_fixed_size_supported = false; |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 279 |
| 282 return eglGetDisplay(native_display); | 280 return eglGetDisplay(native_display); |
| 283 } | 281 } |
| 284 #endif | 282 #endif |
| 285 | 283 |
| 286 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) | 284 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) |
| 287 : window_(window), | 285 : window_(window), |
| 288 surface_(NULL), | 286 surface_(NULL), |
| 289 supports_post_sub_buffer_(false), | 287 supports_post_sub_buffer_(false), |
| 290 config_(NULL), | 288 config_(NULL), |
| 291 size_(1, 1), | 289 size_(1, 1) { |
| 292 swap_interval_(1), | |
| 293 swap_generation_(0) { | |
| 294 #if defined(OS_ANDROID) | 290 #if defined(OS_ANDROID) |
| 295 if (window) | 291 if (window) |
| 296 ANativeWindow_acquire(window); | 292 ANativeWindow_acquire(window); |
| 297 #endif | 293 #endif |
| 298 | 294 |
| 299 #if defined(OS_WIN) | 295 #if defined(OS_WIN) |
| 300 RECT windowRect; | 296 RECT windowRect; |
| 301 if (GetClientRect(window_, &windowRect)) | 297 if (GetClientRect(window_, &windowRect)) |
| 302 size_ = gfx::Rect(windowRect).size(); | 298 size_ = gfx::Rect(windowRect).size(); |
| 303 #endif | 299 #endif |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 443 |
| 448 bool NativeViewGLSurfaceEGL::IsOffscreen() { | 444 bool NativeViewGLSurfaceEGL::IsOffscreen() { |
| 449 return false; | 445 return false; |
| 450 } | 446 } |
| 451 | 447 |
| 452 bool NativeViewGLSurfaceEGL::SwapBuffers() { | 448 bool NativeViewGLSurfaceEGL::SwapBuffers() { |
| 453 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers", | 449 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers", |
| 454 "width", GetSize().width(), | 450 "width", GetSize().width(), |
| 455 "height", GetSize().height()); | 451 "height", GetSize().height()); |
| 456 | 452 |
| 457 #if defined(OS_WIN) | |
| 458 bool force_no_vsync = false; | |
| 459 if (swap_interval_ != 0) { | |
| 460 // This code is a simple way of enforcing that only one surface actually | |
| 461 // vsyncs per frame. This provides single window cases a stable refresh | |
| 462 // while allowing multi-window cases to not slow down due to multiple syncs | |
| 463 // on a single thread. A better way to fix this problem would be to have | |
| 464 // each surface present on its own thread. | |
| 465 if (current_swap_generation_ == swap_generation_) { | |
| 466 current_swap_generation_++; | |
| 467 } else { | |
| 468 force_no_vsync = true; | |
| 469 eglSwapInterval(GetDisplay(), 0); | |
| 470 } | |
| 471 | |
| 472 swap_generation_ = current_swap_generation_; | |
| 473 } | |
| 474 #endif | |
| 475 | |
| 476 if (!eglSwapBuffers(GetDisplay(), surface_)) { | 453 if (!eglSwapBuffers(GetDisplay(), surface_)) { |
| 477 DVLOG(1) << "eglSwapBuffers failed with error " | 454 DVLOG(1) << "eglSwapBuffers failed with error " |
| 478 << GetLastEGLErrorString(); | 455 << GetLastEGLErrorString(); |
| 479 return false; | 456 return false; |
| 480 } | 457 } |
| 481 | 458 |
| 482 #if defined(OS_WIN) | |
| 483 if (force_no_vsync) { | |
| 484 eglSwapInterval(GetDisplay(), swap_interval_); | |
| 485 } | |
| 486 #endif | |
| 487 | |
| 488 return true; | 459 return true; |
| 489 } | 460 } |
| 490 | 461 |
| 491 gfx::Size NativeViewGLSurfaceEGL::GetSize() { | 462 gfx::Size NativeViewGLSurfaceEGL::GetSize() { |
| 492 EGLint width; | 463 EGLint width; |
| 493 EGLint height; | 464 EGLint height; |
| 494 if (!eglQuerySurface(GetDisplay(), surface_, EGL_WIDTH, &width) || | 465 if (!eglQuerySurface(GetDisplay(), surface_, EGL_WIDTH, &width) || |
| 495 !eglQuerySurface(GetDisplay(), surface_, EGL_HEIGHT, &height)) { | 466 !eglQuerySurface(GetDisplay(), surface_, EGL_HEIGHT, &height)) { |
| 496 NOTREACHED() << "eglQuerySurface failed with error " | 467 NOTREACHED() << "eglQuerySurface failed with error " |
| 497 << GetLastEGLErrorString(); | 468 << GetLastEGLErrorString(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 << GetLastEGLErrorString(); | 523 << GetLastEGLErrorString(); |
| 553 return false; | 524 return false; |
| 554 } | 525 } |
| 555 return true; | 526 return true; |
| 556 } | 527 } |
| 557 | 528 |
| 558 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { | 529 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { |
| 559 return vsync_provider_.get(); | 530 return vsync_provider_.get(); |
| 560 } | 531 } |
| 561 | 532 |
| 562 void NativeViewGLSurfaceEGL::SetSwapInterval(int interval) { | |
| 563 swap_interval_ = interval; | |
| 564 } | |
| 565 | |
| 566 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { | 533 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { |
| 567 Destroy(); | 534 Destroy(); |
| 568 #if defined(OS_ANDROID) | 535 #if defined(OS_ANDROID) |
| 569 if (window_) | 536 if (window_) |
| 570 ANativeWindow_release(window_); | 537 ANativeWindow_release(window_); |
| 571 #endif | 538 #endif |
| 572 } | 539 } |
| 573 | 540 |
| 574 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size) | 541 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size) |
| 575 : size_(size), | 542 : size_(size), |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 } | 705 } |
| 739 | 706 |
| 740 void* SurfacelessEGL::GetShareHandle() { | 707 void* SurfacelessEGL::GetShareHandle() { |
| 741 return NULL; | 708 return NULL; |
| 742 } | 709 } |
| 743 | 710 |
| 744 SurfacelessEGL::~SurfacelessEGL() { | 711 SurfacelessEGL::~SurfacelessEGL() { |
| 745 } | 712 } |
| 746 | 713 |
| 747 } // namespace gfx | 714 } // namespace gfx |
| OLD | NEW |