MCPcopy Index your code
hub / github.com/endbasic/endbasic / fill

Method fill

std/src/gfx/lcd/buffered/mod.rs:265–297  ·  view source on GitHub ↗

Fills the area contained between `x1y1` and `x2y2` (inclusive) with the current drawing color. If syncing is enabled, this writes directly to the LCD. Otherwise, this writes to the framebuffer and records the area as damaged.

(&mut self, x1y1: LcdXY, x2y2: LcdXY)

Source from the content-addressed store, hash-verified

263 /// If syncing is enabled, this writes directly to the LCD. Otherwise, this writes to the
264 /// framebuffer and records the area as damaged.
265 fn fill(&mut self, x1y1: LcdXY, x2y2: LcdXY) -> io::Result<()> {
266 // Prepare self.row_buffer with the content of every row to be copied to the framebuffer.
267 // We do this for efficiency reasons because manipulating individual pixels is costly.
268 let rowlen = {
269 let xlen = x2y2.x - x1y1.x + 1;
270 let rowlen = xlen * self.stride;
271 self.row_buffer.clear();
272 let color = self.draw_color.as_slice();
273 for _ in 0..xlen {
274 self.row_buffer.extend_from_slice(color);
275 }
276 debug_assert_eq!(rowlen, self.row_buffer.len());
277 rowlen
278 };
279
280 if self.sync {
281 let mut data = LcdSize::between(x1y1, x2y2).new_buffer(self.stride);
282 for y in x1y1.y..(x2y2.y + 1) {
283 let offset = self.fb_addr(x1y1.x, y);
284 self.fb[offset..offset + rowlen].copy_from_slice(&self.row_buffer);
285 data.extend(&self.row_buffer);
286 }
287 self.lcd.set_data(x1y1, x2y2, &data)?;
288 } else {
289 for y in x1y1.y..(x2y2.y + 1) {
290 let offset = self.fb_addr(x1y1.x, y);
291 self.fb[offset..offset + rowlen].copy_from_slice(&self.row_buffer);
292 }
293 self.damage(x1y1, x2y2);
294 }
295
296 Ok(())
297 }
298
299 /// Flushes any pending damaged area to the LCD.
300 fn force_present_canvas(&mut self) -> io::Result<()> {

Callers 15

clear_runtime_stateMethod · 0.80
clearMethod · 0.80
draw_pixelMethod · 0.80
draw_rect_filledMethod · 0.80
test_fill_one_pixel_syncFunction · 0.80
test_fill_rect_syncFunction · 0.80
test_fill_rect_no_syncFunction · 0.80
test_read_pixels_syncFunction · 0.80

Calls 6

new_bufferMethod · 0.80
fb_addrMethod · 0.80
damageMethod · 0.80
clearMethod · 0.45
as_sliceMethod · 0.45
set_dataMethod · 0.45

Tested by 9

test_fill_one_pixel_syncFunction · 0.64
test_fill_rect_syncFunction · 0.64
test_fill_rect_no_syncFunction · 0.64
test_read_pixels_syncFunction · 0.64
test_read_pixels_no_syncFunction · 0.64