From d094fd34dde4a5d34f385b216b1662296517744d Mon Sep 17 00:00:00 2001 From: Adrian Wells <23338636+adrianwells@users.noreply.github.com> Date: Wed, 2 Dec 2026 16:57:42 -0500 Subject: [PATCH 1/2] displayio: include vectorio members in a Group's previous area displayio_group_get_previous_area() only handled TileGrid and Group members. For a draw protocol member (vectorio shape, videocore buffer) neither branch ran and layer_area was used without being set, so when a Group containing vectorio shapes was removed from its parent, the shapes' area was not marked dirty and the shapes stayed on screen. Get the area from draw_get_dirty_area(), as _remove_layer() does for a direct draw protocol member, and skip any member that has no area instead of reading layer_area uninitialized. Fixes #12003 Co-Authored-By: Claude Opus 5.5 --- shared-module/displayio/legacy/Group.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/shared-module/displayio/legacy/Group.c b/shared-module/displayio/legacy/Group.c index ae0a01320f2..779c8ab959f 100644 --- a/shared-module/displayio/legacy/Group.c +++ b/shared-module/displayio/legacy/Group.c @@ -116,20 +116,30 @@ bool displayio_group_get_previous_area(displayio_group_t *self, displayio_area_t for (size_t i = 0; i < self->members->len; i++) { mp_obj_t layer; displayio_area_t layer_area; + bool has_area = false; layer = mp_obj_cast_to_native_base( self->members->items[i], &displayio_tilegrid_type); if (layer != MP_OBJ_NULL) { - if (!displayio_tilegrid_get_previous_area(layer, &layer_area)) { - continue; - } + has_area = displayio_tilegrid_get_previous_area(layer, &layer_area); } else { layer = mp_obj_cast_to_native_base( self->members->items[i], &displayio_group_type); if (layer != MP_OBJ_NULL) { - if (!displayio_group_get_previous_area(layer, &layer_area)) { - continue; + has_area = displayio_group_get_previous_area(layer, &layer_area); + } + #if CIRCUITPY_VECTORIO || CIRCUITPY_VIDEOCORE + else { + // Draw protocol layers (vectorio shapes, videocore buffers), as in _remove_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]); + has_area = draw_protocol->draw_protocol_impl->draw_get_dirty_area(layer, &layer_area); } } + #endif + } + if (!has_area) { + continue; } if (first) { displayio_area_copy(&layer_area, area); From 69f2e1c7c743e2bec37d8c0218a2afdc7bc175f7 Mon Sep 17 00:00:00 2001 From: Adrian Wells <23338636+adrianwells@users.noreply.github.com> Date: Thu, 3 Dec 2026 19:49:37 -0500 Subject: [PATCH 2/2] zephyr-cp: test removing a Group that holds vectorio shapes A Group with a Circle and a Rectangle is shown and then removed from the root group. The capture after the removal must show only the rectangle that stays in the root group. Without the previous commit the legacy compositor leaves the removed shapes on screen. Co-Authored-By: Claude Opus 5.5 --- ports/zephyr-cp/tests/test_vectorio.py | 93 ++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/ports/zephyr-cp/tests/test_vectorio.py b/ports/zephyr-cp/tests/test_vectorio.py index 657bbddef45..b31fb990882 100644 --- a/ports/zephyr-cp/tests/test_vectorio.py +++ b/ports/zephyr-cp/tests/test_vectorio.py @@ -294,6 +294,99 @@ def test_vectorio_move_and_hide(circuitpython): assert _pixel_at(after, 160, 45) == green +# A Group holding shapes is removed from its parent. The area of the shapes has +# to be redrawn without them (#12003). The rectangle that stays in the root +# group shows that the rest of the screen is kept. +REMOVE_GROUP_CODE = ( + _DISPLAY_HELPER + + """\ +import displayio +import time +import vectorio + +palette = displayio.Palette(4) +palette[0] = 0x000000 +palette[1] = 0xFF0000 +palette[2] = 0x00FF00 +palette[3] = 0x0000FF + +root = displayio.Group() + +kept = vectorio.Rectangle( + pixel_shader=palette, width=40, height=20, x=220, y=40, color_index=3 +) +root.append(kept) + +shapes = displayio.Group() +shapes.append( + vectorio.Circle(pixel_shader=palette, radius=20, x=40, y=40, color_index=1) +) +shapes.append( + vectorio.Rectangle( + pixel_shader=palette, width=40, height=20, x=100, y=40, color_index=2 + ) +) +root.append(shapes) + +display.auto_refresh = False +display.root_group = root +display.refresh() +print('shown') +time.sleep(5) +root.remove(shapes) +display.refresh() +print('removed') +while True: + time.sleep(1) +""" +) + + +@pytest.mark.circuitpy_drive({"code.py": REMOVE_GROUP_CODE}) +@pytest.mark.display(capture_times_ns=[4_000_000_000, 12_000_000_000]) +@pytest.mark.duration(16) +def test_vectorio_remove_group(circuitpython): + """Removing a Group that holds shapes clears the shapes from the screen.""" + circuitpython.wait_until_done() + + output = circuitpython.serial.all_output + assert "shown" in output + assert "removed" in output + + captures = circuitpython.display_capture_paths() + if len(captures) < 2 or not all(capture.exists() for capture in captures): + pytest.skip("display capture was not produced") + + with Image.open(captures[0]) as img: + before = img.convert("RGB") + with Image.open(captures[1]) as img: + after = img.convert("RGB") + + red = (255, 0, 0) + green = (0, 255, 0) + blue = (0, 0, 255) + black = (0, 0, 0) + + # The first capture is taken while the shapes are shown. + assert _pixel_at(before, 40, 40) == red + assert _pixel_at(before, 120, 50) == green + assert _pixel_at(before, 240, 50) == blue + + # After the removal only the rectangle in the root group is left. + expected = Image.new("RGB", after.size, black) + for y in range(40, 60): + for x in range(220, 260): + expected.putpixel((x, y), blue) + mismatches = [] + for y in range(after.height): + for x in range(after.width): + actual_pixel = after.getpixel((x, y)) + expected_pixel = expected.getpixel((x, y)) + if actual_pixel != expected_pixel: + mismatches.append((x, y, expected_pixel, actual_pixel)) + assert not mismatches, f"{len(mismatches)} pixels differ, first: {mismatches[:5]}" + + # Corner radius, outlines and the geometry that display_shapes needs. Both # compositors answer contains() from the same coverage test, so this is the same # on both even though they rasterize differently.