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