core: Make RenderBackend downcastable

This commit is contained in:
Nathan Adams 2020-05-11 09:02:49 +02:00 committed by Mike Welsh
parent a4905536b9
commit 2343074c56
3 changed files with 5 additions and 3 deletions

View File

@ -1,9 +1,10 @@
use crate::shape_utils::DistilledShape; use crate::shape_utils::DistilledShape;
pub use crate::{transform::Transform, Color}; pub use crate::{transform::Transform, Color};
use downcast_rs::Downcast;
use std::io::Read; use std::io::Read;
pub use swf; pub use swf;
pub trait RenderBackend { pub trait RenderBackend: Downcast {
fn set_viewport_dimensions(&mut self, width: u32, height: u32); fn set_viewport_dimensions(&mut self, width: u32, height: u32);
fn register_shape(&mut self, shape: DistilledShape) -> ShapeHandle; fn register_shape(&mut self, shape: DistilledShape) -> ShapeHandle;
fn register_glyph_shape(&mut self, shape: &swf::Glyph) -> ShapeHandle; fn register_glyph_shape(&mut self, shape: &swf::Glyph) -> ShapeHandle;
@ -31,6 +32,7 @@ pub trait RenderBackend {
fn activate_mask(&mut self); fn activate_mask(&mut self);
fn pop_mask(&mut self); fn pop_mask(&mut self);
} }
impl_downcast!(RenderBackend);
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct ShapeHandle(pub usize); pub struct ShapeHandle(pub usize);

View File

@ -58,7 +58,7 @@ pub struct UpdateContext<'a, 'gc, 'gc_context> {
pub navigator: &'a mut (dyn NavigatorBackend + 'a), pub navigator: &'a mut (dyn NavigatorBackend + 'a),
/// The renderer, used by the display objects to draw themselves. /// The renderer, used by the display objects to draw themselves.
pub renderer: &'a mut (dyn RenderBackend + 'a), pub renderer: &'a mut dyn RenderBackend,
/// The input backend, used to detect user interactions. /// The input backend, used to detect user interactions.
pub input: &'a mut dyn InputBackend, pub input: &'a mut dyn InputBackend,

View File

@ -5,7 +5,7 @@ pub trait RenderTargetFrame: Debug {
fn view(&self) -> &wgpu::TextureView; fn view(&self) -> &wgpu::TextureView;
} }
pub trait RenderTarget: Debug { pub trait RenderTarget: Debug + 'static {
type Frame: RenderTargetFrame; type Frame: RenderTargetFrame;
fn resize(&mut self, device: &wgpu::Device, width: u32, height: u32); fn resize(&mut self, device: &wgpu::Device, width: u32, height: u32);