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_
23 namespace hwcomposer {
28 // - timeout: time in miliseconds to stay blocked before returning if fd
30 int HWCPoll(int fd, int timeout);
32 // Reset's rect to include region hwc_region.
33 void ResetRectToRegion(const HwcRegion& hwc_region, HwcRect<int>& rect);
35 // Calculate new_rect to include target_rect. This is used to calculate
36 // Display Frame and Surface Damage rect of layers.
37 void CalculateRect(const HwcRect<int>& target_rect, HwcRect<int>& new_rect);
39 // Calculate new_rect to include target_rect. This is used to calculate
40 // Source Rect of layers.
41 void CalculateSourceRect(const HwcRect<float>& target_rect,
42 HwcRect<float>& new_rect);
44 // Returns true if format is a Media format.
45 bool IsSupportedMediaFormat(uint32_t format);
47 // Returns total planes for a given format.
48 uint32_t GetTotalPlanesForFormat(uint32_t format);
51 inline bool IsOverlapping(T l1, T t1, T r1, T b1, T l2, T t2, T r2, T b2)
52 // Do two rectangles overlap?
53 // Top-left is inclusive; bottom-right is exclusive
55 return ((l1 < r2 && r1 > l2) && (t1 < b2 && b1 > t2));
58 inline bool IsOverlapping(const hwcomposer::HwcRect<int>& rect1,
59 const hwcomposer::HwcRect<int>& rect2) {
60 return IsOverlapping(rect1.left, rect1.top, rect1.right, rect1.bottom,
61 rect2.left, rect2.top, rect2.right, rect2.bottom);
65 inline bool IsEnclosedBy(T l1, T t1, T r1, T b1, T l2, T t2, T r2, T b2)
66 // Do two rectangles overlap?
67 // Top-left is inclusive; bottom-right is exclusive
69 return ((l1 >= l2 && t1 >= t2) && (r1 <= r2 && b1 <= b2));
72 inline bool IsEnclosedBy(const hwcomposer::HwcRect<int>& rect1,
73 const hwcomposer::HwcRect<int>& rect2) {
74 return IsEnclosedBy(rect1.left, rect1.top, rect1.right, rect1.bottom,
75 rect2.left, rect2.top, rect2.right, rect2.bottom);
78 enum OverlapType { kEnclosed = 0, kOverlapping, kOutside };
80 inline OverlapType AnalyseOverlap(const hwcomposer::HwcRect<int>& rect,
81 const hwcomposer::HwcRect<int>& bounds) {
82 if (IsEnclosedBy(rect, bounds)) {
84 } else if (IsOverlapping(rect, bounds)) {
92 * Pretty-print HwcRect for debugging.
94 std::string StringifyRect(HwcRect<int> rect);
97 * Pretty-print HwcRegion for debugging.
99 std::string StringifyRegion(HwcRegion region);
101 } // namespace hwcomposer
103 #endif // COMMON_UTILS_HWCUTILS_H_