summaryrefslogtreecommitdiff
path: root/hwc2/common/utils/Utils.h (plain)
blob: 6894dfb8248b363fd239100eede2ac95f2aaf034
1/*
2// Copyright (c) 2016 Amlogic
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
18#ifndef UTILS_H_
19#define UTILS_H_
20
21#include <Amavutils.h>
22#include <hardware/hwcomposer_defs.h>
23
24#define DISPLAY_HPD_STATE "/sys/class/amhdmitx/amhdmitx0/hpd_state"
25#define DISPLAY_HDMI_EDID "/sys/class/amhdmitx/amhdmitx0/disp_cap"
26#define SYSFS_AMVIDEO_CURIDX "/sys/module/amvideo/parameters/cur_dev_idx"
27#define SYSFS_DISPLAY_MODE "/sys/class/display/mode"
28#define SYSFS_DISPLAY1_MODE "/sys/class/display/mode"
29#define SYSFS_DISPLAY2_MODE "/sys/class/display2/mode"
30#define SYSFS_FB0_FREE_SCALE "/sys/class/graphics/fb0/free_scale"
31#define SYSFS_FB1_FREE_SCALE "/sys/class/graphics/fb1/free_scale"
32#define SYSFS_VIDEO_AXIS "/sys/class/video/axis"
33#define SYSFS_VIDEOBUFUSED "/sys/class/amstream/videobufused"
34#define SYSFS_WINDOW_AXIS "/sys/class/graphics/fb0/window_axis"
35
36namespace android {
37namespace amlogic {
38
39class Utils {
40public:
41 Utils();
42 ~Utils();
43
44 static int get_int_prop(const char* prop);
45 static bool get_bool_prop(const char* prop);
46
47 static int getSysfsInt(const char* syspath, int def);
48 static int getSysfsStr(const char* syspath, char *valstr, int size,
49 bool needOriginalData = false);
50 static int setSysfsStr(const char *path, const char *val);
51
52 static bool checkBoolProp(const char* prop);
53 static int32_t checkIntProp(const char* prop);
54 static int32_t checkAndDupFd(int32_t fd);
55 static inline void closeFd(int32_t fd) {
56 if (fd > -1) close(fd);
57 }
58 static bool checkSysfsStatus(const char* sysfstr, char* lastr, int32_t size);
59
60 static const char* getHotplugUeventEnvelope();
61 static const char* getHdcpUeventEnvelope();
62 static const char* getSwitchState0();
63 static const char* getSwitchState1();
64
65 template <typename T, typename S>
66 static inline bool compareRect(T a, S b) {
67 if ((int32_t)a.left == (int32_t)b.left
68 && (int32_t)a.top == (int32_t)b.top
69 && (int32_t)a.right == (int32_t)b.right
70 && (int32_t)a.bottom == (int32_t)b.bottom) {
71 return true;
72 }
73 return false;
74 }
75 template <typename T, typename S>
76 static inline bool compareSize(T a, S b) {
77 if ((int32_t)(a.right-a.left) == (int32_t)(b.right-b.left)
78 && (int32_t)(a.bottom-a.top) == (int32_t)(b.bottom-b.top)) {
79 return true;
80 }
81 return false;
82 }
83 template<typename T>
84 inline static T abs(const T& value) {
85 return value < 0 ? - value : value;
86 }
87 template <typename T>
88 static inline T min(T a, T b) {
89 return a<b ? a : b;
90 }
91 template <typename T>
92 static inline T max(T a, T b) {
93 return a>b ? a : b;
94 }
95 template <typename T>
96 static inline void swap(T& a, T& b) {
97 T t = a;
98 a = b;
99 b = t;
100 }
101
102 /*
103 * hwc_rect_t operation
104 */
105 enum OVERLAP_TYPE{
106 OVERLAP_EMPTY = 0,
107 OVERLAP_PART,
108 OVERLAP_FULL
109 };
110
111 static bool rectEmpty(hwc_rect_t& rect);
112 static bool rectIntersect(hwc_rect_t& source, hwc_rect_t& dest, hwc_rect_t& result);
113 static OVERLAP_TYPE rectOverlap(hwc_rect_t& source, hwc_rect_t& dest);
114};
115
116} // namespace amlogic
117} // namespace android
118#endif /* UTILS_H_ */
119