Skip to content

[mtl] fix CAMetalLayer creation and resize on iOS#2937

Merged
bors[bot] merged 1 commit intomasterfrom
unknown repository
Aug 3, 2019
Merged

[mtl] fix CAMetalLayer creation and resize on iOS#2937
bors[bot] merged 1 commit intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Aug 2, 2019

Fixes #issue
PR checklist:

  • make succeeds (on *nix)
  • make reftests succeeds
  • tested examples with the following backends: mtl
  • rustfmt run on changed code

r? @mtak-

Comment thread src/backend/metal/src/window.rs Outdated
// 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();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be ios-only?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!
bors r+

bors bot added a commit that referenced this pull request Aug 2, 2019
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]>
Comment thread src/backend/metal/src/lib.rs Outdated
msg_send![new_layer, setBounds: bounds];

let frame: CGRect = msg_send![view, frame];
msg_send![new_layer, setFrame: frame];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe [CALayer setAutoresizingMask: kCALayerWidthSizable | kCALayerHeightSizable] is an alternate solution to resizing in build swapchain? I haven't tested it, but the docs look good.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh autoresizingMask is macos only.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 moved to #2938

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now addressed this here for iOS. We should handle #2938 for macOS in a separate PR.

Comment thread src/backend/metal/src/window.rs Outdated
#[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];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar situation here, but it only matters in corner cases.

@mtak-
Copy link
Copy Markdown
Contributor

mtak- commented Aug 2, 2019

Thanks!

@kvark
Copy link
Copy Markdown
Member

kvark commented Aug 2, 2019

bors r-
@mtak- wow, thank you for jumping on the review!
@aleksijuvani do you want to address these here? or as a follow-up?

@bors
Copy link
Copy Markdown
Contributor

bors bot commented Aug 2, 2019

Canceled

@ghost
Copy link
Copy Markdown
Author

ghost commented Aug 2, 2019

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.

@kvark kvark mentioned this pull request Aug 2, 2019
@kvark
Copy link
Copy Markdown
Member

kvark commented Aug 3, 2019

bors r+

bors bot added a commit that referenced this pull request Aug 3, 2019
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]>
@bors
Copy link
Copy Markdown
Contributor

bors bot commented Aug 3, 2019

Build succeeded

@bors bors bot merged commit 526b320 into gfx-rs:master Aug 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants