XenevaOS
Loading...
Searching...
No Matches
drm_rect.h
Go to the documentation of this file.
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
46struct drm_rect {
47 int x1, y1, x2, y2;
48};
49
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
69#define DRM_RECT_FMT "%dx%d%+d%+d"
74#define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1
75
79#define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u"
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
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
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
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
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
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
184static inline int drm_rect_width(const struct drm_rect *r)
185{
186 return r->x2 - r->x1;
187}
188
196static inline int drm_rect_height(const struct drm_rect *r)
197{
198 return r->y2 - r->y1;
199}
200
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
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
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
249static inline bool drm_rect_overlap(const struct drm_rect *a,
250 const struct drm_rect *b)
251{
252 return (a->x2 > b->x1 && b->x2 > a->x1 &&
253 a->y2 > b->y1 && b->y2 > a->y1);
254}
255
256bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
257bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
258 const struct drm_rect *clip);
259int drm_rect_calc_hscale(const struct drm_rect *src,
260 const struct drm_rect *dst,
261 int min_hscale, int max_hscale);
262int drm_rect_calc_vscale(const struct drm_rect *src,
263 const struct drm_rect *dst,
264 int min_vscale, int max_vscale);
265void drm_rect_debug_print(const char *prefix,
266 const struct drm_rect *r, bool fixed_point);
268 int width, int height,
269 unsigned int rotation);
271 int width, int height,
272 unsigned int rotation);
273
274#endif
size_t a
Definition main.cpp:156
size_t b
Definition main.cpp:156
void drm_rect_rotate_inv(struct drm_rect *r, int width, int height, unsigned int rotation)
void drm_rect_debug_print(const char *prefix, const struct drm_rect *r, bool fixed_point)
int drm_rect_calc_hscale(const struct drm_rect *src, const struct drm_rect *dst, int min_hscale, int max_hscale)
bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip)
bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst, const struct drm_rect *clip)
void drm_rect_rotate(struct drm_rect *r, int width, int height, unsigned int rotation)
int drm_rect_calc_vscale(const struct drm_rect *src, const struct drm_rect *dst, int min_vscale, int max_vscale)
i32 clip(i32 x, i32 y, i32 z)
int y
Definition layout.c:118
int x
Definition layout.c:118
Definition drm_rect.h:46
int y2
Definition drm_rect.h:47
int x1
Definition drm_rect.h:47
int x2
Definition drm_rect.h:47
int y1
Definition drm_rect.h:47