Skip to content

Commit a3db1d5

Browse files
authored
Merge pull request #90 from ardera/develop
fix some issues
2 parents 43822ff + 35dcb4d commit a3db1d5

File tree

8 files changed

+456
-20
lines changed

8 files changed

+456
-20
lines changed

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
REAL_CFLAGS = -I./include $(shell pkg-config --cflags gbm libdrm glesv2 egl libsystemd libinput libudev) \
22
-DBUILD_TEXT_INPUT_PLUGIN \
3-
-DBUILD_GPIOD_PLUGIN \
4-
-DBUILD_SPIDEV_PLUGIN \
53
-DBUILD_TEST_PLUGIN \
64
-DBUILD_OMXPLAYER_VIDEO_PLAYER_PLUGIN \
75
-O0 -ggdb \

include/flutter-pi.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,25 @@ int flutterpi_fill_view_properties(
464464
int rotation
465465
);
466466

467+
int flutterpi_post_platform_task(
468+
int (*callback)(void *userdata),
469+
void *userdata
470+
);
471+
472+
int flutterpi_post_platform_task_with_time(
473+
int (*callback)(void *userdata),
474+
void *userdata,
475+
uint64_t target_time_usec
476+
);
477+
478+
int flutterpi_sd_event_add_io(
479+
sd_event_source **source_out,
480+
int fd,
481+
uint32_t events,
482+
sd_event_io_handler_t callback,
483+
void *userdata
484+
);
485+
467486
int flutterpi_send_platform_message(
468487
const char *channel,
469488
const uint8_t *restrict message,

include/modesetting.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,38 @@ int drmdev_configure(
8686
const drmModeModeInfo *mode
8787
);
8888

89+
int drmdev_plane_supports_setting_rotation_value(
90+
struct drmdev *drmdev,
91+
uint32_t plane_id,
92+
int drm_rotation,
93+
bool *result
94+
);
95+
96+
int drmdev_plane_get_min_zpos_value(
97+
struct drmdev *drmdev,
98+
uint32_t plane_id,
99+
int64_t *min_zpos_out
100+
);
101+
102+
int drmdev_plane_get_max_zpos_value(
103+
struct drmdev *drmdev,
104+
uint32_t plane_id,
105+
int64_t *max_zpos_out
106+
);
107+
108+
int drmdev_plane_supports_setting_zpos(
109+
struct drmdev *drmdev,
110+
uint32_t plane_id,
111+
bool *result
112+
);
113+
114+
int drmdev_plane_supports_setting_zpos_value(
115+
struct drmdev *drmdev,
116+
uint32_t plane_id,
117+
int64_t zpos,
118+
bool *result
119+
);
120+
89121
int drmdev_new_atomic_req(
90122
struct drmdev *drmdev,
91123
struct drmdev_atomic_req **req_out

src/compositor.c

Lines changed: 108 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ static int rendertarget_gbm_present(
351351
struct rendertarget_gbm *gbm_target;
352352
struct gbm_bo *next_front_bo;
353353
uint32_t next_front_fb_id;
354+
bool supported;
354355
int ok;
355356

356357
gbm_target = &target->gbm;
@@ -368,8 +369,41 @@ static int rendertarget_gbm_present(
368369
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "CRTC_Y", 0);
369370
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "CRTC_W", flutterpi.display.width);
370371
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "CRTC_H", flutterpi.display.height);
371-
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "rotation", DRM_MODE_ROTATE_0);
372-
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "zpos", zpos);
372+
373+
ok = drmdev_plane_supports_setting_rotation_value(atomic_req->drmdev, drm_plane_id, DRM_MODE_ROTATE_0, &supported);
374+
if (ok != 0) return ok;
375+
376+
if (supported) {
377+
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "rotation", DRM_MODE_ROTATE_0);
378+
} else {
379+
static bool printed = false;
380+
381+
if (!printed) {
382+
fprintf(stderr,
383+
"[compositor] GPU does not support reflecting the screen in Y-direction.\n"
384+
" This is required for rendering into hardware overlay planes though.\n"
385+
" Any UI that is drawn in overlay planes will look upside down.\n"
386+
);
387+
printed = true;
388+
}
389+
}
390+
391+
ok = drmdev_plane_supports_setting_zpos_value(atomic_req->drmdev, drm_plane_id, zpos, &supported);
392+
if (ok != 0) return ok;
393+
394+
if (supported) {
395+
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "zpos", zpos);
396+
} else {
397+
static bool printed = false;
398+
399+
if (!printed) {
400+
fprintf(stderr,
401+
"[compositor] GPU does not supported the desired HW plane order.\n"
402+
" Some UI layers may be invisible.\n"
403+
);
404+
printed = true;
405+
}
406+
}
373407

374408
// TODO: move this to the page flip handler.
375409
// We can only be sure the buffer can be released when the buffer swap
@@ -438,6 +472,7 @@ static int rendertarget_nogbm_present(
438472
int zpos
439473
) {
440474
struct rendertarget_nogbm *nogbm_target;
475+
bool supported;
441476
int ok;
442477

443478
nogbm_target = &target->nogbm;
@@ -456,8 +491,41 @@ static int rendertarget_nogbm_present(
456491
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "CRTC_Y", 0);
457492
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "CRTC_W", flutterpi.display.width);
458493
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "CRTC_H", flutterpi.display.height);
459-
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "rotation", DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y);
460-
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "zpos", zpos);
494+
495+
ok = drmdev_plane_supports_setting_rotation_value(req->drmdev, drm_plane_id, DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y, &supported);
496+
if (ok != 0) return ok;
497+
498+
if (supported) {
499+
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "rotation", DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y);
500+
} else {
501+
static bool printed = false;
502+
503+
if (!printed) {
504+
fprintf(stderr,
505+
"[compositor] GPU does not support reflecting the screen in Y-direction.\n"
506+
" This is required for rendering into hardware overlay planes though.\n"
507+
" Any UI that is drawn in overlay planes will look upside down.\n"
508+
);
509+
printed = true;
510+
}
511+
}
512+
513+
ok = drmdev_plane_supports_setting_zpos_value(req->drmdev, drm_plane_id, zpos, &supported);
514+
if (ok != 0) return ok;
515+
516+
if (supported) {
517+
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "zpos", zpos);
518+
} else {
519+
static bool printed = false;
520+
521+
if (!printed) {
522+
fprintf(stderr,
523+
"[compositor] GPU does not supported the desired HW plane order.\n"
524+
" Some UI layers may be invisible.\n"
525+
);
526+
printed = true;
527+
}
528+
}
461529

462530
return 0;
463531
}
@@ -709,10 +777,32 @@ static bool on_present_layers(
709777
ok = drmdev_atomic_req_put_modeset_props(req, &req_flags);
710778
if (ok != 0) return false;
711779

780+
int64_t max_zpos = 0;
781+
712782
for_each_unreserved_plane_in_atomic_req(req, plane) {
713783
if (plane->type == DRM_PLANE_TYPE_CURSOR) {
714784
// make sure the cursor is in front of everything
715-
drmdev_atomic_req_put_plane_property(req, plane->plane->plane_id, "zpos", 2);
785+
int64_t max_zpos;
786+
bool supported;
787+
788+
ok = drmdev_plane_get_max_zpos_value(req->drmdev, plane->plane->plane_id, &max_zpos);
789+
if (ok != 0) {
790+
printf("[compositor] Could not move cursor to front. Mouse cursor may be invisible. drmdev_plane_get_max_zpos_value: %s\n", strerror(ok));
791+
continue;
792+
}
793+
794+
ok = drmdev_plane_supports_setting_zpos_value(req->drmdev, plane->plane->plane_id, max_zpos, &supported);
795+
if (ok != 0) {
796+
printf("[compositor] Could not move cursor to front. Mouse cursor may be invisible. drmdev_plane_supports_setting_zpos_value: %s\n", strerror(ok));
797+
continue;
798+
}
799+
800+
if (supported) {
801+
drmdev_atomic_req_put_plane_property(req, plane->plane->plane_id, "zpos", max_zpos);
802+
} else {
803+
printf("[compositor] Could not move cursor to front. Mouse cursor may be invisible. drmdev_plane_supports_setting_zpos_value: %s\n", strerror(ok));
804+
continue;
805+
}
716806
}
717807
}
718808

@@ -865,6 +955,17 @@ static bool on_present_layers(
865955
}
866956
}
867957
}
958+
959+
int64_t min_zpos;
960+
for_each_unreserved_plane_in_atomic_req(req, plane) {
961+
if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
962+
ok = drmdev_plane_get_min_zpos_value(req->drmdev, plane->plane->plane_id, &min_zpos);
963+
if (ok != 0) {
964+
min_zpos = 0;
965+
}
966+
break;
967+
}
968+
}
868969

869970
for (int i = 0; i < layers_count; i++) {
870971
if (layers[i]->type == kFlutterLayerContentTypeBackingStore) {
@@ -899,7 +1000,7 @@ static bool on_present_layers(
8991000
0,
9001001
compositor->drmdev->selected_mode->hdisplay,
9011002
compositor->drmdev->selected_mode->vdisplay,
902-
plane->type == DRM_PLANE_TYPE_PRIMARY ? 0 : 1
1003+
i + min_zpos
9031004
);
9041005
if (ok != 0) {
9051006
fprintf(stderr, "[compositor] Could not present backing store. rendertarget->present: %s\n", strerror(ok));
@@ -917,7 +1018,7 @@ static bool on_present_layers(
9171018
(int) round(layers[i]->offset.y),
9181019
(int) round(layers[i]->size.width),
9191020
(int) round(layers[i]->size.height),
920-
i,
1021+
i + min_zpos,
9211022
cb_data->userdata
9221023
);
9231024
if (ok != 0) {
@@ -1003,8 +1104,6 @@ int compositor_remove_view_callbacks(int64_t view_id) {
10031104
return 0;
10041105
}
10051106

1006-
/// DRM HARDWARE PLANE RESERVATION
1007-
10081107
/// COMPOSITOR INITIALIZATION
10091108
int compositor_initialize(struct drmdev *drmdev) {
10101109
compositor.drmdev = drmdev;

src/flutter-pi.c

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ SEE ALSO:\n\
132132

133133
struct flutterpi flutterpi;
134134

135-
static int post_platform_task(
135+
/*static int flutterpi_post_platform_task(
136136
int (*callback)(void *userdata),
137137
void *userdata
138-
);
138+
);*/
139139

140140
static bool runs_platform_tasks_on_current_thread(void *userdata);
141141

@@ -442,7 +442,7 @@ static void on_frame_request(
442442
}
443443

444444
if (reply_instantly) {
445-
post_platform_task(
445+
flutterpi_post_platform_task(
446446
on_execute_frame_request,
447447
NULL
448448
);
@@ -480,7 +480,7 @@ static int on_execute_platform_task(
480480
return 0;
481481
}
482482

483-
static int post_platform_task(
483+
int flutterpi_post_platform_task(
484484
int (*callback)(void *userdata),
485485
void *userdata
486486
) {
@@ -558,7 +558,7 @@ static int on_execute_platform_task_with_time(
558558
return 0;
559559
}
560560

561-
static int post_platform_task_with_time(
561+
int flutterpi_post_platform_task_with_time(
562562
int (*callback)(void *userdata),
563563
void *userdata,
564564
uint64_t target_time_usec
@@ -621,6 +621,54 @@ static int post_platform_task_with_time(
621621
return ok;
622622
}
623623

624+
int flutterpi_sd_event_add_io(
625+
sd_event_source **source_out,
626+
int fd,
627+
uint32_t events,
628+
sd_event_io_handler_t callback,
629+
void *userdata
630+
) {
631+
int ok;
632+
633+
if (pthread_self() != flutterpi.event_loop_thread) {
634+
pthread_mutex_lock(&flutterpi.event_loop_mutex);
635+
}
636+
637+
ok = sd_event_add_io(
638+
flutterpi.event_loop,
639+
source_out,
640+
fd,
641+
events,
642+
callback,
643+
userdata
644+
);
645+
if (ok < 0) {
646+
fprintf(stderr, "[flutter-pi] Could not add IO callback to event loop. sd_event_add_io: %s\n", strerror(-ok));
647+
return -ok;
648+
}
649+
650+
if (pthread_self() != flutterpi.event_loop_thread) {
651+
ok = write(flutterpi.wakeup_event_loop_fd, (uint8_t[8]) {0, 0, 0, 0, 0, 0, 0, 1}, 8);
652+
if (ok < 0) {
653+
perror("[flutter-pi] Error arming main loop for io callback. write");
654+
ok = errno;
655+
goto fail_unlock_event_loop;
656+
}
657+
}
658+
659+
if (pthread_self() != flutterpi.event_loop_thread) {
660+
pthread_mutex_unlock(&flutterpi.event_loop_mutex);
661+
}
662+
663+
return 0;
664+
665+
666+
fail_unlock_event_loop:
667+
if (pthread_self() != flutterpi.event_loop_thread) {
668+
pthread_mutex_unlock(&flutterpi.event_loop_mutex);
669+
}
670+
}
671+
624672
/// flutter tasks
625673
static int on_execute_flutter_task(
626674
void *userdata
@@ -658,7 +706,7 @@ static void on_post_flutter_task(
658706

659707
*dup_task = task;
660708

661-
ok = post_platform_task_with_time(
709+
ok = flutterpi_post_platform_task_with_time(
662710
on_execute_flutter_task,
663711
dup_task,
664712
target_time / 1000
@@ -762,7 +810,7 @@ int flutterpi_send_platform_message(
762810
msg->message_size = 0;
763811
}
764812

765-
ok = post_platform_task(
813+
ok = flutterpi_post_platform_task(
766814
on_send_platform_message,
767815
msg
768816
);
@@ -819,7 +867,7 @@ int flutterpi_respond_to_platform_message(
819867
msg->message = 0;
820868
}
821869

822-
ok = post_platform_task(
870+
ok = flutterpi_post_platform_task(
823871
on_send_platform_message,
824872
msg
825873
);
@@ -987,6 +1035,7 @@ static void on_pageflip_event(
9871035

9881036
flutterpi.flutter.libflutter_engine.FlutterEngineTraceEventInstant("pageflip");
9891037

1038+
9901039
cqueue_lock(&flutterpi.frame_queue);
9911040

9921041
ok = cqueue_try_dequeue_locked(&flutterpi.frame_queue, &presented_frame);

0 commit comments

Comments
 (0)