summaryrefslogtreecommitdiffstats
path: root/src/core/chromium_gpu_helper.cpp
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-04-10 17:32:36 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-10 21:03:22 +0200
commit682ddcd7187b16723af66d7f9c1b61bc060f44c1 (patch)
treeda181af0cbb3656a95c6b3c3b0708d6fda91a369 /src/core/chromium_gpu_helper.cpp
parentf61493ee97f285e4b7257f7590f45764980ca52e (diff)
Use a fence sync to synchronize GL between threads
The NVidia driver needs more than a glFlush to ensure that GL commands consuming Chromium resources are run only when the resource is completely produced by the Chromium GPU thread. This produces artifacts and an uneven frame rate in WebGL examples on this kind of hardware. Use the same mechanism as used by gfx::GLFence, doing a few things manually to cope with the fact that Chromium and Qt both have their own GL function table and contexts. Change-Id: I33eeb1068994dc4176038a74579ce768b2bccb9d Reviewed-by: Andras Becsi <andras.becsi@digia.com> Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'src/core/chromium_gpu_helper.cpp')
-rw-r--r--src/core/chromium_gpu_helper.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/core/chromium_gpu_helper.cpp b/src/core/chromium_gpu_helper.cpp
index 3d393c25d..8782f5d98 100644
--- a/src/core/chromium_gpu_helper.cpp
+++ b/src/core/chromium_gpu_helper.cpp
@@ -39,6 +39,10 @@
**
****************************************************************************/
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
#include "chromium_gpu_helper.h"
#include "content/common/gpu/gpu_channel_manager.h"
@@ -52,6 +56,30 @@ static void addSyncPointCallbackDelegate(content::SyncPointManager *syncPointMan
syncPointManager->AddSyncPointCallback(sync_point, callback);
}
+FenceSync createFence()
+{
+ FenceSync ret;
+ // Logic taken from chromium/ui/gl/gl_fence.cc
+#if !defined(OS_MACOSX)
+ if (gfx::g_driver_egl.ext.b_EGL_KHR_fence_sync) {
+ ret.type = FenceSync::EglSync;
+ ret.egl.display = eglGetCurrentDisplay();
+ ret.egl.sync = eglCreateSyncKHR(ret.egl.display, EGL_SYNC_FENCE_KHR, NULL);
+ } else
+#endif
+ if (gfx::g_driver_gl.ext.b_GL_ARB_sync) {
+ ret.type = FenceSync::ArbSync;
+ ret.arb.sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
+ }
+
+ // glFlush is necessary to make sure that our fence creation reaches the GL server
+ // before we try waiting on it from a different context, which could deadlock.
+ // In cases where no fence extension is available, this also serves as flushing
+ // Chromium's GL context command stream before yielding to the SG thread.
+ glFlush();
+ return ret;
+}
+
base::MessageLoop *gpu_message_loop()
{
return content::GpuChildThread::instance()->message_loop();