From 3f09ecc6bfaeaaab5cb10fcf965bb5a6963669c4 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Sat, 27 Jan 2024 00:29:10 +0100 Subject: [PATCH] Remove the winit feature (#271) Now that we can use raw_window_handle, drop the winit feature. This should make the dependency graph a little bit less complicated for crates that depend on surfman. A few changes: - The Wayland implementation needs the size when creating a native widget from a raw window handle, so add that parameters Unfortunately, it doesn't look like there is another option here. - Rename create_native_widget_from_rwh to create_native_widget_from_raw_window_handle. There already exists API that uses the `raw_window_handle` terminology. - Try to fix the build of the android-example, which depended on the old winit and now depends on the new one. This is a breaking API change, so the next release should be a major version bump. --- .github/workflows/rust.yml | 2 +- android-example/rust/Cargo.toml | 16 ++---- android-example/rust/src/lib.rs | 21 ++++--- surfman/Cargo.toml | 5 +- surfman/examples/chaos_game.rs | 5 +- surfman/examples/threads.rs | 10 +++- surfman/src/connection.rs | 19 +------ surfman/src/error.rs | 2 - surfman/src/implementation/connection.rs | 23 +------- surfman/src/platform/android/connection.rs | 32 +---------- .../src/platform/generic/multi/connection.rs | 56 +++---------------- surfman/src/platform/macos/cgl/connection.rs | 24 +------- .../src/platform/macos/system/connection.rs | 35 +----------- .../src/platform/unix/generic/connection.rs | 25 +-------- .../src/platform/unix/wayland/connection.rs | 51 +---------------- surfman/src/platform/unix/x11/connection.rs | 32 +---------- .../src/platform/windows/angle/connection.rs | 44 +-------------- .../src/platform/windows/wgl/connection.rs | 33 +---------- 18 files changed, 60 insertions(+), 375 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index adad4458..8d7137ef 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,7 +19,7 @@ jobs: matrix: os: [macos-latest, ubuntu-22.04, windows-latest] rust: [stable] - features: ["", "--features 'chains sm-winit sm-raw-window-handle'"] + features: ["", "--features 'chains sm-raw-window-handle'"] target: ["default"] include: # rust stable diff --git a/android-example/rust/Cargo.toml b/android-example/rust/Cargo.toml index 337d2df0..531b78c8 100644 --- a/android-example/rust/Cargo.toml +++ b/android-example/rust/Cargo.toml @@ -15,16 +15,10 @@ panic = "abort" panic = "abort" [dependencies] -android_logger = "0.8" +android_logger = "0.13" +euclid = { version = "0.22" } gl = "0.14" -jni = "0.13" +jni = "0.21" log = "0.4" -winit = { version = "0.28.1", features = [ "android-native-activity" ] } - -[dependencies.euclid] -version = "0.22" -features = [] - -[dependencies.surfman] -path = "../../surfman" -features = ["sm-test"] +surfman = { path = "../../surfman", features = [ "sm-test" ] } +winit = { version = "0.29.10", features = [ "android-native-activity", "rwh_05" ] } diff --git a/android-example/rust/src/lib.rs b/android-example/rust/src/lib.rs index d7a4390f..e6ac95bc 100644 --- a/android-example/rust/src/lib.rs +++ b/android-example/rust/src/lib.rs @@ -8,7 +8,7 @@ use crate::threads::App; use android_logger::Config; use euclid::default::Size2D; -use jni::objects::{GlobalRef, JByteBuffer, JClass, JObject, JValue}; +use jni::objects::{GlobalRef, JByteBuffer, JClass, JObject, JValue, JValueGen}; use jni::{JNIEnv, JavaVM}; use log::Level; use std::cell::{Cell, RefCell}; @@ -35,7 +35,7 @@ pub unsafe extern "system" fn Java_org_mozilla_surfmanthreadsexample_SurfmanThre ) { ATTACHED_TO_JNI.with(|attached_to_jni| attached_to_jni.set(true)); - android_logger::init_once(Config::default().with_min_level(Level::Trace)); + android_logger::init_once(Config::default()); let window_size = Size2D::new(width, height); @@ -166,20 +166,25 @@ impl ResourceLoader for JavaResourceLoader { }); let loader = self.loader.as_obj(); - let env = self.vm.get_env().unwrap(); + let mut env = self.vm.get_env().unwrap(); match env .call_method( loader, "slurp", "(Ljava/lang/String;)Ljava/nio/ByteBuffer;", - &[JValue::Object(*env.new_string(filename).unwrap())], + &[JValue::Object(&env.new_string(filename).unwrap())], ) - .unwrap() { - JValue::Object(object) => { + Ok(JValueGen::Object(object)) => { let byte_buffer = JByteBuffer::from(object); - dest.extend_from_slice(env.get_direct_buffer_address(byte_buffer).unwrap()); - } + unsafe { + let slice = std::slice::from_raw_parts( + env.get_direct_buffer_address(&byte_buffer).unwrap(), + env.get_direct_buffer_capacity(&byte_buffer).unwrap(), + ); + dest.extend_from_slice(slice); + } + }, _ => panic!("Unexpected return value!"), } } diff --git a/surfman/Cargo.toml b/surfman/Cargo.toml index f6f2b16f..fb0f58e8 100644 --- a/surfman/Cargo.toml +++ b/surfman/Cargo.toml @@ -18,14 +18,13 @@ cfg_aliases = "0.1.0" [features] chains = ["fnv", "sparkle"] -default = ["sm-winit", "sm-raw-window-handle"] +default = ["sm-raw-window-handle"] sm-angle = [] sm-angle-builtin = ["mozangle"] sm-angle-default = ["sm-angle"] sm-no-wgl = ["sm-angle-default"] sm-test = [] sm-wayland-default = [] -sm-winit = ["winit"] sm-x11 = ["x11"] sm-raw-window-handle = ["raw-window-handle"] @@ -38,7 +37,6 @@ libc = "0.2" log = "0.4" sparkle = { version = "0.1", optional = true } osmesa-sys = { version = "0.1", optional = true } -winit = { version = "0.28.1", optional = true } raw-window-handle = { version = "0.5", optional = true } [dev-dependencies] @@ -79,4 +77,3 @@ winapi = { version = "0.3", features = ["d3d11", "libloaderapi", "winbase", "win [target.'cfg(target_os = "android")'.dependencies] raw-window-handle = "0.5" -winit = { version = "0.28.1", features = [ "android-native-activity" ] } diff --git a/surfman/examples/chaos_game.rs b/surfman/examples/chaos_game.rs index 226eaaa3..96788cce 100644 --- a/surfman/examples/chaos_game.rs +++ b/surfman/examples/chaos_game.rs @@ -49,8 +49,11 @@ fn main() { window.set_visible(true); + let window_size = window.inner_size(); + let window_size = Size2D::new(window_size.width as i32, window_size.height as i32); + let handle = window.window_handle().unwrap(); let native_widget = connection - .create_native_widget_from_winit_window(&window) + .create_native_widget_from_raw_window_handle(handle.as_raw(), window_size); .unwrap(); let surface_type = SurfaceType::Widget { native_widget }; diff --git a/surfman/examples/threads.rs b/surfman/examples/threads.rs index 60f32e60..7482f937 100644 --- a/surfman/examples/threads.rs +++ b/surfman/examples/threads.rs @@ -23,6 +23,7 @@ use winit::{ event_loop::{ControlFlow, EventLoop}, window::WindowBuilder }; +use winit::raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; pub mod common; @@ -99,9 +100,14 @@ fn main() { window.set_visible(true); - let connection = Connection::from_winit_window(&window).unwrap(); + let raw_display_handle = window.raw_display_handle(); + let connection = Connection::from_raw_display_handle(raw_display_handle).unwrap(); + + let window_size = window.inner_size(); + let window_size = Size2D::new(window_size.width as i32, window_size.height as i32); + let raw_window_handle = window.raw_window_handle(); let native_widget = connection - .create_native_widget_from_winit_window(&window) + .create_native_widget_from_raw_window_handle(raw_window_handle, window_size) .unwrap(); let adapter = connection.create_low_power_adapter().unwrap(); let mut device = connection.create_device(&adapter).unwrap(); diff --git a/surfman/src/connection.rs b/surfman/src/connection.rs index d762422c..d9bdfc23 100644 --- a/surfman/src/connection.rs +++ b/surfman/src/connection.rs @@ -9,9 +9,6 @@ use euclid::default::Size2D; use std::os::raw::c_void; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - /// Methods relating to display server connections. pub trait Connection: Sized { /// The adapter type associated with this connection. @@ -57,25 +54,12 @@ pub trait Connection: Sized { native_device: Self::NativeDevice, ) -> Result; - /// Opens the display connection corresponding to the given `winit` window. - #[cfg(feature = "sm-winit")] - fn from_winit_window(window: &Window) -> Result; - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] fn from_raw_display_handle( raw_handle: raw_window_handle::RawDisplayHandle, ) -> Result; - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[cfg(feature = "sm-winit")] - fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result; - /// Creates a native widget from a raw pointer unsafe fn create_native_widget_from_ptr( &self, @@ -85,8 +69,9 @@ pub trait Connection: Sized { /// Create a native widget type from the given `raw_window_handle::RawWindowHandle`. #[cfg(feature = "sm-raw-window-handle")] - fn create_native_widget_from_rwh( + fn create_native_widget_from_raw_window_handle( &self, window: raw_window_handle::RawWindowHandle, + size: Size2D, ) -> Result; } diff --git a/surfman/src/error.rs b/surfman/src/error.rs index 5057d5eb..16cc5908 100644 --- a/surfman/src/error.rs +++ b/surfman/src/error.rs @@ -88,8 +88,6 @@ pub enum Error { IncompatibleAdapter, /// The native widget type does not match the supplied device. IncompatibleNativeWidget, - /// The `winit` window is incompatible with this backend. - IncompatibleWinitWindow, /// The `raw display handle` is incompatible with this backend. IncompatibleRawDisplayHandle, /// The native context does not match the supplied device. diff --git a/surfman/src/implementation/connection.rs b/surfman/src/implementation/connection.rs index 2fdb6a81..f0d380ce 100644 --- a/surfman/src/implementation/connection.rs +++ b/surfman/src/implementation/connection.rs @@ -14,9 +14,6 @@ use euclid::default::Size2D; use std::os::raw::c_void; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - #[deny(unconditional_recursion)] impl ConnectionInterface for Connection { type Adapter = Adapter; @@ -73,12 +70,6 @@ impl ConnectionInterface for Connection { Connection::create_device_from_native_device(self, native_device) } - #[inline] - #[cfg(feature = "sm-winit")] - fn from_winit_window(window: &Window) -> Result { - Connection::from_winit_window(window) - } - #[inline] #[cfg(feature = "sm-raw-window-handle")] fn from_raw_display_handle( @@ -87,15 +78,6 @@ impl ConnectionInterface for Connection { Connection::from_raw_display_handle(raw_handle) } - #[inline] - #[cfg(feature = "sm-winit")] - fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result { - Connection::create_native_widget_from_winit_window(self, window) - } - #[inline] unsafe fn create_native_widget_from_ptr( &self, @@ -107,10 +89,11 @@ impl ConnectionInterface for Connection { #[inline] #[cfg(feature = "sm-raw-window-handle")] - fn create_native_widget_from_rwh( + fn create_native_widget_from_raw_window_handle( &self, window: raw_window_handle::RawWindowHandle, + size: Size2D, ) -> Result { - Connection::create_native_widget_from_rwh(self, window) + Connection::create_native_widget_from_raw_window_handle(self, window, size) } } diff --git a/surfman/src/platform/android/connection.rs b/surfman/src/platform/android/connection.rs index fe275116..70acbd4c 100644 --- a/surfman/src/platform/android/connection.rs +++ b/surfman/src/platform/android/connection.rs @@ -14,9 +14,6 @@ use euclid::default::Size2D; use std::os::raw::c_void; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - /// A connection to the display server. #[derive(Clone)] pub struct Connection; @@ -100,13 +97,6 @@ impl Connection { }) } - /// Opens the display connection corresponding to the given `winit` window. - #[cfg(feature = "sm-winit")] - #[inline] - pub fn from_winit_window(_: &Window) -> Result { - Ok(Connection) - } - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] pub fn from_raw_display_handle( @@ -115,25 +105,6 @@ impl Connection { Ok(Connection) } - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[cfg(feature = "sm-winit")] - #[inline] - pub fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result { - use raw_window_handle::HasRawWindowHandle; - use raw_window_handle::RawWindowHandle::AndroidNdk; - match window.raw_window_handle() { - AndroidNdk(handle) => Ok(NativeWidget { - native_window: handle.a_native_window as *mut _, - }), - _ => Err(Error::IncompatibleNativeWidget), - } - } - /// Create a native widget from a raw pointer pub unsafe fn create_native_widget_from_ptr( &self, @@ -148,9 +119,10 @@ impl Connection { /// Create a native widget type from the given `raw_window_handle::RawWindowHandle`. #[cfg(feature = "sm-raw-window-handle")] #[inline] - pub fn create_native_widget_from_rwh( + pub fn create_native_widget_from_raw_window_handle( &self, raw_handle: raw_window_handle::RawWindowHandle, + _size: Size2D, ) -> Result { use raw_window_handle::RawWindowHandle::AndroidNdk; diff --git a/surfman/src/platform/generic/multi/connection.rs b/surfman/src/platform/generic/multi/connection.rs index 3d227e2d..bc756cb4 100644 --- a/surfman/src/platform/generic/multi/connection.rs +++ b/surfman/src/platform/generic/multi/connection.rs @@ -13,9 +13,6 @@ use euclid::default::Size2D; use std::os::raw::c_void; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - /// A connection to the display server. pub enum Connection where @@ -182,15 +179,6 @@ where } } - /// Opens the connection corresponding to the given `winit` window. - #[cfg(feature = "sm-winit")] - pub fn from_winit_window(window: &Window) -> Result, Error> { - match ::from_winit_window(window) { - Ok(connection) => Ok(Connection::Default(connection)), - Err(_) => ::from_winit_window(window).map(Connection::Alternate), - } - } - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] pub fn from_raw_display_handle( @@ -204,24 +192,6 @@ where } } - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[cfg(feature = "sm-winit")] - pub fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result, Error> { - match *self { - Connection::Default(ref connection) => connection - .create_native_widget_from_winit_window(window) - .map(NativeWidget::Default), - Connection::Alternate(ref connection) => connection - .create_native_widget_from_winit_window(window) - .map(NativeWidget::Alternate), - } - } - /// Create a native widget from a raw pointer pub unsafe fn create_native_widget_from_ptr( &self, @@ -240,16 +210,17 @@ where /// Create a native widget type from the given `raw_window_handle::HasRawWindowHandle`. #[cfg(feature = "sm-raw-window-handle")] - pub fn create_native_widget_from_rwh( + pub fn create_native_widget_from_raw_window_handle( &self, raw_handle: raw_window_handle::RawWindowHandle, + size: Size2D, ) -> Result, Error> { match *self { Connection::Default(ref connection) => connection - .create_native_widget_from_rwh(raw_handle) + .create_native_widget_from_raw_window_handle(raw_handle, size) .map(NativeWidget::Default), Connection::Alternate(ref connection) => connection - .create_native_widget_from_rwh(raw_handle) + .create_native_widget_from_raw_window_handle(raw_handle, size) .map(NativeWidget::Alternate), } } @@ -316,12 +287,6 @@ where Connection::create_device_from_native_device(self, native_device) } - #[inline] - #[cfg(feature = "sm-winit")] - fn from_winit_window(window: &Window) -> Result, Error> { - Connection::from_winit_window(window) - } - #[cfg(feature = "sm-raw-window-handle")] fn from_raw_display_handle( raw_handle: raw_window_handle::RawDisplayHandle, @@ -329,14 +294,6 @@ where Connection::from_raw_display_handle(raw_handle) } - #[cfg(feature = "sm-winit")] - fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result { - Connection::create_native_widget_from_winit_window(self, window) - } - #[inline] unsafe fn create_native_widget_from_ptr( &self, @@ -347,10 +304,11 @@ where } #[cfg(feature = "sm-raw-window-handle")] - fn create_native_widget_from_rwh( + fn create_native_widget_from_raw_window_handle( &self, raw_handle: raw_window_handle::RawWindowHandle, + size: Size2D, ) -> Result { - Connection::create_native_widget_from_rwh(self, raw_handle) + Connection::create_native_widget_from_raw_window_handle(self, raw_handle, size) } } diff --git a/surfman/src/platform/macos/cgl/connection.rs b/surfman/src/platform/macos/cgl/connection.rs index 420bce49..2e2e600b 100644 --- a/surfman/src/platform/macos/cgl/connection.rs +++ b/surfman/src/platform/macos/cgl/connection.rs @@ -21,9 +21,6 @@ use crate::platform::macos::system::surface::NSView; #[cfg(feature = "sm-raw-window-handle")] use cocoa::base::id; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - pub use crate::platform::macos::system::connection::NativeConnection; /// A connection to the display server. @@ -102,12 +99,6 @@ impl Connection { .map(Device) } - /// Opens the display connection corresponding to the given `winit` window. - #[cfg(feature = "sm-winit")] - pub fn from_winit_window(window: &Window) -> Result { - SystemConnection::from_winit_window(window).map(Connection) - } - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] pub fn from_raw_display_handle( @@ -116,18 +107,6 @@ impl Connection { SystemConnection::from_raw_display_handle(raw_handle).map(Connection) } - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[cfg(feature = "sm-winit")] - #[inline] - pub fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result { - self.0.create_native_widget_from_winit_window(window) - } - /// Creates a native widget from a raw pointer pub unsafe fn create_native_widget_from_ptr( &self, @@ -140,9 +119,10 @@ impl Connection { /// Create a native widget type from the given `raw_window_handle::RawWindowHandle`. #[cfg(feature = "sm-raw-window-handle")] #[inline] - pub fn create_native_widget_from_rwh( + pub fn create_native_widget_from_raw_window_handle( &self, raw_handle: raw_window_handle::RawWindowHandle, + _size: Size2D, ) -> Result { use raw_window_handle::RawWindowHandle::AppKit; diff --git a/surfman/src/platform/macos/system/connection.rs b/surfman/src/platform/macos/system/connection.rs index 8e7c305f..00b2bcb2 100644 --- a/surfman/src/platform/macos/system/connection.rs +++ b/surfman/src/platform/macos/system/connection.rs @@ -22,11 +22,6 @@ use euclid::default::Size2D; use std::os::raw::c_void; use std::str::FromStr; -#[cfg(feature = "sm-winit")] -use winit::platform::macos::WindowExtMacOS; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - /// A no-op connection. /// /// Connections to the CGS window server are implicit on macOS, so this is a zero-sized type. @@ -123,12 +118,6 @@ impl Connection { self.create_device(&self.create_adapter()?) } - /// Opens the display connection corresponding to the given `winit` window. - #[cfg(feature = "sm-winit")] - pub fn from_winit_window(_: &Window) -> Result { - Connection::new() - } - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] pub fn from_raw_display_handle( @@ -137,27 +126,6 @@ impl Connection { Connection::new() } - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[cfg(feature = "sm-winit")] - pub fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result { - let ns_view = window.ns_view() as id; - let ns_window = window.ns_window() as id; - if ns_view.is_null() { - return Err(Error::IncompatibleNativeWidget); - } - unsafe { - Ok(NativeWidget { - view: NSView(msg_send![ns_view, retain]), - opaque: msg_send![ns_window as id, isOpaque], - }) - } - } - /// Create a native widget from a raw pointer pub unsafe fn create_native_widget_from_ptr( &self, @@ -173,9 +141,10 @@ impl Connection { /// Create a native widget type from the given `raw_window_handle::RawWindowHandle`. #[cfg(feature = "sm-raw-window-handle")] #[inline] - pub fn create_native_widget_from_rwh( + pub fn create_native_widget_from_raw_window_handle( &self, raw_handle: raw_window_handle::RawWindowHandle, + _size: Size2D, ) -> Result { use raw_window_handle::RawWindowHandle::AppKit; diff --git a/surfman/src/platform/unix/generic/connection.rs b/surfman/src/platform/unix/generic/connection.rs index 84e16521..4f822ae9 100644 --- a/surfman/src/platform/unix/generic/connection.rs +++ b/surfman/src/platform/unix/generic/connection.rs @@ -16,9 +16,6 @@ use euclid::default::Size2D; use std::os::raw::c_void; use std::sync::Arc; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - /// A no-op connection. #[derive(Clone)] pub struct Connection { @@ -137,13 +134,6 @@ impl Connection { Device::new(self, &self.create_adapter()?) } - /// Opens the display connection corresponding to the given `winit` window. - #[inline] - #[cfg(feature = "sm-winit")] - pub fn from_winit_window(_: &Window) -> Result { - Err(Error::IncompatibleNativeWidget) - } - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] pub fn from_raw_display_handle( @@ -152,18 +142,6 @@ impl Connection { Err(Error::IncompatibleNativeWidget) } - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[inline] - #[cfg(feature = "sm-winit")] - pub fn create_native_widget_from_winit_window( - &self, - _: &Window, - ) -> Result { - Err(Error::IncompatibleNativeWidget) - } - /// Create a native widget from a raw pointer pub unsafe fn create_native_widget_from_ptr( &self, @@ -176,9 +154,10 @@ impl Connection { /// Create a native widget type from the given `raw_window_handle::RawWindowHandle`. #[cfg(feature = "sm-raw-window-handle")] #[inline] - pub fn create_native_widget_from_rwh( + pub fn create_native_widget_from_raw_window_handle( &self, _: raw_window_handle::RawWindowHandle, + _size: Size2D, ) -> Result { Err(Error::IncompatibleNativeWidget) } diff --git a/surfman/src/platform/unix/wayland/connection.rs b/surfman/src/platform/unix/wayland/connection.rs index 2a272c34..5fdcbbf8 100644 --- a/surfman/src/platform/unix/wayland/connection.rs +++ b/surfman/src/platform/unix/wayland/connection.rs @@ -17,11 +17,6 @@ use std::ptr; use std::sync::Arc; use wayland_sys::client::{wl_display, wl_proxy, WAYLAND_CLIENT_HANDLE}; -#[cfg(feature = "sm-winit")] -use winit::platform::wayland::WindowExtWayland; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - /// A connection to the Wayland server. #[derive(Clone)] pub struct Connection { @@ -161,18 +156,6 @@ impl Connection { }) } - /// Opens the display connection corresponding to the given `winit` window. - #[cfg(feature = "sm-winit")] - pub fn from_winit_window(window: &Window) -> Result { - unsafe { - let wayland_display = match window.wayland_display() { - Some(wayland_display) => wayland_display as *mut wl_display, - None => return Err(Error::IncompatibleWinitWindow), - }; - Connection::from_wayland_display(wayland_display, false) - } - } - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] pub fn from_raw_display_handle( @@ -190,34 +173,6 @@ impl Connection { } } - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[cfg(feature = "sm-winit")] - pub fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result { - let wayland_surface = match window.wayland_surface() { - Some(wayland_surface) => wayland_surface as *mut wl_proxy, - None => return Err(Error::IncompatibleNativeWidget), - }; - - // The window's DPI factor is 1.0 when nothing has been rendered to it yet. So use the DPI - // factor of the primary monitor instead, since that's where the window will presumably go - // when actually displayed. (The user might move it somewhere else later, of course.) - // - // FIXME(pcwalton): Is it true that the window will go the primary monitor first? - // let hidpi_factor = window.primary_monitor().scale_factor(); - let window_size = window.inner_size(); - let window_size = Size2D::new(window_size.width as i32, window_size.height as i32); - - Ok(NativeWidget { - wayland_surface, - size: window_size, - }) - } - /// Create a native widget from a raw pointer pub unsafe fn create_native_widget_from_ptr( &self, @@ -232,9 +187,10 @@ impl Connection { /// Creates a native widget type from the given `raw_window_handle::HasRawWindowHandle` #[cfg(feature = "sm-raw-window-handle")] - pub fn create_native_widget_from_rwh( + pub fn create_native_widget_from_raw_window_handle( &self, raw_handle: raw_window_handle::RawWindowHandle, + window_size: Size2D, ) -> Result { use raw_window_handle::RawWindowHandle::Wayland; @@ -243,9 +199,6 @@ impl Connection { _ => return Err(Error::IncompatibleNativeWidget), }; - // TODO: Find out how to get actual size from the raw window handle - let window_size = Size2D::new(400, 500); - Ok(NativeWidget { wayland_surface, size: window_size, diff --git a/surfman/src/platform/unix/x11/connection.rs b/surfman/src/platform/unix/x11/connection.rs index 0c4069bb..09e2b8af 100644 --- a/surfman/src/platform/unix/x11/connection.rs +++ b/surfman/src/platform/unix/x11/connection.rs @@ -20,11 +20,6 @@ use std::ptr; use std::sync::Arc; use x11::xlib::{Display, XCloseDisplay, XInitThreads, XLockDisplay, XOpenDisplay, XUnlockDisplay}; -#[cfg(feature = "sm-winit")] -use winit::platform::x11::WindowExtX11; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - lazy_static! { static ref X_THREADS_INIT: () = { unsafe { @@ -192,16 +187,6 @@ impl Connection { Device::new(self, &native_device.adapter) } - /// Opens the display connection corresponding to the given `winit` window. - #[cfg(feature = "sm-winit")] - pub fn from_winit_window(window: &Window) -> Result { - if let Some(display) = window.xlib_display() { - Connection::from_x11_display(display as *mut Display, false) - } else { - Err(Error::IncompatibleWinitWindow) - } - } - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] pub fn from_raw_display_handle( @@ -219,20 +204,6 @@ impl Connection { Connection::from_x11_display(display, false) } - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[cfg(feature = "sm-winit")] - pub fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result { - match window.xlib_window() { - Some(window) => Ok(NativeWidget { window }), - None => Err(Error::IncompatibleNativeWidget), - } - } - /// Create a native widget from a raw pointer pub unsafe fn create_native_widget_from_ptr( &self, @@ -246,9 +217,10 @@ impl Connection { /// Create a native widget type from the given `raw_window_handle::HasRawWindowHandle`. #[cfg(feature = "sm-raw-window-handle")] - pub fn create_native_widget_from_rwh( + pub fn create_native_widget_from_raw_window_handle( &self, raw_handle: raw_window_handle::RawWindowHandle, + _size: Size2D, ) -> Result { use raw_window_handle::RawWindowHandle::Xlib; diff --git a/surfman/src/platform/windows/angle/connection.rs b/surfman/src/platform/windows/angle/connection.rs index d7d01e42..4dcc820c 100644 --- a/surfman/src/platform/windows/angle/connection.rs +++ b/surfman/src/platform/windows/angle/connection.rs @@ -20,11 +20,6 @@ use std::os::raw::c_void; use winapi::shared::minwindef::UINT; use winapi::um::d3dcommon::{D3D_DRIVER_TYPE_UNKNOWN, D3D_DRIVER_TYPE_WARP}; -#[cfg(all(feature = "sm-winit", not(target_vendor = "uwp")))] -use winit::platform::windows::WindowExtWindows; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - const INTEL_PCI_ID: UINT = 0x8086; /// A no-op connection. @@ -133,12 +128,6 @@ impl Connection { Device::from_egl_display(egl_display) } - /// Opens the display connection corresponding to the given `winit` window. - #[cfg(feature = "sm-winit")] - pub fn from_winit_window(_: &Window) -> Result { - Connection::new() - } - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] pub fn from_raw_display_handle( @@ -147,36 +136,6 @@ impl Connection { Connection::new() } - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[cfg(all(feature = "sm-winit", not(target_vendor = "uwp")))] - #[inline] - pub fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result { - let hwnd = window.hwnd() as EGLNativeWindowType; - if hwnd.is_null() { - Err(Error::IncompatibleNativeWidget) - } else { - Ok(NativeWidget { - egl_native_window: hwnd, - }) - } - } - - /// Creates a native widget type from the given `winit` window. - /// This is unsupported on UWP. - #[cfg(all(feature = "sm-winit", target_vendor = "uwp"))] - #[inline] - pub fn create_native_widget_from_winit_window( - &self, - _window: &Window, - ) -> Result { - Err(Error::IncompatibleNativeWidget) - } - /// Create a native widget from a raw pointer pub unsafe fn create_native_widget_from_ptr( &self, @@ -191,9 +150,10 @@ impl Connection { /// Create a native widget type from the given `raw_window_handle::RawWindowHandle`. #[cfg(feature = "sm-raw-window-handle")] #[inline] - pub fn create_native_widget_from_rwh( + pub fn create_native_widget_from_raw_window_handle( &self, handle: raw_window_handle::RawWindowHandle, + _size: Size2D, ) -> Result { if let raw_window_handle::RawWindowHandle::Win32(handle) = handle { Ok(NativeWidget { diff --git a/surfman/src/platform/windows/wgl/connection.rs b/surfman/src/platform/windows/wgl/connection.rs index 2ddb0b67..cfed2de2 100644 --- a/surfman/src/platform/windows/wgl/connection.rs +++ b/surfman/src/platform/windows/wgl/connection.rs @@ -15,11 +15,6 @@ use std::os::raw::c_void; use winapi::shared::windef::HWND; -#[cfg(feature = "sm-winit")] -use winit::platform::windows::WindowExtWindows; -#[cfg(feature = "sm-winit")] -use winit::window::Window; - /// Represents a connection to the display server. /// /// Window server connections are implicit in the Win32 API, so this is a zero-sized type. @@ -104,12 +99,6 @@ impl Connection { Device::from_native_device(native_device) } - /// Opens the display connection corresponding to the given `winit` window. - #[cfg(feature = "sm-winit")] - pub fn from_winit_window(_: &Window) -> Result { - Connection::new() - } - /// Opens the display connection corresponding to the given raw display handle. #[cfg(feature = "sm-raw-window-handle")] pub fn from_raw_display_handle( @@ -118,25 +107,6 @@ impl Connection { Connection::new() } - /// Creates a native widget type from the given `winit` window. - /// - /// This type can be later used to create surfaces that render to the window. - #[cfg(feature = "sm-winit")] - #[inline] - pub fn create_native_widget_from_winit_window( - &self, - window: &Window, - ) -> Result { - let hwnd = window.hwnd() as HWND; - if hwnd.is_null() { - Err(Error::IncompatibleNativeWidget) - } else { - Ok(NativeWidget { - window_handle: hwnd, - }) - } - } - /// Create a native widget from a raw pointer pub unsafe fn create_native_widget_from_ptr( &self, @@ -150,9 +120,10 @@ impl Connection { /// Create a native widget type from the given `raw_window_handle::HasRawWindowHandle`. #[cfg(feature = "sm-raw-window-handle")] - pub fn create_native_widget_from_rwh( + pub fn create_native_widget_from_raw_window_handle( &self, raw_handle: raw_window_handle::RawWindowHandle, + _size: Size2D, ) -> Result { use raw_window_handle::RawWindowHandle::Win32;