Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle surface loss. #557

Merged
merged 2 commits into from
Apr 2, 2019
Merged

Conversation

cdavis5e
Copy link
Collaborator

@cdavis5e cdavis5e commented Apr 1, 2019

Sometimes, the CAMetalLayer backing a view can be replaced--for
example, when the window is moved to another screen, or the style bits
on the window are changed. In that case, we must allow the client the
opportunity to recreate the surface and swapchain.

Layer-backed views always set themselves as the layer's delegate; we use
this fact to Key-Value Observe the view's layer property.

Other alternatives considered:

  • Registering for NSViewGlobalFrameDidChange notifications. Aside from
    only working on macOS, this doesn't actually catch every case where we
    want to report a lost surface. I'm not even sure it works at all for
    Metal.
  • Holding a reference to the view, and checking when its layer property
    has changed.
  • Holding a weak reference to the layer; that way, the reference will
    become nil when the layer is replaced. But this requires ARC.

Sometimes, the `CAMetalLayer` backing a view can be replaced--for
example, when the window is moved to another screen, or the style bits
on the window are changed. In that case, we must allow the client the
opportunity to recreate the surface and swapchain.

Layer-backed views always set themselves as the layer's delegate; we use
this fact to Key-Value Observe the view's `layer` property.

Other alternatives considered:

* Registering for `NSViewGlobalFrameDidChange` notifications. Aside from
  only working on macOS, this doesn't actually catch every case where we
  want to report a lost surface. I'm not even sure it works at all for
  Metal.
* Holding a reference to the view, and checking when its layer property
  has changed.
* Holding a weak reference to the layer; that way, the reference will
  become `nil` when the layer is replaced. But this requires ARC.
@cdavis5e cdavis5e requested a review from billhollings April 1, 2019 18:11
Copy link
Contributor

@billhollings billhollings left a comment

Choose a reason for hiding this comment

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

Nice! Looks great to me. Very creative and elegant solution!

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.

2 participants