compositor: use GL_EXT_unpack_subimage only if available

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This commit is contained in:
Pekka Paalanen
2012-04-11 16:19:37 +03:00
parent 2eaa11e954
commit 52bfbaae14
2 changed files with 34 additions and 14 deletions
+31 -14
View File
@@ -1165,6 +1165,33 @@ surface_attach(struct wl_client *client,
es->configure(es, sx, sy); es->configure(es, sx, sy);
} }
static void
texture_set_subimage(struct weston_surface *surface,
int32_t x, int32_t y, int32_t width, int32_t height)
{
glBindTexture(GL_TEXTURE_2D, surface->texture);
#ifdef GL_UNPACK_ROW_LENGTH
/* Mesa does not define GL_EXT_unpack_subimage */
if (surface->compositor->has_unpack_subimage) {
glPixelStorei(GL_UNPACK_ROW_LENGTH, surface->pitch);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
glPixelStorei(GL_UNPACK_SKIP_ROWS, y);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height,
GL_BGRA_EXT, GL_UNSIGNED_BYTE,
wl_shm_buffer_get_data(surface->buffer));
return;
}
#endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT,
surface->pitch, surface->buffer->height, 0,
GL_BGRA_EXT, GL_UNSIGNED_BYTE,
wl_shm_buffer_get_data(surface->buffer));
}
static void static void
surface_damage(struct wl_client *client, surface_damage(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
@@ -1174,16 +1201,8 @@ surface_damage(struct wl_client *client,
weston_surface_damage_rectangle(es, x, y, width, height); weston_surface_damage_rectangle(es, x, y, width, height);
if (es->buffer && wl_buffer_is_shm(es->buffer)) { if (es->buffer && wl_buffer_is_shm(es->buffer))
glBindTexture(GL_TEXTURE_2D, es->texture); texture_set_subimage(es, x, y, width, height);
glPixelStorei(GL_UNPACK_ROW_LENGTH, es->pitch);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
glPixelStorei(GL_UNPACK_SKIP_ROWS, y);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height,
GL_BGRA_EXT, GL_UNSIGNED_BYTE,
wl_shm_buffer_get_data(es->buffer));
}
} }
static void static void
@@ -2372,10 +2391,8 @@ weston_compositor_init(struct weston_compositor *ec, struct wl_display *display)
return -1; return -1;
} }
if (!strstr(extensions, "GL_EXT_unpack_subimage")) { if (strstr(extensions, "GL_EXT_unpack_subimage"))
fprintf(stderr, "GL_EXT_unpack_subimage not available\n"); ec->has_unpack_subimage = 1;
return -1;
}
extensions = extensions =
(const char *) eglQueryString(ec->display, EGL_EXTENSIONS); (const char *) eglQueryString(ec->display, EGL_EXTENSIONS);
+3
View File
@@ -221,6 +221,9 @@ struct weston_compositor {
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d; PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
PFNEGLCREATEIMAGEKHRPROC create_image; PFNEGLCREATEIMAGEKHRPROC create_image;
PFNEGLDESTROYIMAGEKHRPROC destroy_image; PFNEGLDESTROYIMAGEKHRPROC destroy_image;
int has_unpack_subimage;
PFNEGLBINDWAYLANDDISPLAYWL bind_display; PFNEGLBINDWAYLANDDISPLAYWL bind_display;
PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display; PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display;
int has_bind_display; int has_bind_display;