@@ -117,6 +117,7 @@ struct {
117
117
size_t crtc_index ;
118
118
struct gbm_bo * previous_bo ;
119
119
drmEventContext evctx ;
120
+ bool disable_vsync ;
120
121
} drm = {0 };
121
122
122
123
struct {
@@ -284,10 +285,19 @@ bool present(void* userdata) {
284
285
next_bo = gbm_surface_lock_front_buffer (gbm .surface );
285
286
fb = drm_fb_get_from_bo (next_bo );
286
287
287
- ok = drmModePageFlip (drm .fd , drm .crtc_id , fb -> fb_id , DRM_MODE_PAGE_FLIP_EVENT , drm .previous_bo );
288
- if (ok ) {
289
- perror ("failed to queue page flip" );
290
- return false;
288
+ // workaround for #38
289
+ if (!drm .disable_vsync ) {
290
+ ok = drmModePageFlip (drm .fd , drm .crtc_id , fb -> fb_id , DRM_MODE_PAGE_FLIP_EVENT , drm .previous_bo );
291
+ if (ok ) {
292
+ perror ("failed to queue page flip" );
293
+ return false;
294
+ }
295
+ } else {
296
+ ok = drmModeSetCrtc (drm .fd , drm .crtc_id , fb -> fb_id , 0 , 0 , & drm .connector_id , 1 , drm .mode );
297
+ if (ok == -1 ) {
298
+ perror ("failed swap buffers\n" );
299
+ return false;
300
+ }
291
301
}
292
302
293
303
gbm_surface_release_buffer (gbm .surface , drm .previous_bo );
@@ -1083,7 +1093,7 @@ void destroy_display(void) {
1083
1093
}
1084
1094
1085
1095
bool init_application (void ) {
1086
- int ok ;
1096
+ int ok , _errno ;
1087
1097
1088
1098
printf ("Initializing Plugin Registry...\n" );
1089
1099
ok = PluginRegistry_init ();
@@ -1130,16 +1140,21 @@ bool init_application(void) {
1130
1140
// only enable vsync if the kernel supplies valid vblank timestamps
1131
1141
uint64_t ns = 0 ;
1132
1142
ok = drmCrtcGetSequence (drm .fd , drm .crtc_id , NULL , & ns );
1133
- if (ok != 0 ) {
1134
- perror ("Could not get last VBlank timestamp. drmCrtcGetSequence" );
1135
- return false;
1136
- }
1143
+ if (ok != 0 ) _errno = errno ;
1137
1144
1138
- if (ns != 0 ) {
1145
+ if ((ok == 0 ) && (ns != 0 )) {
1146
+ drm .disable_vsync = false;
1139
1147
flutter .args .vsync_callback = vsync_callback ;
1140
1148
} else {
1149
+ drm .disable_vsync = true;
1150
+ if (ok != 0 ) {
1151
+ fprintf (stderr ,
1152
+ "WARNING: Could not get last vblank timestamp. %s" , strerror (_errno ));
1153
+ } else {
1154
+ fprintf (stderr ,
1155
+ "WARNING: Kernel didn't return a valid vblank timestamp. (timestamp == 0)\n" );
1156
+ }
1141
1157
fprintf (stderr ,
1142
- "WARNING: Kernel didn't return a valid vblank timestamp.\n"
1143
1158
" VSync will be disabled.\n"
1144
1159
" See https://github.com/ardera/flutter-pi/issues/38 for more info.\n" );
1145
1160
}
0 commit comments