@@ -70,6 +70,15 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
7070 false // reverse_bytes_in_word
7171 );
7272
73+ self -> first_pixel_offset = self -> framebuffer_protocol -> get_first_pixel_offset
74+ ? self -> framebuffer_protocol -> get_first_pixel_offset (self -> framebuffer )
75+ : 0 ;
76+ self -> row_stride = self -> framebuffer_protocol -> get_row_stride
77+ ? self -> framebuffer_protocol -> get_row_stride (self -> framebuffer )
78+ : 0 ;
79+ if (self -> row_stride == 0 ) {
80+ self -> row_stride = self -> core .width * self -> core .colorspace .depth /8 ;
81+ }
7382 self -> first_manual_refresh = !auto_refresh ;
7483
7584 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
209218
210219 uint8_t * buf = (uint8_t * )self -> bufinfo .buf , * endbuf = buf + self -> bufinfo .len ;
211220 (void )endbuf ; // Hint to compiler that endbuf is "used" even if NDEBUG
221+ buf += self -> first_pixel_offset ;
212222
213- uint8_t * dest = self -> bufinfo .buf + (subrectangle .y1 * self -> core .width + subrectangle .x1 ) * self -> core .colorspace .depth / 8 ;
223+ size_t rowstride = self -> row_stride ;
224+ uint8_t * dest = buf + subrectangle .y1 * rowstride + subrectangle .x1 * self -> core .colorspace .depth / 8 ;
214225 uint8_t * src = (uint8_t * )buffer ;
215226 size_t rowsize = (subrectangle .x2 - subrectangle .x1 ) * self -> core .colorspace .depth / 8 ;
216- size_t rowstride = self -> core . width * self -> core . colorspace . depth / 8 ;
227+
217228 for (uint16_t i = subrectangle .y1 ; i < subrectangle .y2 ; i ++ ) {
218229 assert (dest >= buf && dest < endbuf && dest + rowsize <= endbuf );
219230 memcpy (dest , src , rowsize );
@@ -230,9 +241,9 @@ STATIC bool _refresh_area(framebufferio_framebufferdisplay_obj_t* self, const di
230241
231242STATIC void _refresh_display (framebufferio_framebufferdisplay_obj_t * self ) {
232243 displayio_display_core_start_refresh (& self -> core );
233- self -> framebuffer_protocol -> get_bufinfo (self -> framebuffer , & self -> bufinfo );
234244 const displayio_area_t * current_area = _get_refresh_areas (self );
235245 if (current_area ) {
246+ self -> framebuffer_protocol -> get_bufinfo (self -> framebuffer , & self -> bufinfo );
236247 while (current_area != NULL ) {
237248 _refresh_area (self , current_area );
238249 current_area = current_area -> next ;
0 commit comments