![]() |
|
|||
0001 /* 0002 * Copyright (C) 2011-2013 Intel Corporation 0003 * 0004 * Permission is hereby granted, free of charge, to any person obtaining a 0005 * copy of this software and associated documentation files (the "Software"), 0006 * to deal in the Software without restriction, including without limitation 0007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 0008 * and/or sell copies of the Software, and to permit persons to whom the 0009 * Software is furnished to do so, subject to the following conditions: 0010 * 0011 * The above copyright notice and this permission notice (including the next 0012 * paragraph) shall be included in all copies or substantial portions of the 0013 * Software. 0014 * 0015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 0018 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0021 * SOFTWARE. 0022 */ 0023 0024 #ifndef DRM_RECT_H 0025 #define DRM_RECT_H 0026 0027 #include <linux/types.h> 0028 0029 /** 0030 * DOC: rect utils 0031 * 0032 * Utility functions to help manage rectangular areas for 0033 * clipping, scaling, etc. calculations. 0034 */ 0035 0036 /** 0037 * struct drm_rect - two dimensional rectangle 0038 * @x1: horizontal starting coordinate (inclusive) 0039 * @x2: horizontal ending coordinate (exclusive) 0040 * @y1: vertical starting coordinate (inclusive) 0041 * @y2: vertical ending coordinate (exclusive) 0042 * 0043 * Note that this must match the layout of struct drm_mode_rect or the damage 0044 * helpers like drm_atomic_helper_damage_iter_init() break. 0045 */ 0046 struct drm_rect { 0047 int x1, y1, x2, y2; 0048 }; 0049 0050 /** 0051 * DRM_RECT_INIT - initialize a rectangle from x/y/w/h 0052 * @x: x coordinate 0053 * @y: y coordinate 0054 * @w: width 0055 * @h: height 0056 * 0057 * RETURNS: 0058 * A new rectangle of the specified size. 0059 */ 0060 #define DRM_RECT_INIT(x, y, w, h) ((struct drm_rect){ \ 0061 .x1 = (x), \ 0062 .y1 = (y), \ 0063 .x2 = (x) + (w), \ 0064 .y2 = (y) + (h) }) 0065 0066 /** 0067 * DRM_RECT_FMT - printf string for &struct drm_rect 0068 */ 0069 #define DRM_RECT_FMT "%dx%d%+d%+d" 0070 /** 0071 * DRM_RECT_ARG - printf arguments for &struct drm_rect 0072 * @r: rectangle struct 0073 */ 0074 #define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1 0075 0076 /** 0077 * DRM_RECT_FP_FMT - printf string for &struct drm_rect in 16.16 fixed point 0078 */ 0079 #define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u" 0080 /** 0081 * DRM_RECT_FP_ARG - printf arguments for &struct drm_rect in 16.16 fixed point 0082 * @r: rectangle struct 0083 * 0084 * This is useful for e.g. printing plane source rectangles, which are in 16.16 0085 * fixed point. 0086 */ 0087 #define DRM_RECT_FP_ARG(r) \ 0088 drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \ 0089 drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \ 0090 (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \ 0091 (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10 0092 0093 /** 0094 * drm_rect_init - initialize the rectangle from x/y/w/h 0095 * @r: rectangle 0096 * @x: x coordinate 0097 * @y: y coordinate 0098 * @width: width 0099 * @height: height 0100 */ 0101 static inline void drm_rect_init(struct drm_rect *r, int x, int y, 0102 int width, int height) 0103 { 0104 r->x1 = x; 0105 r->y1 = y; 0106 r->x2 = x + width; 0107 r->y2 = y + height; 0108 } 0109 0110 /** 0111 * drm_rect_adjust_size - adjust the size of the rectangle 0112 * @r: rectangle to be adjusted 0113 * @dw: horizontal adjustment 0114 * @dh: vertical adjustment 0115 * 0116 * Change the size of rectangle @r by @dw in the horizontal direction, 0117 * and by @dh in the vertical direction, while keeping the center 0118 * of @r stationary. 0119 * 0120 * Positive @dw and @dh increase the size, negative values decrease it. 0121 */ 0122 static inline void drm_rect_adjust_size(struct drm_rect *r, int dw, int dh) 0123 { 0124 r->x1 -= dw >> 1; 0125 r->y1 -= dh >> 1; 0126 r->x2 += (dw + 1) >> 1; 0127 r->y2 += (dh + 1) >> 1; 0128 } 0129 0130 /** 0131 * drm_rect_translate - translate the rectangle 0132 * @r: rectangle to be tranlated 0133 * @dx: horizontal translation 0134 * @dy: vertical translation 0135 * 0136 * Move rectangle @r by @dx in the horizontal direction, 0137 * and by @dy in the vertical direction. 0138 */ 0139 static inline void drm_rect_translate(struct drm_rect *r, int dx, int dy) 0140 { 0141 r->x1 += dx; 0142 r->y1 += dy; 0143 r->x2 += dx; 0144 r->y2 += dy; 0145 } 0146 0147 /** 0148 * drm_rect_translate_to - translate the rectangle to an absolute position 0149 * @r: rectangle to be tranlated 0150 * @x: horizontal position 0151 * @y: vertical position 0152 * 0153 * Move rectangle @r to @x in the horizontal direction, 0154 * and to @y in the vertical direction. 0155 */ 0156 static inline void drm_rect_translate_to(struct drm_rect *r, int x, int y) 0157 { 0158 drm_rect_translate(r, x - r->x1, y - r->y1); 0159 } 0160 0161 /** 0162 * drm_rect_downscale - downscale a rectangle 0163 * @r: rectangle to be downscaled 0164 * @horz: horizontal downscale factor 0165 * @vert: vertical downscale factor 0166 * 0167 * Divide the coordinates of rectangle @r by @horz and @vert. 0168 */ 0169 static inline void drm_rect_downscale(struct drm_rect *r, int horz, int vert) 0170 { 0171 r->x1 /= horz; 0172 r->y1 /= vert; 0173 r->x2 /= horz; 0174 r->y2 /= vert; 0175 } 0176 0177 /** 0178 * drm_rect_width - determine the rectangle width 0179 * @r: rectangle whose width is returned 0180 * 0181 * RETURNS: 0182 * The width of the rectangle. 0183 */ 0184 static inline int drm_rect_width(const struct drm_rect *r) 0185 { 0186 return r->x2 - r->x1; 0187 } 0188 0189 /** 0190 * drm_rect_height - determine the rectangle height 0191 * @r: rectangle whose height is returned 0192 * 0193 * RETURNS: 0194 * The height of the rectangle. 0195 */ 0196 static inline int drm_rect_height(const struct drm_rect *r) 0197 { 0198 return r->y2 - r->y1; 0199 } 0200 0201 /** 0202 * drm_rect_visible - determine if the rectangle is visible 0203 * @r: rectangle whose visibility is returned 0204 * 0205 * RETURNS: 0206 * %true if the rectangle is visible, %false otherwise. 0207 */ 0208 static inline bool drm_rect_visible(const struct drm_rect *r) 0209 { 0210 return drm_rect_width(r) > 0 && drm_rect_height(r) > 0; 0211 } 0212 0213 /** 0214 * drm_rect_equals - determine if two rectangles are equal 0215 * @r1: first rectangle 0216 * @r2: second rectangle 0217 * 0218 * RETURNS: 0219 * %true if the rectangles are equal, %false otherwise. 0220 */ 0221 static inline bool drm_rect_equals(const struct drm_rect *r1, 0222 const struct drm_rect *r2) 0223 { 0224 return r1->x1 == r2->x1 && r1->x2 == r2->x2 && 0225 r1->y1 == r2->y1 && r1->y2 == r2->y2; 0226 } 0227 0228 /** 0229 * drm_rect_fp_to_int - Convert a rect in 16.16 fixed point form to int form. 0230 * @dst: rect to be stored the converted value 0231 * @src: rect in 16.16 fixed point form 0232 */ 0233 static inline void drm_rect_fp_to_int(struct drm_rect *dst, 0234 const struct drm_rect *src) 0235 { 0236 drm_rect_init(dst, src->x1 >> 16, src->y1 >> 16, 0237 drm_rect_width(src) >> 16, 0238 drm_rect_height(src) >> 16); 0239 } 0240 0241 bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip); 0242 bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst, 0243 const struct drm_rect *clip); 0244 int drm_rect_calc_hscale(const struct drm_rect *src, 0245 const struct drm_rect *dst, 0246 int min_hscale, int max_hscale); 0247 int drm_rect_calc_vscale(const struct drm_rect *src, 0248 const struct drm_rect *dst, 0249 int min_vscale, int max_vscale); 0250 void drm_rect_debug_print(const char *prefix, 0251 const struct drm_rect *r, bool fixed_point); 0252 void drm_rect_rotate(struct drm_rect *r, 0253 int width, int height, 0254 unsigned int rotation); 0255 void drm_rect_rotate_inv(struct drm_rect *r, 0256 int width, int height, 0257 unsigned int rotation); 0258 0259 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |