blob: 53a55d0cff2c2731061ede1c34fec86706d0a9fa
1 | /* |
2 | // Copyright(c) 2016 Amlogic Corporation |
3 | */ |
4 | |
5 | #ifndef UTILS_H_ |
6 | #define UTILS_H_ |
7 | |
8 | #include <gralloc_priv.h> |
9 | #if WITH_LIBPLAYER_MODULE |
10 | #include <Amavutils.h> |
11 | #endif |
12 | |
13 | #define DISPLAY_HPD_STATE "/sys/class/amhdmitx/amhdmitx0/hpd_state" |
14 | #define DISPLAY_HDMI_EDID "/sys/class/amhdmitx/amhdmitx0/disp_cap" |
15 | #define SYSFS_AMVIDEO_CURIDX "/sys/module/amvideo/parameters/cur_dev_idx" |
16 | #define SYSFS_DISPLAY_MODE "/sys/class/display/mode" |
17 | #define SYSFS_DISPLAY1_MODE "/sys/class/display/mode" |
18 | #define SYSFS_DISPLAY2_MODE "/sys/class/display2/mode" |
19 | #define SYSFS_FB0_FREE_SCALE "/sys/class/graphics/fb0/free_scale" |
20 | #define SYSFS_FB1_FREE_SCALE "/sys/class/graphics/fb1/free_scale" |
21 | #define SYSFS_VIDEO_AXIS "/sys/class/video/axis" |
22 | #define SYSFS_VIDEOBUFUSED "/sys/class/amstream/videobufused" |
23 | #define SYSFS_WINDOW_AXIS "/sys/class/graphics/fb0/window_axis" |
24 | |
25 | namespace android { |
26 | namespace amlogic { |
27 | |
28 | class Utils { |
29 | public: |
30 | Utils(); |
31 | ~Utils(); |
32 | |
33 | static int get_int_prop(const char* prop); |
34 | static bool get_bool_prop(const char* prop); |
35 | |
36 | static int getSysfsInt(const char* syspath, int def); |
37 | static int getSysfsStr(const char* syspath, char *valstr, int size, |
38 | bool needOriginalData = false); |
39 | static int setSysfsStr(const char *path, const char *val); |
40 | |
41 | static bool checkBoolProp(const char* prop); |
42 | static int32_t checkIntProp(const char* prop); |
43 | static int32_t checkAndDupFd(int32_t fd); |
44 | static inline void closeFd(int32_t fd) { |
45 | if (fd > -1) close(fd); |
46 | } |
47 | #if WITH_LIBPLAYER_MODULE |
48 | static bool checkSysfsStatus(const char* sysfstr, char* lastr, int32_t size); |
49 | #endif |
50 | static bool checkOutputMode(char* curmode, int32_t* rate); |
51 | static bool checkVinfo(framebuffer_info_t *fbinfo); |
52 | |
53 | static const char* getHotplugUeventEnvelope(); |
54 | static const char* getHdcpUeventEnvelope(); |
55 | static const char* getSwitchState0(); |
56 | static const char* getSwitchState1(); |
57 | |
58 | template <typename T, typename S> |
59 | static inline bool compareRect(T a, S b) { |
60 | if ((int32_t)a.left == (int32_t)b.left |
61 | && (int32_t)a.top == (int32_t)b.top |
62 | && (int32_t)a.right == (int32_t)b.right |
63 | && (int32_t)a.bottom == (int32_t)b.bottom) { |
64 | return true; |
65 | } |
66 | return false; |
67 | } |
68 | template <typename T, typename S> |
69 | static inline bool compareSize(T a, S b) { |
70 | if ((int32_t)(a.right-a.left) == (int32_t)(b.right-b.left) |
71 | && (int32_t)(a.bottom-a.top) == (int32_t)(b.bottom-b.top)) { |
72 | return true; |
73 | } |
74 | return false; |
75 | } |
76 | template<typename T> |
77 | inline static T abs(const T& value) { |
78 | return value < 0 ? - value : value; |
79 | } |
80 | template <typename T> |
81 | static inline T min(T a, T b) { |
82 | return a<b ? a : b; |
83 | } |
84 | template <typename T> |
85 | static inline T max(T a, T b) { |
86 | return a>b ? a : b; |
87 | } |
88 | template <typename T> |
89 | static inline void swap(T& a, T& b) { |
90 | T t = a; |
91 | a = b; |
92 | b = t; |
93 | } |
94 | |
95 | }; |
96 | |
97 | } // namespace amlogic |
98 | } // namespace android |
99 | #endif /* UTILS_H_ */ |
100 |