drm_rect.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #ifndef DRM_RECT_H
  24. #define DRM_RECT_H
  25. /**
  26. * drm_rect - two dimensional rectangle
  27. * @x1: horizontal starting coordinate (inclusive)
  28. * @x2: horizontal ending coordinate (exclusive)
  29. * @y1: vertical starting coordinate (inclusive)
  30. * @y2: vertical ending coordinate (exclusive)
  31. */
  32. struct drm_rect {
  33. int x1, y1, x2, y2;
  34. };
  35. /**
  36. * drm_rect_adjust_size - adjust the size of the rectangle
  37. * @r: rectangle to be adjusted
  38. * @dw: horizontal adjustment
  39. * @dh: vertical adjustment
  40. *
  41. * Change the size of rectangle @r by @dw in the horizontal direction,
  42. * and by @dh in the vertical direction, while keeping the center
  43. * of @r stationary.
  44. *
  45. * Positive @dw and @dh increase the size, negative values decrease it.
  46. */
  47. static inline void drm_rect_adjust_size(struct drm_rect *r, int dw, int dh)
  48. {
  49. r->x1 -= dw >> 1;
  50. r->y1 -= dh >> 1;
  51. r->x2 += (dw + 1) >> 1;
  52. r->y2 += (dh + 1) >> 1;
  53. }
  54. /**
  55. * drm_rect_translate - translate the rectangle
  56. * @r: rectangle to be tranlated
  57. * @dx: horizontal translation
  58. * @dy: vertical translation
  59. *
  60. * Move rectangle @r by @dx in the horizontal direction,
  61. * and by @dy in the vertical direction.
  62. */
  63. static inline void drm_rect_translate(struct drm_rect *r, int dx, int dy)
  64. {
  65. r->x1 += dx;
  66. r->y1 += dy;
  67. r->x2 += dx;
  68. r->y2 += dy;
  69. }
  70. /**
  71. * drm_rect_downscale - downscale a rectangle
  72. * @r: rectangle to be downscaled
  73. * @horz: horizontal downscale factor
  74. * @vert: vertical downscale factor
  75. *
  76. * Divide the coordinates of rectangle @r by @horz and @vert.
  77. */
  78. static inline void drm_rect_downscale(struct drm_rect *r, int horz, int vert)
  79. {
  80. r->x1 /= horz;
  81. r->y1 /= vert;
  82. r->x2 /= horz;
  83. r->y2 /= vert;
  84. }
  85. /**
  86. * drm_rect_width - determine the rectangle width
  87. * @r: rectangle whose width is returned
  88. *
  89. * RETURNS:
  90. * The width of the rectangle.
  91. */
  92. static inline int drm_rect_width(const struct drm_rect *r)
  93. {
  94. return r->x2 - r->x1;
  95. }
  96. /**
  97. * drm_rect_height - determine the rectangle height
  98. * @r: rectangle whose height is returned
  99. *
  100. * RETURNS:
  101. * The height of the rectangle.
  102. */
  103. static inline int drm_rect_height(const struct drm_rect *r)
  104. {
  105. return r->y2 - r->y1;
  106. }
  107. /**
  108. * drm_rect_visible - determine if the the rectangle is visible
  109. * @r: rectangle whose visibility is returned
  110. *
  111. * RETURNS:
  112. * %true if the rectangle is visible, %false otherwise.
  113. */
  114. static inline bool drm_rect_visible(const struct drm_rect *r)
  115. {
  116. return drm_rect_width(r) > 0 && drm_rect_height(r) > 0;
  117. }
  118. bool drm_rect_intersect(struct drm_rect *r, const struct drm_rect *clip);
  119. bool drm_rect_clip_scaled(struct drm_rect *src, struct drm_rect *dst,
  120. const struct drm_rect *clip,
  121. int hscale, int vscale);
  122. #endif