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 |
57 namespace { | 59 namespace { |
58 | 60 |
59 EGLConfig g_config; | 61 EGLConfig g_config; |
60 EGLDisplay g_display; | 62 EGLDisplay g_display; |
61 EGLNativeDisplayType g_native_display; | 63 EGLNativeDisplayType g_native_display; |
62 | 64 |
63 const char* g_egl_extensions = NULL; | 65 const char* g_egl_extensions = NULL; |
64 bool g_egl_create_context_robustness_supported = false; | 66 bool g_egl_create_context_robustness_supported = false; |
65 bool g_egl_sync_control_supported = false; | 67 bool g_egl_sync_control_supported = false; |
66 bool g_egl_window_fixed_size_supported = false; | 68 bool g_egl_window_fixed_size_supported = false; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 281 |
280 return eglGetDisplay(native_display); | 282 return eglGetDisplay(native_display); |
281 } | 283 } |
282 #endif | 284 #endif |
283 | 285 |
284 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) | 286 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) |
285 : window_(window), | 287 : window_(window), |
286 surface_(NULL), | 288 surface_(NULL), |
287 supports_post_sub_buffer_(false), | 289 supports_post_sub_buffer_(false), |
288 config_(NULL), | 290 config_(NULL), |
289 size_(1, 1) { | 291 size_(1, 1), |
| 292 swap_interval_(1), |
| 293 swap_generation_(0) { |
290 #if defined(OS_ANDROID) | 294 #if defined(OS_ANDROID) |
291 if (window) | 295 if (window) |
292 ANativeWindow_acquire(window); | 296 ANativeWindow_acquire(window); |
293 #endif | 297 #endif |
294 | 298 |
295 #if defined(OS_WIN) | 299 #if defined(OS_WIN) |
296 RECT windowRect; | 300 RECT windowRect; |
297 if (GetClientRect(window_, &windowRect)) | 301 if (GetClientRect(window_, &windowRect)) |
298 size_ = gfx::Rect(windowRect).size(); | 302 size_ = gfx::Rect(windowRect).size(); |
299 #endif | 303 #endif |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 447 |
444 bool NativeViewGLSurfaceEGL::IsOffscreen() { | 448 bool NativeViewGLSurfaceEGL::IsOffscreen() { |
445 return false; | 449 return false; |
446 } | 450 } |
447 | 451 |
448 bool NativeViewGLSurfaceEGL::SwapBuffers() { | 452 bool NativeViewGLSurfaceEGL::SwapBuffers() { |
449 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers", | 453 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers", |
450 "width", GetSize().width(), | 454 "width", GetSize().width(), |
451 "height", GetSize().height()); | 455 "height", GetSize().height()); |
452 | 456 |
| 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 |
453 if (!eglSwapBuffers(GetDisplay(), surface_)) { | 476 if (!eglSwapBuffers(GetDisplay(), surface_)) { |
454 DVLOG(1) << "eglSwapBuffers failed with error " | 477 DVLOG(1) << "eglSwapBuffers failed with error " |
455 << GetLastEGLErrorString(); | 478 << GetLastEGLErrorString(); |
456 return false; | 479 return false; |
457 } | 480 } |
458 | 481 |
| 482 #if defined(OS_WIN) |
| 483 if (force_no_vsync) { |
| 484 eglSwapInterval(GetDisplay(), swap_interval_); |
| 485 } |
| 486 #endif |
| 487 |
459 return true; | 488 return true; |
460 } | 489 } |
461 | 490 |
462 gfx::Size NativeViewGLSurfaceEGL::GetSize() { | 491 gfx::Size NativeViewGLSurfaceEGL::GetSize() { |
463 EGLint width; | 492 EGLint width; |
464 EGLint height; | 493 EGLint height; |
465 if (!eglQuerySurface(GetDisplay(), surface_, EGL_WIDTH, &width) || | 494 if (!eglQuerySurface(GetDisplay(), surface_, EGL_WIDTH, &width) || |
466 !eglQuerySurface(GetDisplay(), surface_, EGL_HEIGHT, &height)) { | 495 !eglQuerySurface(GetDisplay(), surface_, EGL_HEIGHT, &height)) { |
467 NOTREACHED() << "eglQuerySurface failed with error " | 496 NOTREACHED() << "eglQuerySurface failed with error " |
468 << GetLastEGLErrorString(); | 497 << GetLastEGLErrorString(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 << GetLastEGLErrorString(); | 552 << GetLastEGLErrorString(); |
524 return false; | 553 return false; |
525 } | 554 } |
526 return true; | 555 return true; |
527 } | 556 } |
528 | 557 |
529 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { | 558 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { |
530 return vsync_provider_.get(); | 559 return vsync_provider_.get(); |
531 } | 560 } |
532 | 561 |
| 562 void NativeViewGLSurfaceEGL::SetSwapInterval(int interval) { |
| 563 swap_interval_ = interval; |
| 564 } |
| 565 |
533 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { | 566 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { |
534 Destroy(); | 567 Destroy(); |
535 #if defined(OS_ANDROID) | 568 #if defined(OS_ANDROID) |
536 if (window_) | 569 if (window_) |
537 ANativeWindow_release(window_); | 570 ANativeWindow_release(window_); |
538 #endif | 571 #endif |
539 } | 572 } |
540 | 573 |
541 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size) | 574 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size) |
542 : size_(size), | 575 : size_(size), |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 } | 738 } |
706 | 739 |
707 void* SurfacelessEGL::GetShareHandle() { | 740 void* SurfacelessEGL::GetShareHandle() { |
708 return NULL; | 741 return NULL; |
709 } | 742 } |
710 | 743 |
711 SurfacelessEGL::~SurfacelessEGL() { | 744 SurfacelessEGL::~SurfacelessEGL() { |
712 } | 745 } |
713 | 746 |
714 } // namespace gfx | 747 } // namespace gfx |
OLD | NEW |