PDA

View Full Version : [iOS] Why empty QOpenGLWidget update/repaint() uses about 20%-50% cpu?



vitaliynet
13th July 2020, 21:55
Hello
I am new and just touch a the framework.

Now in the QT I see the same thing but load is about 20%-50%.
On iPhone 10 - 15-20% cpu load
On iPad 13 inch Pro - 30-50% cpu load.

Yes it's better with -O3. About 28-34% but wait.. it's just empty screen. Perhaps I'm doing something wrong? Or not called something before the initialisation? And the difference between repaint() and update() I not noticed at all. I want about 6-7% cpu, like the native iOS's setNeedDisplay() does it. But not sure what to do. Thanks.

This is my code. BTW, about 6-8% uses mouseMoveEvent when I move the finger.


Moreover, energy use is HIGH in the Xcode profiler avr: 83.4% GPU. It's really strange. I never saw this in any project. Always just: Low.

Thank you!



#include "mainwidget.h"

MainWidget::MainWidget(QOpenGLWidget *parent) : QOpenGLWidget(parent)
{

}

MainWidget::~MainWidget() {

}


void MainWidget::resizeEvent(QResizeEvent *e) {
QOpenGLWidget::resizeEvent(e);
}


void MainWidget::mouseMoveEvent(QMouseEvent *e) {
update();
}

void MainWidget::paintGL()
{

}

d_stranz
14th July 2020, 17:28
void MainWidget::mouseMoveEvent(QMouseEvent *e) {
update();
}

I am guessing that this is the cause of your problem. You should not have to call update(), repaint(), or anything else in a mouse event. Qt takes care of whatever needs to be done in response to mouse move events to keep the window updated.

vitaliynet
14th July 2020, 17:46
I am guessing that this is the cause of your problem. You should not have to call update(), repaint(), or anything else in a mouse event. Qt takes care of whatever needs to be done in response to mouse move events to keep the window updated.

Thanks for response. but sorry I'm unclear. If I'll insert some code to draw for example simple rectangle (0, 0, mouse_y, 100). Then Nothing happens if I NOT call update(); Please note that I use iOS/Android devices, not the windows in MacOS/Windows OS.

But ok... Let's not use mouse. Even with a QTimer for 100-200 ms (i.e. if I call update() each 100ms). I see 30-40% cpu load and GPU 70-80% load. On the iOS with a basic 4000 CALayers and changing their frame/bounds at the same time - I see just 5-7% cpu load and gpu load is about 0-1%. I tried Juce framework, but they have 60-70% cpu and very very critical GPU load. about 80-90%. Again I'm asking only about iPad/iPhone. Not tested a lot android.

ChrisW67
18th July 2020, 08:29
The mouse move event handler may be called hundreds or thousands of times during a finger drag. The mouse handler should inspect the event and record the rectangle you intend to draw in a member variable. Call update() only if it changes materially. The mouse move event handler should not draw anything: that is the exclusive domain of the paintEvent()/paintGL().

If you want specific advice then post actual code that behaves poorly.

Do any of the Qt demo/example OpenGL programs (https://doc.qt.io/qt-5/examples-widgets-opengl.html) behave poorly?

vitaliynet
20th July 2020, 20:41
The mouse move event handler may be called hundreds or thousands of times during a finger drag. The mouse handler should inspect the event and record the rectangle you intend to draw in a member variable. Call update() only if it changes materially. The mouse move event handler should not draw anything: that is the exclusive domain of the paintEvent()/paintGL().

If you want specific advice then post actual code that behaves poorly.

Do any of the Qt demo/example OpenGL programs (https://doc.qt.io/qt-5/examples-widgets-opengl.html) behave poorly?

Thanks. Everything is correct. I don't draw anything in the mouse handler and I don't need a static image on screen. I plan to draw a jog wheel for my synth app. My jog is simple rect lines (about 46 lines width: 70px, height: 2px) When moving my finger on a iPad screen this lines should move behind the finger with great precision + = 0.5f by the Y coordinate.

So in the mouse handler, I tell the graphics context to redraw this lines. Because the position of rect/line changes each time user drag the finger. So YES I need it to be called hundreds or thousands of times. If the calling "update" from mouse handler is bad way, then how to tell graphic card to redraw my code from paintEvent method? The position of all lines is depend on the position of the finger on the screen.

And yes, unfortunately in the DEMO I see the same CPU/GPU load. And in the xcode profiler this load is critical. Especially on the graphics card. BTW I don't see this critical load with Flutter framework or with native Apple's CALayer.

But as I said above, I have not written any line of code. A regular timer that refreshes the context every 60frames/per second, on an empty widget, again... without a single line of code, shows a heavy load on the processor and video card. It's empty widget, why such a load?