From 16e3a3e4ec675b37a6be4807aeb65f0b88834928 Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Tue, 26 Oct 2021 09:12:02 -0700 Subject: [PATCH] CocoaSpice: save screenshot for GL backend --- CocoaSpice/CSDisplayMetal.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CocoaSpice/CSDisplayMetal.m b/CocoaSpice/CSDisplayMetal.m index 2a85390e8..968644702 100644 --- a/CocoaSpice/CSDisplayMetal.m +++ b/CocoaSpice/CSDisplayMetal.m @@ -14,6 +14,7 @@ // limitations under the License. // +@import CoreImage; #import "TargetConditionals.h" #import "UTMScreenshot.h" #import "UTMShaderTypes.h" @@ -431,9 +432,11 @@ - (UTMScreenshot *)screenshot { CGDataProviderRef dataProviderRef = CGDataProviderCreateWithData(NULL, self.canvasData, self.canvasStride * self.canvasArea.size.height, nil); img = CGImageCreate(self.canvasArea.size.width, self.canvasArea.size.height, 8, 32, self.canvasStride, colorSpaceRef, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, dataProviderRef, NULL, NO, kCGRenderingIntentDefault); CGDataProviderRelease(dataProviderRef); - } else if (_glTexture) { - // TODO: make screenshot from IOSurface - img = NULL; + } else if (self.glTexture) { + CIImage *ciimage = [[CIImage alloc] initWithMTLTexture:self.glTexture options:nil]; + CIImage *flipped = [ciimage imageByApplyingOrientation:kCGImagePropertyOrientationDownMirrored]; + CIContext *cictx = [CIContext context]; + img = [cictx createCGImage:flipped fromRect:flipped.extent]; } else { img = NULL; }