From 84c904d6f91da41547a0895036d52583dc60b490 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 12 Apr 2013 14:05:19 +0200 Subject: [PATCH] EGL backend: Check if implementation supports swap interval of 1 before setting it REVIEW: 110023 --- eglonxbackend.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/eglonxbackend.cpp b/eglonxbackend.cpp index ecb6e0a9d8..7895af6efe 100644 --- a/eglonxbackend.cpp +++ b/eglonxbackend.cpp @@ -88,12 +88,21 @@ void EglOnXBackend::init() if (surfaceHasSubPost) { kDebug(1212) << "EGL implementation and surface support eglPostSubBufferNV, let's use it"; - // set swap interval appropriately - const bool wantSync = options->glPreferBufferSwap() != Options::NoSwapEncourage; - const EGLBoolean res = eglSwapInterval(dpy, wantSync ? 1 : 0); - if (res && wantSync) { - kDebug(1212) << "Enabled v-sync"; - setHasWaitSync(true); + if (options->glPreferBufferSwap() != Options::NoSwapEncourage) { + // check if swap interval 1 is supported + EGLint val; + eglGetConfigAttrib(dpy, config, EGL_MAX_SWAP_INTERVAL, &val); + if (val >= 1) { + if (eglSwapInterval(dpy, 1)) { + kDebug(1212) << "Enabled v-sync"; + setHasWaitSync(true); + } + } else { + kWarning(1212) << "Cannot enable v-sync as max. swap interval is" << val; + } + } else { + // disable v-sync + eglSwapInterval(dpy, 0); } } else { /* In the GLX backend, we fall back to using glCopyPixels if we have no extension providing support for partial screen updates.