11#import <Metal/Metal.h>
12#import <UIKit/UIKit.h>
23 return [CAMetalLayer class];
33 ~MetalWindowContext_ios()
override;
35 bool onInitializeContext()
override;
36 void onDestroyContext()
override;
38 void resize(
int w,
int h)
override;
42 UIViewController* fViewController;
49 , fWindow(
info.fWindow)
50 , fViewController(
info.fViewController) {
54 this->initializeContext();
57MetalWindowContext_ios::~MetalWindowContext_ios() {
58 this->destroyContext();
59 [fMetalView removeFromSuperview];
63bool MetalWindowContext_ios::onInitializeContext() {
67 CGRect frameRect = [fViewController.view frame];
68 fMetalView = [[[
MetalView alloc] initWithFrame:frameRect] initWithWindow:fWindow];
69 [fViewController.view addSubview:fMetalView];
71 fMetalLayer = (CAMetalLayer*)fMetalView.layer;
72 fMetalLayer.device = fDevice.get();
73 fMetalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
74 fMetalLayer.drawableSize = frameRect.size;
75 fMetalLayer.frame = frameRect;
77 fMetalLayer.contentsGravity = kCAGravityTopLeft;
79 fWidth = frameRect.size.width;
80 fHeight = frameRect.size.height;
85void MetalWindowContext_ios::onDestroyContext() {}
87void MetalWindowContext_ios::resize(
int w,
int h) {
88 fMetalLayer.drawableSize = fMetalView.frame.size;
89 fMetalLayer.frame = fMetalView.frame;
100 std::unique_ptr<WindowContext> ctx(
new MetalWindowContext_ios(
info,
params));
101 if (!ctx->isValid()) {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
const EmbeddedViewParams * params
std::unique_ptr< WindowContext > MakeMetalForIOS(const IOSWindowInfo &info, const DisplayParams ¶ms)