From 5b84b15cf610eb7ba2f62cf0f675238531816c30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20Br=C3=BCning?= <michael.bruning@qt.io>
Date: Tue, 16 Oct 2018 18:24:27 +0200
Subject: [PATCH] Trigger disabling offline renderers on late 2013 Mac Pros
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reads the hw.model string through sysctlbyname and sets the
environment variable QT_MAC_PRO_WEBENGINE_WORKAROUND to tell the
Cocoa platform plugin to not enable offline renderers upon creation
of the platform OpenGL context.

Task-number: QTBUG-70062
Change-Id: I986d9d76a80f96a215f3fcd08b3d47e546682e35
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
---
 src/core/api/qtwebenginecoreglobal.cpp | 27 +++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/core/api/qtwebenginecoreglobal.cpp b/src/core/api/qtwebenginecoreglobal.cpp
index 0353dac7d..4bb69ac21 100644
--- a/src/core/api/qtwebenginecoreglobal.cpp
+++ b/src/core/api/qtwebenginecoreglobal.cpp
@@ -42,6 +42,10 @@
 #include <QGuiApplication>
 #ifndef QT_NO_OPENGL
 # include <QOpenGLContext>
+#ifdef Q_OS_MACOS
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
 #endif
 #include <QThread>
 
@@ -52,6 +56,23 @@ Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context();
 QT_END_NAMESPACE
 #endif
 
+#ifndef QT_NO_OPENGL
+#ifdef Q_OS_MACOS
+static bool needsOfflineRendererWorkaround() {
+    size_t hwmodelsize = 0;
+
+    if (sysctlbyname("hw.model", nullptr, &hwmodelsize, nullptr, 0) == -1)
+        return false;
+
+    char hwmodel[hwmodelsize];
+    if (sysctlbyname("hw.model", &hwmodel, &hwmodelsize, nullptr, 0) == -1)
+        return false;
+
+    return QString::fromLatin1(hwmodel) == QLatin1String("MacPro6,1");
+}
+#endif
+#endif
+
 namespace QtWebEngineCore {
 #ifndef QT_NO_OPENGL
 static QOpenGLContext *shareContext;
@@ -74,7 +95,10 @@ QWEBENGINE_PRIVATE_EXPORT void initialize()
 #ifdef Q_OS_WIN32
     qputenv("QT_D3DCREATE_MULTITHREADED", "1");
 #endif
-
+#ifdef Q_OS_MACOS
+    if (needsOfflineRendererWorkaround())
+        qputenv("QT_MAC_PRO_WEBENGINE_WORKAROUND", "1");
+#endif
     // No need to override the shared context if QApplication already set one (e.g with Qt::AA_ShareOpenGLContexts).
     if (qt_gl_global_share_context())
         return;
@@ -107,3 +131,4 @@ QWEBENGINE_PRIVATE_EXPORT void initialize()
 #endif // QT_NO_OPENGL
 }
 } // namespace QtWebEngineCore
+
-- 
GitLab