[mtl] fix CAMetalLayer creation and resize on iOS#2937
Conversation
| // create one as a sublayer. However, when the view changes size, | ||
| // its sublayers are not automatically resized, and we must resize | ||
| // it here. The drawable size and the layer size don't correlate | ||
| let view = surface.inner.view.unwrap().as_ptr(); |
There was a problem hiding this comment.
It didn't seem to have any ill effect on macOS, so it probably doesn't matter. We could make it iOS only. On a separate note, it occurred to me that view may be None if the surface is created with create_surface_from_layer instead of create_surface_from_uiview. I'll address these now.
2937: [mtl] fix `CAMetalLayer` creation and resize on iOS r=kvark a=aleksijuvani Fixes #issue PR checklist: - [x] `make` succeeds (on *nix) - [x] `make reftests` succeeds - [x] tested examples with the following backends: mtl - [ ] `rustfmt` run on changed code r? @mtak- Co-authored-by: Aleksi Juvani <[email protected]>
| msg_send![new_layer, setBounds: bounds]; | ||
|
|
||
| let frame: CGRect = msg_send![view, frame]; | ||
| msg_send![new_layer, setFrame: frame]; |
There was a problem hiding this comment.
I believe this is more correct as [new_layer setFrame: [main_layer bounds]]. Frames are always in the parents coordinate space, and bounds are in view/layer's own coordinate space.
There was a problem hiding this comment.
Maybe [CALayer setAutoresizingMask: kCALayerWidthSizable | kCALayerHeightSizable] is an alternate solution to resizing in build swapchain? I haven't tested it, but the docs look good.
There was a problem hiding this comment.
Ahh autoresizingMask is macos only.
There was a problem hiding this comment.
I've now addressed this here for iOS. We should handle #2938 for macOS in a separate PR.
| #[cfg(target_os = "ios")] { | ||
| if let Some(view) = surface.inner.view { | ||
| let frame: CGRect = msg_send![view.as_ptr(), frame]; | ||
| msg_send![render_layer, setFrame: frame]; |
There was a problem hiding this comment.
Similar situation here, but it only matters in corner cases.
|
Thanks! |
|
bors r- |
Canceled |
|
Thank you for the review, @mtak-! I can address these here. It's getting late so it might take me until tomorrow to finish doing so. |
|
bors r+ |
2937: [mtl] fix `CAMetalLayer` creation and resize on iOS r=kvark a=aleksijuvani Fixes #issue PR checklist: - [x] `make` succeeds (on *nix) - [x] `make reftests` succeeds - [x] tested examples with the following backends: mtl - [ ] `rustfmt` run on changed code r? @mtak- Co-authored-by: Aleksi Juvani <[email protected]>
Build succeeded |
Fixes #issue
PR checklist:
makesucceeds (on *nix)make reftestssucceedsrustfmtrun on changed coder? @mtak-