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