[PATCH] Extract compositor MESA code into separate file

Marcus Lorentzon marcus.xm.lorentzon at stericsson.com
Tue Apr 12 11:12:09 PDT 2011


---
 compositor/Makefile.am      |    2 +-
 compositor/compositor-drm.c |   22 +++++++---------------
 compositor/mesa.c           |   27 +++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 16 deletions(-)
 create mode 100644 compositor/mesa.c

diff --git a/compositor/Makefile.am b/compositor/Makefile.am
index e90830a..20dd330 100644
--- a/compositor/Makefile.am
+++ b/compositor/Makefile.am
@@ -12,7 +12,7 @@ compositor_LDADD =				\
 	$(COMPOSITOR_LIBS)
 
 if ENABLE_DRM_COMPOSITOR
-drm_compositor_sources = compositor-drm.c tty.c evdev.c
+drm_compositor_sources = compositor-drm.c tty.c evdev.c mesa.c
 endif
 
 if ENABLE_X11_COMPOSITOR
diff --git a/compositor/compositor-drm.c b/compositor/compositor-drm.c
index 545bde5..b6fc036 100644
--- a/compositor/compositor-drm.c
+++ b/compositor/compositor-drm.c
@@ -147,7 +147,7 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
 	}
 
 	ec->drm.fd = fd;
-	ec->base.display = eglGetDRMDisplayMESA(ec->drm.fd);
+	ec->base.display = drm_get_egl_display(ec->drm.fd);
 	if (ec->base.display == NULL) {
 		fprintf(stderr, "failed to create display\n");
 		return -1;
@@ -205,13 +205,7 @@ create_output_for_connector(struct drm_compositor *ec,
 	drmModeEncoder *encoder;
 	drmModeModeInfo *mode;
 	int i, ret;
-	EGLint handle, stride, 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
-	};
+	EGLint handle, stride;
 
 	output = malloc(sizeof *output);
 	if (output == NULL)
@@ -255,15 +249,13 @@ create_output_for_connector(struct drm_compositor *ec,
 	for (i = 0; i < 2; i++) {
 		glBindRenderbuffer(GL_RENDERBUFFER, output->rbo[i]);
 
-		attribs[1] = output->base.width;
-		attribs[3] = output->base.height;
-		output->image[i] =
-			eglCreateDRMImageMESA(ec->base.display, attribs);
+		output->image[i] = drm_create_scanout_image(ec->base.display,
+							    output->base.width,
+							    output->base.height,
+							    &handle, &stride);
 		glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
 						       output->image[i]);
-		eglExportDRMImageMESA(ec->base.display, output->image[i],
-				      NULL, &handle, &stride);
-
+		
 		ret = drmModeAddFB(ec->drm.fd,
 				   output->base.width, output->base.height,
 				   32, 32, stride, handle, &output->fb_id[i]);
diff --git a/compositor/mesa.c b/compositor/mesa.c
new file mode 100644
index 0000000..62fb2cb
--- /dev/null
+++ b/compositor/mesa.c
@@ -0,0 +1,27 @@
+
+
+int drm_get_egl_display(int fd)
+{
+	return eglGetDRMDisplayMESA(fd);
+}
+
+EGLimage drm_create_scanout_image(EGLDisplay display, EGLint w, EGLint h,
+				  EGLint *handle, EGLint *stride)
+{
+	EGLImageKHR image;
+	EGLing 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
+	};
+
+	attribs[1] = w;
+	attribs[3] = h;
+	image = eglCreateDRMImageMESA(display, attribs);
+	eglExportDRMImageMESA(display, image, NULL, handle, stride);
+
+	return image;
+}
+
-- 
1.7.3.2


--------------070800020807050305020607--


More information about the wayland-devel mailing list