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/