1/************************************************************************** 2 * 3 * Copyright 2009 VMware, Inc. All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sub license, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the 14 * next paragraph) shall be included in all copies or substantial portions 15 * of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * 25 **************************************************************************/ 26 27#include "VG/openvg.h" 28 29#include "vg_context.h" 30 31#include "matrix.h" 32#include "api.h" 33 34void vegaLoadIdentity(void) 35{ 36 struct vg_context *ctx = vg_current_context(); 37 struct matrix *mat = vg_state_matrix(&ctx->state.vg); 38 matrix_load_identity(mat); 39} 40 41void vegaLoadMatrix(const VGfloat * m) 42{ 43 struct vg_context *ctx = vg_current_context(); 44 struct matrix *mat; 45 46 if (!ctx) 47 return; 48 49 if (!m || !is_aligned(m)) { 50 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 51 return; 52 } 53 54 mat = vg_state_matrix(&ctx->state.vg); 55 matrix_init(mat, m); 56 if (!matrix_is_affine(mat)) { 57 if (ctx->state.vg.matrix_mode != VG_MATRIX_IMAGE_USER_TO_SURFACE) { 58 matrix_make_affine(mat); 59 } 60 } 61} 62 63void vegaGetMatrix(VGfloat * m) 64{ 65 struct vg_context *ctx = vg_current_context(); 66 struct matrix *mat; 67 68 if (!ctx) 69 return; 70 71 if (!m || !is_aligned(m)) { 72 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 73 return; 74 } 75 76 mat = vg_state_matrix(&ctx->state.vg); 77 memcpy(m, mat->m, sizeof(VGfloat)*9); 78} 79 80void vegaMultMatrix(const VGfloat * m) 81{ 82 struct vg_context *ctx = vg_current_context(); 83 struct matrix *dst, src; 84 85 if (!ctx) 86 return; 87 88 if (!m || !is_aligned(m)) { 89 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 90 return; 91 } 92 matrix_init(&src, m); 93 dst = vg_state_matrix(&ctx->state.vg); 94 if (!matrix_is_affine(&src)) { 95 if (ctx->state.vg.matrix_mode != VG_MATRIX_IMAGE_USER_TO_SURFACE) { 96 matrix_make_affine(&src); 97 } 98 } 99 matrix_mult(dst, &src); 100 101} 102 103void vegaTranslate(VGfloat tx, VGfloat ty) 104{ 105 struct vg_context *ctx = vg_current_context(); 106 struct matrix *dst = vg_state_matrix(&ctx->state.vg); 107 matrix_translate(dst, tx, ty); 108} 109 110void vegaScale(VGfloat sx, VGfloat sy) 111{ 112 struct vg_context *ctx = vg_current_context(); 113 struct matrix *dst = vg_state_matrix(&ctx->state.vg); 114 matrix_scale(dst, sx, sy); 115} 116 117void vegaShear(VGfloat shx, VGfloat shy) 118{ 119 struct vg_context *ctx = vg_current_context(); 120 struct matrix *dst = vg_state_matrix(&ctx->state.vg); 121 matrix_shear(dst, shx, shy); 122} 123 124void vegaRotate(VGfloat angle) 125{ 126 struct vg_context *ctx = vg_current_context(); 127 struct matrix *dst = vg_state_matrix(&ctx->state.vg); 128 matrix_rotate(dst, angle); 129} 130