@@ -49,10 +49,16 @@ void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t widt
49
49
self -> half_height = height ;
50
50
51
51
self -> data = m_malloc (height * sizeof (uint32_t ), false);
52
+ //for (uint16_t i = 0; i < height; i++) {
52
53
for (uint16_t i = 0 ; i <= height ; i ++ ) {
53
54
self -> data [2 * i ] = 0 ;
54
55
self -> data [2 * i + 1 ] = width ;
55
56
}
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 ;
56
62
}
57
63
58
64
void 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
66
72
if (self -> mirror_x && (start_x > half_width || end_x > half_width )) {
67
73
mp_raise_ValueError_varg (translate ("Maximum x value when mirrored is %d" ), half_width );
68
74
}
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
+
69
95
self -> data [2 * y ] = start_x ;
70
96
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
+
71
127
}
72
128
73
129
uint32_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) {
88
144
}
89
145
return 1 ;
90
146
}
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