Results 1 to 2 of 2

Thread: QT App performance is too slow on OSX

  1. #1
    Join Date
    May 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QT App performance is too slow on OSX

    Hello! First of all - i'm not programmer, just tester. I test an app that use grabWindow function to capture screen and get average color.
    We have compiled our program for Win/Linux/Mac and for Win/Linux app performance is much much higher about 40-90fps but on Mac with same settings it drops to 6-8fps and not much.

    App use few zones to capture via iteration. Zones count 1-8.


    This code is capable to grab and transform captured screen.

    Qt Code:
    1. namespace GrabQt
    2. {
    3.  
    4. QRgb getColor(const QWidget * grabme)
    5. {
    6. DEBUG_HIGH_LEVEL << Q_FUNC_INFO;
    7.  
    8. int x = grabme->x();
    9. int y = grabme->y();
    10. int width = grabme->width();
    11. int height = grabme->height();
    12.  
    13. DEBUG_HIGH_LEVEL << "x y w h:" << x << y << width << height;
    14.  
    15. QPixmap pix = QPixmap::grabWindow(QApplication::desktop()->winId(), x, y, width, height);
    16. QPixmap scaledPix = pix.scaled(1,1, Qt::IgnoreAspectRatio, Qt::FastTransformation);
    17. QImage im = scaledPix.toImage();
    18. QRgb result = im.pixel(0,0);
    19.  
    20. DEBUG_HIGH_LEVEL << "QRgb result =" << hex << result;
    21.  
    22. return result;
    23. }
    24.  
    25. };
    To copy to clipboard, switch view to plain text mode 

    This code call grab and transform iteration for each zones.

    Qt Code:
    1. void GrabManager::updateLedsColorsIfChanged()
    2. {
    3. DEBUG_HIGH_LEVEL << Q_FUNC_INFO;
    4.  
    5. // Temporary switch off updating colors
    6. // if one of LED widgets resizing or moving
    7. if(isResizeOrMoving){
    8. timerGrab->start(50); // check in 50 ms
    9. return;
    10. }
    11.  
    12. bool needToUpdate = false;
    13.  
    14. int avgR = 0, avgG = 0, avgB = 0;
    15. int countGrabEnabled = 0;
    16.  
    17. clearColorsNew();
    18.  
    19.  
    20. //#define PRINT_TIME_SPENT_ON_GRAB
    21. #ifdef PRINT_TIME_SPENT_ON_GRAB
    22. QTime t; t.start();
    23. #endif
    24.  
    25. // Capture screen what contains first LED widgets
    26. if(isGrabWinAPI){
    27. GrabWinAPI::captureScreen();
    28. }
    29.  
    30. for(int ledIndex=0; ledIndex<LEDS_COUNT; ledIndex++){
    31. if(ledWidgets[ledIndex]->isGrabEnabled()){
    32. QRgb rgb;
    33. if(isGrabWinAPI){
    34. rgb = GrabWinAPI::getColor( ledWidgets[ledIndex] );
    35. } else {
    36. rgb = GrabQt::getColor( ledWidgets[ledIndex] );
    37. }
    38.  
    39. if( avgColorsOnAllLeds ){
    40. avgR += qRed(rgb);
    41. avgG += qGreen(rgb);
    42. avgB += qBlue(rgb);
    43. countGrabEnabled++;
    44. }else{
    45. colorsNew[ledIndex].rgb = rgb;
    46. }
    47. }else{
    48. colorsNew[ledIndex].rgb = 0; // off led
    49. }
    50. }
    51.  
    52. #ifdef PRINT_TIME_SPENT_ON_GRAB
    53. qDebug() << "Time spent on grab:" << t.elapsed() << "ms";
    54. #endif
    55.  
    56. if( avgColorsOnAllLeds ){
    57. if( countGrabEnabled != 0 ){
    58. avgR /= countGrabEnabled;
    59. avgG /= countGrabEnabled;
    60. avgB /= countGrabEnabled;
    61. }
    62. // Set one AVG color to all LEDs
    63. for(int ledIndex = 0; ledIndex < LEDS_COUNT; ledIndex++){
    64. if(ledWidgets[ledIndex]->isGrabEnabled()){
    65. colorsNew[ledIndex].rgb = qRgb(avgR, avgG, avgB);
    66. }
    67. }
    68. }
    69.  
    70. #if 0
    71. // 0 <= color <= ambilight_color_depth
    To copy to clipboard, switch view to plain text mode 


    I think on Mac OS X this part of upper code is slowing down all capture. Iteration of grabWindow slowing down all process.

    Qt Code:
    1. for(int ledIndex=0; ledIndex<LEDS_COUNT; ledIndex++){
    2. if(ledWidgets[ledIndex]->isGrabEnabled()){
    3. QRgb rgb;
    4. if(isGrabWinAPI){
    5. rgb = GrabWinAPI::getColor( ledWidgets[ledIndex] );
    6. } else {
    7. rgb = GrabQt::getColor( ledWidgets[ledIndex] );
    8. }
    9.  
    10. if( avgColorsOnAllLeds ){
    11. avgR += qRed(rgb);
    12. avgG += qGreen(rgb);
    13. avgB += qBlue(rgb);
    14. countGrabEnabled++;
    15. }else{
    16. colorsNew[ledIndex].rgb = rgb;
    17. }
    18. }else{
    19. colorsNew[ledIndex].rgb = 0; // off led
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 


    Does anyone know the reason why grabbing screen on OSX is too slow instead of Win/Linux. And how we can fix it? Maybe via grabbing screen in OSX from OGL framebuffer, cause OSX output all to OGL surface? Or maybe use one screen capture for all zones and do an iteration of cut/resize parts from one catured screen? Or maybe something else?

    Thank you!

    ps. sorry for bad language.
    project home is http://code.google.com/p/lightpack/

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QT App performance is too slow on OSX

    I'm not a OSX user, so I don't know the answer, but what I know is that the getColor method could be done better.
    I understand that it's purpose is to grab the (0,0) pixel color from widget, so I don't see why you need to grab the whole desktop ? Can't you use the QWidget::winId()? And if all you need is this one pixel, pass a QRectF(0,0,1,1) to QPixmap::grabWindow, no need to scale anything, so your method will look like:
    Qt Code:
    1. QRgb getColor(const QWidget * grabme)
    2. {
    3. DEBUG_HIGH_LEVEL << Q_FUNC_INFO;
    4.  
    5. QPixmap pix = QPixmap::grabWindow(grabme->winId(),0,0,1,1);
    6. QImage im = pix.toImage();
    7. QRgb result = im.pixel(0,0);
    8.  
    9. DEBUG_HIGH_LEVEL << "QRgb result =" << hex << result;
    10.  
    11. return result;
    12. }
    To copy to clipboard, switch view to plain text mode 
    I think it could be faster.

Similar Threads

  1. Slow performance of QGraphicsView - why?
    By zeldaknight in forum Newbie
    Replies: 2
    Last Post: 25th August 2010, 03:34
  2. Replies: 1
    Last Post: 8th August 2010, 20:04
  3. Qt4 designer SLOW - how to fix?
    By hvengel in forum Qt Tools
    Replies: 3
    Last Post: 10th January 2008, 12:07
  4. Slow application
    By Pieter from Belgium in forum Qt Programming
    Replies: 3
    Last Post: 17th October 2006, 09:44

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.