mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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:
parent
9ae1fe67a3
commit
ed995e61a6
3 changed files with 38 additions and 1 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -6930,6 +6930,8 @@ dependencies = [
|
|||
"net",
|
||||
"net_traits",
|
||||
"nix",
|
||||
"objc2-app-kit",
|
||||
"objc2-foundation",
|
||||
"ohos-ime",
|
||||
"ohos-ime-sys",
|
||||
"ohos-vsync",
|
||||
|
|
|
@ -131,3 +131,15 @@ sig = "1.0"
|
|||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
windows-sys = { workspace = true, features = ["Win32_Graphics_Gdi"] }
|
||||
libservo = { path = "../../components/servo", features = ["no-wgl"] }
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
objc2-app-kit = { version = "0.2.2", default-features = false, features = [
|
||||
"std",
|
||||
"NSColorSpace",
|
||||
"NSResponder",
|
||||
"NSView",
|
||||
"NSWindow",
|
||||
] }
|
||||
objc2-foundation = { version = "0.2.2", default-features = false, features = [
|
||||
"std",
|
||||
] }
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue