PDQ graphics benchmark · Round 1.28" touch watch
Showcase 7 - PDQ / TFT_eSPI-style graphics benchmark The classic "graphicstest_PDQ" suite, timed in microseconds per test: screen fill, text, lines, horizontal/vertical lines, rectangles (outline/filled), circles (filled/outline), triangles (outline/filled), rounded rectangles (outline/filled). Each test draws with LVGL's draw API into a full-screen canvas and pushes the frame to the panel (lv.refr_now), so a result = software rendering + SPI transfer of the whole 240x240 frame. That is directly comparable between firmware builds / display settings; it is NOT the same as TFT_eSPI writing primitives straight to the panel without a frame buffer.
You’ll learn: TFT_eSPI/PDQ test suite timed in microseconds
Board: Waveshare ESP32-S3-Touch-LCD-1.28 (ESP32-S3R2). Part of the kit’s Showcase and benchmarks. Needs the board’s LVGL firmware: flash it from the notebook’s Flash button, then press Open in Full IDE.
# Showcase 7 - PDQ / TFT_eSPI-style graphics benchmark
# The classic "graphicstest_PDQ" suite, timed in microseconds per test:
# screen fill, text, lines, horizontal/vertical lines, rectangles (outline/filled),
# circles (filled/outline), triangles (outline/filled), rounded rectangles (outline/filled).
#
# Each test draws with LVGL's draw API into a full-screen canvas and pushes the frame to the
# panel (lv.refr_now), so a result = software rendering + SPI transfer of the whole 240x240
# frame. That is directly comparable between firmware builds / display settings; it is NOT
# the same as TFT_eSPI writing primitives straight to the panel without a frame buffer.
import gc
import time
import lvgl as lv
import display
display.init() # start the display and touch (does nothing if already on)
BG = 0x05110A
TEXT = 0xE3EFE6
MUTED = 0x8EA999
ACCENT = 0x46E07C
def new_screen(bg=BG):
"""Load a fresh screen and delete the old one (and its running animations)."""
lv.anim_delete_all()
s = lv.obj()
s.set_style_bg_color(lv.color_hex(bg), 0)
s.remove_flag(lv.obj.FLAG.SCROLLABLE)
lv.screen_load_anim(s, lv.SCREEN_LOAD_ANIM.NONE, 0, 0, True)
return s
FONTS = {12: lv.font_montserrat_12, 14: lv.font_montserrat_14, 16: lv.font_montserrat_16}
def label(parent, text="", color=TEXT, font=16, align=lv.ALIGN.CENTER, x=0, y=0, zoom=0):
"""lv.label with a colour and a Montserrat 12/14/16 font. zoom=2 draws it twice as big."""
lb = lv.label(parent)
lb.set_text(text)
lb.set_style_text_color(lv.color_hex(color), 0)
lb.set_style_text_font(FONTS.get(font, lv.font_montserrat_16), 0)
if zoom:
lb.set_style_transform_scale(int(256 * zoom), 0) # 256 = 100 %
lb.update_layout()
lb.set_style_transform_pivot_x(lb.get_width() // 2, 0)
lb.set_style_transform_pivot_y(lb.get_height() // 2, 0)
lb.align(align, int(x), int(y))
return lb
W = H = 240
BLACK, WHITE = lv.color_hex(0x000000), lv.color_hex(0xFFFFFF)
PALETTE = [lv.color_hex(c) for c in (0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF)]
scr = new_screen(bg=0x000000)
buf = lv.draw_buf_create(W, H, lv.COLOR_FORMAT.RGB565, 0)
cv = lv.canvas(scr)
cv.set_draw_buf(buf)
cv.set_pos(0, 0)
layer = lv.layer_t()
rect = lv.draw_rect_dsc_t()
line = lv.draw_line_dsc_t()
arc = lv.draw_arc_dsc_t()
text = lv.draw_label_dsc_t()
tri = lv.draw_triangle_dsc_t()
TP = [lv.point_precise_t() for _ in range(3)]
def area(x1, y1, x2, y2):
a = lv.area_t()
a.x1, a.y1, a.x2, a.y2 = int(x1), int(y1), int(x2), int(y2)
return a
def frame(draw, clear=BLACK):
"""Clear, draw, push one full frame."""
cv.fill_bg(clear, lv.OPA.COVER)
cv.init_layer(layer)
draw()
cv.finish_layer(layer)
lv.refr_now(None)
def hline(x1, x2, y, c):
line.init(); line.color = c; line.width = 1
line.p1.x, line.p1.y, line.p2.x, line.p2.y = x1, y, x2, y
lv.draw_line(layer, line)
def seg(x1, y1, x2, y2, c):
line.init(); line.color = c; line.width = 1
line.p1.x, line.p1.y, line.p2.x, line.p2.y = x1, y1, x2, y2
lv.draw_line(layer, line)
def box(x, y, w, h, c, filled, radius=0):
rect.init()
rect.radius = radius
if filled:
rect.bg_color = c
rect.border_width = 0
else:
rect.bg_opa = 0
rect.border_width = 1
rect.border_color = c
lv.draw_rect(layer, rect, area(x, y, x + w - 1, y + h - 1))
def circle(x, y, r, c, filled):
if filled:
box(x - r, y - r, 2 * r + 1, 2 * r + 1, c, True, lv.RADIUS_CIRCLE)
else:
arc.init(); arc.color = c; arc.width = 1
arc.center.x, arc.center.y = x, y
arc.radius = r
arc.start_angle, arc.end_angle = 0, 360
lv.draw_arc(layer, arc)
def triangle(p, c, filled):
if filled:
tri.init(); tri.color = c
for dst, (x, y) in zip(TP, p):
dst.x, dst.y = x, y
tri.p = TP
lv.draw_triangle(layer, tri)
else:
(a, b, d) = p
seg(a[0], a[1], b[0], b[1], c); seg(b[0], b[1], d[0], d[1], c); seg(d[0], d[1], a[0], a[1], c)
# ------------------------------------------------------------------ the tests (PDQ shapes)
def t_fill():
for c in (lv.color_hex(0xFF0000), lv.color_hex(0x00FF00), lv.color_hex(0x0000FF), BLACK, WHITE):
cv.fill_bg(c, lv.OPA.COVER)
lv.refr_now(None)
def t_text():
def d():
text.init()
y = 20
for s, c in (("Hello World!", WHITE), ("1234.56", lv.color_hex(0xFFFF00)), ("0xDEADBEEF", lv.color_hex(0xFF0000)),
("Groop", lv.color_hex(0x00FF00)), ("I implore thee,", WHITE), ("my foonting turlingdromes.", WHITE),
("And hooptiously drangle me", WHITE), ("with crinkly bindlewurdles,", WHITE),
("Or I will rend thee", WHITE), ("in the gobberwarts", WHITE), ("with my blurglecruncheon,", WHITE),
("see if I don't!", WHITE)):
text.color = c
text.text = s
lv.draw_label(layer, text, area(30, y, 230, y + 16))
y += 16
frame(d)
def t_lines():
corners = ((0, 0), (W - 1, 0), (0, H - 1), (W - 1, H - 1))
for k, (x1, y1) in enumerate(corners):
def d(x1=x1, y1=y1):
c = PALETTE[k]
for x in range(0, W, 6):
seg(x1, y1, x, H - 1 - y1, c)
for y in range(0, H, 6):
seg(x1, y1, W - 1 - x1, y, c)
frame(d)
def t_fast_lines():
def d():
for y in range(0, H, 5):
hline(0, W - 1, y, lv.color_hex(0xFF0000))
for x in range(0, W, 5):
seg(x, 0, x, H - 1, lv.color_hex(0x0000FF))
frame(d)
def t_rects(filled):
def d():
n = min(W, H) // 2
for i in range(2 if filled else 2, n, 6):
box(W // 2 - i, H // 2 - i, i * 2, i * 2, lv.color_make(0, i * 2 % 256, 255 - i * 2 % 256) if filled else lv.color_hex(0x00FF00), filled)
frame(d)
def t_circles(filled, r=10):
def d():
for x in range(r, W, r * 2):
for y in range(r, H, r * 2):
circle(x, y, r, lv.color_hex(0xFF00FF) if filled else WHITE, filled)
frame(d)
def t_triangles(filled):
def d():
cx, cy = W // 2, H // 2
n = min(cx, cy)
for i in range(n, 0, -5):
c = lv.color_make(0, i * 10 % 256, i * 10 % 256) if filled else lv.color_make(i * 2 % 256, i * 2 % 256, 255)
triangle(((cx, cy - i), (cx - i, cy + i), (cx + i, cy + i)), c, filled)
frame(d)
def t_round_rects(filled):
def d():
cx, cy = W // 2, H // 2
for i in range(min(W, H) // 2 - 2, 20, -6):
box(cx - i, cy - i, i * 2, i * 2, lv.color_make(i % 256, 0, 0) if filled else lv.color_make(i % 256, 255, 0), filled, i // 8)
frame(d)
TESTS = [
("Screen fill", t_fill),
("Text", t_text),
("Lines", t_lines),
("Horiz/Vert Lines", t_fast_lines),
("Rectangles (outline)", lambda: t_rects(False)),
("Rectangles (filled)", lambda: t_rects(True)),
("Circles (filled)", lambda: t_circles(True)),
("Circles (outline)", lambda: t_circles(False)),
("Triangles (outline)", lambda: t_triangles(False)),
("Triangles (filled)", lambda: t_triangles(True)),
("Rounded rects (outline)", lambda: t_round_rects(False)),
("Rounded rects (filled)", lambda: t_round_rects(True)),
]
handler = display.handler
if handler:
handler.disable() # benchmark drives every frame itself
results = []
try:
lv.refr_now(None)
for name, fn in TESTS:
gc.collect()
t0 = time.ticks_us()
fn()
results.append((name, time.ticks_diff(time.ticks_us(), t0)))
time.sleep_ms(250) # let you see each test
finally:
if handler:
handler.enable()
total = sum(us for _, us in results)
print("\nBenchmark Time (microseconds)")
for name, us in results:
print("%-24s %10d" % (name, us))
print("%-24s %10d" % ("Total", total))
print("Waveshare ESP32-S3 1.28\" GC9A01 240x240, LVGL %d.%d, full-frame canvas + SPI push per test"
% (lv.version_major(), lv.version_minor()))
# ------------------------------------------------------------------ results on the watch
res = new_screen(bg=0x05110A)
label(res, "PDQ BENCHMARK (ms)", ACCENT, 12, y=-100)
tbl = lv.table(res)
tbl.set_column_count(2)
tbl.set_column_width(0, 132)
tbl.set_column_width(1, 52)
tbl.set_size(190, 160)
tbl.align(lv.ALIGN.CENTER, 0, 4)
tbl.set_style_text_font(lv.font_montserrat_12, lv.PART.ITEMS)
tbl.set_style_pad_ver(2, lv.PART.ITEMS)
tbl.set_style_pad_hor(4, lv.PART.ITEMS)
tbl.set_style_bg_opa(lv.OPA.TRANSP, 0)
tbl.set_style_border_width(0, 0)
for i, (name, us) in enumerate(results):
tbl.set_cell_value(i, 0, name)
tbl.set_cell_value(i, 1, "%.1f" % (us / 1000))
label(res, "total %.2f s - scroll the table" % (total / 1e6), MUTED, 12, y=96)
Comments