mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
[rs] Drop for surfaces and adapters
This commit is contained in:
parent
dff98ac2a8
commit
edbe112d23
@ -26,14 +26,14 @@ vulkan-portability = ["wgc/gfx-backend-vulkan", "gfx-backend-vulkan"]
|
|||||||
package = "wgpu-core"
|
package = "wgpu-core"
|
||||||
#version = "0.6"
|
#version = "0.6"
|
||||||
git = "https://github.com/gfx-rs/wgpu"
|
git = "https://github.com/gfx-rs/wgpu"
|
||||||
rev = "789b09c7bde774f09b0cec87d6ea1b5700a6de2f"
|
rev = "af9713b249cc158276aeb643900f095e7699167a"
|
||||||
features = ["raw-window-handle"]
|
features = ["raw-window-handle"]
|
||||||
|
|
||||||
[dependencies.wgt]
|
[dependencies.wgt]
|
||||||
package = "wgpu-types"
|
package = "wgpu-types"
|
||||||
#version = "0.6"
|
#version = "0.6"
|
||||||
git = "https://github.com/gfx-rs/wgpu"
|
git = "https://github.com/gfx-rs/wgpu"
|
||||||
rev = "789b09c7bde774f09b0cec87d6ea1b5700a6de2f"
|
rev = "af9713b249cc158276aeb643900f095e7699167a"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
arrayvec = "0.5"
|
arrayvec = "0.5"
|
||||||
|
|||||||
@ -33,7 +33,7 @@ impl Context {
|
|||||||
|
|
||||||
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
||||||
pub unsafe fn create_surface_from_core_animation_layer(
|
pub unsafe fn create_surface_from_core_animation_layer(
|
||||||
&self,
|
self: &Arc<Self>,
|
||||||
layer: *mut std::ffi::c_void,
|
layer: *mut std::ffi::c_void,
|
||||||
) -> crate::Surface {
|
) -> crate::Surface {
|
||||||
let surface = wgc::instance::Surface {
|
let surface = wgc::instance::Surface {
|
||||||
@ -52,7 +52,16 @@ impl Context {
|
|||||||
self.0
|
self.0
|
||||||
.surfaces
|
.surfaces
|
||||||
.register(id, surface, &mut wgc::hub::Token::root());
|
.register(id, surface, &mut wgc::hub::Token::root());
|
||||||
crate::Surface { id }
|
crate::Surface {
|
||||||
|
context: Arc::clone(self),
|
||||||
|
id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for Context {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
//nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1207,6 +1216,15 @@ impl crate::Context for Context {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn surface_drop(&self, surface: &Self::SurfaceId) {
|
||||||
|
self.0.surface_drop(*surface)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn adapter_drop(&self, adapter: &Self::AdapterId) {
|
||||||
|
let global = &self.0;
|
||||||
|
wgc::gfx_select!(*adapter => global.adapter_drop(*adapter))
|
||||||
|
}
|
||||||
|
|
||||||
fn buffer_destroy(&self, buffer: &Self::BufferId) {
|
fn buffer_destroy(&self, buffer: &Self::BufferId) {
|
||||||
let global = &self.0;
|
let global = &self.0;
|
||||||
wgc::gfx_select!(buffer.id => global.buffer_destroy(buffer.id)).unwrap_pretty()
|
wgc::gfx_select!(buffer.id => global.buffer_destroy(buffer.id)).unwrap_pretty()
|
||||||
|
|||||||
@ -1261,6 +1261,14 @@ impl crate::Context for Context {
|
|||||||
Sendable(texture.0.create_view_with_descriptor(&mapped))
|
Sendable(texture.0.create_view_with_descriptor(&mapped))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn surface_drop(&self, _surface: &Self::SurfaceId) {
|
||||||
|
// Dropped automatically
|
||||||
|
}
|
||||||
|
|
||||||
|
fn adapter_drop(&self, _adapter: &Self::AdapterId) {
|
||||||
|
// Dropped automatically
|
||||||
|
}
|
||||||
|
|
||||||
fn buffer_destroy(&self, _buffer: &Self::BufferId) {
|
fn buffer_destroy(&self, _buffer: &Self::BufferId) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|||||||
@ -302,6 +302,8 @@ trait Context: Debug + Send + Sized + Sync {
|
|||||||
desc: &TextureViewDescriptor,
|
desc: &TextureViewDescriptor,
|
||||||
) -> Self::TextureViewId;
|
) -> Self::TextureViewId;
|
||||||
|
|
||||||
|
fn surface_drop(&self, surface: &Self::SurfaceId);
|
||||||
|
fn adapter_drop(&self, adapter: &Self::AdapterId);
|
||||||
fn buffer_destroy(&self, buffer: &Self::BufferId);
|
fn buffer_destroy(&self, buffer: &Self::BufferId);
|
||||||
fn buffer_drop(&self, buffer: &Self::BufferId);
|
fn buffer_drop(&self, buffer: &Self::BufferId);
|
||||||
fn texture_destroy(&self, buffer: &Self::TextureId);
|
fn texture_destroy(&self, buffer: &Self::TextureId);
|
||||||
@ -434,6 +436,14 @@ pub struct Adapter {
|
|||||||
id: <C as Context>::AdapterId,
|
id: <C as Context>::AdapterId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for Adapter {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if !thread::panicking() {
|
||||||
|
self.context.adapter_drop(&self.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Open connection to a graphics and/or compute device.
|
/// Open connection to a graphics and/or compute device.
|
||||||
///
|
///
|
||||||
/// Responsible for the creation of most rendering and compute resources.
|
/// Responsible for the creation of most rendering and compute resources.
|
||||||
@ -586,9 +596,18 @@ impl Drop for Sampler {
|
|||||||
/// be presented. A `Surface` may be created with the unsafe function [`Instance::create_surface`].
|
/// be presented. A `Surface` may be created with the unsafe function [`Instance::create_surface`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Surface {
|
pub struct Surface {
|
||||||
|
context: Arc<C>,
|
||||||
id: <C as Context>::SurfaceId,
|
id: <C as Context>::SurfaceId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Drop for Surface {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if !thread::panicking() {
|
||||||
|
self.context.surface_drop(&self.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle to a swap chain.
|
/// Handle to a swap chain.
|
||||||
///
|
///
|
||||||
/// A `SwapChain` represents the image or series of images that will be presented to a [`Surface`].
|
/// A `SwapChain` represents the image or series of images that will be presented to a [`Surface`].
|
||||||
@ -1335,6 +1354,7 @@ impl Instance {
|
|||||||
window: &W,
|
window: &W,
|
||||||
) -> Surface {
|
) -> Surface {
|
||||||
Surface {
|
Surface {
|
||||||
|
context: Arc::clone(&self.context),
|
||||||
id: Context::instance_create_surface(&*self.context, window),
|
id: Context::instance_create_surface(&*self.context, window),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user