diff --git a/CHANGELOG.md b/CHANGELOG.md index 55e675ec97..4f5b5a45e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fixed EGL's `Display::new()` making an `EGLDisplay::Khr` when the EGL version for the display is 1.4 or lower. - Added `Device::drm_device_node_path()` and `Device::drm_render_device_node_path()` getters to EGL via `EGL_EXT_device_drm`. - Added support for `DrmDisplayHandle` in EGL's `Display::with_device()` using `EGL_DRM_MASTER_FD_EXT` from `EGL_EXT_device_drm`. +- Properly set up OpenGL-specific stuff on the `NSView`, instead of relying on Winit to do it. # Version 0.32.0 diff --git a/glutin/Cargo.toml b/glutin/Cargo.toml index ecc94998cb..4566af5fa7 100644 --- a/glutin/Cargo.toml +++ b/glutin/Cargo.toml @@ -66,10 +66,12 @@ features = [ [target.'cfg(any(target_os = "macos"))'.dependencies.objc2-app-kit] version = "0.2.0" features = [ + "NSApplication", "NSResponder", "NSView", "NSWindow", "NSOpenGL", + "NSOpenGLView", ] [build-dependencies] diff --git a/glutin/src/api/cgl/surface.rs b/glutin/src/api/cgl/surface.rs index 26044ea77c..65b87b4243 100644 --- a/glutin/src/api/cgl/surface.rs +++ b/glutin/src/api/cgl/surface.rs @@ -5,7 +5,7 @@ use std::marker::PhantomData; use std::num::NonZeroU32; use objc2::rc::Id; -use objc2_app_kit::NSView; +use objc2_app_kit::{NSAppKitVersionNumber, NSAppKitVersionNumber10_12, NSView}; use objc2_foundation::{run_on_main, MainThreadBound, MainThreadMarker}; use raw_window_handle::RawWindowHandle; @@ -60,12 +60,29 @@ impl Display { // SAFETY: Validity of the view and window is ensured by caller // This function makes sure the window is non null. let ns_view = if let Some(ns_view) = - unsafe { Id::retain(native_window.ns_view.as_ptr().cast()) } + unsafe { Id::retain(native_window.ns_view.as_ptr().cast::()) } { ns_view } else { return Err(ErrorKind::NotSupported("ns_view of provided native window is nil").into()); }; + + // The default value of `wantsBestResolutionOpenGLSurface` is `false` when + // linked with the macOS 10.14 SDK and `true` if linked with a macOS 10.15 SDK + // or newer. We always set it to `true` because we want High DPI surfaces, and + // we want to avoid this confusing default system value. + #[allow(deprecated)] + ns_view.setWantsBestResolutionOpenGLSurface(true); + + // On Mojave, views apparently automatically become layer-backed shortly after + // being added to a window. Changing the layer-backedness of a view breaks the + // association between the view and its associated OpenGL context. To work + // around this, we explicitly make the view layer-backed up front so that AppKit + // doesn't do it itself and break the association with its context. + if unsafe { NSAppKitVersionNumber }.floor() > NSAppKitVersionNumber10_12 { + ns_view.setWantsLayer(true); + } + let ns_view = MainThreadBound::new(ns_view, mtm); let surface = Surface {