@@ -49,10 +49,16 @@ void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t widt
4949 self -> half_height = height ;
5050
5151 self -> data = m_malloc (height * sizeof (uint32_t ), false);
52+ //for (uint16_t i = 0; i < height; i++) {
5253 for (uint16_t i = 0 ; i <= height ; i ++ ) {
5354 self -> data [2 * i ] = 0 ;
5455 self -> data [2 * i + 1 ] = width ;
5556 }
57+
58+ self -> dirty_area .x1 = 0 ;
59+ self -> dirty_area .x2 = width ;
60+ self -> dirty_area .y1 = 0 ;
61+ self -> dirty_area .y2 = height ;
5662}
5763
5864void common_hal_displayio_shape_set_boundary (displayio_shape_t * self , uint16_t y , uint16_t start_x , uint16_t end_x ) {
@@ -66,8 +72,58 @@ void common_hal_displayio_shape_set_boundary(displayio_shape_t *self, uint16_t y
6672 if (self -> mirror_x && (start_x > half_width || end_x > half_width )) {
6773 mp_raise_ValueError_varg (translate ("Maximum x value when mirrored is %d" ), half_width );
6874 }
75+
76+ uint16_t lower_x , upper_x ;
77+
78+ // find x-boundaries for updating based on current data and start_x, end_x
79+ if (start_x < self -> data [2 * y ]) {
80+ lower_x = start_x ;
81+ } else {
82+ lower_x = self -> data [2 * y ];
83+ }
84+
85+ if (self -> mirror_x ) {
86+ upper_x = self -> width - lower_x ;
87+ } else {
88+ if (end_x > self -> data [2 * y + 1 ]) {
89+ upper_x = end_x + 1 ;
90+ } else {
91+ upper_x = self -> data [2 * y + 1 ] + 1 ;
92+ }
93+ }
94+
6995 self -> data [2 * y ] = start_x ;
7096 self -> data [2 * y + 1 ] = end_x ;
97+
98+ if (self -> dirty_area .x1 == self -> dirty_area .x2 ) { // Dirty region is empty
99+ self -> dirty_area .x1 = lower_x ;
100+ self -> dirty_area .x2 = upper_x ;
101+ self -> dirty_area .y1 = y ;
102+ if (self -> mirror_y ) {
103+ self -> dirty_area .y2 = self -> height - y ;
104+ } else {
105+ self -> dirty_area .y2 = y + 1 ;
106+ }
107+ } else { // Dirty region is not empty
108+ if (lower_x < self -> dirty_area .x1 ) {
109+ self -> dirty_area .x1 = lower_x ;
110+ }
111+ if (upper_x > self -> dirty_area .x2 ) {
112+ self -> dirty_area .x2 = upper_x ;
113+ }
114+ if (y < self -> dirty_area .y1 ) {
115+ self -> dirty_area .y1 = y ;
116+ if (self -> mirror_y ) { // if y is mirrored and the lower y was updated, the upper y must be updated too
117+ self -> dirty_area .y2 = self -> height - y ;
118+ }
119+ }
120+ else {
121+ if ( !self -> mirror_y && (y >= self -> dirty_area .y2 ) ) { // y is not mirrored
122+ self -> dirty_area .y2 = y + 1 ;
123+ }
124+ }
125+ }
126+
71127}
72128
73129uint32_t common_hal_displayio_shape_get_pixel (void * obj , int16_t x , int16_t y ) {
@@ -88,3 +144,21 @@ uint32_t common_hal_displayio_shape_get_pixel(void *obj, int16_t x, int16_t y) {
88144 }
89145 return 1 ;
90146}
147+
148+ displayio_area_t * displayio_shape_get_refresh_areas (displayio_shape_t * self , displayio_area_t * tail ) {
149+ if (self -> dirty_area .x1 == self -> dirty_area .x2 ) {
150+ return tail ;
151+ }
152+ self -> dirty_area .next = tail ;
153+ return & self -> dirty_area ;
154+ }
155+
156+ void displayio_shape_finish_refresh (displayio_shape_t * self ) {
157+ self -> dirty_area .x1 = 0 ;
158+ self -> dirty_area .x2 = 0 ;
159+ }
160+
161+
162+
163+
164+
0 commit comments