1
0
Fork 0
forked from wry/wry

all: use trait upcasting

This commit is contained in:
Julian Orth 2025-04-03 16:47:24 +02:00
parent f0caafc862
commit 09e5f89174
44 changed files with 90 additions and 269 deletions

View file

@ -30,7 +30,7 @@ use {
},
},
bstr::ByteSlice,
std::{any::Any, cell::Cell, error::Error, io, os::unix::ffi::OsStrExt, pin::Pin, rc::Rc},
std::{cell::Cell, error::Error, io, os::unix::ffi::OsStrExt, pin::Pin, rc::Rc},
thiserror::Error,
uapi::c,
};
@ -287,10 +287,6 @@ impl Backend for TestBackend {
})
}
fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
self
}
fn switch_to(&self, vtnr: u32) {
let _ = vtnr;
}

View file

@ -278,14 +278,6 @@ impl GfxTexture for TestGfxImage {
}
}
fn as_any(&self) -> &dyn Any {
self
}
fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
self
}
fn dmabuf(&self) -> Option<&DmaBuf> {
match self {
TestGfxImage::Shm(_) => None,
@ -298,11 +290,7 @@ impl GfxTexture for TestGfxImage {
}
}
impl ShmGfxTexture for TestGfxImage {
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
self
}
}
impl ShmGfxTexture for TestGfxImage {}
impl AsyncShmGfxTexture for TestGfxImage {
fn async_upload(
@ -344,10 +332,6 @@ impl AsyncShmGfxTexture for TestGfxImage {
};
shm.format == format && shm.width == width && shm.height == height && shm.stride == stride
}
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
self
}
}
impl GfxImage for TestGfxImage {
@ -573,10 +557,6 @@ impl GfxFramebuffer for TestGfxFb {
}
impl GfxInternalFramebuffer for TestGfxFb {
fn into_fb(self: Rc<Self>) -> Rc<dyn GfxFramebuffer> {
self
}
fn stride(&self) -> i32 {
let TestGfxImage::Shm(shm) = &*self.img else {
unreachable!();
@ -604,7 +584,7 @@ impl GfxInternalFramebuffer for TestGfxFb {
impl dyn GfxTexture {
fn as_native(&self) -> &TestGfxImage {
self.as_any()
(self as &dyn Any)
.downcast_ref()
.expect("Non-test texture passed into vulkan")
}

View file

@ -1,6 +1,6 @@
use {
crate::{it::test_error::TestError, object::Object},
std::rc::Rc,
std::{any::Any, rc::Rc},
};
pub trait TestObjectExt {
@ -9,7 +9,7 @@ pub trait TestObjectExt {
impl TestObjectExt for dyn Object {
fn downcast<T: 'static>(self: Rc<Self>) -> Result<Rc<T>, TestError> {
match self.into_any().downcast() {
match (self as Rc<dyn Any>).downcast() {
Ok(t) => Ok(t),
_ => bail!("Object has an incompatible type id"),
}