/* * Copyright (c) Hisilicon Technologies Co., Ltd.. 2019-2022. All rights reserved. * Description: Support hwdisplay hal adaptation interface * Author: Hisilicon * Created: 2022-12-28 */ #ifndef DISPLAY_IMPL_H #define DISPLAY_IMPL_H #include "td_type.h" #include "uapi_svr_dispmng.h" #include "uapi_pdm.h" #include "uapi_win.h" #include "uapi_hdmitx.h" #include "securec.h" #include #include namespace android { using LocalAtomicPfn = td_s32 (*)(const android::Parcel &request, android::Parcel &reply); using DispmngEventCallback = void (*)(uapi_svr_dispmng_event event, void *msg, unsigned int msglen, void *privdata); const td_s32 UI_MAX = 100; const td_s32 UI_MIN = 0; enum class DispHdcpMode { MW_DISP_HDCP_MODE_AUTO, /* HDCP auto mode */ MW_DISP_HDCP_MODE_14, /* force to HDCP1.4 */ MW_DISP_HDCP_MODE_2X, /* force to HDCP2.x */ MW_DISP_HDCP_MODE_MAX }; using DispHdcpCapability = struct { td_bool support14; /* sink support HDCP1.4 */ td_bool support2x; /* sink support HDCP2.x */ }; using DispHdcpStatus = struct { td_bool authStart; /* HDCP authentication start. */ td_bool authSuccess; /* HDCP authentication success. */ td_u32 reauthTimes; /* HDCP current re-authen times. */ td_u32 mode; /* HDCP authentication mode. */ td_u32 errCode; /* HDCP error code. */ }; using DispOutputStatus = struct { td_u32 actualOutHdrType; /* output hdr type */ td_u32 actualOutColorpace; /* output colorspace */ td_u32 refreshRate; /* output real-time refresh rate */ }; using DispHdmitxStatus = struct { td_u32 hdmitxId; td_u32 connStatus; /* the hdmi sink connect status */ td_u32 rsenStatus; /* HDMITX TMDS link rsen status */ td_bool enabled; /* HDMITX signal output enable status */ }; using DispCvbsStatus = struct { td_u8 dac; td_bool connected; /* TV connected */ td_bool cgms; /* CGMS enable */ td_u32 macrovision; /* Macrovision enable */ }; using DispPanelStatus = struct { td_u32 panelId; td_bool powerOn; td_bool dynamicBacklightEnabled; td_u32 backlightLevel; td_bool abnormal; }; enum class DispIntfType { DISPMNG_INTERFACE_HDMITX = 0, DISPMNG_INTERFACE_CVBS = 0x0A, DISPMNG_INTERFACE_PANEL = 0x16, DISPMNG_INTERFACE_MAX }; using DispInterfaceStatus = struct { DispIntfType intfType; /* interface type */ union { DispCvbsStatus cvbs; DispHdmitxStatus hdmi; DispPanelStatus panel; } intf; }; const td_u32 DISP_INTERFACE_NUM = 8; using DisplayStatus = struct { td_u32 number; DispInterfaceStatus intf[DISP_INTERFACE_NUM]; }; const td_u32 MANUFACTURERS_NAME_LENGTH = 4; using DispSinkInfo = struct { td_u8 mfrsName[MANUFACTURERS_NAME_LENGTH]; /* Manufacture name */ /* CNcomment: 制造商名 */ td_u32 productCode; /* Product code */ /* CNcomment: 产品编码 */ td_u32 serialNumber; /* Serial number of manufacture */ /* CNcomment: 序列号 */ td_u32 week; /* the week of manufacture */ /* CNcomment: 生产年 */ td_u32 year; /* the year of manufacture */ /* CNcomment: 生产周 */ }; const td_u32 DISP_COLORIMETRY_MAX = 9; using DispColorimetryCapability = struct { td_bool colorimetry[DISP_COLORIMETRY_MAX]; }; using DispDolbyCapsV0 = struct { td_bool yuv42212bit; /* support(TD_TRUE) or not support(TD_FALSE) a YUV422-12Bit dolby singal */ td_bool support2160p60; /* capable of processing a max timming 3840X2160p60(TD_TRUE)/3840X2160p30(TD_FALSE) */ td_bool globalDimming; /* support(TD_TRUE) or not support(TD_FALSE) global dimming. */ td_u16 whiteX; /* white point chromaticity coordinate x, bit[11:0] valid. */ td_u16 whiteY; /* white point chromaticity coordinate y, bit[11:0] valid. */ td_u8 dmMajorVersion; /* the major version of display management implemented. */ td_u8 dmMinorVersion; /* the minor version of display management implemented. */ td_u16 minPq; /* Perceptual quantization(PQ)-encoded value of minimum display luminance */ td_u16 maxPq; /* PQ-encoded value of maximum display luminance */ td_u16 redX; /* red primary chromaticity coordinate x, bit[11:0]valid. */ td_u16 redY; /* red primary chromaticity coordinate y, bit[11:0]valid. */ td_u16 greenX; /* green primary chromaticity coordinate x, bit[11:0]valid. */ td_u16 greenY; /* green primary chromaticity coordinate y, bit[11:0]valid. */ td_u16 blueX; /* blue primary chromaticity coordinate x, bit[11:0]valid. */ td_u16 blueY; /* blue primary chromaticity coordinate y, bit[11:0]valid. */ }; using DispDolbyCapsV1 = struct { td_bool yuv42212bit; /* support or not YUV422-12Bit dolby singal; For low-latency this flag is ingnored */ td_bool support2160p60; /* capable of processing a max timming 3840X2160p60/3840X2160p30 */ td_bool globalDimming; /* support(TD_TRUE) or not support(TD_FALSE) global dimming. */ td_bool colorimetry; /* this bit is valid only u8VSVDBVersion = 1. 0: Dolby Vision HDMI sink's colorimetry is close to Rec.709, 1: EDR HDMI sink's colorimetry is close to P3, if Byte[9] to Byte[14] are present, ignores this bit. */ td_u8 dmVersion; /* 0:based on display management v2.x; 1:based on the video and blending pipeline v3.x; 2-7: reserved. only support when u8VSVDBVersion = 1. */ td_u8 lowLatency; /* 0: Supports only standard DolbyVison; 1: Supports low latency with 12-bit YUV 4:2:2 interface; 2-3:reserved */ td_u16 minLuminance; /* minimum display luminance = (100+50*CV)cd/m2, where CV is the value */ td_u16 maxLuminance; /* maximum display luminance = (CV/127)^2cd/m2, where CV is the value */ td_u16 redX; /* red primary chromaticity coordinate x, bit[11:0]valid. */ td_u16 redY; /* red primary chromaticity coordinate y, bit[11:0]valid. */ td_u16 greenX; /* green primary chromaticity coordinate x, bit[11:0]valid. */ td_u16 greenY; /* green primary chromaticity coordinate y, bit[11:0]valid. */ td_u16 blueX; /* blue primary chromaticity coordinate x, bit[11:0]valid. */ td_u16 blueY; /* blue primary chromaticity coordinate y, bit[11:0]valid. */ }; using DispDolbyCapsV2 = struct { td_bool yuv42212bit; /* support(TD_TRUE) or not support(TD_FALSE) a YUV422-12Bit dolby singal */ td_bool backLightContol; /* supports Backlight Control */ td_bool globalDimming; /* support(TD_TRUE) or not support(TD_FALSE) global dimming. */ td_u8 dmVersion; /* 0:based on display management v2.x; 1:based on the video and blending pipeline v3.x; 2-7: reserved. only support when u8VSVDBVersion = 1. */ td_u8 backltMinLuma; /* minimum luminance level 0:25cd/m2 1:50cd/m2 2:75cd/m2 3:100cd/m2 */ td_u8 interface; /* 0:support only "low latency with YUV422" 1:support both "low latency with YUV422" and YUV444/RGB_10/12bit* 2:support both "standard DolbyVision" and "low latency with YUV422" 3:support "standard DolbyVision" "low latency YUV422 YUV444/RGB_10/12bit" */ td_u8 yuv444Rgb44410b12b; /* 0:not support 1:Support YUV444/RGB444_10bit 2:YUV444/RGB444_12bit 3:reserved */ td_u16 minPqV2; /* maximum display luminance */ td_u16 maxPqV2; /* minimum display luminance, in the PQ-encoded value= 2055+u16TargetMaxPQv2*65. */ td_u16 redX; /* red primary chromaticity coordinate x ,bit[11:0]valid. */ td_u16 redY; /* red primary chromaticity coordinate y ,bit[11:0]valid. */ td_u16 greenX; /* green primary chromaticity coordinate x ,bit[11:0]valid. */ td_u16 greenY; /* green primary chromaticity coordinate y ,bit[11:0]valid. */ td_u16 blueX; /* blue primary chromaticity coordinate x ,bit[11:0]valid. */ td_u16 blueY; /* blue primary chromaticity coordinate y ,bit[11:0]valid. */ }; using DispDolbyCapability = struct { td_bool supportV0; /* V0 support */ /* CNcomment: V0支持 */ td_bool supportV1; /* V1 support */ /* CNcomment: V1支持 */ td_bool supportV2; /* V2 support */ /* CNcomment: V2支持 */ DispDolbyCapsV0 v0; /* V0 detail */ /* CNcomment: V0详细能力 */ DispDolbyCapsV1 v1; /* V1 detail */ /* CNcomment: V1详细能力 */ DispDolbyCapsV2 v2; /* V2 detail */ /* CNcomment: V2详细能力 */ }; using DispEotfCapabiliey = struct { td_bool eotfSdr; /* CNcomment: 传统伽玛-SDR亮度范围 */ td_bool eotfHdr; /* CNcomment: 传统伽玛-HDR亮度范围 */ td_bool eotfSmpteSt2084; /* CNcomment: HDMT HDR的HDR10模式 */ td_bool eotfHlg; /* CNcomment: HDMT HDR的HLG模式(混合对数伽玛) */ }; using DispDynamicMetadataCapability = struct { td_bool dynamicType1Support; /* CNcomment: type1动态元数据支持 */ td_u8 dynamicType1Version; /* CNcomment: type1动态元数据版本 */ td_bool dynamicType2Support; /* CNcomment: type2动态元数据支持 */ td_u8 dynamicType2Version; /* CNcomment: type2动态元数据版本 */ td_bool dynamicType3Support; /* CNcomment: type3动态元数据支持 */ td_bool dynamicType4Support; /* CNcomment: type4动态元数据支持 */ td_u8 dynamicType4Version; /* CNcomment: type4动态元数据版本 */ }; using DispStaticMetadataCapability = struct { td_bool staticType1; /* Static Metadata Type 1 support */ td_u8 maxLumCv; /* Desired Content Max Luminance Data. Real value(in 1cd/m^2) = 50.2^(CV/32) */ td_u8 averLumCv; /* Desired Content Max Frame-average Luminance. Real value(in 1cd/m^2) = 50.2^(CV/32) */ td_u8 minLumCv; /* Desired Content Min Luminance Data. Real value(in 1cd/m^2) = MaxLuminance_CV * * (MinLuminance_CV/255)^2 / 100 */ }; using DispHdrCapability = struct { DispEotfCapabiliey eotf; /* CNcomment:电光转换函数 */ DispStaticMetadataCapability staticMetadata; /* HDR Static Metadata Type */ DispDynamicMetadataCapability dynamicMetadata; /* HDR Dynamic Metadata Type */ }; using DispLatency = struct { td_bool latencyPresent; /* Latency info is valid. */ td_u32 pvideoLatency; /* video latency for progressive video formats.in milliseconds */ td_u32 paudioLatency; /* audio latency for progressive video formats.in milliseconds */ td_u32 ivideoLatency; /* video latency for interlaced video formats.in milliseconds */ td_u32 iaudioLatency; /* audio latency for interlaced video formats.in milliseconds */ }; using DispVrrCapability = struct { td_bool support; td_bool fva; /* FVA */ td_bool cnmVrr; /* CNMVRR */ td_bool cinemaVrr; /* CinemaVRR */ td_bool mDelta; /* MDelta */ td_bool fapaStartLocat; /* fapaStartLocation */ td_bool allm; /* ALLM */ td_u16 vrrMin; /* VRRMin */ td_u16 vrrMax; /* VRRMax */ }; using DispCuvaInfo = struct { td_u8 systemStartCode; /* support version code. */ td_u8 versionCode; /* support HDMI version code. */ td_u32 displayMaxLum; /* display maximum luminance. max display is displayMaxLum/10000. */ td_u32 displayMinLum; /* display minimum luminance. min display is displayMinLum/10000. */ td_bool monitorModeSupport; /* monitor mode support. */ td_bool rxModeSupport; /* rx mode support. */ }; using DisplayCapability = struct { DispColorimetryCapability colorimetry; /* Sink colorimety capability infomation struct */ DispDolbyCapability dolbyVision; /* EDID dolby vision capability */ DispHdrCapability hdr; /* Sink HDR capability struct */ DispLatency latency; /* EDID latency capability */ DispVrrCapability vrr; /* Sink VRR capability */ td_u8 reserved; DispCuvaInfo cuva; /* Sink CUVA capability */ }; const td_u32 MAX_DISPLAY_MODE_NAME_LENGTH = 32; using DisplayMode = struct { td_u32 vic; /* 0----auto detect, 0xFFFF --- Advance option */ td_u32 format; /* Display format, refer to UAPI_ENC_FMT_E in uapi_svr_video.h. when vic==0xFFFF, the display manager use this field to set the display out mode */ td_u32 pixelFormat; /* Pixel format, such as RGB,YCbCr422,YCbCr444,YCbCr420 */ td_u32 bitDepth; /* Pixel bit depth, 8bits/10bits/12bits */ td_u8 name[MAX_DISPLAY_MODE_NAME_LENGTH]; /* Display mode name, such as "1080P60Hz", "1080I50Hz" */ td_u32 width; /* width, 8K-----7680 */ td_u32 height; /* height, 8K-----4320 */ td_bool progressive; /* progressive or not */ td_u32 fieldRate; /* field/frame rate, Hz */ }; const td_u32 MAX_DISPLAY_MODE_NUM = 70; using DisplayAvailableMode = struct { DisplayMode nativeMode; DisplayMode maxMode; td_u32 number; DisplayMode mode[MAX_DISPLAY_MODE_NUM]; }; using VideoAspectInfo = struct { td_u32 ratio; td_u32 width; td_u32 height; }; using DispHdcpKey = struct { td_u32 keyVersion; /* KEY version */ td_u8 *data; /* Pointer of key data */ td_s32 length; /* Length of key data, in bytes */ }; using DispHdcpSrm = struct { td_u8 *data; /* Pointer of SRM data */ td_s32 length; /* Length of SRM data, in bytes */ }; using HdmiConfigInfo = struct { td_u32 hdcpEnable; /* CNcomment:HDCP功能是否使能 */ td_u32 hdcpMode; /* CNcoment:选择模式 0为AUTO, 1为HDCP 1.4, 2为HDCP 2.x */ td_u32 cecEnable; /* CNcomment:是否使能CEC功能 */ td_u32 cecMode; /* CNcomment:cec模式选择 */ }; using DisplayConfig = struct { td_u32 index; /* display index, 0 is master disp */ td_bool enable; /* Enable or not */ td_bool attach; /* Attached to another display or not */ td_u32 srcDisp; /* display id which attached to */ td_u32 rType; /* Rotation type */ td_u32 rAngle; /* Rotation angle */ td_bool hFlip; /* Horizontal flip */ td_bool vFlip; /* Vertical flip */ td_u32 touchId; /* Touchpad ID */ td_u32 panelIndex; /* Panel index */ }; struct CROP_RECT_S { td_u32 u32LeftOffset; td_u32 u32TopOffset; td_u32 u32RightOffset; td_u32 u32BottomOffset; }; /* 3D 视点、景深 调整范围 */ struct DISPLAY_RANGE_S { td_u32 min; /* 下限 */ td_u32 max; /* 上限 */ }; #define UAPI_EVENT_TYPE(MOD, EVTTYPE) ((((td_s32)(MOD)) << 16) | (td_s32)(EVTTYPE)) const td_s32 DISPLAY_ENUM = 0x09; enum class TV_EVENT_E { TV_EVT_DISP_MODE_ALL = UAPI_EVENT_TYPE(DISPLAY_ENUM, 1), TV_EVT_DISP_HDCP_SUCCESS, TV_EVT_DISP_HDCP_FAIL, TV_EVT_DISP_MODE_CHANGED, TV_EVT_DISP_MODE_PLUG_IN, TV_EVT_DISP_MODE_PLUG_OUT, }; class DisplayImpl { public: static DisplayImpl *Instance(); static td_void DeInstance(); td_s32 GetDispmngCount(td_s32 &count) const; td_s32 GetDispmngDispid(td_s32 index, td_s32 &dispid) const; td_s32 DispmngAttachDispid(td_s32 dstid, td_s32 srcid) const; td_s32 DispmngDetachDispid(td_s32 dstid, td_s32 srcid) const; td_s32 SetBrightness(td_s32 dispid, td_u32 brightness) const; td_s32 GetBrightness(td_s32 dispid, td_u32 &brightness) const; td_s32 GetContrast(td_s32 dispid, td_u32 &contrast) const; td_s32 SetContrast(td_s32 dispid, td_u32 contrast) const; td_s32 GetHue(td_s32 dispid, td_u32 &hue) const; td_s32 SetHue(td_s32 dispid, td_u32 hue) const; td_s32 GetSaturation(td_s32 dispid, td_u32 &saturation) const; td_s32 SetSaturation(td_s32 dispid, td_u32 saturation) const; td_s32 GetBacklight(td_s32 dispid, td_u32 &backlight) const; td_s32 SetBacklight(td_s32 dispid, td_u32 backlight) const; td_s32 GetScreenOffset(td_s32 dispid, CROP_RECT_S& offset) const; td_s32 SetScreenOffset(td_s32 dispid, CROP_RECT_S offset) const; td_s32 SetEnableHdcp(td_s32 dispid, DispHdcpMode mode) const; td_s32 SetDisableHdcp(td_s32 dispid) const; td_s32 GetHdcpCapability(td_s32 dispid, DispHdcpCapability &cap) const; td_s32 GetHdcpStatus(td_s32 dispid, DispHdcpStatus &status) const; td_s32 GetHdrType(td_s32 dispid, td_s32 &hdrType) const; td_s32 SetHdrType(td_s32 dispid, td_s32 hdrType) const; td_s32 GetVirtualScreenhw(td_s32 dispid, td_u32 &width, td_u32 &height) const; td_s32 SetVirtualScreenhw(td_s32 dispid, td_u32 width, td_u32 height) const; td_s32 GetQmsEnable(td_s32 dispid, td_bool& enable) const; td_s32 SetQmsEnable(td_s32 dispid, td_bool enable) const; td_s32 GetQmsAttr(td_s32 dispid, td_u32& qmsRate) const; td_s32 SetQmsAttr(td_s32 dispid, td_u32 qmsRate) const; td_s32 GetVrrEnable(td_s32 dispid, td_bool &enable) const; td_s32 SetVrrEnable(td_s32 dispid, td_bool enable) const; td_s32 GetAllmAttr(td_s32 dispid, td_u32 &allmMode) const; td_s32 SetAllmAttr(td_s32 dispid, td_u32 allmMode) const; td_s32 GetOutputStatus(td_s32 dispid, DispOutputStatus &status) const; td_s32 GetDisplayStatus(td_s32 dispid, DisplayStatus &status) const; td_s32 GetDisplayInfo(td_s32 dispid, DispSinkInfo &info) const; td_s32 GetDisplayCapabilities(td_s32 dispid, DisplayCapability &cap) const; td_s32 GetDisplaySupportedModeList(td_s32 dispid, DisplayAvailableMode &mode) const; td_s32 GetDisplayAllModeList(td_s32 dispid, DisplayAvailableMode &mode) const; td_s32 GetDisplayMode(td_s32 dispid, DisplayMode &mode) const; td_s32 SetDisplayMode(td_s32 dispid, DisplayMode mode) const; td_s32 GetSceneMode(td_s32 dispid, td_s32 &sceneMode) const; td_s32 SetSceneMode(td_s32 dispid, td_s32 mode) const; td_s32 GetAspectRatio(td_s32 dispid, VideoAspectInfo &aspectInfo) const; td_s32 SetAspectRatio(td_s32 dispid, VideoAspectInfo aspectInfo) const; td_s32 GetHdrMatchContent(td_s32 dispid, td_bool &match) const; td_s32 SetHdrMatchContent(td_s32 dispid, td_bool match) const; td_s32 LoadHDCPKey(td_s32 dispid, DispHdcpKey key) const; td_s32 LoadHDCPSrm(td_s32 dispid, DispHdcpSrm srm) const; td_s32 GetHdmiConfigInfo(td_s32 hdmitx, HdmiConfigInfo &info) const; td_s32 SetHdmiConfigInfo(td_s32 hdmitx, HdmiConfigInfo info) const; td_s32 GetHdmitxidByDispid(td_s32 dispid, td_u32 &hdmitx) const; td_s32 GetDisplayConfig(td_s32 dispid, DisplayConfig &info) const; td_s32 SetDisplayConfig(td_s32 dispid, DisplayConfig info) const; td_s32 SetHdmiConfig() const; td_s32 GetVrrAttr(td_s32 dispid, DISPLAY_RANGE_S &range) const; td_s32 SetVrrAttr(td_s32 dispid, DISPLAY_RANGE_S range) const; td_s32 SetPQBypass(td_s32 enable) const; td_s32 GetPQBypass(td_u32 &enable) const; td_s32 SetAspectCvrs(int cvrs) const; td_s32 GetAspectCvrs() const; td_s32 SetHdmiStart(td_s32 dispid) const; td_s32 SetHdmiStop(td_s32 dispid) const; td_s32 SetEnable3D(td_s32 dispid, td_bool enable) const; td_s32 GetEnable3D(td_s32 dispid, td_bool &enable) const; td_s32 AttachIntf(int dispid) const; td_s32 DetachIntf(int dispid) const; td_s32 GetDisplayWindowNumber(int dispid, uapi_win_handle_info *handleInfo) const; td_s32 GetFmtFromVic(int vic) const; td_s32 GetVicFromFmt(int fmt) const; td_s32 SetOutputEnable(int dispid, int port, td_bool enable) const; td_s32 GetOutputEnable(int dispid, int port) const; td_s32 GetDisplayLuminance(int dispid, uapi_svr_dispmng_display_luminance& luminance) const; td_s32 SetDisplayLuminance(int dispid, uapi_svr_dispmng_display_luminance& luminance) const; td_s32 SetDisplayCount() const; td_s32 SetCuvaConfig() const; DisplayImpl(); virtual ~DisplayImpl(); private: static DisplayImpl *mDisplayImpl; static android::Mutex mLockInstance; }; inline DisplayImpl *DisplayImpl::Instance() { android::Mutex::Autolock lock(mLockInstance); if (mDisplayImpl == nullptr) { mDisplayImpl = new DisplayImpl(); } return mDisplayImpl; } inline td_void DisplayImpl::DeInstance() { if (mDisplayImpl != nullptr) { delete mDisplayImpl; mDisplayImpl = nullptr; } } inline DisplayImpl::DisplayImpl() {} inline DisplayImpl::~DisplayImpl() {} } #endif // _DISPLAY_IMPL_H__