# HG changeset patch # User sl # Date 1401804707 -7200 # Node ID a42cc76a2d5ac3a058bd328a23d4aa5d4fb709f5 # Parent 8297924aa384d9fef0d691c5c28132241e13df77 Trying to get rid of our QML timer. We now connect to our window after animation signal from C++. It looks like it works much better now. Less UI lags smother animation. diff -r 8297924aa384 -r a42cc76a2d5a MiniDisplay/minidisplay.cpp --- a/MiniDisplay/minidisplay.cpp Mon Jun 02 21:56:03 2014 +0200 +++ b/MiniDisplay/minidisplay.cpp Tue Jun 03 16:11:47 2014 +0200 @@ -197,6 +197,49 @@ iDisplay.BitBlit(bits,w,h,0,0); } + +/** + * @brief MiniDisplay::connectWindow + * @param aWindow + */ +void MiniDisplay::connectWindow(QQuickWindow* aWindow, QJSValue aFunction) +{ + QObject::connect(aWindow, SIGNAL(afterAnimating()), + this, SLOT(onAfterAnimating())); + + iAfterAnimatingCallback = aFunction; + iWindow = aWindow; +} + +/** + * @brief MiniDisplay::onAfterAnimating + */ +void MiniDisplay::onAfterAnimating() +{ + static int frame=0; + qDebug() << frame << "MiniDisplay::onAfterAnimating"; + /* + if (iAfterAnimatingCallback.isCallable()) + { + iAfterAnimatingCallback.call(); + }*/ + + renderWindow(iWindow); + swapBuffers(); + + //Interrestingly rendering will suspend when we stop changing our text field content + if (frame%8==0) + { + if (iAfterAnimatingCallback.isCallable()) + { + iAfterAnimatingCallback.call(QJSValueList() << frame); + } + } + + frame++; +} + + /** * @brief MiniDisplay::setPixel * @param x diff -r 8297924aa384 -r a42cc76a2d5a MiniDisplay/minidisplay.h --- a/MiniDisplay/minidisplay.h Mon Jun 02 21:56:03 2014 +0200 +++ b/MiniDisplay/minidisplay.h Tue Jun 03 16:11:47 2014 +0200 @@ -40,6 +40,8 @@ Q_INVOKABLE void renderWindow(QQuickWindow* aWindow); Q_INVOKABLE void renderImage(QImage* aImage); // + Q_INVOKABLE void connectWindow(QQuickWindow* aWindow, QJSValue aFunction); + // Q_INVOKABLE void setPixel(int x, int y, bool on); @@ -69,6 +71,9 @@ QPoint framePosition() const; void setFramePosition(const QPoint& aPoint); +public slots: + void onAfterAnimating(); + signals: void opened(); void openError(); @@ -98,6 +103,8 @@ int iReadAttempt; int iBrightness; QPoint iFramePosition; + QJSValue iAfterAnimatingCallback; + QQuickWindow* iWindow; }; #endif // MINIDISPLAY_H diff -r 8297924aa384 -r a42cc76a2d5a TestsTab.qml --- a/TestsTab.qml Mon Jun 02 21:56:03 2014 +0200 +++ b/TestsTab.qml Tue Jun 03 16:11:47 2014 +0200 @@ -37,7 +37,8 @@ //! [screen-properties] width: rectangleScreen.width height: rectangleScreen.height - property int frameCounter:0; + //property int frameCounter:0; + property int firstFrame:-1; property var startTime:new Date(); Rectangle { @@ -111,76 +112,87 @@ antialiasing: false } + //onA: {} + } + function doFrame(frameCount) + { + var current = new Date(); + var milliseconds = (current.getTime() - startTime.getTime()); + if (firstFrame==-1) + { + firstFrame=frameCount + } + + + var frameCounter=frameCount-firstFrame; + labelFrameCount.text=frameCounter; + labelTime.text=milliseconds/1000; + labelTimePerFrame.text=(milliseconds/frameCounter).toFixed(3); + labelFps.text=(1000/(milliseconds/frameCounter)).toFixed(0); + + if (checkBoxDoClear.checked) + { + display.clear(); + } + + if (checkBoxRenderToDisplay.checked) + { + if (checkBoxFillAndClearOnly.checked) + { + //Trying to make it a worse case scenario for our frame diff algo + if (doFill) + { + display.fill(); + } + else + { + display.clear(); + } + + if (frameCounter%2) + { + doFill=!doFill; + } + } + else if (checkBoxOnePixelOnly.checked) + { + display.setPixel(0,0,frameCounter%2); + } + else + { + display.renderWindow(frameWindow); + } + + if (!checkBoxNoSwapBuffers.checked) + { + display.swapBuffers(); + } + + } + } //! [timer] Timer { id: timer - interval: frameWindow.timeoutInterval; running: true; repeat: true + interval: frameWindow.timeoutInterval; running: false; repeat: true property bool doFill: true onTriggered: { //visible = false - - var current = new Date(); - var milliseconds = (current.getTime() - frameWindow.startTime.getTime()); - - frameWindow.frameCounter++; - labelFrameCount.text=frameWindow.frameCounter; - labelTime.text=milliseconds/1000; - labelTimePerFrame.text=(milliseconds/frameWindow.frameCounter).toFixed(3); - labelFps.text=(1000/(milliseconds/frameWindow.frameCounter)).toFixed(0); - - if (checkBoxDoClear.checked) - { - display.clear(); - } - - if (checkBoxRenderToDisplay.checked) - { - if (checkBoxFillAndClearOnly.checked) - { - //Trying to make it a worse case scenario for our frame diff algo - if (doFill) - { - display.fill(); - } - else - { - display.clear(); - } - - if (frameWindow.frameCounter%2) - { - doFill=!doFill; - } - } - else if (checkBoxOnePixelOnly.checked) - { - display.setPixel(0,0,frameWindow.frameCounter%2); - } - else - { - display.renderWindow(frameWindow); - } - - if (!checkBoxNoSwapBuffers.checked) - { - display.swapBuffers(); - } - - } + //frameWindow.doFrame(); //Signal our timeout - frameWindow.timeout(); + //frameWindow.timeout(); } } //! [timer] Component.onCompleted: { - visible = true + visible = true; + display.connectWindow(frameWindow,doFrame); } } @@ -202,7 +214,8 @@ text: qsTr("Reset stats") onClicked: { frameWindow.startTime = new Date(); - frameWindow.frameCounter = 0; + //frameWindow.frameCounter = 0; + frameWindow.firstFrame = -1; } }