#include "vg_context.h"
#include "image.h"
#include "api.h"
+#include "handle.h"
#include "renderer.h"
#include "shaders_cache.h"
return;
}
- d = (struct vg_image*)dst;
- s = (struct vg_image*)src;
+ d = handle_to_image(dst);
+ s = handle_to_image(src);
if (vg_image_overlaps(d, s)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- d = (struct vg_image*)dst;
- s = (struct vg_image*)src;
+ d = handle_to_image(dst);
+ s = handle_to_image(src);
if (vg_image_overlaps(d, s)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- d = (struct vg_image*)dst;
- s = (struct vg_image*)src;
+ d = handle_to_image(dst);
+ s = handle_to_image(src);
if (vg_image_overlaps(d, s)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- d = (struct vg_image*)dst;
- s = (struct vg_image*)src;
+ d = handle_to_image(dst);
+ s = handle_to_image(src);
if (vg_image_overlaps(d, s)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- d = (struct vg_image*)dst;
- s = (struct vg_image*)src;
+ d = handle_to_image(dst);
+ s = handle_to_image(src);
if (vg_image_overlaps(d, s)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
#include "vg_translate.h"
#include "api_consts.h"
#include "api.h"
+#include "handle.h"
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
return VG_INVALID_HANDLE;
}
- return (VGImage)image_create(format, width, height);
+ return image_to_handle(image_create(format, width, height));
}
void vegaDestroyImage(VGImage image)
{
struct vg_context *ctx = vg_current_context();
- struct vg_image *img = (struct vg_image *)image;
+ struct vg_image *img = handle_to_image(image);
if (image == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- if (!vg_object_is_valid((void*)image, VG_OBJECT_IMAGE)) {
+ if (!vg_object_is_valid(image, VG_OBJECT_IMAGE)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
return;
}
- img = (struct vg_image*)image;
+ img = handle_to_image(image);
if (x + width < 0 || y + height < 0)
return;
return;
}
- img = (struct vg_image*)(image);
+ img = handle_to_image(image);
image_sub_data(img, data, dataStride, dataFormat,
x, y, width, height);
}
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- img = (struct vg_image*)image;
+ img = handle_to_image(image);
image_get_sub_data(img, data, dataStride, dataFormat,
x, y, width, height);
}
struct vg_image *p;
if (parent == VG_INVALID_HANDLE ||
- !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void*)parent) ||
- !vg_object_is_valid((void*)parent, VG_OBJECT_IMAGE)) {
+ !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, parent) ||
+ !vg_object_is_valid(parent, VG_OBJECT_IMAGE)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return VG_INVALID_HANDLE;
}
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return VG_INVALID_HANDLE;
}
- p = (struct vg_image *)parent;
+ p = handle_to_image(parent);
if (x > p->width || y > p->height) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return VG_INVALID_HANDLE;
return VG_INVALID_HANDLE;
}
- return (VGImage)image_child_image(p, x, y, width, height);
+ return image_to_handle(image_child_image(p, x, y, width, height));
}
VGImage vegaGetParent(VGImage image)
return VG_INVALID_HANDLE;
}
- img = (struct vg_image*)image;
+ img = handle_to_image(image);
if (img->parent)
- return (VGImage)img->parent;
+ return image_to_handle(img->parent);
else
return image;
}
return;
}
vg_validate_state(ctx);
- image_copy((struct vg_image*)dst, dx, dy,
- (struct vg_image*)src, sx, sy,
+ image_copy(handle_to_image(dst), dx, dy,
+ handle_to_image(src), sx, sy,
width, height, dither);
}
}
vg_validate_state(ctx);
- image_draw((struct vg_image*)image,
+ image_draw(handle_to_image(image),
&ctx->state.vg.image_user_to_surface_matrix);
}
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- image_set_pixels(dx, dy, (struct vg_image*)src, sx, sy, width,
+ image_set_pixels(dx, dy, handle_to_image(src), sx, sy, width,
height);
}
return;
}
- img = (struct vg_image*)dst;
+ img = handle_to_image(dst);
image_get_pixels(img, dx, dy,
sx, sy, width, height);
#include "mask.h"
#include "api.h"
+#include "handle.h"
#include "renderer.h"
#include "vg_context.h"
mask_fill(x, y, width, height, 0.f);
} else if (operation == VG_FILL_MASK) {
mask_fill(x, y, width, height, 1.f);
- } else if (vg_object_is_valid((void*)mask, VG_OBJECT_IMAGE)) {
- struct vg_image *image = (struct vg_image *)mask;
+ } else if (vg_object_is_valid(mask, VG_OBJECT_IMAGE)) {
+ struct vg_image *image = handle_to_image(mask);
mask_using_image(image, operation, x, y, width, height);
- } else if (vg_object_is_valid((void*)mask, VG_OBJECT_MASK)) {
- struct vg_mask_layer *layer = (struct vg_mask_layer *)mask;
+ } else if (vg_object_is_valid(mask, VG_OBJECT_MASK)) {
+ struct vg_mask_layer *layer = handle_to_masklayer(mask);
mask_using_layer(layer, operation, x, y, width, height);
} else {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- if (!vg_object_is_valid((void*)path, VG_OBJECT_PATH)) {
+ if (!vg_object_is_valid(path, VG_OBJECT_PATH)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
vg_validate_state(ctx);
- mask_render_to((struct path *)path, paintModes, operation);
+ mask_render_to(handle_to_path(path), paintModes, operation);
}
VGMaskLayer vegaCreateMaskLayer(VGint width, VGint height)
return VG_INVALID_HANDLE;
}
- return (VGMaskLayer)mask_layer_create(width, height);
+ return masklayer_to_handle(mask_layer_create(width, height));
}
void vegaDestroyMaskLayer(VGMaskLayer maskLayer)
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) {
+ if (!vg_object_is_valid(maskLayer, VG_OBJECT_MASK)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- mask = (struct vg_mask_layer *)maskLayer;
+ mask = handle_to_masklayer(maskLayer);
mask_layer_destroy(mask);
}
return;
}
- if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) {
+ if (!vg_object_is_valid(maskLayer, VG_OBJECT_MASK)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- mask = (struct vg_mask_layer*)maskLayer;
+ mask = handle_to_masklayer(maskLayer);
if (x + width > mask_layer_width(mask) ||
y + height > mask_layer_height(mask)) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- if (!vg_object_is_valid((void*)maskLayer, VG_OBJECT_MASK)) {
+ if (!vg_object_is_valid(maskLayer, VG_OBJECT_MASK)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
vg_validate_state(ctx);
- mask = (struct vg_mask_layer*)maskLayer;
+ mask = handle_to_masklayer(maskLayer);
mask_copy(mask, sx, sy, dx, dy, width, height);
}
#include "vg_context.h"
#include "paint.h"
#include "api.h"
+#include "handle.h"
+
VGPaint vegaCreatePaint(void)
{
- return (VGPaint) paint_create(vg_current_context());
+ return paint_to_handle(paint_create(vg_current_context()));
}
void vegaDestroyPaint(VGPaint p)
{
struct vg_context *ctx = vg_current_context();
- struct vg_paint *paint;
if (p == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- paint = (struct vg_paint *)p;
- paint_destroy(paint);
+ paint_destroy(handle_to_paint(p));
}
void vegaSetPaint(VGPaint paint, VGbitfield paintModes)
if (paint == VG_INVALID_HANDLE) {
/* restore the default */
- paint = (VGPaint)ctx->default_paint;
- } else if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) {
+ paint = paint_to_handle(ctx->default_paint);
+ } else if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
}
if (paintModes & VG_FILL_PATH) {
- ctx->state.vg.fill_paint = (struct vg_paint *)paint;
+ ctx->state.vg.fill_paint = handle_to_paint(paint);
}
if (paintModes & VG_STROKE_PATH) {
- ctx->state.vg.stroke_paint = (struct vg_paint *)paint;
+ ctx->state.vg.stroke_paint = handle_to_paint(paint);
}
}
}
if (paintMode == VG_FILL_PATH)
- paint = (VGPaint)ctx->state.vg.fill_paint;
+ paint = paint_to_handle(ctx->state.vg.fill_paint);
else if (paintMode == VG_STROKE_PATH)
- paint = (VGPaint)ctx->state.vg.stroke_paint;
+ paint = paint_to_handle(ctx->state.vg.stroke_paint);
- if (paint == (VGPaint)ctx->default_paint)
+ if (paint == paint_to_handle(ctx->default_paint))
paint = VG_INVALID_HANDLE;
return paint;
return;
}
- if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) {
+ if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- {
- struct vg_paint *p = (struct vg_paint *)paint;
- paint_set_colori(p, rgba);
- }
+
+ paint_set_colori(handle_to_paint(paint), rgba);
}
VGuint vegaGetColor(VGPaint paint)
return rgba;
}
- if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT)) {
+ if (!vg_object_is_valid(paint, VG_OBJECT_PAINT)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return rgba;
}
- p = (struct vg_paint *)paint;
+ p = handle_to_paint(paint);
return paint_colori(p);
}
struct vg_context *ctx = vg_current_context();
if (paint == VG_INVALID_HANDLE ||
- !vg_context_is_object_valid(ctx, VG_OBJECT_PAINT, (void *)paint)) {
+ !vg_context_is_object_valid(ctx, VG_OBJECT_PAINT, paint)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
if (pattern == VG_INVALID_HANDLE) {
- paint_set_type((struct vg_paint*)paint, VG_PAINT_TYPE_COLOR);
+ paint_set_type(handle_to_paint(paint), VG_PAINT_TYPE_COLOR);
return;
}
- if (!vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)pattern)) {
+ if (!vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, pattern)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- if (!vg_object_is_valid((void*)paint, VG_OBJECT_PAINT) ||
- !vg_object_is_valid((void*)pattern, VG_OBJECT_IMAGE)) {
+ if (!vg_object_is_valid(paint, VG_OBJECT_PAINT) ||
+ !vg_object_is_valid(pattern, VG_OBJECT_IMAGE)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- paint_set_pattern((struct vg_paint*)paint,
- (struct vg_image*)pattern);
+ paint_set_pattern(handle_to_paint(paint),
+ handle_to_image(pattern));
}
#include "vg_context.h"
#include "paint.h"
#include "path.h"
+#include "handle.h"
#include "image.h"
#include "text.h"
#include "matrix.h"
VGfloat value)
{
struct vg_context *ctx = vg_current_context();
- void *ptr = (void*)object;
+ void *ptr = handle_to_pointer(object);
- if (!object || object == VG_INVALID_HANDLE || !is_aligned(ptr)) {
+ if (object == VG_INVALID_HANDLE || !is_aligned(ptr)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
break;
case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: {
- struct vg_paint *p = (struct vg_paint *)object;
+ struct vg_paint *p = handle_to_paint(object);
paint_set_color_ramp_premultiplied(p, value);
}
break;
VGint value)
{
struct vg_context *ctx = vg_current_context();
- void *ptr = (void*)object;
+ void *ptr = handle_to_pointer(object);
- if (!object || object == VG_INVALID_HANDLE || !is_aligned(ptr)) {
+ if (object == VG_INVALID_HANDLE || !is_aligned(ptr)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
value > VG_PAINT_TYPE_PATTERN)
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
- struct vg_paint *paint = (struct vg_paint *)ptr;
+ struct vg_paint *paint = handle_to_paint(object);
paint_set_type(paint, value);
}
break;
value > VG_COLOR_RAMP_SPREAD_REFLECT)
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
- struct vg_paint *paint = (struct vg_paint *)ptr;
+ struct vg_paint *paint = handle_to_paint(object);
paint_set_spread_mode(paint, value);
}
break;
case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: {
- struct vg_paint *p = (struct vg_paint *)object;
+ struct vg_paint *p = handle_to_paint(object);
paint_set_color_ramp_premultiplied(p, value);
}
break;
value > VG_TILE_REFLECT)
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
- struct vg_paint *paint = (struct vg_paint *)ptr;
+ struct vg_paint *paint = handle_to_paint(object);
paint_set_pattern_tiling(paint, value);
}
break;
const VGfloat * values)
{
struct vg_context *ctx = vg_current_context();
- void *ptr = (void*)object;
+ void *ptr = handle_to_pointer(object);
VGint real_count = vgGetParameterVectorSize(object, paramType);
- if (!object || object == VG_INVALID_HANDLE || !is_aligned(ptr)) {
+ if (object == VG_INVALID_HANDLE || !is_aligned(ptr)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
if (count != 4)
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_set_color(paint, values);
}
}
if (count && count < 4)
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
count = MIN2(count, VEGA_MAX_COLOR_RAMP_STOPS);
paint_set_ramp_stops(paint, values, count);
{
if (count != 4)
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_set_linear_gradient(paint, values);
{
VGint vals[4];
if (count != 5)
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_set_radial_gradient(paint, values);
{
VGint vals[5];
const VGint * values)
{
struct vg_context *ctx = vg_current_context();
- void *ptr = (void*)object;
+ void *ptr = handle_to_pointer(object);
VGint real_count = vgGetParameterVectorSize(object, paramType);
- if (!object || object == VG_INVALID_HANDLE || !is_aligned(ptr)) {
+ if (object == VG_INVALID_HANDLE || !is_aligned(ptr)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
if (count != 4)
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_set_coloriv(paint, values);
}
}
else {
VGfloat *vals = 0;
int i;
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
if (count) {
vals = malloc(sizeof(VGfloat)*count);
for (i = 0; i < count; ++i)
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
VGfloat vals[4];
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
vals[0] = values[0];
vals[1] = values[1];
vals[2] = values[2];
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
else {
VGfloat vals[5];
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
vals[0] = values[0];
vals[1] = values[1];
vals[2] = values[2];
VGint paramType)
{
struct vg_context *ctx = vg_current_context();
- void *ptr = (void*)object;
- if (!ptr || object == VG_INVALID_HANDLE) {
+ if (object == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return 0;
}
case VG_PAINT_COLOR:
return 4;
case VG_PAINT_COLOR_RAMP_STOPS: {
- struct vg_paint *p = (struct vg_paint *)object;
+ struct vg_paint *p = handle_to_paint(object);
return paint_num_ramp_stops(p);
}
break;
VGint paramType)
{
struct vg_context *ctx = vg_current_context();
- void *ptr = (void*)object;
- if (!ptr || object == VG_INVALID_HANDLE) {
+ if (object == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return 0;
}
case VG_PATH_FORMAT:
return VG_PATH_FORMAT_STANDARD;
case VG_PATH_SCALE: {
- struct path *p = (struct path*)object;
+ struct path *p = handle_to_path(object);
return path_scale(p);
}
case VG_PATH_BIAS: {
- struct path *p = (struct path*)object;
+ struct path *p = handle_to_path(object);
return path_bias(p);
}
case VG_PATH_DATATYPE:
VGint paramType)
{
struct vg_context *ctx = vg_current_context();
- void *ptr = (void*)object;
- if (!ptr || object == VG_INVALID_HANDLE) {
+ if (object == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return 0;
}
switch(paramType) {
case VG_PAINT_TYPE: {
- struct vg_paint *paint = (struct vg_paint *)ptr;
+ struct vg_paint *paint = handle_to_paint(object);
return paint_type(paint);
}
break;
case VG_PAINT_COLOR_RAMP_SPREAD_MODE: {
- struct vg_paint *p = (struct vg_paint *)object;
+ struct vg_paint *p = handle_to_paint(object);
return paint_spread_mode(p);
}
case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: {
- struct vg_paint *p = (struct vg_paint *)object;
+ struct vg_paint *p = handle_to_paint(object);
return paint_color_ramp_premultiplied(p);
}
break;
case VG_PAINT_PATTERN_TILING_MODE: {
- struct vg_paint *p = (struct vg_paint *)object;
+ struct vg_paint *p = handle_to_paint(object);
return paint_pattern_tiling(p);
}
break;
case VG_PATH_BIAS:
return vgGetParameterf(object, paramType);
case VG_PATH_DATATYPE: {
- struct path *p = (struct path*)object;
+ struct path *p = handle_to_path(object);
return path_datatype(p);
}
case VG_PATH_NUM_SEGMENTS: {
- struct path *p = (struct path*)object;
+ struct path *p = handle_to_path(object);
return path_num_segments(p);
}
case VG_PATH_NUM_COORDS: {
- struct path *p = (struct path*)object;
+ struct path *p = handle_to_path(object);
return path_num_coords(p);
}
break;
case VG_IMAGE_FORMAT: {
- struct vg_image *img = (struct vg_image*)object;
+ struct vg_image *img = handle_to_image(object);
return img->format;
}
break;
case VG_IMAGE_WIDTH: {
- struct vg_image *img = (struct vg_image*)object;
+ struct vg_image *img = handle_to_image(object);
return img->width;
}
break;
case VG_IMAGE_HEIGHT: {
- struct vg_image *img = (struct vg_image*)object;
+ struct vg_image *img = handle_to_image(object);
return img->height;
}
break;
#ifdef OPENVG_VERSION_1_1
case VG_FONT_NUM_GLYPHS: {
- struct vg_font *font = (struct vg_font*)object;
+ struct vg_font *font = handle_to_font(object);
return font_num_glyphs(font);
}
break;
VGfloat * values)
{
struct vg_context *ctx = vg_current_context();
- void *ptr = (void*)object;
VGint real_count = vgGetParameterVectorSize(object, paramType);
- if (!ptr || object == VG_INVALID_HANDLE) {
+ if (object == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
switch(paramType) {
case VG_PAINT_TYPE: {
- struct vg_paint *p = (struct vg_paint *)object;
+ struct vg_paint *p = handle_to_paint(object);
values[0] = paint_type(p);
}
break;
case VG_PAINT_COLOR_RAMP_SPREAD_MODE: {
- struct vg_paint *p = (struct vg_paint *)object;
+ struct vg_paint *p = handle_to_paint(object);
values[0] = paint_spread_mode(p);
}
break;
case VG_PAINT_COLOR_RAMP_PREMULTIPLIED: {
- struct vg_paint *p = (struct vg_paint *)object;
+ struct vg_paint *p = handle_to_paint(object);
values[0] = paint_color_ramp_premultiplied(p);
}
break;
}
break;
case VG_PAINT_COLOR: {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_get_color(paint, values);
}
break;
case VG_PAINT_COLOR_RAMP_STOPS: {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_ramp_stops(paint, values, count);
}
break;
case VG_PAINT_LINEAR_GRADIENT: {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_linear_gradient(paint, values);
}
break;
case VG_PAINT_RADIAL_GRADIENT: {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_radial_gradient(paint, values);
}
break;
VGint * values)
{
struct vg_context *ctx = vg_current_context();
- void *ptr = (void*)object;
VGint real_count = vgGetParameterVectorSize(object, paramType);
- if (!ptr || object == VG_INVALID_HANDLE) {
+ if (object || object == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
break;
#endif
case VG_PAINT_COLOR: {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_get_coloriv(paint, values);
}
break;
case VG_PAINT_COLOR_RAMP_STOPS: {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_ramp_stopsi(paint, values, count);
}
break;
case VG_PAINT_LINEAR_GRADIENT: {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_linear_gradienti(paint, values);
}
break;
case VG_PAINT_RADIAL_GRADIENT: {
- struct vg_paint *paint = (struct vg_paint *)object;
+ struct vg_paint *paint = handle_to_paint(object);
paint_radial_gradienti(paint, values);
}
break;
#include "VG/openvg.h"
#include "vg_context.h"
+#include "handle.h"
#include "path.h"
#include "api.h"
return VG_INVALID_HANDLE;
}
- return (VGPath)path_create(datatype, scale, bias,
- segmentCapacityHint, coordCapacityHint,
- capabilities);
+ return path_to_handle(path_create(datatype, scale, bias,
+ segmentCapacityHint, coordCapacityHint,
+ capabilities));
}
void vegaClearPath(VGPath path, VGbitfield capabilities)
return;
}
- p = (struct path *)path;
+ p = handle_to_path(path);
path_clear(p, capabilities);
}
return;
}
- path = (struct path *)p;
+ path = handle_to_path(p);
path_destroy(path);
}
return;
}
- p = (struct path*)path;
+ p = handle_to_path(path);
current = path_capabilities(p);
path_set_capabilities(p, (current &
(~(capabilities & VG_PATH_CAPABILITY_ALL))));
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return 0;
}
- p = (struct path*)path;
+ p = handle_to_path(path);
return path_capabilities(p);
}
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- src = (struct path *)srcPath;
- dst = (struct path *)dstPath;
+ src = handle_to_path(srcPath);
+ dst = handle_to_path(dstPath);
if (!(path_capabilities(src) & VG_PATH_CAPABILITY_APPEND_FROM) ||
!(path_capabilities(dst) & VG_PATH_CAPABILITY_APPEND_TO)) {
}
}
- p = (struct path*)dstPath;
+ p = handle_to_path(dstPath);
if (!pathData || !is_aligned_to(pathData, path_datatype_size(p))) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- p = (struct path *)dstPath;
+ p = handle_to_path(dstPath);
if (!pathData || !is_aligned_to(pathData, path_datatype_size(p))) {
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- src = (struct path *)srcPath;
- dst = (struct path *)dstPath;
+ src = handle_to_path(srcPath);
+ dst = handle_to_path(dstPath);
if (!(path_capabilities(src) & VG_PATH_CAPABILITY_TRANSFORM_FROM) ||
!(path_capabilities(dst) & VG_PATH_CAPABILITY_TRANSFORM_TO)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return VG_FALSE;
}
- dst = (struct path *)dstPath;
- start = (struct path *)startPath;
- end = (struct path *)endPath;
+ dst = handle_to_path(dstPath);
+ start = handle_to_path(startPath);
+ end = handle_to_path(endPath);
if (!(path_capabilities(dst) & VG_PATH_CAPABILITY_INTERPOLATE_TO) ||
!(path_capabilities(start) & VG_PATH_CAPABILITY_INTERPOLATE_FROM) ||
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return -1;
}
- p = (struct path*)path;
+ p = handle_to_path(path);
if (!(path_capabilities(p) & VG_PATH_CAPABILITY_PATH_LENGTH)) {
vg_set_error(ctx, VG_PATH_CAPABILITY_ERROR);
return;
}
- p = (struct path*)path;
+ p = handle_to_path(path);
caps = path_capabilities(p);
if (!(caps & VG_PATH_CAPABILITY_POINT_ALONG_PATH) ||
return;
}
- p = (struct path*)path;
+ p = handle_to_path(path);
caps = path_capabilities(p);
if (!(caps & VG_PATH_CAPABILITY_PATH_BOUNDS)) {
return;
}
- p = (struct path*)path;
+ p = handle_to_path(path);
caps = path_capabilities(p);
if (!(caps & VG_PATH_CAPABILITY_PATH_TRANSFORMED_BOUNDS)) {
void vegaDrawPath(VGPath path, VGbitfield paintModes)
{
struct vg_context *ctx = vg_current_context();
+ struct path *p = handle_to_path(path);
if (path == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- if (path_is_empty((struct path*)path))
+ if (path_is_empty(p))
return;
- path_render((struct path*)path, paintModes,
+ path_render(p, paintModes,
&ctx->state.vg.path_user_to_surface_matrix);
}
#include "vg_context.h"
#include "text.h"
#include "api.h"
+#include "handle.h"
#include "util/u_memory.h"
return VG_INVALID_HANDLE;
}
- return (VGFont) font_create(glyphCapacityHint);
+ return font_to_handle(font_create(glyphCapacityHint));
}
void vegaDestroyFont(VGFont f)
{
- struct vg_font *font = (struct vg_font *)f;
+ struct vg_font *font = handle_to_font(f);
struct vg_context *ctx = vg_current_context();
if (f == VG_INVALID_HANDLE) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- if (!vg_object_is_valid((void *) font, VG_OBJECT_FONT)) {
+ if (!vg_object_is_valid(f, VG_OBJECT_FONT)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
struct vg_font *f;
if (font == VG_INVALID_HANDLE ||
- !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, (void *)font)) {
+ !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, font)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
return;
}
if (path != VG_INVALID_HANDLE &&
- !vg_context_is_object_valid(ctx, VG_OBJECT_PATH, (void *)path)) {
+ !vg_context_is_object_valid(ctx, VG_OBJECT_PATH, path)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- pathObj = (struct path*) path;
- f = (struct vg_font*) font;
+ pathObj = handle_to_path(path);
+ f = handle_to_font(font);
font_set_glyph_to_path(f, glyphIndex, pathObj,
isHinted, glyphOrigin, escapement);
struct vg_font *f;
if (font == VG_INVALID_HANDLE ||
- !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, (void *)font)) {
+ !vg_context_is_object_valid(ctx, VG_OBJECT_FONT, font)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
return;
}
if (image != VG_INVALID_HANDLE &&
- !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, (void *)image)) {
+ !vg_context_is_object_valid(ctx, VG_OBJECT_IMAGE, image)) {
vg_set_error(ctx, VG_BAD_HANDLE_ERROR);
return;
}
- img_obj = (struct vg_image*)image;
- f = (struct vg_font*)font;
+ img_obj = handle_to_image(image);
+ f = handle_to_font(font);
font_set_glyph_to_image(f, glyphIndex, img_obj, glyphOrigin, escapement);
}
return;
}
- f = (struct vg_font*) font;
+ f = handle_to_font(font);
font_clear_glyph(f, glyphIndex);
}
vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
return;
}
- f = (struct vg_font*)font;
+ f = handle_to_font(font);
font_draw_glyph(f, glyphIndex, paintModes, allowAutoHinting);
}
return;
}
- f = (struct vg_font*)font;
+ f = handle_to_font(font);
font_draw_glyphs(f, glyphCount, glyphIndices,
adjustments_x, adjustments_y, paintModes, allowAutoHinting);
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2010 VMware, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+/**
+ * Convert opaque VG object handles into pointers and vice versa.
+ * XXX This is not yet 64-bit safe! All VG handles are 32 bits in size.
+ */
+
+
+#ifndef HANDLE_H
+#define HANDLE_H
+
+#include "VG/openvg.h"
+#include "pipe/p_compiler.h"
+
+
+struct vg_mask_layer;
+struct vg_font;
+struct vg_image;
+struct vg_paint;
+struct path;
+
+
+static INLINE VGHandle
+image_to_handle(struct vg_image *img)
+{
+ return (VGHandle) img;
+}
+
+
+static INLINE VGHandle
+masklayer_to_handle(struct vg_mask_layer *mask)
+{
+ return (VGHandle) mask;
+}
+
+
+static INLINE VGHandle
+font_to_handle(struct vg_font *font)
+{
+ return (VGHandle) font;
+}
+
+static INLINE VGHandle
+paint_to_handle(struct vg_paint *paint)
+{
+ return (VGHandle) paint;
+}
+
+static INLINE VGHandle
+path_to_handle(struct path *path)
+{
+ return (VGHandle) path;
+}
+
+
+static INLINE void *
+handle_to_pointer(VGHandle h)
+{
+ return (void *) h;
+}
+
+
+static INLINE struct vg_font *
+handle_to_font(VGHandle h)
+{
+ return (struct vg_font *) handle_to_pointer(h);
+}
+
+
+static INLINE struct vg_image *
+handle_to_image(VGHandle h)
+{
+ return (struct vg_image *) handle_to_pointer(h);
+}
+
+
+static INLINE struct vg_mask_layer *
+handle_to_masklayer(VGHandle h)
+{
+ return (struct vg_mask_layer *) handle_to_pointer(h);
+}
+
+
+static INLINE struct vg_object *
+handle_to_object(VGHandle h)
+{
+ return (struct vg_object *) handle_to_pointer(h);
+}
+
+
+static INLINE struct vg_paint *
+handle_to_paint(VGHandle h)
+{
+ return (struct vg_paint *) handle_to_pointer(h);
+}
+
+
+static INLINE struct path *
+handle_to_path(VGHandle h)
+{
+ return (struct path *) handle_to_pointer(h);
+}
+
+
+#endif /* HANDLE_H */
#include "vg_manager.h"
#include "api.h"
#include "mask.h"
+#include "handle.h"
#include "pipe/p_context.h"
#include "util/u_inlines.h"
VGboolean vg_context_is_object_valid(struct vg_context *ctx,
enum vg_object_type type,
- void *ptr)
+ VGHandle object)
{
if (ctx) {
struct cso_hash *hash = ctx->owned_objects[type];
if (!hash)
return VG_FALSE;
- return cso_hash_contains(hash, (unsigned)(long)ptr);
+ return cso_hash_contains(hash, (unsigned)(long)object);
}
return VG_FALSE;
}
shader_set_color_transform(ctx->shader, ctx->state.vg.color_transform);
}
-VGboolean vg_object_is_valid(void *ptr, enum vg_object_type type)
+VGboolean vg_object_is_valid(VGHandle object, enum vg_object_type type)
{
- struct vg_object *obj = ptr;
- if (ptr && is_aligned(obj) && obj->type == type)
+ struct vg_object *obj = handle_to_object(object);
+ if (object && is_aligned(obj) && obj->type == type)
return VG_TRUE;
else
return VG_FALSE;
struct vg_context *ctx;
};
void vg_init_object(struct vg_object *obj, struct vg_context *ctx, enum vg_object_type type);
-VGboolean vg_object_is_valid(void *ptr, enum vg_object_type type);
+VGboolean vg_object_is_valid(VGHandle object, enum vg_object_type type);
struct vg_context *vg_create_context(struct pipe_context *pipe,
const void *visual,
VGboolean vg_context_is_object_valid(struct vg_context *ctx,
enum vg_object_type type,
- void *ptr);
+ VGHandle object);
void vg_context_add_object(struct vg_context *ctx,
enum vg_object_type type,
void *ptr);
#include "matrix.h"
#include "path.h"
+#include "handle.h"
#include "util/u_debug.h"
#include "util/u_pointer.h"
VGint num_coords)
{
VGubyte common_data[40 * sizeof(VGfloat)];
- struct path *p = (struct path *)path;
+ struct path *p = handle_to_path(path);
vg_float_to_datatype(path_datatype(p), common_data, coords, num_coords);
vgAppendPathData(path, num_cmds, cmds, common_data);