compositor: Remove drm.c, use shm.c for pointer images

dev
Benjamin Franzke 14 years ago committed by Kristian Høgsberg
parent 2af7f10674
commit c649a92549
  1. 6
      compositor/Makefile.am
  2. 5
      compositor/compositor-drm.c
  3. 2
      compositor/compositor-wayland.c
  4. 2
      compositor/compositor-x11.c
  5. 2
      compositor/compositor.c
  6. 17
      compositor/compositor.h
  7. 113
      compositor/drm.c
  8. 80
      compositor/shm.c

@ -13,17 +13,14 @@ compositor_LDADD = \
if ENABLE_DRM_COMPOSITOR if ENABLE_DRM_COMPOSITOR
drm_compositor_sources = compositor-drm.c tty.c evdev.c drm_compositor_sources = compositor-drm.c tty.c evdev.c
drm_sources = drm.c
endif endif
if ENABLE_X11_COMPOSITOR if ENABLE_X11_COMPOSITOR
x11_compositor_sources = compositor-x11.c x11_compositor_sources = compositor-x11.c
drm_sources = drm.c
endif endif
if ENABLE_WAYLAND_COMPOSITOR if ENABLE_WAYLAND_COMPOSITOR
wayland_compositor_sources = compositor-wayland.c wayland_compositor_sources = compositor-wayland.c
drm_sources = drm.c
endif endif
compositor_SOURCES = \ compositor_SOURCES = \
@ -36,8 +33,7 @@ compositor_SOURCES = \
shm.c \ shm.c \
$(drm_compositor_sources) \ $(drm_compositor_sources) \
$(x11_compositor_sources) \ $(x11_compositor_sources) \
$(wayland_compositor_sources) \ $(wayland_compositor_sources)
$(drm_sources)
udevrulesddir = $(sysconfdir)/udev/rules.d udevrulesddir = $(sysconfdir)/udev/rules.d

@ -22,6 +22,9 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#define GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES #define EGL_EGLEXT_PROTOTYPES
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
@ -352,7 +355,7 @@ drm_compositor_create(struct wl_display *display, int connector)
ec->base.destroy = drm_destroy; ec->base.destroy = drm_destroy;
ec->base.present = drm_compositor_present; ec->base.present = drm_compositor_present;
ec->base.create_buffer = wlsc_drm_buffer_create; ec->base.create_buffer = wlsc_shm_buffer_create;
ec->base.focus = 1; ec->base.focus = 1;
glGenFramebuffers(1, &ec->base.fbo); glGenFramebuffers(1, &ec->base.fbo);

@ -464,7 +464,7 @@ wayland_compositor_create(struct wl_display *display, int width, int height)
c->base.destroy = wayland_destroy; c->base.destroy = wayland_destroy;
c->base.present = wayland_compositor_present; c->base.present = wayland_compositor_present;
c->base.create_buffer = wlsc_drm_buffer_create; c->base.create_buffer = wlsc_shm_buffer_create;
/* 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(&c->base, display) < 0) if (wlsc_compositor_init(&c->base, display) < 0)

@ -566,7 +566,7 @@ x11_compositor_create(struct wl_display *display, int width, int height)
c->base.destroy = x11_destroy; c->base.destroy = x11_destroy;
c->base.present = x11_compositor_present; c->base.present = x11_compositor_present;
c->base.create_buffer = wlsc_drm_buffer_create; c->base.create_buffer = wlsc_shm_buffer_create;
/* 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(&c->base, display) < 0) if (wlsc_compositor_init(&c->base, display) < 0)

@ -314,7 +314,7 @@ create_buffer_from_png(struct wlsc_compositor *ec,
if(pixels == NULL) if(pixels == NULL)
return NULL; return NULL;
buffer = ec->create_buffer(ec, width, height, buffer = ec->create_buffer(ec, width, height, width * 4,
&ec->compositor.premultiplied_argb_visual, &ec->compositor.premultiplied_argb_visual,
pixels); pixels);

@ -19,8 +19,6 @@
#ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_ #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
#define _WAYLAND_SYSTEM_COMPOSITOR_H_ #define _WAYLAND_SYSTEM_COMPOSITOR_H_
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <libudev.h> #include <libudev.h>
#include <pixman.h> #include <pixman.h>
#include "wayland-server.h" #include "wayland-server.h"
@ -116,8 +114,8 @@ struct wlsc_compositor {
void (*present)(struct wlsc_compositor *c); void (*present)(struct wlsc_compositor *c);
struct wl_buffer *(*create_buffer)(struct wlsc_compositor *c, struct wl_buffer *(*create_buffer)(struct wlsc_compositor *c,
int32_t width, int32_t height, int32_t width, int32_t height,
struct wl_visual *visual, int32_t stride, struct wl_visual *visual,
const void *data); void *data);
}; };
#define MODIFIER_CTRL (1 << 8) #define MODIFIER_CTRL (1 << 8)
@ -205,9 +203,10 @@ uint32_t
get_time(void); get_time(void);
struct wl_buffer * struct wl_buffer *
wlsc_drm_buffer_create(struct wlsc_compositor *ec, wlsc_shm_buffer_create(struct wlsc_compositor *ec,
int width, int height, int32_t width, int32_t height,
struct wl_visual *visual, const void *data); int32_t stride, struct wl_visual *visual,
void *data);
int int
wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display); wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
@ -234,10 +233,6 @@ shell_resize(struct wl_client *client, struct wl_shell *shell,
struct wl_surface *surface, struct wl_surface *surface,
struct wl_input_device *device, uint32_t time, uint32_t edges); struct wl_input_device *device, uint32_t time, uint32_t edges);
struct wl_buffer *
wl_buffer_create_drm(struct wlsc_compositor *compositor,
struct wl_visual *visual);
struct wlsc_compositor * struct wlsc_compositor *
x11_compositor_create(struct wl_display *display, int width, int height); x11_compositor_create(struct wl_display *display, int width, int height);

@ -1,113 +0,0 @@
/*
* Copyright © 2010 Kristian Høgsberg
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "compositor.h"
struct wlsc_drm_buffer {
struct wl_buffer buffer;
EGLImageKHR image;
};
static void
drm_buffer_attach(struct wl_buffer *buffer_base, struct wl_surface *surface)
{
struct wlsc_surface *es = (struct wlsc_surface *) surface;
struct wlsc_drm_buffer *buffer =
(struct wlsc_drm_buffer *) buffer_base;
glBindTexture(GL_TEXTURE_2D, es->texture);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, buffer->image);
es->visual = buffer->buffer.visual;
}
static void
drm_buffer_damage(struct wl_buffer *buffer,
struct wl_surface *surface,
int32_t x, int32_t y, int32_t width, int32_t height)
{
}
static struct wlsc_drm_buffer *
wlsc_drm_buffer_create_for_image(struct wlsc_compositor *compositor,
EGLImageKHR *image,
int32_t width, int32_t height,
struct wl_visual *visual)
{
struct wlsc_drm_buffer *buffer;
buffer = malloc(sizeof *buffer);
if (buffer == NULL)
return NULL;
buffer->buffer.compositor = &compositor->compositor;
buffer->buffer.width = width;
buffer->buffer.height = height;
buffer->buffer.visual = visual;
buffer->buffer.attach = drm_buffer_attach;
buffer->buffer.damage = drm_buffer_damage;
buffer->image = image;
return buffer;
}
struct wl_buffer *
wlsc_drm_buffer_create(struct wlsc_compositor *ec, int width, int height,
struct wl_visual *visual, const void *data)
{
struct wlsc_drm_buffer *buffer;
EGLImageKHR image;
GLuint texture;
EGLint image_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
};
image_attribs[1] = width;
image_attribs[3] = height;
image = eglCreateDRMImageMESA(ec->display, image_attribs);
if (image == NULL)
return NULL;
buffer = wlsc_drm_buffer_create_for_image(ec, image,
width, height, visual);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, buffer->image);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
GL_BGRA_EXT, GL_UNSIGNED_BYTE, data);
glDeleteTextures(1, &texture);
return &buffer->buffer;
}

@ -28,6 +28,7 @@ struct wlsc_shm_buffer {
struct wl_buffer buffer; struct wl_buffer buffer;
int32_t stride; int32_t stride;
void *data; void *data;
int mapped;
}; };
static void static void
@ -36,7 +37,10 @@ destroy_buffer(struct wl_resource *resource, struct wl_client *client)
struct wlsc_shm_buffer *buffer = struct wlsc_shm_buffer *buffer =
container_of(resource, struct wlsc_shm_buffer, buffer.resource); container_of(resource, struct wlsc_shm_buffer, buffer.resource);
munmap(buffer->data, buffer->stride * buffer->buffer.height); if (buffer->mapped)
munmap(buffer->data, buffer->stride * buffer->buffer.height);
else
free(buffer->data);
free(buffer); free(buffer);
} }
@ -87,6 +91,30 @@ shm_buffer_damage(struct wl_buffer *buffer_base,
* support any unpack attributes except GL_UNPACK_ALIGNMENT. */ * support any unpack attributes except GL_UNPACK_ALIGNMENT. */
} }
static struct wlsc_shm_buffer *
wlsc_shm_buffer_init(struct wlsc_compositor *compositor,
int32_t width, int32_t height,
int32_t stride, struct wl_visual *visual,
void *data)
{
struct wlsc_shm_buffer *buffer;
buffer = malloc(sizeof *buffer);
if (buffer == NULL)
return NULL;
buffer->buffer.compositor = &compositor->compositor;
buffer->buffer.width = width;
buffer->buffer.height = height;
buffer->buffer.visual = visual;
buffer->buffer.attach = shm_buffer_attach;
buffer->buffer.damage = shm_buffer_damage;
buffer->stride = stride;
buffer->data = data;
return buffer;
}
static void static void
shm_create_buffer(struct wl_client *client, struct wl_shm *shm, shm_create_buffer(struct wl_client *client, struct wl_shm *shm,
uint32_t id, int fd, int32_t width, int32_t height, uint32_t id, int fd, int32_t width, int32_t height,
@ -96,6 +124,7 @@ shm_create_buffer(struct wl_client *client, struct wl_shm *shm,
container_of((struct wlsc_shm *) shm, container_of((struct wlsc_shm *) shm,
struct wlsc_compositor, shm); struct wlsc_compositor, shm);
struct wlsc_shm_buffer *buffer; struct wlsc_shm_buffer *buffer;
void *data;
/* FIXME: Define a real exception event instead of abusing the /* FIXME: Define a real exception event instead of abusing the
* display.invalid_object error */ * display.invalid_object error */
@ -118,27 +147,12 @@ shm_create_buffer(struct wl_client *client, struct wl_shm *shm,
return; return;
} }
buffer = malloc(sizeof *buffer); data = mmap(NULL, stride * height, PROT_READ, MAP_SHARED, fd, 0);
if (buffer == NULL) {
close(fd);
wl_client_post_no_memory(client);
return;
}
buffer->buffer.compositor = (struct wl_compositor *) compositor;
buffer->buffer.width = width;
buffer->buffer.height = height;
buffer->buffer.visual = visual;
buffer->buffer.attach = shm_buffer_attach;
buffer->buffer.damage = shm_buffer_damage;
buffer->stride = stride;
buffer->data =
mmap(NULL, stride * height, PROT_READ, MAP_SHARED, fd, 0);
close(fd); close(fd);
if (buffer->data == MAP_FAILED) { if (data == MAP_FAILED) {
/* FIXME: Define a real exception event instead of /* FIXME: Define a real exception event instead of
* abusing this one */ * abusing this one */
free(buffer);
wl_client_post_event(client, wl_client_post_event(client,
(struct wl_object *) compositor->wl_display, (struct wl_object *) compositor->wl_display,
WL_DISPLAY_INVALID_OBJECT, 0); WL_DISPLAY_INVALID_OBJECT, 0);
@ -146,6 +160,15 @@ shm_create_buffer(struct wl_client *client, struct wl_shm *shm,
return; return;
} }
buffer = wlsc_shm_buffer_init(compositor, width, height,
stride, visual, data);
if (buffer == NULL) {
munmap(data, stride * height);
wl_client_post_no_memory(client);
return;
}
buffer->mapped = 1;
buffer->buffer.resource.object.id = id; buffer->buffer.resource.object.id = id;
buffer->buffer.resource.object.interface = &wl_buffer_interface; buffer->buffer.resource.object.interface = &wl_buffer_interface;
buffer->buffer.resource.object.implementation = (void (**)(void)) buffer->buffer.resource.object.implementation = (void (**)(void))
@ -172,3 +195,24 @@ wlsc_shm_init(struct wlsc_compositor *ec)
return 0; return 0;
} }
struct wl_buffer *
wlsc_shm_buffer_create(struct wlsc_compositor *ec, int width, int height,
int stride, struct wl_visual *visual,
void *data)
{
struct wlsc_shm_buffer *buffer;
void *pixels;
pixels = malloc(stride * height);
if (!pixels)
return NULL;
memcpy(pixels, data, stride * height);
buffer = wlsc_shm_buffer_init(ec, width, height,
stride, visual, pixels);
buffer->mapped = 0;
return &buffer->buffer;
}

Loading…
Cancel
Save