Optimize draw_rgb565 display write speed by skipping slow synchronous canvas updates during raw video frames

This commit is contained in:
Adolfo Reyna
2026-06-19 13:38:25 -04:00
parent c8853cc5df
commit 30aff5eb8b
3 changed files with 23 additions and 5 deletions
+17 -1
View File
@@ -77,8 +77,11 @@ class MCPServer:
if self.sock is None:
return
t0 = 0
t1 = 0
try:
client, addr = self.sock.accept()
t0 = time.ticks_ms()
except OSError as e:
import errno
err = getattr(e, 'errno', None)
@@ -110,6 +113,7 @@ class MCPServer:
header_text = req_bytes[:header_end].decode('utf-8', 'ignore')
lines = header_text.split('\r\n')
t1 = time.ticks_ms()
if len(lines) == 0 or not lines[0]:
client.close()
return
@@ -171,6 +175,7 @@ class MCPServer:
if not chunk:
break
body_bytes.extend(chunk)
t2 = time.ticks_ms()
# Parse query parameters from path (e.g. /api/screen/raw?x=0&y=0&w=320&h=240)
width = getattr(self.display, 'width', 320)
@@ -186,10 +191,12 @@ class MCPServer:
elif k == 'y': y = int(v)
elif k == 'w': w = int(v)
elif k == 'h': h = int(v)
t3 = time.ticks_ms()
# Draw directly using display raw RGB565 method
self.override_active = True
self.display.draw_rgb565(x, y, w, h, body_bytes)
self.display.draw_rgb565(x, y, w, h, body_bytes, sync_canvas=False)
t4 = time.ticks_ms()
resp_body = "OK"
resp = "HTTP/1.1 200 OK\r\n"
@@ -206,6 +213,15 @@ class MCPServer:
time.sleep_ms(10)
continue
total_sent += sent
t5 = time.ticks_ms()
print("[RAW API Profile] total={}ms: accept_to_header={}ms, recv_body={}ms, route_n_prep={}ms, draw={}ms, send_resp={}ms".format(
time.ticks_diff(t5, t0),
time.ticks_diff(t1, t0),
time.ticks_diff(t2, t1),
time.ticks_diff(t3, t2),
time.ticks_diff(t4, t3),
time.ticks_diff(t5, t4)
))
else:
# Return 404
resp = "HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"