struct vg_font *font_create(VGint glyphCapacityHint) { struct vg_context *ctx = vg_current_context(); struct vg_font *font; font = CALLOC_STRUCT(vg_font); vg_init_object(&font->base, ctx, VG_OBJECT_FONT); font->glyphs = cso_hash_create(); vg_context_add_object(ctx, &font->base); return font; }
VGFont vgCreateFont(VGint glyphCapacityHint) { struct vg_font *font = 0; struct vg_context *ctx = vg_current_context(); if (glyphCapacityHint < 0) { vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); return VG_INVALID_HANDLE; } font = CALLOC_STRUCT(vg_font); vg_init_object(&font->base, ctx, VG_OBJECT_FONT); vg_context_add_object(ctx, VG_OBJECT_FONT, font); return (VGFont)font; }
struct vg_image * image_create(VGImageFormat format, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); struct vg_image *image = CALLOC_STRUCT(vg_image); enum pipe_format pformat = vg_format_to_pipe(format); struct pipe_texture pt, *newtex; struct pipe_screen *screen = ctx->pipe->screen; vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); image->format = format; image->width = width; image->height = height; 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; assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER, 0)); memset(&pt, 0, sizeof(pt)); pt.target = PIPE_TEXTURE_2D; pt.format = pformat; pt.last_level = 0; pt.width0 = width; pt.height0 = height; pt.depth0 = 1; pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; newtex = screen->texture_create(screen, &pt); debug_assert(newtex); image->texture = newtex; vg_context_add_object(ctx, VG_OBJECT_IMAGE, image); image_cleari(image, 0, 0, 0, image->width, image->height); return image; }
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; }
struct vg_image * image_create(VGImageFormat format, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; struct vg_image *image = CALLOC_STRUCT(vg_image); enum pipe_format pformat = vg_format_to_pipe(format); struct pipe_resource pt, *newtex; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; struct pipe_screen *screen = ctx->pipe->screen; vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); image->format = format; image->width = width; image->height = height; 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; assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW)); memset(&pt, 0, sizeof(pt)); pt.target = PIPE_TEXTURE_2D; pt.format = pformat; pt.last_level = 0; pt.width0 = width; pt.height0 = height; pt.depth0 = 1; pt.array_size = 1; pt.bind = PIPE_BIND_SAMPLER_VIEW; newtex = screen->resource_create(screen, &pt); debug_assert(newtex); u_sampler_view_default_template(&view_templ, newtex, newtex->format); /* R, G, and B are treated as 1.0 for alpha-only formats in OpenVG */ if (newtex->format == PIPE_FORMAT_A8_UNORM) { view_templ.swizzle_r = PIPE_SWIZZLE_ONE; view_templ.swizzle_g = PIPE_SWIZZLE_ONE; view_templ.swizzle_b = PIPE_SWIZZLE_ONE; } view = pipe->create_sampler_view(pipe, newtex, &view_templ); /* want the texture to go away if the view is freed */ pipe_resource_reference(&newtex, NULL); image->sampler_view = view; vg_context_add_object(ctx, &image->base); image_cleari(image, 0, 0, 0, image->width, image->height); return image; }