xref: /openbmc/linux/include/drm/drm_rect.h (revision 4954c428)
13512f976SVille Syrjälä /*
23512f976SVille Syrjälä  * Copyright (C) 2011-2013 Intel Corporation
33512f976SVille Syrjälä  *
43512f976SVille Syrjälä  * Permission is hereby granted, free of charge, to any person obtaining a
53512f976SVille Syrjälä  * copy of this software and associated documentation files (the "Software"),
63512f976SVille Syrjälä  * to deal in the Software without restriction, including without limitation
73512f976SVille Syrjälä  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
83512f976SVille Syrjälä  * and/or sell copies of the Software, and to permit persons to whom the
93512f976SVille Syrjälä  * Software is furnished to do so, subject to the following conditions:
103512f976SVille Syrjälä  *
113512f976SVille Syrjälä  * The above copyright notice and this permission notice (including the next
123512f976SVille Syrjälä  * paragraph) shall be included in all copies or substantial portions of the
133512f976SVille Syrjälä  * Software.
143512f976SVille Syrjälä  *
153512f976SVille Syrjälä  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
163512f976SVille Syrjälä  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
173512f976SVille Syrjälä  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
183512f976SVille Syrjälä  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
193512f976SVille Syrjälä  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
203512f976SVille Syrjälä  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
213512f976SVille Syrjälä  * SOFTWARE.
223512f976SVille Syrjälä  */
233512f976SVille Syrjälä 
243512f976SVille Syrjälä #ifndef DRM_RECT_H
253512f976SVille Syrjälä #define DRM_RECT_H
263512f976SVille Syrjälä 
273512f976SVille Syrjälä /**
283512f976SVille Syrjälä  * drm_rect - two dimensional rectangle
293512f976SVille Syrjälä  * @x1: horizontal starting coordinate (inclusive)
303512f976SVille Syrjälä  * @x2: horizontal ending coordinate (exclusive)
313512f976SVille Syrjälä  * @y1: vertical starting coordinate (inclusive)
323512f976SVille Syrjälä  * @y2: vertical ending coordinate (exclusive)
333512f976SVille Syrjälä  */
343512f976SVille Syrjälä struct drm_rect {
353512f976SVille Syrjälä 	int x1, y1, x2, y2;
363512f976SVille Syrjälä };
373512f976SVille Syrjälä 
383512f976SVille Syrjälä /**
393512f976SVille Syrjälä  * drm_rect_adjust_size - adjust the size of the rectangle
403512f976SVille Syrjälä  * @r: rectangle to be adjusted
413512f976SVille Syrjälä  * @dw: horizontal adjustment
423512f976SVille Syrjälä  * @dh: vertical adjustment
433512f976SVille Syrjälä  *
443512f976SVille Syrjälä  * Change the size of rectangle @r by @dw in the horizontal direction,
453512f976SVille Syrjälä  * and by @dh in the vertical direction, while keeping the center
463512f976SVille Syrjälä  * of @r stationary.
473512f976SVille Syrjälä  *
483512f976SVille Syrjälä  * Positive @dw and @dh increase the size, negative values decrease it.
493512f976SVille Syrjälä  */
503512f976SVille Syrjälä static inline void drm_rect_adjust_size(struct drm_rect *r, int dw, int dh)
513512f976SVille Syrjälä {
523512f976SVille Syrjälä 	r->x1 -= dw >> 1;
533512f976SVille Syrjälä 	r->y1 -= dh >> 1;
543512f976SVille Syrjälä 	r->x2 += (dw + 1) >> 1;
553512f976SVille Syrjälä 	r->y2 += (dh + 1) >> 1;
563512f976SVille Syrjälä }
573512f976SVille Syrjälä 
583512f976SVille Syrjälä /**
593512f976SVille Syrjälä  * drm_rect_translate - translate the rectangle
603512f976SVille Syrjälä  * @r: rectangle to be tranlated
613512f976SVille Syrjälä  * @dx: horizontal translation
623512f976SVille Syrjälä  * @dy: vertical translation
633512f976SVille Syrjälä  *
643512f976SVille Syrjälä  * Move rectangle @r by @dx in the horizontal direction,
653512f976SVille Syrjälä  * and by @dy in the vertical direction.
663512f976SVille Syrjälä  */
673512f976SVille Syrjälä static inline void drm_rect_translate(struct drm_rect *r, int dx, int dy)
683512f976SVille Syrjälä {
693512f976SVille Syrjälä 	r->x1 += dx;
703512f976SVille Syrjälä 	r->y1 += dy;
713512f976SVille Syrjälä 	r->x2 += dx;
723512f976SVille Syrjälä 	r->y2 += dy;
733512f976SVille Syrjälä }
743512f976SVille Syrjälä 
753512f976SVille Syrjälä /**
763512f976SVille Syrjälä  * drm_rect_downscale - downscale a rectangle
773512f976SVille Syrjälä  * @r: rectangle to be downscaled
783512f976SVille Syrjälä  * @horz: horizontal downscale factor
793512f976SVille Syrjälä  * @vert: vertical downscale factor
803512f976SVille Syrjälä  *
813512f976SVille Syrjälä  * Divide the coordinates of rectangle @r by @horz and @vert.
823512f976SVille Syrjälä  */
833512f976SVille Syrjälä static inline void drm_rect_downscale(struct drm_rect *r, int horz, int vert)
843512f976SVille Syrjälä {
853512f976SVille Syrjälä 	r->x1 /= horz;
863512f976SVille Syrjälä 	r->y1 /= vert;
873512f976SVille Syrjälä 	r->x2 /= horz;
883512f976SVille Syrjälä 	r->y2 /= vert;
893512f976SVille Syrjälä }
903512f976SVille Syrjälä 
913512f976SVille Syrjälä /**
923512f976SVille Syrjälä  * drm_rect_width - determine the rectangle width
933512f976SVille Syrjälä  * @r: rectangle whose width is returned
943512f976SVille Syrjälä  *
953512f976SVille Syrjälä  * RETURNS:
963512f976SVille Syrjälä  * The width of the rectangle.
973512f976SVille Syrjälä  */
983512f976SVille Syrjälä static inline int drm_rect_width(const struct drm_rect *r)
993512f976SVille Syrjälä {
1003512f976SVille Syrjälä 	return r->x2 - r->x1;
1013512f976SVille Syrjälä }
1023512f976SVille Syrjälä 
1033512f976SVille Syrjälä /**
1043512f976SVille Syrjälä  * drm_rect_height - determine the rectangle height
1053512f976SVille Syrjälä  * @r: rectangle whose height is returned
1063512f976SVille Syrjälä  *
1073512f976SVille Syrjälä  * RETURNS:
1083512f976SVille Syrjälä  * The height of the rectangle.
1093512f976SVille Syrjälä  */
1103512f976SVille Syrjälä static inline int drm_rect_height(const struct drm_rect *r)
1113512f976SVille Syrjälä {
1123512f976SVille Syrjälä 	return r->y2 - r->y1;
1133512f976SVille Syrjälä }
1143512f976SVille Syrjälä 
1153512f976SVille Syrjälä /**
1163512f976SVille Syrjälä  * drm_rect_visible - determine if the the rectangle is visible
1173512f976SVille Syrjälä  * @r: rectangle whose visibility is returned
1183512f976SVille Syrjälä  *
1193512f976SVille Syrjälä  * RETURNS:
1203512f976SVille Syrjälä  * %true if the rectangle is visible, %false otherwise.
1213512f976SVille Syrjälä  */
1223512f976SVille Syrjälä static inline bool drm_rect_visible(const struct drm_rect *r)
1233512f976SVille Syrjälä {
1243512f976SVille Syrjälä 	return drm_rect_width(r) > 0 && drm_rect_height(r) > 0;
1253512f976SVille Syrjälä }
1263512f976SVille Syrjälä 
1273512f976SVille Syrjälä bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
1283512f976SVille Syrjälä bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
1293512f976SVille Syrjälä 			  const struct drm_rect *clip,
1303512f976SVille Syrjälä 			  int hscale, int vscale);
1314954c428SVille Syrjälä int drm_rect_calc_hscale(const struct drm_rect *src,
1324954c428SVille Syrjälä 			 const struct drm_rect *dst,
1334954c428SVille Syrjälä 			 int min_hscale, int max_hscale);
1344954c428SVille Syrjälä int drm_rect_calc_vscale(const struct drm_rect *src,
1354954c428SVille Syrjälä 			 const struct drm_rect *dst,
1364954c428SVille Syrjälä 			 int min_vscale, int max_vscale);
1374954c428SVille Syrjälä int drm_rect_calc_hscale_relaxed(struct drm_rect *src,
1384954c428SVille Syrjälä 				 struct drm_rect *dst,
1394954c428SVille Syrjälä 				 int min_hscale, int max_hscale);
1404954c428SVille Syrjälä int drm_rect_calc_vscale_relaxed(struct drm_rect *src,
1414954c428SVille Syrjälä 				 struct drm_rect *dst,
1424954c428SVille Syrjälä 				 int min_vscale, int max_vscale);
1433512f976SVille Syrjälä 
1443512f976SVille Syrjälä #endif
145