diff options
author | Igor Oliveira <igor.oliveira@openbossa.org> | 2010-07-08 13:16:54 -0400 |
---|---|---|
committer | Igor Oliveira <igor.oliveira@openbossa.org> | 2010-07-08 13:16:54 -0400 |
commit | 3336d8482db508137b33437e7cde026c159176dd (patch) | |
tree | 9ef5e7ca85ed33a5a8b2a76c6d11f5498186a58c | |
parent | 4ce0bdef25244369c67ad9fa3e8af86a48faf071 (diff) |
DRM/Gallium3d: make fill even odd works fine
-rw-r--r-- | src/drm/cairo-drm-gallium-surface.c | 101 |
1 files changed, 65 insertions, 36 deletions
diff --git a/src/drm/cairo-drm-gallium-surface.c b/src/drm/cairo-drm-gallium-surface.c index a3781a91..744e5c8c 100644 --- a/src/drm/cairo-drm-gallium-surface.c +++ b/src/drm/cairo-drm-gallium-surface.c @@ -32,6 +32,7 @@ */ #include "cairoint.h" +#include "cairo-boxes-private.h" #include "cairo-drm-private.h" #include "cairo-error-private.h" @@ -629,7 +630,7 @@ _gallium_surface_paint_solid (gallium_surface_t *surface, return CAIRO_STATUS_SUCCESS; } -#define MIN_POINTS 50 +#define MIN_POINTS 100 struct _gallium_path { cairo_matrix_t *ctm_inverse; @@ -653,6 +654,11 @@ struct _gallium_stroke { struct list_head list_head; gallium_path_t *current_path; + float minx; + float miny; + float maxx; + float maxy; + float line_width; }; @@ -665,6 +671,8 @@ _gallium_init_path () goto CLEAN; } + path->buf = 0; + path->points = (float *) malloc(sizeof(float) * MIN_POINTS * 2); if (path->points == NULL) { goto CLEAN; @@ -695,6 +703,8 @@ _gallium_init_stroke() stroker->list_head.next = 0; stroker->list_head.prev = 0; + stroker->minx = stroker->miny = stroker->maxx = stroker->maxy = 0; + return stroker; } @@ -718,7 +728,7 @@ _gallium_append_point (gallium_path_t *path, const cairo_point_t *point) path->points[path->count] = _cairo_fixed_to_double (point->x); path->points[path->count + 1] = _cairo_fixed_to_double (point->y); - printf("%f %f", path->points[0], path->points[1]); + printf("%f %f", path->points[path->count], path->points[path->count +1]); path->minx = MIN2(path->points[path->count], path->minx); path->maxx = MAX2(path->points[path->count], path->maxx); @@ -734,7 +744,8 @@ CLEAN: static void draw_path (gallium_surface_t *surface, - gallium_path_t *path) + gallium_path_t *path, + unsigned mode) { const int components = 2; gallium_device_t *device= gallium_device(surface); @@ -745,9 +756,11 @@ draw_path (gallium_surface_t *surface, int vert_size = path->count * sizeof(float); int num_vert = path->count * 0.5; - path->buf = pipe_buffer_create(device->pipe->screen, PIPE_BIND_CONSTANT_BUFFER, vert_size); - pipe_buffer_write(device->pipe, path->buf, 0, vert_size, path->points); - device->pipe->set_constant_buffer(device->pipe, PIPE_SHADER_VERTEX, 0, path->buf); + if (path->buf == NULL) { + path->buf = pipe_buffer_create(device->pipe->screen, PIPE_BIND_CONSTANT_BUFFER, vert_size); + pipe_buffer_write(device->pipe, path->buf, 0, vert_size, path->points); + device->pipe->set_constant_buffer(device->pipe, PIPE_SHADER_VERTEX, 0, path->buf); + } memset(&vbuffer, 0, sizeof(vbuffer)); vbuffer.buffer = path->buf; @@ -764,12 +777,7 @@ draw_path (gallium_surface_t *surface, velement.src_format = PIPE_FORMAT_R32G32_FLOAT; cso_set_vertex_elements(device->cso, 1, &velement); - _gallium_set_states(surface); - - ctx->draw_arrays(ctx, PIPE_PRIM_LINE_STRIP, - 0, num_vert); - - cso_restore_rasterizer(device->cso); + ctx->draw_arrays(ctx, mode, 0, num_vert); } static void @@ -891,14 +899,14 @@ _gallium_curve_to (void *closure, initial_point.x = 0; initial_point.y = 0; } - +/* if (path->ctm_inverse) { cairo_matrix_transform_point (path->ctm_inverse, initial_point.x, initial_point.y); cairo_matrix_transform_point (path->ctm_inverse, p0->x, p0->y); cairo_matrix_transform_point (path->ctm_inverse, p1->x, p1->y); cairo_matrix_transform_point (path->ctm_inverse, p2->x, p2->y); } - +*/ _cairo_spline_init(spline, _gallium_line_to, path, @@ -1056,13 +1064,14 @@ gallium_surface_stroke (void *abstract_surface, surface->rasterizer.line_width = gallium_stroke->line_width; + _gallium_set_states(abstract_surface); { struct list_head *head, *next; for (head = gallium_stroke->list_head.next; head != &gallium_stroke->list_head; head = next) { gallium_path_t *gallium_path = LIST_ENTRY (gallium_path_t, head, list); - draw_path(abstract_surface, gallium_path); + draw_path(abstract_surface, gallium_path, PIPE_PRIM_LINE_STRIP); _gallium_finish_path(gallium_path); gallium_surface_flush(abstract_surface); @@ -1084,7 +1093,7 @@ gallium_surface_fill (void *abstract_surface, cairo_clip_t *clip) { gallium_surface_t *surface = abstract_surface; - gallium_path_t *gallium_stroke; + gallium_stroke_t *gallium_stroke; gallium_device_t *device = gallium_device(surface); gallium_shader_t *shader = device->shader; struct pipe_depth_stencil_alpha_state st; @@ -1110,12 +1119,12 @@ gallium_surface_fill (void *abstract_surface, struct pipe_resource template; memset(&template, 0, sizeof(template)); template.target = PIPE_TEXTURE_2D; - template.format = PIPE_FORMAT_A8R8G8B8_UNORM; + template.format = PIPE_FORMAT_Z24_UNORM_S8_USCALED; template.width0 = surface->drm.width; template.height0 = surface->drm.height; template.depth0 = 1; template.last_level = 0; - template.bind = PIPE_BIND_RENDER_TARGET; + template.bind = PIPE_BIND_DEPTH_STENCIL; resource = device->screen->resource_create (device->screen, &template); @@ -1133,7 +1142,7 @@ gallium_surface_fill (void *abstract_surface, cso_save_blend(device->cso); struct pipe_blend_state blend; memset(&blend, 0, sizeof(struct pipe_blend_state)); - blend.rt[0].colormask = PIPE_MASK_R; /*disable colorwrites*/ + blend.rt[0].colormask = 0; /*disable colorwrites*/ blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; @@ -1144,36 +1153,56 @@ gallium_surface_fill (void *abstract_surface, } memset(&sr, 0, sizeof(struct pipe_stencil_ref)); cso_set_stencil_ref(device->cso, &sr); -/* - device->pipe->clear(device->pipe, PIPE_CLEAR_STENCIL, NULL, 0.0, 0); + + device->pipe->clear(device->pipe, PIPE_CLEAR_DEPTHSTENCIL, NULL, 1.0, 0); // initialize stencil st.depth.enabled = 1; st.stencil[0].enabled = 1; st.stencil[0].func = PIPE_FUNC_ALWAYS; - st.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE; - st.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE; - st.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; - st.stencil[0].valuemask = 1; + st.stencil[0].fail_op = PIPE_STENCIL_OP_KEEP; + st.stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP; + st.stencil[0].zpass_op = PIPE_STENCIL_OP_INVERT; + st.stencil[0].valuemask = ~0; st.stencil[0].writemask = 1; + st.stencil[1] = st.stencil[0]; cso_set_depth_stencil_alpha(device->cso, &st); - draw_path(abstract_surface, gallium_stroke->current_path); + { + struct list_head *head, *next; + + for (head = gallium_stroke->list_head.next; head != &gallium_stroke->list_head; head = next) { + gallium_path_t *gallium_path = LIST_ENTRY (gallium_path_t, head, list); + + draw_path(abstract_surface, gallium_path, PIPE_PRIM_TRIANGLE_FAN); + _gallium_finish_path(gallium_path); + + gallium_stroke->minx = MIN2(gallium_stroke->minx, gallium_path->minx); + gallium_stroke->maxx = MAX2(gallium_stroke->maxx, gallium_path->maxx); + + gallium_stroke->miny = MIN2(gallium_stroke->miny, gallium_path->miny); + gallium_stroke->maxy = MAX2(gallium_stroke->maxy, gallium_path->maxy); + + gallium_surface_flush(abstract_surface); + next = head->next; + } + } st.depth.enabled = 0; - st.stencil[0].func = PIPE_FUNC_EQUAL; - st.stencil[0].fail_op = PIPE_STENCIL_OP_KEEP; - st.stencil[0].zfail_op = PIPE_STENCIL_OP_KEEP; - st.stencil[0].zpass_op = PIPE_STENCIL_OP_KEEP; - st.stencil[0].valuemask = 1; + st.stencil[0].func = PIPE_FUNC_NOTEQUAL; + st.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE; + st.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE; + st.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE; + st.stencil[0].valuemask = ~0; + st.stencil[0].writemask = ~0; + st.stencil[1] = st.stencil[0]; cso_set_depth_stencil_alpha(device->cso, &st); cso_restore_blend(device->cso); - _gallium_draw_quad(surface, - gallium_path->minx, gallium_path->miny, - gallium_path->maxx, gallium_path->maxy); - _gallium_finish_path(gallium_path); + _gallium_draw_quad(surface, + gallium_stroke->minx, gallium_stroke->miny, + gallium_stroke->maxx, gallium_stroke->maxy); - gallium_surface_flush(abstract_surface);*/ + gallium_surface_flush(abstract_surface); cso_restore_depth_stencil_alpha(device->cso); printf("filling"); |