Skip to content

Commit

Permalink
port for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kuebk committed Jul 25, 2011
1 parent 545e286 commit 2c84282
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 52 deletions.
46 changes: 25 additions & 21 deletions adl3/adl_api.py
Expand Up @@ -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
Expand All @@ -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())

Expand Down Expand Up @@ -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))]
Expand Down
102 changes: 71 additions & 31 deletions adl3/adl_structures.py
Expand Up @@ -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
Expand Down

0 comments on commit 2c84282

Please sign in to comment.