Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9880703

Browse files
konkerschinmaygarde
authored andcommitted
[content handler] Fix waiting for GPU. (#3858)
Previously WaitForFirstDisplayDriver() would return, prematurely, on the first event in "/dev/class/display". This would cause apps started before the GPU driver came up to fall back on SW rendering.
1 parent 456d746 commit 9880703

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

content_handler/vulkan_rasterizer.cc

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,24 @@ namespace {
2424

2525
constexpr char kDisplayDriverClass[] = "/dev/class/display";
2626

27+
static mx_status_t DriverWatcher(int dirfd, int event, const char* fn, void* cookie) {
28+
if (event == WATCH_EVENT_ADD_FILE && !strcmp(fn, "000")) {
29+
return MX_ERR_STOP;
30+
}
31+
return MX_OK;
32+
}
33+
2734
bool WaitForFirstDisplayDriver() {
2835
ftl::UniqueFD fd(open(kDisplayDriverClass, O_DIRECTORY | O_RDONLY));
2936
if (fd.get() < 0) {
3037
FTL_DLOG(ERROR) << "Failed to open " << kDisplayDriverClass;
3138
return false;
3239
}
3340

34-
// Create the directory watch channel.
35-
vfs_watch_dir_t wd;
36-
wd.mask = VFS_WATCH_MASK_ALL;
37-
wd.options = 0;
38-
39-
mx::channel watcher;
40-
mx_status_t status = mx_channel_create(0, &wd.channel, watcher.reset_and_get_address());
41-
if (status != MX_OK) {
42-
FTL_DLOG(ERROR) << "Failed to create channel";
43-
return false;
44-
}
45-
46-
status = ioctl_vfs_watch_dir(fd.get(), &wd);
47-
if (status != MX_OK) {
48-
FTL_DLOG(ERROR) << "Failed to create directory watcher for "
49-
<< kDisplayDriverClass;
50-
return false;
51-
}
52-
53-
mx_signals_t pending;
54-
// Wait for 1 second for the display driver to appear before falling back to
55-
// software.
56-
status = watcher.wait_one(MX_CHANNEL_READABLE | MX_CHANNEL_PEER_CLOSED,
57-
mx_deadline_after(MX_SEC(1)), &pending);
58-
if (status != MX_OK) {
59-
FTL_DLOG(ERROR) << "Failed to wait on file watcher channel ";
60-
return false;
61-
}
62-
63-
return pending & MX_CHANNEL_READABLE;
41+
mx_status_t status = mxio_watch_directory(fd.get(), DriverWatcher,
42+
mx_deadline_after(MX_SEC(1)),
43+
nullptr);
44+
return status == MX_ERR_STOP;
6445
}
6546

6647
} // namespace

0 commit comments

Comments
 (0)