From fa8e6d5083a01667bd5bdd3450ca5f883a068d10 Mon Sep 17 00:00:00 2001
From: Bernd Weimer <bweimer@blackberry.com>
Date: Wed, 29 Jan 2014 13:43:03 +0100
Subject: [PATCH] QNX: Add support for lgmon

Added configure test, whether lgmon (liquid graphics performance monitor)
is available. The test is supposed to be positive only for internal
BlackBerry NDKs currently.
Added calls to initialize lgmon and to indicate when an app is ready for
user input.

Change-Id: I5cbc29fb38a86585dcebd14d462436deaa1998aa
Reviewed-by: Wolfgang Bremer <wbremer@blackberry.com>
Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Reviewed-by: Kevin Krammer <kevin.krammer@kdab.com>
---
 config.tests/unix/lgmon/lgmon.cpp             | 49 ++++++++++++
 config.tests/unix/lgmon/lgmon.pro             |  3 +
 configure                                     | 21 +++++
 qtbase.pro                                    |  1 +
 src/plugins/platforms/qnx/main.cpp            |  7 +-
 src/plugins/platforms/qnx/qnx.pro             |  9 ++-
 src/plugins/platforms/qnx/qqnxeglwindow.cpp   |  5 +-
 src/plugins/platforms/qnx/qqnxlgmon.cpp       | 49 ++++++++++++
 src/plugins/platforms/qnx/qqnxlgmon.h         | 80 +++++++++++++++++++
 .../platforms/qnx/qqnxrasterwindow.cpp        |  5 +-
 src/plugins/platforms/qnx/qqnxwindow.cpp      |  8 ++
 src/plugins/platforms/qnx/qqnxwindow.h        |  3 +-
 tools/configure/configureapp.cpp              | 21 ++++-
 13 files changed, 250 insertions(+), 11 deletions(-)
 create mode 100644 config.tests/unix/lgmon/lgmon.cpp
 create mode 100644 config.tests/unix/lgmon/lgmon.pro
 create mode 100644 src/plugins/platforms/qnx/qqnxlgmon.cpp
 create mode 100644 src/plugins/platforms/qnx/qqnxlgmon.h

diff --git a/config.tests/unix/lgmon/lgmon.cpp b/config.tests/unix/lgmon/lgmon.cpp
new file mode 100644
index 00000000000..49357758062
--- /dev/null
+++ b/config.tests/unix/lgmon/lgmon.cpp
@@ -0,0 +1,49 @@
+/***************************************************************************
+**
+** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the config.tests of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <lgmon.h>
+
+int main(int, char **)
+{
+    lgmon_supported(getpid());
+    return 0;
+}
+
diff --git a/config.tests/unix/lgmon/lgmon.pro b/config.tests/unix/lgmon/lgmon.pro
new file mode 100644
index 00000000000..7bd094dc86c
--- /dev/null
+++ b/config.tests/unix/lgmon/lgmon.pro
@@ -0,0 +1,3 @@
+SOURCES = lgmon.cpp
+CONFIG -= qt
+LIBS += -llgmon
diff --git a/configure b/configure
index dc23bb4eb6e..e491836533d 100755
--- a/configure
+++ b/configure
@@ -633,6 +633,7 @@ CFG_STACK_PROTECTOR_STRONG=auto
 CFG_SLOG2=auto
 CFG_PPS=auto
 CFG_QNX_IMF=auto
+CFG_LGMON=auto
 CFG_SYSTEM_PROXIES=no
 
 # Target architecture
@@ -1800,6 +1801,13 @@ while [ "$#" -gt 0 ]; do
             UNKNOWN_OPT=yes
         fi
         ;;
+    lgmon)
+        if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
+            CFG_LGMON="$VAL"
+        else
+            UNKNOWN_OPT=yes
+        fi
+        ;;
     gtkstyle)
         if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then
             CFG_QGTKSTYLE="$VAL"
@@ -2502,6 +2510,9 @@ QNX/Blackberry options:
     -no-imf ............ Do not compile with imf support.
     -imf ............... Compile with imf support.
 
+    -no-lgmon .......... Do not compile with lgmon support.
+    -lgmon ............. Compile with lgmon support.
+
 MacOS/iOS options:
 
     -Fstring ........... Add an explicit framework path.
@@ -4416,6 +4427,15 @@ if [ "$XPLATFORM_QNX" = "yes" ]; then
             CFG_PPS=no
         fi
     fi
+
+    if [ "$CFG_LGMON" != "no" ]; then
+        if compileTest unix/lgmon "lgmon"; then
+            CFG_LGMON=yes
+            QMAKE_CONFIG="$QMAKE_CONFIG lgmon"
+        else
+            CFG_LGMON=no
+        fi
+    fi
 fi
 
 if [ "$CFG_ZLIB" = "auto" ]; then
@@ -6841,6 +6861,7 @@ if [ "$XPLATFORM_QNX" = "yes" ]; then
     report_support "  SLOG2 .................." "$CFG_SLOG2"
     report_support "  IMF ...................." "$CFG_QNX_IMF"
     report_support "  PPS ...................." "$CFG_PPS"
+    report_support "  LGMON .................." "$CFG_LGMON"
 fi
 report_support "  SQL drivers:"
 report_support "    DB2 .................." "$CFG_SQL_db2" plugin "plugin" yes "built into QtSql"
diff --git a/qtbase.pro b/qtbase.pro
index 140a1370997..1cd82bbc84c 100644
--- a/qtbase.pro
+++ b/qtbase.pro
@@ -32,6 +32,7 @@ unix {
 			(cd config.tests/unix/libjpeg && $(MAKE) distclean); \
 			(cd config.tests/unix/libpng && $(MAKE) distclean); \
                         (cd config.tests/unix/slog2 && $(MAKE) distclean); \
+                        (cd config.tests/unix/lgmon && $(MAKE) distclean); \
 			(cd config.tests/x11/xcursor && $(MAKE) distclean); \
 			(cd config.tests/x11/xrender && $(MAKE) distclean); \
 			(cd config.tests/x11/xrandr && $(MAKE) distclean); \
diff --git a/src/plugins/platforms/qnx/main.cpp b/src/plugins/platforms/qnx/main.cpp
index 50779d3e127..01e71b38104 100644
--- a/src/plugins/platforms/qnx/main.cpp
+++ b/src/plugins/platforms/qnx/main.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **
-** Copyright (C) 2011 - 2012 Research In Motion
+** Copyright (C) 2011 - 2014 BlackBerry Limited. All rights reserved.
 ** Contact: http://www.qt-project.org/legal
 **
 ** This file is part of the plugins of the Qt Toolkit.
@@ -41,13 +41,16 @@
 
 #include "main.h"
 #include "qqnxintegration.h"
+#include "qqnxlgmon.h"
 
 QT_BEGIN_NAMESPACE
 
 QPlatformIntegration *QQnxIntegrationPlugin::create(const QString& system, const QStringList& paramList)
 {
-    if (!system.compare(QLatin1String("qnx"), Qt::CaseInsensitive))
+    if (!system.compare(QLatin1String("qnx"), Qt::CaseInsensitive)) {
+        qqnxLgmonInit();
         return new QQnxIntegration(paramList);
+    }
 
     return 0;
 }
diff --git a/src/plugins/platforms/qnx/qnx.pro b/src/plugins/platforms/qnx/qnx.pro
index c6051260912..2399a91c122 100644
--- a/src/plugins/platforms/qnx/qnx.pro
+++ b/src/plugins/platforms/qnx/qnx.pro
@@ -65,7 +65,8 @@ HEADERS =   main.h \
             qqnxcursor.h \
             qqnxrasterwindow.h \
             qqnxscreeneventfilter.h \
-            qqnxglobal.h
+            qqnxglobal.h \
+            qqnxlgmon.h
 
 CONFIG(qqnx_screeneventthread) {
     DEFINES += QQNX_SCREENEVENTTHREAD
@@ -145,6 +146,12 @@ CONFIG(qqnx_pps) {
     }
 }
 
+lgmon {
+    DEFINES += QQNX_LGMON
+    SOURCES += qqnxlgmon.cpp
+    LIBS += -llgmon
+}
+
 OTHER_FILES += qnx.json
 
 QMAKE_CXXFLAGS += -I./private
diff --git a/src/plugins/platforms/qnx/qqnxeglwindow.cpp b/src/plugins/platforms/qnx/qqnxeglwindow.cpp
index 45a7bab8717..3c08cc9f82c 100644
--- a/src/plugins/platforms/qnx/qqnxeglwindow.cpp
+++ b/src/plugins/platforms/qnx/qqnxeglwindow.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **
-** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Copyright (C) 2013 - 2014 BlackBerry Limited. All rights reserved.
 ** Contact: http://www.qt-project.org/legal
 **
 ** This file is part of the plugins of the Qt Toolkit.
@@ -135,8 +135,7 @@ void QQnxEglWindow::swapEGLBuffers()
     if (eglResult != EGL_TRUE)
         qFatal("QQNX: failed to swap EGL buffers, err=%d", eglGetError());
 
-    if (m_cover)
-        m_cover->updateCover();
+    windowPosted();
 }
 
 EGLSurface QQnxEglWindow::getSurface()
diff --git a/src/plugins/platforms/qnx/qqnxlgmon.cpp b/src/plugins/platforms/qnx/qqnxlgmon.cpp
new file mode 100644
index 00000000000..3c8d1c11a53
--- /dev/null
+++ b/src/plugins/platforms/qnx/qqnxlgmon.cpp
@@ -0,0 +1,49 @@
+/***************************************************************************
+**
+** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qqnxlgmon.h"
+
+QT_BEGIN_NAMESPACE
+
+bool qqnxLgmonFirstFrame = true;
+
+QT_END_NAMESPACE
+
diff --git a/src/plugins/platforms/qnx/qqnxlgmon.h b/src/plugins/platforms/qnx/qqnxlgmon.h
new file mode 100644
index 00000000000..e3930ce93a1
--- /dev/null
+++ b/src/plugins/platforms/qnx/qqnxlgmon.h
@@ -0,0 +1,80 @@
+/***************************************************************************
+**
+** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQNXLGMON_H
+#define QQNXLGMON_H
+
+#include <qglobal.h>
+
+#if defined(QQNX_LGMON)
+#include <lgmon.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#if defined(QQNX_LGMON)
+
+extern bool qqnxLgmonFirstFrame;
+
+inline void qqnxLgmonInit()
+{
+    lgmon_supported(getpid());
+}
+
+inline void qqnxLgmonFramePosted(bool isCover)
+{
+    if (qqnxLgmonFirstFrame && !isCover) {
+        qqnxLgmonFirstFrame = false;
+        lgmon_app_ready_for_user_input(getpid());
+    }
+}
+
+#else
+
+inline void qqnxLgmonInit() {}
+inline void qqnxLgmonFramePosted(bool /*isCover*/) {}
+
+#endif
+
+QT_END_NAMESPACE
+
+#endif  // QQNXLGMON_H
+
diff --git a/src/plugins/platforms/qnx/qqnxrasterwindow.cpp b/src/plugins/platforms/qnx/qqnxrasterwindow.cpp
index 2c0639e8e32..eb9fac540f7 100644
--- a/src/plugins/platforms/qnx/qqnxrasterwindow.cpp
+++ b/src/plugins/platforms/qnx/qqnxrasterwindow.cpp
@@ -1,6 +1,6 @@
 /***************************************************************************
 **
-** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Copyright (C) 2013 - 2014 BlackBerry Limited. All rights reserved.
 ** Contact: http://www.qt-project.org/legal
 **
 ** This file is part of the plugins of the Qt Toolkit.
@@ -123,8 +123,7 @@ void QQnxRasterWindow::post(const QRegion &dirty)
         m_previousDirty = dirty;
         m_scrolled = QRegion();
 
-        if (m_cover)
-            m_cover->updateCover();
+        windowPosted();
     }
 }
 
diff --git a/src/plugins/platforms/qnx/qqnxwindow.cpp b/src/plugins/platforms/qnx/qqnxwindow.cpp
index bb76efea64f..e57025cbc69 100644
--- a/src/plugins/platforms/qnx/qqnxwindow.cpp
+++ b/src/plugins/platforms/qnx/qqnxwindow.cpp
@@ -44,6 +44,7 @@
 #include "qqnxwindow.h"
 #include "qqnxintegration.h"
 #include "qqnxscreen.h"
+#include "qqnxlgmon.h"
 
 #include <QUuid>
 
@@ -705,5 +706,12 @@ void QQnxWindow::applyWindowState()
     }
 }
 
+void QQnxWindow::windowPosted()
+{
+    if (m_cover)
+        m_cover->updateCover();
+
+    qqnxLgmonFramePosted(m_cover);  // for performance measurements
+}
 
 QT_END_NAMESPACE
diff --git a/src/plugins/platforms/qnx/qqnxwindow.h b/src/plugins/platforms/qnx/qqnxwindow.h
index ea7b388e9fc..e97e941a085 100644
--- a/src/plugins/platforms/qnx/qqnxwindow.h
+++ b/src/plugins/platforms/qnx/qqnxwindow.h
@@ -117,9 +117,9 @@ protected:
     virtual void resetBuffers() = 0;
 
     void initWindow();
+    void windowPosted();
 
     screen_context_t m_screenContext;
-    QScopedPointer<QQnxAbstractCover> m_cover;
 
 private:
     void createWindowGroup();
@@ -137,6 +137,7 @@ private:
     QQnxScreen *m_screen;
     QQnxWindow *m_parentWindow;
     QList<QQnxWindow*> m_childWindows;
+    QScopedPointer<QQnxAbstractCover> m_cover;
     bool m_visible;
     bool m_exposed;
     QRect m_unmaximizedGeometry;
diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp
index 350ce630873..0553235b805 100644
--- a/tools/configure/configureapp.cpp
+++ b/tools/configure/configureapp.cpp
@@ -197,6 +197,7 @@ Configure::Configure(int& argc, char** argv)
     dictionary[ "SLOG2" ]           = "no";
     dictionary[ "QNX_IMF" ]         = "no";
     dictionary[ "PPS" ]             = "no";
+    dictionary[ "LGMON" ]           = "no";
     dictionary[ "SYSTEM_PROXIES" ]  = "no";
     dictionary[ "WERROR" ]          = "auto";
     dictionary[ "QREAL" ]           = "double";
@@ -890,6 +891,10 @@ void Configure::parseCmdLine()
             dictionary[ "PPS" ] = "no";
         } else if (configCmdLine.at(i) == "-pps") {
             dictionary[ "PPS" ] = "yes";
+        } else if (configCmdLine.at(i) == "-no-lgmon") {
+            dictionary[ "LGMON" ] = "no";
+        } else if (configCmdLine.at(i) == "-lgmon") {
+            dictionary[ "LGMON" ] = "yes";
         } else if (configCmdLine.at(i) == "-no-system-proxies") {
             dictionary[ "SYSTEM_PROXIES" ] = "no";
         } else if (configCmdLine.at(i) == "-system-proxies") {
@@ -1666,6 +1671,7 @@ void Configure::applySpecSpecifics()
         dictionary["SLOG2"]                 = "auto";
         dictionary["QNX_IMF"]               = "auto";
         dictionary["PPS"]                   = "auto";
+        dictionary["LGMON"]                 = "auto";
         dictionary["QT_XKBCOMMON"]          = "no";
         dictionary[ "ANGLE" ]               = "no";
         dictionary[ "FONT_CONFIG" ]         = "auto";
@@ -1877,7 +1883,7 @@ bool Configure::displayHelp()
                                                         "by setting QT_HARFBUZZ environment variable to \"old\".");
         desc("HARFBUZZ", "system","-system-harfbuzz",   "(experimental) Use HarfBuzz-NG from the operating system\n"
                                                         "to do text shaping. It can still be disabled\n"
-                                                        "by setting QT_HARFBUZZ environment variable to \"old\".");
+                                                        "by setting QT_HARFBUZZ environment variable to \"old\".\n");
 
         if ((platform() == QNX) || (platform() == BLACKBERRY)) {
             desc("SLOG2", "yes",  "-slog2",             "Compile with slog2 support.");
@@ -1886,6 +1892,8 @@ bool Configure::displayHelp()
             desc("QNX_IMF", "no",  "-no-imf",           "Do not compile with imf support.");
             desc("PPS", "yes",  "-pps",                 "Compile with PPS support.");
             desc("PPS", "no",  "-no-pps",               "Do not compile with PPS support.");
+            desc("LGMON", "yes",  "-lgmon",             "Compile with lgmon support.");
+            desc("LGMON", "no",   "-no-lgmon",          "Do not compile with lgmon support.\n");
         }
 
         desc("ANGLE", "yes",       "-angle",            "Use the ANGLE implementation of OpenGL ES 2.0.");
@@ -2236,6 +2244,9 @@ bool Configure::checkAvailability(const QString &part)
         available = tryCompileProject("unix/qqnx_imf");
     } else if (part == "PPS") {
         available = (platform() == QNX || platform() == BLACKBERRY) && tryCompileProject("unix/pps");
+    } else if (part == "LGMON") {
+        available = (platform() == QNX || platform() == BLACKBERRY)
+                    && tryCompileProject("unix/lgmon");
     } else if (part == "NEON") {
         available = (dictionary["QT_ARCH"] == "arm") && tryCompileProject("unix/neon");
     } else if (part == "FONT_CONFIG") {
@@ -2389,6 +2400,10 @@ void Configure::autoDetection()
         dictionary["PPS"] = checkAvailability("PPS") ? "yes" : "no";
     }
 
+    if ((platform() == QNX || platform() == BLACKBERRY) && dictionary["LGMON"] == "auto") {
+        dictionary["LGMON"] = checkAvailability("LGMON") ? "yes" : "no";
+    }
+
     if (dictionary["QT_EVENTFD"] == "auto")
         dictionary["QT_EVENTFD"] = checkAvailability("QT_EVENTFD") ? "yes" : "no";
 
@@ -3244,6 +3259,9 @@ void Configure::generateQConfigPri()
         if (dictionary[ "PPS" ] == "yes")
             configStream << " qqnx_pps";
 
+        if (dictionary[ "LGMON" ] == "yes")
+            configStream << " lgmon";
+
         if (dictionary["DIRECTWRITE"] == "yes")
             configStream << " directwrite";
 
@@ -3620,6 +3638,7 @@ void Configure::displayConfig()
         sout << "    SLOG2 support..........." << dictionary[ "SLOG2" ] << endl;
         sout << "    IMF support............." << dictionary[ "QNX_IMF" ] << endl;
         sout << "    PPS support............." << dictionary[ "PPS" ] << endl;
+        sout << "    LGMON support..........." << dictionary[ "LGMON" ] << endl;
     }
     sout << "    ANGLE..................." << dictionary[ "ANGLE" ] << endl;
     sout << endl;
-- 
GitLab