blob: 5c7824dcb39db476454d871483f0009bda2ca673
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 | |
36 | #define MAX_STR_LEN 4096 |
37 | |
38 | namespace android { |
39 | namespace amlogic { |
40 | |
41 | class Utils { |
42 | public: |
43 | Utils(); |
44 | ~Utils(); |
45 | |
46 | static int get_int_prop(const char* prop); |
47 | static bool get_bool_prop(const char* prop); |
48 | static bool get_str_prop(const char *key, char *value, const char *def); |
49 | |
50 | static int getSysfsInt(const char* syspath, int def); |
51 | static int getSysfsStr(const char *syspath, char *valstr); |
52 | static int getSysfsStr(const char* syspath, char *valstr, int size, |
53 | bool needOriginalData = false); |
54 | static int setSysfsStr(const char *path, const char *val); |
55 | |
56 | static bool checkBoolProp(const char* prop); |
57 | static int32_t checkIntProp(const char* prop); |
58 | static int32_t checkAndDupFd(int32_t fd); |
59 | static inline void closeFd(int32_t fd) { |
60 | if (fd > -1) close(fd); |
61 | } |
62 | static bool checkSysfsStatus(const char* sysfstr, char* lastr, int32_t size); |
63 | |
64 | static const char* getHotplugUeventEnvelope(); |
65 | static const char* getHdcpUeventEnvelope(); |
66 | static const char* getModeChangeUeventEnvelope(); |
67 | static const char* getSwitchState0(); |
68 | static const char* getSwitchState1(); |
69 | static const char* getSwitchModeState0(); |
70 | static const char* getSwitchModeState1(); |
71 | |
72 | template <typename T, typename S> |
73 | static inline bool compareRect(T a, S b) { |
74 | if ((int32_t)a.left == (int32_t)b.left |
75 | && (int32_t)a.top == (int32_t)b.top |
76 | && (int32_t)a.right == (int32_t)b.right |
77 | && (int32_t)a.bottom == (int32_t)b.bottom) { |
78 | return true; |
79 | } |
80 | return false; |
81 | } |
82 | template <typename T, typename S> |
83 | static inline bool compareSize(T a, S b) { |
84 | if ((int32_t)(a.right-a.left) == (int32_t)(b.right-b.left) |
85 | && (int32_t)(a.bottom-a.top) == (int32_t)(b.bottom-b.top)) { |
86 | return true; |
87 | } |
88 | return false; |
89 | } |
90 | template<typename T> |
91 | inline static T abs(const T& value) { |
92 | return value < 0 ? - value : value; |
93 | } |
94 | template <typename T> |
95 | static inline T min(T a, T b) { |
96 | return a<b ? a : b; |
97 | } |
98 | template <typename T> |
99 | static inline T max(T a, T b) { |
100 | return a>b ? a : b; |
101 | } |
102 | template <typename T> |
103 | static inline void swap(T& a, T& b) { |
104 | T t = a; |
105 | a = b; |
106 | b = t; |
107 | } |
108 | |
109 | /* |
110 | * hwc_rect_t operation |
111 | */ |
112 | enum OVERLAP_TYPE{ |
113 | OVERLAP_EMPTY = 0, |
114 | OVERLAP_PART, |
115 | OVERLAP_FULL |
116 | }; |
117 | |
118 | static bool rectEmpty(hwc_rect_t& rect); |
119 | static bool rectIntersect(hwc_rect_t& source, hwc_rect_t& dest, hwc_rect_t& result); |
120 | static OVERLAP_TYPE rectOverlap(hwc_rect_t& source, hwc_rect_t& dest); |
121 | }; |
122 | |
123 | } // namespace amlogic |
124 | } // namespace android |
125 | #endif /* UTILS_H_ */ |
126 |