servoshell: Use sRGB colorspace on macOS (#35683)

* servoshell: Use sRGB colorspace on macOS

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>

* Make lint happy

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>

* Address review

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>

* Move to helper function

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>

* Rebase Cargo.lock

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>

* Fix build

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>

* Fix build (again)

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>

---------

Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>
This commit is contained in:
Isaac Marovitz 2025-03-24 19:59:27 -04:00 committed by GitHub
parent 9ae1fe67a3
commit ed995e61a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 1 deletions

View file

@ -13,7 +13,7 @@ use std::time::Duration;
use euclid::{Angle, Length, Point2D, Rotation3D, Scale, Size2D, UnknownUnit, Vector2D, Vector3D};
use keyboard_types::{Modifiers, ShortcutMatcher};
use log::{debug, info};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawWindowHandle};
use servo::compositing::windowing::{
AnimationState, EmbedderCoordinates, WebRenderDebugOption, WindowMethods,
};
@ -37,6 +37,11 @@ use winit::event_loop::ActiveEventLoop;
use winit::keyboard::{Key as LogicalKey, ModifiersState, NamedKey};
#[cfg(any(target_os = "linux", target_os = "windows"))]
use winit::window::Icon;
#[cfg(target_os = "macos")]
use {
objc2_app_kit::{NSColorSpace, NSView},
objc2_foundation::MainThreadMarker,
};
use super::app_state::RunningAppState;
use super::geometry::{winit_position_to_euclid_point, winit_size_to_euclid_size};
@ -101,6 +106,8 @@ impl Window {
winit_window.set_window_icon(Some(load_icon(icon_bytes)));
}
Window::force_srgb_color_space(winit_window.window_handle().unwrap().as_raw());
let monitor = winit_window
.current_monitor()
.or_else(|| winit_window.available_monitors().nth(0))
@ -420,6 +427,22 @@ impl Window {
pub(crate) fn offscreen_rendering_context(&self) -> Rc<OffscreenRenderingContext> {
self.rendering_context.clone()
}
#[allow(unused_variables)]
fn force_srgb_color_space(window_handle: RawWindowHandle) {
#[cfg(target_os = "macos")]
{
if let RawWindowHandle::AppKit(handle) = window_handle {
assert!(MainThreadMarker::new().is_some());
unsafe {
let view = handle.ns_view.cast::<NSView>().as_ref();
view.window()
.unwrap()
.setColorSpace(Some(&NSColorSpace::sRGBColorSpace()));
}
}
}
}
}
impl WindowPortsMethods for Window {