Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
da16c24
fix: fix wgpu_texture to run on android emulator on mac with disable …
burhankhanzada Nov 26, 2025
8fb53c0
refactor: remove cfgs for android to enable hardware rendering
burhankhanzada Nov 27, 2025
eb32bed
refactor: Make GL binding generation unconditional for all targets an…
burhankhanzada Nov 27, 2025
ec07860
refactor: Update servo and its depncies and code for ne APi changes
burhankhanzada Nov 27, 2025
bf4cc19
wip: Fix crash on android
burhankhanzada Nov 30, 2025
457b65a
refactor: use hardware rendering wiht NativeWidget
burhankhanzada Dec 1, 2025
0e1f2f2
fix: Upside down texture
burhankhanzada Dec 1, 2025
e3474af
refactor: remove native widget
burhankhanzada Dec 1, 2025
881163b
refactor: bring back original linux implementation
burhankhanzada Dec 1, 2025
515a842
refactor: clean up
burhankhanzada Dec 1, 2025
b41b71d
refactor: clean up
burhankhanzada Dec 1, 2025
ebabf4f
refactor: run cpu fallback on emulator
burhankhanzada Dec 2, 2025
1f493c6
feat: Added vulkan module to consolidate vulkan related code
burhankhanzada Dec 2, 2025
01e4ec4
refactor: improve code and fix metal crash
burhankhanzada Dec 2, 2025
b83c59a
refactor: improve imports
burhankhanzada Dec 2, 2025
4ecda44
refactor: improve code
burhankhanzada Dec 2, 2025
8cd711c
fix: added insets
burhankhanzada Dec 2, 2025
db989ec
refactor: clean up surfman_context remove dead code
burhankhanzada Dec 2, 2025
d427263
refactor: improve code
burhankhanzada Dec 2, 2025
3f1577c
refactor: improve code
burhankhanzada Dec 3, 2025
d666278
refactor: Extract image flipping, and into shared utility functions.
burhankhanzada Dec 3, 2025
88b9812
refactor: move Vulkan image creation and OpenGL import logic into a n…
burhankhanzada Dec 3, 2025
d198c1b
refactor: improve imports
burhankhanzada Dec 4, 2025
75a6cf9
refactor: improve metal errors handling
burhankhanzada Dec 4, 2025
ef08457
docs: add docs
burhankhanzada Dec 4, 2025
a44d2ce
Revert "fix: fix wgpu_texture to run on android emulator on mac with …
burhankhanzada Dec 4, 2025
2ec55d8
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 4, 2025
34bcb4f
fix: remove local surfman and raw-handle
burhankhanzada Dec 4, 2025
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
986 changes: 553 additions & 433 deletions examples/servo/Cargo.lock

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions examples/servo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,26 @@ winit = "0.30.12"
spin_on = "0.1.1"
rustls = "0.23.34"
euclid = "0.22.11"
surfman = "0.10.0"
surfman = "0.11.0"
time-now = "0.1.2"
termcolor = "1.4.1"
thiserror = "2.0.17"
foreign-types-shared = "0.3.1"

wgpu-hal = "27.0.2"
wgpu-core = "27.0.1"
wgpu-hal = "27.0.4"
wgpu-core = "27.0.3"
wgpu = { version = "27.0.1", features = ["metal"] }

libservo = { git = "https://github.com/servo/servo", rev = "158bf97e" }
embedder_traits = { git = "https://github.com/servo/servo", rev = "158bf97e", features = ["baked-default-resources"] }
libservo = { git = "https://github.com/servo/servo", rev = "39d3fc6c" }
embedder_traits = { git = "https://github.com/servo/servo", rev = "39d3fc6c", features = ["baked-default-resources"] }
# not used in code but added for no need to set specific rev whenever run cargo update or freash install and without this its not building
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't very clear to me

Copy link
Member Author

@burhankhanzada burhankhanzada Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah its not related to vulkan or hardware rendering any way its just whenever i update servo revision to new version and run cargo update it update its internal dependencies to new version which conflict sometimes and making build to failed that why i added it here so all servo dependencies use this specific version.

servo-media = { git = "https://github.com/servo/media", rev = "6c1766f5" }

[target.'cfg(target_os = "linux")'.dependencies]
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
ash = "0.38.0"

[target.'cfg(target_os = "android")'.dependencies]
slint = { path = "../../api/rs/slint", features = ["backend-android-activity-06"] }
slint = { path = "../../api/rs/slint", features = ["backend-android-activity-06", "unstable-wgpu-27"] }

[target.'cfg(not(target_os = "android"))'.dependencies]
slint = { path = "../../api/rs/slint", features = ["unstable-winit-030", "unstable-wgpu-27"] }
Expand All @@ -64,10 +66,9 @@ objc2-foundation = "0.3.2"
objc2-metal = { version = "0.3.2", features = ["MTLDevice", "MTLAllocation", "MTLResource", "MTLTexture", "objc2-io-surface"] }

[build-dependencies]
slint-build = { path = "../../api/rs/build" }

[target.'cfg(target_os = "linux")'.build-dependencies]
# need to add to for all host to generate gl_bindings for android
gl_generator = "0.14.0"
slint-build = { path = "../../api/rs/build" }

[[package.metadata.android.uses_permission]]
name = "android.permission.INTERNET"
19 changes: 9 additions & 10 deletions examples/servo/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ use std::fs::File;
use std::io::Write;
use std::path::Path;

#[cfg(target_os = "linux")]
use gl_generator::{Api, Fallbacks, Profile, Registry, StructGenerator};

#[cfg(target_os = "linux")]
extern crate gl_generator;

fn main() {
Expand All @@ -18,16 +16,21 @@ fn main() {
let out = env::var("OUT_DIR").unwrap();
let out = Path::new(&out);

#[cfg(target_os = "linux")]
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();

{
let mut file = File::create(&out.join("gl_bindings.rs")).unwrap();

// Config copied from https://github.com/YaLTeR/bxt-rs/blob/9f621251b8ce5c2af00b67d2feab731e48d1dae9/build.rs.

let api = if target_os == "android" { Api::Gles2 } else { Api::Gl };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this code, the decision is "sort of" made at run-time by comparing strings. However, this can be done at compile-time, using either #[cfg(target_os = "android"] or using if cfg!(target_os = "android").

Given that either branch is compilable, I think this should be written like this:

let api = if cfg!(target_os = "android") { ... } else { ... };

That said, I wonder if we can get away with just OpenGL ES 3.0 everywhere. On Android and Linux Embedded that'll be preferred. On Windows I thought servo is using angle, so that's also OpenGL ES.

@expenses I'm unsure, but is there perhaps a reason to use "Desktop GL" over GLES here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with the different OpenGL versions. I believe that if we're only using the GLES feature set and nothing exclusive to Desktop GL then using GLES everywhere is fine.

let version = if target_os == "android" { (3, 0) } else { (4, 6) };
let profile = if target_os == "android" { Profile::Core } else { Profile::Compatibility };

Registry::new(
Api::Gl,
(4, 6),
Profile::Compatibility,
api,
version,
profile,
Fallbacks::All,
[
"GL_EXT_memory_object",
Expand All @@ -42,10 +45,6 @@ fn main() {
.unwrap();
}

// Note: We can't use `#[cfg(windows)]`, since that would check the host platform
// and not the target platform
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();

// On MacOS, all dylib dependencies are shipped along with the binary
// in the "/lib" directory. Setting the rpath here, allows the dynamic
// linker to locate them. See `man dyld` for more info.
Expand Down
23 changes: 4 additions & 19 deletions examples/servo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pub mod webview;

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "android"))]
mod gl_bindings {
#![allow(unsafe_op_in_unsafe_fn)]

Expand All @@ -12,26 +12,16 @@ mod gl_bindings {

use slint::ComponentHandle;

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

slint::include_modules!();

pub fn main() {
#[cfg(not(target_os = "android"))]
let (device, queue) = setup_wgpu();

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

#[cfg(not(target_os = "android"))]
WebView::new(
app.clone_strong(),
"https://slint.dev".into(),
#[cfg(not(target_os = "android"))]
device,
#[cfg(not(target_os = "android"))]
queue,
);
WebView::new(app.clone_strong(), "https://slint.dev".into(), device, queue);

app.run().expect("Application failed to run - check for runtime errors");
}
Expand All @@ -43,16 +33,11 @@ pub fn android_main(android_app: slint::android::AndroidApp) {
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 instance =
wgpu::Instance::new(&wgpu::InstanceDescriptor { backends, ..Default::default() });

let adapter = spin_on::spin_on(async {
instance
Expand Down
13 changes: 3 additions & 10 deletions examples/servo/src/webview/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use smol::channel::{Receiver, Sender};

use slint::ComponentHandle;

#[cfg(not(target_os = "android"))]
use slint::wgpu_27::wgpu;

use crate::{MyApp, WebviewLogic, webview::rendering_context::ServoRenderingAdapter};
use crate::{MyApp, WebviewLogic, webview::ServoRenderingAdapter};

/// Upgrades a weak reference to `SlintServoAdapter` to a strong reference.
///
Expand Down Expand Up @@ -61,18 +60,16 @@ pub struct SlintServoAdapterInner {
servo: Option<Servo>,
webview: Option<WebView>,
rendering_adapter: Option<Rc<Box<dyn ServoRenderingAdapter>>>,
#[cfg(not(target_os = "android"))]
device: wgpu::Device,
#[cfg(not(target_os = "android"))]
queue: wgpu::Queue,
}

impl SlintServoAdapter {
pub fn new(
waker_sender: Sender<()>,
waker_receiver: Receiver<()>,
#[cfg(not(target_os = "android"))] device: wgpu::Device,
#[cfg(not(target_os = "android"))] queue: wgpu::Queue,
device: wgpu::Device,
queue: wgpu::Queue,
) -> Self {
Self {
waker_sender,
Expand All @@ -81,9 +78,7 @@ impl SlintServoAdapter {
servo: None,
webview: None,
rendering_adapter: None,
#[cfg(not(target_os = "android"))]
device: device,
#[cfg(not(target_os = "android"))]
queue: queue,
}),
}
Expand All @@ -105,12 +100,10 @@ impl SlintServoAdapter {
self.waker_receiver.clone()
}

#[cfg(not(target_os = "android"))]
pub fn wgpu_device(&self) -> wgpu::Device {
self.inner().device.clone()
}

#[cfg(not(target_os = "android"))]
pub fn wgpu_queue(&self) -> wgpu::Queue {
self.inner().queue.clone()
}
Expand Down
Loading
Loading