Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011-2013 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 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 |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 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 |
| 13 | * Software. |
| 14 | * |
| 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, |
| 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 |
| 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 |
| 21 | * SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/export.h> |
| 26 | #include <linux/kernel.h> |
Sam Ravnborg | 0500c04 | 2019-05-26 19:35:35 +0200 | [diff] [blame] | 27 | |
| 28 | #include <drm/drm_mode.h> |
| 29 | #include <drm/drm_print.h> |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 30 | #include <drm/drm_rect.h> |
| 31 | |
| 32 | /** |
| 33 | * drm_rect_intersect - intersect two rectangles |
| 34 | * @r1: first rectangle |
| 35 | * @r2: second rectangle |
| 36 | * |
| 37 | * Calculate the intersection of rectangles @r1 and @r2. |
| 38 | * @r1 will be overwritten with the intersection. |
| 39 | * |
| 40 | * RETURNS: |
| 41 | * %true if rectangle @r1 is still visible after the operation, |
| 42 | * %false otherwise. |
| 43 | */ |
| 44 | bool drm_rect_intersect(struct drm_rect *r1, const struct drm_rect *r2) |
| 45 | { |
| 46 | r1->x1 = max(r1->x1, r2->x1); |
| 47 | r1->y1 = max(r1->y1, r2->y1); |
| 48 | r1->x2 = min(r1->x2, r2->x2); |
| 49 | r1->y2 = min(r1->y2, r2->y2); |
| 50 | |
| 51 | return drm_rect_visible(r1); |
| 52 | } |
| 53 | EXPORT_SYMBOL(drm_rect_intersect); |
| 54 | |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 55 | static u32 clip_scaled(int src, int dst, int *clip) |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 56 | { |
Ville Syrjälä | 433480c | 2019-11-22 19:56:20 +0200 | [diff] [blame] | 57 | u64 tmp; |
| 58 | |
| 59 | if (dst == 0) |
| 60 | return 0; |
| 61 | |
Ville Syrjälä | 2e35170 | 2019-11-22 19:56:21 +0200 | [diff] [blame] | 62 | /* Only clip what we have. Keeps the result bounded. */ |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 63 | *clip = min(*clip, dst); |
Ville Syrjälä | 2e35170 | 2019-11-22 19:56:21 +0200 | [diff] [blame] | 64 | |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 65 | tmp = mul_u32_u32(src, dst - *clip); |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * Round toward 1.0 when clipping so that we don't accidentally |
| 69 | * change upscaling to downscaling or vice versa. |
| 70 | */ |
| 71 | if (src < (dst << 16)) |
| 72 | return DIV_ROUND_UP_ULL(tmp, dst); |
| 73 | else |
| 74 | return DIV_ROUND_DOWN_ULL(tmp, dst); |
| 75 | } |
| 76 | |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 77 | /** |
| 78 | * drm_rect_clip_scaled - perform a scaled clip operation |
| 79 | * @src: source window rectangle |
| 80 | * @dst: destination window rectangle |
| 81 | * @clip: clip rectangle |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 82 | * |
| 83 | * Clip rectangle @dst by rectangle @clip. Clip rectangle @src by the |
Daniel Vetter | 94fee4a | 2019-11-26 15:52:13 +0100 | [diff] [blame] | 84 | * the corresponding amounts, retaining the vertical and horizontal scaling |
| 85 | * factors from @src to @dst. |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 86 | * |
| 87 | * RETURNS: |
Daniel Vetter | 94fee4a | 2019-11-26 15:52:13 +0100 | [diff] [blame] | 88 | * |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 89 | * %true if rectangle @dst is still visible after being clipped, |
Daniel Vetter | 94fee4a | 2019-11-26 15:52:13 +0100 | [diff] [blame] | 90 | * %false otherwise. |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 91 | */ |
| 92 | bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst, |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 93 | const struct drm_rect *clip) |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 94 | { |
| 95 | int diff; |
| 96 | |
| 97 | diff = clip->x1 - dst->x1; |
| 98 | if (diff > 0) { |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 99 | u32 new_src_w = clip_scaled(drm_rect_width(src), |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 100 | drm_rect_width(dst), &diff); |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 101 | |
Ville Syrjälä | 2e35170 | 2019-11-22 19:56:21 +0200 | [diff] [blame] | 102 | src->x1 = src->x2 - new_src_w; |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 103 | dst->x1 += diff; |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 104 | } |
| 105 | diff = clip->y1 - dst->y1; |
| 106 | if (diff > 0) { |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 107 | u32 new_src_h = clip_scaled(drm_rect_height(src), |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 108 | drm_rect_height(dst), &diff); |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 109 | |
Ville Syrjälä | 2e35170 | 2019-11-22 19:56:21 +0200 | [diff] [blame] | 110 | src->y1 = src->y2 - new_src_h; |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 111 | dst->y1 += diff; |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 112 | } |
| 113 | diff = dst->x2 - clip->x2; |
| 114 | if (diff > 0) { |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 115 | u32 new_src_w = clip_scaled(drm_rect_width(src), |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 116 | drm_rect_width(dst), &diff); |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 117 | |
Ville Syrjälä | 2e35170 | 2019-11-22 19:56:21 +0200 | [diff] [blame] | 118 | src->x2 = src->x1 + new_src_w; |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 119 | dst->x2 -= diff; |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 120 | } |
| 121 | diff = dst->y2 - clip->y2; |
| 122 | if (diff > 0) { |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 123 | u32 new_src_h = clip_scaled(drm_rect_height(src), |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 124 | drm_rect_height(dst), &diff); |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 125 | |
Ville Syrjälä | 2e35170 | 2019-11-22 19:56:21 +0200 | [diff] [blame] | 126 | src->y2 = src->y1 + new_src_h; |
Ville Syrjälä | 2020af2 | 2019-11-22 19:56:22 +0200 | [diff] [blame] | 127 | dst->y2 -= diff; |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 128 | } |
| 129 | |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 130 | return drm_rect_visible(dst); |
Ville Syrjälä | 3512f97 | 2013-04-24 18:52:34 +0300 | [diff] [blame] | 131 | } |
| 132 | EXPORT_SYMBOL(drm_rect_clip_scaled); |
Ville Syrjälä | 4954c42 | 2013-04-24 18:52:35 +0300 | [diff] [blame] | 133 | |
| 134 | static int drm_calc_scale(int src, int dst) |
| 135 | { |
| 136 | int scale = 0; |
| 137 | |
Ville Syrjälä | 1e1a5f8 | 2016-07-26 19:06:56 +0300 | [diff] [blame] | 138 | if (WARN_ON(src < 0 || dst < 0)) |
Ville Syrjälä | 4954c42 | 2013-04-24 18:52:35 +0300 | [diff] [blame] | 139 | return -EINVAL; |
| 140 | |
| 141 | if (dst == 0) |
| 142 | return 0; |
| 143 | |
Maarten Lankhorst | 6f96f20 | 2018-05-03 13:22:13 +0200 | [diff] [blame] | 144 | if (src > (dst << 16)) |
| 145 | return DIV_ROUND_UP(src, dst); |
| 146 | else |
| 147 | scale = src / dst; |
Ville Syrjälä | 4954c42 | 2013-04-24 18:52:35 +0300 | [diff] [blame] | 148 | |
| 149 | return scale; |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * drm_rect_calc_hscale - calculate the horizontal scaling factor |
| 154 | * @src: source window rectangle |
| 155 | * @dst: destination window rectangle |
| 156 | * @min_hscale: minimum allowed horizontal scaling factor |
| 157 | * @max_hscale: maximum allowed horizontal scaling factor |
| 158 | * |
| 159 | * Calculate the horizontal scaling factor as |
| 160 | * (@src width) / (@dst width). |
| 161 | * |
Maarten Lankhorst | 6f96f20 | 2018-05-03 13:22:13 +0200 | [diff] [blame] | 162 | * If the scale is below 1 << 16, round down. If the scale is above |
| 163 | * 1 << 16, round up. This will calculate the scale with the most |
| 164 | * pessimistic limit calculation. |
| 165 | * |
Ville Syrjälä | 4954c42 | 2013-04-24 18:52:35 +0300 | [diff] [blame] | 166 | * RETURNS: |
| 167 | * The horizontal scaling factor, or errno of out of limits. |
| 168 | */ |
| 169 | int drm_rect_calc_hscale(const struct drm_rect *src, |
| 170 | const struct drm_rect *dst, |
| 171 | int min_hscale, int max_hscale) |
| 172 | { |
| 173 | int src_w = drm_rect_width(src); |
| 174 | int dst_w = drm_rect_width(dst); |
| 175 | int hscale = drm_calc_scale(src_w, dst_w); |
| 176 | |
| 177 | if (hscale < 0 || dst_w == 0) |
| 178 | return hscale; |
| 179 | |
| 180 | if (hscale < min_hscale || hscale > max_hscale) |
| 181 | return -ERANGE; |
| 182 | |
| 183 | return hscale; |
| 184 | } |
| 185 | EXPORT_SYMBOL(drm_rect_calc_hscale); |
| 186 | |
| 187 | /** |
| 188 | * drm_rect_calc_vscale - calculate the vertical scaling factor |
| 189 | * @src: source window rectangle |
| 190 | * @dst: destination window rectangle |
| 191 | * @min_vscale: minimum allowed vertical scaling factor |
| 192 | * @max_vscale: maximum allowed vertical scaling factor |
| 193 | * |
| 194 | * Calculate the vertical scaling factor as |
| 195 | * (@src height) / (@dst height). |
| 196 | * |
Maarten Lankhorst | 6f96f20 | 2018-05-03 13:22:13 +0200 | [diff] [blame] | 197 | * If the scale is below 1 << 16, round down. If the scale is above |
| 198 | * 1 << 16, round up. This will calculate the scale with the most |
| 199 | * pessimistic limit calculation. |
| 200 | * |
Ville Syrjälä | 4954c42 | 2013-04-24 18:52:35 +0300 | [diff] [blame] | 201 | * RETURNS: |
| 202 | * The vertical scaling factor, or errno of out of limits. |
| 203 | */ |
| 204 | int drm_rect_calc_vscale(const struct drm_rect *src, |
| 205 | const struct drm_rect *dst, |
| 206 | int min_vscale, int max_vscale) |
| 207 | { |
| 208 | int src_h = drm_rect_height(src); |
| 209 | int dst_h = drm_rect_height(dst); |
| 210 | int vscale = drm_calc_scale(src_h, dst_h); |
| 211 | |
| 212 | if (vscale < 0 || dst_h == 0) |
| 213 | return vscale; |
| 214 | |
| 215 | if (vscale < min_vscale || vscale > max_vscale) |
| 216 | return -ERANGE; |
| 217 | |
| 218 | return vscale; |
| 219 | } |
| 220 | EXPORT_SYMBOL(drm_rect_calc_vscale); |
| 221 | |
| 222 | /** |
Ville Syrjälä | e7272df | 2013-04-24 18:52:36 +0300 | [diff] [blame] | 223 | * drm_rect_debug_print - print the rectangle information |
Ville Syrjälä | c70f577 | 2015-11-16 17:02:36 +0200 | [diff] [blame] | 224 | * @prefix: prefix string |
Ville Syrjälä | e7272df | 2013-04-24 18:52:36 +0300 | [diff] [blame] | 225 | * @r: rectangle to print |
| 226 | * @fixed_point: rectangle is in 16.16 fixed point format |
| 227 | */ |
Ville Syrjälä | c70f577 | 2015-11-16 17:02:36 +0200 | [diff] [blame] | 228 | void drm_rect_debug_print(const char *prefix, const struct drm_rect *r, bool fixed_point) |
Ville Syrjälä | e7272df | 2013-04-24 18:52:36 +0300 | [diff] [blame] | 229 | { |
Ville Syrjälä | e7272df | 2013-04-24 18:52:36 +0300 | [diff] [blame] | 230 | if (fixed_point) |
Rob Clark | 65c7dc1 | 2016-11-05 11:08:06 -0400 | [diff] [blame] | 231 | DRM_DEBUG_KMS("%s" DRM_RECT_FP_FMT "\n", prefix, DRM_RECT_FP_ARG(r)); |
Ville Syrjälä | e7272df | 2013-04-24 18:52:36 +0300 | [diff] [blame] | 232 | else |
Rob Clark | 65c7dc1 | 2016-11-05 11:08:06 -0400 | [diff] [blame] | 233 | DRM_DEBUG_KMS("%s" DRM_RECT_FMT "\n", prefix, DRM_RECT_ARG(r)); |
Ville Syrjälä | e7272df | 2013-04-24 18:52:36 +0300 | [diff] [blame] | 234 | } |
| 235 | EXPORT_SYMBOL(drm_rect_debug_print); |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * drm_rect_rotate - Rotate the rectangle |
| 239 | * @r: rectangle to be rotated |
| 240 | * @width: Width of the coordinate space |
| 241 | * @height: Height of the coordinate space |
| 242 | * @rotation: Transformation to be applied |
| 243 | * |
| 244 | * Apply @rotation to the coordinates of rectangle @r. |
| 245 | * |
| 246 | * @width and @height combined with @rotation define |
| 247 | * the location of the new origin. |
| 248 | * |
| 249 | * @width correcsponds to the horizontal and @height |
| 250 | * to the vertical axis of the untransformed coordinate |
| 251 | * space. |
| 252 | */ |
| 253 | void drm_rect_rotate(struct drm_rect *r, |
| 254 | int width, int height, |
| 255 | unsigned int rotation) |
| 256 | { |
| 257 | struct drm_rect tmp; |
| 258 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 259 | if (rotation & (DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y)) { |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 260 | tmp = *r; |
| 261 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 262 | if (rotation & DRM_MODE_REFLECT_X) { |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 263 | r->x1 = width - tmp.x2; |
| 264 | r->x2 = width - tmp.x1; |
| 265 | } |
| 266 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 267 | if (rotation & DRM_MODE_REFLECT_Y) { |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 268 | r->y1 = height - tmp.y2; |
| 269 | r->y2 = height - tmp.y1; |
| 270 | } |
| 271 | } |
| 272 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 273 | switch (rotation & DRM_MODE_ROTATE_MASK) { |
| 274 | case DRM_MODE_ROTATE_0: |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 275 | break; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 276 | case DRM_MODE_ROTATE_90: |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 277 | tmp = *r; |
| 278 | r->x1 = tmp.y1; |
| 279 | r->x2 = tmp.y2; |
| 280 | r->y1 = width - tmp.x2; |
| 281 | r->y2 = width - tmp.x1; |
| 282 | break; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 283 | case DRM_MODE_ROTATE_180: |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 284 | tmp = *r; |
| 285 | r->x1 = width - tmp.x2; |
| 286 | r->x2 = width - tmp.x1; |
| 287 | r->y1 = height - tmp.y2; |
| 288 | r->y2 = height - tmp.y1; |
| 289 | break; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 290 | case DRM_MODE_ROTATE_270: |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 291 | tmp = *r; |
| 292 | r->x1 = height - tmp.y2; |
| 293 | r->x2 = height - tmp.y1; |
| 294 | r->y1 = tmp.x1; |
| 295 | r->y2 = tmp.x2; |
| 296 | break; |
| 297 | default: |
| 298 | break; |
| 299 | } |
| 300 | } |
| 301 | EXPORT_SYMBOL(drm_rect_rotate); |
| 302 | |
| 303 | /** |
| 304 | * drm_rect_rotate_inv - Inverse rotate the rectangle |
| 305 | * @r: rectangle to be rotated |
| 306 | * @width: Width of the coordinate space |
| 307 | * @height: Height of the coordinate space |
| 308 | * @rotation: Transformation whose inverse is to be applied |
| 309 | * |
| 310 | * Apply the inverse of @rotation to the coordinates |
| 311 | * of rectangle @r. |
| 312 | * |
| 313 | * @width and @height combined with @rotation define |
| 314 | * the location of the new origin. |
| 315 | * |
| 316 | * @width correcsponds to the horizontal and @height |
| 317 | * to the vertical axis of the original untransformed |
| 318 | * coordinate space, so that you never have to flip |
| 319 | * them when doing a rotatation and its inverse. |
Daniel Vetter | 5edbfc4 | 2016-12-29 21:48:29 +0100 | [diff] [blame] | 320 | * That is, if you do :: |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 321 | * |
Ville Syrjälä | ec66723 | 2018-04-26 17:16:31 +0300 | [diff] [blame] | 322 | * drm_rect_rotate(&r, width, height, rotation); |
| 323 | * drm_rect_rotate_inv(&r, width, height, rotation); |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 324 | * |
| 325 | * you will always get back the original rectangle. |
| 326 | */ |
| 327 | void drm_rect_rotate_inv(struct drm_rect *r, |
| 328 | int width, int height, |
| 329 | unsigned int rotation) |
| 330 | { |
| 331 | struct drm_rect tmp; |
| 332 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 333 | switch (rotation & DRM_MODE_ROTATE_MASK) { |
| 334 | case DRM_MODE_ROTATE_0: |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 335 | break; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 336 | case DRM_MODE_ROTATE_90: |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 337 | tmp = *r; |
| 338 | r->x1 = width - tmp.y2; |
| 339 | r->x2 = width - tmp.y1; |
| 340 | r->y1 = tmp.x1; |
| 341 | r->y2 = tmp.x2; |
| 342 | break; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 343 | case DRM_MODE_ROTATE_180: |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 344 | tmp = *r; |
| 345 | r->x1 = width - tmp.x2; |
| 346 | r->x2 = width - tmp.x1; |
| 347 | r->y1 = height - tmp.y2; |
| 348 | r->y2 = height - tmp.y1; |
| 349 | break; |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 350 | case DRM_MODE_ROTATE_270: |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 351 | tmp = *r; |
| 352 | r->x1 = tmp.y1; |
| 353 | r->x2 = tmp.y2; |
| 354 | r->y1 = height - tmp.x2; |
| 355 | r->y2 = height - tmp.x1; |
| 356 | break; |
| 357 | default: |
| 358 | break; |
| 359 | } |
| 360 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 361 | if (rotation & (DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y)) { |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 362 | tmp = *r; |
| 363 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 364 | if (rotation & DRM_MODE_REFLECT_X) { |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 365 | r->x1 = width - tmp.x2; |
| 366 | r->x2 = width - tmp.x1; |
| 367 | } |
| 368 | |
Robert Foss | c2c446a | 2017-05-19 16:50:17 -0400 | [diff] [blame] | 369 | if (rotation & DRM_MODE_REFLECT_Y) { |
Ville Syrjälä | 07074006 | 2014-07-08 10:31:55 +0530 | [diff] [blame] | 370 | r->y1 = height - tmp.y2; |
| 371 | r->y2 = height - tmp.y1; |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | EXPORT_SYMBOL(drm_rect_rotate_inv); |