2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
36 // for dlsym and friends
37 #if defined(__WINDOWS__)
38 #include "../windows/dlfcn-win32.h"
41 using namespace PLATFORM
;
43 CADLEdidParser::CADLEdidParser(void) :
50 CADLEdidParser::~CADLEdidParser(void)
55 bool CADLEdidParser::OpenLibrary(void)
59 #if !defined(__WINDOWS__)
60 m_handle
= dlopen("libatiadlxx.so", RTLD_LAZY
|RTLD_GLOBAL
);
62 m_handle
= LoadLibrary("atiadlxx.dll");
65 m_handle
= LoadLibrary("atiadlxy.dll");
68 return m_handle
!= NULL
;
71 void CADLEdidParser::CloseLibrary(void)
74 ADL_Main_Control_Destroy();
81 void *__stdcall
ADL_AllocMemory(int iSize
)
83 void* lpBuffer
= malloc(iSize
);
87 void CADLEdidParser::Initialise(void)
91 // dlsym the methods we need
92 ADL_Main_Control_Create
= (ADL_MAIN_CONTROL_CREATE
) dlsym(m_handle
, "ADL_Main_Control_Create");
93 ADL_Main_Control_Destroy
= (ADL_MAIN_CONTROL_DESTROY
) dlsym(m_handle
, "ADL_Main_Control_Destroy");
94 ADL_Adapter_NumberOfAdapters_Get
= (ADL_ADAPTER_NUMBEROFADAPTERS_GET
) dlsym(m_handle
, "ADL_Adapter_NumberOfAdapters_Get");
95 ADL_Adapter_AdapterInfo_Get
= (ADL_ADAPTER_ADAPTERINFO_GET
) dlsym(m_handle
, "ADL_Adapter_AdapterInfo_Get");
96 ADL_Display_DisplayInfo_Get
= (ADL_DISPLAY_DISPLAYINFO_GET
) dlsym(m_handle
, "ADL_Display_DisplayInfo_Get");
97 ADL_Display_EdidData_Get
= (ADL_DISPLAY_EDIDDATA_GET
) dlsym(m_handle
, "ADL_Display_EdidData_Get");
99 // check whether they could all be resolved
100 if (ADL_Main_Control_Create
&&
101 ADL_Main_Control_Destroy
&&
102 ADL_Adapter_NumberOfAdapters_Get
&&
103 ADL_Adapter_AdapterInfo_Get
&&
104 ADL_Display_DisplayInfo_Get
&&
105 ADL_Display_EdidData_Get
)
107 // and try to initialise it
108 m_bOpen
= (ADL_OK
== ADL_Main_Control_Create(ADL_AllocMemory
, 1));
113 int CADLEdidParser::GetNumAdapters(void)
117 if (!LibOpen() || ADL_OK
!= ADL_Adapter_NumberOfAdapters_Get(&iNumAdapters
))
123 LPAdapterInfo
CADLEdidParser::GetAdapterInfo(int iNumAdapters
)
126 if (iNumAdapters
<= 0)
129 LPAdapterInfo adapterInfo
= (LPAdapterInfo
)malloc(sizeof(AdapterInfo
) * iNumAdapters
);
130 memset(adapterInfo
, 0, sizeof(AdapterInfo
) * iNumAdapters
);
133 ADL_Adapter_AdapterInfo_Get(adapterInfo
, sizeof(AdapterInfo
) * iNumAdapters
);
138 bool CADLEdidParser::GetAdapterEDID(int iAdapterIndex
, int iDisplayIndex
, ADLDisplayEDIDData
*data
)
141 if (iAdapterIndex
< 0 || iDisplayIndex
< 0)
144 memset(data
, 0, sizeof(ADLDisplayEDIDData
));
145 data
->iSize
= sizeof(ADLDisplayEDIDData
);
146 data
->iBlockIndex
= 1;
148 return (ADL_Display_EdidData_Get(iAdapterIndex
, iDisplayIndex
, data
) == ADL_OK
);
151 uint16_t CADLEdidParser::GetPhysicalAddress(void)
155 // get the number of adapters
156 int iNumAdapters
= GetNumAdapters();
157 if (iNumAdapters
<= 0)
160 // get the adapter info
161 LPAdapterInfo adapterInfo
= GetAdapterInfo(iNumAdapters
);
166 for (int iAdapterPtr
= 0; iAdapterPtr
< iNumAdapters
; iAdapterPtr
++)
168 int iNumDisplays(-1);
169 LPADLDisplayInfo
displayInfo(NULL
);
170 int iAdapterIndex
= adapterInfo
[iAdapterPtr
].iAdapterIndex
;
172 // get the display info
173 if (ADL_OK
!= ADL_Display_DisplayInfo_Get(iAdapterIndex
, &iNumDisplays
, &displayInfo
, 0))
177 for (int iDisplayPtr
= 0; iDisplayPtr
< iNumDisplays
; iDisplayPtr
++)
179 // check whether the display is connected
180 if ((displayInfo
[iDisplayPtr
].iDisplayInfoValue
& ADL_DISPLAY_CONNECTED
) != ADL_DISPLAY_CONNECTED
)
183 int iDisplayIndex
= displayInfo
[iDisplayPtr
].displayID
.iDisplayLogicalIndex
;
185 // try to get the EDID
186 ADLDisplayEDIDData edidData
;
187 if (GetAdapterEDID(iAdapterIndex
, iDisplayIndex
, &edidData
))
189 // try to get the PA from the EDID
190 iPA
= CEDIDParser::GetPhysicalAddressFromEDID(edidData
.cEDIDData
, edidData
.iEDIDSize
);