Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions examples/servo/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

use std::rc::Rc;

use servo::{WebView, WebViewDelegate};

use crate::{MyApp, adapter::SlintServoAdapter};
use servo::{WebView, WebViewDelegate};

pub struct AppDelegate {
pub state: Rc<SlintServoAdapter>,
pub app: slint::Weak<MyApp>,
pub adapter: Rc<SlintServoAdapter>,
}

impl AppDelegate {
pub fn new(state: Rc<SlintServoAdapter>, app: slint::Weak<MyApp>) -> Self {
Self { state, app }
pub fn new(app: slint::Weak<MyApp>, adapter: Rc<SlintServoAdapter>) -> Self {
Self { app, adapter }
}
}

Expand All @@ -24,7 +23,7 @@ impl WebViewDelegate for AppDelegate {
fn notify_new_frame_ready(&self, webview: WebView) {
webview.paint();
if let Some(app) = self.app.upgrade() {
self.state.update_web_content_with_latest_frame(&app);
self.adapter.update_web_content_with_latest_frame(&app);
}
}
}
81 changes: 41 additions & 40 deletions examples/servo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

mod adapter;
mod delegate;
mod on_events;
mod rendering_context;
mod servo_util;
mod waker;
mod webview;

#[cfg(target_os = "linux")]
mod gl_bindings {
Expand All @@ -17,54 +16,21 @@ mod gl_bindings {

use slint::ComponentHandle;

use crate::servo_util::init_servo;
#[cfg(not(target_os = "android"))]
use crate::webview::WebView;

slint::include_modules!();

pub fn main() {
#[cfg(not(target_os = "android"))]
let (device, queue) = {
let backends = wgpu::Backends::from_env().unwrap_or_default();

let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends,
flags: Default::default(),
backend_options: Default::default(),
memory_budget_thresholds: Default::default(),
});

let adapter = spin_on::spin_on(async {
instance
.request_adapter(&Default::default())
.await
.expect("Failed to find an appropriate WGPU adapter")
});

let (device, queue) = spin_on::spin_on(async {
adapter.request_device(&Default::default()).await.expect("Failed to create WGPU device")
});

slint::BackendSelector::new()
.require_wgpu_27(slint::wgpu_27::WGPUConfiguration::Manual {
instance,
adapter,
device: device.clone(),
queue: queue.clone()
})
.select()
.expect("Failed to create Slint backend with WGPU based renderer - ensure your system supports WGPU");

(device, queue)
};
let (device, queue) = setup_wgpu();

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

let url = "https://slint.dev";

#[cfg(not(target_os = "android"))]
let _adapter = init_servo(
WebView::new(
app.clone_strong(),
url.into(),
"https://slint.dev".into(),
#[cfg(not(target_os = "android"))]
device,
#[cfg(not(target_os = "android"))]
Expand All @@ -80,3 +46,38 @@ pub fn android_main(android_app: slint::android::AndroidApp) {
slint::android::init(android_app).unwrap();
main();
}

#[cfg(not(target_os = "android"))]
fn setup_wgpu() -> (wgpu::Device, wgpu::Queue) {
let backends = wgpu::Backends::from_env().unwrap_or_default();

let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
backends,
flags: Default::default(),
backend_options: Default::default(),
memory_budget_thresholds: Default::default(),
});

let adapter = spin_on::spin_on(async {
instance
.request_adapter(&Default::default())
.await
.expect("Failed to find an appropriate WGPU adapter")
});

let (device, queue) = spin_on::spin_on(async {
adapter.request_device(&Default::default()).await.expect("Failed to create WGPU device")
});

slint::BackendSelector::new()
.require_wgpu_27(slint::wgpu_27::WGPUConfiguration::Manual {
instance,
adapter,
device: device.clone(),
queue: queue.clone()
})
.select()
.expect("Failed to create Slint backend with WGPU based renderer - ensure your system supports WGPU");

(device, queue)
}
194 changes: 0 additions & 194 deletions examples/servo/src/on_events.rs

This file was deleted.

11 changes: 4 additions & 7 deletions examples/servo/src/rendering_context/servo_rendering_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
use std::rc::Rc;

use euclid::Point2D;
use winit::dpi::PhysicalSize;

use slint::{Image, SharedPixelBuffer};
use winit::dpi::PhysicalSize;

use servo::{RenderingContext, SoftwareRenderingContext, webrender_api::units::DeviceIntRect};

#[cfg(not(target_os = "android"))]
use crate::rendering_context::GPURenderingContext;
use {crate::rendering_context::GPURenderingContext, slint::wgpu_27::wgpu};

pub fn create_software_context(size: PhysicalSize<u32>) -> Box<dyn ServoRenderingAdapter> {
let rendering_context = Rc::new(
Expand Down Expand Up @@ -74,10 +73,8 @@ impl ServoRenderingAdapter for ServoGPURenderingContext {
);

#[cfg(target_vendor = "apple")]
let texture = self
.rendering_context
.get_wgpu_texture_from_metal(&self.device, &self.queue)
.expect(
let texture =
self.rendering_context.get_wgpu_texture_from_metal(&self.device, &self.queue).expect(
"Failed to get WGPU texture from Metal texture - ensure rendering context is valid",
);

Expand Down
Loading
Loading