• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can
5  * be found in the LICENSE file.
6  *
7  */
8 
9 //
10 //
11 //
12 
13 #pragma once
14 
15 //
16 //
17 //
18 
19 #include <stdint.h>
20 
21 //
22 //
23 //
24 
25 struct ts_transform_stack;
26 
27 //
28 //
29 //
30 
31 #if 1
32 typedef float  ts_transform_float_t;
33 #define TS_TRANSFORM_FLOAT_SUFFIX f
34 #else
35 typedef double ts_transform_float_t;
36 #define TS_TRANSFORM_FLOAT_SUFFIX
37 #endif
38 
39 //
40 //
41 //
42 
43 typedef uint64_t ts_transform_weakref_t;
44 
45 #define TS_TRANSFORM_WEAKREF_INVALID UINT64_MAX;
46 
47 //
48 //
49 //
50 
51 typedef enum ts_transform_type
52 {
53   TS_TRANSFORM_TYPE_INVALID,
54   TS_TRANSFORM_TYPE_AFFINE,
55   TS_TRANSFORM_TYPE_PROJECTIVE
56 } ts_transform_type_e;
57 
58 //
59 //
60 //
61 
62 struct ts_transform_stack *
63 ts_transform_stack_create(const uint32_t size);
64 
65 void
66 ts_transform_stack_release(struct ts_transform_stack * const ts);
67 
68 //
69 //
70 //
71 
72 uint32_t
73 ts_transform_stack_save(struct ts_transform_stack * const ts);
74 
75 void
76 ts_transform_stack_restore(struct ts_transform_stack * const ts, uint32_t const restore);
77 
78 //
79 //
80 //
81 
82 ts_transform_float_t *
83 ts_transform_stack_top_transform(struct ts_transform_stack * const ts);
84 
85 ts_transform_weakref_t *
86 ts_transform_stack_top_weakref(struct ts_transform_stack * const ts);
87 
88 //
89 //
90 //
91 
92 void
93 ts_transform_stack_dup(struct ts_transform_stack * const ts);
94 
95 void
96 ts_transform_stack_drop(struct ts_transform_stack * const ts);
97 
98 //
99 //
100 //
101 
102 void
103 ts_transform_stack_transform_xy(struct ts_transform_stack * const ts,
104                                 ts_transform_float_t        const x,
105                                 ts_transform_float_t        const y,
106                                 ts_transform_float_t      * const xp,
107                                 ts_transform_float_t      * const yp);
108 
109 //
110 //
111 //
112 
113 void
114 ts_transform_stack_push_matrix(struct ts_transform_stack * const ts,
115                                ts_transform_float_t        const sx,
116                                ts_transform_float_t        const shx,
117                                ts_transform_float_t        const tx,
118                                ts_transform_float_t        const shy,
119                                ts_transform_float_t        const sy,
120                                ts_transform_float_t        const ty,
121                                ts_transform_float_t        const w0,
122                                ts_transform_float_t        const w1,
123                                ts_transform_float_t        const w2);
124 
125 void
126 ts_transform_stack_push_identity(struct ts_transform_stack * const ts);
127 
128 void
129 ts_transform_stack_push_affine(struct ts_transform_stack * const ts,
130                                ts_transform_float_t        const sx,
131                                ts_transform_float_t        const shx,
132                                ts_transform_float_t        const tx,
133                                ts_transform_float_t        const shy,
134                                ts_transform_float_t        const sy,
135                                ts_transform_float_t        const ty);
136 
137 void
138 ts_transform_stack_push_translate(struct ts_transform_stack * const ts,
139                                   ts_transform_float_t        const tx,
140                                   ts_transform_float_t        const ty);
141 
142 void
143 ts_transform_stack_push_scale(struct ts_transform_stack * const ts,
144                               ts_transform_float_t        const sx,
145                               ts_transform_float_t        const sy);
146 
147 void
148 ts_transform_stack_push_shear(struct ts_transform_stack * const ts,
149                               ts_transform_float_t        const shx,
150                               ts_transform_float_t        const shy);
151 
152 
153 void
154 ts_transform_stack_push_skew_x(struct ts_transform_stack * const ts,
155                                ts_transform_float_t        const theta);
156 
157 void
158 ts_transform_stack_push_skew_y(struct ts_transform_stack * const ts,
159                                ts_transform_float_t        const theta);
160 
161 void
162 ts_transform_stack_push_rotate(struct ts_transform_stack * const ts,
163                                ts_transform_float_t        const theta);
164 
165 void
166 ts_transform_stack_push_rotate_xy2(struct ts_transform_stack * const ts,
167                                    ts_transform_float_t        const theta,
168                                    ts_transform_float_t        const cx,
169                                    ts_transform_float_t        const cy,
170                                    ts_transform_float_t        const tx,
171                                    ts_transform_float_t        const ty);
172 
173 void
174 ts_transform_stack_push_rotate_xy(struct ts_transform_stack * const ts,
175                                   ts_transform_float_t        const theta,
176                                   ts_transform_float_t        const cx,
177                                   ts_transform_float_t        const cy);
178 
179 void
180 ts_transform_stack_push_rotate_scale_xy(struct ts_transform_stack * const ts,
181                                         ts_transform_float_t        const theta,
182                                         ts_transform_float_t        const sx,
183                                         ts_transform_float_t        const sy,
184                                         ts_transform_float_t        const cx,
185                                         ts_transform_float_t        const cy);
186 //
187 // Quadrilateral coordinates are ts_transform_float_t2 structs:
188 //
189 //   float2[4] = { xy0, xy1, xy2, xy3 }
190 //
191 // -or-
192 //
193 //   float[8]  = { x0, y0, x1, y1, x2, y2, x3, y3 };
194 //
195 
196 ts_transform_type_e
197 ts_transform_stack_push_quad_to_unit(struct ts_transform_stack * const ts,
198                                      ts_transform_float_t        const quad[8]);
199 
200 ts_transform_type_e
201 ts_transform_stack_push_unit_to_quad(struct ts_transform_stack * const ts,
202                                      ts_transform_float_t        const quad[8]);
203 
204 ts_transform_type_e
205 ts_transform_stack_push_quad_to_quad(struct ts_transform_stack * const ts,
206                                      ts_transform_float_t        const quad_src[8],
207                                      ts_transform_float_t        const quad_dst[8]);
208 
209 ts_transform_type_e
210 ts_transform_stack_push_rect_to_quad(struct ts_transform_stack * const ts,
211                                      ts_transform_float_t        const x0,
212                                      ts_transform_float_t        const y0,
213                                      ts_transform_float_t        const x1,
214                                      ts_transform_float_t        const y1,
215                                      ts_transform_float_t        const quad_dst[8]);
216 
217 //
218 // The second matrix on the stack (TOS[-1]) is post-multiplied by the
219 // top matrix on the stack (TOS[0]).
220 //
221 // The result replaces TOS[0] and TOS[-1] is unmodified.
222 //
223 // The stack effect of concat is:
224 //
225 //   | B |    | A*B |
226 //   | A |    |  A  |
227 //   | . | => |  .  |
228 //   | . |    |  .  |
229 //   | . |    |  .  |
230 //
231 
232 void
233 ts_transform_stack_concat(struct ts_transform_stack * const ts);
234 
235 //
236 // The second matrix on the stack (TOS[-1]) is post-multiplied by the
237 // top matrix on the stack (TOS[0]).
238 //
239 // The result replaces both matrices.
240 //
241 // The stack effect of multiply is:
242 //
243 //   | B |    | A*B |
244 //   | A |    |  .  |
245 //   | . | => |  .  |
246 //   | . |    |  .  |
247 //   | . |    |  .  |
248 //
249 
250 void
251 ts_transform_stack_multiply(struct ts_transform_stack * const ts);
252 
253 //
254 //
255 //
256