]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/gpu/drm/drm_rect.c
2 * Copyright (C) 2011-2013 Intel Corporation
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:
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
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
24 #include <linux/errno.h>
25 #include <linux/export.h>
26 #include <linux/kernel.h>
27 #include <drm/drm_rect.h>
30 * drm_rect_intersect - intersect two rectangles
31 * @r1: first rectangle
32 * @r2: second rectangle
34 * Calculate the intersection of rectangles @r1 and @r2.
35 * @r1 will be overwritten with the intersection.
38 * %true if rectangle @r1 is still visible after the operation,
41 bool drm_rect_intersect(struct drm_rect
*r1
, const struct drm_rect
*r2
)
43 r1
->x1
= max(r1
->x1
, r2
->x1
);
44 r1
->y1
= max(r1
->y1
, r2
->y1
);
45 r1
->x2
= min(r1
->x2
, r2
->x2
);
46 r1
->y2
= min(r1
->y2
, r2
->y2
);
48 return drm_rect_visible(r1
);
50 EXPORT_SYMBOL(drm_rect_intersect
);
53 * drm_rect_clip_scaled - perform a scaled clip operation
54 * @src: source window rectangle
55 * @dst: destination window rectangle
56 * @clip: clip rectangle
57 * @hscale: horizontal scaling factor
58 * @vscale: vertical scaling factor
60 * Clip rectangle @dst by rectangle @clip. Clip rectangle @src by the
61 * same amounts multiplied by @hscale and @vscale.
64 * %true if rectangle @dst is still visible after being clipped,
67 bool drm_rect_clip_scaled(struct drm_rect
*src
, struct drm_rect
*dst
,
68 const struct drm_rect
*clip
,
69 int hscale
, int vscale
)
73 diff
= clip
->x1
- dst
->x1
;
75 int64_t tmp
= src
->x1
+ (int64_t) diff
* hscale
;
76 src
->x1
= clamp_t(int64_t, tmp
, INT_MIN
, INT_MAX
);
78 diff
= clip
->y1
- dst
->y1
;
80 int64_t tmp
= src
->y1
+ (int64_t) diff
* vscale
;
81 src
->y1
= clamp_t(int64_t, tmp
, INT_MIN
, INT_MAX
);
83 diff
= dst
->x2
- clip
->x2
;
85 int64_t tmp
= src
->x2
- (int64_t) diff
* hscale
;
86 src
->x2
= clamp_t(int64_t, tmp
, INT_MIN
, INT_MAX
);
88 diff
= dst
->y2
- clip
->y2
;
90 int64_t tmp
= src
->y2
- (int64_t) diff
* vscale
;
91 src
->y2
= clamp_t(int64_t, tmp
, INT_MIN
, INT_MAX
);
94 return drm_rect_intersect(dst
, clip
);
96 EXPORT_SYMBOL(drm_rect_clip_scaled
);