Upgrade Blitz to 0.1.0-alpha.3 and add wgpu-texture example (#4286)

* Use Blitz 0.1.0-alpha.3

* Add wgpu-texture example

* Native: Support configuring wgpu Features and Limits
This commit is contained in:
Nico Burns authored and GitHub committed 2025-06-17 18:06:32 -07:00
1 parent 544d8cc4da
commit 6fcb496fd5
11 files changed
+796 -162

No files matched your search

+52 -9
View File
@@ -13,12 +13,16 @@ mod assets;
mod contexts;
mod dioxus_application;
mod dioxus_document;
mod dioxus_renderer;
mod events;
mod mutation_writer;
use blitz_dom::{ns, Atom, QualName};
pub use anyrender_vello::{CustomPaintCtx, CustomPaintSource, TextureHandle};
use assets::DioxusNativeNetProvider;
use blitz_dom::{ns, LocalName, Namespace, QualName};
pub use dioxus_application::{DioxusNativeApplication, DioxusNativeEvent};
pub use dioxus_document::DioxusDocument;
pub use dioxus_renderer::{use_wgpu, DioxusNativeWindowRenderer, Features, Limits};
use blitz_shell::{create_default_event_loop, BlitzShellEvent, Config, WindowConfig};
use dioxus_core::{ComponentFunction, Element, VirtualDom};
@@ -44,12 +48,36 @@ pub fn launch_cfg_with_props<P: Clone + 'static, M: 'static>(
app: impl ComponentFunction<P, M>,
props: P,
contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
_cfg: Vec<Box<dyn Any>>,
configs: Vec<Box<dyn Any>>,
) {
let _cfg = _cfg
.into_iter()
.find_map(|cfg| cfg.downcast::<Config>().ok())
.unwrap_or_default();
// Macro to attempt to downcast a type out of a Box<dyn Any>
macro_rules! try_read_config {
($input:ident, $store:ident, $kind:ty) => {
// Try to downcast the Box<dyn Any> to type $kind
match $input.downcast::<$kind>() {
// If the type matches then write downcast value to variable $store
Ok(value) => {
$store = Some(*value);
continue;
}
// Else extract the original Box<dyn Any> value out of the error type
// and return it so that we can try again with a different type.
Err(cfg) => cfg,
}
};
}
// Read config values
let mut features = None;
let mut limits = None;
let mut _config = None;
for mut cfg in configs {
cfg = try_read_config!(cfg, features, Features);
cfg = try_read_config!(cfg, limits, Limits);
cfg = try_read_config!(cfg, _config, Config);
let _ = cfg;
}
let event_loop = create_default_event_loop::<BlitzShellEvent>();
// Turn on the runtime and enter it
@@ -84,8 +112,23 @@ pub fn launch_cfg_with_props<P: Clone + 'static, M: 'static>(
vdom.insert_any_root_context(context());
}
#[cfg(feature = "net")]
let net_provider = {
let proxy = event_loop.create_proxy();
let net_provider = DioxusNativeNetProvider::shared(proxy);
Some(net_provider)
};
#[cfg(not(feature = "net"))]
let net_provider = None;
// Create document + window from the baked virtualdom
let doc = DioxusDocument::new(vdom, net_provider);
let renderer = DioxusNativeWindowRenderer::with_features_and_limits(features, limits);
let config = WindowConfig::new(Box::new(doc) as _, renderer.clone());
// Create application
let mut application = DioxusNativeApplication::new(event_loop.create_proxy(), vdom);
let mut application = DioxusNativeApplication::new(event_loop.create_proxy(), config);
// Run event loop
event_loop.run_app(&mut application).unwrap();
@@ -94,8 +137,8 @@ pub fn launch_cfg_with_props<P: Clone + 'static, M: 'static>(
pub(crate) fn qual_name(local_name: &str, namespace: Option<&str>) -> QualName {
QualName {
prefix: None,
ns: namespace.map(Atom::from).unwrap_or(ns!(html)),
local: Atom::from(local_name),
ns: namespace.map(Namespace::from).unwrap_or(ns!(html)),
local: LocalName::from(local_name),
}
}