Use gbm for compositor-{drm,openwfd}

dev
Benjamin Franzke 14 years ago
parent 41402f8ec6
commit 060cf805bb
  1. 87
      compositor/compositor-drm.c
  2. 41
      compositor/compositor-openwfd.c
  3. 4
      configure.ac

@ -27,6 +27,8 @@
#include <xf86drm.h> #include <xf86drm.h>
#include <xf86drmMode.h> #include <xf86drmMode.h>
#include <gbm.h>
#include "compositor.h" #include "compositor.h"
struct drm_compositor { struct drm_compositor {
@ -41,12 +43,10 @@ struct drm_compositor {
struct { struct {
int fd; int fd;
} drm; } drm;
struct gbm_device *gbm;
uint32_t crtc_allocator; uint32_t crtc_allocator;
uint32_t connector_allocator; uint32_t connector_allocator;
struct tty *tty; struct tty *tty;
PFNEGLCREATEDRMIMAGEMESA create_drm_image;
PFNEGLEXPORTDRMIMAGEMESA export_drm_image;
}; };
struct drm_mode { struct drm_mode {
@ -62,6 +62,7 @@ struct drm_output {
GLuint rbo[2]; GLuint rbo[2];
uint32_t fb_id[2]; uint32_t fb_id[2];
EGLImageKHR image[2]; EGLImageKHR image[2];
struct gbm_bo *bo[2];
uint32_t current; uint32_t current;
struct wlsc_surface *scanout_surface; struct wlsc_surface *scanout_surface;
@ -147,6 +148,7 @@ drm_output_prepare_scanout_surface(struct wlsc_output *output_base,
EGLint handle, stride; EGLint handle, stride;
int ret; int ret;
uint32_t fb_id = 0; uint32_t fb_id = 0;
struct gbm_bo *bo;
if (es->x != output->base.x || if (es->x != output->base.x ||
es->y != output->base.y || es->y != output->base.y ||
@ -155,8 +157,15 @@ drm_output_prepare_scanout_surface(struct wlsc_output *output_base,
es->image == EGL_NO_IMAGE_KHR) es->image == EGL_NO_IMAGE_KHR)
return -1; return -1;
c->export_drm_image(c->base.display, bo = gbm_bo_create_from_egl_image(c->gbm,
es->image, NULL, &handle, &stride); c->base.display, es->image,
es->width, es->height,
GBM_BO_USE_SCANOUT);
handle = gbm_bo_get_handle(bo).s32;
stride = gbm_bo_get_pitch(bo);
gbm_bo_destroy(bo);
if (handle == 0) if (handle == 0)
return -1; return -1;
@ -185,6 +194,7 @@ drm_output_set_cursor(struct wlsc_output *output_base,
EGLint handle, stride; EGLint handle, stride;
int ret = -1; int ret = -1;
pixman_region32_t cursor_region; pixman_region32_t cursor_region;
struct gbm_bo *bo;
if (eid == NULL) { if (eid == NULL) {
drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0); drmModeSetCursor(c->drm.fd, output->crtc_id, 0, 0, 0);
@ -211,8 +221,15 @@ drm_output_set_cursor(struct wlsc_output *output_base,
if (eid->sprite->width > 64 || eid->sprite->height > 64) if (eid->sprite->width > 64 || eid->sprite->height > 64)
goto out; goto out;
c->export_drm_image(c->base.display, eid->sprite->image, bo = gbm_bo_create_from_egl_image(c->gbm,
NULL, &handle, &stride); c->base.display,
eid->sprite->image, 64, 64,
GBM_BO_USE_CURSOR_64X64);
handle = gbm_bo_get_handle(bo).s32;
stride = gbm_bo_get_pitch(bo);
gbm_bo_destroy(bo);
if (stride != 64 * 4) { if (stride != 64 * 4) {
fprintf(stderr, "info: cursor stride is != 64\n"); fprintf(stderr, "info: cursor stride is != 64\n");
@ -277,7 +294,8 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
setenv("EGL_PLATFORM", "drm", 1); setenv("EGL_PLATFORM", "drm", 1);
ec->drm.fd = fd; ec->drm.fd = fd;
ec->base.display = eglGetDisplay(FD_TO_EGL_NATIVE_DPY(ec->drm.fd)); ec->gbm = gbm_create_device(ec->drm.fd);
ec->base.display = eglGetDisplay(ec->gbm);
if (ec->base.display == NULL) { if (ec->base.display == NULL) {
fprintf(stderr, "failed to create display\n"); fprintf(stderr, "failed to create display\n");
return -1; return -1;
@ -375,13 +393,7 @@ create_output_for_connector(struct drm_compositor *ec,
struct drm_mode *drm_mode; struct drm_mode *drm_mode;
drmModeEncoder *encoder; drmModeEncoder *encoder;
int i, ret; int i, ret;
EGLint handle, stride, attribs[] = { unsigned handle, stride;
EGL_WIDTH, 0,
EGL_HEIGHT, 0,
EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SCANOUT_MESA,
EGL_NONE
};
encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[0]); encoder = drmModeGetEncoder(ec->drm.fd, connector->encoders[0]);
if (encoder == NULL) { if (encoder == NULL) {
@ -439,14 +451,22 @@ create_output_for_connector(struct drm_compositor *ec,
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
glBindRenderbuffer(GL_RENDERBUFFER, output->rbo[i]); glBindRenderbuffer(GL_RENDERBUFFER, output->rbo[i]);
attribs[1] = output->base.current->width; output->bo[i] =
attribs[3] = output->base.current->height; gbm_bo_create(ec->gbm,
output->image[i] = output->base.current->width,
ec->create_drm_image(ec->base.display, attribs); output->base.current->height,
GBM_BO_FORMAT_XRGB8888,
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
output->image[i] = ec->base.create_image(ec->base.display,
NULL,
EGL_NATIVE_PIXMAP_KHR,
output->bo[i], NULL);
ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER, ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER,
output->image[i]); output->image[i]);
ec->export_drm_image(ec->base.display, output->image[i], stride = gbm_bo_get_pitch(output->bo[i]);
NULL, &handle, &stride); handle = gbm_bo_get_handle(output->bo[i]).u32;
ret = drmModeAddFB(ec->drm.fd, ret = drmModeAddFB(ec->drm.fd,
output->base.current->width, output->base.current->width,
@ -663,19 +683,23 @@ static EGLImageKHR
drm_compositor_create_cursor_image(struct wlsc_compositor *ec, drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
int32_t width, int32_t height) int32_t width, int32_t height)
{ {
static const EGLint image_attribs[] = {
EGL_WIDTH, 64,
EGL_HEIGHT, 64,
EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_CURSOR_MESA,
EGL_NONE
};
struct drm_compositor *c = (struct drm_compositor *) ec; struct drm_compositor *c = (struct drm_compositor *) ec;
struct gbm_bo *bo;
EGLImageKHR image;
if (width > 64 || height > 64) if (width > 64 || height > 64)
return EGL_NO_IMAGE_KHR; return EGL_NO_IMAGE_KHR;
return c->create_drm_image(ec->display, image_attribs); bo = gbm_bo_create(c->gbm,
/* width, height, */ 64, 64,
GBM_BO_FORMAT_ARGB8888,
GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_RENDERING);
image = ec->create_image(c->base.display, NULL,
EGL_NATIVE_PIXMAP_KHR, bo, NULL);
gbm_bo_destroy(bo);
return image;
} }
static void static void
@ -765,11 +789,6 @@ drm_compositor_create(struct wl_display *display, int connector)
glGenFramebuffers(1, &ec->base.fbo); glGenFramebuffers(1, &ec->base.fbo);
glBindFramebuffer(GL_FRAMEBUFFER, ec->base.fbo); glBindFramebuffer(GL_FRAMEBUFFER, ec->base.fbo);
ec->create_drm_image =
(void *) eglGetProcAddress("eglCreateDRMImageMESA");
ec->export_drm_image =
(void *) eglGetProcAddress("eglExportDRMImageMESA");
/* Can't init base class until we have a current egl context */ /* Can't init base class until we have a current egl context */
if (wlsc_compositor_init(&ec->base, display) < 0) if (wlsc_compositor_init(&ec->base, display) < 0)
return NULL; return NULL;

@ -27,12 +27,15 @@
#include <WF/wfd.h> #include <WF/wfd.h>
#include <WF/wfdext.h> #include <WF/wfdext.h>
#include <gbm.h>
#include "compositor.h" #include "compositor.h"
struct wfd_compositor { struct wfd_compositor {
struct wlsc_compositor base; struct wlsc_compositor base;
struct udev *udev; struct udev *udev;
struct gbm_device *gbm;
WFDDevice dev; WFDDevice dev;
WFDEvent event; WFDEvent event;
@ -43,9 +46,6 @@ struct wfd_compositor {
uint32_t start_time; uint32_t start_time;
uint32_t used_pipelines; uint32_t used_pipelines;
PFNEGLCREATEDRMIMAGEMESA create_drm_image;
PFNEGLEXPORTDRMIMAGEMESA export_drm_image;
}; };
struct wfd_output { struct wfd_output {
@ -59,6 +59,7 @@ struct wfd_output {
WFDPortMode mode; WFDPortMode mode;
WFDSource source[2]; WFDSource source[2];
struct gbm_bo *bo[2];
EGLImageKHR image[2]; EGLImageKHR image[2];
GLuint rbo[2]; GLuint rbo[2];
uint32_t current; uint32_t current;
@ -121,7 +122,8 @@ init_egl(struct wfd_compositor *ec)
ec->wfd_fd = fd; ec->wfd_fd = fd;
setenv("EGL_PLATFORM", "drm", 1); setenv("EGL_PLATFORM", "drm", 1);
ec->base.display = eglGetDisplay(FD_TO_EGL_NATIVE_DPY(ec->wfd_fd)); ec->gbm = gbm_create_device(ec->wfd_fd);
ec->base.display = eglGetDisplay(ec->gbm);
if (ec->base.display == NULL) { if (ec->base.display == NULL) {
fprintf(stderr, "failed to create display\n"); fprintf(stderr, "failed to create display\n");
return -1; return -1;
@ -180,13 +182,6 @@ create_output_for_port(struct wfd_compositor *ec,
{ {
struct wfd_output *output; struct wfd_output *output;
int i; int i;
EGLint attribs[] = {
EGL_WIDTH, 0,
EGL_HEIGHT, 0,
EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SCANOUT_MESA,
EGL_NONE
};
WFDint num_pipelines, *pipelines; WFDint num_pipelines, *pipelines;
WFDint num_modes; WFDint num_modes;
WFDint rect[4] = { 0, 0, 0, 0 }; WFDint rect[4] = { 0, 0, 0, 0 };
@ -271,18 +266,20 @@ create_output_for_port(struct wfd_compositor *ec,
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
glBindRenderbuffer(GL_RENDERBUFFER, output->rbo[i]); glBindRenderbuffer(GL_RENDERBUFFER, output->rbo[i]);
attribs[1] = output->base.current->width; output->bo[i] =
attribs[3] = output->base.current->height; gbm_bo_create(ec->gbm,
output->image[i] = output->base.current->width,
ec->create_drm_image(ec->base.display, attribs); output->base.current->height,
GBM_BO_FORMAT_XRGB8888,
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
output->image[i] = ec->base.create_image(ec->base.display,
NULL,
EGL_NATIVE_PIXMAP_KHR,
output->bo[i], NULL);
printf("output->image[i]: %p\n", output->image[i]); printf("output->image[i]: %p\n", output->image[i]);
ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER, ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER,
output->image[i]); output->image[i]);
int handle;
ec->export_drm_image(ec->base.display, output->image[i],
NULL, &handle, NULL);
printf("handle: %d\n", handle);
output->source[i] = output->source[i] =
wfdCreateSourceFromImage(ec->dev, output->pipeline, wfdCreateSourceFromImage(ec->dev, output->pipeline,
output->image[i], NULL); output->image[i], NULL);
@ -392,6 +389,7 @@ destroy_output(struct wfd_output *output)
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
ec->base.destroy_image(ec->base.display, output->image[i]); ec->base.destroy_image(ec->base.display, output->image[i]);
gbm_bo_destroy(output->bo[i]);
wfdDestroySource(ec->dev, output->source[i]); wfdDestroySource(ec->dev, output->source[i]);
} }
@ -583,11 +581,6 @@ wfd_compositor_create(struct wl_display *display, int connector)
if (wlsc_compositor_init(&ec->base, display) < 0) if (wlsc_compositor_init(&ec->base, display) < 0)
return NULL; return NULL;
ec->create_drm_image =
(void *) eglGetProcAddress("eglCreateDRMImageMESA");
ec->export_drm_image =
(void *) eglGetProcAddress("eglExportDRMImageMESA");
if (create_outputs(ec, connector) < 0) { if (create_outputs(ec, connector) < 0) {
fprintf(stderr, "failed to create outputs\n"); fprintf(stderr, "failed to create outputs\n");
return NULL; return NULL;

@ -53,7 +53,7 @@ AC_ARG_ENABLE(drm-compositor, [ --enable-drm-compositor],,
AM_CONDITIONAL(ENABLE_DRM_COMPOSITOR, test x$enable_drm_compositor == xyes) AM_CONDITIONAL(ENABLE_DRM_COMPOSITOR, test x$enable_drm_compositor == xyes)
if test x$enable_drm_compositor == xyes; then if test x$enable_drm_compositor == xyes; then
AC_DEFINE([BUILD_DRM_COMPOSITOR], [1], [Build the DRM compositor]) AC_DEFINE([BUILD_DRM_COMPOSITOR], [1], [Build the DRM compositor])
PKG_CHECK_MODULES(DRM_COMPOSITOR, [libudev >= 136 libdrm >= 2.4.23]) PKG_CHECK_MODULES(DRM_COMPOSITOR, [libudev >= 136 libdrm >= 2.4.23 gbm])
fi fi
@ -62,7 +62,7 @@ AC_ARG_ENABLE(openwfd-compositor, [ --enable-openwfd-compositor],,
AM_CONDITIONAL(ENABLE_OPENWFD_COMPOSITOR, test x$enable_openwfd_compositor == xyes) AM_CONDITIONAL(ENABLE_OPENWFD_COMPOSITOR, test x$enable_openwfd_compositor == xyes)
if test x$enable_openwfd_compositor == xyes; then if test x$enable_openwfd_compositor == xyes; then
AC_DEFINE([BUILD_OPENWFD_COMPOSITOR], [1], [Build the OpenWF compositor]) AC_DEFINE([BUILD_OPENWFD_COMPOSITOR], [1], [Build the OpenWF compositor])
PKG_CHECK_MODULES(OPENWFD_COMPOSITOR, [openwfd]) PKG_CHECK_MODULES(OPENWFD_COMPOSITOR, [openwfd gbm])
fi fi

Loading…
Cancel
Save