summaryrefslogtreecommitdiff
path: root/shared-module/framebufferio/FramebufferDisplay.c
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-08-06 14:28:10 -0500
committerJeff Epler <jepler@gmail.com>2020-08-12 07:32:18 -0500
commita33e48c065093212729e620bb22da5ca327fabe4 (patch)
tree2d30bf5bee91eeb97eb90b593b3063a84abf9eba /shared-module/framebufferio/FramebufferDisplay.c
parent8021f3b4cbb96e0edaf139fa88ea7273c92a5493 (diff)
framebufferio: add "first pixel offset" and "row stride"
Diffstat (limited to 'shared-module/framebufferio/FramebufferDisplay.c')
-rw-r--r--shared-module/framebufferio/FramebufferDisplay.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/shared-module/framebufferio/FramebufferDisplay.c b/shared-module/framebufferio/FramebufferDisplay.c
index 190d3cb9d..e16777b83 100644
--- a/shared-module/framebufferio/FramebufferDisplay.c
+++ b/shared-module/framebufferio/FramebufferDisplay.c
@@ -70,6 +70,15 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
false // reverse_bytes_in_word
);
+ self->first_pixel_offset = self->framebuffer_protocol->get_first_pixel_offset
+ ? self->framebuffer_protocol->get_first_pixel_offset(self->framebuffer)
+ : 0;
+ self->row_stride = self->framebuffer_protocol->get_row_stride
+ ? self->framebuffer_protocol->get_row_stride(self->framebuffer)
+ : 0;
+ if (self->row_stride == 0) {
+ self->row_stride = self->core.width * self->core.colorspace.depth/8;
+ }
self->first_manual_refresh = !auto_refresh;
self->native_frames_per_second = self->framebuffer_protocol->get_native_frames_per_second(self->framebuffer);
@@ -209,11 +218,13 @@ STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const di
uint8_t *buf = (uint8_t *)self->bufinfo.buf, *endbuf = buf + self->bufinfo.len;
(void)endbuf; // Hint to compiler that endbuf is "used" even if NDEBUG
+ buf += self->first_pixel_offset;
- uint8_t *dest = self->bufinfo.buf + (subrectangle.y1 * self->core.width + subrectangle.x1) * self->core.colorspace.depth / 8;
+ size_t rowstride = self->row_stride;
+ uint8_t *dest = buf + subrectangle.y1 * rowstride + subrectangle.x1 * self->core.colorspace.depth / 8;
uint8_t *src = (uint8_t*)buffer;
size_t rowsize = (subrectangle.x2 - subrectangle.x1) * self->core.colorspace.depth / 8;
- size_t rowstride = self->core.width * self->core.colorspace.depth/8;
+
for (uint16_t i = subrectangle.y1; i < subrectangle.y2; i++) {
assert(dest >= buf && dest < endbuf && dest+rowsize <= endbuf);
memcpy(dest, src, rowsize);
@@ -230,9 +241,9 @@ STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const di
STATIC void _refresh_display(framebufferio_framebufferdisplay_obj_t* self) {
displayio_display_core_start_refresh(&self->core);
- self->framebuffer_protocol->get_bufinfo(self->framebuffer, &self->bufinfo);
const displayio_area_t* current_area = _get_refresh_areas(self);
if (current_area) {
+ self->framebuffer_protocol->get_bufinfo(self->framebuffer, &self->bufinfo);
while (current_area != NULL) {
_refresh_area(self, current_area);
current_area = current_area->next;