gl: Introduce _cairo_gl_device_has_glsl() function

The function takes a cairo_device_t argument as it can be called on an
unacquired device.

This is the first patch in a process to try to rid cairo-gl-surface.c of
casts from cairo_device_t to cairo_gl_context_t. As its members should
usually only be accessed when the device is locked, the only way the
cairo_gl_context_t should be acquired is using
_cairo_gl_context_acquire().
This commit is contained in:
Benjamin Otte 2010-05-05 12:21:23 +02:00
parent 5223b65423
commit 58b03691d3
3 changed files with 11 additions and 6 deletions

View file

@ -316,7 +316,7 @@ _cairo_gl_glyphs_set_shader (cairo_gl_context_t *ctx,
if (setup->in == in)
return;
if (ctx->using_glsl) {
if (_cairo_gl_device_has_glsl (&ctx->base)) {
cairo_status_t status;
status = _cairo_gl_get_program (ctx,

View file

@ -224,6 +224,12 @@ _cairo_gl_operand_init (cairo_gl_context_t *ctx,
int dst_x, int dst_y,
int width, int height);
static cairo_always_inline cairo_bool_t
_cairo_gl_device_has_glsl (cairo_device_t *device)
{
return ((cairo_gl_context_t *) device)->using_glsl;
}
static cairo_always_inline cairo_status_t cairo_warn
_cairo_gl_context_acquire (cairo_device_t *device,
cairo_gl_context_t **ctx)

View file

@ -637,7 +637,7 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
GLuint tex;
GLfloat vertices[8], texcoords[8];
if (ctx->using_glsl) {
if (_cairo_gl_device_has_glsl (&ctx->base)) {
cairo_gl_shader_program_t *program;
status = _cairo_gl_get_program (ctx,
@ -710,7 +710,7 @@ _cairo_gl_surface_draw_image (cairo_gl_surface_t *dst,
glDisableClientState (GL_VERTEX_ARRAY);
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
if (ctx->using_glsl)
if (_cairo_gl_device_has_glsl (&ctx->base))
_cairo_gl_use_program (NULL);
glDeleteTextures (1, &tex);
glDisable (ctx->tex_target);
@ -1268,7 +1268,7 @@ _cairo_gl_gradient_operand_init(cairo_gl_context_t *ctx,
}
}
if (!ctx->using_glsl)
if (! _cairo_gl_device_has_glsl (&ctx->base))
return CAIRO_INT_STATUS_UNSUPPORTED;
if (gradient->base.type == CAIRO_PATTERN_TYPE_LINEAR) {
@ -2487,9 +2487,8 @@ _cairo_gl_surface_fill_rectangles (void *abstract_surface,
int num_rects)
{
cairo_gl_surface_t *surface = abstract_surface;
cairo_gl_context_t *ctx = (cairo_gl_context_t *) surface->base.device;
if (ctx->using_glsl) {
if (_cairo_gl_device_has_glsl (surface->base.device)) {
return _cairo_gl_surface_fill_rectangles_glsl(abstract_surface,
op,
color,