Skip to content

fix some issues #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
REAL_CFLAGS = -I./include $(shell pkg-config --cflags gbm libdrm glesv2 egl libsystemd libinput libudev) \
-DBUILD_TEXT_INPUT_PLUGIN \
-DBUILD_GPIOD_PLUGIN \
-DBUILD_SPIDEV_PLUGIN \
-DBUILD_TEST_PLUGIN \
-DBUILD_OMXPLAYER_VIDEO_PLAYER_PLUGIN \
-O0 -ggdb \
Expand Down
19 changes: 19 additions & 0 deletions include/flutter-pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,25 @@ int flutterpi_fill_view_properties(
int rotation
);

int flutterpi_post_platform_task(
int (*callback)(void *userdata),
void *userdata
);

int flutterpi_post_platform_task_with_time(
int (*callback)(void *userdata),
void *userdata,
uint64_t target_time_usec
);

int flutterpi_sd_event_add_io(
sd_event_source **source_out,
int fd,
uint32_t events,
sd_event_io_handler_t callback,
void *userdata
);

int flutterpi_send_platform_message(
const char *channel,
const uint8_t *restrict message,
Expand Down
32 changes: 32 additions & 0 deletions include/modesetting.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,38 @@ int drmdev_configure(
const drmModeModeInfo *mode
);

int drmdev_plane_supports_setting_rotation_value(
struct drmdev *drmdev,
uint32_t plane_id,
int drm_rotation,
bool *result
);

int drmdev_plane_get_min_zpos_value(
struct drmdev *drmdev,
uint32_t plane_id,
int64_t *min_zpos_out
);

int drmdev_plane_get_max_zpos_value(
struct drmdev *drmdev,
uint32_t plane_id,
int64_t *max_zpos_out
);

int drmdev_plane_supports_setting_zpos(
struct drmdev *drmdev,
uint32_t plane_id,
bool *result
);

int drmdev_plane_supports_setting_zpos_value(
struct drmdev *drmdev,
uint32_t plane_id,
int64_t zpos,
bool *result
);

int drmdev_new_atomic_req(
struct drmdev *drmdev,
struct drmdev_atomic_req **req_out
Expand Down
117 changes: 108 additions & 9 deletions src/compositor.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ static int rendertarget_gbm_present(
struct rendertarget_gbm *gbm_target;
struct gbm_bo *next_front_bo;
uint32_t next_front_fb_id;
bool supported;
int ok;

gbm_target = &target->gbm;
Expand All @@ -368,8 +369,41 @@ static int rendertarget_gbm_present(
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "CRTC_Y", 0);
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "CRTC_W", flutterpi.display.width);
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "CRTC_H", flutterpi.display.height);
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "rotation", DRM_MODE_ROTATE_0);
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "zpos", zpos);

ok = drmdev_plane_supports_setting_rotation_value(atomic_req->drmdev, drm_plane_id, DRM_MODE_ROTATE_0, &supported);
if (ok != 0) return ok;

if (supported) {
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "rotation", DRM_MODE_ROTATE_0);
} else {
static bool printed = false;

if (!printed) {
fprintf(stderr,
"[compositor] GPU does not support reflecting the screen in Y-direction.\n"
" This is required for rendering into hardware overlay planes though.\n"
" Any UI that is drawn in overlay planes will look upside down.\n"
);
printed = true;
}
}

ok = drmdev_plane_supports_setting_zpos_value(atomic_req->drmdev, drm_plane_id, zpos, &supported);
if (ok != 0) return ok;

if (supported) {
drmdev_atomic_req_put_plane_property(atomic_req, drm_plane_id, "zpos", zpos);
} else {
static bool printed = false;

if (!printed) {
fprintf(stderr,
"[compositor] GPU does not supported the desired HW plane order.\n"
" Some UI layers may be invisible.\n"
);
printed = true;
}
}

// TODO: move this to the page flip handler.
// We can only be sure the buffer can be released when the buffer swap
Expand Down Expand Up @@ -438,6 +472,7 @@ static int rendertarget_nogbm_present(
int zpos
) {
struct rendertarget_nogbm *nogbm_target;
bool supported;
int ok;

nogbm_target = &target->nogbm;
Expand All @@ -456,8 +491,41 @@ static int rendertarget_nogbm_present(
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "CRTC_Y", 0);
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "CRTC_W", flutterpi.display.width);
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "CRTC_H", flutterpi.display.height);
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "rotation", DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y);
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "zpos", zpos);

ok = drmdev_plane_supports_setting_rotation_value(req->drmdev, drm_plane_id, DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y, &supported);
if (ok != 0) return ok;

if (supported) {
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "rotation", DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_Y);
} else {
static bool printed = false;

if (!printed) {
fprintf(stderr,
"[compositor] GPU does not support reflecting the screen in Y-direction.\n"
" This is required for rendering into hardware overlay planes though.\n"
" Any UI that is drawn in overlay planes will look upside down.\n"
);
printed = true;
}
}

ok = drmdev_plane_supports_setting_zpos_value(req->drmdev, drm_plane_id, zpos, &supported);
if (ok != 0) return ok;

if (supported) {
drmdev_atomic_req_put_plane_property(req, drm_plane_id, "zpos", zpos);
} else {
static bool printed = false;

if (!printed) {
fprintf(stderr,
"[compositor] GPU does not supported the desired HW plane order.\n"
" Some UI layers may be invisible.\n"
);
printed = true;
}
}

return 0;
}
Expand Down Expand Up @@ -709,10 +777,32 @@ static bool on_present_layers(
ok = drmdev_atomic_req_put_modeset_props(req, &req_flags);
if (ok != 0) return false;

int64_t max_zpos = 0;

for_each_unreserved_plane_in_atomic_req(req, plane) {
if (plane->type == DRM_PLANE_TYPE_CURSOR) {
// make sure the cursor is in front of everything
drmdev_atomic_req_put_plane_property(req, plane->plane->plane_id, "zpos", 2);
int64_t max_zpos;
bool supported;

ok = drmdev_plane_get_max_zpos_value(req->drmdev, plane->plane->plane_id, &max_zpos);
if (ok != 0) {
printf("[compositor] Could not move cursor to front. Mouse cursor may be invisible. drmdev_plane_get_max_zpos_value: %s\n", strerror(ok));
continue;
}

ok = drmdev_plane_supports_setting_zpos_value(req->drmdev, plane->plane->plane_id, max_zpos, &supported);
if (ok != 0) {
printf("[compositor] Could not move cursor to front. Mouse cursor may be invisible. drmdev_plane_supports_setting_zpos_value: %s\n", strerror(ok));
continue;
}

if (supported) {
drmdev_atomic_req_put_plane_property(req, plane->plane->plane_id, "zpos", max_zpos);
} else {
printf("[compositor] Could not move cursor to front. Mouse cursor may be invisible. drmdev_plane_supports_setting_zpos_value: %s\n", strerror(ok));
continue;
}
}
}

Expand Down Expand Up @@ -865,6 +955,17 @@ static bool on_present_layers(
}
}
}

int64_t min_zpos;
for_each_unreserved_plane_in_atomic_req(req, plane) {
if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
ok = drmdev_plane_get_min_zpos_value(req->drmdev, plane->plane->plane_id, &min_zpos);
if (ok != 0) {
min_zpos = 0;
}
break;
}
}

for (int i = 0; i < layers_count; i++) {
if (layers[i]->type == kFlutterLayerContentTypeBackingStore) {
Expand Down Expand Up @@ -899,7 +1000,7 @@ static bool on_present_layers(
0,
compositor->drmdev->selected_mode->hdisplay,
compositor->drmdev->selected_mode->vdisplay,
plane->type == DRM_PLANE_TYPE_PRIMARY ? 0 : 1
i + min_zpos
);
if (ok != 0) {
fprintf(stderr, "[compositor] Could not present backing store. rendertarget->present: %s\n", strerror(ok));
Expand All @@ -917,7 +1018,7 @@ static bool on_present_layers(
(int) round(layers[i]->offset.y),
(int) round(layers[i]->size.width),
(int) round(layers[i]->size.height),
i,
i + min_zpos,
cb_data->userdata
);
if (ok != 0) {
Expand Down Expand Up @@ -1003,8 +1104,6 @@ int compositor_remove_view_callbacks(int64_t view_id) {
return 0;
}

/// DRM HARDWARE PLANE RESERVATION

/// COMPOSITOR INITIALIZATION
int compositor_initialize(struct drmdev *drmdev) {
compositor.drmdev = drmdev;
Expand Down
65 changes: 57 additions & 8 deletions src/flutter-pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ SEE ALSO:\n\

struct flutterpi flutterpi;

static int post_platform_task(
/*static int flutterpi_post_platform_task(
int (*callback)(void *userdata),
void *userdata
);
);*/

static bool runs_platform_tasks_on_current_thread(void *userdata);

Expand Down Expand Up @@ -442,7 +442,7 @@ static void on_frame_request(
}

if (reply_instantly) {
post_platform_task(
flutterpi_post_platform_task(
on_execute_frame_request,
NULL
);
Expand Down Expand Up @@ -480,7 +480,7 @@ static int on_execute_platform_task(
return 0;
}

static int post_platform_task(
int flutterpi_post_platform_task(
int (*callback)(void *userdata),
void *userdata
) {
Expand Down Expand Up @@ -558,7 +558,7 @@ static int on_execute_platform_task_with_time(
return 0;
}

static int post_platform_task_with_time(
int flutterpi_post_platform_task_with_time(
int (*callback)(void *userdata),
void *userdata,
uint64_t target_time_usec
Expand Down Expand Up @@ -621,6 +621,54 @@ static int post_platform_task_with_time(
return ok;
}

int flutterpi_sd_event_add_io(
sd_event_source **source_out,
int fd,
uint32_t events,
sd_event_io_handler_t callback,
void *userdata
) {
int ok;

if (pthread_self() != flutterpi.event_loop_thread) {
pthread_mutex_lock(&flutterpi.event_loop_mutex);
}

ok = sd_event_add_io(
flutterpi.event_loop,
source_out,
fd,
events,
callback,
userdata
);
if (ok < 0) {
fprintf(stderr, "[flutter-pi] Could not add IO callback to event loop. sd_event_add_io: %s\n", strerror(-ok));
return -ok;
}

if (pthread_self() != flutterpi.event_loop_thread) {
ok = write(flutterpi.wakeup_event_loop_fd, (uint8_t[8]) {0, 0, 0, 0, 0, 0, 0, 1}, 8);
if (ok < 0) {
perror("[flutter-pi] Error arming main loop for io callback. write");
ok = errno;
goto fail_unlock_event_loop;
}
}

if (pthread_self() != flutterpi.event_loop_thread) {
pthread_mutex_unlock(&flutterpi.event_loop_mutex);
}

return 0;


fail_unlock_event_loop:
if (pthread_self() != flutterpi.event_loop_thread) {
pthread_mutex_unlock(&flutterpi.event_loop_mutex);
}
}

/// flutter tasks
static int on_execute_flutter_task(
void *userdata
Expand Down Expand Up @@ -658,7 +706,7 @@ static void on_post_flutter_task(

*dup_task = task;

ok = post_platform_task_with_time(
ok = flutterpi_post_platform_task_with_time(
on_execute_flutter_task,
dup_task,
target_time / 1000
Expand Down Expand Up @@ -762,7 +810,7 @@ int flutterpi_send_platform_message(
msg->message_size = 0;
}

ok = post_platform_task(
ok = flutterpi_post_platform_task(
on_send_platform_message,
msg
);
Expand Down Expand Up @@ -819,7 +867,7 @@ int flutterpi_respond_to_platform_message(
msg->message = 0;
}

ok = post_platform_task(
ok = flutterpi_post_platform_task(
on_send_platform_message,
msg
);
Expand Down Expand Up @@ -987,6 +1035,7 @@ static void on_pageflip_event(

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


cqueue_lock(&flutterpi.frame_queue);

ok = cqueue_try_dequeue_locked(&flutterpi.frame_queue, &presented_frame);
Expand Down
Loading