pub struct FbDbDrawTarget<'proto> { /* private fields */ }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>
impl<'proto> FbDbDrawTarget<'proto>
Sourcepub fn new(protocol: &'proto mut ScopedProtocol<GraphicsOutput>) -> Self
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?
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
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}Sourcepub fn commit(&mut self)
pub fn commit(&mut self)
Transfer the backbuffer contents to the primary buffer.
Examples found in repository?
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
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}Sourcepub fn discard_changes(&mut self)
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?
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}Sourcepub fn discard_changes_no_reset(&mut self)
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>
impl FbDbDrawTarget<'static>
Sourcepub unsafe fn new_free_lifetime(
protocol: &mut ScopedProtocol<GraphicsOutput>,
) -> Self
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.