third_party/cairo/src/cairo-cogl-surface.c
static void
_cairo_cogl_apply_tex_clips (cairo_cogl_surface_t  *surface,
                             int                   *clip_stack_depth,
                             cairo_cogl_pipeline_t *pipeline)
{
    CoglDepthState depth_state;
    CoglBool cogl_status;

    /* Enable the depth test if it will be needed */
    if ((!pipeline->mask_bounded && pipeline->has_mask_tex_clip) ||
        (!pipeline->src_bounded && pipeline->has_src_tex_clip))
    {
        cogl_depth_state_init (&depth_state);
        cogl_depth_state_set_test_enabled (&depth_state, TRUE);
        cogl_status = cogl_pipeline_set_depth_state (pipeline->pipeline,
                                                     &depth_state,
                                                     NULL);
        if (unlikely (cogl_status != TRUE))
            g_warning ("Error setting depth state for unbounded render");

        /* Clear the depth buffer to 1.0. The color values are unused
         * placeholders. */
        cogl_framebuffer_clear4f (surface->framebuffer,
                                  COGL_BUFFER_BIT_DEPTH,
                                  0.0, 0.0, 0.0, 0.0);
    }

    if (pipeline->mask_bounded && !pipeline->src_bounded) {
        /* Push mask clip first so later we can pop the source clip
         * and still be bound by the mask clip */
        if (pipeline->has_mask_tex_clip)
            _cairo_cogl_set_path_prim_clip (surface,
                                            &pipeline->mask_tex_clip,
                                            clip_stack_depth,
                                            CAIRO_FILL_RULE_WINDING,
                                            0.0);
        if (pipeline->has_src_tex_clip)
            _cairo_cogl_set_path_prim_clip (surface,
                                            &pipeline->src_tex_clip,
                                            clip_stack_depth,
                                            CAIRO_FILL_RULE_WINDING,
                                            0.0);
    } else {
        if (pipeline->has_src_tex_clip)
            _cairo_cogl_set_path_prim_clip (surface,
                                            &pipeline->src_tex_clip,
                                            clip_stack_depth,
                                            CAIRO_FILL_RULE_WINDING,
                                            0.0);
        if (pipeline->has_mask_tex_clip)
            _cairo_cogl_set_path_prim_clip (surface,
                                            &pipeline->mask_tex_clip,
                                            clip_stack_depth,
                                            CAIRO_FILL_RULE_WINDING,
                                            0.0);
    }
}
/* This is the way in which we handle CAIRO_EXTEND_NONE set on the
 * source or mask pattern surfaces, as well as unbounded operators.
 * First, we limit the rendering area to the region which will not be
 * sampled from beyond the source or mask textures with additional clip
 * paths, which were created when we obtained the original pipeline.
 * The region will also be limited by the drawing area due to the fact
 * we are drawing with the original primitive's vertices.
 *
 * In order to handle unbounded operators, we do a second rendering pass
 * for places outside of such region. We limit the rending to outside
 * this region by using a depth buffer to preserve all places where
 * rendering took place during the first pass. For this region, we also
 * have to remove the CAIRO_EXTEND_NONE clips if the operator is not
 * bound by their respective contents. Because OpenGL sets all vertex
 * z-values to 0.0 if none are supplied in the attributes data (we only
 * supply x and y values), it will update the region in the buffer to a
 * value over the default clearing value of 1.0. Given that the default
 * test function is GL_LESS, we don't have to set z attributes on the
 * vertices of the second rendering pass either, as 0.0 will never be
 * less than 0.0. If cogl ever adds a method to clip out a primitive
 * instead of just clipping it in, we may be able to use a more
 * efficient method using the stencil buffer. */
This is the way in which we handle CAIRO_EXTEND_NONE set on the
source or mask pattern surfaces, as well as unbounded operators.
First, we limit the rendering area to the region which will not be
sampled from beyond the source or mask textures with additional clip
paths, which were created when we obtained the original pipeline.
The region will also be limited by the drawing area due to the fact
we are drawing with the original primitive's vertices.

In order to handle unbounded operators, we do a second rendering pass
for places outside of such region. We limit the rending to outside
this region by using a depth buffer to preserve all places where
rendering took place during the first pass. For this region, we also
have to remove the CAIRO_EXTEND_NONE clips if the operator is not
bound by their respective contents. Because OpenGL sets all vertex
z-values to 0.0 if none are supplied in the attributes data (we only
supply x and y values), it will update the region in the buffer to a
value over the default clearing value of 1.0. Given that the default
test function is GL_LESS, we don't have to set z attributes on the
vertices of the second rendering pass either, as 0.0 will never be
less than 0.0. If cogl ever adds a method to clip out a primitive
instead of just clipping it in, we may be able to use a more
efficient method using the stencil buffer.
This is the way in which we handle CAIRO_EXTEND_NONE set on the source or mask pattern surfaces as well as unbounded operators . First we limit the rendering area to the region which will not be sampled from beyond the source or mask textures with additional clip paths which were created when we obtained the original pipeline . The region will also be limited by the drawing area due to the fact we are drawing with the original primitive ' s vertices . In order to handle unbounded operators we do a second rendering pass for places outside of such region . We limit the rending to outside this region by using a depth buffer to preserve all places where rendering took place during the first pass . For this region we also have to remove the CAIRO_EXTEND_NONE clips if the operator is not bound by their respective contents . Because OpenGL sets all vertex z - values to 0 . 0 if none are supplied in the attributes data ( we only supply x and y values ) it will update the region in the buffer to a value over the default clearing value of 1 . 0 . Given that the default test function is GL_LESS we don ' t have to set z attributes on the vertices of the second rendering pass either as 0 . 0 will never be less than 0 . 0 . If cogl ever adds a method to clip out a primitive instead of just clipping it in we may be able to use a more efficient method using the stencil buffer .
static void
_cairo_cogl_apply_tex_clips (cairo_cogl_surface_t  *surface,
                             int                   *clip_stack_depth,
                             cairo_cogl_pipeline_t *pipeline)
{
    CoglDepthState depth_state;
    CoglBool cogl_status;
    if ((!pipeline->mask_bounded && pipeline->has_mask_tex_clip) ||
        (!pipeline->src_bounded && pipeline->has_src_tex_clip))
    {
        cogl_depth_state_init (&depth_state);
        cogl_depth_state_set_test_enabled (&depth_state, TRUE);
        cogl_status = cogl_pipeline_set_depth_state (pipeline->pipeline,
                                                     &depth_state,
                                                     NULL);
        if (unlikely (cogl_status != TRUE))
            g_warning ("Error setting depth state for unbounded render");
        cogl_framebuffer_clear4f (surface->framebuffer,
                                  COGL_BUFFER_BIT_DEPTH,
                                  0.0, 0.0, 0.0, 0.0);
    }
    if (pipeline->mask_bounded && !pipeline->src_bounded) {
        if (pipeline->has_mask_tex_clip)
            _cairo_cogl_set_path_prim_clip (surface,
                                            &pipeline->mask_tex_clip,
                                            clip_stack_depth,
                                            CAIRO_FILL_RULE_WINDING,
                                            0.0);
        if (pipeline->has_src_tex_clip)
            _cairo_cogl_set_path_prim_clip (surface,
                                            &pipeline->src_tex_clip,
                                            clip_stack_depth,
                                            CAIRO_FILL_RULE_WINDING,
                                            0.0);
    } else {
        if (pipeline->has_src_tex_clip)
            _cairo_cogl_set_path_prim_clip (surface,
                                            &pipeline->src_tex_clip,
                                            clip_stack_depth,
                                            CAIRO_FILL_RULE_WINDING,
                                            0.0);
        if (pipeline->has_mask_tex_clip)
            _cairo_cogl_set_path_prim_clip (surface,
                                            &pipeline->mask_tex_clip,
                                            clip_stack_depth,
                                            CAIRO_FILL_RULE_WINDING,
                                            0.0);
    }
}
static void _cairo_cogl_apply_tex_clips ( cairo_cogl_surface_t * surface , int * clip_stack_depth , cairo_cogl_pipeline_t * pipeline ) { CoglDepthState depth_state ; CoglBool cogl_status ; if ( ( ! pipeline -> mask_bounded && pipeline -> has_mask_tex_clip ) || ( ! pipeline -> src_bounded && pipeline -> has_src_tex_clip ) ) { cogl_depth_state_init ( & depth_state ) ; cogl_depth_state_set_test_enabled ( & depth_state , TRUE ) ; cogl_status = cogl_pipeline_set_depth_state ( pipeline -> pipeline , & depth_state , NULL ) ; if ( unlikely ( cogl_status != TRUE ) ) g_warning ( " " ) ; cogl_framebuffer_clear4f ( surface -> framebuffer , COGL_BUFFER_BIT_DEPTH , 0.0 , 0.0 , 0.0 , 0.0 ) ; } if ( pipeline -> mask_bounded && ! pipeline -> src_bounded ) { if ( pipeline -> has_mask_tex_clip ) _cairo_cogl_set_path_prim_clip ( surface , & pipeline -> mask_tex_clip , clip_stack_depth , CAIRO_FILL_RULE_WINDING , 0.0 ) ; if ( pipeline -> has_src_tex_clip ) _cairo_cogl_set_path_prim_clip ( surface , & pipeline -> src_tex_clip , clip_stack_depth , CAIRO_FILL_RULE_WINDING , 0.0 ) ; } else { if ( pipeline -> has_src_tex_clip ) _cairo_cogl_set_path_prim_clip ( surface , & pipeline -> src_tex_clip , clip_stack_depth , CAIRO_FILL_RULE_WINDING , 0.0 ) ; if ( pipeline -> has_mask_tex_clip ) _cairo_cogl_set_path_prim_clip ( surface , & pipeline -> mask_tex_clip , clip_stack_depth , CAIRO_FILL_RULE_WINDING , 0.0 ) ; } }
This is the way in which we handle CAIRO_EXTEND_NONE set on the
 source or mask pattern surfaces, as well as unbounded operators.
This is the way in which we handle CAIRO_EXTEND_NONE set on the source or mask pattern surfaces as well as unbounded operators .
/* Enable the depth test if it will be needed */ /* Clear the depth buffer to 1.0. The color values are unused
         * placeholders. */ /* Push mask clip first so later we can pop the source clip
         * and still be bound by the mask clip */