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