mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 00:11:11 +01:00
This adds #[derive(Debug)] to all public structs and enums possible. This also required adding it to some private types that they transitively depend on. However, the following types depend on types from external crates that do not implement Debug: * device::Device * hub::Hub * swap_chain::Surface * swap_chain::SwapChain To support these types, we would need to use either custom Debug impls or something like Derivative. This helps improve the situation in #76.
56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
use crate::{GlobalMessage, InstanceMessage};
|
|
|
|
use ipc_channel::ipc::IpcReceiver;
|
|
use wgn;
|
|
|
|
#[derive(Debug)]
|
|
pub struct Server {
|
|
channel: IpcReceiver<GlobalMessage>,
|
|
}
|
|
|
|
impl Server {
|
|
pub(crate) fn new(channel: IpcReceiver<GlobalMessage>) -> Self {
|
|
Server { channel }
|
|
}
|
|
}
|
|
|
|
enum ControlFlow {
|
|
Continue,
|
|
Terminate,
|
|
}
|
|
|
|
fn process(message: GlobalMessage) -> ControlFlow {
|
|
match message {
|
|
GlobalMessage::Instance(msg) => match msg {
|
|
InstanceMessage::Create(instance_id) => {
|
|
let instance = wgn::create_instance();
|
|
wgn::HUB.instances.register(instance_id, instance);
|
|
}
|
|
InstanceMessage::InstanceGetAdapter(instance_id, ref desc, id) => {
|
|
let adapter = wgn::instance_get_adapter(instance_id, desc);
|
|
wgn::HUB.adapters.register(id, adapter);
|
|
}
|
|
InstanceMessage::AdapterCreateDevice(adapter_id, ref desc, id) => {
|
|
let device = wgn::adapter_create_device(adapter_id, desc);
|
|
wgn::HUB.devices.register(id, device);
|
|
}
|
|
InstanceMessage::Destroy(instance_id) => {
|
|
wgn::HUB.instances.unregister(instance_id);
|
|
}
|
|
},
|
|
GlobalMessage::Terminate => return ControlFlow::Terminate,
|
|
}
|
|
|
|
ControlFlow::Continue
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn wgpu_server_process(server: &Server) {
|
|
while let Ok(message) = server.channel.try_recv() {
|
|
match process(message) {
|
|
ControlFlow::Continue => {}
|
|
ControlFlow::Terminate => break,
|
|
}
|
|
}
|
|
}
|