OS X help needed

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

OS X help needed

John W. Eaton
Administrator
We have the following code to get the number of bits per pixel for the
current display on OS X systems:

#if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL)

       *dp = CGDisplayBitsPerPixel (display);

#else

       /* FIXME: This will only work for MacOS > 10.5.  For earlier versions
          this code is not needed (use CGDisplayBitsPerPixel instead).  */

       CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display);
       CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode);

       if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels),
0) == 0)
         *dp = 32;
       else if (CFStringCompare (pixelEncoding,
                                 CFSTR (IO16BitDirectPixels), 0) == 0)
         *dp = 16;
       else
         *dp = 8;

#endif

But now I see that the function CGDisplayModeCopyPixelEncoding has been
deprecated for OS X 10.11.  Is there a replacement?  It doesn't have to
be a direct replacement for this function, we just need some way to get
a value for the number of bits per pixel for the display.

jwe


Reply | Threaded
Open this post in threaded view
|

Re: OS X help needed

Nir Krakauer-3
Nobody on the Internet seems to know, except for a hack being mentioned
https://github.com/SFML/SFML/issues/1122
Reply | Threaded
Open this post in threaded view
|

Re: OS X help needed

John Swensen-3
In reply to this post by John W. Eaton

On Oct 27, 2016, at 10:05 AM, John W. Eaton <[hidden email]> wrote:

We have the following code to get the number of bits per pixel for the current display on OS X systems:

#if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL)

     *dp = CGDisplayBitsPerPixel (display);

#else

     /* FIXME: This will only work for MacOS > 10.5.  For earlier versions
        this code is not needed (use CGDisplayBitsPerPixel instead).  */

     CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display);
     CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode);

     if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels), 0) == 0)
       *dp = 32;
     else if (CFStringCompare (pixelEncoding,
                               CFSTR (IO16BitDirectPixels), 0) == 0)
       *dp = 16;
     else
       *dp = 8;

#endif

But now I see that the function CGDisplayModeCopyPixelEncoding has been deprecated for OS X 10.11.  Is there a replacement?  It doesn't have to be a direct replacement for this function, we just need some way to get a value for the number of bits per pixel for the display.

jwe



Unfortunately, I don’t think there are any good options. As far as I can tell, Apple is trying to move toward “act like you have 30 bit depth and we will take care of making it look right if it is something less”.

There is a hack shown how to do it linked from https://github.com/SFML/SFML/issues/1122 to http://stackoverflow.com/questions/8210824/how-to-avoid-cgdisplaymodecopypixelencoding-to-get-bpp/33519316#33519316. The likelihood of that dictionary changing in the future is probably pretty good, so probably not a good/satisfying solution.

Sorry to not be more help.

John S.

Reply | Threaded
Open this post in threaded view
|

Re: OS X help needed

Sebastian Schöps
In reply to this post by John W. Eaton
John W. Eaton wrote
We have the following code to get the number of bits per pixel for the
current display on OS X systems:

[...]

But now I see that the function CGDisplayModeCopyPixelEncoding has been
deprecated for OS X 10.11.  Is there a replacement?  It doesn't have to
be a direct replacement for this function, we just need some way to get
a value for the number of bits per pixel for the display.

jwe
I am not much help w.r.t. GUI programming but are you aware of the discussion at https://savannah.gnu.org/bugs/?49053 ? or let me ask differently: could one use qt for this?

Sebastian
Reply | Threaded
Open this post in threaded view
|

Re: OS X help needed

John W. Eaton
Administrator
On 10/27/2016 01:49 PM, Sebastian Schöps wrote:

> John W. Eaton wrote
>> We have the following code to get the number of bits per pixel for the
>> current display on OS X systems:
>>
>> [...]
>>
>> But now I see that the function CGDisplayModeCopyPixelEncoding has been
>> deprecated for OS X 10.11.  Is there a replacement?  It doesn't have to
>> be a direct replacement for this function, we just need some way to get
>> a value for the number of bits per pixel for the display.
>>
>> jwe
>
> I am not much help w.r.t. GUI programming but are you aware of the
> discussion at https://savannah.gnu.org/bugs/?49053 ? or let me ask
> differently: could one use qt for this?

Not really, as we still want to be able to get the info for the root
figure object even if not using Qt.

But, just to see what Qt provides and how it works, I looked and there
is the function

http://doc.qt.io/qt-4.8/qpaintdevice.html#metric

along with an enum value to get the display depth, as well as

http://doc.qt.io/qt-4.8/qpaintdevice.html#depth

to get the display depth directly (I think that's just a wrapper around
the metric function).  Anyway, for OS X systems, Qt 4.8 simply returns
32 unconditionally, and for Qt 5, it returns 24.

I suppose we could do the same if the functions to get the value from
the OS are not available.

jwe