Skip to content
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

drm-platform: support wl_resource exports, drmModeAddFB2 fallback #145

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Changes from 1 commit
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
111 changes: 71 additions & 40 deletions platform/cog-platform-drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,65 @@ drm_page_flip_handler (int fd, unsigned int frame, unsigned int sec, unsigned in
drm_data.committed_buffer = (struct buffer_object *) data;
}

static void
drm_update_from_bo (struct gbm_bo *bo, struct wl_resource *buffer_resource, uint32_t width, uint32_t height, uint32_t format)
{
uint32_t in_handles[4] = { 0, };
uint32_t in_strides[4] = { 0, };
uint32_t in_offsets[4] = { 0, };
uint64_t in_modifiers[4] = { 0, };

in_modifiers[0] = gbm_bo_get_modifier (bo);

int plane_count = gbm_bo_get_plane_count (bo);
zdobersek marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < plane_count; ++i) {
in_handles[i] = gbm_bo_get_handle_for_plane (bo, i).u32;
in_strides[i] = gbm_bo_get_stride_for_plane (bo, i);
in_offsets[i] = gbm_bo_get_offset (bo, i);
in_modifiers[i] = in_modifiers[0];
}

int flags = 0;
if (in_modifiers[0])
flags = DRM_MODE_FB_MODIFIERS;

uint32_t fb_id = 0;
int ret = drmModeAddFB2WithModifiers (drm_data.fd, width, height, format,
in_handles, in_strides, in_offsets, in_modifiers,
&fb_id, flags);
if (ret) {
in_handles[0] = gbm_bo_get_handle (bo).u32;
in_handles[1] = in_handles[2] = in_handles[3] = 0;
in_strides[0] = gbm_bo_get_stride (bo);
in_strides[1] = in_strides[2] = in_strides[3] = 0;
in_offsets[0] = in_offsets[1] = in_offsets[2] = in_offsets[3] = 0;

ret = drmModeAddFB2 (drm_data.fd, width, height, format,
in_handles, in_strides, in_offsets,
&fb_id, 0);
}

if (ret)
zdobersek marked this conversation as resolved.
Show resolved Hide resolved
return;

if (!drm_data.mode_set) {
ret = drmModeSetCrtc (drm_data.fd, drm_data.crtc_id, fb_id, 0, 0,
&drm_data.connector_id, 1, drm_data.mode);
if (ret)
return;

drm_data.mode_set = 0;
}

struct buffer_object *buffer = g_new0 (struct buffer_object, 1);
buffer->fb_id = fb_id;
buffer->bo = bo;
buffer->buffer_resource = buffer_resource;

ret = drmModePageFlip (drm_data.fd, drm_data.crtc_id, fb_id,
zdobersek marked this conversation as resolved.
Show resolved Hide resolved
DRM_MODE_PAGE_FLIP_EVENT, buffer);
}


static void
clear_gbm (void)
Expand Down Expand Up @@ -569,7 +628,16 @@ init_glib (void)
static void
on_export_buffer_resource (void *data, struct wl_resource *buffer_resource)
{
assert (!"should not be reached");
struct gbm_bo* bo = gbm_bo_import (gbm_data.device, GBM_BO_IMPORT_WL_BUFFER,
(void *) buffer_resource, GBM_BO_USE_SCANOUT);
if (!bo)
zdobersek marked this conversation as resolved.
Show resolved Hide resolved
return;

uint32_t width = gbm_bo_get_width (bo);
uint32_t height = gbm_bo_get_height (bo);
uint32_t format = gbm_bo_get_format (bo);

drm_update_from_bo (bo, buffer_resource, width, height, format);
}

static void
Expand All @@ -593,45 +661,8 @@ on_export_dmabuf_resource (void *data, struct wpe_view_backend_exportable_fdo_dm
if (!bo)
return;

uint32_t in_handles[4] = { 0, };
uint32_t in_strides[4] = { 0, };
uint32_t in_offsets[4] = { 0, };
uint64_t in_modifiers[4] = { 0, };
in_modifiers[0] = gbm_bo_get_modifier (bo);

int plane_count = gbm_bo_get_plane_count (bo);
for (int i = 0; i < plane_count; ++i) {
in_handles[i] = gbm_bo_get_handle_for_plane (bo, i).u32;
in_strides[i] = gbm_bo_get_stride_for_plane (bo, i);
in_offsets[i] = gbm_bo_get_offset (bo, i);
in_modifiers[i] = in_modifiers[0];
}

int flags = 0;
if (in_modifiers[0])
flags = DRM_MODE_FB_MODIFIERS;

uint32_t fb_id = 0;
int ret = drmModeAddFB2WithModifiers (drm_data.fd, dmabuf_resource->width, dmabuf_resource->height, dmabuf_resource->format,
in_handles, in_strides, in_offsets,
in_modifiers, &fb_id, flags);
if (ret)
return;

if (!drm_data.mode_set) {
ret = drmModeSetCrtc (drm_data.fd, drm_data.crtc_id, fb_id, 0, 0,
&drm_data.connector_id, 1, drm_data.mode);
if (ret)
return;
drm_data.mode_set = true;
}

struct buffer_object *buffer = g_new0 (struct buffer_object, 1);
buffer->fb_id = fb_id;
buffer->bo = bo;
buffer->buffer_resource = dmabuf_resource->buffer_resource;
ret = drmModePageFlip (drm_data.fd, drm_data.crtc_id, fb_id,
DRM_MODE_PAGE_FLIP_EVENT, buffer);
drm_update_from_bo (bo, dmabuf_resource->buffer_resource, dmabuf_resource->width,
dmabuf_resource->height, dmabuf_resource->format);
}

gboolean
Expand Down