Rev 6084 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6084 | Rev 6937 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2011-2013 Intel Corporation |
2 | * Copyright (C) 2011-2013 Intel Corporation |
3 | * |
3 | * |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
5 | * copy of this software and associated documentation files (the "Software"), |
5 | * copy of this software and associated documentation files (the "Software"), |
6 | * to deal in the Software without restriction, including without limitation |
6 | * to deal in the Software without restriction, including without limitation |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
8 | * and/or sell copies of the Software, and to permit persons to whom the |
8 | * and/or sell copies of the Software, and to permit persons to whom the |
9 | * Software is furnished to do so, subject to the following conditions: |
9 | * Software is furnished to do so, subject to the following conditions: |
10 | * |
10 | * |
11 | * The above copyright notice and this permission notice (including the next |
11 | * The above copyright notice and this permission notice (including the next |
12 | * paragraph) shall be included in all copies or substantial portions of the |
12 | * paragraph) shall be included in all copies or substantial portions of the |
13 | * Software. |
13 | * Software. |
14 | * |
14 | * |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21 | * SOFTWARE. |
21 | * SOFTWARE. |
22 | */ |
22 | */ |
23 | 23 | ||
24 | #include |
24 | #include |
25 | #include |
25 | #include |
26 | #include |
26 | #include |
27 | #include |
27 | #include |
28 | #include |
28 | #include |
29 | 29 | ||
30 | /** |
30 | /** |
31 | * drm_rect_intersect - intersect two rectangles |
31 | * drm_rect_intersect - intersect two rectangles |
32 | * @r1: first rectangle |
32 | * @r1: first rectangle |
33 | * @r2: second rectangle |
33 | * @r2: second rectangle |
34 | * |
34 | * |
35 | * Calculate the intersection of rectangles @r1 and @r2. |
35 | * Calculate the intersection of rectangles @r1 and @r2. |
36 | * @r1 will be overwritten with the intersection. |
36 | * @r1 will be overwritten with the intersection. |
37 | * |
37 | * |
38 | * RETURNS: |
38 | * RETURNS: |
39 | * %true if rectangle @r1 is still visible after the operation, |
39 | * %true if rectangle @r1 is still visible after the operation, |
40 | * %false otherwise. |
40 | * %false otherwise. |
41 | */ |
41 | */ |
42 | bool drm_rect_intersect(struct drm_rect *r1, const struct drm_rect *r2) |
42 | bool drm_rect_intersect(struct drm_rect *r1, const struct drm_rect *r2) |
43 | { |
43 | { |
44 | r1->x1 = max(r1->x1, r2->x1); |
44 | r1->x1 = max(r1->x1, r2->x1); |
45 | r1->y1 = max(r1->y1, r2->y1); |
45 | r1->y1 = max(r1->y1, r2->y1); |
46 | r1->x2 = min(r1->x2, r2->x2); |
46 | r1->x2 = min(r1->x2, r2->x2); |
47 | r1->y2 = min(r1->y2, r2->y2); |
47 | r1->y2 = min(r1->y2, r2->y2); |
48 | 48 | ||
49 | return drm_rect_visible(r1); |
49 | return drm_rect_visible(r1); |
50 | } |
50 | } |
51 | EXPORT_SYMBOL(drm_rect_intersect); |
51 | EXPORT_SYMBOL(drm_rect_intersect); |
52 | 52 | ||
53 | /** |
53 | /** |
54 | * drm_rect_clip_scaled - perform a scaled clip operation |
54 | * drm_rect_clip_scaled - perform a scaled clip operation |
55 | * @src: source window rectangle |
55 | * @src: source window rectangle |
56 | * @dst: destination window rectangle |
56 | * @dst: destination window rectangle |
57 | * @clip: clip rectangle |
57 | * @clip: clip rectangle |
58 | * @hscale: horizontal scaling factor |
58 | * @hscale: horizontal scaling factor |
59 | * @vscale: vertical scaling factor |
59 | * @vscale: vertical scaling factor |
60 | * |
60 | * |
61 | * Clip rectangle @dst by rectangle @clip. Clip rectangle @src by the |
61 | * Clip rectangle @dst by rectangle @clip. Clip rectangle @src by the |
62 | * same amounts multiplied by @hscale and @vscale. |
62 | * same amounts multiplied by @hscale and @vscale. |
63 | * |
63 | * |
64 | * RETURNS: |
64 | * RETURNS: |
65 | * %true if rectangle @dst is still visible after being clipped, |
65 | * %true if rectangle @dst is still visible after being clipped, |
66 | * %false otherwise |
66 | * %false otherwise |
67 | */ |
67 | */ |
68 | bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst, |
68 | bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst, |
69 | const struct drm_rect *clip, |
69 | const struct drm_rect *clip, |
70 | int hscale, int vscale) |
70 | int hscale, int vscale) |
71 | { |
71 | { |
72 | int diff; |
72 | int diff; |
73 | 73 | ||
74 | diff = clip->x1 - dst->x1; |
74 | diff = clip->x1 - dst->x1; |
75 | if (diff > 0) { |
75 | if (diff > 0) { |
76 | int64_t tmp = src->x1 + (int64_t) diff * hscale; |
76 | int64_t tmp = src->x1 + (int64_t) diff * hscale; |
77 | src->x1 = clamp_t(int64_t, tmp, INT_MIN, INT_MAX); |
77 | src->x1 = clamp_t(int64_t, tmp, INT_MIN, INT_MAX); |
78 | } |
78 | } |
79 | diff = clip->y1 - dst->y1; |
79 | diff = clip->y1 - dst->y1; |
80 | if (diff > 0) { |
80 | if (diff > 0) { |
81 | int64_t tmp = src->y1 + (int64_t) diff * vscale; |
81 | int64_t tmp = src->y1 + (int64_t) diff * vscale; |
82 | src->y1 = clamp_t(int64_t, tmp, INT_MIN, INT_MAX); |
82 | src->y1 = clamp_t(int64_t, tmp, INT_MIN, INT_MAX); |
83 | } |
83 | } |
84 | diff = dst->x2 - clip->x2; |
84 | diff = dst->x2 - clip->x2; |
85 | if (diff > 0) { |
85 | if (diff > 0) { |
86 | int64_t tmp = src->x2 - (int64_t) diff * hscale; |
86 | int64_t tmp = src->x2 - (int64_t) diff * hscale; |
87 | src->x2 = clamp_t(int64_t, tmp, INT_MIN, INT_MAX); |
87 | src->x2 = clamp_t(int64_t, tmp, INT_MIN, INT_MAX); |
88 | } |
88 | } |
89 | diff = dst->y2 - clip->y2; |
89 | diff = dst->y2 - clip->y2; |
90 | if (diff > 0) { |
90 | if (diff > 0) { |
91 | int64_t tmp = src->y2 - (int64_t) diff * vscale; |
91 | int64_t tmp = src->y2 - (int64_t) diff * vscale; |
92 | src->y2 = clamp_t(int64_t, tmp, INT_MIN, INT_MAX); |
92 | src->y2 = clamp_t(int64_t, tmp, INT_MIN, INT_MAX); |
93 | } |
93 | } |
94 | 94 | ||
95 | return drm_rect_intersect(dst, clip); |
95 | return drm_rect_intersect(dst, clip); |
96 | } |
96 | } |
97 | EXPORT_SYMBOL(drm_rect_clip_scaled); |
97 | EXPORT_SYMBOL(drm_rect_clip_scaled); |
98 | 98 | ||
99 | static int drm_calc_scale(int src, int dst) |
99 | static int drm_calc_scale(int src, int dst) |
100 | { |
100 | { |
101 | int scale = 0; |
101 | int scale = 0; |
102 | 102 | ||
103 | if (src < 0 || dst < 0) |
103 | if (src < 0 || dst < 0) |
104 | return -EINVAL; |
104 | return -EINVAL; |
105 | 105 | ||
106 | if (dst == 0) |
106 | if (dst == 0) |
107 | return 0; |
107 | return 0; |
108 | 108 | ||
109 | scale = src / dst; |
109 | scale = src / dst; |
110 | 110 | ||
111 | return scale; |
111 | return scale; |
112 | } |
112 | } |
113 | 113 | ||
114 | /** |
114 | /** |
115 | * drm_rect_calc_hscale - calculate the horizontal scaling factor |
115 | * drm_rect_calc_hscale - calculate the horizontal scaling factor |
116 | * @src: source window rectangle |
116 | * @src: source window rectangle |
117 | * @dst: destination window rectangle |
117 | * @dst: destination window rectangle |
118 | * @min_hscale: minimum allowed horizontal scaling factor |
118 | * @min_hscale: minimum allowed horizontal scaling factor |
119 | * @max_hscale: maximum allowed horizontal scaling factor |
119 | * @max_hscale: maximum allowed horizontal scaling factor |
120 | * |
120 | * |
121 | * Calculate the horizontal scaling factor as |
121 | * Calculate the horizontal scaling factor as |
122 | * (@src width) / (@dst width). |
122 | * (@src width) / (@dst width). |
123 | * |
123 | * |
124 | * RETURNS: |
124 | * RETURNS: |
125 | * The horizontal scaling factor, or errno of out of limits. |
125 | * The horizontal scaling factor, or errno of out of limits. |
126 | */ |
126 | */ |
127 | int drm_rect_calc_hscale(const struct drm_rect *src, |
127 | int drm_rect_calc_hscale(const struct drm_rect *src, |
128 | const struct drm_rect *dst, |
128 | const struct drm_rect *dst, |
129 | int min_hscale, int max_hscale) |
129 | int min_hscale, int max_hscale) |
130 | { |
130 | { |
131 | int src_w = drm_rect_width(src); |
131 | int src_w = drm_rect_width(src); |
132 | int dst_w = drm_rect_width(dst); |
132 | int dst_w = drm_rect_width(dst); |
133 | int hscale = drm_calc_scale(src_w, dst_w); |
133 | int hscale = drm_calc_scale(src_w, dst_w); |
134 | 134 | ||
135 | if (hscale < 0 || dst_w == 0) |
135 | if (hscale < 0 || dst_w == 0) |
136 | return hscale; |
136 | return hscale; |
137 | 137 | ||
138 | if (hscale < min_hscale || hscale > max_hscale) |
138 | if (hscale < min_hscale || hscale > max_hscale) |
139 | return -ERANGE; |
139 | return -ERANGE; |
140 | 140 | ||
141 | return hscale; |
141 | return hscale; |
142 | } |
142 | } |
143 | EXPORT_SYMBOL(drm_rect_calc_hscale); |
143 | EXPORT_SYMBOL(drm_rect_calc_hscale); |
144 | 144 | ||
145 | /** |
145 | /** |
146 | * drm_rect_calc_vscale - calculate the vertical scaling factor |
146 | * drm_rect_calc_vscale - calculate the vertical scaling factor |
147 | * @src: source window rectangle |
147 | * @src: source window rectangle |
148 | * @dst: destination window rectangle |
148 | * @dst: destination window rectangle |
149 | * @min_vscale: minimum allowed vertical scaling factor |
149 | * @min_vscale: minimum allowed vertical scaling factor |
150 | * @max_vscale: maximum allowed vertical scaling factor |
150 | * @max_vscale: maximum allowed vertical scaling factor |
151 | * |
151 | * |
152 | * Calculate the vertical scaling factor as |
152 | * Calculate the vertical scaling factor as |
153 | * (@src height) / (@dst height). |
153 | * (@src height) / (@dst height). |
154 | * |
154 | * |
155 | * RETURNS: |
155 | * RETURNS: |
156 | * The vertical scaling factor, or errno of out of limits. |
156 | * The vertical scaling factor, or errno of out of limits. |
157 | */ |
157 | */ |
158 | int drm_rect_calc_vscale(const struct drm_rect *src, |
158 | int drm_rect_calc_vscale(const struct drm_rect *src, |
159 | const struct drm_rect *dst, |
159 | const struct drm_rect *dst, |
160 | int min_vscale, int max_vscale) |
160 | int min_vscale, int max_vscale) |
161 | { |
161 | { |
162 | int src_h = drm_rect_height(src); |
162 | int src_h = drm_rect_height(src); |
163 | int dst_h = drm_rect_height(dst); |
163 | int dst_h = drm_rect_height(dst); |
164 | int vscale = drm_calc_scale(src_h, dst_h); |
164 | int vscale = drm_calc_scale(src_h, dst_h); |
165 | 165 | ||
166 | if (vscale < 0 || dst_h == 0) |
166 | if (vscale < 0 || dst_h == 0) |
167 | return vscale; |
167 | return vscale; |
168 | 168 | ||
169 | if (vscale < min_vscale || vscale > max_vscale) |
169 | if (vscale < min_vscale || vscale > max_vscale) |
170 | return -ERANGE; |
170 | return -ERANGE; |
171 | 171 | ||
172 | return vscale; |
172 | return vscale; |
173 | } |
173 | } |
174 | EXPORT_SYMBOL(drm_rect_calc_vscale); |
174 | EXPORT_SYMBOL(drm_rect_calc_vscale); |
175 | 175 | ||
176 | /** |
176 | /** |
177 | * drm_calc_hscale_relaxed - calculate the horizontal scaling factor |
177 | * drm_calc_hscale_relaxed - calculate the horizontal scaling factor |
178 | * @src: source window rectangle |
178 | * @src: source window rectangle |
179 | * @dst: destination window rectangle |
179 | * @dst: destination window rectangle |
180 | * @min_hscale: minimum allowed horizontal scaling factor |
180 | * @min_hscale: minimum allowed horizontal scaling factor |
181 | * @max_hscale: maximum allowed horizontal scaling factor |
181 | * @max_hscale: maximum allowed horizontal scaling factor |
182 | * |
182 | * |
183 | * Calculate the horizontal scaling factor as |
183 | * Calculate the horizontal scaling factor as |
184 | * (@src width) / (@dst width). |
184 | * (@src width) / (@dst width). |
185 | * |
185 | * |
186 | * If the calculated scaling factor is below @min_vscale, |
186 | * If the calculated scaling factor is below @min_vscale, |
187 | * decrease the height of rectangle @dst to compensate. |
187 | * decrease the height of rectangle @dst to compensate. |
188 | * |
188 | * |
189 | * If the calculated scaling factor is above @max_vscale, |
189 | * If the calculated scaling factor is above @max_vscale, |
190 | * decrease the height of rectangle @src to compensate. |
190 | * decrease the height of rectangle @src to compensate. |
191 | * |
191 | * |
192 | * RETURNS: |
192 | * RETURNS: |
193 | * The horizontal scaling factor. |
193 | * The horizontal scaling factor. |
194 | */ |
194 | */ |
195 | int drm_rect_calc_hscale_relaxed(struct drm_rect *src, |
195 | int drm_rect_calc_hscale_relaxed(struct drm_rect *src, |
196 | struct drm_rect *dst, |
196 | struct drm_rect *dst, |
197 | int min_hscale, int max_hscale) |
197 | int min_hscale, int max_hscale) |
198 | { |
198 | { |
199 | int src_w = drm_rect_width(src); |
199 | int src_w = drm_rect_width(src); |
200 | int dst_w = drm_rect_width(dst); |
200 | int dst_w = drm_rect_width(dst); |
201 | int hscale = drm_calc_scale(src_w, dst_w); |
201 | int hscale = drm_calc_scale(src_w, dst_w); |
202 | 202 | ||
203 | if (hscale < 0 || dst_w == 0) |
203 | if (hscale < 0 || dst_w == 0) |
204 | return hscale; |
204 | return hscale; |
205 | 205 | ||
206 | if (hscale < min_hscale) { |
206 | if (hscale < min_hscale) { |
207 | int max_dst_w = src_w / min_hscale; |
207 | int max_dst_w = src_w / min_hscale; |
208 | 208 | ||
209 | drm_rect_adjust_size(dst, max_dst_w - dst_w, 0); |
209 | drm_rect_adjust_size(dst, max_dst_w - dst_w, 0); |
210 | 210 | ||
211 | return min_hscale; |
211 | return min_hscale; |
212 | } |
212 | } |
213 | 213 | ||
214 | if (hscale > max_hscale) { |
214 | if (hscale > max_hscale) { |
215 | int max_src_w = dst_w * max_hscale; |
215 | int max_src_w = dst_w * max_hscale; |
216 | 216 | ||
217 | drm_rect_adjust_size(src, max_src_w - src_w, 0); |
217 | drm_rect_adjust_size(src, max_src_w - src_w, 0); |
218 | 218 | ||
219 | return max_hscale; |
219 | return max_hscale; |
220 | } |
220 | } |
221 | 221 | ||
222 | return hscale; |
222 | return hscale; |
223 | } |
223 | } |
224 | EXPORT_SYMBOL(drm_rect_calc_hscale_relaxed); |
224 | EXPORT_SYMBOL(drm_rect_calc_hscale_relaxed); |
225 | 225 | ||
226 | /** |
226 | /** |
227 | * drm_rect_calc_vscale_relaxed - calculate the vertical scaling factor |
227 | * drm_rect_calc_vscale_relaxed - calculate the vertical scaling factor |
228 | * @src: source window rectangle |
228 | * @src: source window rectangle |
229 | * @dst: destination window rectangle |
229 | * @dst: destination window rectangle |
230 | * @min_vscale: minimum allowed vertical scaling factor |
230 | * @min_vscale: minimum allowed vertical scaling factor |
231 | * @max_vscale: maximum allowed vertical scaling factor |
231 | * @max_vscale: maximum allowed vertical scaling factor |
232 | * |
232 | * |
233 | * Calculate the vertical scaling factor as |
233 | * Calculate the vertical scaling factor as |
234 | * (@src height) / (@dst height). |
234 | * (@src height) / (@dst height). |
235 | * |
235 | * |
236 | * If the calculated scaling factor is below @min_vscale, |
236 | * If the calculated scaling factor is below @min_vscale, |
237 | * decrease the height of rectangle @dst to compensate. |
237 | * decrease the height of rectangle @dst to compensate. |
238 | * |
238 | * |
239 | * If the calculated scaling factor is above @max_vscale, |
239 | * If the calculated scaling factor is above @max_vscale, |
240 | * decrease the height of rectangle @src to compensate. |
240 | * decrease the height of rectangle @src to compensate. |
241 | * |
241 | * |
242 | * RETURNS: |
242 | * RETURNS: |
243 | * The vertical scaling factor. |
243 | * The vertical scaling factor. |
244 | */ |
244 | */ |
245 | int drm_rect_calc_vscale_relaxed(struct drm_rect *src, |
245 | int drm_rect_calc_vscale_relaxed(struct drm_rect *src, |
246 | struct drm_rect *dst, |
246 | struct drm_rect *dst, |
247 | int min_vscale, int max_vscale) |
247 | int min_vscale, int max_vscale) |
248 | { |
248 | { |
249 | int src_h = drm_rect_height(src); |
249 | int src_h = drm_rect_height(src); |
250 | int dst_h = drm_rect_height(dst); |
250 | int dst_h = drm_rect_height(dst); |
251 | int vscale = drm_calc_scale(src_h, dst_h); |
251 | int vscale = drm_calc_scale(src_h, dst_h); |
252 | 252 | ||
253 | if (vscale < 0 || dst_h == 0) |
253 | if (vscale < 0 || dst_h == 0) |
254 | return vscale; |
254 | return vscale; |
255 | 255 | ||
256 | if (vscale < min_vscale) { |
256 | if (vscale < min_vscale) { |
257 | int max_dst_h = src_h / min_vscale; |
257 | int max_dst_h = src_h / min_vscale; |
258 | 258 | ||
259 | drm_rect_adjust_size(dst, 0, max_dst_h - dst_h); |
259 | drm_rect_adjust_size(dst, 0, max_dst_h - dst_h); |
260 | 260 | ||
261 | return min_vscale; |
261 | return min_vscale; |
262 | } |
262 | } |
263 | 263 | ||
264 | if (vscale > max_vscale) { |
264 | if (vscale > max_vscale) { |
265 | int max_src_h = dst_h * max_vscale; |
265 | int max_src_h = dst_h * max_vscale; |
266 | 266 | ||
267 | drm_rect_adjust_size(src, 0, max_src_h - src_h); |
267 | drm_rect_adjust_size(src, 0, max_src_h - src_h); |
268 | 268 | ||
269 | return max_vscale; |
269 | return max_vscale; |
270 | } |
270 | } |
271 | 271 | ||
272 | return vscale; |
272 | return vscale; |
273 | } |
273 | } |
274 | EXPORT_SYMBOL(drm_rect_calc_vscale_relaxed); |
274 | EXPORT_SYMBOL(drm_rect_calc_vscale_relaxed); |
275 | 275 | ||
276 | /** |
276 | /** |
277 | * drm_rect_debug_print - print the rectangle information |
277 | * drm_rect_debug_print - print the rectangle information |
- | 278 | * @prefix: prefix string |
|
278 | * @r: rectangle to print |
279 | * @r: rectangle to print |
279 | * @fixed_point: rectangle is in 16.16 fixed point format |
280 | * @fixed_point: rectangle is in 16.16 fixed point format |
280 | */ |
281 | */ |
281 | void drm_rect_debug_print(const struct drm_rect *r, bool fixed_point) |
282 | void drm_rect_debug_print(const char *prefix, const struct drm_rect *r, bool fixed_point) |
282 | { |
283 | { |
283 | int w = drm_rect_width(r); |
284 | int w = drm_rect_width(r); |
284 | int h = drm_rect_height(r); |
285 | int h = drm_rect_height(r); |
285 | 286 | ||
286 | if (fixed_point) |
287 | if (fixed_point) |
287 | DRM_DEBUG_KMS("%d.%06ux%d.%06u%+d.%06u%+d.%06u\n", |
288 | DRM_DEBUG_KMS("%s%d.%06ux%d.%06u%+d.%06u%+d.%06u\n", prefix, |
288 | w >> 16, ((w & 0xffff) * 15625) >> 10, |
289 | w >> 16, ((w & 0xffff) * 15625) >> 10, |
289 | h >> 16, ((h & 0xffff) * 15625) >> 10, |
290 | h >> 16, ((h & 0xffff) * 15625) >> 10, |
290 | r->x1 >> 16, ((r->x1 & 0xffff) * 15625) >> 10, |
291 | r->x1 >> 16, ((r->x1 & 0xffff) * 15625) >> 10, |
291 | r->y1 >> 16, ((r->y1 & 0xffff) * 15625) >> 10); |
292 | r->y1 >> 16, ((r->y1 & 0xffff) * 15625) >> 10); |
292 | else |
293 | else |
293 | DRM_DEBUG_KMS("%dx%d%+d%+d\n", w, h, r->x1, r->y1); |
294 | DRM_DEBUG_KMS("%s%dx%d%+d%+d\n", prefix, w, h, r->x1, r->y1); |
294 | } |
295 | } |
295 | EXPORT_SYMBOL(drm_rect_debug_print); |
296 | EXPORT_SYMBOL(drm_rect_debug_print); |
296 | 297 | ||
297 | /** |
298 | /** |
298 | * drm_rect_rotate - Rotate the rectangle |
299 | * drm_rect_rotate - Rotate the rectangle |
299 | * @r: rectangle to be rotated |
300 | * @r: rectangle to be rotated |
300 | * @width: Width of the coordinate space |
301 | * @width: Width of the coordinate space |
301 | * @height: Height of the coordinate space |
302 | * @height: Height of the coordinate space |
302 | * @rotation: Transformation to be applied |
303 | * @rotation: Transformation to be applied |
303 | * |
304 | * |
304 | * Apply @rotation to the coordinates of rectangle @r. |
305 | * Apply @rotation to the coordinates of rectangle @r. |
305 | * |
306 | * |
306 | * @width and @height combined with @rotation define |
307 | * @width and @height combined with @rotation define |
307 | * the location of the new origin. |
308 | * the location of the new origin. |
308 | * |
309 | * |
309 | * @width correcsponds to the horizontal and @height |
310 | * @width correcsponds to the horizontal and @height |
310 | * to the vertical axis of the untransformed coordinate |
311 | * to the vertical axis of the untransformed coordinate |
311 | * space. |
312 | * space. |
312 | */ |
313 | */ |
313 | void drm_rect_rotate(struct drm_rect *r, |
314 | void drm_rect_rotate(struct drm_rect *r, |
314 | int width, int height, |
315 | int width, int height, |
315 | unsigned int rotation) |
316 | unsigned int rotation) |
316 | { |
317 | { |
317 | struct drm_rect tmp; |
318 | struct drm_rect tmp; |
318 | 319 | ||
319 | if (rotation & (BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y))) { |
320 | if (rotation & (BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y))) { |
320 | tmp = *r; |
321 | tmp = *r; |
321 | 322 | ||
322 | if (rotation & BIT(DRM_REFLECT_X)) { |
323 | if (rotation & BIT(DRM_REFLECT_X)) { |
323 | r->x1 = width - tmp.x2; |
324 | r->x1 = width - tmp.x2; |
324 | r->x2 = width - tmp.x1; |
325 | r->x2 = width - tmp.x1; |
325 | } |
326 | } |
326 | 327 | ||
327 | if (rotation & BIT(DRM_REFLECT_Y)) { |
328 | if (rotation & BIT(DRM_REFLECT_Y)) { |
328 | r->y1 = height - tmp.y2; |
329 | r->y1 = height - tmp.y2; |
329 | r->y2 = height - tmp.y1; |
330 | r->y2 = height - tmp.y1; |
330 | } |
331 | } |
331 | } |
332 | } |
332 | 333 | ||
333 | switch (rotation & DRM_ROTATE_MASK) { |
334 | switch (rotation & DRM_ROTATE_MASK) { |
334 | case BIT(DRM_ROTATE_0): |
335 | case BIT(DRM_ROTATE_0): |
335 | break; |
336 | break; |
336 | case BIT(DRM_ROTATE_90): |
337 | case BIT(DRM_ROTATE_90): |
337 | tmp = *r; |
338 | tmp = *r; |
338 | r->x1 = tmp.y1; |
339 | r->x1 = tmp.y1; |
339 | r->x2 = tmp.y2; |
340 | r->x2 = tmp.y2; |
340 | r->y1 = width - tmp.x2; |
341 | r->y1 = width - tmp.x2; |
341 | r->y2 = width - tmp.x1; |
342 | r->y2 = width - tmp.x1; |
342 | break; |
343 | break; |
343 | case BIT(DRM_ROTATE_180): |
344 | case BIT(DRM_ROTATE_180): |
344 | tmp = *r; |
345 | tmp = *r; |
345 | r->x1 = width - tmp.x2; |
346 | r->x1 = width - tmp.x2; |
346 | r->x2 = width - tmp.x1; |
347 | r->x2 = width - tmp.x1; |
347 | r->y1 = height - tmp.y2; |
348 | r->y1 = height - tmp.y2; |
348 | r->y2 = height - tmp.y1; |
349 | r->y2 = height - tmp.y1; |
349 | break; |
350 | break; |
350 | case BIT(DRM_ROTATE_270): |
351 | case BIT(DRM_ROTATE_270): |
351 | tmp = *r; |
352 | tmp = *r; |
352 | r->x1 = height - tmp.y2; |
353 | r->x1 = height - tmp.y2; |
353 | r->x2 = height - tmp.y1; |
354 | r->x2 = height - tmp.y1; |
354 | r->y1 = tmp.x1; |
355 | r->y1 = tmp.x1; |
355 | r->y2 = tmp.x2; |
356 | r->y2 = tmp.x2; |
356 | break; |
357 | break; |
357 | default: |
358 | default: |
358 | break; |
359 | break; |
359 | } |
360 | } |
360 | } |
361 | } |
361 | EXPORT_SYMBOL(drm_rect_rotate); |
362 | EXPORT_SYMBOL(drm_rect_rotate); |
362 | 363 | ||
363 | /** |
364 | /** |
364 | * drm_rect_rotate_inv - Inverse rotate the rectangle |
365 | * drm_rect_rotate_inv - Inverse rotate the rectangle |
365 | * @r: rectangle to be rotated |
366 | * @r: rectangle to be rotated |
366 | * @width: Width of the coordinate space |
367 | * @width: Width of the coordinate space |
367 | * @height: Height of the coordinate space |
368 | * @height: Height of the coordinate space |
368 | * @rotation: Transformation whose inverse is to be applied |
369 | * @rotation: Transformation whose inverse is to be applied |
369 | * |
370 | * |
370 | * Apply the inverse of @rotation to the coordinates |
371 | * Apply the inverse of @rotation to the coordinates |
371 | * of rectangle @r. |
372 | * of rectangle @r. |
372 | * |
373 | * |
373 | * @width and @height combined with @rotation define |
374 | * @width and @height combined with @rotation define |
374 | * the location of the new origin. |
375 | * the location of the new origin. |
375 | * |
376 | * |
376 | * @width correcsponds to the horizontal and @height |
377 | * @width correcsponds to the horizontal and @height |
377 | * to the vertical axis of the original untransformed |
378 | * to the vertical axis of the original untransformed |
378 | * coordinate space, so that you never have to flip |
379 | * coordinate space, so that you never have to flip |
379 | * them when doing a rotatation and its inverse. |
380 | * them when doing a rotatation and its inverse. |
380 | * That is, if you do: |
381 | * That is, if you do: |
381 | * |
382 | * |
382 | * drm_rotate(&r, width, height, rotation); |
383 | * drm_rotate(&r, width, height, rotation); |
383 | * drm_rotate_inv(&r, width, height, rotation); |
384 | * drm_rotate_inv(&r, width, height, rotation); |
384 | * |
385 | * |
385 | * you will always get back the original rectangle. |
386 | * you will always get back the original rectangle. |
386 | */ |
387 | */ |
387 | void drm_rect_rotate_inv(struct drm_rect *r, |
388 | void drm_rect_rotate_inv(struct drm_rect *r, |
388 | int width, int height, |
389 | int width, int height, |
389 | unsigned int rotation) |
390 | unsigned int rotation) |
390 | { |
391 | { |
391 | struct drm_rect tmp; |
392 | struct drm_rect tmp; |
392 | 393 | ||
393 | switch (rotation & DRM_ROTATE_MASK) { |
394 | switch (rotation & DRM_ROTATE_MASK) { |
394 | case BIT(DRM_ROTATE_0): |
395 | case BIT(DRM_ROTATE_0): |
395 | break; |
396 | break; |
396 | case BIT(DRM_ROTATE_90): |
397 | case BIT(DRM_ROTATE_90): |
397 | tmp = *r; |
398 | tmp = *r; |
398 | r->x1 = width - tmp.y2; |
399 | r->x1 = width - tmp.y2; |
399 | r->x2 = width - tmp.y1; |
400 | r->x2 = width - tmp.y1; |
400 | r->y1 = tmp.x1; |
401 | r->y1 = tmp.x1; |
401 | r->y2 = tmp.x2; |
402 | r->y2 = tmp.x2; |
402 | break; |
403 | break; |
403 | case BIT(DRM_ROTATE_180): |
404 | case BIT(DRM_ROTATE_180): |
404 | tmp = *r; |
405 | tmp = *r; |
405 | r->x1 = width - tmp.x2; |
406 | r->x1 = width - tmp.x2; |
406 | r->x2 = width - tmp.x1; |
407 | r->x2 = width - tmp.x1; |
407 | r->y1 = height - tmp.y2; |
408 | r->y1 = height - tmp.y2; |
408 | r->y2 = height - tmp.y1; |
409 | r->y2 = height - tmp.y1; |
409 | break; |
410 | break; |
410 | case BIT(DRM_ROTATE_270): |
411 | case BIT(DRM_ROTATE_270): |
411 | tmp = *r; |
412 | tmp = *r; |
412 | r->x1 = tmp.y1; |
413 | r->x1 = tmp.y1; |
413 | r->x2 = tmp.y2; |
414 | r->x2 = tmp.y2; |
414 | r->y1 = height - tmp.x2; |
415 | r->y1 = height - tmp.x2; |
415 | r->y2 = height - tmp.x1; |
416 | r->y2 = height - tmp.x1; |
416 | break; |
417 | break; |
417 | default: |
418 | default: |
418 | break; |
419 | break; |
419 | } |
420 | } |
420 | 421 | ||
421 | if (rotation & (BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y))) { |
422 | if (rotation & (BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y))) { |
422 | tmp = *r; |
423 | tmp = *r; |
423 | 424 | ||
424 | if (rotation & BIT(DRM_REFLECT_X)) { |
425 | if (rotation & BIT(DRM_REFLECT_X)) { |
425 | r->x1 = width - tmp.x2; |
426 | r->x1 = width - tmp.x2; |
426 | r->x2 = width - tmp.x1; |
427 | r->x2 = width - tmp.x1; |
427 | } |
428 | } |
428 | 429 | ||
429 | if (rotation & BIT(DRM_REFLECT_Y)) { |
430 | if (rotation & BIT(DRM_REFLECT_Y)) { |
430 | r->y1 = height - tmp.y2; |
431 | r->y1 = height - tmp.y2; |
431 | r->y2 = height - tmp.y1; |
432 | r->y2 = height - tmp.y1; |
432 | } |
433 | } |
433 | } |
434 | } |
434 | } |
435 | } |
435 | EXPORT_SYMBOL(drm_rect_rotate_inv);>>>>>>>>>> |
436 | EXPORT_SYMBOL(drm_rect_rotate_inv);>>>>>>>>>> |