summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-02-02 16:28:46 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-02-02 16:28:46 +0100
commit66987727601880c608ffa2a92174d8c7fc8c5701 (patch)
tree3ade07f3eef58f87d5bcd944af4871b7806efd33
parent621cd3e9576630c508ab4aee3980b4024439dd56 (diff)
Update to api changes
- wl_egl_surface -> wl_egl_window - wl_egl_<action>_native_<object> -> wl_egl_native_<object>_<action>
-rw-r--r--egl-wayland-image.c391
-rw-r--r--egl-wayland-pixmap-image.c (renamed from egl-wayland-pixmap.c)37
-rw-r--r--egl-wayland-window.c (renamed from egl-wayland-surface.c)20
3 files changed, 38 insertions, 410 deletions
diff --git a/egl-wayland-image.c b/egl-wayland-image.c
deleted file mode 100644
index 82cca62..0000000
--- a/egl-wayland-image.c
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * Copyright © 2011 Benjamin Franzke
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting documentation, and
- * that the name of the copyright holders not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no representations
- * about the suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
- * OF THIS SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <math.h>
-#include <assert.h>
-
-#include <wayland-client.h>
-#include <wayland-egl.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>
-
-struct display {
- struct wl_display *display;
- struct wl_egl_display *egl_display;
- struct wl_compositor *compositor;
- struct wl_shell *shell;
- struct {
- EGLDisplay dpy;
- EGLContext ctx;
- } egl;
- uint32_t mask;
-};
-
-struct window {
- struct display *display;
- struct {
- int width, height;
- } geometry;
- struct {
- GLuint fbo;
- GLuint color_rbo;
-
- GLuint program;
- GLuint rotation_uniform;
-
- GLuint pos;
- GLuint col;
- } gl;
- struct {
- struct wl_surface *surface;
- struct wl_egl_image *egl_image;
- } surface;
- int dx, dy;
- int attached_width, attached_height;
-};
-
-static const char *vert_shader_text =
- "uniform mat4 rotation;\n"
- "attribute vec4 pos;\n"
- "attribute vec4 color;\n"
- "varying vec4 v_color;\n"
- "void main() {\n"
- " gl_Position = rotation * pos;\n"
- " v_color = color;\n"
- "}\n";
-
-static const char *frag_shader_text =
- "precision mediump float;\n"
- "varying vec4 v_color;\n"
- "void main() {\n"
- " gl_FragColor = v_color;\n"
- "}\n";
-
-static void
-init_egl(struct display *display)
-{
- static const EGLint context_attribs[] = {
- EGL_CONTEXT_CLIENT_VERSION, 2,
- EGL_NONE
- };
-
- EGLint major, minor;
- EGLBoolean ret;
-
- display->egl.dpy =
- eglGetDisplay((EGLNativeDisplayType) display->egl_display);
- assert(display->egl.dpy);
-
- ret = eglInitialize(display->egl.dpy, &major, &minor);
- assert(ret == EGL_TRUE);
- ret = eglBindAPI(EGL_OPENGL_ES_API);
- assert(ret == EGL_TRUE);
-
- display->egl.ctx = eglCreateContext(display->egl.dpy, NULL,
- EGL_NO_CONTEXT, context_attribs);
- assert(display->egl.ctx);
- ret = eglMakeCurrent(display->egl.dpy, NULL, NULL, display->egl.ctx);
- assert(ret == EGL_TRUE);
-}
-
-static GLuint
-create_shader(struct window *window, const char *source, GLenum shader_type)
-{
- GLuint shader;
- GLint status;
-
- shader = glCreateShader(shader_type);
- assert(shader != 0);
-
- glShaderSource(shader, 1, (const char **) &source, NULL);
- glCompileShader(shader);
-
- glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
- if (!status) {
- char log[1000];
- GLsizei len;
- glGetShaderInfoLog(shader, 1000, &len, log);
- fprintf(stderr, "Error: compiling %s: %*s\n",
- shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",
- len, log);
- exit(1);
- }
-
- return shader;
-}
-
-static void
-init_gl(struct window *window)
-{
- GLuint frag, vert;
- GLint status;
-
- glGenFramebuffers(1, &window->gl.fbo);
- glBindFramebuffer(GL_FRAMEBUFFER, window->gl.fbo);
-
- glGenRenderbuffers(1, &window->gl.color_rbo);
-
- glViewport(0, 0, window->geometry.width, window->geometry.height);
-
- frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER);
- vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER);
-
- window->gl.program = glCreateProgram();
- glAttachShader(window->gl.program, frag);
- glAttachShader(window->gl.program, vert);
- glLinkProgram(window->gl.program);
-
- glGetProgramiv(window->gl.program, GL_LINK_STATUS, &status);
- if (!status) {
- char log[1000];
- GLsizei len;
- glGetProgramInfoLog(window->gl.program, 1000, &len, log);
- fprintf(stderr, "Error: linking:\n%*s\n", len, log);
- exit(1);
- }
-
- glUseProgram(window->gl.program);
-
- window->gl.pos = 0;
- window->gl.pos = 1;
-
- glBindAttribLocation(window->gl.program, window->gl.pos, "pos");
- glBindAttribLocation(window->gl.program, window->gl.col, "color");
- glLinkProgram(window->gl.program);
-
- window->gl.rotation_uniform =
- glGetUniformLocation(window->gl.program, "rotation");
-}
-
-static void
-create_surface(struct window *window)
-{
- struct display *display = window->display;
- struct wl_visual *visual;
-
- window->surface.surface =
- wl_compositor_create_surface(display->compositor);
- wl_surface_set_user_data(window->surface.surface, window);
-
- visual = wl_display_get_premultiplied_argb_visual(display->display);
- window->surface.egl_image = wl_egl_create_image(display->egl.dpy,
- window->geometry.width,
- window->geometry.height,
- visual, 0);
-
- wl_surface_map_toplevel(window->surface.surface);
-
- glBindRenderbuffer(GL_RENDERBUFFER, window->gl.color_rbo);
- glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
- wl_egl_image_get_image(window->surface.egl_image));
-
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_RENDERBUFFER, window->gl.color_rbo);
-
- assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) ==
- GL_FRAMEBUFFER_COMPLETE);
-}
-
-static void
-redraw(void *data, uint32_t time)
-{
- struct window *window = data;
- static const GLfloat verts[3][2] = {
- { -0.5, -0.5 },
- { 0.5, -0.5 },
- { 0, 0.5 }
- };
- static const GLfloat colors[3][3] = {
- { 1, 0, 0 },
- { 0, 1, 0 },
- { 0, 0, 1 }
- };
- GLfloat angle;
- GLfloat rotation[4][4] = {
- { 1, 0, 0, 0 },
- { 0, 1, 0, 0 },
- { 0, 0, 1, 0 },
- { 0, 0, 0, 1 }
- };
- static const int32_t speed_div = 5;
- static uint32_t start_time = 0;
-
- if (start_time == 0)
- start_time = time;
-
- angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0;
- rotation[0][0] = cos(angle);
- rotation[0][2] = sin(angle);
- rotation[2][0] = -sin(angle);
- rotation[2][2] = cos(angle);
-
- glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE,
- (GLfloat *) rotation);
-
- glClearColor(0.0, 0.0, 0.0, 0.5);
- glClear(GL_COLOR_BUFFER_BIT);
-
- glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
- glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors);
- glEnableVertexAttribArray(window->gl.pos);
- glEnableVertexAttribArray(window->gl.col);
-
- glDrawArrays(GL_TRIANGLES, 0, 3);
-
- glDisableVertexAttribArray(window->gl.pos);
- glDisableVertexAttribArray(window->gl.col);
-
- wl_egl_image_attach(window->display->egl_display,
- window->surface.egl_image,
- window->surface.surface,
- window->dx, window->dy);
- window->attached_width = window->geometry.width;
- window->attached_height = window->geometry.height;
-
- window->dx = window->dy = 0;
-
- wl_surface_damage(window->surface.surface, 0, 0,
- window->geometry.width, window->geometry.height);
-
- wl_display_frame_callback(window->display->display, redraw, window);
-}
-
-static void
-handle_configure(void *data, struct wl_shell *shell,
- uint32_t time, uint32_t edges,
- struct wl_surface *surface,
- int32_t width, int32_t height)
-{
- struct display *d = data;
- struct window *window = wl_surface_get_user_data(surface);
- struct wl_visual *visual;
-
- struct wl_egl_image *old_egl_image = window->surface.egl_image;
-
-#define WINDOW_RESIZING_LEFT 4
-#define WINDOW_RESIZING_TOP 1
-
- if (width <= 0 || height <= 0)
- return;
-
- window->dx = 0;
- window->dy = 0;
- window->geometry.width = width;
- window->geometry.height = height;
-
- if (edges & WINDOW_RESIZING_LEFT)
- window->dx = window->attached_width - width;
- if (edges & WINDOW_RESIZING_TOP)
- window->dy = window->attached_height - height;
-
- visual = wl_display_get_premultiplied_argb_visual(d->display);
- window->surface.egl_image =
- wl_egl_create_image(d->egl.dpy,
- window->geometry.width,
- window->geometry.height,
- visual, 0);
-
- assert(window->surface.egl_image);
-
- glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
- wl_egl_image_get_image(window->surface.egl_image));
-
- wl_egl_destroy_image(old_egl_image);
-
- glViewport(0, 0, window->geometry.width, window->geometry.height);
-}
-
-static const struct wl_shell_listener shell_listener = {
- handle_configure,
-};
-
-static void
-display_handle_global(struct wl_display *display, uint32_t id,
- const char *interface, uint32_t version, void *data)
-{
- struct display *d = data;
-
- if (strcmp(interface, "compositor") == 0) {
- d->compositor = wl_compositor_create(display, id);
- } else if (strcmp(interface, "shell") == 0) {
- d->shell = wl_shell_create(display, id);
- wl_shell_add_listener(d->shell, &shell_listener, d);
- }
-}
-
-static int
-event_mask_update(uint32_t mask, void *data)
-{
- struct display *d = data;
-
- d->mask = mask;
-
- return 0;
-}
-
-int
-main(int argc, char **argv)
-{
- struct display display = { 0 };
- struct window window = { 0 };
-
- memset(&display, 0, sizeof display);
- memset(&window, 0, sizeof window);
-
- window.display = &display;
- window.geometry.width = 250;
- window.geometry.height = 250;
-
- display.display = wl_display_connect(NULL);
- assert(display.display);
-
- display.egl_display = wl_egl_create_native_display(display.display);
- assert(display.egl_display);
-
- wl_display_add_global_listener(display.display,
- display_handle_global, &display);
- /* process connection events */
- wl_display_iterate(display.display, WL_DISPLAY_READABLE);
-
- init_egl(&display);
- init_gl(&window);
- create_surface(&window);
-
- wl_display_frame_callback(display.display, redraw, &window);
- wl_display_get_fd(display.display, event_mask_update, &display);
-
- while (true)
- wl_display_iterate(display.display, display.mask);
-
- return 0;
-}
diff --git a/egl-wayland-pixmap.c b/egl-wayland-pixmap-image.c
index 85ad1d9..cff8fc4 100644
--- a/egl-wayland-pixmap.c
+++ b/egl-wayland-pixmap-image.c
@@ -69,6 +69,7 @@ struct window {
struct {
struct wl_surface *surface;
struct wl_egl_pixmap *egl_pixmap;
+ struct wl_buffer *buffer;
EGLImageKHR *egl_image;
} surface;
int dx, dy;
@@ -200,10 +201,11 @@ create_surface(struct window *window)
visual = wl_display_get_premultiplied_argb_visual(display->display);
window->surface.egl_pixmap =
- wl_egl_create_native_pixmap(display->egl_display,
+ wl_egl_native_pixmap_create(display->egl_display,
window->geometry.width,
window->geometry.height,
visual, 0);
+ window->surface.buffer = NULL;
wl_surface_map_toplevel(window->surface.surface);
@@ -211,6 +213,7 @@ create_surface(struct window *window)
eglCreateImageKHR(display->egl.dpy, display->egl.ctx,
EGL_NATIVE_PIXMAP_KHR,
window->surface.egl_pixmap, NULL);
+ assert(window->surface.egl_image);
glBindRenderbuffer(GL_RENDERBUFFER, window->gl.color_rbo);
glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER,
@@ -272,10 +275,16 @@ redraw(void *data, uint32_t time)
glDisableVertexAttribArray(window->gl.pos);
glDisableVertexAttribArray(window->gl.col);
- wl_egl_pixmap_attach(window->display->egl_display,
- window->surface.egl_pixmap,
- window->surface.surface,
- window->dx, window->dy);
+ if (!window->surface.buffer)
+ window->surface.buffer = wl_egl_native_pixmap_create_buffer(
+ window->display->egl_display,
+ window->surface.egl_pixmap);
+
+ wl_egl_native_pixmap_flush(window->display->egl_display,
+ window->surface.egl_pixmap);
+ wl_surface_attach(window->surface.surface, window->surface.buffer,
+ window->dx, window->dy);
+
window->attached_width = window->geometry.width;
window->attached_height = window->geometry.height;
@@ -303,9 +312,14 @@ handle_configure(void *data, struct wl_shell *shell,
#define WINDOW_RESIZING_LEFT 4
#define WINDOW_RESIZING_TOP 1
- if (width <= 0 || height <= 0)
+ if (width <= 0 && height <= 0)
return;
+ if (width <= 0)
+ width = window->attached_width;
+ if (height <= 0)
+ height = window->attached_height;
+
window->dx = 0;
window->dy = 0;
window->geometry.width = width;
@@ -318,11 +332,16 @@ handle_configure(void *data, struct wl_shell *shell,
visual = wl_display_get_premultiplied_argb_visual(d->display);
window->surface.egl_pixmap =
- wl_egl_create_native_pixmap(d->egl_display,
+ wl_egl_native_pixmap_create(d->egl_display,
window->geometry.width,
window->geometry.height,
visual, 0);
+ if (window->surface.buffer) {
+ wl_buffer_destroy(window->surface.buffer);
+ window->surface.buffer = NULL;
+ }
+
window->surface.egl_image =
eglCreateImageKHR(d->egl.dpy, d->egl.ctx,
EGL_NATIVE_PIXMAP_KHR,
@@ -333,7 +352,7 @@ handle_configure(void *data, struct wl_shell *shell,
window->surface.egl_image);
eglDestroyImageKHR(d->egl.dpy, window->surface.egl_image);
- wl_egl_pixmap_destroy(old_egl_pixmap);
+ wl_egl_native_pixmap_destroy(old_egl_pixmap);
glViewport(0, 0, window->geometry.width, window->geometry.height);
}
@@ -382,7 +401,7 @@ main(int argc, char **argv)
display.display = wl_display_connect(NULL);
assert(display.display);
- display.egl_display = wl_egl_create_native_display(display.display);
+ display.egl_display = wl_egl_native_display_create(display.display);
assert(display.egl_display);
wl_display_add_global_listener(display.display,
diff --git a/egl-wayland-surface.c b/egl-wayland-window.c
index 797235a..67d6e9a 100644
--- a/egl-wayland-surface.c
+++ b/egl-wayland-window.c
@@ -29,7 +29,7 @@ struct display {
struct window {
struct display *display;
struct wl_surface *surface;
- struct wl_egl_surface *egl_surface;
+ struct wl_egl_window *egl_window;
int width, height;
int attached_width, attached_height;
@@ -70,20 +70,20 @@ init_egl(struct display *display)
}
static void
-create_egl_surface(struct display *display, struct window *window)
+create_egl_window(struct display *display, struct window *window)
{
struct wl_visual *visual;
visual = wl_display_get_premultiplied_argb_visual(display->display);
- window->egl_surface = wl_egl_create_native_surface(window->surface,
- window->width,
- window->height,
- visual);
+ window->egl_window = wl_egl_native_window_create(window->surface,
+ window->width,
+ window->height,
+ visual);
printf("surface: %p\n", window->surface);
window->egl.surf =
eglCreateWindowSurface(display->egl.dpy, display->egl.conf,
- (EGLNativeWindowType) window->egl_surface,
+ (EGLNativeWindowType) window->egl_window,
NULL);
assert(window->egl.surf);
assert(eglMakeCurrent(display->egl.dpy,
@@ -185,7 +185,7 @@ handle_configure(void *data, struct wl_shell *shell,
if (edges & WINDOW_RESIZING_TOP)
dy = window->attached_height - height;
- wl_egl_surface_resize(window->egl_surface, width, height, dx, dy);
+ wl_egl_native_window_resize(window->egl_window, width, height, dx, dy);
window->width = width;
window->height = height;
@@ -234,7 +234,7 @@ main(int argc, char **argv)
display.display = wl_display_connect(NULL);
assert(display.display);
- display.egl_display = wl_egl_create_native_display(display.display);
+ display.egl_display = wl_egl_native_display_create(display.display);
assert(display.egl_display);
wl_display_add_global_listener(display.display,
@@ -246,7 +246,7 @@ main(int argc, char **argv)
window.surface =
wl_compositor_create_surface(display.interface.compositor);
wl_surface_set_user_data(window.surface, &window);
- create_egl_surface(&display, &window);
+ create_egl_window(&display, &window);
init_gl(&window);