Access to the OSX 10.7 framebuffer

I am currently working on a project such as Remote Desktop, in particular, I am trying to provide replacement code for the old methods described above that were used previously. I dealt with this quite successfully, for the most part, but it seems that I have reached a stumbling block.

In OSX 10.7, the call method CGDisplayBaseAddress has been depreciated ( 1 ). This used to give me the base address of the framebuffer in memory, which was used elsewhere to see which parts of the screen were changed and determine what needs to be sent to the remote display. Now it returns NULL.

My current solution was to use CGDisplayCreateImage ( 2 ), which gives me CGImageRef, which I can then use to get a pointer to the raw data (via the CFDataRef object - for code see below) for the image.

Is this the best way to do this? Surely there should be a better way to do this!

To summarize: I don’t want to do any drawing on the screen or anything that I’m just trying to get a pointer to the first byte in memory that contains either a desktop framebuffer or (as I am doing now) a data image.

Thanks for any help you can give! :)

Current solution code:

CFDataRef copy_image_pixels(CGImageRef inImage) { return CGDataProviderCopyData(CGImageGetDataProvider(inImage)); } /** ret_byte_buffer is the byte buffer containing the pixel data for the image **/ void *getPixelDataForImage (CGImageRef image) { //Check image ref is not null if (!image){ NSLog(@"Error - image was null"); return -1; } //Gets a CFData reference for the specified image reference CFDataRef pixelData = copy_image_pixels(image); //Gets a readonly pointer to the image data const UInt8 *pointerToData = CFDataGetBytePtr(pixelData); //This returns a read only version //Casting to a void pointer to return, expected to be cast to a byte_t * CFIndex length_of_buffer = CFDataGetLength(pixelData); printf("Size of buffer is %zu\n",length_of_buffer); return (void *)pointerToData; } 

code snippet to get CGImageRef -

 osx_disp= main_screen_details->main_screenid; //Returns CGDirectDisplayID CGImageRef screenShot = CGDisplayCreateImage(osx_disp); byte_t *image_byte_data = getPixelDataForImage(screenShot); 

byte_t is typedef'd for an unsigned char

+6
source share
1 answer

From my research, it seems that you no longer need access to the framebuffer.

They, like I did it above, may not be the best way, but it certainly works for what I need: :)

Previously, you had to block the display to do what you wanted to do with it, and then release it, which sometimes can cause the screen to flicker when you exit the screen.

The new way, creating an image, means that you do not need to deal with any of them, just create an image and your golden one :)

One thing that I would add to my existing code is that you have to remember to free up CGImageRef or its MAJOR memory leak.

To do this, just call:

 CFRelease(screenShot); 

We also need to free the pixelData object in the same way.

 CFRelease(pixelData); 
+2
source

All Articles