<!--
{
  "documentType" : "article",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/getting-the-gpu-that-drives-a-views-display",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Getting the GPU that drives a view’s display"
}
-->

# Getting the GPU that drives a view’s display

Keep up to date with the optimal device for your display.

## Discussion

A user can have multiple external displays connected directly to a Mac or to an external GPU. Each view in your app shows on a single display, and a single GPU drives each display. The display in which your view appears and the GPU that drives the display can change dynamically; therefore, you need to prepare your app to handle these changes. Register for display change notifications, get the device that drives your view’s display, and decide if your app should use that device to present rendered graphics.

### Handle display change notifications

Register for the following notifications so the system can notify your app about specific display changes:

- <doc://com.apple.documentation/documentation/AppKit/NSWindow/didChangeScreenNotification>: The system posts this notification when any window, including the window containing your view, moves to a different display.
- <doc://com.apple.documentation/documentation/AppKit/NSApplication/didChangeScreenParametersNotification>: The system posts this notification when the Mac system’s display configuration changes; for example, when the user connects or disconnects an external display from the system. Another example is when the GPU driving the display changes, such as when system has automatic graphics switching enabled and switches between the discrete and integrated GPUs to drive the display.

When the system posts a display change notification, you can decide if you should get and use a new device.

```swift
@objc func handleDisplayChanges(notification: NSNotification) {
    // Handle display changes
}

func registerForDisplayChangeNotifications() {
    NotificationCenter.default.addObserver(self,
                                           selector: #selector(handleDisplayChanges(notification:)),
                                           name: NSNotification.Name(rawValue: "NSWindowDidChangeScreenNotification"),
                                           object: nil)
    
    NotificationCenter.default.addObserver(self,
                                           selector: #selector(handleDisplayChanges(notification:)),
                                           name: NSNotification.Name(rawValue: "NSApplicationDidChangeScreenParametersNotification"),
                                           object: nil)
}
```

To deregister from the previous notifications, call the <doc://com.apple.documentation/documentation/Foundation/NotificationCenter/removeObserver(_:name:object:)> method.

### Identify the device that drives your view’s display

Get the <doc://com.apple.documentation/documentation/CoreGraphics/CGDirectDisplayID> value for the display in which your view currently appears. Then call the <doc://com.apple.documentation/documentation/CoreGraphics/CGDirectDisplayCopyCurrentMetalDevice(_:)> function to get the device that drives that display.

```swift
guard let viewDisplayID = mtkView.window?.screen?.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? CGDirectDisplayID else { return }
let displayDevice = CGDirectDisplayCopyCurrentMetalDevice(viewDisplayID)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)