Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: ui/gl/gl_surface_egl.cc

Issue 749483002: Allow Windows to use system Vsync if only one window is swapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« ui/gl/gl_surface.h ('K') | « ui/gl/gl_surface_egl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #endif 50 #endif
51 #if !defined(EGL_PLATFORM_ANGLE_USE_WARP_ANGLE) 51 #if !defined(EGL_PLATFORM_ANGLE_USE_WARP_ANGLE)
52 #define EGL_PLATFORM_ANGLE_USE_WARP_ANGLE 0x3208 52 #define EGL_PLATFORM_ANGLE_USE_WARP_ANGLE 0x3208
53 #endif 53 #endif
54 #endif // defined(OS_WIN) 54 #endif // defined(OS_WIN)
55 55
56 using ui::GetLastEGLErrorString; 56 using ui::GetLastEGLErrorString;
57 57
58 namespace gfx { 58 namespace gfx {
59 59
60 #if defined(OS_WIN)
61 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0;
62 unsigned int NativeViewGLSurfaceEGL::swaps_this_generation_ = 0;
63 unsigned int NativeViewGLSurfaceEGL::last_multiswap_generation_ = 0;
64
65 const unsigned int MULTISWAP_FRAME_VSYNC_THRESHOLD = 60;
66 #endif
67
60 namespace { 68 namespace {
61 69
62 EGLConfig g_config; 70 EGLConfig g_config;
63 EGLDisplay g_display; 71 EGLDisplay g_display;
64 EGLNativeDisplayType g_native_display; 72 EGLNativeDisplayType g_native_display;
65 73
66 const char* g_egl_extensions = NULL; 74 const char* g_egl_extensions = NULL;
67 bool g_egl_create_context_robustness_supported = false; 75 bool g_egl_create_context_robustness_supported = false;
68 bool g_egl_sync_control_supported = false; 76 bool g_egl_sync_control_supported = false;
69 bool g_egl_window_fixed_size_supported = false; 77 bool g_egl_window_fixed_size_supported = false;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 290
283 return eglGetDisplay(native_display); 291 return eglGetDisplay(native_display);
284 } 292 }
285 #endif 293 #endif
286 294
287 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) 295 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window)
288 : window_(window), 296 : window_(window),
289 surface_(NULL), 297 surface_(NULL),
290 supports_post_sub_buffer_(false), 298 supports_post_sub_buffer_(false),
291 config_(NULL), 299 config_(NULL),
292 size_(1, 1) { 300 size_(1, 1),
301 swap_interval_(1),
302 swap_generation_(0),
303 vsync_override_(false) {
293 #if defined(OS_ANDROID) 304 #if defined(OS_ANDROID)
294 if (window) 305 if (window)
295 ANativeWindow_acquire(window); 306 ANativeWindow_acquire(window);
296 #endif 307 #endif
297 308
298 #if defined(OS_WIN) 309 #if defined(OS_WIN)
299 RECT windowRect; 310 RECT windowRect;
300 if (GetClientRect(window_, &windowRect)) 311 if (GetClientRect(window_, &windowRect))
301 size_ = gfx::Rect(windowRect).size(); 312 size_ = gfx::Rect(windowRect).size();
302 #endif 313 #endif
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 457
447 bool NativeViewGLSurfaceEGL::IsOffscreen() { 458 bool NativeViewGLSurfaceEGL::IsOffscreen() {
448 return false; 459 return false;
449 } 460 }
450 461
451 bool NativeViewGLSurfaceEGL::SwapBuffers() { 462 bool NativeViewGLSurfaceEGL::SwapBuffers() {
452 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers", 463 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers",
453 "width", GetSize().width(), 464 "width", GetSize().width(),
454 "height", GetSize().height()); 465 "height", GetSize().height());
455 466
467 #if defined(OS_WIN)
468 if (swap_interval_ != 0) {
469 // This code is a simple way of enforcing that we only vsync if one surface
470 // is swapping per frame. This provides single window cases a stable refresh
471 // while allowing multi-window cases to not slow down due to multiple syncs
472 // on a single thread. A better way to fix this problem would be to have
473 // each surface present on its own thread.
474
475 if (current_swap_generation_ == swap_generation_) {
476 if (swaps_this_generation_ > 1)
477 last_multiswap_generation_ = current_swap_generation_;
478 swaps_this_generation_ = 0;
479 current_swap_generation_++;
480 }
481
482 swap_generation_ = current_swap_generation_;
483
484 if (swaps_this_generation_ != 0 ||
485 (current_swap_generation_ - last_multiswap_generation_ <
486 MULTISWAP_FRAME_VSYNC_THRESHOLD)) {
487 // Override vsync settings and switch it off
488 if (!vsync_override_) {
489 eglSwapInterval(GetDisplay(), 0);
Ken Russell (switch to Gerrit) 2014/11/21 00:05:58 eglSwapInterval applies to the current context. Th
490 vsync_override_ = true;
491 }
492 } else if (vsync_override_) {
493 // Only one window swapping, so let the normal vsync setting take over
494 eglSwapInterval(GetDisplay(), swap_interval_);
495 vsync_override_ = false;
496 }
497
498 swaps_this_generation_++;
499 }
500 #endif
501
456 if (!eglSwapBuffers(GetDisplay(), surface_)) { 502 if (!eglSwapBuffers(GetDisplay(), surface_)) {
457 DVLOG(1) << "eglSwapBuffers failed with error " 503 DVLOG(1) << "eglSwapBuffers failed with error "
458 << GetLastEGLErrorString(); 504 << GetLastEGLErrorString();
459 return false; 505 return false;
460 } 506 }
461 507
462 return true; 508 return true;
463 } 509 }
464 510
465 gfx::Size NativeViewGLSurfaceEGL::GetSize() { 511 gfx::Size NativeViewGLSurfaceEGL::GetSize() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 << GetLastEGLErrorString(); 572 << GetLastEGLErrorString();
527 return false; 573 return false;
528 } 574 }
529 return true; 575 return true;
530 } 576 }
531 577
532 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { 578 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() {
533 return vsync_provider_.get(); 579 return vsync_provider_.get();
534 } 580 }
535 581
582 void NativeViewGLSurfaceEGL::SetSwapInterval(int interval) {
583 swap_interval_ = interval;
584 }
585
536 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() { 586 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() {
537 Destroy(); 587 Destroy();
538 #if defined(OS_ANDROID) 588 #if defined(OS_ANDROID)
539 if (window_) 589 if (window_)
540 ANativeWindow_release(window_); 590 ANativeWindow_release(window_);
541 #endif 591 #endif
542 } 592 }
543 593
544 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size) 594 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size)
545 : size_(size), 595 : size_(size),
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 } 758 }
709 759
710 void* SurfacelessEGL::GetShareHandle() { 760 void* SurfacelessEGL::GetShareHandle() {
711 return NULL; 761 return NULL;
712 } 762 }
713 763
714 SurfacelessEGL::~SurfacelessEGL() { 764 SurfacelessEGL::~SurfacelessEGL() {
715 } 765 }
716 766
717 } // namespace gfx 767 } // namespace gfx
OLDNEW
« ui/gl/gl_surface.h ('K') | « ui/gl/gl_surface_egl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698