2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 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/
35 // for dlsym and friends
36 #if defined(__WINDOWS__)
37 #include "../windows/dlfcn-win32.h"
40 using namespace PLATFORM
;
42 CADLEdidParser::CADLEdidParser(void) :
49 CADLEdidParser::~CADLEdidParser(void)
54 bool CADLEdidParser::OpenLibrary(void)
58 #if !defined(__WINDOWS__)
59 m_handle
= dlopen("libatiadlxx.so", RTLD_LAZY
|RTLD_GLOBAL
);
61 m_handle
= LoadLibrary("atiadlxx.dll");
64 m_handle
= LoadLibrary("atiadlxy.dll");
67 return m_handle
!= NULL
;
70 void CADLEdidParser::CloseLibrary(void)
73 ADL_Main_Control_Destroy();
80 void *__stdcall
ADL_AllocMemory(int iSize
)
82 void* lpBuffer
= malloc(iSize
);
86 void CADLEdidParser::Initialise(void)
90 // dlsym the methods we need
91 ADL_Main_Control_Create
= (ADL_MAIN_CONTROL_CREATE
) dlsym(m_handle
, "ADL_Main_Control_Create");
92 ADL_Main_Control_Destroy
= (ADL_MAIN_CONTROL_DESTROY
) dlsym(m_handle
, "ADL_Main_Control_Destroy");
93 ADL_Adapter_NumberOfAdapters_Get
= (ADL_ADAPTER_NUMBEROFADAPTERS_GET
) dlsym(m_handle
, "ADL_Adapter_NumberOfAdapters_Get");
94 ADL_Adapter_AdapterInfo_Get
= (ADL_ADAPTER_ADAPTERINFO_GET
) dlsym(m_handle
, "ADL_Adapter_AdapterInfo_Get");
95 ADL_Display_DisplayInfo_Get
= (ADL_DISPLAY_DISPLAYINFO_GET
) dlsym(m_handle
, "ADL_Display_DisplayInfo_Get");
96 ADL_Display_EdidData_Get
= (ADL_DISPLAY_EDIDDATA_GET
) dlsym(m_handle
, "ADL_Display_EdidData_Get");
98 // check whether they could all be resolved
99 if (ADL_Main_Control_Create
&&
100 ADL_Main_Control_Destroy
&&
101 ADL_Adapter_NumberOfAdapters_Get
&&
102 ADL_Adapter_AdapterInfo_Get
&&
103 ADL_Display_DisplayInfo_Get
&&
104 ADL_Display_EdidData_Get
)
106 // and try to initialise it
107 m_bOpen
= (ADL_OK
== ADL_Main_Control_Create(ADL_AllocMemory
, 1));
112 int CADLEdidParser::GetNumAdapters(void)
116 if (!LibOpen() || ADL_OK
!= ADL_Adapter_NumberOfAdapters_Get(&iNumAdapters
))
122 LPAdapterInfo
CADLEdidParser::GetAdapterInfo(int iNumAdapters
)
125 if (iNumAdapters
<= 0)
128 LPAdapterInfo adapterInfo
= (LPAdapterInfo
)malloc(sizeof(AdapterInfo
) * iNumAdapters
);
129 memset(adapterInfo
, 0, sizeof(AdapterInfo
) * iNumAdapters
);
132 ADL_Adapter_AdapterInfo_Get(adapterInfo
, sizeof(AdapterInfo
) * iNumAdapters
);
137 bool CADLEdidParser::GetAdapterEDID(int iAdapterIndex
, int iDisplayIndex
, ADLDisplayEDIDData
*data
)
140 if (iAdapterIndex
< 0 || iDisplayIndex
< 0)
143 memset(data
, 0, sizeof(ADLDisplayEDIDData
));
144 data
->iSize
= sizeof(ADLDisplayEDIDData
);
145 data
->iBlockIndex
= 1;
147 return (ADL_Display_EdidData_Get(iAdapterIndex
, iDisplayIndex
, data
) == ADL_OK
);
150 uint16_t CADLEdidParser::GetPhysicalAddress(void)
154 // get the number of adapters
155 int iNumAdapters
= GetNumAdapters();
156 if (iNumAdapters
<= 0)
159 // get the adapter info
160 LPAdapterInfo adapterInfo
= GetAdapterInfo(iNumAdapters
);
165 for (int iAdapterPtr
= 0; iAdapterPtr
< iNumAdapters
; iAdapterPtr
++)
167 int iNumDisplays(-1);
168 LPADLDisplayInfo
displayInfo(NULL
);
169 int iAdapterIndex
= adapterInfo
[iAdapterPtr
].iAdapterIndex
;
171 // get the display info
172 if (ADL_OK
!= ADL_Display_DisplayInfo_Get(iAdapterIndex
, &iNumDisplays
, &displayInfo
, 0))
176 for (int iDisplayPtr
= 0; iDisplayPtr
< iNumDisplays
; iDisplayPtr
++)
178 // check whether the display is connected
179 if ((displayInfo
[iDisplayPtr
].iDisplayInfoValue
& ADL_DISPLAY_CONNECTED
) != ADL_DISPLAY_CONNECTED
)
182 int iDisplayIndex
= displayInfo
[iDisplayPtr
].displayID
.iDisplayLogicalIndex
;
184 // try to get the EDID
185 ADLDisplayEDIDData edidData
;
186 if (GetAdapterEDID(iAdapterIndex
, iDisplayIndex
, &edidData
))
188 // try to get the PA from the EDID
189 iPA
= CEDIDParser::GetPhysicalAddressFromEDID(edidData
.cEDIDData
, edidData
.iEDIDSize
);