1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  * Copyright (C) 2012, The Linux Foundation. All rights reserved.
4  *
5  * Not a Contribution, Apache license notifications and license are
6  * retained for attribution purposes only.
7 
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef HWC_EXTERNAL_DISPLAY_H
22 #define HWC_EXTERNAL_DISPLAY_H
23 
24 #include <utils/threads.h>
25 #include <linux/fb.h>
26 
27 struct hwc_context_t;
28 
29 namespace qhwc {
30 
31 //Type of scanning of EDID(Video Capability Data Block)
32 enum external_scansupport_type {
33     EXT_SCAN_NOT_SUPPORTED      = 0,
34     EXT_SCAN_ALWAYS_OVERSCANED  = 1,
35     EXT_SCAN_ALWAYS_UNDERSCANED = 2,
36     EXT_SCAN_BOTH_SUPPORTED     = 3
37 };
38 
39 class ExternalDisplay
40 {
41 public:
42     ExternalDisplay(hwc_context_t* ctx);
43     ~ExternalDisplay();
44     int getModeCount() const;
45     void getEDIDModes(int *out) const;
isCEUnderscanSupported()46     bool isCEUnderscanSupported() { return mUnderscanSupported; }
47     void setExternalDisplay(bool connected, int extFbNum = 0);
isExternalConnected()48     bool isExternalConnected() { return mConnected;};
setExtDpyNum(int extDpyNum)49     void  setExtDpyNum(int extDpyNum) { mExtDpyNum = extDpyNum;};
50     void setHPD(uint32_t startEnd);
51     void setEDIDMode(int resMode);
52     void setActionSafeDimension(int w, int h);
53     void processUEventOnline(const char *str);
54     void processUEventOffline(const char *str);
55 
56 private:
57     void readCEUnderscanInfo();
58     bool readResolution();
59     int  parseResolution(char* edidStr, int* edidModes);
60     void setResolution(int ID);
61     bool openFrameBuffer(int fbNum);
62     bool closeFrameBuffer();
63     bool writeHPDOption(int userOption) const;
64     bool isValidMode(int ID);
65     void handleUEvent(char* str, int len);
66     int  getModeOrder(int mode);
67     int  getUserMode();
68     int  getBestMode();
69     bool isInterlacedMode(int mode);
70     void resetInfo();
71     void setDpyHdmiAttr();
72     void setDpyWfdAttr();
73     void getAttrForMode(int& width, int& height, int& fps);
74     void updateExtDispDevFbIndex();
75     int  configureHDMIDisplay();
76     int  configureWFDDisplay();
77     int  teardownHDMIDisplay();
78     int  teardownWFDDisplay();
79     int  getExtFbNum(int &fbNum);
80 
81     mutable android::Mutex mExtDispLock;
82     int mFd;
83     int mCurrentMode;
84     int mConnected;
85     int mConnectedFbNum;
86     int mResolutionMode;
87     char mEDIDs[128];
88     int mEDIDModes[64];
89     int mModeCount;
90     bool mUnderscanSupported;
91     hwc_context_t *mHwcContext;
92     fb_var_screeninfo mVInfo;
93     int mHdmiFbNum;
94     int mWfdFbNum;
95     int mExtDpyNum;
96 };
97 
98 }; //qhwc
99 // ---------------------------------------------------------------------------
100 #endif //HWC_EXTERNAL_DISPLAY_H
101