Created
November 30, 2017 22:57
-
-
Save ccgus/0337933e6b5b079a4865ef77619da855 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void TSCreateImageFromIOSurfaceReleaseCallback(void * __nullable info, const void *data, size_t size); | |
void TSCreateImageFromIOSurfaceReleaseCallback(void * __nullable info, const void *data, size_t size) { | |
CFRelease(info); | |
} | |
CGImageRef TSCreateImageFromIOSurface(IOSurfaceRef surface, CGColorSpaceRef cs) { | |
IOReturn result = IOSurfaceLock(surface, 0, nil); | |
FMAssert(result == kIOReturnSuccess); | |
CFRetain(surface); // will be released in TSCreateImageFromIOSurfaceReleaseCallback | |
CGDataProviderRef dp = CGDataProviderCreateWithData(surface, IOSurfaceGetBaseAddress(surface), IOSurfaceGetHeight(surface) * IOSurfaceGetBytesPerRow(surface), &TSCreateImageFromIOSurfaceReleaseCallback); | |
CGImageRef r = CGImageCreate(IOSurfaceGetWidth(surface), IOSurfaceGetHeight(surface), 8, 32, IOSurfaceGetBytesPerRow(surface), cs, (CGBitmapInfo)kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big, dp, nil, false, kCGRenderingIntentDefault); | |
CGDataProviderRelease(dp); | |
IOSurfaceUnlock(surface, 0, nil); | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment