Skip to content

CGDisplayBitsPerPixel is deprecated #2

@soundflix

Description

@soundflix

Thanks for forking / putting this up here!

I noticed in Xcode 12.4, this line raises an error:

long bpp = CGDisplayBitsPerPixel(cgScreenID);

"Implicit declaration of function 'CGDisplayBitsPerPixel' is invalid in C99"

I found that CGDisplayBitsPerPixel is deprecated.

I found this solution:

https://stackoverflow.com/questions/8210824/how-to-avoid-cgdisplaymodecopypixelencoding-to-get-bpp

I replaced the above line with this code and it works again:

        CGDisplayModeRef mode = CGDisplayCopyDisplayMode(cgScreenID);
        CFDictionaryRef dict = (CFDictionaryRef)*((int64_t *)mode + 2);
        CFNumberRef num;
        int bpp;
        if (CFGetTypeID(dict) == CFDictionaryGetTypeID()
            && CFDictionaryGetValueIfPresent(dict, kCGDisplayBitsPerPixel, (const void**)&num))
        {
            CFNumberGetValue(num, kCFNumberSInt32Type, (void*)&bpp);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions