1 /**************************************************************************
3 * Copyright 2009 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
25 **************************************************************************/
27 #include "VG/openvg.h"
29 #include "vg_context.h"
33 void vgLoadIdentity(void)
35 struct vg_context
*ctx
= vg_current_context();
36 struct matrix
*mat
= vg_state_matrix(&ctx
->state
.vg
);
37 matrix_load_identity(mat
);
40 void vgLoadMatrix(const VGfloat
* m
)
42 struct vg_context
*ctx
= vg_current_context();
48 if (!m
|| !is_aligned(m
)) {
49 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
53 mat
= vg_state_matrix(&ctx
->state
.vg
);
55 if (!matrix_is_affine(mat
)) {
56 if (ctx
->state
.vg
.matrix_mode
!= VG_MATRIX_IMAGE_USER_TO_SURFACE
) {
57 matrix_make_affine(mat
);
62 void vgGetMatrix(VGfloat
* m
)
64 struct vg_context
*ctx
= vg_current_context();
70 if (!m
|| !is_aligned(m
)) {
71 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
75 mat
= vg_state_matrix(&ctx
->state
.vg
);
76 memcpy(m
, mat
->m
, sizeof(VGfloat
)*9);
79 void vgMultMatrix(const VGfloat
* m
)
81 struct vg_context
*ctx
= vg_current_context();
82 struct matrix
*dst
, src
;
87 if (!m
|| !is_aligned(m
)) {
88 vg_set_error(ctx
, VG_ILLEGAL_ARGUMENT_ERROR
);
92 dst
= vg_state_matrix(&ctx
->state
.vg
);
93 if (!matrix_is_affine(&src
)) {
94 if (ctx
->state
.vg
.matrix_mode
!= VG_MATRIX_IMAGE_USER_TO_SURFACE
) {
95 matrix_make_affine(&src
);
98 matrix_mult(dst
, &src
);
102 void vgTranslate(VGfloat tx
, VGfloat ty
)
104 struct vg_context
*ctx
= vg_current_context();
105 struct matrix
*dst
= vg_state_matrix(&ctx
->state
.vg
);
106 matrix_translate(dst
, tx
, ty
);
109 void vgScale(VGfloat sx
, VGfloat sy
)
111 struct vg_context
*ctx
= vg_current_context();
112 struct matrix
*dst
= vg_state_matrix(&ctx
->state
.vg
);
113 matrix_scale(dst
, sx
, sy
);
116 void vgShear(VGfloat shx
, VGfloat shy
)
118 struct vg_context
*ctx
= vg_current_context();
119 struct matrix
*dst
= vg_state_matrix(&ctx
->state
.vg
);
120 matrix_shear(dst
, shx
, shy
);
123 void vgRotate(VGfloat angle
)
125 struct vg_context
*ctx
= vg_current_context();
126 struct matrix
*dst
= vg_state_matrix(&ctx
->state
.vg
);
127 matrix_rotate(dst
, angle
);