FbDbDrawTarget

Struct FbDbDrawTarget 

Source
pub struct FbDbDrawTarget<'proto> { /* private fields */ }
Available on crate feature alloc only.
Expand description

A double-buffered framebuffer DrawTarget.

Rudimentary damage tracking is performed to minimize the region that gets copied to the primary buffer.

Any untransferred changes are automatically transferred when the FbDbDrawTarget is dropped.

See the module-level documentation for more information on the framebuffer DrawTargets.

§Examples

use embedded_graphics_gop::fb::FbDbDrawTarget;
use uefi::{prelude::*, proto::console::gop::GraphicsOutput};

// Get the first available handle for the GOP.
let handle = boot::get_handle_for_protocol::<GraphicsOutput>().unwrap();
// Open the protocol in exclusive mode (exclusive mode is for applications, other modes are
// intended for drivers)
let mut protocol = boot::open_protocol_exclusive::<GraphicsOutput>(handle).unwrap();
// Configure protocol here if desired, for example
let mode = protocol.modes().find(|m| m.info().resolution() == (800, 600)).unwrap();
protocol.set_mode(&mode).unwrap();

// Create the draw target utilizing the configured protocol.
let mut target = FbDbDrawTarget::new(&mut protocol);

// ...draw on it...

// Transfer changes to the framebuffer
target.commit();

Implementations§

Source§

impl<'proto> FbDbDrawTarget<'proto>

Source

pub fn new(protocol: &'proto mut ScopedProtocol<GraphicsOutput>) -> Self

Create a new FbDbDrawTarget given a GOP protocol handle.

Fills the framebuffer and backbuffer with black.

Note that one should configure the desired graphics mode for the protocol prior to creating the FbDbDrawTarget.

§Panics

Exactly the same as FbDrawTarget::new.

Examples found in repository?
examples/double_buffered_framebuffer.rs (line 37)
21fn main() -> Status {
22	helpers::init().unwrap();
23
24	let handle =
25		boot::get_handle_for_protocol::<GraphicsOutput>().expect("Unable to get GOP handle");
26	let mut gop =
27		boot::open_protocol_exclusive::<GraphicsOutput>(handle).expect("Unable to open GOP handle");
28
29	let mode_800x600 = gop
30		.modes()
31		// one of the standard modes, although some systems may only provide 640×480
32		.find(|m| m.info().resolution() == (800, 600))
33		.expect("Unable to find 800x600 video mode");
34	gop.set_mode(&mode_800x600)
35		.expect("Couldn't switch to 800x600 video mode");
36
37	let mut target = FbDbDrawTarget::new(&mut gop);
38
39	let center = Point::new(400, 300);
40
41	let white_fill = PrimitiveStyle::with_fill(Rgb888::WHITE);
42	let (red_outline, green_outline, blue_outline) = {
43		let base = PrimitiveStyleBuilder::new().stroke_width(10);
44		(
45			base.stroke_color(Rgb888::RED).build(),
46			base.stroke_color(Rgb888::GREEN).build(),
47			base.stroke_color(Rgb888::BLUE).build(),
48		)
49	};
50
51	Circle::with_center(center, 500)
52		.into_styled(red_outline)
53		.draw(&mut target)
54		.expect("infallible");
55
56	Circle::with_center(center, 400)
57		.into_styled(green_outline)
58		.draw(&mut target)
59		.expect("infallible");
60
61	target.commit();
62
63	// Would cover circles
64	Rectangle::with_center(Point::new(50, 50), Size::new(700, 500))
65		.into_styled(white_fill)
66		.draw(&mut target)
67		.expect("infallible");
68
69	target.discard_changes();
70
71	Circle::with_center(center, 300)
72		.into_styled(blue_outline)
73		.draw(&mut target)
74		.expect("infallible");
75
76	// should auto-commit
77	drop(target);
78
79	boot::stall(Duration::from_secs(10));
80	runtime::reset(ResetType::SHUTDOWN, Status::SUCCESS, None);
81}
More examples
Hide additional examples
examples/ball_framebuffer.rs (line 37)
21fn main() -> Status {
22	helpers::init().unwrap();
23
24	let handle =
25		boot::get_handle_for_protocol::<GraphicsOutput>().expect("Unable to get GOP handle");
26	let mut gop =
27		boot::open_protocol_exclusive::<GraphicsOutput>(handle).expect("Unable to open GOP handle");
28
29	let mode_800x600 = gop
30		.modes()
31		// one of the standard modes, although some systems may only provide 640×480
32		.find(|m| m.info().resolution() == (800, 600))
33		.expect("Unable to find 800x600 video mode");
34	gop.set_mode(&mode_800x600)
35		.expect("Couldn't switch to 800x600 video mode");
36
37	let mut target = FbDbDrawTarget::new(&mut gop);
38
39	let red_fill = PrimitiveStyle::with_fill(Rgb888::RED);
40	let blue_fill = PrimitiveStyle::with_fill(Rgb888::BLUE);
41
42	let mut ball_pos = Point::new(200, 300);
43	let mut ball_dir = Point::new(5, 5);
44	let ball_size = 10;
45	for _ in 0..1000 {
46		// Drawing over old position with blue instead of black to leave trail behind and
47		// demonstrate more colors
48		Rectangle::new(ball_pos, Size::new(ball_size, ball_size))
49			.into_styled(blue_fill)
50			.draw(&mut target)
51			.expect("infallible");
52
53		ball_pos += ball_dir;
54
55		if ball_pos.x <= 0 {
56			ball_pos.x = 0;
57			ball_dir.x = -ball_dir.x;
58		} else if ball_pos.x >= 790 {
59			ball_pos.x = 790;
60			ball_dir.x = -ball_dir.x;
61		}
62		if ball_pos.y <= 0 {
63			ball_pos.y = 0;
64			ball_dir.y = -ball_dir.y;
65		} else if ball_pos.y >= 590 {
66			ball_pos.y = 590;
67			ball_dir.y = -ball_dir.y;
68		}
69
70		Circle::new(ball_pos, 10)
71			.into_styled(red_fill)
72			.draw(&mut target)
73			.expect("infallible");
74
75		// In real code would probably want to set up UEFI timer and commit in there?
76		target.commit();
77		boot::stall(Duration::from_millis(10));
78	}
79
80	runtime::reset(ResetType::SHUTDOWN, Status::SUCCESS, None);
81}
Source

pub fn commit(&mut self)

Transfer the backbuffer contents to the primary buffer.

Examples found in repository?
examples/double_buffered_framebuffer.rs (line 61)
21fn main() -> Status {
22	helpers::init().unwrap();
23
24	let handle =
25		boot::get_handle_for_protocol::<GraphicsOutput>().expect("Unable to get GOP handle");
26	let mut gop =
27		boot::open_protocol_exclusive::<GraphicsOutput>(handle).expect("Unable to open GOP handle");
28
29	let mode_800x600 = gop
30		.modes()
31		// one of the standard modes, although some systems may only provide 640×480
32		.find(|m| m.info().resolution() == (800, 600))
33		.expect("Unable to find 800x600 video mode");
34	gop.set_mode(&mode_800x600)
35		.expect("Couldn't switch to 800x600 video mode");
36
37	let mut target = FbDbDrawTarget::new(&mut gop);
38
39	let center = Point::new(400, 300);
40
41	let white_fill = PrimitiveStyle::with_fill(Rgb888::WHITE);
42	let (red_outline, green_outline, blue_outline) = {
43		let base = PrimitiveStyleBuilder::new().stroke_width(10);
44		(
45			base.stroke_color(Rgb888::RED).build(),
46			base.stroke_color(Rgb888::GREEN).build(),
47			base.stroke_color(Rgb888::BLUE).build(),
48		)
49	};
50
51	Circle::with_center(center, 500)
52		.into_styled(red_outline)
53		.draw(&mut target)
54		.expect("infallible");
55
56	Circle::with_center(center, 400)
57		.into_styled(green_outline)
58		.draw(&mut target)
59		.expect("infallible");
60
61	target.commit();
62
63	// Would cover circles
64	Rectangle::with_center(Point::new(50, 50), Size::new(700, 500))
65		.into_styled(white_fill)
66		.draw(&mut target)
67		.expect("infallible");
68
69	target.discard_changes();
70
71	Circle::with_center(center, 300)
72		.into_styled(blue_outline)
73		.draw(&mut target)
74		.expect("infallible");
75
76	// should auto-commit
77	drop(target);
78
79	boot::stall(Duration::from_secs(10));
80	runtime::reset(ResetType::SHUTDOWN, Status::SUCCESS, None);
81}
More examples
Hide additional examples
examples/ball_framebuffer.rs (line 76)
21fn main() -> Status {
22	helpers::init().unwrap();
23
24	let handle =
25		boot::get_handle_for_protocol::<GraphicsOutput>().expect("Unable to get GOP handle");
26	let mut gop =
27		boot::open_protocol_exclusive::<GraphicsOutput>(handle).expect("Unable to open GOP handle");
28
29	let mode_800x600 = gop
30		.modes()
31		// one of the standard modes, although some systems may only provide 640×480
32		.find(|m| m.info().resolution() == (800, 600))
33		.expect("Unable to find 800x600 video mode");
34	gop.set_mode(&mode_800x600)
35		.expect("Couldn't switch to 800x600 video mode");
36
37	let mut target = FbDbDrawTarget::new(&mut gop);
38
39	let red_fill = PrimitiveStyle::with_fill(Rgb888::RED);
40	let blue_fill = PrimitiveStyle::with_fill(Rgb888::BLUE);
41
42	let mut ball_pos = Point::new(200, 300);
43	let mut ball_dir = Point::new(5, 5);
44	let ball_size = 10;
45	for _ in 0..1000 {
46		// Drawing over old position with blue instead of black to leave trail behind and
47		// demonstrate more colors
48		Rectangle::new(ball_pos, Size::new(ball_size, ball_size))
49			.into_styled(blue_fill)
50			.draw(&mut target)
51			.expect("infallible");
52
53		ball_pos += ball_dir;
54
55		if ball_pos.x <= 0 {
56			ball_pos.x = 0;
57			ball_dir.x = -ball_dir.x;
58		} else if ball_pos.x >= 790 {
59			ball_pos.x = 790;
60			ball_dir.x = -ball_dir.x;
61		}
62		if ball_pos.y <= 0 {
63			ball_pos.y = 0;
64			ball_dir.y = -ball_dir.y;
65		} else if ball_pos.y >= 590 {
66			ball_pos.y = 590;
67			ball_dir.y = -ball_dir.y;
68		}
69
70		Circle::new(ball_pos, 10)
71			.into_styled(red_fill)
72			.draw(&mut target)
73			.expect("infallible");
74
75		// In real code would probably want to set up UEFI timer and commit in there?
76		target.commit();
77		boot::stall(Duration::from_millis(10));
78	}
79
80	runtime::reset(ResetType::SHUTDOWN, Status::SUCCESS, None);
81}
Source

pub fn discard_changes(&mut self)

Discard any uncommitted changes when in double-buffered mode.

The damaged portion of the backbuffer will have its contents overwritten with the current state of the primary buffer, truly discarding any changes since the last commit.

Examples found in repository?
examples/double_buffered_framebuffer.rs (line 69)
21fn main() -> Status {
22	helpers::init().unwrap();
23
24	let handle =
25		boot::get_handle_for_protocol::<GraphicsOutput>().expect("Unable to get GOP handle");
26	let mut gop =
27		boot::open_protocol_exclusive::<GraphicsOutput>(handle).expect("Unable to open GOP handle");
28
29	let mode_800x600 = gop
30		.modes()
31		// one of the standard modes, although some systems may only provide 640×480
32		.find(|m| m.info().resolution() == (800, 600))
33		.expect("Unable to find 800x600 video mode");
34	gop.set_mode(&mode_800x600)
35		.expect("Couldn't switch to 800x600 video mode");
36
37	let mut target = FbDbDrawTarget::new(&mut gop);
38
39	let center = Point::new(400, 300);
40
41	let white_fill = PrimitiveStyle::with_fill(Rgb888::WHITE);
42	let (red_outline, green_outline, blue_outline) = {
43		let base = PrimitiveStyleBuilder::new().stroke_width(10);
44		(
45			base.stroke_color(Rgb888::RED).build(),
46			base.stroke_color(Rgb888::GREEN).build(),
47			base.stroke_color(Rgb888::BLUE).build(),
48		)
49	};
50
51	Circle::with_center(center, 500)
52		.into_styled(red_outline)
53		.draw(&mut target)
54		.expect("infallible");
55
56	Circle::with_center(center, 400)
57		.into_styled(green_outline)
58		.draw(&mut target)
59		.expect("infallible");
60
61	target.commit();
62
63	// Would cover circles
64	Rectangle::with_center(Point::new(50, 50), Size::new(700, 500))
65		.into_styled(white_fill)
66		.draw(&mut target)
67		.expect("infallible");
68
69	target.discard_changes();
70
71	Circle::with_center(center, 300)
72		.into_styled(blue_outline)
73		.draw(&mut target)
74		.expect("infallible");
75
76	// should auto-commit
77	drop(target);
78
79	boot::stall(Duration::from_secs(10));
80	runtime::reset(ResetType::SHUTDOWN, Status::SUCCESS, None);
81}
Source

pub fn discard_changes_no_reset(&mut self)

When in double-buffered mode, discard any uncommitted changes without resetting the backbuffer contents.

Note that this leaves the backbuffer untouched but marked as not needing to be transferred. This will make future drawing and committing very inconsistent and should likely only be used to discard changes prior to dropping the FbDbDrawTarget.

Source§

impl FbDbDrawTarget<'static>

Source

pub unsafe fn new_free_lifetime( protocol: &mut ScopedProtocol<GraphicsOutput>, ) -> Self

Equivalent to FbDbDrawTarget::new, but allows the FbDrawTarget to outlive the input ScopedProtocol.

See FbDrawTarget::new_free_lifetime for complete usage and safety information.

Trait Implementations§

Source§

impl<'proto> Debug for FbDbDrawTarget<'proto>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DrawTarget for FbDbDrawTarget<'_>

Source§

type Color = Rgb888

The pixel color type the targetted display supports.
Source§

type Error = Infallible

Error type to return when a drawing operation fails. Read more
Source§

fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where I: IntoIterator<Item = Pixel<Self::Color>>,

Draw individual pixels to the display without a defined order. Read more
Source§

fn fill_solid( &mut self, area: &Rectangle, color: Self::Color, ) -> Result<(), Self::Error>

Fill a given area with a solid color. Read more
Source§

fn fill_contiguous<I>( &mut self, area: &Rectangle, colors: I, ) -> Result<(), Self::Error>
where I: IntoIterator<Item = Self::Color>,

Fill a given area with an iterator providing a contiguous stream of pixel colors. Read more
Source§

fn clear(&mut self, color: Self::Color) -> Result<(), Self::Error>

Fill the entire display with a solid color. Read more
Source§

impl Drop for FbDbDrawTarget<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl OriginDimensions for FbDbDrawTarget<'_>

Source§

fn size(&self) -> Size

Returns the size of the bounding box.

Auto Trait Implementations§

§

impl<'proto> Freeze for FbDbDrawTarget<'proto>

§

impl<'proto> RefUnwindSafe for FbDbDrawTarget<'proto>

§

impl<'proto> !Send for FbDbDrawTarget<'proto>

§

impl<'proto> !Sync for FbDbDrawTarget<'proto>

§

impl<'proto> Unpin for FbDbDrawTarget<'proto>

§

impl<'proto> !UnwindSafe for FbDbDrawTarget<'proto>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> Dimensions for T

Source§

fn bounding_box(&self) -> Rectangle

Returns the bounding box.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.