OSDN Git Service

Fix MosaicDisplay.
[android-x86/external-IA-Hardware-Composer.git] / public / hwcutils.h
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef COMMON_UTILS_HWCUTILS_H_
18 #define COMMON_UTILS_HWCUTILS_H_
19
20 #include <hwcdefs.h>
21
22 namespace hwcomposer {
23
24 // Helper functions.
25
26 // Call poll() on fd.
27 //  - timeout: time in miliseconds to stay blocked before returning if fd
28 //  is not ready.
29 int HWCPoll(int fd, int timeout);
30
31 // Reset's rect to include region hwc_region.
32 void ResetRectToRegion(const HwcRegion& hwc_region, HwcRect<int>& rect);
33
34 // Returns true if format is a Media format.
35 bool IsSupportedMediaFormat(uint32_t format);
36
37 // Returns total planes for a given format.
38 uint32_t GetTotalPlanesForFormat(uint32_t format);
39
40 template <class T>
41 inline bool IsOverlapping(T l1, T t1, T r1, T b1, T l2, T t2, T r2, T b2)
42 // Do two rectangles overlap?
43 // Top-left is inclusive; bottom-right is exclusive
44 {
45   return ((l1 < r2 && r1 > l2) && (t1 < b2 && b1 > t2));
46 }
47
48 inline bool IsOverlapping(const hwcomposer::HwcRect<int>& rect1,
49                           const hwcomposer::HwcRect<int>& rect2) {
50   return IsOverlapping(rect1.left, rect1.top, rect1.right, rect1.bottom,
51                        rect2.left, rect2.top, rect2.right, rect2.bottom);
52 }
53
54 template <class T>
55 inline bool IsEnclosedBy(T l1, T t1, T r1, T b1, T l2, T t2, T r2, T b2)
56 // Do two rectangles overlap?
57 // Top-left is inclusive; bottom-right is exclusive
58 {
59   return ((l1 >= l2 && t1 >= t2) && (r1 <= r2 && b1 <= b2));
60 }
61
62 inline bool IsEnclosedBy(const hwcomposer::HwcRect<int>& rect1,
63                          const hwcomposer::HwcRect<int>& rect2) {
64   return IsEnclosedBy(rect1.left, rect1.top, rect1.right, rect1.bottom,
65                       rect2.left, rect2.top, rect2.right, rect2.bottom);
66 }
67
68 enum OverlapType { kEnclosed = 0, kOverlapping, kOutside };
69
70 inline OverlapType AnalyseOverlap(const hwcomposer::HwcRect<int>& rect,
71                                   const hwcomposer::HwcRect<int>& bounds) {
72   if (IsEnclosedBy(rect, bounds)) {
73     return kEnclosed;
74   } else if (IsOverlapping(rect, bounds)) {
75     return kOverlapping;
76   } else {
77     return kOutside;
78   }
79 }
80
81 }  // namespace hwcomposer
82
83 #endif  // COMMON_UTILS_HWCUTILS_H_