Skip to content

web VNC display mirror fix for FramebufferDisplay under LVGL - #11911

Merged
dhalbert merged 1 commit into
adafruit:mainfrom
FoamyGuy:lvgl_vnc_display_mirror_fix
Nov 18, 2026
Merged

dhalbert merged 1 commit into
adafruit:mainfrom
FoamyGuy:lvgl_vnc_display_mirror_fix

Conversation

@FoamyGuy

Copy link
Copy Markdown
Collaborator

This fixes an issue with the web/VNC display mirror under LVGL for FramebufferDisplay.

This reproducer code can be used to see the issue on a Metro P4 with 5" Pi Touch Display 2:

import binascii
import time

import board
import displayio
import supervisor
import vectorio

try:
    ROTATION
except NameError:
    ROTATION = 90
try:
    DUMP
except NameError:
    DUMP = False
STEPS = 5
STEP_S = 4
WAIT_S = 25       # after READY: a viewer's first full frame takes ~15 s over Wi-Fi
HOLD_S = 30


def make_display():
    d = supervisor.runtime.display
    if d is not None and hasattr(d, "framebuffer"):
        d.rotation = ROTATION
        return d
    import adafruit_ili9881
    import framebufferio
    import mipidsi
    displayio.release_displays()
    bus = mipidsi.Bus(minimum_frequency=adafruit_ili9881.RaspberryPiTouchDisplay2.MINIMUM_BUS_FREQUENCY,
                      num_lanes=2)
    panel = adafruit_ili9881.RaspberryPiTouchDisplay2(bus, board.I2C(), color_depth=16)
    d = framebufferio.FramebufferDisplay(panel, rotation=ROTATION, auto_refresh=False)
    supervisor.runtime.display = d
    return d


def rect(group, color, x, y, w, h):
    p = displayio.Palette(1)
    p[0] = color
    r = vectorio.Rectangle(pixel_shader=p, x=x, y=y, width=w, height=h)
    group.append(r)
    return r


display = make_display()
display.auto_refresh = False
W, H = display.width, display.height
print("display %dx%d rotation %d" % (W, H, display.rotation))
scene = displayio.Group()
rect(scene, 0x000000, 0, 0, W, H)
rect(scene, 0xFF0000, 0, 0, W // 4, H // 4)              # top left
rect(scene, 0x00FF00, W - W // 4, 0, W // 4, H // 4)     # top right
rect(scene, 0x0000FF, 0, H - H // 4, W // 4, H // 4)     # bottom left
M = 80
marker = rect(scene, 0xFFFFFF, 0, H // 2 - M // 2, M, M)
display.root_group = scene
print("READY")
display.refresh(target_frames_per_second=None)
time.sleep(WAIT_S)
for i in range(STEPS):
    marker.x = (2 * i + 1) * W // (2 * STEPS) - M // 2
    display.refresh(target_frames_per_second=None)
    print("STEP", i, marker.x, marker.y)
    time.sleep(STEP_S)

if DUMP:
    fb = display.framebuffer
    mv = memoryview(fb)
    FW, FH = fb.width, fb.height
    row = bytearray(FW)          # FW // 2 pixels, 2 bytes each (RGB565)
    print("DIM", FW // 2, FH // 2)
    for y in range(0, FH, 2):
        o = y * FW * 2
        for i in range(FW // 2):
            row[2 * i] = mv[o + 4 * i]
            row[2 * i + 1] = mv[o + 4 * i + 1]
        print("@R" + binascii.b2a_base64(row).decode().strip())
    print("END")
print("HOLD")
time.sleep(HOLD_S)
print("DONE")

Running on main it produces this display mirror:
Screenshot from 2026-11-18 15-26-25

With the fix it looks correct:
Screenshot from 2026-11-18 15-26-47

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tagging @tannewt on this:

I would hope that lvgl and classic displayio don't differ much on the internal API's. If they do maybe they should be made consistent. Here we are talking about off-by-one stuff and rotation or not.

@dhalbert
dhalbert requested a review from tannewt November 18, 2026 21:36

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt

tannewt commented Nov 18, 2026

Copy link
Copy Markdown
Member

tagging @tannewt on this:

I would hope that lvgl and classic displayio don't differ much on the internal API's. If they do maybe they should be made consistent. Here we are talking about off-by-one stuff and rotation or not.

I don't really want to make area consistent because I want it to be compositor native.

The rotation stuff can likely be changed in the LVGL implementation of framebuffer instead.

@dhalbert
dhalbert merged commit 5dbd293 into adafruit:main Nov 18, 2026
616 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants