Skip to content

Commit 9c4f644

Browse files
committed
framebufferio: add dirty row tracking
1 parent 5e4ed93 commit 9c4f644

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

shared-bindings/rgbmatrix/RGBMatrix.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ STATIC void rgbmatrix_rgbmatrix_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t *
352352

353353
// These version exists so that the prototype matches the protocol,
354354
// avoiding a type cast that can hide errors
355-
STATIC void rgbmatrix_rgbmatrix_swapbuffers(mp_obj_t self_in) {
355+
STATIC void rgbmatrix_rgbmatrix_swapbuffers(mp_obj_t self_in, uint8_t *dirty_row_bitmap) {
356+
(void)dirty_row_bitmap;
356357
common_hal_rgbmatrix_rgbmatrix_refresh(self_in);
357358
}
358359

shared-module/framebufferio/FramebufferDisplay.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ STATIC const displayio_area_t* _get_refresh_areas(framebufferio_framebufferdispl
156156
return NULL;
157157
}
158158

159-
STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const displayio_area_t* area) {
159+
#define MARK_ROW_DIRTY(r) (dirty_row_bitmask[r/8] = (1 << (r & 7)))
160+
STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const displayio_area_t* area, uint8_t *dirty_row_bitmask) {
160161
uint16_t buffer_size = 128; // In uint32_ts
161162

162163
displayio_area_t clipped;
@@ -235,6 +236,7 @@ STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const di
235236

236237
for (uint16_t i = subrectangle.y1; i < subrectangle.y2; i++) {
237238
assert(dest >= buf && dest < endbuf && dest+rowsize <= endbuf);
239+
MARK_ROW_DIRTY(i);
238240
memcpy(dest, src, rowsize);
239241
dest += rowstride;
240242
src += rowsize;
@@ -251,12 +253,14 @@ STATIC void _refresh_display(framebufferio_framebufferdisplay_obj_t* self) {
251253
displayio_display_core_start_refresh(&self->core);
252254
const displayio_area_t* current_area = _get_refresh_areas(self);
253255
if (current_area) {
256+
uint8_t dirty_row_bitmask[(self->core.height + 7) / 8];
257+
memset(dirty_row_bitmask, 0, sizeof(dirty_row_bitmask));
254258
self->framebuffer_protocol->get_bufinfo(self->framebuffer, &self->bufinfo);
255259
while (current_area != NULL) {
256-
_refresh_area(self, current_area);
260+
_refresh_area(self, current_area, dirty_row_bitmask);
257261
current_area = current_area->next;
258262
}
259-
self->framebuffer_protocol->swapbuffers(self->framebuffer);
263+
self->framebuffer_protocol->swapbuffers(self->framebuffer, dirty_row_bitmask);
260264
}
261265
displayio_display_core_finish_refresh(&self->core);
262266
}

shared-module/framebufferio/FramebufferDisplay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ typedef int (*framebuffer_get_width_fun)(mp_obj_t);
7979
typedef mp_float_t (*framebuffer_get_brightness_fun)(mp_obj_t);
8080
typedef void (*framebuffer_deinit_fun)(mp_obj_t);
8181
typedef void (*framebuffer_get_bufinfo_fun)(mp_obj_t, mp_buffer_info_t *bufinfo);
82-
typedef void (*framebuffer_swapbuffers_fun)(mp_obj_t);
82+
typedef void (*framebuffer_swapbuffers_fun)(mp_obj_t, uint8_t *dirty_row_bitmask);
8383

8484
typedef struct _framebuffer_p_t {
8585
MP_PROTOCOL_HEAD // MP_QSTR_protocol_framebuffer

0 commit comments

Comments
 (0)