From 2c842826b3cc1307c6c5dc96e63acec3531f03f4 Mon Sep 17 00:00:00 2001 From: kuebk Date: Mon, 25 Jul 2011 23:51:15 +0200 Subject: [PATCH] port for windows --- adl3/adl_api.py | 46 ++++++++++--------- adl3/adl_structures.py | 102 ++++++++++++++++++++++++++++------------- 2 files changed, 96 insertions(+), 52 deletions(-) diff --git a/adl3/adl_api.py b/adl3/adl_api.py index 3d02723..e588708 100644 --- a/adl3/adl_api.py +++ b/adl3/adl_api.py @@ -27,15 +27,31 @@ from .adl_structures import * _platform = platform.system() +_release = platform.release() -if _platform == "Linux": - from ctypes import CDLL, RTLD_GLOBAL, CFUNCTYPE - - # load the ADL 3.0 dso/dll - _libadl = CDLL("libatiadlxx.so", mode=RTLD_GLOBAL) +if _platform == "Linux" or _platform == "Windows": + from ctypes import CDLL, CFUNCTYPE + + if _platform == "Linux": + from ctypes import RTLD_GLOBAL - # ADL requires we pass an allocation function and handle freeing it ourselves - _libc = CDLL("libc.so.6") + # load the ADL 3.0 dso/dll + _libadl = CDLL("libatiadlxx.so", mode=RTLD_GLOBAL) + + # ADL requires we pass an allocation function and handle freeing it ourselves + _libc = CDLL("libc.so.6") + else: + from ctypes.util import find_msvcrt + try: + # first try to load the 64-bit library + _libadl = CDLL("atiadlxx.dll") + except OSError: + # fall back on the 32-bit library + _libadl = CDLL("atiadlxy.dll") + + _libc = CDLL(find_msvcrt()); + + _malloc = _libc.malloc _malloc.argtypes = [c_size_t] _malloc.restype = c_void_p @@ -54,19 +70,7 @@ def ADL_Main_Memory_Free(lpBuffer): if lpBuffer[0] is not None: _free(lpBuffer[0]) lpBuffer[0] = None - -elif _platform == "Windows": - from ctypes import WinDLL, WINFUNCTYPE - - # load the ADL 3.0 dso/dll - try: - # first try to load the 64-bit library - _libadl = WinDLL("atiadlxx.dll") - except OSError: - # fall back on the 32-bit library - _libadl = WinDLL("atiadlxy.dll") - - # TODO: I have no idea how to allocate memory in Windows + else: raise RuntimeError("Platform '%s' is not Supported." % platform.system()) @@ -378,7 +382,7 @@ def ADL_Main_Memory_Free(lpBuffer): ADL_Display_SLSMapConfig_Rearrange.restype = c_int ADL_Display_SLSMapConfig_Rearrange.argtypes = [c_int, c_int, c_int, POINTER(ADLSLSTarget), ADLSLSMap, c_int] -if _platform == "Windows": +if _platform == "Windows" and _release == "XP": ADL_Display_PossibleMode_WinXP_Get = _libadl.ADL_Display_PossibleMode_WinXP_Get ADL_Display_PossibleMode_WinXP_Get.restype = c_int ADL_Display_PossibleMode_WinXP_Get.argtypes = [c_int, c_int, POINTER(ADLDisplayTarget), c_int, c_int, POINTER(c_int), POINTER(POINTER(ADLMode))] diff --git a/adl3/adl_structures.py b/adl3/adl_structures.py index bb7f29d..9e1e402 100644 --- a/adl3/adl_structures.py +++ b/adl3/adl_structures.py @@ -22,38 +22,78 @@ from ctypes import Structure, POINTER from ctypes import c_int, c_float, c_char, c_char_p, c_short, c_long, c_longlong - -class struct_AdapterInfo(Structure): - __slots__ = [ - 'iSize', - 'iAdapterIndex', - 'strUDID', - 'iBusNumber', - 'iDeviceNumber', - 'iFunctionNumber', - 'iVendorID', - 'strAdapterName', - 'strDisplayName', - 'iPresent', - 'iXScreenNum', - 'iDrvIndex', - 'strXScreenConfigName', +import platform + +_platform = platform.system() + +if _platform == "Linux": + class struct_AdapterInfo(Structure): + __slots__ = [ + 'iSize', + 'iAdapterIndex', + 'strUDID', + 'iBusNumber', + 'iDeviceNumber', + 'iFunctionNumber', + 'iVendorID', + 'strAdapterName', + 'strDisplayName', + 'iPresent', + 'iXScreenNum', + 'iDrvIndex', + 'strXScreenConfigName', + ] + struct_AdapterInfo._fields_ = [ + ('iSize', c_int), + ('iAdapterIndex', c_int), + ('strUDID', c_char * 256), + ('iBusNumber', c_int), + ('iDeviceNumber', c_int), + ('iFunctionNumber', c_int), + ('iVendorID', c_int), + ('strAdapterName', c_char * 256), + ('strDisplayName', c_char * 256), + ('iPresent', c_int), + ('iXScreenNum', c_int), + ('iDrvIndex', c_int), + ('strXScreenConfigName', c_char * 256), + ] +elif _platform == "Windows": + class struct_AdapterInfo(Structure): + __slots__ = [ + 'iSize', + 'iAdapterIndex', + 'strUDID', + 'iBusNumber', + 'iDeviceNumber', + 'iFunctionNumber', + 'iVendorID', + 'strAdapterName', + 'strDisplayName', + 'iPresent', + 'iExist', + 'strDriverPath', + 'strDriverPathExt', + 'strPNPString', + 'iOSDisplayIndex' + ] + struct_AdapterInfo._fields_ = [ + ('iSize', c_int), + ('iAdapterIndex', c_int), + ('strUDID', c_char * 256), + ('iBusNumber', c_int), + ('iDeviceNumber', c_int), + ('iFunctionNumber', c_int), + ('iVendorID', c_int), + ('strAdapterName', c_char * 256), + ('strDisplayName', c_char * 256), + ('iPresent', c_int), + ('iExist', c_int), + ('strDriverPath', c_char * 256), + ('strDriverPathExt', c_char * 256), + ('strPNPString', c_char * 256), + ('iOSDisplayIndex', c_char * 256) ] -struct_AdapterInfo._fields_ = [ - ('iSize', c_int), - ('iAdapterIndex', c_int), - ('strUDID', c_char * 256), - ('iBusNumber', c_int), - ('iDeviceNumber', c_int), - ('iFunctionNumber', c_int), - ('iVendorID', c_int), - ('strAdapterName', c_char * 256), - ('strDisplayName', c_char * 256), - ('iPresent', c_int), - ('iXScreenNum', c_int), - ('iDrvIndex', c_int), - ('strXScreenConfigName', c_char * 256), -] AdapterInfo = struct_AdapterInfo # ADL_SDK_3.0/include/adl_structures.h:123 LPAdapterInfo = POINTER(struct_AdapterInfo) # ADL_SDK_3.0/include/adl_structures.h:123