slint/examples/servo
burhankhanzada a3baa4f6c0
Some checks are pending
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
autofix.ci / ci (push) Blocked by required conditions
feat: Update OpenGL ES and GL versions
2025-12-10 21:25:37 +01:00
..
src feat: Update OpenGL ES and GL versions 2025-12-10 21:25:37 +01:00
ui fix: Url bar not updating when user input something but dosent hit enter or go button then navigation links from webview 2025-12-09 15:15:09 +01:00
.gitignore
build.rs refactor: use only GLES 2025-12-09 15:03:47 +01:00
Cargo.lock servo: Update lock file after separation of the slint software renderer into a crate of its own 2025-12-10 18:26:14 +01:00
Cargo.toml refactor: use vulkan implementation on android 2025-12-09 09:19:34 +01:00
README.md Remove license header from .md/.mdx files 2025-12-04 21:58:09 +01:00

Slint Servo Example

Disclaimer: Servo is still experimental and not ready for productions use.

Integrate Servo Web Engine as WebView Component for Slint to render websites using hardware rendring on MacOS, Linux and software rendring on android for now.

Preview

Prerequisites

Simple Usage

  • Copy webview from src and paste it in your project.
  • Add webview to your .slint file.
  • Initialize it in your app with below code.
pub mod webview;

use slint::ComponentHandle;

use crate::webview::WebView;

slint::include_modules!();

pub fn main() {
    let (device, queue) = setup_wgpu();

    let app = MyApp::new().unwrap();

    WebView::new(
        app.clone_strong(),
        "https://slint.dev".into(),
        device,
        queue,
    );

    app.run().unwrap();
}

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
            .unwrap()
    });

    let (device, queue) = spin_on::spin_on(async {
        adapter.request_device(&Default::default()).await.unwrap()
    });

    slint::BackendSelector::new()
        .require_wgpu_27(slint::wgpu_27::WGPUConfiguration::Manual {
            instance,
            adapter,
            device: device.clone(),
            queue: queue.clone()
        })
        .select()
        .unwrap();

    (device, queue)
}

For Android build

  • Update your code with android specific code from example to your project.

Prerequisites for Android

Install platofrm-tools

${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager --install "platforms;android-30"

Add rust target and install cargo apk

rustup target add aarch64-linux-android
cargo install cargo-apk

Setup Bindgen for Android

On Mac

export BINDGEN_EXTRA_CLANG_ARGS="--target=aarch64-linux-android30 --sysroot=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/sysroot"

On Linux

export BINDGEN_EXTRA_CLANG_ARGS="--target=aarch64-linux-android30 --sysroot=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/sysroot"

Run on android emulator or device

cargo apk run --target aarch64-linux-android --lib