fixup! feat(core): introduce new drawing library

cepetr/gfx-alpha
cepetr 4 weeks ago
parent 91a0202a52
commit 0b55d8d3db

@ -245,33 +245,12 @@ impl<'a> BitBltCopy<'a> {
}
}
/// Copies a part of the source bitmap to the destination bitmap.
///
/// - The source bitmap format uses MONO4.
/// - The destination bitmap uses RGB565.
pub fn rgb565_copy_mono4(&self, dst: &mut Bitmap) {
/// Copies a part of the source bitmap to the destination bitmap in RGB565
/// format.
pub fn rgb565_copy(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::RGB565);
assert!(self.src.format() == BitmapFormat::MONO4);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
// - Source and destination coordinates are properly clipped, which is ensured
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_rgb565_copy_mono4(&self.bitblt.with_dst(dst)) };
dst.mark_dma_pending();
self.src.bitmap.mark_dma_pending();
}
/// Copies a part of the source bitmap to the destination bitmap.
///
/// - The source bitmap uses the RGB565 format.
/// - The destination bitmap usesthe RGB565 format.
pub fn rgb565_copy_rgb565(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::RGB565);
assert!(self.src.format() == BitmapFormat::RGB565);
let bitblt = self.bitblt.with_dst(dst);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
@ -279,39 +258,22 @@ impl<'a> BitBltCopy<'a> {
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_rgb565_copy_rgb565(&self.bitblt.with_dst(dst)) };
match self.src.format() {
BitmapFormat::MONO4 => unsafe { ffi::gl_rgb565_copy_mono4(&bitblt) },
BitmapFormat::RGB565 => unsafe { ffi::gl_rgb565_copy_rgb565(&bitblt) },
_ => unimplemented!(),
}
dst.mark_dma_pending();
self.src.bitmap.mark_dma_pending();
dst.mark_dma_pending();
}
/// Blends a part of the source bitmap with the destination bitmap.
///
/// - The source bitmap uses the MONO4 format.
/// - The destination bitmap uses the RGB565 format.
pub fn rgb565_blend_mono4(&self, dst: &mut Bitmap) {
/// Blends a part of the source bitmap with the destination bitmap in RGB565
/// format.
pub fn rgb565_blend(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::RGB565);
assert!(self.src.format() == BitmapFormat::MONO4);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
// - Source and destination coordinates are properly clipped, which is ensured
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_rgb565_blend_mono4(&self.bitblt.with_dst(dst)) };
dst.mark_dma_pending();
self.src.bitmap.mark_dma_pending();
}
/// Copies a part of the source bitmap to the destination bitmap.
///
/// - The source bitmap uses the MONO4 format.
/// - The destination bitmap uses the RGBA8888 format.
pub fn rgba8888_copy_mono4(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::RGBA8888);
assert!(self.src.format() == BitmapFormat::MONO4);
let bitblt = self.bitblt.with_dst(dst);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
@ -319,39 +281,21 @@ impl<'a> BitBltCopy<'a> {
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_rgba8888_copy_mono4(&self.bitblt.with_dst(dst)) };
match self.src.format() {
BitmapFormat::MONO4 => unsafe { ffi::gl_rgb565_blend_mono4(&bitblt) },
_ => unimplemented!(),
}
dst.mark_dma_pending();
self.src.bitmap.mark_dma_pending();
}
/// Copies a part of the source bitmap to the destination bitmap.
///
/// - The source bitmap uses the RGB565 format.
/// - The destination bitmap uses the RGBA8888 format.
pub fn rgba8888_copy_rgb565(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::RGBA8888);
assert!(self.src.format() == BitmapFormat::RGB565);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
// - Source and destination coordinates are properly clipped, which is ensured
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_rgba8888_copy_rgb565(&self.bitblt.with_dst(dst)) };
dst.mark_dma_pending();
self.src.bitmap.mark_dma_pending();
}
/// Copies a part of the source bitmap to the destination bitmap.
///
/// - The source bitmap uses the RGBA8888 format.
/// - The destination bitmap uses the RGBA8888 format.
pub fn rgba8888_copy_rgba8888(&self, dst: &mut Bitmap) {
/// Copies a part of the source bitmap to the destination bitmap in RGBA8888
/// format.
pub fn rgba8888_copy(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::RGBA8888);
assert!(self.src.format() == BitmapFormat::RGBA8888);
let bitblt = self.bitblt.with_dst(dst);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
@ -359,39 +303,23 @@ impl<'a> BitBltCopy<'a> {
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_rgba8888_copy_rgba8888(&self.bitblt.with_dst(dst)) };
match self.src.format() {
BitmapFormat::MONO4 => unsafe { ffi::gl_rgba8888_copy_mono4(&bitblt) },
BitmapFormat::RGB565 => unsafe { ffi::gl_rgba8888_copy_rgb565(&bitblt) },
BitmapFormat::RGBA8888 => unsafe { ffi::gl_rgba8888_copy_rgba8888(&bitblt) },
_ => unimplemented!(),
}
dst.mark_dma_pending();
self.src.bitmap.mark_dma_pending();
dst.mark_dma_pending();
}
/// Blends a part of the source bitmap with the destination bitmap.
///
/// - The source bitmap uses the MONO4 format.
/// - The destination bitmap uses the RGBA8888 format.
pub fn rgba8888_blend_mono4(&self, dst: &mut Bitmap) {
/// Blends a part of the source bitmap with the destination bitmap in
/// RGBA8888 format.
pub fn rgba8888_blend(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::RGBA8888);
assert!(self.src.format() == BitmapFormat::MONO4);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
// - Source and destination coordinates are properly clipped, which is ensured
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_rgba8888_blend_mono4(&self.bitblt.with_dst(dst)) };
dst.mark_dma_pending();
self.src.bitmap.mark_dma_pending();
}
/// Copies a part of the source bitmap to the destination bitmap.
///
/// - The source bitmap uses the MONO1P format.
/// - The destination bitmap uses the MONO8 format.
pub fn mono8_copy_mono1p(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::MONO8);
assert!(self.src.format() == BitmapFormat::MONO1P);
let bitblt = self.bitblt.with_dst(dst);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
@ -399,39 +327,21 @@ impl<'a> BitBltCopy<'a> {
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_mono8_copy_mono1p(&self.bitblt.with_dst(dst)) };
match self.src.format() {
BitmapFormat::MONO4 => unsafe { ffi::gl_rgba8888_blend_mono4(&bitblt) },
_ => unimplemented!(),
}
dst.mark_dma_pending();
self.src.bitmap.mark_dma_pending();
}
/// Copies a part of the source bitmap to the destination bitmap.
///
/// - The source bitmap uses the MONO4 format.
/// - The destination bitmap uses the MONO8 format.
pub fn mono8_copy_mono4(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::MONO8);
assert!(self.src.format() == BitmapFormat::MONO4);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
// - Source and destination coordinates are properly clipped, which is ensured
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_mono8_copy_mono4(&self.bitblt.with_dst(dst)) };
dst.mark_dma_pending();
self.src.bitmap.mark_dma_pending();
}
/// Blends a part of the source bitmap with the destination bitmap.
///
/// - The source bitmap uses the MONO1P format.
/// - The destination bitmap uses the MONO8 format.
pub fn mono8_blend_mono1p(&self, dst: &mut Bitmap) {
/// Copies a part of the source bitmap to the destination bitmap in MONO8
/// format.
pub fn mono8_copy(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::MONO8);
assert!(self.src.format() == BitmapFormat::MONO1P);
let bitblt = self.bitblt.with_dst(dst);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
@ -439,19 +349,23 @@ impl<'a> BitBltCopy<'a> {
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_mono8_blend_mono1p(&self.bitblt.with_dst(dst)) };
dst.mark_dma_pending();
match self.src.format() {
BitmapFormat::MONO1P => unsafe { ffi::gl_mono8_copy_mono1p(&bitblt) },
BitmapFormat::MONO4 => unsafe { ffi::gl_mono8_copy_mono4(&bitblt) },
_ => unimplemented!(),
}
self.src.bitmap.mark_dma_pending();
dst.mark_dma_pending();
}
/// Blends a part of the source bitmap with the destination bitmap.
///
/// - The source bitmap uses the MONO4 format.
/// - The destination bitmap uses the MONO8 format.
pub fn mono8_blend_mono4(&self, dst: &mut Bitmap) {
/// Blends a part of the source bitmap with the destination bitmap in MONO8
/// format.
pub fn mono8_blend(&self, dst: &mut Bitmap) {
assert!(dst.format() == BitmapFormat::MONO8);
assert!(self.src.format() == BitmapFormat::MONO4);
let bitblt = self.bitblt.with_dst(dst);
// SAFETY:
// - The destination and source bitmaps are in the correct formats.
@ -459,26 +373,33 @@ impl<'a> BitBltCopy<'a> {
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for both bitmaps after operations.
unsafe { ffi::gl_mono8_blend_mono4(&self.bitblt.with_dst(dst)) };
dst.mark_dma_pending();
match self.src.format() {
BitmapFormat::MONO1P => unsafe { ffi::gl_mono8_blend_mono1p(&bitblt) },
BitmapFormat::MONO4 => unsafe { ffi::gl_mono8_blend_mono4(&bitblt) },
_ => unimplemented!(),
}
self.src.bitmap.mark_dma_pending();
dst.mark_dma_pending();
}
/// Copies a part of the source bitmap to the display.
///
/// - The source bitmap uses the RGB565 format.
#[cfg(all(not(feature = "xframebuffer"), feature = "new_rendering"))]
pub fn display_copy_rgb565(&self) {
assert!(self.src.format() == BitmapFormat::MONO4);
pub fn display_copy(&self) {
// SAFETY:
// - The source bitmap is in the correct formats.
// - Source and destination coordinates are properly clipped, which is ensured
// by the `new()` and `with_dst()` methods.
// - BitBlt structure is properly initialized.
// - The DMA pending flag is set for src bitmap after operations.
unsafe { ffi::display_copy_rgb565(&self.bitblt) };
match self.src.format() {
BitmapFormat::RGB565 => unsafe { ffi::display_copy_rgb565(&self.bitblt) },
_ => unimplemented!(),
}
self.src.bitmap.mark_dma_pending();
}

@ -1,6 +1,3 @@
pub mod bitmap_base;
pub mod mono8;
pub mod rgb565;
pub mod rgba8888;
pub use bitmap_base::{Bitmap, BitmapFormat, BitmapView};

@ -1,37 +0,0 @@
use super::{Bitmap, BitmapFormat, BitmapView};
use crate::{
trezorhal::bitblt::{BitBltCopy, BitBltFill},
ui::{display::Color, geometry::Rect},
};
impl<'a> Bitmap<'a> {
/// Fills a rectangle with the specified color.
///
/// The function is aplicable only on bitmaps with MONO8 format.
pub fn mono8_fill(&mut self, r: Rect, clip: Rect, color: Color, alpha: u8) {
if let Some(bitblt) = BitBltFill::new(r, clip, color, alpha) {
bitblt.mono8_fill(self);
}
}
//
pub fn mono8_copy(&mut self, r: Rect, clip: Rect, src: &BitmapView) {
if let Some(bitblt) = BitBltCopy::new(r, clip, src) {
match src.format() {
BitmapFormat::MONO1P => bitblt.mono8_copy_mono1p(self),
BitmapFormat::MONO4 => bitblt.mono8_copy_mono4(self),
_ => panic!("Unsupported DMA operation"),
}
}
}
pub fn mono8_blend(&mut self, r: Rect, clip: Rect, src: &BitmapView) {
if let Some(bitblt) = BitBltCopy::new(r, clip, src) {
match src.format() {
BitmapFormat::MONO1P => bitblt.mono8_blend_mono1p(self),
BitmapFormat::MONO4 => bitblt.mono8_blend_mono4(self),
_ => panic!("Unsupported DMA operation"),
}
}
}
}

@ -1,41 +0,0 @@
use super::{Bitmap, BitmapFormat, BitmapView};
use crate::{
trezorhal::bitblt::{BitBltCopy, BitBltFill},
ui::{display::Color, geometry::Rect},
};
impl<'a> Bitmap<'a> {
/// Fills a rectangle with the specified color.
///
/// The function is aplicable only on bitmaps with RGB565 format.
pub fn rgb565_fill(&mut self, r: Rect, clip: Rect, color: Color, alpha: u8) {
if let Some(bitblt) = BitBltFill::new(r, clip, color, alpha) {
bitblt.rgb565_fill(self);
}
}
/// Copy a rectangle from the source bitmap to the destination bitmap.
///
/// The function is aplicable only on bitmaps with RGB565 format.
pub fn rgb565_copy(&mut self, r: Rect, clip: Rect, src: &BitmapView) {
if let Some(bitblt) = BitBltCopy::new(r, clip, src) {
match src.format() {
BitmapFormat::MONO4 => bitblt.rgb565_copy_mono4(self),
BitmapFormat::RGB565 => bitblt.rgb565_copy_rgb565(self),
_ => panic!("Unsupported DMA operation"),
}
}
}
/// Blend a rectangle from the source bitmap to the destination bitmap.
///
/// The function is aplicable only on bitmaps with RGB565 format.
pub fn rgb565_blend(&mut self, r: Rect, clip: Rect, src: &BitmapView) {
if let Some(bitblt) = BitBltCopy::new(r, clip, src) {
match src.format() {
BitmapFormat::MONO4 => bitblt.rgb565_blend_mono4(self),
_ => panic!("Unsupported DMA operation"),
}
}
}
}

@ -1,36 +0,0 @@
use super::{Bitmap, BitmapFormat, BitmapView};
use crate::{
trezorhal::bitblt::{BitBltCopy, BitBltFill},
ui::{display::Color, geometry::Rect},
};
impl<'a> Bitmap<'a> {
/// Fills a rectangle with the specified color.
///
/// The function is aplicable only on bitmaps with RGBA888 format.
pub fn rgba8888_fill(&mut self, r: Rect, clip: Rect, color: Color, alpha: u8) {
if let Some(bitblt) = BitBltFill::new(r, clip, color, alpha) {
bitblt.rgba8888_fill(self);
}
}
pub fn rgba8888_copy(&mut self, r: Rect, clip: Rect, src: &BitmapView) {
if let Some(bitblt) = BitBltCopy::new(r, clip, src) {
match src.format() {
BitmapFormat::MONO4 => bitblt.rgba8888_copy_mono4(self),
BitmapFormat::RGB565 => bitblt.rgba8888_copy_rgb565(self),
BitmapFormat::RGBA8888 => bitblt.rgba8888_copy_rgba8888(self),
_ => panic!("Unsupported DMA operation"),
}
}
}
pub fn rgba8888_blend(&mut self, r: Rect, clip: Rect, src: &BitmapView) {
if let Some(bitblt) = BitBltCopy::new(r, clip, src) {
match src.format() {
BitmapFormat::MONO4 => bitblt.rgba8888_blend_mono4(self),
_ => panic!("Unsupported DMA operation"),
}
}
}
}

@ -1,6 +1,9 @@
use crate::ui::{
display::Color,
geometry::{Offset, Point, Rect},
use crate::{
trezorhal::bitblt::{BitBltCopy, BitBltFill},
ui::{
display::Color,
geometry::{Offset, Point, Rect},
},
};
use super::{
@ -58,12 +61,16 @@ impl<'a> BasicCanvas for Mono8Canvas<'a> {
fn fill_rect(&mut self, r: Rect, color: Color, alpha: u8) {
let r = r.translate(self.viewport.origin);
self.bitmap.mono8_fill(r, self.viewport.clip, color, alpha);
if let Some(bitblt) = BitBltFill::new(r, self.viewport.clip, color, alpha) {
bitblt.mono8_fill(&mut self.bitmap);
}
}
fn draw_bitmap(&mut self, r: Rect, bitmap: BitmapView) {
let r = r.translate(self.viewport.origin);
self.bitmap.mono8_copy(r, self.viewport.clip, &bitmap);
if let Some(bitblt) = BitBltCopy::new(r, self.viewport.clip, &bitmap) {
bitblt.mono8_copy(&mut self.bitmap);
}
}
}
@ -95,7 +102,9 @@ impl<'a> Canvas for Mono8Canvas<'a> {
fn blend_bitmap(&mut self, r: Rect, src: BitmapView) {
let r = r.translate(self.viewport.origin);
self.bitmap.mono8_blend(r, self.viewport.clip, &src);
if let Some(bitblt) = BitBltCopy::new(r, self.viewport.clip, &src) {
bitblt.mono8_blend(&mut self.bitmap);
}
}
#[cfg(feature = "ui_blurring")]

@ -1,6 +1,9 @@
use crate::ui::{
display::Color,
geometry::{Offset, Point, Rect},
use crate::{
trezorhal::bitblt::{self, BitBltCopy, BitBltFill},
ui::{
display::Color,
geometry::{Offset, Point, Rect},
},
};
use super::{
@ -58,12 +61,16 @@ impl<'a> BasicCanvas for Rgb565Canvas<'a> {
fn fill_rect(&mut self, r: Rect, color: Color, alpha: u8) {
let r = r.translate(self.viewport.origin);
self.bitmap.rgb565_fill(r, self.viewport.clip, color, alpha);
if let Some(bitblt) = BitBltFill::new(r, self.viewport.clip, color, alpha) {
bitblt.rgb565_fill(&mut self.bitmap);
}
}
fn draw_bitmap(&mut self, r: Rect, bitmap: BitmapView) {
let r = r.translate(self.viewport.origin);
self.bitmap.rgb565_copy(r, self.viewport.clip, &bitmap);
if let Some(bitblt) = BitBltCopy::new(r, self.viewport.clip, &bitmap) {
bitblt.rgb565_copy(&mut self.bitmap);
}
}
}
@ -94,7 +101,9 @@ impl<'a> Canvas for Rgb565Canvas<'a> {
fn blend_bitmap(&mut self, r: Rect, src: BitmapView) {
let r = r.translate(self.viewport.origin);
self.bitmap.rgb565_blend(r, self.viewport.clip, &src);
if let Some(bitblt) = BitBltCopy::new(r, self.viewport.clip, &src) {
bitblt.rgb565_blend(&mut self.bitmap);
}
}
#[cfg(feature = "ui_blurring")]

@ -1,6 +1,9 @@
use crate::ui::{
display::Color,
geometry::{Offset, Point, Rect},
use crate::{
trezorhal::bitblt::{BitBltCopy, BitBltFill},
ui::{
display::Color,
geometry::{Offset, Point, Rect},
},
};
use super::{
@ -58,13 +61,16 @@ impl<'a> BasicCanvas for Rgba8888Canvas<'a> {
fn fill_rect(&mut self, r: Rect, color: Color, alpha: u8) {
let r = r.translate(self.viewport.origin);
self.bitmap
.rgba8888_fill(r, self.viewport.clip, color, alpha);
if let Some(bitblt) = BitBltFill::new(r, self.viewport.clip, color, alpha) {
bitblt.rgba8888_fill(&mut self.bitmap);
}
}
fn draw_bitmap(&mut self, r: Rect, bitmap: BitmapView) {
let r = r.translate(self.viewport.origin);
self.bitmap.rgba8888_copy(r, self.viewport.clip, &bitmap);
if let Some(bitblt) = BitBltCopy::new(r, self.viewport.clip, &bitmap) {
bitblt.rgba8888_copy(&mut self.bitmap);
}
}
}
@ -110,7 +116,9 @@ impl<'a> Canvas for Rgba8888Canvas<'a> {
fn blend_bitmap(&mut self, r: Rect, src: BitmapView) {
let r = r.translate(self.viewport.origin);
self.bitmap.rgba8888_blend(r, self.viewport.clip, &src);
if let Some(bitblt) = BitBltCopy::new(r, self.viewport.clip, &src) {
bitblt.rgba8888_blend(&mut self.bitmap);
}
}
#[cfg(feature = "ui_blurring")]

@ -103,10 +103,7 @@ impl BasicCanvas for DisplayCanvas {
fn draw_bitmap(&mut self, r: Rect, bitmap: BitmapView) {
let r = r.translate(self.viewport.origin);
if let Some(bitblt) = BitBltCopy::new(r, self.viewport.clip, &bitmap) {
match bitmap.format() {
BitmapFormat::RGB565 => bitblt.display_copy_rgb565(),
_ => panic!("Unsupported DMA operation"),
}
bitblt.display_copy();
}
}
}

Loading…
Cancel
Save