Skip to content

Commit c68073e

Browse files
authored
Merge pull request adafruit#4331 from dhalbert/tilegrid-transpose-fix
Tilegrid transpose fix
2 parents 7970c88 + b126810 commit c68073e

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ jobs:
475475
id: idf-cache
476476
with:
477477
path: ${{ github.workspace }}/.idf_tools
478-
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210303
478+
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210304
479479
- name: Clone IDF submodules
480480
run: |
481481
(cd $IDF_PATH && git submodule update --init)

lib/tinyusb

Submodule tinyusb updated 218 files

shared-module/displayio/TileGrid.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_
7474
self->flip_x = false;
7575
self->flip_y = false;
7676
self->transpose_xy = false;
77+
self->absolute_transform = NULL;
7778
}
7879

7980

@@ -110,17 +111,24 @@ void _update_current_x(displayio_tilegrid_t *self) {
110111
} else {
111112
width = self->pixel_width;
112113
}
113-
if (self->absolute_transform->transpose_xy) {
114-
self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->x;
115-
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + width);
114+
115+
// If there's no transform, substitute an identity transform so the calculations will work.
116+
const displayio_buffer_transform_t* absolute_transform =
117+
self->absolute_transform == NULL
118+
? &null_transform
119+
: self->absolute_transform;
120+
121+
if (absolute_transform->transpose_xy) {
122+
self->current_area.y1 = absolute_transform->y + absolute_transform->dy * self->x;
123+
self->current_area.y2 = absolute_transform->y + absolute_transform->dy * (self->x + width);
116124
if (self->current_area.y2 < self->current_area.y1) {
117125
int16_t temp = self->current_area.y2;
118126
self->current_area.y2 = self->current_area.y1;
119127
self->current_area.y1 = temp;
120128
}
121129
} else {
122-
self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->x;
123-
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + width);
130+
self->current_area.x1 = absolute_transform->x + absolute_transform->dx * self->x;
131+
self->current_area.x2 = absolute_transform->x + absolute_transform->dx * (self->x + width);
124132
if (self->current_area.x2 < self->current_area.x1) {
125133
int16_t temp = self->current_area.x2;
126134
self->current_area.x2 = self->current_area.x1;
@@ -136,17 +144,24 @@ void _update_current_y(displayio_tilegrid_t *self) {
136144
} else {
137145
height = self->pixel_height;
138146
}
139-
if (self->absolute_transform->transpose_xy) {
140-
self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->y;
141-
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + height);
147+
148+
// If there's no transform, substitute an identity transform so the calculations will work.
149+
const displayio_buffer_transform_t* absolute_transform =
150+
self->absolute_transform == NULL
151+
? &null_transform
152+
: self->absolute_transform;
153+
154+
if (absolute_transform->transpose_xy) {
155+
self->current_area.x1 = absolute_transform->x + absolute_transform->dx * self->y;
156+
self->current_area.x2 = absolute_transform->x + absolute_transform->dx * (self->y + height);
142157
if (self->current_area.x2 < self->current_area.x1) {
143158
int16_t temp = self->current_area.x2;
144159
self->current_area.x2 = self->current_area.x1;
145160
self->current_area.x1 = temp;
146161
}
147162
} else {
148-
self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->y;
149-
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + height);
163+
self->current_area.y1 = absolute_transform->y + absolute_transform->dy * self->y;
164+
self->current_area.y2 = absolute_transform->y + absolute_transform->dy * (self->y + height);
150165
if (self->current_area.y2 < self->current_area.y1) {
151166
int16_t temp = self->current_area.y2;
152167
self->current_area.y2 = self->current_area.y1;

shared-module/displayio/__init__.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626

2727
primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];
2828

29+
displayio_buffer_transform_t null_transform = {
30+
.x = 0,
31+
.y = 0,
32+
.dx = 1,
33+
.dy = 1,
34+
.scale = 1,
35+
.width = 0,
36+
.height = 0,
37+
.mirror_x = false,
38+
.mirror_y = false,
39+
.transpose_xy = false
40+
};
41+
42+
2943
#if CIRCUITPY_RGBMATRIX
3044
STATIC bool any_display_uses_this_framebuffer(mp_obj_base_t *obj) {
3145
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {

shared-module/displayio/area.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ typedef struct {
5151
bool transpose_xy;
5252
} displayio_buffer_transform_t;
5353

54+
extern displayio_buffer_transform_t null_transform;
55+
5456
void displayio_area_union(const displayio_area_t* a,
5557
const displayio_area_t* b,
5658
displayio_area_t* u);

shared-module/vectorio/VectorShape.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,6 @@ void common_hal_vectorio_vector_shape_set_dirty(void *vector_shape) {
9393
}
9494

9595

96-
static displayio_buffer_transform_t null_transform = {
97-
.x = 0,
98-
.y = 0,
99-
.dx = 1,
100-
.dy = 1,
101-
.scale = 1,
102-
.width = 0,
103-
.height = 0,
104-
.mirror_x = false,
105-
.mirror_y = false,
106-
.transpose_xy = false
107-
};
108-
109-
11096
void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self,
11197
vectorio_ishape_t ishape,
11298
mp_obj_t pixel_shader, uint16_t x, uint16_t y) {

0 commit comments

Comments
 (0)