mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-06 13:29:48 -05:00
Use eglBindTexImage instead of copying texture data.
This commit is contained in:
parent
ca1d1f65d0
commit
2d9cd1ee51
1 changed files with 15 additions and 60 deletions
|
|
@ -21,15 +21,15 @@ struct egl_compositor {
|
||||||
EGLDisplay display;
|
EGLDisplay display;
|
||||||
EGLSurface surface;
|
EGLSurface surface;
|
||||||
EGLContext context;
|
EGLContext context;
|
||||||
|
EGLConfig config;
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
int gem_fd;
|
int gem_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct surface_data {
|
struct surface_data {
|
||||||
uint32_t handle;
|
|
||||||
int32_t width, height, stride;
|
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
struct wl_map map;
|
struct wl_map map;
|
||||||
|
EGLSurface surface;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -102,7 +102,7 @@ void notify_surface_create(struct wl_compositor *compositor,
|
||||||
if (sd == NULL)
|
if (sd == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sd->handle = 0;
|
sd->surface = EGL_NO_SURFACE;
|
||||||
wl_surface_set_data(surface, sd);
|
wl_surface_set_data(surface, sd);
|
||||||
|
|
||||||
glGenTextures(1, &sd->texture);
|
glGenTextures(1, &sd->texture);
|
||||||
|
|
@ -113,18 +113,13 @@ void notify_surface_destroy(struct wl_compositor *compositor,
|
||||||
{
|
{
|
||||||
struct egl_compositor *ec = (struct egl_compositor *) compositor;
|
struct egl_compositor *ec = (struct egl_compositor *) compositor;
|
||||||
struct surface_data *sd;
|
struct surface_data *sd;
|
||||||
struct drm_gem_close close_arg;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
sd = wl_surface_get_data(surface);
|
sd = wl_surface_get_data(surface);
|
||||||
if (sd == NULL || sd->handle == 0)
|
if (sd == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
close_arg.handle = sd->handle;
|
if (sd->surface != EGL_NO_SURFACE)
|
||||||
ret = ioctl(ec->gem_fd, DRM_IOCTL_GEM_CLOSE, &close_arg);
|
eglDestroySurface(ec->display, sd->surface);
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "failed to gem_close handle %d: %m\n", sd->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
glDeleteTextures(1, &sd->texture);
|
glDeleteTextures(1, &sd->texture);
|
||||||
|
|
||||||
|
|
@ -139,64 +134,23 @@ void notify_surface_attach(struct wl_compositor *compositor,
|
||||||
{
|
{
|
||||||
struct egl_compositor *ec = (struct egl_compositor *) compositor;
|
struct egl_compositor *ec = (struct egl_compositor *) compositor;
|
||||||
struct surface_data *sd;
|
struct surface_data *sd;
|
||||||
struct drm_gem_open open_arg;
|
|
||||||
struct drm_gem_close close_arg;
|
|
||||||
struct drm_i915_gem_pread pread;
|
|
||||||
void *data;
|
|
||||||
uint32_t size;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
sd = wl_surface_get_data(surface);
|
sd = wl_surface_get_data(surface);
|
||||||
if (sd == NULL)
|
if (sd == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sd->handle != 0) {
|
if (sd->surface != EGL_NO_SURFACE)
|
||||||
close_arg.handle = sd->handle;
|
eglDestroySurface(ec->display, sd->surface);
|
||||||
ret = ioctl(ec->gem_fd, DRM_IOCTL_GEM_CLOSE, &close_arg);
|
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "failed to gem_close name %d: %m\n", name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
open_arg.name = name;
|
sd->surface = eglCreatePixmapForName(ec->display, ec->config,
|
||||||
ret = ioctl(ec->gem_fd, DRM_IOCTL_GEM_OPEN, &open_arg);
|
name, width, height, stride, NULL);
|
||||||
if (ret != 0) {
|
|
||||||
fprintf(stderr, "failed to gem_open name %d, fd=%d: %m\n", name, ec->gem_fd);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sd->handle = open_arg.handle;
|
|
||||||
sd->width = width;
|
|
||||||
sd->height = height;
|
|
||||||
sd->stride = stride;
|
|
||||||
|
|
||||||
size = sd->height * sd->stride;
|
|
||||||
data = malloc(size);
|
|
||||||
if (data == NULL) {
|
|
||||||
fprintf(stderr, "swap buffers malloc failed\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pread.handle = sd->handle;
|
|
||||||
pread.pad = 0;
|
|
||||||
pread.offset = 0;
|
|
||||||
pread.size = size;
|
|
||||||
pread.data_ptr = (long) data;
|
|
||||||
|
|
||||||
if (ioctl(ec->gem_fd, DRM_IOCTL_I915_GEM_PREAD, &pread)) {
|
|
||||||
fprintf(stderr, "gem pread failed\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, sd->texture);
|
glBindTexture(GL_TEXTURE_2D, sd->texture);
|
||||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
eglBindTexImage(ec->display, sd->surface, GL_TEXTURE_2D);
|
||||||
GL_BGRA, GL_UNSIGNED_BYTE, data);
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
|
|
||||||
schedule_repaint(ec);
|
schedule_repaint(ec);
|
||||||
}
|
}
|
||||||
|
|
@ -256,14 +210,15 @@ wl_compositor_create(struct wl_display *display)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ec->surface = eglCreateSurfaceNative(ec->display, configs[24],
|
ec->config = configs[24];
|
||||||
|
ec->surface = eglCreateSurfaceNative(ec->display, ec->config,
|
||||||
0, 0, width, height);
|
0, 0, width, height);
|
||||||
if (ec->surface == NULL) {
|
if (ec->surface == NULL) {
|
||||||
fprintf(stderr, "failed to create surface\n");
|
fprintf(stderr, "failed to create surface\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ec->context = eglCreateContext(ec->display, configs[24], NULL, NULL);
|
ec->context = eglCreateContext(ec->display, ec->config, NULL, NULL);
|
||||||
if (ec->context == NULL) {
|
if (ec->context == NULL) {
|
||||||
fprintf(stderr, "failed to create context\n");
|
fprintf(stderr, "failed to create context\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue