Implement content-addressed resource storage for raster images (#4148)

* Implement content-addressed resource storage

* Implement OPFS resource storage

* Remove ResourceStorage::read

* Review
This commit is contained in:
Timon
2026-05-21 19:31:07 +00:00
committed by GitHub
parent 21d2994059
commit 2770df7567
50 changed files with 1535 additions and 355 deletions
+76 -6
View File
@@ -1,14 +1,84 @@
use dyn_any::StaticType;
#[cfg(feature = "wgpu")]
use wgpu_executor::WgpuExecutor;
#[cfg(not(target_family = "wasm"))]
mod native;
#[cfg(target_family = "wasm")]
mod wasm;
pub mod resource;
pub use graphene_application_io::{ApplicationIo, LoadResource, Resource, ResourceFuture, ResourceHash, ResourceStorage};
pub use resource::HashMapResourceStorage;
#[cfg(not(target_family = "wasm"))]
pub type PlatformApplicationIo = native::NativeApplicationIo;
pub use resource::mmap::MmapResourceStorage;
#[cfg(target_family = "wasm")]
pub type PlatformApplicationIo = wasm::WasmApplicationIo;
pub use resource::opfs::OpfsResourceStorage;
#[derive(Default)]
pub struct PlatformApplicationIo {
#[cfg(feature = "wgpu")]
pub(crate) gpu_executor: Option<WgpuExecutor>,
resources: Option<Box<dyn LoadResource>>,
}
impl PlatformApplicationIo {
pub async fn new() -> Self {
#[cfg(feature = "wgpu")]
let executor = WgpuExecutor::new().await;
#[cfg(not(feature = "wgpu"))]
let wgpu_available = false;
#[cfg(feature = "wgpu")]
let wgpu_available = executor.is_some();
set_wgpu_available(wgpu_available);
Self {
#[cfg(feature = "wgpu")]
gpu_executor: executor,
resources: None,
}
}
#[cfg(feature = "wgpu")]
pub fn new_with_context(context: wgpu_executor::WgpuContext) -> Self {
let executor = WgpuExecutor::with_context(context);
let wgpu_available = executor.is_some();
set_wgpu_available(wgpu_available);
Self {
gpu_executor: executor,
resources: None,
}
}
pub fn inject_resource_proxy(&mut self, resources: Box<dyn LoadResource>) {
self.resources = Some(resources);
}
}
impl ApplicationIo for PlatformApplicationIo {
#[cfg(feature = "wgpu")]
type Executor = WgpuExecutor;
#[cfg(not(feature = "wgpu"))]
type Executor = ();
#[cfg(feature = "wgpu")]
fn gpu_executor(&self) -> Option<&Self::Executor> {
self.gpu_executor.as_ref()
}
fn load_resource(&self, hash: ResourceHash) -> graphene_application_io::ResourceFuture {
self.resources.as_ref().expect("Resource storage not initialized").load(hash)
}
}
impl std::fmt::Debug for PlatformApplicationIo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PlatformApplicationIo").finish_non_exhaustive()
}
}
unsafe impl StaticType for PlatformApplicationIo {
type Static = PlatformApplicationIo;
}
pub type PlatformEditorApi = graphene_application_io::EditorApi<PlatformApplicationIo>;