summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-09-06 22:19:01 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-09-06 22:19:01 -0400
commit01d4a6484040f46ce500adb9521f1790ed576bda (patch)
treec9220d68140d66725dc45a75a54612fe585e6ee1
parent4226385e53efbaa5c72f1e6262cdc5fb4137e9bf (diff)
move extention funcs and read_output
-rw-r--r--src/compositor.h13
-rw-r--r--src/gles2-renderer.c81
-rw-r--r--src/screenshooter.c20
3 files changed, 69 insertions, 45 deletions
diff --git a/src/compositor.h b/src/compositor.h
index 728be6fd..d7d0e40f 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -273,6 +273,8 @@ struct weston_renderer {
void (*flush_damage)(struct weston_surface *surface);
void (*attach)(struct weston_surface *es, struct wl_buffer *buffer);
void (*destroy_surface)(struct weston_surface *surface);
+ void (*read_output)(struct weston_output *output,
+ int x, int y, int width, int height, void *pixel);
};
struct weston_compositor {
@@ -337,20 +339,9 @@ struct weston_compositor {
struct weston_renderer *renderer;
- PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
- image_target_renderbuffer_storage;
- PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
- PFNEGLCREATEIMAGEKHRPROC create_image;
- PFNEGLDESTROYIMAGEKHRPROC destroy_image;
-
int has_unpack_subimage;
GLenum read_format;
- PFNEGLBINDWAYLANDDISPLAYWL bind_display;
- PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
- PFNEGLQUERYWAYLANDBUFFERWL query_buffer;
- int has_bind_display;
-
void (*destroy)(struct weston_compositor *ec);
void (*restore)(struct weston_compositor *ec);
int (*authenticate)(struct weston_compositor *c, uint32_t id);
diff --git a/src/gles2-renderer.c b/src/gles2-renderer.c
index a19c8c5d..7f26e859 100644
--- a/src/gles2-renderer.c
+++ b/src/gles2-renderer.c
@@ -28,6 +28,21 @@
#include "compositor.h"
+struct gles2_renderer {
+ struct weston_renderer base;
+
+ PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
+ image_target_renderbuffer_storage;
+ PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
+ PFNEGLCREATEIMAGEKHRPROC create_image;
+ PFNEGLDESTROYIMAGEKHRPROC destroy_image;
+
+ PFNEGLBINDWAYLANDDISPLAYWL bind_display;
+ PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
+ PFNEGLQUERYWAYLANDBUFFERWL query_buffer;
+ int has_bind_display;
+};
+
static const char *
egl_error_string(EGLint code)
{
@@ -735,12 +750,13 @@ static void
gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
{
struct weston_compositor *ec = es->compositor;
+ struct gles2_renderer *r = (struct gles2_renderer *) ec->renderer;
EGLint attribs[3], format;
int i, num_planes;
if (!buffer) {
for (i = 0; i < es->num_images; i++) {
- ec->destroy_image(ec->egl_display, es->images[i]);
+ r->destroy_image(ec->egl_display, es->images[i]);
es->images[i] = NULL;
}
es->num_images = 0;
@@ -762,10 +778,10 @@ gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
es->shader = &ec->texture_shader_rgbx;
else
es->shader = &ec->texture_shader_rgba;
- } else if (ec->query_buffer(ec->egl_display, buffer,
+ } else if (r->query_buffer(ec->egl_display, buffer,
EGL_TEXTURE_FORMAT, &format)) {
for (i = 0; i < es->num_images; i++)
- ec->destroy_image(ec->egl_display, es->images[i]);
+ r->destroy_image(ec->egl_display, es->images[i]);
es->num_images = 0;
es->target = GL_TEXTURE_2D;
switch (format) {
@@ -799,10 +815,10 @@ gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
attribs[0] = EGL_WAYLAND_PLANE_WL;
attribs[1] = i;
attribs[2] = EGL_NONE;
- es->images[i] = ec->create_image(ec->egl_display,
- NULL,
- EGL_WAYLAND_BUFFER_WL,
- buffer, attribs);
+ es->images[i] = r->create_image(ec->egl_display,
+ NULL,
+ EGL_WAYLAND_BUFFER_WL,
+ buffer, attribs);
if (!es->images[i]) {
weston_log("failed to create img for plane %d\n", i);
continue;
@@ -811,8 +827,7 @@ gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(es->target, es->textures[i]);
- ec->image_target_texture_2d(es->target,
- es->images[i]);
+ r->image_target_texture_2d(es->target, es->images[i]);
}
es->pitch = buffer->width;
@@ -825,12 +840,23 @@ static void
gles2_renderer_destroy_surface(struct weston_surface *surface)
{
struct weston_compositor *ec = surface->compositor;
+ struct gles2_renderer *renderer =
+ (struct gles2_renderer *) ec->renderer;
int i;
glDeleteTextures(surface->num_textures, surface->textures);
for (i = 0; i < surface->num_images; i++)
- ec->destroy_image(ec->egl_display, surface->images[i]);
+ renderer->destroy_image(ec->egl_display, surface->images[i]);
+}
+
+static void
+gles2_renderer_read_output(struct weston_output *output,
+ int x, int y, int width, int height, void *pixels)
+{
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ glReadPixels(x, y, width, height, output->compositor->read_format,
+ GL_UNSIGNED_BYTE, pixels);
}
static const char vertex_shader[] =
@@ -1047,15 +1073,14 @@ log_egl_gl_info(EGLDisplay egldpy)
log_extensions("GL extensions", str ? str : "(null)");
}
-struct gles2_renderer {
- struct weston_renderer base;
-};
-
WL_EXPORT void
gles2_renderer_destroy(struct weston_compositor *ec)
{
- if (ec->has_bind_display)
- ec->unbind_display(ec->egl_display, ec->wl_display);
+ struct gles2_renderer *renderer =
+ (struct gles2_renderer *) ec->renderer;
+
+ if (renderer->has_bind_display)
+ renderer->unbind_display(ec->egl_display, ec->wl_display);
}
WL_EXPORT int
@@ -1101,17 +1126,19 @@ gles2_renderer_init(struct weston_compositor *ec)
log_egl_gl_info(ec->egl_display);
- ec->image_target_texture_2d =
+ renderer->image_target_texture_2d =
(void *) eglGetProcAddress("glEGLImageTargetTexture2DOES");
- ec->image_target_renderbuffer_storage = (void *)
+ renderer->image_target_renderbuffer_storage = (void *)
eglGetProcAddress("glEGLImageTargetRenderbufferStorageOES");
- ec->create_image = (void *) eglGetProcAddress("eglCreateImageKHR");
- ec->destroy_image = (void *) eglGetProcAddress("eglDestroyImageKHR");
- ec->bind_display =
+ renderer->create_image =
+ (void *) eglGetProcAddress("eglCreateImageKHR");
+ renderer->destroy_image =
+ (void *) eglGetProcAddress("eglDestroyImageKHR");
+ renderer->bind_display =
(void *) eglGetProcAddress("eglBindWaylandDisplayWL");
- ec->unbind_display =
+ renderer->unbind_display =
(void *) eglGetProcAddress("eglUnbindWaylandDisplayWL");
- ec->query_buffer =
+ renderer->query_buffer =
(void *) eglGetProcAddress("eglQueryWaylandBufferWL");
extensions = (const char *) glGetString(GL_EXTENSIONS);
@@ -1144,9 +1171,9 @@ gles2_renderer_init(struct weston_compositor *ec)
}
if (strstr(extensions, "EGL_WL_bind_wayland_display"))
- ec->has_bind_display = 1;
- if (ec->has_bind_display)
- ec->bind_display(ec->egl_display, ec->wl_display);
+ renderer->has_bind_display = 1;
+ if (renderer->has_bind_display)
+ renderer->bind_display(ec->egl_display, ec->wl_display);
glActiveTexture(GL_TEXTURE0);
@@ -1177,6 +1204,8 @@ gles2_renderer_init(struct weston_compositor *ec)
renderer->base.flush_damage = gles2_renderer_flush_damage;
renderer->base.attach = gles2_renderer_attach;
renderer->base.destroy_surface = gles2_renderer_destroy_surface;
+ renderer->base.read_output = gles2_renderer_read_output;
+
ec->renderer = &renderer->base;
return 0;
diff --git a/src/screenshooter.c b/src/screenshooter.c
index ba80ce55..e9d268bd 100644
--- a/src/screenshooter.c
+++ b/src/screenshooter.c
@@ -98,6 +98,8 @@ screenshooter_frame_notify(struct wl_listener *listener, void *data)
container_of(listener,
struct screenshooter_frame_listener, listener);
struct weston_output *output = data;
+ struct weston_renderer *renderer =
+ (struct weston_renderer *) output->compositor->renderer;
int32_t stride;
uint8_t *pixels, *d, *s;
@@ -112,10 +114,10 @@ screenshooter_frame_notify(struct wl_listener *listener, void *data)
return;
}
- glPixelStorei(GL_PACK_ALIGNMENT, 1);
- glReadPixels(0, 0, output->current->width, output->current->height,
- output->compositor->read_format,
- GL_UNSIGNED_BYTE, pixels);
+ renderer->read_output(output, 0, 0,
+ output->current->width,
+ output->current->height,
+ pixels);
stride = wl_shm_buffer_get_stride(l->buffer);
@@ -259,6 +261,8 @@ weston_recorder_frame_notify(struct wl_listener *listener, void *data)
struct weston_recorder *recorder =
container_of(listener, struct weston_recorder, frame_listener);
struct weston_output *output = data;
+ struct weston_renderer *renderer =
+ (struct weston_renderer *) output->compositor->renderer;
uint32_t msecs = output->frame_time;
pixman_box32_t *r;
pixman_region32_t damage;
@@ -290,10 +294,10 @@ weston_recorder_frame_notify(struct wl_listener *listener, void *data)
for (i = 0; i < n; i++) {
width = r[i].x2 - r[i].x1;
height = r[i].y2 - r[i].y1;
- glReadPixels(r[i].x1, output->current->height - r[i].y2,
- width, height,
- output->compositor->read_format,
- GL_UNSIGNED_BYTE, recorder->rect);
+
+ renderer->read_output(output, r[i].x1,
+ output->current->height - r[i].y2,
+ width, height, recorder->rect);
s = recorder->rect;
p = recorder->rect;