Adl2/Adl2_Sample.cpp
This document describes the APIs (application programming interfaces) that can be used to access AMD-specific display driver functionality, such as those related to specific display devices.
Included in this document are definitions as well as the data structures used by each API.
Public functions are prefixed with "ADL_". The majority of the APIs are supported on 32-bit and 64-bit versions of Windows (XP and Vista) and Linux platforms.
Working code samples and snippets of the API source code files are also provided for reference purposes.
- Note:
- Although a number of header files are referenced in this document, only three are required and provoided with this SDK:
The three files should be placed in the same folder. A C/C++ Sample Application for Windows (XP, Vista and above); 32bit and 64bit
Visual Studio 2012 solution file "Adl2.sln" is included in ADL SDK
#if defined (LINUX)
#include "../../include/adl_sdk.h"
#include "../../include/customer/oem_structures.h"
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#else
#include <windows.h>
#include <tchar.h>
#include "..\..\include\adl_sdk.h"
#endif
#include <stdio.h>
typedef int (*ADL_MAIN_CONTROL_CREATE )(ADL_MAIN_MALLOC_CALLBACK, int );
typedef int (*ADL_MAIN_CONTROL_DESTROY )();
typedef int (*ADL_ADAPTER_NUMBEROFADAPTERS_GET ) ( int* );
typedef int (*ADL2_MAIN_CONTROL_CREATE )(ADL_MAIN_MALLOC_CALLBACK, int, ADL_CONTEXT_HANDLE*);
typedef int (*ADL2_MAIN_CONTROL_DESTROY )( ADL_CONTEXT_HANDLE);
typedef int (*ADL2_ADAPTER_ACTIVE_GET ) (ADL_CONTEXT_HANDLE, int, int* );
typedef int (*ADL2_DISPLAY_MODES_GET )(ADL_CONTEXT_HANDLE, int iAdapterIndex, int iDisplayIndex, int* lpNumModes, ADLMode** lppModes);
ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create;
ADL_MAIN_CONTROL_DESTROY ADL_Main_Control_Destroy;
ADL_ADAPTER_NUMBEROFADAPTERS_GET ADL_Adapter_NumberOfAdapters_Get;
ADL2_MAIN_CONTROL_CREATE ADL2_Main_Control_Create;
ADL2_MAIN_CONTROL_DESTROY ADL2_Main_Control_Destroy;
ADL2_DISPLAY_MODES_GET ADL2_Display_Modes_Get;
ADL2_ADAPTER_ACTIVE_GET ADL2_Adapter_Active_Get;
void* __stdcall ADL_Main_Memory_Alloc ( int iSize )
{
void* lpBuffer = malloc ( iSize );
return lpBuffer;
}
void __stdcall ADL_Main_Memory_Free ( void* lpBuffer )
{
if ( NULL != lpBuffer )
{
free ( lpBuffer );
lpBuffer = NULL;
}
}
#if defined (LINUX)
void * GetProcAddress( void * pLibrary, const char * name)
{
return dlsym( pLibrary, name);
}
#endif
int InitADL ()
{
#if defined (LINUX)
void *hDLL;
#else
HINSTANCE hDLL;
#endif
#if defined (LINUX)
hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL);
#else
hDLL = LoadLibrary("atiadlxx.dll");
if (hDLL == NULL)
hDLL = LoadLibrary("atiadlxy.dll");
#endif
if (NULL == hDLL)
{
printf("ADL library not found!\n");
return ADL_ERR;
}
ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE) GetProcAddress(hDLL,"ADL_Main_Control_Create");
ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY) GetProcAddress(hDLL,"ADL_Main_Control_Destroy");
ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET) GetProcAddress(hDLL,"ADL_Adapter_NumberOfAdapters_Get");
ADL2_Main_Control_Create = (ADL2_MAIN_CONTROL_CREATE) GetProcAddress(hDLL,"ADL2_Main_Control_Create");
ADL2_Main_Control_Destroy = (ADL2_MAIN_CONTROL_DESTROY) GetProcAddress(hDLL,"ADL2_Main_Control_Destroy");
ADL2_Display_Modes_Get = (ADL2_DISPLAY_MODES_GET) GetProcAddress(hDLL,"ADL2_Display_Modes_Get");
ADL2_Adapter_Active_Get = (ADL2_ADAPTER_ACTIVE_GET)GetProcAddress(hDLL, "ADL2_Adapter_Active_Get");
if (NULL == ADL_Main_Control_Create ||
NULL == ADL_Main_Control_Destroy ||
NULL == ADL_Adapter_NumberOfAdapters_Get ||
NULL == ADL2_Main_Control_Create ||
NULL == ADL2_Main_Control_Destroy ||
NULL == ADL2_Display_Modes_Get ||
NULL == ADL2_Adapter_Active_Get)
{
printf("ADL's API is missing!\n");
return ADL_ERR;
}
return ADL_OK;
}
int GetAdapterActiveStatus (int adapterId, int& active)
{
ADL_CONTEXT_HANDLE context = NULL;
active = 0;
if (ADL_OK != ADL2_Main_Control_Create (ADL_Main_Memory_Alloc, 1, &context))
{
printf ("Failed to initialize nested ADL2 context");
return ADL_ERR;
}
if (ADL_OK != ADL2_Adapter_Active_Get(context, adapterId , &active))
{
printf ("Failed to get adapter status");
}
if (ADL_OK != ADL2_Main_Control_Destroy (context))
{
printf ("Failed to destroy nested ADL2 context");
return ADL_ERR;
}
return ADL_OK;
}
int PrintAdapterInfo (int adapterId)
{
ADL_CONTEXT_HANDLE context = NULL;
if (ADL_OK != ADL2_Main_Control_Create (ADL_Main_Memory_Alloc, 1, &context))
{
printf ("Failed to initialize ADL2 context");
return ADL_ERR;
}
int active = 0;
if (ADL_OK == GetAdapterActiveStatus (adapterId, active))
{
printf ("*************************************************\n" );
printf ("Adapter %d is %s\n", adapterId, (active)?"active":"not active" );
if (active)
{
int numModes;
ADLMode* adlMode;
if (ADL_OK == ADL2_Display_Modes_Get (context, adapterId, -1, &numModes, &adlMode))
{
if (numModes == 1)
{
printf ("Adapter %d resolution is %d by %d\n", adapterId, adlMode->iXRes, adlMode->iYRes );
ADL_Main_Memory_Free (adlMode);
}
}
}
}
if (ADL_OK != ADL2_Main_Control_Destroy (context))
{
printf ("Failed to destroy ADL2 context");
return ADL_ERR;
}
return ADL_OK;
}
int main (int c,char* k[],char* s[])
{
if (ADL_OK != InitADL ())
{
return 0;
}
if ( ADL_OK != ADL_Main_Control_Create (ADL_Main_Memory_Alloc, 1) )
{
printf("ADL Initialization Error!\n");
return 0;
}
int iNumberAdapters;
if ( ADL_OK != ADL_Adapter_NumberOfAdapters_Get ( &iNumberAdapters ) )
{
printf("Cannot get the number of adapters!\n");
return 0;
}
for (int adapterId = 0; adapterId < iNumberAdapters; adapterId++ )
{
if (ADL_OK != PrintAdapterInfo (adapterId))
break;
}
if ( ADL_OK != ADL_Main_Control_Destroy ())
{
printf ("Failed to destroy ADL context");
}
return 0;
}