1#include "ppsspp_config.h"
2#if PPSSPP_PLATFORM(MAC)
3#import <Cocoa/Cocoa.h>
4#else
5#import <UIKit/UIKit.h>
6#endif
7#import <QuartzCore/CAMetalLayer.h>
8
9#include "SDLCocoaMetalLayer.h"
10
11void *makeWindowMetalCompatible(void *window) {
12	// https://github.com/KhronosGroup/MoltenVK/issues/78#issuecomment-371118536
13#if PPSSPP_PLATFORM(MAC)
14	NSView *view = ((NSWindow *)window).contentView;
15	assert([view isKindOfClass:[NSView class]]);
16
17	if (![view.layer isKindOfClass:[CAMetalLayer class]])
18	{
19		[view setLayer:[CAMetalLayer layer]];
20	}
21	return view.layer;
22#else
23	UIView *view = (UIView *)window;
24	assert([view isKindOfClass:[UIView class]]);
25
26	CAMetalLayer *metalLayer = [CAMetalLayer new];
27
28	CGSize viewSize = view.frame.size;
29	metalLayer.frame = view.frame;
30	metalLayer.opaque = true;
31	metalLayer.framebufferOnly = true;
32	metalLayer.drawableSize = viewSize;
33	metalLayer.pixelFormat = (MTLPixelFormat)80;//BGRA8Unorm==80
34	[view.layer addSublayer:metalLayer];
35	return metalLayer;
36#endif
37}
38