blob: 785b40b41c3e42355c144ccf63b924b339c369c9
1 | #ifndef AML_DISPLAY_HDMI_H |
2 | #define AML_DISPLAY_HDMI_H |
3 | |
4 | #include <gralloc_priv.h> |
5 | #include <utils/String8.h> |
6 | #include <sys/ioctl.h> |
7 | #include <sys/mman.h> |
8 | #include <sys/time.h> |
9 | #include <sys/types.h> |
10 | #include <sys/resource.h> |
11 | #include <linux/fb.h> |
12 | #include <string> |
13 | #include <vector> |
14 | |
15 | #include <hardware/hardware.h> |
16 | #include <hardware/hwcomposer.h> |
17 | #include <Hwcomposer.h> |
18 | #include <SoftVsyncObserver.h> |
19 | #include <Utils.h> |
20 | #include <ISystemControlService.h> |
21 | #include <gui/SurfaceComposerClient.h> |
22 | |
23 | #include <vendor/amlogic/hardware/systemcontrol/1.0/ISystemControl.h> |
24 | |
25 | #define HWC_DISPLAY_MODE_LENGTH 32 |
26 | |
27 | using ::vendor::amlogic::hardware::systemcontrol::V1_0::ISystemControl; |
28 | using ::vendor::amlogic::hardware::systemcontrol::V1_0::Result; |
29 | using ::android::hardware::hidl_vec; |
30 | using ::android::hardware::hidl_string; |
31 | using ::android::hardware::Return; |
32 | |
33 | namespace android { |
34 | namespace amlogic { |
35 | |
36 | // display config |
37 | class DisplayConfig { |
38 | public: |
39 | DisplayConfig(const char* dm, |
40 | int rr, |
41 | int w = 0, |
42 | int h = 0, |
43 | int dpix = 0, |
44 | int dpiy = 0) |
45 | : mRefreshRate(rr), |
46 | mWidth(w), |
47 | mHeight(h), |
48 | mDpiX(dpix), |
49 | mDpiY(dpiy) |
50 | { |
51 | memset(mDisplayMode, 0, HWC_DISPLAY_MODE_LENGTH); |
52 | int length = strlen(dm); |
53 | length = (length <= HWC_DISPLAY_MODE_LENGTH-1)?length:(HWC_DISPLAY_MODE_LENGTH-1); |
54 | memcpy(mDisplayMode, dm, length); |
55 | } |
56 | public: |
57 | char* getDisplayMode() const { return (char*)(&mDisplayMode[0]); }; |
58 | int getRefreshRate() const { return mRefreshRate; }; |
59 | int getWidth() const { return mWidth; }; |
60 | int getHeight() const { return mHeight; }; |
61 | int getDpiX() const { return mDpiX; }; |
62 | int getDpiY() const { return mDpiY; }; |
63 | void setDpi(int dpix, int dpiy) { |
64 | mDpiX = dpix; |
65 | mDpiY = dpiy; |
66 | }; |
67 | |
68 | private: |
69 | char mDisplayMode[HWC_DISPLAY_MODE_LENGTH]; |
70 | int mRefreshRate; |
71 | int mWidth; |
72 | int mHeight; |
73 | int mDpiX; |
74 | int mDpiY; |
75 | }; |
76 | |
77 | class DisplayHdmi { |
78 | public: |
79 | DisplayHdmi(hwc2_display_t id); |
80 | ~DisplayHdmi(); |
81 | |
82 | void initialize(); |
83 | void deinitialize(); |
84 | void reset(); |
85 | bool updateHotplug(bool connected, framebuffer_info_t * framebufferInfo, |
86 | private_handle_t* framebufferHnd); |
87 | int updateDisplayModeList(); |
88 | int updateActiveDisplayMode(); |
89 | int setDisplayMode(const char* displaymode); |
90 | int updateDisplayConfigures(); |
91 | int updateActiveDisplayConfigure(); |
92 | |
93 | int getDisplayConfigs(uint32_t* outNumConfigs, hwc2_config_t* outConfigs); |
94 | int getDisplayAttribute(hwc2_config_t config, int32_t attribute, int32_t* outValue); |
95 | int getActiveConfig(hwc2_config_t* outConfig); |
96 | int setActiveConfig(int id); |
97 | //int setPowerMode(int power) {return 0;}; |
98 | |
99 | inline bool isConnected() {return mConnected;}; |
100 | int getActiveRefreshRate() {return mActiveRefreshRate;}; |
101 | bool calcMode2Config(const char *dispMode, int* refreshRate, int* width, int* height); |
102 | bool readConfigFile(const char* configPath, std::vector<std::string>* supportDispModes); |
103 | void setSurfaceFlingerActiveMode(); |
104 | void initModes(); |
105 | |
106 | void dump(Dump& d); |
107 | |
108 | private: |
109 | void initBinderService(); |
110 | struct SystemControlDeathRecipient : public android::hardware::hidl_death_recipient |
111 | { |
112 | // hidl_death_recipient interface |
113 | virtual void serviceDied(uint64_t cookie, |
114 | const ::android::wp<::android::hidl::base::V1_0::IBase>& who) override; |
115 | }; |
116 | |
117 | hwc2_display_t mDisplayId; //0-primary 1-external |
118 | bool mConnected; |
119 | bool mTrebleSystemControlEnable; |
120 | sp<ISystemControlService> mSystemControlService; |
121 | sp<ISystemControl> mTrebleSystemControl; |
122 | sp<SystemControlDeathRecipient> mDeathRecipient = nullptr; |
123 | sp<SurfaceComposerClient> mComposerClient; |
124 | |
125 | //display outputmode as 4k20hz, 1080p60hz, panel. etc. |
126 | std::vector<std::string> mAllModes; |
127 | std::vector<std::string> mSupportDispModes; |
128 | char mActiveDisplaymode[HWC_DISPLAY_MODE_LENGTH]; |
129 | int mActiveRefreshRate; |
130 | |
131 | std::vector<DisplayConfig*> mDisplayConfigs; |
132 | hwc2_config_t mActiveDisplayConfigItem; |
133 | |
134 | framebuffer_info_t *mFramebufferInfo; |
135 | private_handle_t *mFramebufferHnd; |
136 | }; |
137 | |
138 | } // namespace amlogic |
139 | } // namespace android |
140 | |
141 | #endif |
142 |