Commit 7c47e1ce authored by Daniel Smith's avatar Daniel Smith

Add basic QML and benchmark framework to measure frame times.

parent f7514ea4
......@@ -13,7 +13,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
main.cpp \
benchmark.cpp
RESOURCES += qml.qrc
......@@ -27,3 +28,6 @@ QML_DESIGNER_IMPORT_PATH =
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
benchmark.h
This diff is collapsed.
#include <QObject>
#include <benchmark.h>
#include <QtDebug>
#include <QString>
#include <QElapsedTimer>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QGuiApplication>
void Benchmark::startTimer(){
}
void Benchmark::countFrame(){
qint64 frametime = timer.restart();
int thisframe = static_cast<int>(frametime);
try{
frametimes[frame] = thisframe;
} catch (int e){
printf("frame.");
//No need to handle this. We probably just rendered extra frames before finished() completed.
}
printf("frame %d: %d ms\n", frame, thisframe);
frame+=1;
if (frame >= maxframes){
this->finished();
}
}
void Benchmark::measureFrame(qint64 value){
printf("%d,", static_cast<int>(value));
}
void Benchmark::finished(){
QCoreApplication::quit();
}
int Benchmark::runBenchmark(QGuiApplication &app){
this->timer.start();
QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
if (engine.rootObjects().size() != 1)
return -1;
QQuickWindow *window = qobject_cast<QQuickWindow*>(engine.rootObjects().first());
//Finish timing after the first frame is ready.
QObject::connect(window, &QQuickWindow::frameSwapped,
this, &Benchmark::countFrame);
//QCoreApplication::instance(), &QCoreApplication::quit);
if (app.exec() != 0)
return -1;
//return timer.elapsed(); //change to print averages.
//return runBenchmark(startup);
}
#ifndef BENCHMARK_H
#define BENCHMARK_H
#include <QObject>
#include <QGuiApplication>
#include <QElapsedTimer>
class Benchmark: public QObject{
public:
int runBenchmark(QGuiApplication &);
public slots:
void countFrame();
void countMemory(int value);
private:
QElapsedTimer timer;
int frame = 0;
int lastframetotal;
static const int maxframes = 120;
int frametimes [maxframes];
void finished();
void startTimer();
void measureFrame(qint64);
};
#endif // BENCHMARK_H
#include <QGuiApplication>
#include <QQuickWindow>
#include <QQmlApplicationEngine>
#include <QtCore/QElapsedTimer>
#include <benchmark.h>
int runBenchmark(std::function<qint64()> f) {
{
printf("Startup times (ms): [1st run, 2nd run]\n");
auto r = f();
if (r >= 0)
printf("%d,", static_cast<int>(r));
else
return -1;
}
{
auto r = f();
if (r >= 0)
printf("%d\n", static_cast<int>(r));
else
return -1;
}
return 0;
}
int main(int argc, char *argv[])
{
......@@ -14,10 +38,20 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
Benchmark benchmark;
/*
auto startup = [&app](){
QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
if (engine.rootObjects().size() != 1)
return -1;
QQuickWindow *window = qobject_cast<QQuickWindow*>(engine.rootObjects().first());
QObject::connect(window, &QQuickWindow::frameSwapped,
&benchmark, &Benchmark::countFrame);
//QCoreApplication::instance(), &QCoreApplication::quit);
if (app.exec() != 0)
return -1;
};
*/
//return runBenchmark(startup);
return benchmark.runBenchmark(app);
}
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Enterprise.VirtualKeyboard 2.0
Window {
id: window
......@@ -9,32 +9,17 @@ Window {
height: 480
title: qsTr("Hello World")
InputPanel {
id: inputPanel
z: 99
x: 0
y: window.height
width: window.width
states: State {
name: "visible"
when: inputPanel.active
PropertyChanges {
target: inputPanel
y: window.height - inputPanel.height
}
}
transitions: Transition {
from: ""
to: "visible"
reversible: true
ParallelAnimation {
NumberAnimation {
properties: "y"
duration: 250
easing.type: Easing.InOutQuad
}
}
Rectangle {
id: xmovingBox
width: 50
height: 50
color: "lightsteelblue"
XAnimator {
target: xmovingBox;
from: 590;
to: 0;
duration: 30000
running: true
}
}
}
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>timer.qml</file>
</qresource>
</RCC>
import QtQuick 2.2
Timer {
running: true
interval: 0
onTriggered: Qt.quit();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment