compositor: Stop using EGL_EGLEXT_PROTOTYPES and look up extension functions

dev
Kristian Høgsberg 14 years ago
parent c352ab03fe
commit b5819dc61d
  1. 47
      compositor/compositor-drm.c
  2. 21
      compositor/compositor-openwfd.c
  3. 52
      compositor/compositor.c
  4. 11
      compositor/compositor.h

@ -27,13 +27,6 @@
#include <xf86drm.h> #include <xf86drm.h>
#include <xf86drmMode.h> #include <xf86drmMode.h>
#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "compositor.h" #include "compositor.h"
struct drm_compositor { struct drm_compositor {
@ -51,6 +44,9 @@ struct drm_compositor {
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_output { struct drm_output {
@ -153,8 +149,8 @@ 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;
eglExportDRMImageMESA(c->base.display, es->image, c->export_drm_image(c->base.display,
NULL, &handle, &stride); es->image, NULL, &handle, &stride);
if (handle == 0) if (handle == 0)
return -1; return -1;
@ -203,7 +199,7 @@ 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;
eglExportDRMImageMESA(c->base.display, eid->sprite->image, c->export_drm_image(c->base.display, eid->sprite->image,
NULL, &handle, &stride); NULL, &handle, &stride);
if (stride != 64 * 4) { if (stride != 64 * 4) {
@ -268,7 +264,7 @@ init_egl(struct drm_compositor *ec, struct udev_device *device)
} }
ec->drm.fd = fd; ec->drm.fd = fd;
ec->base.display = eglGetDRMDisplayMESA(ec->drm.fd); ec->base.display = eglGetDisplay((EGLNativeDisplayType) ec->drm.fd);
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;
@ -379,10 +375,10 @@ create_output_for_connector(struct drm_compositor *ec,
attribs[1] = output->base.width; attribs[1] = output->base.width;
attribs[3] = output->base.height; attribs[3] = output->base.height;
output->image[i] = output->image[i] =
eglCreateDRMImageMESA(ec->base.display, attribs); ec->create_drm_image(ec->base.display, attribs);
glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER,
output->image[i]); output->image[i]);
eglExportDRMImageMESA(ec->base.display, output->image[i], ec->export_drm_image(ec->base.display, output->image[i],
NULL, &handle, &stride); NULL, &handle, &stride);
ret = drmModeAddFB(ec->drm.fd, ret = drmModeAddFB(ec->drm.fd,
@ -477,7 +473,7 @@ destroy_output(struct drm_output *output)
glDeleteRenderbuffers(2, output->rbo); glDeleteRenderbuffers(2, output->rbo);
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
eglDestroyImageKHR(ec->base.display, output->image[i]); ec->base.destroy_image(ec->base.display, output->image[i]);
drmModeRmFB(ec->drm.fd, output->fb_id[i]); drmModeRmFB(ec->drm.fd, output->fb_id[i]);
} }
@ -609,6 +605,7 @@ drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
}; };
EGLint stride, name; EGLint stride, name;
EGLImageKHR tmp_image, image; EGLImageKHR tmp_image, image;
struct drm_compositor *c = (struct drm_compositor *) ec;
if (width > 64 || height > 64) if (width > 64 || height > 64)
return EGL_NO_IMAGE_KHR; return EGL_NO_IMAGE_KHR;
@ -618,9 +615,9 @@ drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
image_attribs[6] = EGL_DRM_BUFFER_USE_MESA; image_attribs[6] = EGL_DRM_BUFFER_USE_MESA;
image_attribs[7] = EGL_DRM_BUFFER_USE_SCANOUT_MESA; image_attribs[7] = EGL_DRM_BUFFER_USE_SCANOUT_MESA;
tmp_image = eglCreateDRMImageMESA(ec->display, image_attribs); tmp_image = c->create_drm_image(ec->display, image_attribs);
eglExportDRMImageMESA(ec->display, tmp_image, &name, NULL, &stride); c->export_drm_image(ec->display, tmp_image, &name, NULL, &stride);
if (stride == 64) if (stride == 64)
return tmp_image; return tmp_image;
@ -631,11 +628,14 @@ drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
image_attribs[6] = EGL_DRM_BUFFER_STRIDE_MESA; image_attribs[6] = EGL_DRM_BUFFER_STRIDE_MESA;
image_attribs[7] = 64; image_attribs[7] = 64;
image = eglCreateImageKHR(ec->display, EGL_NO_CONTEXT, EGL_DRM_BUFFER_MESA, image = ec->create_image(ec->display,
(EGLClientBuffer)(intptr_t) name, image_attribs); EGL_NO_CONTEXT,
eglExportDRMImageMESA(ec->display, image, &name, NULL, &stride); EGL_DRM_BUFFER_MESA,
(EGLClientBuffer)(intptr_t) name,
image_attribs);
c->export_drm_image(ec->display, image, &name, NULL, &stride);
eglDestroyImageKHR(ec->display, tmp_image); ec->destroy_image(ec->display, tmp_image);
return image; return image;
} }
@ -706,6 +706,11 @@ drm_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 output for %s\n", path); fprintf(stderr, "failed to create output for %s\n", path);
return NULL; return NULL;

@ -22,13 +22,6 @@
#include <sys/time.h> #include <sys/time.h>
#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <WF/wfd.h> #include <WF/wfd.h>
#include <WF/wfdext.h> #include <WF/wfdext.h>
@ -48,6 +41,9 @@ 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 {
@ -261,13 +257,13 @@ create_output_for_port(struct wfd_compositor *ec,
attribs[1] = output->base.width; attribs[1] = output->base.width;
attribs[3] = output->base.height; attribs[3] = output->base.height;
output->image[i] = output->image[i] =
eglCreateDRMImageMESA(ec->base.display, attribs); ec->create_drm_image(ec->base.display, attribs);
printf("output->image[i]: %p\n", output->image[i]); printf("output->image[i]: %p\n", output->image[i]);
glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER,
output->image[i]); output->image[i]);
int handle; int handle;
eglExportDRMImageMESA(ec->base.display, output->image[i], ec->export_drm_image(ec->base.display, output->image[i],
NULL, &handle, NULL); NULL, &handle, NULL);
printf("handle: %d\n", handle); printf("handle: %d\n", handle);
output->source[i] = output->source[i] =
@ -561,6 +557,11 @@ 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;

@ -250,6 +250,7 @@ destroy_surface(struct wl_resource *resource, struct wl_client *client)
struct wlsc_surface *surface = struct wlsc_surface *surface =
container_of(resource, struct wlsc_surface, surface.resource); container_of(resource, struct wlsc_surface, surface.resource);
struct wl_listener *l, *next; struct wl_listener *l, *next;
struct wlsc_compositor *compositor = surface->compositor;
uint32_t time; uint32_t time;
wlsc_surface_damage(surface); wlsc_surface_damage(surface);
@ -262,7 +263,7 @@ destroy_surface(struct wl_resource *resource, struct wl_client *client)
if (surface->image != EGL_NO_IMAGE_KHR) if (surface->image != EGL_NO_IMAGE_KHR)
eglDestroyImageKHR(surface->compositor->display, compositor->destroy_image(compositor->display,
surface->image); surface->image);
wl_list_remove(&surface->buffer_link); wl_list_remove(&surface->buffer_link);
@ -372,11 +373,11 @@ wlsc_buffer_attach(struct wl_buffer *buffer, struct wl_surface *surface)
wl_list_remove(&es->buffer_link); wl_list_remove(&es->buffer_link);
wl_list_insert(surfaces_attached_to, &es->buffer_link); wl_list_insert(surfaces_attached_to, &es->buffer_link);
} else { } else {
es->image = eglCreateImageKHR(ec->display, NULL, es->image = ec->create_image(ec->display, NULL,
EGL_WAYLAND_BUFFER_WL, EGL_WAYLAND_BUFFER_WL,
buffer, NULL); buffer, NULL);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, es->image); ec->image_target_texture_2d(GL_TEXTURE_2D, es->image);
es->visual = buffer->visual; es->visual = buffer->visual;
es->pitch = es->width; es->pitch = es->width;
} }
@ -386,12 +387,13 @@ static void
wlsc_sprite_attach(struct wlsc_sprite *sprite, struct wl_surface *surface) wlsc_sprite_attach(struct wlsc_sprite *sprite, struct wl_surface *surface)
{ {
struct wlsc_surface *es = (struct wlsc_surface *) surface; struct wlsc_surface *es = (struct wlsc_surface *) surface;
struct wlsc_compositor *ec = es->compositor;
es->pitch = es->width; es->pitch = es->width;
es->image = sprite->image; es->image = sprite->image;
if (sprite->image != EGL_NO_IMAGE_KHR) { if (sprite->image != EGL_NO_IMAGE_KHR) {
glBindTexture(GL_TEXTURE_2D, es->texture); glBindTexture(GL_TEXTURE_2D, es->texture);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, es->image); ec->image_target_texture_2d(GL_TEXTURE_2D, es->image);
} else { } else {
if (es->saved_texture == 0) if (es->saved_texture == 0)
es->saved_texture = es->texture; es->saved_texture = es->texture;
@ -439,7 +441,7 @@ create_sprite_from_png(struct wlsc_compositor *ec,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (sprite->image != EGL_NO_IMAGE_KHR) { if (sprite->image != EGL_NO_IMAGE_KHR) {
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, sprite->image); ec->image_target_texture_2d(GL_TEXTURE_2D, sprite->image);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels); GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
} else { } else {
@ -1864,9 +1866,31 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display)
wl_compositor_init(&ec->compositor, &compositor_interface, display); wl_compositor_init(&ec->compositor, &compositor_interface, display);
ec->shm = wl_shm_init(display, &shm_callbacks); ec->shm = wl_shm_init(display, &shm_callbacks);
if (strstr(eglQueryString(ec->display, EGL_EXTENSIONS),
"EGL_WL_bind_wayland_display")) ec->image_target_texture_2d =
eglBindWaylandDisplayWL(ec->display, ec->wl_display); (void *) eglGetProcAddress("glEGLImageTargetTexture2DOES");
ec->image_target_renderbuffer_storage = (void *)
eglGetProcAddress("glEGLImageTargetRenderbufferStorageOES");
ec->create_image = (void *) eglGetProcAddress("eglCreateImageKHR");
ec->destroy_image = (void *) eglGetProcAddress("eglDestroyImageKHR");
ec->bind_display =
(void *) eglGetProcAddress("eglBindWaylandDisplayWL");
ec->unbind_display =
(void *) eglGetProcAddress("eglUnbindWaylandDisplayWL");
extensions = (const char *) glGetString(GL_EXTENSIONS);
if (!strstr(extensions, "GL_EXT_texture_format_BGRA8888")) {
fprintf(stderr,
"GL_EXT_texture_format_BGRA8888 not available\n");
return -1;
}
extensions =
(const char *) eglQueryString(ec->display, EGL_EXTENSIONS);
if (strstr(extensions, "EGL_WL_bind_wayland_display"))
ec->has_bind_display = 1;
if (ec->has_bind_display)
ec->bind_display(ec->display, ec->wl_display);
wl_list_init(&ec->surface_list); wl_list_init(&ec->surface_list);
wl_list_init(&ec->input_device_list); wl_list_init(&ec->input_device_list);
@ -1885,13 +1909,6 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display)
screenshooter_create(ec); screenshooter_create(ec);
extensions = (const char *) glGetString(GL_EXTENSIONS);
if (!strstr(extensions, "GL_EXT_texture_format_BGRA8888")) {
fprintf(stderr,
"GL_EXT_texture_format_BGRA8888 not available\n");
return -1;
}
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
if (wlsc_shader_init(&ec->texture_shader, if (wlsc_shader_init(&ec->texture_shader,
@ -2005,9 +2022,8 @@ int main(int argc, char *argv[])
wl_display_run(display); wl_display_run(display);
if (strstr(eglQueryString(ec->display, EGL_EXTENSIONS), if (ec->has_bind_display)
"EGL_WL_bind_wayland_display")) ec->unbind_display(ec->display, display);
eglUnbindWaylandDisplayWL(ec->display, display);
wl_display_destroy(display); wl_display_destroy(display);
ec->destroy(ec); ec->destroy(ec);

@ -24,8 +24,6 @@
#include "wayland-server.h" #include "wayland-server.h"
#include "wayland-util.h" #include "wayland-util.h"
#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#include <EGL/egl.h> #include <EGL/egl.h>
@ -167,6 +165,15 @@ struct wlsc_compositor {
struct wlsc_switcher *switcher; struct wlsc_switcher *switcher;
uint32_t focus; uint32_t focus;
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
image_target_renderbuffer_storage;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
PFNEGLCREATEIMAGEKHRPROC create_image;
PFNEGLDESTROYIMAGEKHRPROC destroy_image;
PFNEGLBINDWAYLANDDISPLAYWL bind_display;
PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
int has_bind_display;
void (*destroy)(struct wlsc_compositor *ec); void (*destroy)(struct wlsc_compositor *ec);
int (*authenticate)(struct wlsc_compositor *c, uint32_t id); int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c, EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c,

Loading…
Cancel
Save