matejcik/new-drawing-api
matejcik 4 months ago
parent 67a07426fb
commit 8b112956c2

@ -136,9 +136,8 @@ fn draw_screen(split: Point) -> time::Duration {
let bump_a = unsafe { &mut *core::ptr::addr_of_mut!(POOL_A) }; let bump_a = unsafe { &mut *core::ptr::addr_of_mut!(POOL_A) };
let bump_b = unsafe { &mut *core::ptr::addr_of_mut!(POOL_B) }; let bump_b = unsafe { &mut *core::ptr::addr_of_mut!(POOL_B) };
{ {
let mut context = DrawingContextImpl::new(bump_a, bump_b);
let mut canvas = display::Canvas::acquire().unwrap(); let mut canvas = display::Canvas::acquire().unwrap();
let mut context = DrawingContextImpl::new(bump_a, bump_b);
let vp = canvas.set_window(canvas.bounds().inset(Insets::new(20, 0, 0, 0))); let vp = canvas.set_window(canvas.bounds().inset(Insets::new(20, 0, 0, 0)));

@ -5,7 +5,7 @@ pub struct BitmapCache<'a> {
} }
impl<'a> BitmapCache<'a> { impl<'a> BitmapCache<'a> {
pub fn new<'alloc: 'a, T>(_pool: &'alloc T) -> BitmapCache<'alloc> pub fn new<'alloc: 'a, T>(_pool: &'alloc T) -> Self
where where
T: LocalAllocLeakExt<'alloc>, T: LocalAllocLeakExt<'alloc>,
{ {

@ -5,7 +5,7 @@ pub struct BlurCache<'a> {
} }
impl<'a> BlurCache<'a> { impl<'a> BlurCache<'a> {
pub fn new<'alloc: 'a, T>(_pool: &'alloc T) -> BlurCache<'alloc> pub fn new<'alloc: 'a, T>(_pool: &'alloc T) -> Self
where where
T: LocalAllocLeakExt<'alloc>, T: LocalAllocLeakExt<'alloc>,
{ {

@ -24,18 +24,17 @@ pub trait DrawingContext<'a> {
) -> Result<(), tjpgd::Error>; ) -> Result<(), tjpgd::Error>;
} }
pub struct DrawingContextImpl<'a, 'b> { pub struct DrawingContextImpl<'alloc> {
zlib_cache: ZlibCache<'a>, zlib_cache: ZlibCache<'alloc>,
jpeg_cache: JpegCache<'a>, jpeg_cache: JpegCache<'alloc>,
blur_cache: BlurCache<'a>, blur_cache: BlurCache<'alloc>,
bitmap_cache: BitmapCache<'b>, bitmap_cache: BitmapCache<'alloc>,
} }
impl<'a, 'b> DrawingContextImpl<'a, 'b> { impl<'alloc> DrawingContextImpl<'alloc> {
pub fn new<TA, TB>(pool_a: &'a TA, pool_b: &'b TB) -> Self pub fn new<TA>(pool_a: &'alloc TA, pool_b: &'alloc TA) -> Self
where where
TA: LocalAllocLeakExt<'a>, TA: LocalAllocLeakExt<'alloc>,
TB: LocalAllocLeakExt<'b>,
{ {
Self { Self {
zlib_cache: ZlibCache::new(pool_a, 4), zlib_cache: ZlibCache::new(pool_a, 4),
@ -46,7 +45,7 @@ impl<'a, 'b> DrawingContextImpl<'a, 'b> {
} }
} }
impl<'a, 'b> DrawingContext<'a> for DrawingContextImpl<'a, 'b> { impl<'a> DrawingContext<'a> for DrawingContextImpl<'a> {
fn deflate_toif(&mut self, toif: Toif<'static>, from_row: i16, dest_buf: &mut [u8]) { fn deflate_toif(&mut self, toif: Toif<'static>, from_row: i16, dest_buf: &mut [u8]) {
let from_offset = toif.stride() * from_row as usize; let from_offset = toif.stride() * from_row as usize;
self.zlib_cache self.zlib_cache

@ -180,7 +180,7 @@ pub struct JpegCache<'a> {
} }
impl<'a> JpegCache<'a> { impl<'a> JpegCache<'a> {
pub fn new<'alloc: 'a, T>(pool: &'alloc T, slot_count: usize) -> JpegCache<'a> pub fn new<'alloc: 'a, T>(pool: &'alloc T, slot_count: usize) -> Self
where where
T: LocalAllocLeakExt<'alloc>, T: LocalAllocLeakExt<'alloc>,
{ {

@ -97,7 +97,7 @@ pub struct ZlibCache<'a> {
} }
impl<'a> ZlibCache<'a> { impl<'a> ZlibCache<'a> {
pub fn new<'alloc: 'a, T>(pool: &'alloc T, slot_count: usize) -> ZlibCache<'alloc> pub fn new<'alloc: 'a, T>(pool: &'alloc T, slot_count: usize) -> Self
where where
T: LocalAllocLeakExt<'alloc>, T: LocalAllocLeakExt<'alloc>,
{ {

@ -110,9 +110,9 @@ struct ShapeHolder<'a> {
} }
/// A more advanced Renderer implementation that supports deferred rendering. /// A more advanced Renderer implementation that supports deferred rendering.
pub struct ProgressiveRenderer<'can, 'ctx, 'alloc, T: LocalAllocLeakExt<'alloc>> { pub struct ProgressiveRenderer<'a, 'alloc, T: LocalAllocLeakExt<'alloc>> {
/// Target canvas /// Target canvas
canvas: &'can mut dyn rgb::RgbCanvas, canvas: &'a mut dyn rgb::RgbCanvas,
/// Pool for cloning shapes /// Pool for cloning shapes
pool: &'alloc T, pool: &'alloc T,
/// List of rendered shapes /// List of rendered shapes
@ -122,18 +122,18 @@ pub struct ProgressiveRenderer<'can, 'ctx, 'alloc, T: LocalAllocLeakExt<'alloc>>
// Default background color // Default background color
bg_color: Option<Color>, bg_color: Option<Color>,
/// Drawing context (decompression context, scratch-pad memory) /// Drawing context (decompression context, scratch-pad memory)
drawing_context: &'ctx mut dyn DrawingContext<'alloc>, drawing_context: &'a mut dyn DrawingContext<'alloc>,
} }
impl<'can, 'ctx, 'alloc, T> ProgressiveRenderer<'can, 'ctx, 'alloc, T> impl<'a, 'alloc, T> ProgressiveRenderer<'a, 'alloc, T>
where where
T: LocalAllocLeakExt<'alloc>, T: LocalAllocLeakExt<'alloc>,
{ {
/// Creates a new ProgressiveRenderer instance /// Creates a new ProgressiveRenderer instance
pub fn new( pub fn new(
canvas: &'can mut dyn rgb::RgbCanvas, canvas: &'a mut dyn rgb::RgbCanvas,
bg_color: Option<Color>, bg_color: Option<Color>,
context: &'ctx mut dyn DrawingContext<'alloc>, context: &'a mut dyn DrawingContext<'alloc>,
pool: &'alloc T, pool: &'alloc T,
max_shapes: usize, max_shapes: usize,
) -> Self { ) -> Self {
@ -193,7 +193,7 @@ where
} }
} }
impl<'can, 'ctx, 'alloc, T> Renderer for ProgressiveRenderer<'can, 'ctx, 'alloc, T> impl<'a, 'alloc, T> Renderer for ProgressiveRenderer<'a, 'alloc, T>
where where
T: LocalAllocLeakExt<'alloc>, T: LocalAllocLeakExt<'alloc>,
{ {

Loading…
Cancel
Save