Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / state_trackers / vega / api_transform.c
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
33 void vgLoadIdentity(void)
34 {
35 struct vg_context *ctx = vg_current_context();
36 struct matrix *mat = vg_state_matrix(&ctx->state.vg);
37 matrix_load_identity(mat);
38 }
39
40 void vgLoadMatrix(const VGfloat * m)
41 {
42 struct vg_context *ctx = vg_current_context();
43 struct matrix *mat;
44
45 if (!ctx)
46 return;
47
48 if (!m || !is_aligned(m)) {
49 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
50 return;
51 }
52
53 mat = vg_state_matrix(&ctx->state.vg);
54 matrix_init(mat, m);
55 if (!matrix_is_affine(mat)) {
56 if (ctx->state.vg.matrix_mode != VG_MATRIX_IMAGE_USER_TO_SURFACE) {
57 matrix_make_affine(mat);
58 }
59 }
60 }
61
62 void vgGetMatrix(VGfloat * m)
63 {
64 struct vg_context *ctx = vg_current_context();
65 struct matrix *mat;
66
67 if (!ctx)
68 return;
69
70 if (!m || !is_aligned(m)) {
71 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
72 return;
73 }
74
75 mat = vg_state_matrix(&ctx->state.vg);
76 memcpy(m, mat->m, sizeof(VGfloat)*9);
77 }
78
79 void vgMultMatrix(const VGfloat * m)
80 {
81 struct vg_context *ctx = vg_current_context();
82 struct matrix *dst, src;
83
84 if (!ctx)
85 return;
86
87 if (!m || !is_aligned(m)) {
88 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
89 return;
90 }
91 matrix_init(&src, m);
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);
96 }
97 }
98 matrix_mult(dst, &src);
99
100 }
101
102 void vgTranslate(VGfloat tx, VGfloat ty)
103 {
104 struct vg_context *ctx = vg_current_context();
105 struct matrix *dst = vg_state_matrix(&ctx->state.vg);
106 matrix_translate(dst, tx, ty);
107 }
108
109 void vgScale(VGfloat sx, VGfloat sy)
110 {
111 struct vg_context *ctx = vg_current_context();
112 struct matrix *dst = vg_state_matrix(&ctx->state.vg);
113 matrix_scale(dst, sx, sy);
114 }
115
116 void vgShear(VGfloat shx, VGfloat shy)
117 {
118 struct vg_context *ctx = vg_current_context();
119 struct matrix *dst = vg_state_matrix(&ctx->state.vg);
120 matrix_shear(dst, shx, shy);
121 }
122
123 void vgRotate(VGfloat angle)
124 {
125 struct vg_context *ctx = vg_current_context();
126 struct matrix *dst = vg_state_matrix(&ctx->state.vg);
127 matrix_rotate(dst, angle);
128 }