From 68033ac3537a19fc1605a0b60868e4e76ecc6175 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Tue, 4 Dec 2012 15:58:15 +0200 Subject: [PATCH] compositor: move pitch into renderer private It is not used by anything but the gl-renderer. Signed-off-by: Pekka Paalanen --- src/compositor.c | 1 - src/compositor.h | 1 - src/gl-renderer.c | 21 ++++++++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index 38bc6bc5..6e58776f 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -222,7 +222,6 @@ weston_surface_create(struct weston_compositor *compositor) surface->compositor = compositor; surface->alpha = 1.0; - surface->pitch = 1; if (compositor->renderer->create_surface(surface) < 0) { free(surface); diff --git a/src/compositor.h b/src/compositor.h index bbf9bde9..1aefe0ad 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -388,7 +388,6 @@ struct weston_surface { pixman_region32_t damage; pixman_region32_t opaque; pixman_region32_t input; - int32_t pitch; struct wl_list link; struct wl_list layer_link; float alpha; diff --git a/src/gl-renderer.c b/src/gl-renderer.c index 4ab8b0ce..89e9a4d8 100644 --- a/src/gl-renderer.c +++ b/src/gl-renderer.c @@ -64,6 +64,7 @@ struct gl_surface_state { int num_images; struct weston_buffer_reference buffer_ref; + int pitch; /* in pixels */ }; struct gl_renderer { @@ -523,6 +524,7 @@ static int texture_region(struct weston_surface *es, pixman_region32_t *region, pixman_region32_t *surf_region) { + struct gl_surface_state *gs = get_surface_state(es); struct weston_compositor *ec = es->compositor; GLfloat *v, inv_width, inv_height; unsigned int *vtxcnt, nvtx = 0; @@ -538,7 +540,7 @@ texture_region(struct weston_surface *es, pixman_region32_t *region, v = wl_array_add(&ec->vertices, nrects * nsurf * 8 * 4 * sizeof *v); vtxcnt = wl_array_add(&ec->vtxcnt, nrects * nsurf * sizeof *vtxcnt); - inv_width = 1.0 / es->pitch; + inv_width = 1.0 / gs->pitch; switch (es->buffer_transform) { case WL_OUTPUT_TRANSFORM_90: @@ -1069,7 +1071,7 @@ gl_renderer_flush_damage(struct weston_surface *surface) if (!gr->has_unpack_subimage) { glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, - surface->pitch, buffer->height, 0, + gs->pitch, buffer->height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, wl_shm_buffer_get_data(buffer)); @@ -1078,7 +1080,7 @@ gl_renderer_flush_damage(struct weston_surface *surface) #ifdef GL_UNPACK_ROW_LENGTH /* Mesa does not define GL_EXT_unpack_subimage */ - glPixelStorei(GL_UNPACK_ROW_LENGTH, surface->pitch); + glPixelStorei(GL_UNPACK_ROW_LENGTH, gs->pitch); data = wl_shm_buffer_get_data(buffer); rectangles = pixman_region32_rectangles(&surface->texture_damage, &n); for (i = 0; i < n; i++) { @@ -1144,13 +1146,13 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer) } if (wl_buffer_is_shm(buffer)) { - es->pitch = wl_shm_buffer_get_stride(buffer) / 4; + gs->pitch = wl_shm_buffer_get_stride(buffer) / 4; gs->target = GL_TEXTURE_2D; ensure_textures(gs, 1); glBindTexture(GL_TEXTURE_2D, gs->textures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, - es->pitch, buffer->height, 0, + gs->pitch, buffer->height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL); if (wl_shm_buffer_get_format(buffer) == WL_SHM_FORMAT_XRGB8888) gs->shader = &gr->texture_shader_rgbx; @@ -1209,7 +1211,7 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer) gs->images[i]); } - es->pitch = buffer->width; + gs->pitch = buffer->width; } else { weston_log("unhandled buffer type!\n"); weston_buffer_reference(&gs->buffer_ref, NULL); @@ -1237,10 +1239,15 @@ gl_renderer_create_surface(struct weston_surface *surface) struct gl_surface_state *gs; gs = calloc(1, sizeof *gs); - if (!gs) return -1; + /* A buffer is never attached to solid color surfaces, yet + * they still go through texcoord computations. Do not divide + * by zero there. + */ + gs->pitch = 1; + surface->renderer_state = gs; return 0;