void image_destroy(struct vg_image *img) { struct vg_context *ctx = vg_current_context(); vg_context_remove_object(ctx, VG_OBJECT_IMAGE, img); if (img->parent) { /* remove img from the parent child array */ int idx; struct vg_image **array = (struct vg_image **)img->parent->children_array->data; for (idx = 0; idx < img->parent->children_array->num_elements; ++idx) { struct vg_image *child = array[idx]; if (child == img) { break; } } debug_assert(idx < img->parent->children_array->num_elements); array_remove_element(img->parent->children_array, idx); } if (img->children_array && img->children_array->num_elements) { /* reparent the children */ VGint i; struct vg_image *parent = img->parent; struct vg_image **children = (struct vg_image **)img->children_array->data; if (!parent) { VGint min_x = children[0]->x; parent = children[0]; for (i = 1; i < img->children_array->num_elements; ++i) { struct vg_image *child = children[i]; if (child->x < min_x) { parent = child; } } } for (i = 0; i < img->children_array->num_elements; ++i) { struct vg_image *child = children[i]; if (child != parent) { child->parent = parent; if (!parent->children_array) { parent->children_array = array_create( sizeof(struct vg_image*)); } array_append_data(parent->children_array, &child, 1); } else child->parent = NULL; } array_destroy(img->children_array); } pipe_texture_reference(&img->texture, NULL); free(img); }
struct vg_image * image_child_image(struct vg_image *parent, VGint x, VGint y, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); struct vg_image *image = CALLOC_STRUCT(vg_image); vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); image->x = parent->x + x; image->y = parent->y + y; image->width = width; image->height = height; image->parent = parent; image->sampler_view = NULL; pipe_sampler_view_reference(&image->sampler_view, parent->sampler_view); image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; image->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; image->sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; image->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; image->sampler.normalized_coords = 1; if (!parent->children_array) parent->children_array = array_create( sizeof(struct vg_image*)); array_append_data(parent->children_array, &image, 1); vg_context_add_object(ctx, &image->base); return image; }