2 // Copyright (c) 2017 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef COMMON_UTILS_HWCUTILS_H_
18 #define COMMON_UTILS_HWCUTILS_H_
22 namespace hwcomposer {
27 // - timeout: time in miliseconds to stay blocked before returning if fd
29 int HWCPoll(int fd, int timeout);
31 // Reset's rect to include region hwc_region.
32 void ResetRectToRegion(const HwcRegion& hwc_region, HwcRect<int>& rect);
34 // Returns true if format is a Media format.
35 bool IsSupportedMediaFormat(uint32_t format);
37 // Returns total planes for a given format.
38 uint32_t GetTotalPlanesForFormat(uint32_t format);
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
45 return ((l1 < r2 && r1 > l2) && (t1 < b2 && b1 > t2));
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);
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
59 return ((l1 >= l2 && t1 >= t2) && (r1 <= r2 && b1 <= b2));
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);
68 enum OverlapType { kEnclosed = 0, kOverlapping, kOutside };
70 inline OverlapType AnalyseOverlap(const hwcomposer::HwcRect<int>& rect,
71 const hwcomposer::HwcRect<int>& bounds) {
72 if (IsEnclosedBy(rect, bounds)) {
74 } else if (IsOverlapping(rect, bounds)) {
81 } // namespace hwcomposer
83 #endif // COMMON_UTILS_HWCUTILS_H_