compositor: Stop using EGL_EGLEXT_PROTOTYPES and look up extension functions
This commit is contained in:
+29
-24
@@ -27,13 +27,6 @@
|
||||
#include <xf86drm.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"
|
||||
|
||||
struct drm_compositor {
|
||||
@@ -51,6 +44,9 @@ struct drm_compositor {
|
||||
uint32_t crtc_allocator;
|
||||
uint32_t connector_allocator;
|
||||
struct tty *tty;
|
||||
|
||||
PFNEGLCREATEDRMIMAGEMESA create_drm_image;
|
||||
PFNEGLEXPORTDRMIMAGEMESA export_drm_image;
|
||||
};
|
||||
|
||||
struct drm_output {
|
||||
@@ -153,8 +149,8 @@ drm_output_prepare_scanout_surface(struct wlsc_output *output_base,
|
||||
es->image == EGL_NO_IMAGE_KHR)
|
||||
return -1;
|
||||
|
||||
eglExportDRMImageMESA(c->base.display, es->image,
|
||||
NULL, &handle, &stride);
|
||||
c->export_drm_image(c->base.display,
|
||||
es->image, NULL, &handle, &stride);
|
||||
|
||||
if (handle == 0)
|
||||
return -1;
|
||||
@@ -203,8 +199,8 @@ drm_output_set_cursor(struct wlsc_output *output_base,
|
||||
if (eid->sprite->width > 64 || eid->sprite->height > 64)
|
||||
goto out;
|
||||
|
||||
eglExportDRMImageMESA(c->base.display, eid->sprite->image,
|
||||
NULL, &handle, &stride);
|
||||
c->export_drm_image(c->base.display, eid->sprite->image,
|
||||
NULL, &handle, &stride);
|
||||
|
||||
if (stride != 64 * 4) {
|
||||
fprintf(stderr, "info: cursor stride is != 64\n");
|
||||
@@ -268,7 +264,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 = eglGetDisplay((EGLNativeDisplayType) ec->drm.fd);
|
||||
if (ec->base.display == NULL) {
|
||||
fprintf(stderr, "failed to create display\n");
|
||||
return -1;
|
||||
@@ -379,11 +375,11 @@ create_output_for_connector(struct drm_compositor *ec,
|
||||
attribs[1] = output->base.width;
|
||||
attribs[3] = output->base.height;
|
||||
output->image[i] =
|
||||
eglCreateDRMImageMESA(ec->base.display, attribs);
|
||||
glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
|
||||
output->image[i]);
|
||||
eglExportDRMImageMESA(ec->base.display, output->image[i],
|
||||
NULL, &handle, &stride);
|
||||
ec->create_drm_image(ec->base.display, attribs);
|
||||
ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER,
|
||||
output->image[i]);
|
||||
ec->export_drm_image(ec->base.display, output->image[i],
|
||||
NULL, &handle, &stride);
|
||||
|
||||
ret = drmModeAddFB(ec->drm.fd,
|
||||
output->base.width, output->base.height,
|
||||
@@ -477,7 +473,7 @@ destroy_output(struct drm_output *output)
|
||||
glDeleteRenderbuffers(2, output->rbo);
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
@@ -609,6 +605,7 @@ drm_compositor_create_cursor_image(struct wlsc_compositor *ec,
|
||||
};
|
||||
EGLint stride, name;
|
||||
EGLImageKHR tmp_image, image;
|
||||
struct drm_compositor *c = (struct drm_compositor *) ec;
|
||||
|
||||
if (width > 64 || height > 64)
|
||||
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[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)
|
||||
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[7] = 64;
|
||||
|
||||
image = eglCreateImageKHR(ec->display, EGL_NO_CONTEXT, EGL_DRM_BUFFER_MESA,
|
||||
(EGLClientBuffer)(intptr_t) name, image_attribs);
|
||||
eglExportDRMImageMESA(ec->display, image, &name, NULL, &stride);
|
||||
image = ec->create_image(ec->display,
|
||||
EGL_NO_CONTEXT,
|
||||
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;
|
||||
}
|
||||
@@ -706,6 +706,11 @@ drm_compositor_create(struct wl_display *display, int connector)
|
||||
if (wlsc_compositor_init(&ec->base, display) < 0)
|
||||
return NULL;
|
||||
|
||||
ec->create_drm_image =
|
||||
(void *) eglGetProcAddress("eglCreateDRMImageMESA");
|
||||
ec->export_drm_image =
|
||||
(void *) eglGetProcAddress("eglExportDRMImageMESA");
|
||||
|
||||
if (create_outputs(ec, connector) < 0) {
|
||||
fprintf(stderr, "failed to create output for %s\n", path);
|
||||
return NULL;
|
||||
|
||||
@@ -22,13 +22,6 @@
|
||||
|
||||
#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/wfdext.h>
|
||||
|
||||
@@ -48,6 +41,9 @@ struct wfd_compositor {
|
||||
|
||||
uint32_t start_time;
|
||||
uint32_t used_pipelines;
|
||||
|
||||
PFNEGLCREATEDRMIMAGEMESA create_drm_image;
|
||||
PFNEGLEXPORTDRMIMAGEMESA export_drm_image;
|
||||
};
|
||||
|
||||
struct wfd_output {
|
||||
@@ -261,14 +257,14 @@ create_output_for_port(struct wfd_compositor *ec,
|
||||
attribs[1] = output->base.width;
|
||||
attribs[3] = output->base.height;
|
||||
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]);
|
||||
glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
|
||||
output->image[i]);
|
||||
ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER,
|
||||
output->image[i]);
|
||||
int handle;
|
||||
eglExportDRMImageMESA(ec->base.display, output->image[i],
|
||||
NULL, &handle, NULL);
|
||||
ec->export_drm_image(ec->base.display, output->image[i],
|
||||
NULL, &handle, NULL);
|
||||
printf("handle: %d\n", handle);
|
||||
output->source[i] =
|
||||
wfdCreateSourceFromImage(ec->dev, output->pipeline,
|
||||
@@ -561,6 +557,11 @@ wfd_compositor_create(struct wl_display *display, int connector)
|
||||
if (wlsc_compositor_init(&ec->base, display) < 0)
|
||||
return NULL;
|
||||
|
||||
ec->create_drm_image =
|
||||
(void *) eglGetProcAddress("eglCreateDRMImageMESA");
|
||||
ec->export_drm_image =
|
||||
(void *) eglGetProcAddress("eglExportDRMImageMESA");
|
||||
|
||||
if (create_outputs(ec, connector) < 0) {
|
||||
fprintf(stderr, "failed to create outputs\n");
|
||||
return NULL;
|
||||
|
||||
+38
-22
@@ -250,6 +250,7 @@ destroy_surface(struct wl_resource *resource, struct wl_client *client)
|
||||
struct wlsc_surface *surface =
|
||||
container_of(resource, struct wlsc_surface, surface.resource);
|
||||
struct wl_listener *l, *next;
|
||||
struct wlsc_compositor *compositor = surface->compositor;
|
||||
uint32_t time;
|
||||
|
||||
wlsc_surface_damage(surface);
|
||||
@@ -262,8 +263,8 @@ destroy_surface(struct wl_resource *resource, struct wl_client *client)
|
||||
|
||||
|
||||
if (surface->image != EGL_NO_IMAGE_KHR)
|
||||
eglDestroyImageKHR(surface->compositor->display,
|
||||
surface->image);
|
||||
compositor->destroy_image(compositor->display,
|
||||
surface->image);
|
||||
|
||||
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_insert(surfaces_attached_to, &es->buffer_link);
|
||||
} else {
|
||||
es->image = eglCreateImageKHR(ec->display, NULL,
|
||||
EGL_WAYLAND_BUFFER_WL,
|
||||
buffer, NULL);
|
||||
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, es->image);
|
||||
es->image = ec->create_image(ec->display, NULL,
|
||||
EGL_WAYLAND_BUFFER_WL,
|
||||
buffer, NULL);
|
||||
|
||||
ec->image_target_texture_2d(GL_TEXTURE_2D, es->image);
|
||||
es->visual = buffer->visual;
|
||||
es->pitch = es->width;
|
||||
}
|
||||
@@ -386,12 +387,13 @@ static void
|
||||
wlsc_sprite_attach(struct wlsc_sprite *sprite, struct wl_surface *surface)
|
||||
{
|
||||
struct wlsc_surface *es = (struct wlsc_surface *) surface;
|
||||
struct wlsc_compositor *ec = es->compositor;
|
||||
|
||||
es->pitch = es->width;
|
||||
es->image = sprite->image;
|
||||
if (sprite->image != EGL_NO_IMAGE_KHR) {
|
||||
glBindTexture(GL_TEXTURE_2D, es->texture);
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, es->image);
|
||||
ec->image_target_texture_2d(GL_TEXTURE_2D, es->image);
|
||||
} else {
|
||||
if (es->saved_texture == 0)
|
||||
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);
|
||||
|
||||
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,
|
||||
GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);
|
||||
} else {
|
||||
@@ -1864,9 +1866,31 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display)
|
||||
wl_compositor_init(&ec->compositor, &compositor_interface, display);
|
||||
|
||||
ec->shm = wl_shm_init(display, &shm_callbacks);
|
||||
if (strstr(eglQueryString(ec->display, EGL_EXTENSIONS),
|
||||
"EGL_WL_bind_wayland_display"))
|
||||
eglBindWaylandDisplayWL(ec->display, ec->wl_display);
|
||||
|
||||
ec->image_target_texture_2d =
|
||||
(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->input_device_list);
|
||||
@@ -1885,13 +1909,6 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display)
|
||||
|
||||
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);
|
||||
|
||||
if (wlsc_shader_init(&ec->texture_shader,
|
||||
@@ -2005,9 +2022,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
wl_display_run(display);
|
||||
|
||||
if (strstr(eglQueryString(ec->display, EGL_EXTENSIONS),
|
||||
"EGL_WL_bind_wayland_display"))
|
||||
eglUnbindWaylandDisplayWL(ec->display, display);
|
||||
if (ec->has_bind_display)
|
||||
ec->unbind_display(ec->display, display);
|
||||
wl_display_destroy(display);
|
||||
|
||||
ec->destroy(ec);
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
#include "wayland-server.h"
|
||||
#include "wayland-util.h"
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#define EGL_EGLEXT_PROTOTYPES
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
#include <EGL/egl.h>
|
||||
@@ -167,6 +165,15 @@ struct wlsc_compositor {
|
||||
struct wlsc_switcher *switcher;
|
||||
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);
|
||||
int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
|
||||
EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c,
|
||||
|
||||
Reference in New Issue
Block a user