compositor: Introduce a weston_renderer object

Move the gles2 render functions to vfuncs on the renderer object.
This commit is contained in:
Kristian Høgsberg 2012-09-05 22:49:55 -04:00
parent b7b77e6f8f
commit fa1be023a2
7 changed files with 36 additions and 17 deletions

View File

@ -153,7 +153,7 @@ android_output_repaint(struct weston_output *base, pixman_region32_t *damage)
struct android_compositor *compositor = output->compositor;
struct wl_event_loop *loop;
gles2_renderer_repaint_output(&output->base, damage);
compositor->base.renderer->repaint_output(&output->base, damage);
/* FIXME: does Android have a way to signal page flip done? */
loop = wl_display_get_event_loop(compositor->base.wl_display);

View File

@ -323,9 +323,10 @@ drm_output_prepare_scanout_surface(struct weston_output *_output,
static void
drm_output_render(struct drm_output *output, pixman_region32_t *damage)
{
struct weston_compositor *ec = output->base.compositor;
struct gbm_bo *bo;
gles2_renderer_repaint_output(&output->base, damage);
ec->renderer->repaint_output(&output->base, damage);
bo = gbm_surface_lock_front_buffer(output->surface);
if (!bo) {

View File

@ -342,9 +342,10 @@ wayland_output_repaint(struct weston_output *output_base,
pixman_region32_t *damage)
{
struct wayland_output *output = (struct wayland_output *) output_base;
struct weston_compositor *ec = output->base.compositor;
struct wl_callback *callback;
gles2_renderer_repaint_output(output_base, damage);
ec->renderer->repaint_output(&output->base, damage);
callback = wl_surface_frame(output->parent.surface);
wl_callback_add_listener(callback, &frame_listener, output);

View File

@ -324,8 +324,9 @@ x11_output_repaint(struct weston_output *output_base,
pixman_region32_t *damage)
{
struct x11_output *output = (struct x11_output *)output_base;
struct weston_compositor *ec = output->base.compositor;
gles2_renderer_repaint_output(output_base, damage);
ec->renderer->repaint_output(output_base, damage);
wl_event_source_timer_update(output->finish_frame_timer, 10);
}

View File

@ -188,7 +188,7 @@ surface_handle_buffer_destroy(struct wl_listener *listener, void *data)
buffer_destroy_listener);
if (es->buffer && wl_buffer_is_shm(es->buffer))
gles2_renderer_flush_damage(es);
es->compositor->renderer->flush_damage(es);
es->buffer = NULL;
}
@ -752,7 +752,7 @@ weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer)
weston_surface_unmap(es);
}
gles2_renderer_attach(es, buffer);
es->compositor->renderer->attach(es, buffer);
es->buffer = buffer;
}
@ -834,7 +834,7 @@ surface_accumulate_damage(struct weston_surface *surface,
pixman_region32_t *opaque)
{
if (surface->buffer && wl_buffer_is_shm(surface->buffer))
gles2_renderer_flush_damage(surface);
surface->compositor->renderer->flush_damage(surface);
if (surface->transform.enabled) {
pixman_box32_t *extents;

View File

@ -267,6 +267,13 @@ struct weston_plane {
int32_t x, y;
};
struct weston_renderer {
void (*repaint_output)(struct weston_output *output,
pixman_region32_t *output_damage);
void (*flush_damage)(struct weston_surface *surface);
void (*attach)(struct weston_surface *es, struct wl_buffer *buffer);
};
struct weston_compositor {
struct wl_shm *shm;
struct wl_signal destroy_signal;
@ -327,6 +334,8 @@ struct weston_compositor {
uint32_t focus;
struct weston_renderer *renderer;
PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC
image_target_renderbuffer_storage;
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
@ -794,12 +803,5 @@ weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode
int
gles2_renderer_init(struct weston_compositor *ec);
void
gles2_renderer_repaint_output(struct weston_output *output,
pixman_region32_t *output_damage);
void
gles2_renderer_flush_damage(struct weston_surface *surface);
void
gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer);
#endif

View File

@ -620,7 +620,7 @@ repaint_surfaces(struct weston_output *output, pixman_region32_t *damage)
draw_surface(surface, output, damage);
}
WL_EXPORT void
static void
gles2_renderer_repaint_output(struct weston_output *output,
pixman_region32_t *output_damage)
{
@ -674,7 +674,7 @@ gles2_renderer_repaint_output(struct weston_output *output,
}
WL_EXPORT void
static void
gles2_renderer_flush_damage(struct weston_surface *surface)
{
#ifdef GL_UNPACK_ROW_LENGTH
@ -731,7 +731,7 @@ ensure_textures(struct weston_surface *es, int num_textures)
glBindTexture(es->target, 0);
}
WL_EXPORT void
static void
gles2_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
{
struct weston_compositor *ec = es->compositor;
@ -1035,12 +1035,21 @@ log_egl_gl_info(EGLDisplay egldpy)
log_extensions("GL extensions", str ? str : "(null)");
}
struct gles2_renderer {
struct weston_renderer base;
};
WL_EXPORT int
gles2_renderer_init(struct weston_compositor *ec)
{
struct gles2_renderer *renderer;
const char *extensions;
int has_egl_image_external = 0;
renderer = malloc(sizeof *renderer);
if (renderer == NULL)
return -1;
log_egl_gl_info(ec->egl_display);
ec->image_target_texture_2d =
@ -1115,5 +1124,10 @@ gles2_renderer_init(struct weston_compositor *ec)
vertex_shader, solid_fragment_shader) < 0)
return -1;
renderer->base.repaint_output = gles2_renderer_repaint_output;
renderer->base.flush_damage = gles2_renderer_flush_damage;
renderer->base.attach = gles2_renderer_attach;
ec->renderer = &renderer->base;
return 0;
}