Skip to content

Commit e01af64

Browse files
servo: Prepare for usage docs (#10121)
* refactor: Consolidate Servo initialization and event handling into a new `webview` module. * [autofix.ci] apply automated fixes * refactor: Move webview-related modules into the `webview` directory and update all internal import paths. * refactor: move servo field to inner struct and add direct accessor * docs: Add docs for webview module * docs: Change webview module to public and improve example in docs * [autofix.ci] apply automated fixes * docs: Improve example in docs --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 24fb38c commit e01af64

File tree

19 files changed

+718
-477
lines changed

19 files changed

+718
-477
lines changed

examples/servo/src/delegate.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

examples/servo/src/lib.rs

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
// Copyright © SixtyFPS GmbH <[email protected]>
22
// SPDX-License-Identifier: MIT
33

4-
mod adapter;
5-
mod delegate;
6-
mod on_events;
7-
mod rendering_context;
8-
mod servo_util;
9-
mod waker;
4+
pub mod webview;
105

116
#[cfg(target_os = "linux")]
127
mod gl_bindings {
@@ -17,54 +12,21 @@ mod gl_bindings {
1712

1813
use slint::ComponentHandle;
1914

20-
use crate::servo_util::init_servo;
15+
#[cfg(not(target_os = "android"))]
16+
use crate::webview::WebView;
2117

2218
slint::include_modules!();
2319

2420
pub fn main() {
2521
#[cfg(not(target_os = "android"))]
26-
let (device, queue) = {
27-
let backends = wgpu::Backends::from_env().unwrap_or_default();
28-
29-
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
30-
backends,
31-
flags: Default::default(),
32-
backend_options: Default::default(),
33-
memory_budget_thresholds: Default::default(),
34-
});
35-
36-
let adapter = spin_on::spin_on(async {
37-
instance
38-
.request_adapter(&Default::default())
39-
.await
40-
.expect("Failed to find an appropriate WGPU adapter")
41-
});
42-
43-
let (device, queue) = spin_on::spin_on(async {
44-
adapter.request_device(&Default::default()).await.expect("Failed to create WGPU device")
45-
});
46-
47-
slint::BackendSelector::new()
48-
.require_wgpu_27(slint::wgpu_27::WGPUConfiguration::Manual {
49-
instance,
50-
adapter,
51-
device: device.clone(),
52-
queue: queue.clone()
53-
})
54-
.select()
55-
.expect("Failed to create Slint backend with WGPU based renderer - ensure your system supports WGPU");
56-
57-
(device, queue)
58-
};
22+
let (device, queue) = setup_wgpu();
5923

6024
let app = MyApp::new().expect("Failed to create Slint application - check UI resources");
6125

62-
let url = "https://slint.dev";
63-
6426
#[cfg(not(target_os = "android"))]
65-
let _adapter = init_servo(
27+
WebView::new(
6628
app.clone_strong(),
67-
url.into(),
29+
"https://slint.dev".into(),
6830
#[cfg(not(target_os = "android"))]
6931
device,
7032
#[cfg(not(target_os = "android"))]
@@ -80,3 +42,38 @@ pub fn android_main(android_app: slint::android::AndroidApp) {
8042
slint::android::init(android_app).unwrap();
8143
main();
8244
}
45+
46+
#[cfg(not(target_os = "android"))]
47+
fn setup_wgpu() -> (wgpu::Device, wgpu::Queue) {
48+
let backends = wgpu::Backends::from_env().unwrap_or_default();
49+
50+
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
51+
backends,
52+
flags: Default::default(),
53+
backend_options: Default::default(),
54+
memory_budget_thresholds: Default::default(),
55+
});
56+
57+
let adapter = spin_on::spin_on(async {
58+
instance
59+
.request_adapter(&Default::default())
60+
.await
61+
.expect("Failed to find an appropriate WGPU adapter")
62+
});
63+
64+
let (device, queue) = spin_on::spin_on(async {
65+
adapter.request_device(&Default::default()).await.expect("Failed to create WGPU device")
66+
});
67+
68+
slint::BackendSelector::new()
69+
.require_wgpu_27(slint::wgpu_27::WGPUConfiguration::Manual {
70+
instance,
71+
adapter,
72+
device: device.clone(),
73+
queue: queue.clone()
74+
})
75+
.select()
76+
.expect("Failed to create Slint backend with WGPU based renderer - ensure your system supports WGPU");
77+
78+
(device, queue)
79+
}

examples/servo/src/on_events.rs

Lines changed: 0 additions & 194 deletions
This file was deleted.

0 commit comments

Comments
 (0)