mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-31 22:25:25 -04:00
Use FBOs instead of eagle-specific API
This commit is contained in:
parent
450cc8136d
commit
a341fa016c
7 changed files with 127 additions and 129 deletions
|
|
@ -8,8 +8,9 @@ libs = libwayland-server.so libwayland.so
|
||||||
egl_clients = gears
|
egl_clients = gears
|
||||||
cairo_clients = flower screenshot terminal image view
|
cairo_clients = flower screenshot terminal image view
|
||||||
compositors = wayland-system-compositor
|
compositors = wayland-system-compositor
|
||||||
|
clients = $(egl_clients) $(cairo_clients)
|
||||||
|
|
||||||
all : $(libs) $(compositors) $(egl_clients) $(cairo_clients)
|
all : $(libs) $(compositors) $(clients)
|
||||||
|
|
||||||
libwayland-server.so : \
|
libwayland-server.so : \
|
||||||
wayland.o \
|
wayland.o \
|
||||||
|
|
@ -36,7 +37,7 @@ wayland-system-compositor : \
|
||||||
wayland-util.o
|
wayland-util.o
|
||||||
|
|
||||||
wayland-system-compositor : CFLAGS += @EGL_COMPOSITOR_CFLAGS@
|
wayland-system-compositor : CFLAGS += @EGL_COMPOSITOR_CFLAGS@
|
||||||
wayland-system-compositor : LDLIBS += -L. -lwayland-server @EGL_COMPOSITOR_LIBS@ -rdynamic -lrt
|
wayland-system-compositor : LDLIBS += ./libwayland-server.so @EGL_COMPOSITOR_LIBS@ -rdynamic -lrt
|
||||||
|
|
||||||
flower : flower.o wayland-glib.o
|
flower : flower.o wayland-glib.o
|
||||||
gears : gears.o window.o wayland-glib.o cairo-util.o
|
gears : gears.o window.o wayland-glib.o cairo-util.o
|
||||||
|
|
@ -54,7 +55,7 @@ view : LDLIBS += @POPPLER_LIBS@
|
||||||
$(egl_clients) : CFLAGS += @EGL_CLIENT_CFLAGS@
|
$(egl_clients) : CFLAGS += @EGL_CLIENT_CFLAGS@
|
||||||
$(egl_clients) : LDLIBS += -L. -lwayland @EGL_CLIENT_LIBS@ -lrt
|
$(egl_clients) : LDLIBS += -L. -lwayland @EGL_CLIENT_LIBS@ -lrt
|
||||||
$(cairo_clients) : CFLAGS += @CAIRO_CLIENT_CFLAGS@
|
$(cairo_clients) : CFLAGS += @CAIRO_CLIENT_CFLAGS@
|
||||||
$(cairo_clients) : LDLIBS += -L. -lwayland @CAIRO_CLIENT_LIBS@ -lrt
|
$(cairo_clients) : LDLIBS += ./libwayland.so @CAIRO_CLIENT_LIBS@ -lrt
|
||||||
|
|
||||||
install : $(libs) $(compositors)
|
install : $(libs) $(compositors)
|
||||||
install -d @libdir@ @libdir@/pkgconfig ${udev_rules_dir}
|
install -d @libdir@ @libdir@/pkgconfig ${udev_rules_dir}
|
||||||
|
|
|
||||||
92
gears.c
92
gears.c
|
|
@ -32,6 +32,7 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <cairo-drm.h>
|
#include <cairo-drm.h>
|
||||||
|
|
||||||
|
#define GL_GLEXT_PROTOTYPES
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <eagle.h>
|
#include <eagle.h>
|
||||||
|
|
||||||
|
|
@ -52,14 +53,13 @@ struct gears {
|
||||||
struct rectangle rectangle;
|
struct rectangle rectangle;
|
||||||
|
|
||||||
EGLDisplay display;
|
EGLDisplay display;
|
||||||
EGLConfig config;
|
|
||||||
EGLSurface surface;
|
|
||||||
EGLContext context;
|
EGLContext context;
|
||||||
int resized;
|
int resized;
|
||||||
GLfloat angle;
|
GLfloat angle;
|
||||||
cairo_surface_t *cairo_surface;
|
cairo_surface_t *cairo_surface;
|
||||||
|
|
||||||
GLint gear_list[3];
|
GLint gear_list[3];
|
||||||
|
GLuint fbo, color_rbo, depth_rbo;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gear_template {
|
struct gear_template {
|
||||||
|
|
@ -258,19 +258,20 @@ resize_window(struct gears *gears)
|
||||||
|
|
||||||
window_draw(gears->window);
|
window_draw(gears->window);
|
||||||
|
|
||||||
if (gears->surface != NULL)
|
glBindRenderbuffer(GL_RENDERBUFFER_EXT, gears->color_rbo);
|
||||||
eglDestroySurface(gears->display, gears->surface);
|
glRenderbufferStorage(GL_RENDERBUFFER_EXT,
|
||||||
|
GL_RGBA,
|
||||||
|
gears->rectangle.width,
|
||||||
|
gears->rectangle.height);
|
||||||
|
|
||||||
gears->surface = eglCreateSurface(gears->display,
|
glBindRenderbuffer(GL_RENDERBUFFER_EXT, gears->depth_rbo);
|
||||||
gears->config,
|
glRenderbufferStorage(GL_RENDERBUFFER_EXT,
|
||||||
gears->rectangle.width,
|
GL_DEPTH_COMPONENT,
|
||||||
gears->rectangle.height,
|
gears->rectangle.width,
|
||||||
1, NULL);
|
gears->rectangle.height);
|
||||||
|
|
||||||
eglMakeCurrent(gears->display,
|
|
||||||
gears->surface, gears->surface, gears->context);
|
|
||||||
|
|
||||||
glViewport(0, 0, gears->rectangle.width, gears->rectangle.height);
|
glViewport(0, 0, gears->rectangle.width, gears->rectangle.height);
|
||||||
|
|
||||||
gears->resized = 0;
|
gears->resized = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -308,13 +309,12 @@ handle_acknowledge(void *data,
|
||||||
{
|
{
|
||||||
struct gears *gears = data;
|
struct gears *gears = data;
|
||||||
|
|
||||||
if (key != 0)
|
if (key == 10) {
|
||||||
return;
|
if (gears->resized)
|
||||||
|
resize_window(gears);
|
||||||
|
|
||||||
if (gears->resized)
|
draw_gears(gears);
|
||||||
resize_window(gears);
|
}
|
||||||
|
|
||||||
draw_gears(gears);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -322,14 +322,20 @@ handle_frame(void *data,
|
||||||
struct wl_compositor *compositor,
|
struct wl_compositor *compositor,
|
||||||
uint32_t frame, uint32_t timestamp)
|
uint32_t frame, uint32_t timestamp)
|
||||||
{
|
{
|
||||||
struct gears *gears = data;
|
struct gears *gears = data;
|
||||||
uint32_t name, handle, stride;
|
GLint name, stride;
|
||||||
|
|
||||||
eglGetColorBuffer(gears->surface, 0, &name, &handle, &stride);
|
glBindRenderbuffer(GL_RENDERBUFFER_EXT, gears->color_rbo);
|
||||||
|
glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,
|
||||||
|
GL_RENDERBUFFER_STRIDE_INTEL,
|
||||||
|
&stride);
|
||||||
|
glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,
|
||||||
|
GL_RENDERBUFFER_NAME_INTEL,
|
||||||
|
&name);
|
||||||
|
|
||||||
window_copy(gears->window, &gears->rectangle, name, stride);
|
window_copy(gears->window, &gears->rectangle, name, stride);
|
||||||
|
|
||||||
wl_compositor_commit(gears->compositor, 0);
|
window_commit(gears->window, 10);
|
||||||
|
|
||||||
gears->angle = (GLfloat) (timestamp % 8192) * 360 / 8192.0;
|
gears->angle = (GLfloat) (timestamp % 8192) * 360 / 8192.0;
|
||||||
}
|
}
|
||||||
|
|
@ -339,19 +345,11 @@ static const struct wl_compositor_listener compositor_listener = {
|
||||||
handle_frame,
|
handle_frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const EGLint config_attribs[] = {
|
|
||||||
EGL_DEPTH_SIZE, 24,
|
|
||||||
EGL_CONFIG_CAVEAT, EGL_NONE,
|
|
||||||
EGL_RED_SIZE, 8,
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct gears *
|
static struct gears *
|
||||||
gears_create(struct display *display)
|
gears_create(struct display *display)
|
||||||
{
|
{
|
||||||
const int x = 200, y = 200, width = 450, height = 500;
|
const int x = 200, y = 200, width = 450, height = 500;
|
||||||
EGLint major, minor, count;
|
EGLint major, minor;
|
||||||
EGLConfig configs[64];
|
|
||||||
struct udev *udev;
|
struct udev *udev;
|
||||||
struct udev_device *device;
|
struct udev_device *device;
|
||||||
struct gears *gears;
|
struct gears *gears;
|
||||||
|
|
@ -373,18 +371,29 @@ gears_create(struct display *display)
|
||||||
if (!eglInitialize(gears->display, &major, &minor))
|
if (!eglInitialize(gears->display, &major, &minor))
|
||||||
die("failed to initialize display\n");
|
die("failed to initialize display\n");
|
||||||
|
|
||||||
if (!eglGetConfigs(gears->display, configs, 64, &count))
|
gears->context = eglCreateContext(gears->display, NULL, NULL, NULL);
|
||||||
die("failed to get configs\n");
|
|
||||||
|
|
||||||
if (!eglChooseConfig(gears->display, config_attribs, &gears->config, 1, NULL))
|
|
||||||
die("failed to pick a config\n");
|
|
||||||
|
|
||||||
gears->context = eglCreateContext(gears->display, gears->config, NULL, NULL);
|
|
||||||
if (gears->context == NULL)
|
if (gears->context == NULL)
|
||||||
die("failed to create context\n");
|
die("failed to create context\n");
|
||||||
|
|
||||||
resize_window(gears);
|
if (!eglMakeCurrent(gears->display, NULL, NULL, gears->context))
|
||||||
|
die("faile to make context current\n");
|
||||||
|
|
||||||
|
glGenFramebuffers(1, &gears->fbo);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER_EXT, gears->fbo);
|
||||||
|
|
||||||
|
glGenRenderbuffers(1, &gears->color_rbo);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER_EXT, gears->color_rbo);
|
||||||
|
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT,
|
||||||
|
GL_COLOR_ATTACHMENT0_EXT,
|
||||||
|
GL_RENDERBUFFER_EXT,
|
||||||
|
gears->color_rbo);
|
||||||
|
|
||||||
|
glGenRenderbuffers(1, &gears->depth_rbo);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER_EXT, gears->depth_rbo);
|
||||||
|
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT,
|
||||||
|
GL_DEPTH_ATTACHMENT_EXT,
|
||||||
|
GL_RENDERBUFFER_EXT,
|
||||||
|
gears->depth_rbo);
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
gears->gear_list[i] = glGenLists(1);
|
gears->gear_list[i] = glGenLists(1);
|
||||||
glNewList(gears->gear_list[i], GL_COMPILE);
|
glNewList(gears->gear_list[i], GL_COMPILE);
|
||||||
|
|
@ -406,10 +415,13 @@ gears_create(struct display *display)
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glClearColor(0, 0, 0, 0.92);
|
glClearColor(0, 0, 0, 0.92);
|
||||||
|
|
||||||
|
if (glCheckFramebufferStatus (GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE)
|
||||||
|
fprintf(stderr, "framebuffer incomplete\n");
|
||||||
|
|
||||||
gears->compositor = display_get_compositor(display);
|
gears->compositor = display_get_compositor(display);
|
||||||
|
|
||||||
|
resize_window(gears);
|
||||||
draw_gears(gears);
|
draw_gears(gears);
|
||||||
|
|
||||||
handle_frame(gears, gears->compositor, 0, 0);
|
handle_frame(gears, gears->compositor, 0, 0);
|
||||||
|
|
||||||
window_set_resize_handler(gears->window, resize_handler, gears);
|
window_set_resize_handler(gears->window, resize_handler, gears);
|
||||||
|
|
|
||||||
12
image.c
12
image.c
|
|
@ -184,7 +184,7 @@ image_draw(struct image *image)
|
||||||
&rectangle,
|
&rectangle,
|
||||||
image->surface);
|
image->surface);
|
||||||
|
|
||||||
wl_compositor_commit(image->compositor, image->key);
|
window_commit(image->window, image->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -216,6 +216,15 @@ resize_handler(struct window *window, void *data)
|
||||||
image_schedule_redraw(image);
|
image_schedule_redraw(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
keyboard_focus_handler(struct window *window,
|
||||||
|
struct wl_input_device *device, void *data)
|
||||||
|
{
|
||||||
|
struct image *image = data;
|
||||||
|
|
||||||
|
image_schedule_redraw(image);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_acknowledge(void *data,
|
handle_acknowledge(void *data,
|
||||||
struct wl_compositor *compositor,
|
struct wl_compositor *compositor,
|
||||||
|
|
@ -274,6 +283,7 @@ image_create(struct display *display, uint32_t key, const char *filename)
|
||||||
|
|
||||||
image->compositor = display_get_compositor(display);
|
image->compositor = display_get_compositor(display);
|
||||||
window_set_resize_handler(image->window, resize_handler, image);
|
window_set_resize_handler(image->window, resize_handler, image);
|
||||||
|
window_set_keyboard_focus_handler(image->window, keyboard_focus_handler, image);
|
||||||
|
|
||||||
wl_compositor_add_listener(image->compositor, &compositor_listener, image);
|
wl_compositor_add_listener(image->compositor, &compositor_listener, image);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ terminal_draw(struct terminal *terminal)
|
||||||
|
|
||||||
window_draw(terminal->window);
|
window_draw(terminal->window);
|
||||||
terminal_draw_contents(terminal);
|
terminal_draw_contents(terminal);
|
||||||
wl_compositor_commit(terminal->compositor, 0);
|
window_commit(terminal->window, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,13 @@ struct wlsc_output {
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
struct wlsc_compositor *compositor;
|
struct wlsc_compositor *compositor;
|
||||||
struct wlsc_surface *background;
|
struct wlsc_surface *background;
|
||||||
EGLSurface surface;
|
|
||||||
int32_t x, y, width, height;
|
int32_t x, y, width, height;
|
||||||
|
|
||||||
drmModeModeInfo mode;
|
drmModeModeInfo mode;
|
||||||
uint32_t crtc_id;
|
uint32_t crtc_id;
|
||||||
uint32_t connector_id;
|
uint32_t connector_id;
|
||||||
|
|
||||||
|
GLuint rbo[2];
|
||||||
uint32_t fb_id[2];
|
uint32_t fb_id[2];
|
||||||
uint32_t current;
|
uint32_t current;
|
||||||
};
|
};
|
||||||
|
|
@ -102,7 +102,7 @@ struct wlsc_compositor {
|
||||||
|
|
||||||
EGLDisplay display;
|
EGLDisplay display;
|
||||||
EGLContext context;
|
EGLContext context;
|
||||||
EGLConfig config;
|
GLuint fbo;
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
|
|
||||||
struct wl_list output_list;
|
struct wl_list output_list;
|
||||||
|
|
@ -610,16 +610,11 @@ repaint_output(struct wlsc_output *output)
|
||||||
double s = 3000;
|
double s = 3000;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (!eglMakeCurrent(ec->display, output->surface, output->surface, ec->context)) {
|
|
||||||
fprintf(stderr, "failed to make context current\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
glViewport(0, 0, output->width, output->height);
|
glViewport(0, 0, output->width, output->height);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glFrustum(-output->width / s, output->width / s,
|
glFrustum(-output->width / s, output->width / s,
|
||||||
output->height / s, -output->height / s, 1, 2 * s);
|
-output->height / s, output->height / s, 1, 2 * s);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glClearColor(0, 0, 0, 1);
|
glClearColor(0, 0, 0, 1);
|
||||||
|
|
@ -650,7 +645,11 @@ repaint_output(struct wlsc_output *output)
|
||||||
|
|
||||||
fd = eglGetDisplayFD(ec->display);
|
fd = eglGetDisplayFD(ec->display);
|
||||||
output->current ^= 1;
|
output->current ^= 1;
|
||||||
eglBindColorBuffer(ec->display, output->surface, output->current);
|
|
||||||
|
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT,
|
||||||
|
GL_COLOR_ATTACHMENT0_EXT,
|
||||||
|
GL_RENDERBUFFER_EXT,
|
||||||
|
output->rbo[output->current]);
|
||||||
drmModePageFlip(fd, output->crtc_id,
|
drmModePageFlip(fd, output->crtc_id,
|
||||||
output->fb_id[output->current ^ 1],
|
output->fb_id[output->current ^ 1],
|
||||||
DRM_MODE_PAGE_FLIP_EVENT, output);
|
DRM_MODE_PAGE_FLIP_EVENT, output);
|
||||||
|
|
@ -737,8 +736,8 @@ surface_attach(struct wl_client *client,
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTextureExternalMESA(GL_TEXTURE_2D, GL_RGBA, 4,
|
glTextureExternalINTEL(GL_TEXTURE_2D, GL_RGBA, 4,
|
||||||
width, height, stride / 4, name);
|
width, height, stride / 4, name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -762,36 +761,6 @@ surface_copy(struct wl_client *client,
|
||||||
uint32_t name, uint32_t stride,
|
uint32_t name, uint32_t stride,
|
||||||
int32_t x, int32_t y, int32_t width, int32_t height)
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
||||||
{
|
{
|
||||||
struct wlsc_surface *es = (struct wlsc_surface *) surface;
|
|
||||||
GLuint fbo[2], rb;
|
|
||||||
|
|
||||||
glGenFramebuffers(2, fbo);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, fbo[1]);
|
|
||||||
glGenRenderbuffers(1, &rb);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER_EXT, rb);
|
|
||||||
glRenderbufferExternalMESA(GL_RENDERBUFFER_EXT,
|
|
||||||
GL_RGBA,
|
|
||||||
es->width, es->height,
|
|
||||||
stride / 4, name);
|
|
||||||
glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER_EXT,
|
|
||||||
GL_COLOR_ATTACHMENT0_EXT,
|
|
||||||
GL_RENDERBUFFER_EXT,
|
|
||||||
rb);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, fbo[0]);
|
|
||||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER_EXT,
|
|
||||||
GL_COLOR_ATTACHMENT0_EXT,
|
|
||||||
GL_TEXTURE_2D, es->texture, 0);
|
|
||||||
|
|
||||||
glBlitFramebuffer(x, y, x + width, y + height,
|
|
||||||
dst_x, dst_y, dst_x+ width, dst_y + height,
|
|
||||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
|
|
||||||
glDeleteRenderbuffers(1, &rb);
|
|
||||||
glDeleteFramebuffers(2, fbo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -1138,14 +1107,6 @@ on_drm_input(int fd, uint32_t mask, void *data)
|
||||||
static int
|
static int
|
||||||
init_egl(struct wlsc_compositor *ec, struct udev_device *device)
|
init_egl(struct wlsc_compositor *ec, struct udev_device *device)
|
||||||
{
|
{
|
||||||
static const EGLint config_attribs[] = {
|
|
||||||
EGL_DEPTH_SIZE, 0,
|
|
||||||
EGL_STENCIL_SIZE, 0,
|
|
||||||
EGL_CONFIG_CAVEAT, EGL_NONE,
|
|
||||||
EGL_RED_SIZE, 8,
|
|
||||||
EGL_NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
struct wl_event_loop *loop;
|
struct wl_event_loop *loop;
|
||||||
EGLint major, minor;
|
EGLint major, minor;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
@ -1161,15 +1122,20 @@ init_egl(struct wlsc_compositor *ec, struct udev_device *device)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!eglChooseConfig(ec->display, config_attribs, &ec->config, 1, NULL))
|
ec->context = eglCreateContext(ec->display, NULL, NULL, NULL);
|
||||||
return -1;
|
|
||||||
|
|
||||||
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 -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!eglMakeCurrent(ec->display, EGL_NO_SURFACE, EGL_NO_SURFACE, ec->context)) {
|
||||||
|
fprintf(stderr, "failed to make context current\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
glGenFramebuffers(1, &ec->fbo);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER_EXT, ec->fbo);
|
||||||
|
|
||||||
loop = wl_display_get_event_loop(ec->wl_display);
|
loop = wl_display_get_event_loop(ec->wl_display);
|
||||||
fd = eglGetDisplayFD(ec->display);
|
fd = eglGetDisplayFD(ec->display);
|
||||||
ec->drm_source =
|
ec->drm_source =
|
||||||
|
|
@ -1197,7 +1163,7 @@ create_output_for_connector(struct wlsc_compositor *ec,
|
||||||
struct wlsc_output *output;
|
struct wlsc_output *output;
|
||||||
drmModeEncoder *encoder;
|
drmModeEncoder *encoder;
|
||||||
drmModeModeInfo *mode;
|
drmModeModeInfo *mode;
|
||||||
uint32_t name, handle, stride;
|
GLint handle, stride;
|
||||||
int i, ret, fd;
|
int i, ret, fd;
|
||||||
|
|
||||||
fd = eglGetDisplayFD(ec->display);
|
fd = eglGetDisplayFD(ec->display);
|
||||||
|
|
@ -1243,21 +1209,21 @@ create_output_for_connector(struct wlsc_compositor *ec,
|
||||||
|
|
||||||
drmModeFreeEncoder(encoder);
|
drmModeFreeEncoder(encoder);
|
||||||
|
|
||||||
output->surface = eglCreateSurface(ec->display,
|
glGenRenderbuffers(2, output->rbo);
|
||||||
ec->config,
|
|
||||||
output->width,
|
|
||||||
output->height,
|
|
||||||
2, NULL);
|
|
||||||
if (output->surface == NULL) {
|
|
||||||
fprintf(stderr, "failed to create surface\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
eglGetColorBuffer(output->surface,
|
glBindRenderbuffer(GL_RENDERBUFFER_EXT, output->rbo[i]);
|
||||||
i, &name, &handle, &stride);
|
glRenderbufferStorage(GL_RENDERBUFFER_EXT,
|
||||||
|
GL_RGBA,
|
||||||
|
output->width,
|
||||||
|
output->height);
|
||||||
|
glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,
|
||||||
|
GL_RENDERBUFFER_STRIDE_INTEL,
|
||||||
|
&stride);
|
||||||
|
glGetRenderbufferParameteriv(GL_RENDERBUFFER_EXT,
|
||||||
|
GL_RENDERBUFFER_HANDLE_INTEL,
|
||||||
|
&handle);
|
||||||
|
|
||||||
ret = drmModeAddFB(fd, mode->hdisplay, mode->vdisplay,
|
ret = drmModeAddFB(fd, output->width, output->height,
|
||||||
32, 32, stride, handle, &output->fb_id[i]);
|
32, 32, stride, handle, &output->fb_id[i]);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "failed to add fb %d: %m\n", i);
|
fprintf(stderr, "failed to add fb %d: %m\n", i);
|
||||||
|
|
@ -1266,6 +1232,10 @@ create_output_for_connector(struct wlsc_compositor *ec,
|
||||||
}
|
}
|
||||||
|
|
||||||
output->current = 0;
|
output->current = 0;
|
||||||
|
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT,
|
||||||
|
GL_COLOR_ATTACHMENT0_EXT,
|
||||||
|
GL_RENDERBUFFER_EXT,
|
||||||
|
output->rbo[output->current]);
|
||||||
ret = drmModeSetCrtc(fd, output->crtc_id,
|
ret = drmModeSetCrtc(fd, output->crtc_id,
|
||||||
output->fb_id[output->current ^ 1], 0, 0,
|
output->fb_id[output->current ^ 1], 0, 0,
|
||||||
&output->connector_id, 1, &output->mode);
|
&output->connector_id, 1, &output->mode);
|
||||||
|
|
@ -1279,11 +1249,6 @@ create_output_for_connector(struct wlsc_compositor *ec,
|
||||||
wl_display_add_global(ec->wl_display, &output->base, post_output_geometry);
|
wl_display_add_global(ec->wl_display, &output->base, post_output_geometry);
|
||||||
wl_list_insert(ec->output_list.prev, &output->link);
|
wl_list_insert(ec->output_list.prev, &output->link);
|
||||||
|
|
||||||
if (!eglMakeCurrent(ec->display, output->surface, output->surface, ec->context)) {
|
|
||||||
fprintf(stderr, "failed to make context current\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
output->background = background_create(output, option_background);
|
output->background = background_create(output, option_background);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
32
window.c
32
window.c
|
|
@ -66,6 +66,7 @@ struct window {
|
||||||
uint32_t modifiers;
|
uint32_t modifiers;
|
||||||
|
|
||||||
cairo_surface_t *cairo_surface, *pending_surface;
|
cairo_surface_t *cairo_surface, *pending_surface;
|
||||||
|
int new_surface;
|
||||||
|
|
||||||
window_resize_handler_t resize_handler;
|
window_resize_handler_t resize_handler;
|
||||||
window_key_handler_t key_handler;
|
window_key_handler_t key_handler;
|
||||||
|
|
@ -113,6 +114,17 @@ window_attach_surface(struct window *window)
|
||||||
window->allocation.height);
|
window->allocation.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
window_commit(struct window *window, uint32_t key)
|
||||||
|
{
|
||||||
|
if (window->new_surface) {
|
||||||
|
window_attach_surface(window);
|
||||||
|
window->new_surface = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
wl_compositor_commit(window->display->compositor, key);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_draw_decorations(struct window *window)
|
window_draw_decorations(struct window *window)
|
||||||
{
|
{
|
||||||
|
|
@ -210,8 +222,6 @@ window_draw_decorations(struct window *window)
|
||||||
cairo_fill(cr);
|
cairo_fill(cr);
|
||||||
}
|
}
|
||||||
cairo_destroy(cr);
|
cairo_destroy(cr);
|
||||||
|
|
||||||
window_attach_surface(window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -222,8 +232,6 @@ window_draw_fullscreen(struct window *window)
|
||||||
CAIRO_CONTENT_COLOR_ALPHA,
|
CAIRO_CONTENT_COLOR_ALPHA,
|
||||||
window->allocation.width,
|
window->allocation.width,
|
||||||
window->allocation.height);
|
window->allocation.height);
|
||||||
|
|
||||||
window_attach_surface(window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -236,6 +244,8 @@ window_draw(struct window *window)
|
||||||
window_draw_fullscreen(window);
|
window_draw_fullscreen(window);
|
||||||
else
|
else
|
||||||
window_draw_decorations(window);
|
window_draw_decorations(window);
|
||||||
|
|
||||||
|
window->new_surface = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -251,13 +261,11 @@ window_handle_acknowledge(void *data,
|
||||||
* safely free the old window buffer if we resized and
|
* safely free the old window buffer if we resized and
|
||||||
* render the next frame into our back buffer.. */
|
* render the next frame into our back buffer.. */
|
||||||
|
|
||||||
if (key == 0) {
|
pending = window->pending_surface;
|
||||||
pending = window->pending_surface;
|
window->pending_surface = NULL;
|
||||||
window->pending_surface = NULL;
|
if (pending != window->cairo_surface)
|
||||||
if (pending != window->cairo_surface)
|
window_attach_surface(window);
|
||||||
window_attach_surface(window);
|
cairo_surface_destroy(pending);
|
||||||
cairo_surface_destroy(pending);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -585,7 +593,7 @@ window_copy(struct window *window,
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
|
|
||||||
surface = cairo_drm_surface_create_for_name (window->display->device,
|
surface = cairo_drm_surface_create_for_name (window->display->device,
|
||||||
name, CAIRO_CONTENT_COLOR_ALPHA,
|
name, CAIRO_FORMAT_ARGB32,
|
||||||
rectangle->width, rectangle->height,
|
rectangle->width, rectangle->height,
|
||||||
stride);
|
stride);
|
||||||
|
|
||||||
|
|
|
||||||
2
window.h
2
window.h
|
|
@ -60,6 +60,8 @@ window_create(struct display *display, const char *title,
|
||||||
void
|
void
|
||||||
window_draw(struct window *window);
|
window_draw(struct window *window);
|
||||||
void
|
void
|
||||||
|
window_commit(struct window *window, uint32_t key);
|
||||||
|
void
|
||||||
window_get_child_rectangle(struct window *window,
|
window_get_child_rectangle(struct window *window,
|
||||||
struct rectangle *rectangle);
|
struct rectangle *rectangle);
|
||||||
void
|
void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue