Results 1 to 5 of 5

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

  1. #1
    Join Date
    Jul 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Question [iOS] Why empty QOpenGLWidget update/repaint() uses about 20%-50% cpu?

    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!

    Qt Code:
    1. #include "mainwidget.h"
    2.  
    3. MainWidget::MainWidget(QOpenGLWidget *parent) : QOpenGLWidget(parent)
    4. {
    5.  
    6. }
    7.  
    8. MainWidget::~MainWidget() {
    9.  
    10. }
    11.  
    12.  
    13. void MainWidget::resizeEvent(QResizeEvent *e) {
    14. QOpenGLWidget::resizeEvent(e);
    15. }
    16.  
    17.  
    18. void MainWidget::mouseMoveEvent(QMouseEvent *e) {
    19. update();
    20. }
    21.  
    22. void MainWidget::paintGL()
    23. {
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by vitaliynet; 13th July 2020 at 22:28.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,563
    Thanks
    254
    Thanked 728 Times in 718 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

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

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

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

    Quote Originally Posted by d_stranz View Post
    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.
    Last edited by vitaliynet; 14th July 2020 at 17:50.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,647
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

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

    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 behave poorly?

  5. #5
    Join Date
    Jul 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

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

    Quote Originally Posted by ChrisW67 View Post
    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 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?
    Last edited by vitaliynet; 20th July 2020 at 20:45.

Similar Threads

  1. Replies: 3
    Last Post: 18th March 2014, 23:47
  2. repaint/update stops updating GUI
    By gokceng in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th November 2011, 14:35
  3. Replies: 4
    Last Post: 17th October 2010, 22:30
  4. Replies: 4
    Last Post: 10th June 2010, 21:25
  5. Use of repaint/update
    By Placido Currò in forum Qt Programming
    Replies: 3
    Last Post: 3rd April 2007, 19:24

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.