We've got a chunk of code that draws to an NSImage (text with a nice looking background), then converts it to an NSBitmapImageRep for use as a texture (originally OpenGL, now Metal). It's worked without issue for years on thousands of customer machines.
Psuedocode:
image = [[NSImage alloc] initWithSize:size];
[image lockFocus];
//Do drawing
bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:rect];
[image unlockFocus];
//Generate texture using [bitmap bitmapData];
Now we have a customer with a brand new MacBook running macOS 10.15, and the texture is getting corrupted. We've tracked it down to the NSBitmapImageRep being created with floating point samples.
I've also noticed that initWithFocusedViewRect is now deprecated. I've attempted to use [image CGImageForProposedRect] and then create the NSBitmapImageRep from the CGImage, but that has the same problem with floating point samples.
So my questions are:
I've discovered two ways to make this work:
Use NSBitmapImageRep initWithBitmapDataPlanes... to specify the exact format we want to use. Then set the current context to a NSGraphicsContext created with the image rep to draw directly to it:
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmapRep]];