4545#include "frame_scheduler.h"
4646#include "keyboard.h"
4747#include "locales.h"
48- #include "modesetting .h"
48+ #include "kms/drmdev .h"
4949#include "pixel_format.h"
5050#include "platformchannel.h"
5151#include "pluginregistry.h"
@@ -1091,7 +1091,8 @@ static int on_drmdev_ready(sd_event_source *s, int fd, uint32_t revents, void *u
10911091 ASSERT_NOT_NULL (userdata );
10921092 drmdev = userdata ;
10931093
1094- return drmdev_on_event_fd_ready (drmdev );
1094+ drmdev_dispatch_modesetting (drmdev );
1095+ return 0 ;
10951096}
10961097
10971098static const FlutterLocale * on_compute_platform_resolved_locales (const FlutterLocale * * locales , size_t n_locales ) {
@@ -2114,74 +2115,7 @@ static void on_drmdev_close(int fd, void *fd_metadata, void *userdata) {
21142115 }
21152116}
21162117
2117- static const struct drmdev_interface drmdev_interface = { .open = on_drmdev_open , .close = on_drmdev_close };
2118-
2119- static struct drmdev * find_drmdev (struct libseat * libseat ) {
2120- struct drm_connector * connector ;
2121- struct drmdev * drmdev ;
2122- drmDevicePtr devices [64 ];
2123- int ok , n_devices ;
2124-
2125- #ifndef HAVE_LIBSEAT
2126- ASSERT_EQUALS (libseat , NULL );
2127- #endif
2128-
2129- ok = drmGetDevices2 (0 , devices , ARRAY_SIZE (devices ));
2130- if (ok < 0 ) {
2131- LOG_ERROR ("Could not query DRM device list: %s\n" , strerror (- ok ));
2132- return NULL ;
2133- }
2134-
2135- n_devices = ok ;
2136-
2137- // find a GPU that has a primary node
2138- drmdev = NULL ;
2139- for (int i = 0 ; i < n_devices ; i ++ ) {
2140- drmDevicePtr device ;
2141-
2142- device = devices [i ];
2143-
2144- if (!(device -> available_nodes & (1 << DRM_NODE_PRIMARY ))) {
2145- // We need a primary node.
2146- continue ;
2147- }
2148-
2149- drmdev = drmdev_new_from_path (device -> nodes [DRM_NODE_PRIMARY ], & drmdev_interface , libseat );
2150- if (drmdev == NULL ) {
2151- LOG_ERROR ("Could not create drmdev from device at \"%s\". Continuing.\n" , device -> nodes [DRM_NODE_PRIMARY ]);
2152- continue ;
2153- }
2154-
2155- for_each_connector_in_drmdev (drmdev , connector ) {
2156- if (connector -> variable_state .connection_state == kConnected_DrmConnectionState ) {
2157- goto found_connected_connector ;
2158- }
2159- }
2160- LOG_ERROR ("Device \"%s\" doesn't have a display connected. Skipping.\n" , device -> nodes [DRM_NODE_PRIMARY ]);
2161- drmdev_unref (drmdev );
2162- continue ;
2163-
2164- found_connected_connector :
2165- break ;
2166- }
2167-
2168- drmFreeDevices (devices , n_devices );
2169-
2170- if (drmdev == NULL ) {
2171- LOG_ERROR (
2172- "flutter-pi couldn't find a usable DRM device.\n"
2173- "Please make sure you've enabled the Fake-KMS driver in raspi-config.\n"
2174- "If you're not using a Raspberry Pi, please make sure there's KMS support for your graphics chip.\n"
2175- );
2176- goto fail_free_devices ;
2177- }
2178-
2179- return drmdev ;
2180-
2181- fail_free_devices :
2182- drmFreeDevices (devices , n_devices );
2183- return NULL ;
2184- }
2118+ static const struct drmdev_file_interface drmdev_interface = { .open = on_drmdev_open , .close = on_drmdev_close };
21852119
21862120static struct gbm_device * open_rendernode_as_gbm_device (void ) {
21872121 struct gbm_device * gbm ;
@@ -2332,7 +2266,6 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {
23322266 struct flutterpi_cmdline_args cmd_args ;
23332267 struct libseat * libseat ;
23342268 struct locales * locales ;
2335- struct drmdev * drmdev ;
23362269 struct tracer * tracer ;
23372270 struct window * window ;
23382271 void * engine_handle ;
@@ -2449,6 +2382,8 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {
24492382
24502383 locales_print (locales );
24512384
2385+ struct drmdev * drmdev = NULL ;
2386+ struct drm_resources * resources = NULL ;
24522387 if (cmd_args .dummy_display ) {
24532388 drmdev = NULL ;
24542389
@@ -2461,11 +2396,16 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {
24612396 goto fail_destroy_locales ;
24622397 }
24632398 } else {
2464- drmdev = find_drmdev (libseat );
2399+ // TODO: Share this udev instance with the one the user input uses.
2400+ struct udev * udev = udev_new ();
2401+
2402+ drmdev = drmdev_new_from_udev_primary (udev , "seat0" , & drmdev_interface , NULL );
24652403 if (drmdev == NULL ) {
24662404 goto fail_destroy_locales ;
24672405 }
24682406
2407+ udev_unref (udev );
2408+
24692409 gbm_device = drmdev_get_gbm_device (drmdev );
24702410 if (gbm_device == NULL ) {
24712411 LOG_ERROR ("Couldn't create GBM device.\n" );
@@ -2557,6 +2497,7 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {
25572497 cmd_args .has_physical_dimensions , cmd_args .physical_dimensions .x , cmd_args .physical_dimensions .y ,
25582498 cmd_args .has_pixel_format , cmd_args .pixel_format ,
25592499 drmdev ,
2500+ resources ,
25602501 desired_videomode
25612502 // clang-format on
25622503 );
@@ -2566,6 +2507,8 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {
25662507 }
25672508 }
25682509
2510+ drm_resources_unrefp (& resources );
2511+
25692512 compositor = compositor_new (tracer , window );
25702513 if (compositor == NULL ) {
25712514 LOG_ERROR ("Couldn't create compositor.\n" );
@@ -2574,7 +2517,7 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {
25742517
25752518 /// TODO: Do we really need the window after this?
25762519 if (drmdev != NULL ) {
2577- ok = sd_event_add_io (event_loop , NULL , drmdev_get_event_fd (drmdev ), EPOLLIN | EPOLLHUP | EPOLLPRI , on_drmdev_ready , drmdev );
2520+ ok = sd_event_add_io (event_loop , NULL , drmdev_get_modesetting_fd (drmdev ), EPOLLIN | EPOLLHUP | EPOLLPRI , on_drmdev_ready , drmdev );
25782521 if (ok < 0 ) {
25792522 LOG_ERROR ("Could not add DRM pageflip event listener. sd_event_add_io: %s\n" , strerror (- ok ));
25802523 goto fail_unref_compositor ;
@@ -2772,6 +2715,9 @@ struct flutterpi *flutterpi_new_from_args(int argc, char **argv) {
27722715 tracer_unref (tracer );
27732716
27742717fail_destroy_drmdev :
2718+ if (resources != NULL ) {
2719+ drm_resources_unref (resources );
2720+ }
27752721 drmdev_unref (drmdev );
27762722
27772723fail_destroy_locales :
0 commit comments