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.
This commit is contained in:
Julien Wadel 2024-03-12 17:23:23 +01:00
parent f7749a30e3
commit 8817396fa5
6 changed files with 117 additions and 4 deletions

View file

@ -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<MagicSearchProxy>(Constants::MainQmlUri, 1, 0, "MagicSearchProxy");
qmlRegisterType<FriendInitialProxy>(Constants::MainQmlUri, 1, 0, "FriendInitialProxy");
qmlRegisterType<CameraGui>(Constants::MainQmlUri, 1, 0, "CameraGui");
qmlRegisterType<FPSCounter>(Constants::MainQmlUri, 1, 0, "FPSCounter");
LinphoneEnums::registerMetaTypes();
}

View file

@ -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

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "FPSCounter.hpp"
#include <QBrush>
#include <QDateTime>
#include <QPainter>
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();
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <QQuickPaintedItem>
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<qint64> _times;
};

View file

@ -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
}
}

View file

@ -90,9 +90,6 @@ LoginLayout {
fillMode: Image.PreserveAspectFit
source: AppIcons.loginImage
}
Item {
Layout.fillHeight: true
}
}
}
}