glsl2: Add and use new variable mode ir_var_temporary
[mesa/nouveau-pmpeg.git] / src / gallium / state_trackers / vega / api_transform.c
blob0a40fc69b954133c77216292c587142472717e91
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
15 * of the Software.
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"
31 #include "matrix.h"
32 #include "api.h"
34 void vegaLoadIdentity(void)
36 struct vg_context *ctx = vg_current_context();
37 struct matrix *mat = vg_state_matrix(&ctx->state.vg);
38 matrix_load_identity(mat);
41 void vegaLoadMatrix(const VGfloat * m)
43 struct vg_context *ctx = vg_current_context();
44 struct matrix *mat;
46 if (!ctx)
47 return;
49 if (!m || !is_aligned(m)) {
50 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
51 return;
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);
63 void vegaGetMatrix(VGfloat * m)
65 struct vg_context *ctx = vg_current_context();
66 struct matrix *mat;
68 if (!ctx)
69 return;
71 if (!m || !is_aligned(m)) {
72 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
73 return;
76 mat = vg_state_matrix(&ctx->state.vg);
77 memcpy(m, mat->m, sizeof(VGfloat)*9);
80 void vegaMultMatrix(const VGfloat * m)
82 struct vg_context *ctx = vg_current_context();
83 struct matrix *dst, src;
85 if (!ctx)
86 return;
88 if (!m || !is_aligned(m)) {
89 vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
90 return;
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);
99 matrix_mult(dst, &src);
103 void vegaTranslate(VGfloat tx, VGfloat ty)
105 struct vg_context *ctx = vg_current_context();
106 struct matrix *dst = vg_state_matrix(&ctx->state.vg);
107 matrix_translate(dst, tx, ty);
110 void vegaScale(VGfloat sx, VGfloat sy)
112 struct vg_context *ctx = vg_current_context();
113 struct matrix *dst = vg_state_matrix(&ctx->state.vg);
114 matrix_scale(dst, sx, sy);
117 void vegaShear(VGfloat shx, VGfloat shy)
119 struct vg_context *ctx = vg_current_context();
120 struct matrix *dst = vg_state_matrix(&ctx->state.vg);
121 matrix_shear(dst, shx, shy);
124 void vegaRotate(VGfloat angle)
126 struct vg_context *ctx = vg_current_context();
127 struct matrix *dst = vg_state_matrix(&ctx->state.vg);
128 matrix_rotate(dst, angle);