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)
| 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<()> { |