st/egl: Remove.
[mesa.git] / src / gallium / state_trackers / vega / path.c
index 06c96a355029aefd62ef9e618bd837860951622a..6448e642cd61c1bdd82cab448d697f2085d7fe2b 100644 (file)
@@ -192,7 +192,7 @@ struct path * path_create(VGPathDatatype dt, VGfloat scale, VGfloat bias,
 
    vg_init_object(&path->base, vg_current_context(), VG_OBJECT_PATH);
    path->caps = capabilities & VG_PATH_CAPABILITY_ALL;
-   vg_context_add_object(vg_current_context(), VG_OBJECT_PATH, path);
+   vg_context_add_object(vg_current_context(), &path->base);
 
    path->datatype = dt;
    path->scale = scale;
@@ -207,17 +207,35 @@ struct path * path_create(VGPathDatatype dt, VGfloat scale, VGfloat bias,
    return path;
 }
 
+static void polygon_array_cleanup(struct polygon_array *polyarray)
+{
+   if (polyarray->array) {
+      VGint i;
+
+      for (i = 0; i < polyarray->array->num_elements; i++) {
+         struct polygon *p = ((struct polygon **) polyarray->array->data)[i];
+         polygon_destroy(p);
+      }
+
+      array_destroy(polyarray->array);
+      polyarray->array = NULL;
+   }
+}
+
 void path_destroy(struct path *p)
 {
-   vg_context_remove_object(vg_current_context(), VG_OBJECT_PATH, p);
+   vg_context_remove_object(vg_current_context(), &p->base);
 
    array_destroy(p->segments);
    array_destroy(p->control_points);
-   array_destroy(p->fill_polys.polygon_array.array);
+
+   polygon_array_cleanup(&p->fill_polys.polygon_array);
 
    if (p->stroked.path)
       path_destroy(p->stroked.path);
 
+   vg_free_object(&p->base);
+
    FREE(p);
 }
 
@@ -302,7 +320,6 @@ static void convert_path(struct path *p,
    }
 }
 
-
 static void polygon_array_calculate_bounds( struct polygon_array *polyarray )
 {
    struct array *polys = polyarray->array;
@@ -352,6 +369,8 @@ static struct polygon_array * path_get_fill_polygons(struct path *p, struct matr
    void *coords = (VGfloat *)p->control_points->data;
    struct array *array;
 
+   memset(data, 0, sizeof(data));
+
    if (p->fill_polys.polygon_array.array)
    {
       if (memcmp( &p->fill_polys.matrix,
@@ -361,12 +380,12 @@ static struct polygon_array * path_get_fill_polygons(struct path *p, struct matr
          return &p->fill_polys.polygon_array;
       }
       else {
-         array_destroy( p->fill_polys.polygon_array.array );
-         p->fill_polys.polygon_array.array = NULL;
+         polygon_array_cleanup(&p->fill_polys.polygon_array);
       }
    }
 
-   array = array_create(sizeof(struct array*));
+   /* an array of pointers to polygons */
+   array = array_create(sizeof(struct polygon *));
 
    sx = sy = px = py = ox = oy = 0.f;
 
@@ -1068,10 +1087,8 @@ static INLINE VGubyte normalize_coords(struct path_iter_data *pd,
    }
       break;
    case VG_SCUBIC_TO: {
-      VGfloat x0, y0, x1, y1, x2, y2, x3, y3;
+      VGfloat x1, y1, x2, y2, x3, y3;
       data_at(&pd->coords, pd->path, 0, 4, data);
-      x0 = pd->ox;
-      y0 = pd->oy;
       x1 = 2*pd->ox-pd->px;
       y1 = 2*pd->oy-pd->py;
       x2 = data[0];
@@ -1111,6 +1128,7 @@ static INLINE VGubyte normalize_coords(struct path_iter_data *pd,
    default:
       abort();
       assert(!"Unknown segment!");
+      return 0;
    }
 }
 
@@ -1550,10 +1568,11 @@ void path_render(struct path *p, VGbitfield paintModes,
                            mat,
                            &paint_matrix)) {
       /* First the fill */
+      shader_set_surface_matrix(ctx->shader, mat);
       shader_set_paint(ctx->shader, ctx->state.vg.fill_paint);
       shader_set_paint_matrix(ctx->shader, &paint_matrix);
       shader_bind(ctx->shader);
-      path_fill(p, mat);
+      path_fill(p);
    }
 
    if ((paintModes & VG_STROKE_PATH) &&
@@ -1565,18 +1584,23 @@ void path_render(struct path *p, VGbitfield paintModes,
        *  taking place."*/
       if (ctx->state.vg.stroke.line_width.f <= 0)
          return;
+      shader_set_surface_matrix(ctx->shader, mat);
       shader_set_paint(ctx->shader, ctx->state.vg.stroke_paint);
       shader_set_paint_matrix(ctx->shader, &paint_matrix);
       shader_bind(ctx->shader);
-      path_stroke(p, mat);
+      path_stroke(p);
    }
 }
 
-void path_fill(struct path *p, struct matrix *mat)
+void path_fill(struct path *p)
 {
    struct vg_context *ctx = vg_current_context();
+   struct matrix identity;
+
+   matrix_load_identity(&identity);
+
    {
-      struct polygon_array *polygon_array = path_get_fill_polygons(p, mat);
+      struct polygon_array *polygon_array = path_get_fill_polygons(p, &identity);
       struct array *polys = polygon_array->array;
 
       if (!polygon_array || !polys || !polys->num_elements) {
@@ -1586,7 +1610,7 @@ void path_fill(struct path *p, struct matrix *mat)
    }
 }
 
-void path_stroke(struct path *p, struct matrix *mat)
+void path_stroke(struct path *p)
 {
    struct vg_context *ctx = vg_current_context();
    VGFillRule old_fill = ctx->state.vg.fill_rule;
@@ -1598,7 +1622,7 @@ void path_stroke(struct path *p, struct matrix *mat)
    if (stroke && !path_is_empty(stroke)) {
       ctx->state.vg.fill_rule = VG_NON_ZERO;
 
-      path_fill(stroke, mat);
+      path_fill(stroke);
 
       ctx->state.vg.fill_rule = old_fill;
    }