From 8817396fa51dd7cf1ae5f66f3bc79a9b867e0092 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 12 Mar 2024 17:23:23 +0100 Subject: [PATCH] Fix blinking visual on animations (like resizing) by ignoring vertical sync. Add An FPS counter object for benchmarking. Fix dynamic layouts to avoid slinding effects on resizing. --- Linphone/core/App.cpp | 8 +++ Linphone/core/CMakeLists.txt | 1 + Linphone/core/fps-counter/FPSCounter.cpp | 66 ++++++++++++++++++++++++ Linphone/core/fps-counter/FPSCounter.hpp | 40 ++++++++++++++ Linphone/view/App/Layout/LoginLayout.qml | 3 +- Linphone/view/Page/Login/LoginPage.qml | 3 -- 6 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 Linphone/core/fps-counter/FPSCounter.cpp create mode 100644 Linphone/core/fps-counter/FPSCounter.hpp diff --git a/Linphone/core/App.cpp b/Linphone/core/App.cpp index 914c5975..45700973 100644 --- a/Linphone/core/App.cpp +++ b/Linphone/core/App.cpp @@ -40,6 +40,7 @@ #include "core/call/CallList.hpp" #include "core/call/CallProxy.hpp" #include "core/camera/CameraGui.hpp" +#include "core/fps-counter/FPSCounter.hpp" #include "core/friend/FriendCore.hpp" #include "core/friend/FriendGui.hpp" #include "core/friend/FriendInitialProxy.hpp" @@ -64,6 +65,11 @@ DEFINE_ABSTRACT_OBJECT(App) App::App(int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::User | Mode::ExcludeAppPath | Mode::ExcludeAppVersion) { + // Ignore vertical sync. This way, we avoid blinking on resizes(and other refresh like layouts etc.). + auto ignoreVSync = QSurfaceFormat::defaultFormat(); + ignoreVSync.setSwapInterval(0); + QSurfaceFormat::setDefaultFormat(ignoreVSync); + //------------------- mLinphoneThread = new Thread(this); init(); qInfo() << QStringLiteral("Starting application " APPLICATION_NAME " (bin: " EXECUTABLE_NAME @@ -193,6 +199,8 @@ void App::initCppInterfaces() { qmlRegisterType(Constants::MainQmlUri, 1, 0, "MagicSearchProxy"); qmlRegisterType(Constants::MainQmlUri, 1, 0, "FriendInitialProxy"); qmlRegisterType(Constants::MainQmlUri, 1, 0, "CameraGui"); + qmlRegisterType(Constants::MainQmlUri, 1, 0, "FPSCounter"); + LinphoneEnums::registerMetaTypes(); } diff --git a/Linphone/core/CMakeLists.txt b/Linphone/core/CMakeLists.txt index 5ddc5994..a293625c 100644 --- a/Linphone/core/CMakeLists.txt +++ b/Linphone/core/CMakeLists.txt @@ -14,6 +14,7 @@ list(APPEND _LINPHONEAPP_SOURCES core/call-history/CallHistoryProxy.cpp core/camera/CameraGui.cpp core/camera/CameraDummy.cpp + core/fps-counter/FPSCounter.cpp core/friend/FriendCore.cpp core/friend/FriendGui.cpp core/friend/FriendInitialProxy.cpp diff --git a/Linphone/core/fps-counter/FPSCounter.cpp b/Linphone/core/fps-counter/FPSCounter.cpp new file mode 100644 index 00000000..e8db12dd --- /dev/null +++ b/Linphone/core/fps-counter/FPSCounter.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2010-2024 Belledonne Communications SARL. + * + * This file is part of linphone-desktop + * (see https://www.linphone.org). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "FPSCounter.hpp" + +#include +#include +#include + +FPSCounter::FPSCounter(QQuickItem *parent) : QQuickPaintedItem(parent), _currentFPS(0), _cacheCount(0) { + _times.clear(); + setFlag(QQuickItem::ItemHasContents); +} + +FPSCounter::~FPSCounter() { +} + +void FPSCounter::recalculateFPS() { + qint64 currentTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); + _times.push_back(currentTime); + + while (_times[0] < currentTime - 1000) { + _times.pop_front(); + } + + int currentCount = _times.length(); + _currentFPS = (currentCount + _cacheCount) / 2; + qDebug() << _currentFPS; + + if (currentCount != _cacheCount) fpsChanged(_currentFPS); + + _cacheCount = currentCount; +} + +int FPSCounter::fps() const { + return _currentFPS; +} + +void FPSCounter::paint(QPainter *painter) { + recalculateFPS(); + // qDebug() << __FUNCTION__; + QBrush brush(Qt::yellow); + + painter->setBrush(brush); + painter->setPen(Qt::NoPen); + painter->setRenderHint(QPainter::Antialiasing); + painter->drawRoundedRect(0, 0, boundingRect().width(), boundingRect().height(), 0, 0); + update(); +} diff --git a/Linphone/core/fps-counter/FPSCounter.hpp b/Linphone/core/fps-counter/FPSCounter.hpp new file mode 100644 index 00000000..67dd000c --- /dev/null +++ b/Linphone/core/fps-counter/FPSCounter.hpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2010-2024 Belledonne Communications SARL. + * + * This file is part of linphone-desktop + * (see https://www.linphone.org). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +class FPSCounter : public QQuickPaintedItem { + Q_OBJECT + Q_PROPERTY(int fps READ fps NOTIFY fpsChanged) +public: + FPSCounter(QQuickItem *parent = 0); + ~FPSCounter(); + void paint(QPainter *); + Q_INVOKABLE int fps() const; + +signals: + void fpsChanged(int); + +private: + void recalculateFPS(); + int _currentFPS; + int _cacheCount; + QVector _times; +}; diff --git a/Linphone/view/App/Layout/LoginLayout.qml b/Linphone/view/App/Layout/LoginLayout.qml index 15f0c907..d38f380b 100644 --- a/Linphone/view/App/Layout/LoginLayout.qml +++ b/Linphone/view/App/Layout/LoginLayout.qml @@ -23,6 +23,7 @@ Item { RowLayout { Layout.fillWidth: true Layout.preferredHeight: 102 * DefaultStyle.dp + Layout.maximumHeight: 102 * DefaultStyle.dp // Layout.topMargin: 18 // Layout.alignment: Qt.AlignRight | Qt.AlignTop Item { @@ -62,10 +63,10 @@ Item { } ColumnLayout { id: centerLayout - Layout.fillHeight: true } Item { Layout.fillHeight: true + Layout.fillWidth: true } } diff --git a/Linphone/view/Page/Login/LoginPage.qml b/Linphone/view/Page/Login/LoginPage.qml index b1ea309d..36ec352b 100644 --- a/Linphone/view/Page/Login/LoginPage.qml +++ b/Linphone/view/Page/Login/LoginPage.qml @@ -90,9 +90,6 @@ LoginLayout { fillMode: Image.PreserveAspectFit source: AppIcons.loginImage } - Item { - Layout.fillHeight: true - } } } }