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

@ -95,7 +95,7 @@ use {
},
isnt::std_1::vec::IsntVecExt,
once_cell::sync::Lazy,
std::{cell::RefCell, error::Error, rc::Rc, sync::Arc},
std::{any::Any, cell::RefCell, error::Error, rc::Rc, sync::Arc},
thiserror::Error,
};
@ -439,7 +439,7 @@ fn handle_explicit_sync(ctx: &GlRenderContext, img: Option<&Rc<EglImage>>, sync:
impl dyn GfxTexture {
fn as_gl(&self) -> &Texture {
self.as_any()
(self as &dyn Any)
.downcast_ref()
.expect("Non-gl texture passed into gl")
}

View file

@ -127,10 +127,6 @@ impl GfxFramebuffer for Framebuffer {
}
impl GfxInternalFramebuffer for Framebuffer {
fn into_fb(self: Rc<Self>) -> Rc<dyn GfxFramebuffer> {
self
}
fn stride(&self) -> i32 {
self.gl.rb.stride
}

View file

@ -18,7 +18,6 @@ use {
video::dmabuf::DmaBuf,
},
std::{
any::Any,
cell::Cell,
fmt::{Debug, Formatter},
rc::Rc,
@ -52,14 +51,6 @@ impl GfxTexture for Texture {
(self.width(), self.height())
}
fn as_any(&self) -> &dyn Any {
self
}
fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
self
}
fn dmabuf(&self) -> Option<&DmaBuf> {
self.gl.img.as_ref().map(|i| &i.dmabuf)
}
@ -69,11 +60,7 @@ impl GfxTexture for Texture {
}
}
impl ShmGfxTexture for Texture {
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
self
}
}
impl ShmGfxTexture for Texture {}
impl AsyncShmGfxTexture for Texture {
fn async_upload(
@ -136,8 +123,4 @@ impl AsyncShmGfxTexture for Texture {
&& height == self.gl.height
&& stride == self.gl.stride
}
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
self
}
}

View file

@ -28,7 +28,7 @@ use {
format::Format,
gfx_api::{
AsyncShmGfxTexture, GfxBlendBuffer, GfxContext, GfxError, GfxFormat, GfxImage,
GfxInternalFramebuffer, GfxStagingBuffer, ResetStatus, STAGING_DOWNLOAD,
GfxInternalFramebuffer, GfxStagingBuffer, GfxTexture, ResetStatus, STAGING_DOWNLOAD,
STAGING_UPLOAD, ShmGfxTexture, StagingBufferUsecase,
},
gfx_apis::vulkan::{
@ -272,7 +272,7 @@ impl GfxContext for Context {
damage: Option<&[Rect]>,
) -> Result<Rc<dyn ShmGfxTexture>, GfxError> {
if let Some(old) = old {
let old = old.into_texture().into_vk(&self.0.device.device);
let old = (old as Rc<dyn GfxTexture>).into_vk(&self.0.device.device);
let shm = match &old.ty {
VulkanImageMemory::DmaBuf(_) => unreachable!(),
VulkanImageMemory::Blend(_) => unreachable!(),

View file

@ -14,7 +14,7 @@ use {
ImageTiling, ImageType, ImageViewCreateInfo, ImageViewType, SampleCountFlags, SharingMode,
},
gpu_alloc::UsageFlags,
std::{any::Any, cell::Cell, collections::hash_map::Entry, rc::Rc},
std::{cell::Cell, collections::hash_map::Entry, rc::Rc},
};
impl VulkanRenderer {
@ -113,8 +113,4 @@ impl VulkanRenderer {
}
}
impl GfxBlendBuffer for VulkanImage {
fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
self
}
}
impl GfxBlendBuffer for VulkanImage {}

View file

@ -32,7 +32,6 @@ use {
},
gpu_alloc::UsageFlags,
std::{
any::Any,
cell::Cell,
fmt::{Debug, Formatter},
mem,
@ -591,10 +590,6 @@ impl GfxFramebuffer for VulkanImage {
}
impl GfxInternalFramebuffer for VulkanImage {
fn into_fb(self: Rc<Self>) -> Rc<dyn GfxFramebuffer> {
self
}
fn stride(&self) -> i32 {
let VulkanImageMemory::Internal(shm) = &self.ty else {
unreachable!();
@ -637,14 +632,6 @@ impl GfxTexture for VulkanImage {
(self.width as _, self.height as _)
}
fn as_any(&self) -> &dyn Any {
self
}
fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
self
}
fn dmabuf(&self) -> Option<&DmaBuf> {
match &self.ty {
VulkanImageMemory::DmaBuf(b) => Some(&b.template.dmabuf),
@ -658,11 +645,7 @@ impl GfxTexture for VulkanImage {
}
}
impl ShmGfxTexture for VulkanImage {
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
self
}
}
impl ShmGfxTexture for VulkanImage {}
impl AsyncShmGfxTexture for VulkanImage {
fn staging_size(&self) -> usize {
@ -711,10 +694,6 @@ impl AsyncShmGfxTexture for VulkanImage {
&& self.height == height as u32
&& self.stride == stride as u32
}
fn into_texture(self: Rc<Self>) -> Rc<dyn GfxTexture> {
self
}
}
impl AsyncShmGfxTextureTransferCancellable for VulkanImage {

View file

@ -60,6 +60,7 @@ use {
jay_algorithms::rect::Tag,
linearize::{Linearize, LinearizeExt, StaticMap, static_map},
std::{
any::Any,
borrow::Cow,
cell::{Cell, RefCell},
collections::hash_map::Entry,
@ -1967,8 +1968,7 @@ impl VulkanImage {
impl dyn GfxTexture {
fn as_vk(&self, device: &Device) -> &VulkanImage {
let img: &VulkanImage = self
.as_any()
let img: &VulkanImage = (self as &dyn Any)
.downcast_ref()
.expect("Non-vulkan texture passed into vulkan");
img.assert_device(device);
@ -1976,8 +1976,7 @@ impl dyn GfxTexture {
}
pub(super) fn into_vk(self: Rc<Self>, device: &Device) -> Rc<VulkanImage> {
let img: Rc<VulkanImage> = self
.into_any()
let img: Rc<VulkanImage> = (self as Rc<dyn Any>)
.downcast()
.expect("Non-vulkan texture passed into vulkan");
img.assert_device(device);
@ -1987,8 +1986,7 @@ impl dyn GfxTexture {
impl dyn GfxBlendBuffer {
pub(super) fn into_vk(self: Rc<Self>, device: &Device) -> Rc<VulkanImage> {
let img: Rc<VulkanImage> = self
.into_any()
let img: Rc<VulkanImage> = (self as Rc<dyn Any>)
.downcast()
.expect("Non-vulkan blend buffer passed into vulkan");
img.assert_device(device);

View file

@ -178,10 +178,6 @@ impl GfxStagingBuffer for VulkanStagingShell {
fn size(&self) -> usize {
self.size as _
}
fn into_any(self: Rc<Self>) -> Rc<dyn Any> {
self
}
}
impl VulkanStagingShell {
@ -196,8 +192,7 @@ impl VulkanStagingShell {
impl dyn GfxStagingBuffer {
pub(super) fn into_vk(self: Rc<Self>, device: &Device) -> Rc<VulkanStagingShell> {
let shell: Rc<VulkanStagingShell> = self
.into_any()
let shell: Rc<VulkanStagingShell> = (self as Rc<dyn Any>)
.downcast()
.expect("Non-vulkan staging buffer passed into vulkan");
shell.assert_device(device);