wayland: Use wayland-egl

This commit is contained in:
Kristian Høgsberg 2011-02-08 16:02:22 -05:00
parent 541d5172dd
commit 546069f434
3 changed files with 31 additions and 84 deletions

View File

@ -40,7 +40,7 @@
#include "gdkdevicemanager-wayland.h"
#include "gdkkeysprivate.h"
#include <xf86drm.h>
#include <wayland-egl.h>
typedef struct _GdkEventTypeWayland GdkEventTypeWayland;
@ -120,28 +120,6 @@ gdk_input_init (GdkDisplay *display)
g_list_free (list);
}
static void
drm_handle_device(void *data, struct wl_drm *compositor, const char *device)
{
GdkDisplayWayland *display_wayland = data;
fprintf(stderr, "display name: %s\n", device);
display_wayland->device_name = g_strdup (device);
}
static void drm_handle_authenticated(void *data, struct wl_drm *drm)
{
GdkDisplayWayland *display_wayland = data;
display_wayland->authenticated = TRUE;
}
static const struct wl_drm_listener drm_listener = {
drm_handle_device,
drm_handle_authenticated
};
static void
shell_handle_configure(void *data, struct wl_shell *shell,
uint32_t time, uint32_t edges,
@ -205,10 +183,6 @@ gdk_display_handle_global(struct wl_display *display, uint32_t id,
if (strcmp(interface, "compositor") == 0) {
display_wayland->compositor = wl_compositor_create(display, id);
} else if (strcmp(interface, "drm") == 0) {
display_wayland->drm = wl_drm_create(display, id);
wl_drm_add_listener(display_wayland->drm,
&drm_listener, display_wayland);
} else if (strcmp(interface, "shell") == 0) {
display_wayland->shell = wl_shell_create(display, id);
wl_shell_add_listener(display_wayland->shell,
@ -228,36 +202,17 @@ gdk_display_init_egl(GdkDisplay *display)
{
GdkDisplayWayland *display_wayland = GDK_DISPLAY_WAYLAND (display);
EGLint major, minor, i;
drm_magic_t magic;
void *p;
static const struct { const char *f; unsigned int offset; }
extension_functions[] = {
{ "eglCreateDRMImageMESA", offsetof(GdkDisplayWayland, create_drm_image) },
{ "glEGLImageTargetTexture2DOES", offsetof(GdkDisplayWayland, image_target_texture_2d) },
{ "eglExportDRMImageMESA", offsetof(GdkDisplayWayland, export_drm_image) },
{ "eglCreateImageKHR", offsetof(GdkDisplayWayland, create_image) },
{ "eglDestroyImageKHR", offsetof(GdkDisplayWayland, destroy_image) }
};
display_wayland->fd = open(display_wayland->device_name, O_RDWR);
if (display_wayland->fd < 0) {
fprintf(stderr, "drm open failed: %m\n");
return FALSE;
}
if (drmGetMagic(display_wayland->fd, &magic))
{
fprintf(stderr, "DRI2: failed to get drm magic");
return FALSE;
}
/* Authenticate and wait for authenticated event */
wl_drm_authenticate(display_wayland->drm, magic);
wl_display_iterate(display_wayland->wl_display, WL_DISPLAY_WRITABLE);
while (!display_wayland->authenticated)
wl_display_iterate(display_wayland->wl_display, WL_DISPLAY_READABLE);
display_wayland->egl_display = eglGetDRMDisplayMESA(display_wayland->fd);
display_wayland->egl_display =
eglGetDisplay((EGLNativeDisplayType) display_wayland->native_display);
if (!eglInitialize(display_wayland->egl_display, &major, &minor)) {
fprintf(stderr, "failed to initialize display\n");
return FALSE;
@ -318,6 +273,12 @@ _gdk_wayland_display_open (const gchar *display_name)
display_wayland->wl_display = wl_display;
display_wayland->native_display = wl_egl_display_create(wl_display);
if (display_wayland->native_display == NULL) {
wl_display_destroy(wl_display);
return NULL;
}
/* initialize the display's screens */
display_wayland->screens = g_new (GdkScreen *, 1);
for (i = 0; i < 1; i++)
@ -332,9 +293,6 @@ _gdk_wayland_display_open (const gchar *display_name)
wl_display_add_global_listener(display_wayland->wl_display,
gdk_display_handle_global, display_wayland);
/* Process connection events. */
wl_display_iterate(display_wayland->wl_display, WL_DISPLAY_READABLE);
gdk_display_init_egl(display);
display_wayland->event_source = _gdk_wayland_display_event_source_new (display);
@ -369,6 +327,9 @@ gdk_wayland_display_dispose (GObject *object)
display_wayland->event_source = NULL;
}
eglTerminate(display_wayland->egl_display);
wl_egl_display_destroy(display_wayland->native_display);
G_OBJECT_CLASS (_gdk_display_wayland_parent_class)->dispose (object);
}

View File

@ -28,6 +28,8 @@
#include <wayland-client.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <cairo-gl.h>
#include <glib.h>
#include <gdk/gdkkeys.h>
@ -139,23 +141,19 @@ struct _GdkDisplayWayland
GdkWindow *active_offscreen_window;
/* Wayland fields below */
char *device_name;
struct wl_display *wl_display;
struct wl_drm *drm;
struct wl_egl_display *native_display;
struct wl_compositor *compositor;
struct wl_shell *shell;
struct wl_output *output;
struct wl_input_device *input_device;
GSource *event_source;
int fd;
EGLDisplay egl_display;
EGLContext egl_context;
cairo_device_t *cairo_device;
int authenticated;
PFNEGLCREATEDRMIMAGEMESA create_drm_image;
PFNEGLEXPORTDRMIMAGEMESA export_drm_image;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
PFNEGLCREATEIMAGEKHRPROC create_image;
PFNEGLDESTROYIMAGEKHRPROC destroy_image;
};

View File

@ -40,6 +40,8 @@
#include <stdio.h>
#include <string.h>
#include <wayland-egl.h>
#define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \
(GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \
GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN)
@ -295,6 +297,7 @@ static const cairo_user_data_key_t gdk_wayland_cairo_key;
typedef struct _GdkWaylandCairoSurfaceData {
EGLImageKHR image;
GLuint texture;
struct wl_egl_pixmap *pixmap;
struct wl_buffer *buffer;
GdkDisplayWayland *display;
} GdkWaylandCairoSurfaceData;
@ -304,24 +307,12 @@ _gdk_wayland_surface_get_buffer (GdkDisplayWayland *display,
cairo_surface_t *surface)
{
GdkWaylandCairoSurfaceData *data;
EGLint name, stride;
struct wl_visual *visual;
int width, height;
data = cairo_surface_get_user_data (surface, &gdk_wayland_cairo_key);
if (data->buffer)
return data->buffer;
visual =
wl_display_get_premultiplied_argb_visual(display->wl_display);
width = cairo_gl_surface_get_width (surface);
height = cairo_gl_surface_get_height (surface);
display->export_drm_image (display->egl_display,
data->image, &name, NULL, &stride);
data->buffer = wl_drm_create_buffer(display->drm,
name, width, height, stride, visual);
if (!data->buffer)
data->buffer =
wl_egl_pixmap_create_buffer(display->native_display, data->pixmap);
return data->buffer;
}
@ -387,21 +378,18 @@ gdk_wayland_create_cairo_surface (GdkDisplayWayland *display,
{
GdkWaylandCairoSurfaceData *data;
cairo_surface_t *surface;
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
};
struct wl_visual *visual;
data = g_new (GdkWaylandCairoSurfaceData, 1);
data->display = display;
data->buffer = NULL;
image_attribs[1] = width;
image_attribs[3] = height;
data->image = display->create_drm_image(display->egl_display, image_attribs);
visual = wl_display_get_premultiplied_argb_visual(display->wl_display);
data->pixmap =
wl_egl_pixmap_create(display->native_display, width, height, visual, 0);
data->image =
display->create_image(display->egl_display, NULL, EGL_NATIVE_PIXMAP_KHR,
(EGLClientBuffer) data->pixmap, NULL);
glGenTextures(1, &data->texture);
glBindTexture(GL_TEXTURE_2D, data->texture);
display->image_target_texture_2d(GL_TEXTURE_2D, data->image);