8000 Fix vectorio in group tracking · cezer-io/circuitpython@2601436 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2601436

Browse files
committed
Fix vectorio in group tracking
They have Group specific state so limit them to one group at a time. Fixes adafruit#10226
1 parent d0776d3 commit 2601436

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed

shared-bindings/vectorio/VectorShape.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ vectorio_draw_protocol_impl_t vectorio_vector_shape_draw_protocol_impl = {
8282
.draw_finish_refresh = (draw_finish_refresh_fun)vectorio_vector_shape_finish_refresh,
8383
.draw_get_refresh_areas = (draw_get_refresh_areas_fun)vectorio_vector_shape_get_refresh_areas,
8484
.draw_set_dirty = (draw_set_dirty_fun)common_hal_vectorio_vector_shape_set_dirty,
85+
.draw_set_in_group = (draw_set_in_group_fun)vectorio_vector_shape_set_in_group,
8586
};
8687

8788
// Stub checker does not approve of these shared properties.

shared-bindings/vectorio/VectorShape.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape
4343
void common_hal_vectorio_vector_shape_set_pixel_shader(vectorio_vector_shape_t *self, mp_obj_t pixel_shader);
4444

4545
void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displayio_buffer_transform_t *group_transform);
46+
bool vectorio_vector_shape_set_in_group(vectorio_vector_shape_t *self, bool in_group);
4647

4748
// Composable property definition for shapes that use VectorShape
4849
extern vectorio_draw_protocol_impl_t vectorio_vector_shape_draw_protocol_impl;

shared-bindings/vectorio/__init__.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef bool (*draw_get_dirty_area_fun)(mp_obj_t draw_protocol_self, displayio_a
2323
typedef void (*draw_update_transform_fun)(mp_obj_t draw_protocol_self, displayio_buffer_transform_t *group_transform);
2424
typedef void (*draw_finish_refresh_fun)(mp_obj_t draw_protocol_self);
2525
typedef void (*draw_set_dirty_fun)(mp_obj_t draw_protocol_self);
26+
typedef bool (*draw_set_in_group_fun)(mp_obj_t draw_protocol_self, bool in_group);
2627
typedef displayio_area_t *(*draw_get_refresh_areas_fun)(mp_obj_t draw_protocol_self, displayio_area_t *tail);
2728

2829
typedef struct _vectorio_draw_protocol_impl_t {
@@ -32,6 +33,7 @@ typedef struct _vectorio_draw_protocol_impl_t {
3233
draw_finish_refresh_fun draw_finish_refresh;
3334
draw_get_refresh_areas_fun draw_get_refresh_areas;
3435
draw_set_dirty_fun draw_set_dirty;
36+
draw_set_in_group_fun draw_set_in_group;
3537
} vectorio_draw_protocol_impl_t;
3638

3739
// Draw protocol

shared-module/displayio/Group.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ static void _add_layer(displayio_group_t *self, mp_obj_t layer) {
251251
#if CIRCUITPY_VECTORIO
252252
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, layer);
253253
if (draw_protocol != NULL) {
254-
draw_protocol->draw_protocol_impl->draw_update_transform(draw_protocol->draw_get_protocol_self(layer), &self->absolute_transform);
254+
mp_obj_t protocol_self = draw_protocol->draw_get_protocol_self(layer);
255+
if (draw_protocol->draw_protocol_impl->draw_set_in_group(protocol_self, true)) {
256+
mp_raise_ValueError(MP_ERROR_TEXT("Layer already in a group"));
257+
}
258+
draw_protocol->draw_protocol_impl->draw_update_transform(protocol_self, &self->absolute_transform);
255259
return;
256260
}
257261
#endif
@@ -296,6 +300,7 @@ static void _remove_layer(displayio_group_t *self, size_t index) {
296300
bool has_dirty_area = draw_protocol->draw_protocol_impl->draw_get_dirty_area(layer, &layer_area);
297301
rendered_last_frame = has_dirty_area;
298302
draw_protocol->draw_protocol_impl->draw_update_transform(layer, NULL);
303+
draw_protocol->draw_protocol_impl->draw_set_in_group(layer, false);
299304
}
300305
#endif
301306
layer = mp_obj_cast_to_native_base(

shared-module/vectorio/VectorShape.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,9 @@ void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displ
555555
self->absolute_transform = group_transform == NULL ? &null_transform : group_transform;
556556
common_hal_vectorio_vector_shape_set_dirty(self);
557557
}
558+
559+
bool vectorio_vector_shape_set_in_group(vectorio_vector_shape_t *self, bool in_group) {
560+
bool was_in_group = self->in_group;
561+
self->in_group = in_group;
562+
return was_in_group;
563+
}

shared-module/vectorio/VectorShape.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef struct {
4343
displayio_area_t current_area;
4444
bool current_area_dirty;
4545
bool hidden;
46+
bool in_group;
4647
} vectorio_vector_shape_t;
4748

4849
displayio_area_t *vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t *tail);

0 commit comments

Comments
 (0)
0