Skip to content

Commit fe31c20

Browse files
committed
fix: restore daemon startup splash
1 parent 0b91e31 commit fe31c20

5 files changed

Lines changed: 290 additions & 15 deletions

File tree

‎Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ check:
2121
sh tests/test-usbdisplay-load.sh
2222
sh tests/test-package-deb.sh
2323
sh tests/test-splash-preview.sh
24+
sh tests/test-daemon-splash.sh
2425

2526
clean:
2627
$(MAKE) -C userspace BUILD_DIR=$(BUILD_DIR) clean

‎docs/architecture.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ alive even when fbdev or DRM has not published a new frame. Physical backends
5252
never replace the current framebuffer image with a daemon splash during
5353
reconnect; the latest fbdev snapshot is replayed when the stream is reopened.
5454

55+
Before the first application frame, an `INITIAL` update displays the existing
56+
USBDisplayStack `CONNECTED / WAITING FOR APPLICATION` startup splash, including
57+
on physical backends. The next fbdev or DRM update takes over immediately.
58+
Closing an application retains its last frame; restarting the transport does
59+
not replace that retained frame with the startup splash. This splash is drawn
60+
by the daemon's pixel renderer, independently of LVGL. Sending it still requires
61+
a working physical video session; it cannot replace the adapter's firmware page
62+
when the firmware has not accepted video.
63+
5564
The daemon publishes a readiness file after the backend opens. The file carries
5665
the live daemon PID, a positive transport `generation`, and `physical=1` only
5766
for a backend that owns a physical display transport; diagnostic backends

‎tests/test-daemon-splash.c‎

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#include <errno.h>
4+
#include <stdbool.h>
5+
#include <stdint.h>
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
#include <string.h>
9+
#include <unistd.h>
10+
11+
#define main usbdisplay_daemon_main
12+
#include "../userspace/usb-displayd.c"
13+
#undef main
14+
15+
struct capture_context {
16+
unsigned int expected_frames;
17+
unsigned int frames;
18+
struct usbdisplay_frame captured[3];
19+
unsigned char pixels[3][4096];
20+
};
21+
22+
static int capture_submit(void *opaque, const struct usbdisplay_frame *frame)
23+
{
24+
struct capture_context *context = opaque;
25+
unsigned int index = context->frames;
26+
int result = 0;
27+
28+
if (index >= 3U || frame->bytes > sizeof(context->pixels[index])) {
29+
result = -EOVERFLOW;
30+
} else {
31+
context->captured[index] = *frame;
32+
memcpy(context->pixels[index], frame->pixels, frame->bytes);
33+
context->captured[index].pixels = context->pixels[index];
34+
context->frames = index + 1U;
35+
if (context->frames >= context->expected_frames) {
36+
stop_requested = 1;
37+
}
38+
}
39+
40+
return result;
41+
}
42+
43+
static void capture_close(void *opaque)
44+
{
45+
(void)opaque;
46+
}
47+
48+
static const struct usbdisplay_backend_v1 capture_backend = {
49+
.abi_version = USBDISPLAY_BACKEND_ABI_VERSION,
50+
.struct_size = sizeof(struct usbdisplay_backend_v1),
51+
.capabilities = USBDISPLAY_BACKEND_CAP_PHYSICAL,
52+
.name = "test-capture",
53+
.submit = capture_submit,
54+
.close = capture_close,
55+
};
56+
57+
static const struct usbdisplay_backend_v1 diagnostic_backend = {
58+
.abi_version = USBDISPLAY_BACKEND_ABI_VERSION,
59+
.struct_size = sizeof(struct usbdisplay_backend_v1),
60+
.capabilities = USBDISPLAY_BACKEND_CAP_NONE,
61+
.name = "test-diagnostic",
62+
.submit = capture_submit,
63+
.close = capture_close,
64+
};
65+
66+
static void fill_update(struct usbdisplay_update *update, uint32_t source,
67+
uint64_t sequence)
68+
{
69+
memset(update, 0, sizeof(*update));
70+
update->sequence = sequence;
71+
update->timestamp_ns = sequence;
72+
update->slot = 0;
73+
update->width = 32U;
74+
update->height = 16U;
75+
update->stride = 32U * 4U;
76+
update->format = USBDISPLAY_FORMAT_XRGB8888;
77+
update->source = source;
78+
update->damage_width = update->width;
79+
update->damage_height = update->height;
80+
}
81+
82+
static int write_updates(int descriptor, const struct usbdisplay_update *updates,
83+
unsigned int count)
84+
{
85+
unsigned int index;
86+
ssize_t written;
87+
int result = 0;
88+
89+
for (index = 0; index < count && result == 0; ++index) {
90+
written = write(descriptor, &updates[index], sizeof(updates[index]));
91+
if (written != (ssize_t)sizeof(updates[index])) {
92+
result = -EIO;
93+
}
94+
}
95+
96+
return result;
97+
}
98+
99+
static int run_case(const struct usbdisplay_backend_v1 *backend,
100+
const struct usbdisplay_update *updates, unsigned int update_count,
101+
const unsigned char *mapping, size_t mapping_bytes,
102+
unsigned int expected_frames, struct capture_context *capture)
103+
{
104+
struct usbdisplay_device_info info;
105+
int descriptors[2] = {-1, -1};
106+
int result = 0;
107+
108+
memset(capture, 0, sizeof(*capture));
109+
capture->expected_frames = expected_frames;
110+
memset(&info, 0, sizeof(info));
111+
info.abi_version = USBDISPLAY_ABI_VERSION;
112+
info.width = 32U;
113+
info.height = 16U;
114+
info.slot_count = 3U;
115+
info.slot_bytes = 32U * 16U * 4U;
116+
info.map_bytes = info.slot_count * info.slot_bytes;
117+
if (mapping_bytes < info.map_bytes || pipe(descriptors) != 0) {
118+
result = -EIO;
119+
} else {
120+
stop_requested = 0;
121+
result = write_updates(descriptors[1], updates, update_count);
122+
if (result == 0) {
123+
close(descriptors[1]);
124+
descriptors[1] = -1;
125+
result = run_loop(descriptors[0], &info, mapping, backend, capture);
126+
}
127+
}
128+
if (descriptors[0] >= 0) {
129+
close(descriptors[0]);
130+
}
131+
if (descriptors[1] >= 0) {
132+
close(descriptors[1]);
133+
}
134+
135+
return result;
136+
}
137+
138+
static bool frame_matches(const struct usbdisplay_frame *frame,
139+
const unsigned char *expected, size_t bytes)
140+
{
141+
return frame->bytes == bytes &&
142+
memcmp((const unsigned char *)frame->pixels, expected, bytes) == 0;
143+
}
144+
145+
static int test_cases(void)
146+
{
147+
unsigned char mapping[3U * 32U * 16U * 4U];
148+
uint32_t splash[32U * 16U];
149+
struct usbdisplay_update updates[2];
150+
struct capture_context capture;
151+
const struct usbdisplay_backend_v1 *backend;
152+
size_t splash_bytes;
153+
int result = 0;
154+
unsigned int index;
155+
156+
for (index = 0; index < sizeof(mapping); ++index) {
157+
mapping[index] = (unsigned char)((index * 37U + 11U) & 0xffU);
158+
}
159+
splash_bytes = usbdisplay_splash_bytes(32U, 16U);
160+
if (splash_bytes != sizeof(splash) ||
161+
usbdisplay_splash_render((uint32_t *)splash, 32U, 16U, 32U * 4U) != 0) {
162+
result = -EINVAL;
163+
}
164+
165+
if (result == 0) {
166+
fill_update(&updates[0], USBDISPLAY_SOURCE_INITIAL, 1U);
167+
backend = &capture_backend;
168+
result = run_case(backend, updates, 1U, mapping, sizeof(mapping), 1U,
169+
&capture);
170+
if (result == 0 && (capture.frames != 1U ||
171+
capture.captured[0].source != USBDISPLAY_SOURCE_INITIAL ||
172+
!frame_matches(&capture.captured[0], (const unsigned char *)splash,
173+
splash_bytes))) {
174+
result = -EINVAL;
175+
}
176+
}
177+
178+
if (result == 0) {
179+
fill_update(&updates[0], USBDISPLAY_SOURCE_INITIAL, 2U);
180+
fill_update(&updates[1], USBDISPLAY_SOURCE_FBDEV, 3U);
181+
result = run_case(&capture_backend, updates, 2U, mapping,
182+
sizeof(mapping), 2U, &capture);
183+
if (result == 0 && (capture.frames != 2U ||
184+
capture.captured[1].source != USBDISPLAY_SOURCE_FBDEV ||
185+
!frame_matches(&capture.captured[1], mapping,
186+
32U * 16U * 4U))) {
187+
result = -EINVAL;
188+
}
189+
}
190+
191+
if (result == 0) {
192+
fill_update(&updates[0], USBDISPLAY_SOURCE_DRM, 4U);
193+
result = run_case(&capture_backend, updates, 1U, mapping,
194+
sizeof(mapping), 1U, &capture);
195+
if (result == 0 && (capture.frames != 1U ||
196+
capture.captured[0].source != USBDISPLAY_SOURCE_DRM ||
197+
!frame_matches(&capture.captured[0], mapping,
198+
32U * 16U * 4U))) {
199+
result = -EINVAL;
200+
}
201+
}
202+
203+
if (result == 0) {
204+
fill_update(&updates[0], USBDISPLAY_SOURCE_FBDEV, 5U);
205+
result = run_case(&capture_backend, updates, 1U, mapping,
206+
sizeof(mapping), 1U, &capture);
207+
if (result == 0 && (capture.frames != 1U ||
208+
capture.captured[0].source != USBDISPLAY_SOURCE_FBDEV ||
209+
!frame_matches(&capture.captured[0], mapping,
210+
32U * 16U * 4U))) {
211+
result = -EINVAL;
212+
}
213+
}
214+
215+
if (result == 0) {
216+
fill_update(&updates[0], USBDISPLAY_SOURCE_INITIAL, 6U);
217+
result = run_case(&diagnostic_backend, updates, 1U, mapping,
218+
sizeof(mapping), 1U, &capture);
219+
if (result == 0 && (capture.frames != 1U ||
220+
!frame_matches(&capture.captured[0], (const unsigned char *)splash,
221+
splash_bytes))) {
222+
result = -EINVAL;
223+
}
224+
}
225+
226+
return result;
227+
}
228+
229+
int main(void)
230+
{
231+
int result = test_cases();
232+
233+
if (result != 0) {
234+
fprintf(stderr, "daemon splash runtime test failed: %d\n", result);
235+
} else {
236+
printf("daemon splash runtime tests passed\n");
237+
}
238+
239+
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
240+
}

‎tests/test-daemon-splash.sh‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0-only
3+
4+
set -eu
5+
6+
project_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
7+
compiler=${CC:-cc}
8+
temp_dir=$(mktemp -d "${TMPDIR:-/tmp}/usbdisplay-daemon-splash.XXXXXX")
9+
binary=$temp_dir/test-daemon-splash
10+
11+
cleanup()
12+
{
13+
rm -rf -- "$temp_dir"
14+
}
15+
trap cleanup EXIT HUP INT TERM
16+
17+
compiler_path=$(command -v "$compiler")
18+
[ -x "$compiler_path" ]
19+
"$compiler_path" -I"$project_dir/include" -I"$project_dir/userspace" \
20+
-std=gnu11 -Wall -Wextra -Werror -finput-charset=GBK \
21+
-DUSBDISPLAY_VERSION='"runtime-test"' \
22+
"$project_dir/tests/test-daemon-splash.c" \
23+
"$project_dir/userspace/splash.c" -o "$binary" -ldl -lrt
24+
timeout 10s "$binary"

‎userspace/usb-displayd.c‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,19 +287,17 @@ static int run_loop(int device_fd, const struct usbdisplay_device_info *info,
287287
USBDISPLAY_BACKEND_CAP_PHYSICAL) != 0;
288288
int result = 0;
289289

290-
/* Physical output must preserve the current fb1 image during reconnects. */
291-
if (!physical_backend) {
292-
splash_bytes = usbdisplay_splash_bytes(info->width, info->height);
293-
if (splash_bytes == 0) {
294-
result = -EOVERFLOW;
290+
/* Only INITIAL uses the startup splash; retained application frames win. */
291+
splash_bytes = usbdisplay_splash_bytes(info->width, info->height);
292+
if (splash_bytes == 0) {
293+
result = -EOVERFLOW;
294+
} else {
295+
splash_pixels = malloc(splash_bytes);
296+
if (splash_pixels == NULL) {
297+
result = -ENOMEM;
295298
} else {
296-
splash_pixels = malloc(splash_bytes);
297-
if (splash_pixels == NULL) {
298-
result = -ENOMEM;
299-
} else {
300-
result = usbdisplay_splash_render(splash_pixels, info->width,
301-
info->height, info->width * 4U);
302-
}
299+
result = usbdisplay_splash_render(splash_pixels, info->width,
300+
info->height, info->width * 4U);
303301
}
304302
}
305303
descriptor.fd = device_fd;
@@ -321,9 +319,7 @@ static int run_loop(int device_fd, const struct usbdisplay_device_info *info,
321319
result = -EPROTO;
322320
} else {
323321
result = validate_update(info, &update);
324-
if (result == 0 &&
325-
(update.source != USBDISPLAY_SOURCE_INITIAL ||
326-
!physical_backend)) {
322+
if (result == 0) {
327323
memset(&frame, 0, sizeof(frame));
328324
frame.struct_size = sizeof(frame);
329325
if (update.source == USBDISPLAY_SOURCE_INITIAL) {
@@ -353,6 +349,11 @@ static int run_loop(int device_fd, const struct usbdisplay_device_info *info,
353349
frame.source = update.source;
354350
result = backend->submit(backend_context, &frame);
355351
if (result == 0) {
352+
if (!frame_valid && update.source ==
353+
USBDISPLAY_SOURCE_INITIAL) {
354+
fprintf(stderr,
355+
"usb-displayd: startup splash submitted to backend\n");
356+
}
356357
frame_valid = true;
357358
last_submit_ns = monotonic_nanoseconds();
358359
}

0 commit comments

Comments
 (0)