Linux Audio

Check our new training course

Loading...
v6.2
  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#ifndef DRM_RECT_H
 25#define DRM_RECT_H
 26
 27#include <linux/types.h>
 28
 29/**
 30 * DOC: rect utils
 31 *
 32 * Utility functions to help manage rectangular areas for
 33 * clipping, scaling, etc. calculations.
 34 */
 35
 36/**
 37 * struct drm_rect - two dimensional rectangle
 38 * @x1: horizontal starting coordinate (inclusive)
 39 * @x2: horizontal ending coordinate (exclusive)
 40 * @y1: vertical starting coordinate (inclusive)
 41 * @y2: vertical ending coordinate (exclusive)
 42 *
 43 * Note that this must match the layout of struct drm_mode_rect or the damage
 44 * helpers like drm_atomic_helper_damage_iter_init() break.
 45 */
 46struct drm_rect {
 47	int x1, y1, x2, y2;
 48};
 49
 50/**
 51 * DRM_RECT_INIT - initialize a rectangle from x/y/w/h
 52 * @x: x coordinate
 53 * @y: y coordinate
 54 * @w: width
 55 * @h: height
 56 *
 57 * RETURNS:
 58 * A new rectangle of the specified size.
 59 */
 60#define DRM_RECT_INIT(x, y, w, h) ((struct drm_rect){ \
 61		.x1 = (x), \
 62		.y1 = (y), \
 63		.x2 = (x) + (w), \
 64		.y2 = (y) + (h) })
 65
 66/**
 67 * DRM_RECT_FMT - printf string for &struct drm_rect
 68 */
 69#define DRM_RECT_FMT    "%dx%d%+d%+d"
 70/**
 71 * DRM_RECT_ARG - printf arguments for &struct drm_rect
 72 * @r: rectangle struct
 73 */
 74#define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
 75
 76/**
 77 * DRM_RECT_FP_FMT - printf string for &struct drm_rect in 16.16 fixed point
 78 */
 79#define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
 80/**
 81 * DRM_RECT_FP_ARG - printf arguments for &struct drm_rect in 16.16 fixed point
 82 * @r: rectangle struct
 83 *
 84 * This is useful for e.g. printing plane source rectangles, which are in 16.16
 85 * fixed point.
 86 */
 87#define DRM_RECT_FP_ARG(r) \
 88		drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
 89		drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
 90		(r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
 91		(r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
 92
 93/**
 94 * drm_rect_init - initialize the rectangle from x/y/w/h
 95 * @r: rectangle
 96 * @x: x coordinate
 97 * @y: y coordinate
 98 * @width: width
 99 * @height: height
100 */
101static inline void drm_rect_init(struct drm_rect *r, int x, int y,
102				 int width, int height)
103{
104	r->x1 = x;
105	r->y1 = y;
106	r->x2 = x + width;
107	r->y2 = y + height;
108}
109
110/**
111 * drm_rect_adjust_size - adjust the size of the rectangle
112 * @r: rectangle to be adjusted
113 * @dw: horizontal adjustment
114 * @dh: vertical adjustment
115 *
116 * Change the size of rectangle @r by @dw in the horizontal direction,
117 * and by @dh in the vertical direction, while keeping the center
118 * of @r stationary.
119 *
120 * Positive @dw and @dh increase the size, negative values decrease it.
121 */
122static inline void drm_rect_adjust_size(struct drm_rect *r, int dw, int dh)
123{
124	r->x1 -= dw >> 1;
125	r->y1 -= dh >> 1;
126	r->x2 += (dw + 1) >> 1;
127	r->y2 += (dh + 1) >> 1;
128}
129
130/**
131 * drm_rect_translate - translate the rectangle
132 * @r: rectangle to be tranlated
133 * @dx: horizontal translation
134 * @dy: vertical translation
135 *
136 * Move rectangle @r by @dx in the horizontal direction,
137 * and by @dy in the vertical direction.
138 */
139static inline void drm_rect_translate(struct drm_rect *r, int dx, int dy)
140{
141	r->x1 += dx;
142	r->y1 += dy;
143	r->x2 += dx;
144	r->y2 += dy;
145}
146
147/**
148 * drm_rect_translate_to - translate the rectangle to an absolute position
149 * @r: rectangle to be tranlated
150 * @x: horizontal position
151 * @y: vertical position
152 *
153 * Move rectangle @r to @x in the horizontal direction,
154 * and to @y in the vertical direction.
155 */
156static inline void drm_rect_translate_to(struct drm_rect *r, int x, int y)
157{
158	drm_rect_translate(r, x - r->x1, y - r->y1);
159}
160
161/**
162 * drm_rect_downscale - downscale a rectangle
163 * @r: rectangle to be downscaled
164 * @horz: horizontal downscale factor
165 * @vert: vertical downscale factor
166 *
167 * Divide the coordinates of rectangle @r by @horz and @vert.
168 */
169static inline void drm_rect_downscale(struct drm_rect *r, int horz, int vert)
170{
171	r->x1 /= horz;
172	r->y1 /= vert;
173	r->x2 /= horz;
174	r->y2 /= vert;
175}
176
177/**
178 * drm_rect_width - determine the rectangle width
179 * @r: rectangle whose width is returned
180 *
181 * RETURNS:
182 * The width of the rectangle.
183 */
184static inline int drm_rect_width(const struct drm_rect *r)
185{
186	return r->x2 - r->x1;
187}
188
189/**
190 * drm_rect_height - determine the rectangle height
191 * @r: rectangle whose height is returned
192 *
193 * RETURNS:
194 * The height of the rectangle.
195 */
196static inline int drm_rect_height(const struct drm_rect *r)
197{
198	return r->y2 - r->y1;
199}
200
201/**
202 * drm_rect_visible - determine if the rectangle is visible
203 * @r: rectangle whose visibility is returned
204 *
205 * RETURNS:
206 * %true if the rectangle is visible, %false otherwise.
207 */
208static inline bool drm_rect_visible(const struct drm_rect *r)
209{
210	return drm_rect_width(r) > 0 && drm_rect_height(r) > 0;
211}
212
213/**
214 * drm_rect_equals - determine if two rectangles are equal
215 * @r1: first rectangle
216 * @r2: second rectangle
217 *
218 * RETURNS:
219 * %true if the rectangles are equal, %false otherwise.
220 */
221static inline bool drm_rect_equals(const struct drm_rect *r1,
222				   const struct drm_rect *r2)
223{
224	return r1->x1 == r2->x1 && r1->x2 == r2->x2 &&
225		r1->y1 == r2->y1 && r1->y2 == r2->y2;
226}
227
228/**
229 * drm_rect_fp_to_int - Convert a rect in 16.16 fixed point form to int form.
230 * @dst: rect to be stored the converted value
231 * @src: rect in 16.16 fixed point form
232 */
233static inline void drm_rect_fp_to_int(struct drm_rect *dst,
234				      const struct drm_rect *src)
235{
236	drm_rect_init(dst, src->x1 >> 16, src->y1 >> 16,
237		      drm_rect_width(src) >> 16,
238		      drm_rect_height(src) >> 16);
239}
240
241bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
242bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
243			  const struct drm_rect *clip);
244int drm_rect_calc_hscale(const struct drm_rect *src,
245			 const struct drm_rect *dst,
246			 int min_hscale, int max_hscale);
247int drm_rect_calc_vscale(const struct drm_rect *src,
248			 const struct drm_rect *dst,
249			 int min_vscale, int max_vscale);
250void drm_rect_debug_print(const char *prefix,
251			  const struct drm_rect *r, bool fixed_point);
252void drm_rect_rotate(struct drm_rect *r,
253		     int width, int height,
254		     unsigned int rotation);
255void drm_rect_rotate_inv(struct drm_rect *r,
256			 int width, int height,
257			 unsigned int rotation);
258
259#endif
v5.9
  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#ifndef DRM_RECT_H
 25#define DRM_RECT_H
 26
 27#include <linux/types.h>
 28
 29/**
 30 * DOC: rect utils
 31 *
 32 * Utility functions to help manage rectangular areas for
 33 * clipping, scaling, etc. calculations.
 34 */
 35
 36/**
 37 * struct drm_rect - two dimensional rectangle
 38 * @x1: horizontal starting coordinate (inclusive)
 39 * @x2: horizontal ending coordinate (exclusive)
 40 * @y1: vertical starting coordinate (inclusive)
 41 * @y2: vertical ending coordinate (exclusive)
 
 
 
 42 */
 43struct drm_rect {
 44	int x1, y1, x2, y2;
 45};
 46
 47/**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 48 * DRM_RECT_FMT - printf string for &struct drm_rect
 49 */
 50#define DRM_RECT_FMT    "%dx%d%+d%+d"
 51/**
 52 * DRM_RECT_ARG - printf arguments for &struct drm_rect
 53 * @r: rectangle struct
 54 */
 55#define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
 56
 57/**
 58 * DRM_RECT_FP_FMT - printf string for &struct drm_rect in 16.16 fixed point
 59 */
 60#define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
 61/**
 62 * DRM_RECT_FP_ARG - printf arguments for &struct drm_rect in 16.16 fixed point
 63 * @r: rectangle struct
 64 *
 65 * This is useful for e.g. printing plane source rectangles, which are in 16.16
 66 * fixed point.
 67 */
 68#define DRM_RECT_FP_ARG(r) \
 69		drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \
 70		drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \
 71		(r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \
 72		(r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10
 73
 74/**
 75 * drm_rect_init - initialize the rectangle from x/y/w/h
 76 * @r: rectangle
 77 * @x: x coordinate
 78 * @y: y coordinate
 79 * @width: width
 80 * @height: height
 81 */
 82static inline void drm_rect_init(struct drm_rect *r, int x, int y,
 83				 int width, int height)
 84{
 85	r->x1 = x;
 86	r->y1 = y;
 87	r->x2 = x + width;
 88	r->y2 = y + height;
 89}
 90
 91/**
 92 * drm_rect_adjust_size - adjust the size of the rectangle
 93 * @r: rectangle to be adjusted
 94 * @dw: horizontal adjustment
 95 * @dh: vertical adjustment
 96 *
 97 * Change the size of rectangle @r by @dw in the horizontal direction,
 98 * and by @dh in the vertical direction, while keeping the center
 99 * of @r stationary.
100 *
101 * Positive @dw and @dh increase the size, negative values decrease it.
102 */
103static inline void drm_rect_adjust_size(struct drm_rect *r, int dw, int dh)
104{
105	r->x1 -= dw >> 1;
106	r->y1 -= dh >> 1;
107	r->x2 += (dw + 1) >> 1;
108	r->y2 += (dh + 1) >> 1;
109}
110
111/**
112 * drm_rect_translate - translate the rectangle
113 * @r: rectangle to be tranlated
114 * @dx: horizontal translation
115 * @dy: vertical translation
116 *
117 * Move rectangle @r by @dx in the horizontal direction,
118 * and by @dy in the vertical direction.
119 */
120static inline void drm_rect_translate(struct drm_rect *r, int dx, int dy)
121{
122	r->x1 += dx;
123	r->y1 += dy;
124	r->x2 += dx;
125	r->y2 += dy;
126}
127
128/**
129 * drm_rect_translate_to - translate the rectangle to an absolute position
130 * @r: rectangle to be tranlated
131 * @x: horizontal position
132 * @y: vertical position
133 *
134 * Move rectangle @r to @x in the horizontal direction,
135 * and to @y in the vertical direction.
136 */
137static inline void drm_rect_translate_to(struct drm_rect *r, int x, int y)
138{
139	drm_rect_translate(r, x - r->x1, y - r->y1);
140}
141
142/**
143 * drm_rect_downscale - downscale a rectangle
144 * @r: rectangle to be downscaled
145 * @horz: horizontal downscale factor
146 * @vert: vertical downscale factor
147 *
148 * Divide the coordinates of rectangle @r by @horz and @vert.
149 */
150static inline void drm_rect_downscale(struct drm_rect *r, int horz, int vert)
151{
152	r->x1 /= horz;
153	r->y1 /= vert;
154	r->x2 /= horz;
155	r->y2 /= vert;
156}
157
158/**
159 * drm_rect_width - determine the rectangle width
160 * @r: rectangle whose width is returned
161 *
162 * RETURNS:
163 * The width of the rectangle.
164 */
165static inline int drm_rect_width(const struct drm_rect *r)
166{
167	return r->x2 - r->x1;
168}
169
170/**
171 * drm_rect_height - determine the rectangle height
172 * @r: rectangle whose height is returned
173 *
174 * RETURNS:
175 * The height of the rectangle.
176 */
177static inline int drm_rect_height(const struct drm_rect *r)
178{
179	return r->y2 - r->y1;
180}
181
182/**
183 * drm_rect_visible - determine if the rectangle is visible
184 * @r: rectangle whose visibility is returned
185 *
186 * RETURNS:
187 * %true if the rectangle is visible, %false otherwise.
188 */
189static inline bool drm_rect_visible(const struct drm_rect *r)
190{
191	return drm_rect_width(r) > 0 && drm_rect_height(r) > 0;
192}
193
194/**
195 * drm_rect_equals - determine if two rectangles are equal
196 * @r1: first rectangle
197 * @r2: second rectangle
198 *
199 * RETURNS:
200 * %true if the rectangles are equal, %false otherwise.
201 */
202static inline bool drm_rect_equals(const struct drm_rect *r1,
203				   const struct drm_rect *r2)
204{
205	return r1->x1 == r2->x1 && r1->x2 == r2->x2 &&
206		r1->y1 == r2->y1 && r1->y2 == r2->y2;
 
 
 
 
 
 
 
 
 
 
 
 
 
207}
208
209bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
210bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
211			  const struct drm_rect *clip);
212int drm_rect_calc_hscale(const struct drm_rect *src,
213			 const struct drm_rect *dst,
214			 int min_hscale, int max_hscale);
215int drm_rect_calc_vscale(const struct drm_rect *src,
216			 const struct drm_rect *dst,
217			 int min_vscale, int max_vscale);
218void drm_rect_debug_print(const char *prefix,
219			  const struct drm_rect *r, bool fixed_point);
220void drm_rect_rotate(struct drm_rect *r,
221		     int width, int height,
222		     unsigned int rotation);
223void drm_rect_rotate_inv(struct drm_rect *r,
224			 int width, int height,
225			 unsigned int rotation);
226
227#endif