@@ -50,6 +50,7 @@ struct compositor compositor = {
50
50
.has_applied_modeset = false,
51
51
.should_create_window_surface_backing_store = true,
52
52
.stale_rendertargets = CPSET_INITIALIZER (CPSET_DEFAULT_MAX_SIZE ),
53
+ .do_blocking_atomic_commits = false
53
54
};
54
55
55
56
static struct view_cb_data * get_cbs_for_view_id_locked (int64_t view_id ) {
@@ -750,6 +751,31 @@ static bool on_create_backing_store(
750
751
return true;
751
752
}
752
753
754
+ struct simulated_page_flip_event_data {
755
+ unsigned int sec ;
756
+ unsigned int usec ;
757
+ };
758
+
759
+ extern void on_pageflip_event (
760
+ int fd ,
761
+ unsigned int frame ,
762
+ unsigned int sec ,
763
+ unsigned int usec ,
764
+ void * userdata
765
+ );
766
+
767
+ static int execute_simulate_page_flip_event (void * userdata ) {
768
+ struct simulated_page_flip_event_data * data ;
769
+
770
+ data = userdata ;
771
+
772
+ on_pageflip_event (flutterpi .drm .drmdev -> fd , 0 , data -> sec , data -> usec , NULL );
773
+
774
+ free (data );
775
+
776
+ return 0 ;
777
+ }
778
+
753
779
/// PRESENT FUNCS
754
780
static bool on_present_layers (
755
781
const FlutterLayer * * layers ,
@@ -772,7 +798,7 @@ static bool on_present_layers(
772
798
eglMakeCurrent (flutterpi .egl .display , flutterpi .egl .surface , flutterpi .egl .surface , flutterpi .egl .root_context );
773
799
eglSwapBuffers (flutterpi .egl .display , flutterpi .egl .surface );
774
800
775
- req_flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK ;
801
+ req_flags = 0 /* DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK*/ ;
776
802
if (compositor -> has_applied_modeset == false) {
777
803
ok = drmdev_atomic_req_put_modeset_props (req , & req_flags );
778
804
if (ok != 0 ) return false;
@@ -1036,11 +1062,42 @@ static bool on_present_layers(
1036
1062
}
1037
1063
1038
1064
eglMakeCurrent (flutterpi .egl .display , EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT );
1065
+
1066
+ do_commit :
1067
+ if (compositor -> do_blocking_atomic_commits ) {
1068
+ req_flags &= ~(DRM_MODE_ATOMIC_NONBLOCK | DRM_MODE_PAGE_FLIP_EVENT );
1069
+ } else {
1070
+ req_flags |= DRM_MODE_ATOMIC_NONBLOCK | DRM_MODE_PAGE_FLIP_EVENT ;
1071
+ }
1072
+
1073
+ ok = drmdev_atomic_req_commit (req , req_flags , NULL );
1074
+ if ((compositor -> do_blocking_atomic_commits == false) && (ok < 0 ) && (errno == EBUSY )) {
1075
+ printf ("[compositor] Non-blocking drmModeAtomicCommit failed with EBUSY.\n"
1076
+ " Future drmModeAtomicCommits will be executed blockingly.\n"
1077
+ " This may have have an impact on performance.\n" );
1078
+
1079
+ compositor -> do_blocking_atomic_commits = true;
1080
+ goto do_commit ;
1081
+ }
1039
1082
1040
- drmdev_atomic_req_commit (req , req_flags , NULL );
1041
- drmdev_destroy_atomic_req (req );
1083
+ if (compositor -> do_blocking_atomic_commits ) {
1084
+ uint64_t time = flutterpi .flutter .libflutter_engine .FlutterEngineGetCurrentTime ();
1085
+
1086
+ struct simulated_page_flip_event_data * data = malloc (sizeof (struct simulated_page_flip_event_data ));
1087
+ if (data == NULL ) {
1088
+ return false;
1089
+ }
1042
1090
1091
+ data -> sec = time / 1000000000llu ;
1092
+ data -> usec = (time % 1000000000llu ) / 1000 ;
1093
+
1094
+ flutterpi_post_platform_task (execute_simulate_page_flip_event , data );
1095
+ }
1096
+
1097
+ drmdev_destroy_atomic_req (req );
1043
1098
cpset_unlock (& compositor -> cbs );
1099
+
1100
+ return true;
1044
1101
}
1045
1102
1046
1103
int compositor_on_page_flip (
0 commit comments