Skip to content

Commit

Permalink
Auto merge of #29871 - wusyong:raw-handle, r=<try>
Browse files Browse the repository at this point in the history
Use raw handles to create surfman context instead

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because it only changes how winit port create surfman contexts.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

It's amazing to see many activities on Servo recently. I would like to look into building it as a library crate again.
But I think it's best I could start something small to prevent getting stuck.
I hope it can accept any kind of window libraries and frameworks, with something like winit as fallback.
There will be people using various tools like gtk, UI kit, glazier (window crate from druid community).
Exposing API to accept raw window and display handle should do the work.
And I think this can start with chaning internal use first.
However, `Connection::from_raw_display_handle` isn't included in version 0.6, so I have to patch it.
Could it release another version for this?
  • Loading branch information
bors-servo committed Jun 21, 2023
2 parents fa7107a + 5a10430 commit 1f929d5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Expand Up @@ -66,8 +66,8 @@ smallvec = "1.9"
sparkle = "0.1.25"
string_cache = "0.8"
string_cache_codegen = "0.5"
surfman = "0.6"
surfman-chains = "0.7"
surfman = "0.7"
surfman-chains = "0.8"
surfman-chains-api = "0.2"
thin-slice = "0.1.0"
time = "0.1.41"
Expand Down Expand Up @@ -103,6 +103,8 @@ mio = { git = "https://github.com/servo/mio.git", branch = "servo-mio-0.6.22" }
# fork that bumps crates since the original repo is archived.
immeta = { git = "https://github.com/fabricedesre/immeta.git" }

surfman = { git = "https://github.com/wusyong/surfman", branch = "fix-todo" }

# https://github.com/servo/servo/issues/27515#issuecomment-671474054
[patch."https://github.com/servo/webrender"]
webrender = { git = "https://github.com/jdm/webrender", branch = "crash-backtrace" }
Expand Down
3 changes: 2 additions & 1 deletion ports/winit/Cargo.toml
Expand Up @@ -55,9 +55,10 @@ lazy_static = { workspace = true }
libc = { workspace = true }
libservo = { path = "../../components/servo" }
log = { workspace = true }
raw-window-handle = "0.5"
servo-media = { git = "https://github.com/servo/media" }
shellwords = "1.0.0"
surfman = { workspace = true, features = ["sm-winit", "sm-x11"] }
surfman = { workspace = true, features = ["sm-x11", "sm-raw-window-handle"] }
tinyfiledialogs = "3.0"
webxr = { git = "https://github.com/servo/webxr", features = ["ipc", "glwindow", "headless"] }
winit = "0.28.3"
Expand Down
7 changes: 5 additions & 2 deletions ports/winit/headed_window.rs
Expand Up @@ -46,6 +46,7 @@ use surfman::SurfaceType;
use winapi;
use winit::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
use winit::event::ModifiersState;
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};

pub struct Window {
winit_window: winit::window::Window,
Expand Down Expand Up @@ -125,13 +126,15 @@ impl Window {
let inner_size = Size2D::new(width, height);

// Initialize surfman
let display_handle = winit_window.raw_display_handle();
let connection =
Connection::from_winit_window(&winit_window).expect("Failed to create connection");
Connection::from_raw_display_handle(display_handle).expect("Failed to create connection");
let adapter = connection
.create_adapter()
.expect("Failed to create adapter");
let window_handle = winit_window.raw_window_handle();
let native_widget = connection
.create_native_widget_from_winit_window(&winit_window)
.create_native_widget_from_rwh(window_handle)
.expect("Failed to create native widget");
let surface_type = SurfaceType::Widget { native_widget };
let webrender_surfman = WebrenderSurfman::create(&connection, &adapter, surface_type)
Expand Down

0 comments on commit 1f929d5

Please sign in to comment.