Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4251 | Serge | 1 | /* |
2 | * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. All Rights Reserved. |
||
3 | * Copyright (c) 2005 Jesse Barnes |
||
4 | * Copyright © 2010 Intel Corporation |
||
5 | * |
||
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
7 | * copy of this software and associated documentation files (the "Software"), |
||
8 | * to deal in the Software without restriction, including without limitation |
||
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
10 | * and/or sell copies of the Software, and to permit persons to whom the |
||
11 | * Software is furnished to do so, subject to the following conditions: |
||
12 | * |
||
13 | * The above copyright notice and this permission notice (including the next |
||
14 | * paragraph) shall be included in all copies or substantial portions of the |
||
15 | * Software. |
||
16 | * |
||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||
23 | * SOFTWARE. |
||
24 | * |
||
25 | * Authors: |
||
26 | * Jesse Barns |
||
27 | * Chris Wilson |
||
28 | */ |
||
29 | |||
30 | #ifdef HAVE_CONFIG_H |
||
31 | #include "config.h" |
||
32 | #endif |
||
33 | |||
34 | #include "sna.h" |
||
35 | |||
36 | #define pixman_fixed_e ((pixman_fixed_t) 1) |
||
37 | #define pixman_fixed_1 (pixman_int_to_fixed(1)) |
||
38 | #define pixman_fixed_1_minus_e (pixman_fixed_1 - pixman_fixed_e) |
||
39 | #define pixman_fixed_to_int(f) ((int) ((f) >> 16)) |
||
40 | #define pixman_int_to_fixed(i) ((pixman_fixed_t) ((i) << 16)) |
||
41 | #define pixman_fixed_fraction(f) ((f) & pixman_fixed_1_minus_e) |
||
42 | |||
43 | #define IntToxFixed(i) pixman_int_to_fixed(i) |
||
44 | |||
45 | /** |
||
46 | * Returns whether the provided transform is affine. |
||
47 | * |
||
48 | * transform may be null. |
||
49 | */ |
||
50 | bool sna_transform_is_affine(const PictTransform *t) |
||
51 | { |
||
52 | if (t == NULL) |
||
53 | return true; |
||
54 | |||
55 | return t->matrix[2][0] == 0 && t->matrix[2][1] == 0; |
||
56 | } |
||
57 | |||
58 | bool |
||
59 | sna_transform_is_translation(const PictTransform *t, |
||
60 | pixman_fixed_t *tx, |
||
61 | pixman_fixed_t *ty) |
||
62 | { |
||
63 | if (t == NULL) { |
||
64 | *tx = *ty = 0; |
||
65 | return true; |
||
66 | } |
||
67 | |||
68 | if (t->matrix[0][0] != IntToxFixed(1) || |
||
69 | t->matrix[0][1] != 0 || |
||
70 | t->matrix[1][0] != 0 || |
||
71 | t->matrix[1][1] != IntToxFixed(1) || |
||
72 | t->matrix[2][0] != 0 || |
||
73 | t->matrix[2][1] != 0 || |
||
74 | t->matrix[2][2] != IntToxFixed(1)) |
||
75 | return false; |
||
76 | |||
77 | *tx = t->matrix[0][2]; |
||
78 | *ty = t->matrix[1][2]; |
||
79 | return true; |
||
80 | } |
||
81 | |||
82 | bool |
||
83 | sna_transform_is_integer_translation(const PictTransform *t, int16_t *tx, int16_t *ty) |
||
84 | { |
||
85 | if (t == NULL) { |
||
86 | *tx = *ty = 0; |
||
87 | return true; |
||
88 | } |
||
89 | |||
90 | if (t->matrix[0][0] != IntToxFixed(1) || |
||
91 | t->matrix[0][1] != 0 || |
||
92 | t->matrix[1][0] != 0 || |
||
93 | t->matrix[1][1] != IntToxFixed(1) || |
||
94 | t->matrix[2][0] != 0 || |
||
95 | t->matrix[2][1] != 0 || |
||
96 | t->matrix[2][2] != IntToxFixed(1)) |
||
97 | return false; |
||
98 | |||
99 | if (pixman_fixed_fraction(t->matrix[0][2]) || |
||
100 | pixman_fixed_fraction(t->matrix[1][2])) |
||
101 | return false; |
||
102 | |||
103 | *tx = pixman_fixed_to_int(t->matrix[0][2]); |
||
104 | *ty = pixman_fixed_to_int(t->matrix[1][2]); |
||
105 | return true; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Returns the floating-point coordinates transformed by the given transform. |
||
110 | */ |
||
111 | void |
||
112 | sna_get_transformed_coordinates(int x, int y, |
||
113 | const PictTransform *transform, |
||
114 | float *x_out, float *y_out) |
||
115 | { |
||
116 | if (transform == NULL) { |
||
117 | *x_out = x; |
||
118 | *y_out = y; |
||
119 | } else |
||
120 | _sna_get_transformed_coordinates(x, y, transform, x_out, y_out); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Returns the un-normalized floating-point coordinates transformed by the given transform. |
||
125 | */ |
||
126 | void |
||
127 | sna_get_transformed_coordinates_3d(int x, int y, |
||
128 | const PictTransform *transform, |
||
129 | float *x_out, float *y_out, float *w_out) |
||
130 | { |
||
131 | if (transform == NULL) { |
||
132 | *x_out = x; |
||
133 | *y_out = y; |
||
134 | *w_out = 1; |
||
135 | } else { |
||
136 | int64_t result[3]; |
||
137 | |||
138 | if (_sna_transform_point(transform, x, y, result)) { |
||
139 | *x_out = result[0] / 65536.; |
||
140 | *y_out = result[1] / 65536.; |
||
141 | *w_out = result[2] / 65536.; |
||
142 | } else { |
||
143 | *x_out = *y_out = 0; |
||
144 | *w_out = 1.; |
||
145 | } |
||
146 | } |
||
147 | }><> |