From b6a5f421a9b7e3e27534a022c1642e83d7bffdb0 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 8 May 2022 12:02:59 -0500 Subject: [PATCH] use draw protocol impl --- shared-bindings/vectorio/VectorShape.c | 1 + shared-bindings/vectorio/__init__.h | 2 ++ shared-module/displayio/Group.c | 20 ++++---------------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/shared-bindings/vectorio/VectorShape.c b/shared-bindings/vectorio/VectorShape.c index fe6be555cd..6a3e192cb9 100644 --- a/shared-bindings/vectorio/VectorShape.c +++ b/shared-bindings/vectorio/VectorShape.c @@ -78,6 +78,7 @@ vectorio_draw_protocol_impl_t vectorio_vector_shape_draw_protocol_impl = { .draw_update_transform = (draw_update_transform_fun)vectorio_vector_shape_update_transform, .draw_finish_refresh = (draw_finish_refresh_fun)vectorio_vector_shape_finish_refresh, .draw_get_refresh_areas = (draw_get_refresh_areas_fun)vectorio_vector_shape_get_refresh_areas, + .draw_set_dirty = (draw_set_dirty_fun)common_hal_vectorio_vector_shape_set_dirty, }; // Stub checker does not approve of these shared properties. diff --git a/shared-bindings/vectorio/__init__.h b/shared-bindings/vectorio/__init__.h index a34195de26..d4f10c926c 100644 --- a/shared-bindings/vectorio/__init__.h +++ b/shared-bindings/vectorio/__init__.h @@ -17,6 +17,7 @@ typedef bool (*draw_fill_area_fun)(mp_obj_t draw_protocol_self, const _displayio typedef bool (*draw_get_dirty_area_fun)(mp_obj_t draw_protocol_self, displayio_area_t *current_dirty_area); typedef void (*draw_update_transform_fun)(mp_obj_t draw_protocol_self, displayio_buffer_transform_t *group_transform); typedef void (*draw_finish_refresh_fun)(mp_obj_t draw_protocol_self); +typedef void (*draw_set_dirty_fun)(mp_obj_t draw_protocol_self); typedef displayio_area_t *(*draw_get_refresh_areas_fun)(mp_obj_t draw_protocol_self, displayio_area_t *tail); typedef struct _vectorio_draw_protocol_impl_t { @@ -25,6 +26,7 @@ typedef struct _vectorio_draw_protocol_impl_t { draw_update_transform_fun draw_update_transform; draw_finish_refresh_fun draw_finish_refresh; draw_get_refresh_areas_fun draw_get_refresh_areas; + draw_set_dirty_fun draw_set_dirty; } vectorio_draw_protocol_impl_t; // Draw protocol diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index 21b4b2410f..40f34a8336 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -70,22 +70,10 @@ void common_hal_displayio_group_set_hidden(displayio_group_t *self, bool hidden) continue; } #if CIRCUITPY_VECTORIO - layer = mp_obj_cast_to_native_base( - self->members->items[i], &vectorio_circle_type); - if (layer != MP_OBJ_NULL) { - common_hal_vectorio_vector_shape_set_dirty(common_hal_vectorio_circle_get_draw_protocol(layer)); - continue; - } - layer = mp_obj_cast_to_native_base( - self->members->items[i], &vectorio_rectangle_type); - if (layer != MP_OBJ_NULL) { - common_hal_vectorio_vector_shape_set_dirty(common_hal_vectorio_rectangle_get_draw_protocol(layer)); - continue; - } - layer = mp_obj_cast_to_native_base( - self->members->items[i], &vectorio_polygon_type); - if (layer != MP_OBJ_NULL) { - common_hal_vectorio_vector_shape_set_dirty(common_hal_vectorio_polygon_get_draw_protocol(layer)); + const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, self->members->items[i]); + if (draw_protocol != NULL) { + layer = draw_protocol->draw_get_protocol_self(self->members->items[i]); + draw_protocol->draw_protocol_impl->draw_set_dirty(layer); continue; } #endif