From 6344c05b18b8f7f32d01e79cab2bd96914a6fd3d Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 5 Dec 2016 17:21:09 -0500 Subject: [PATCH] Clean up dynamic loading of Win32 funcs, remove makepanda touchinput setting, remove checks for pre-WinXP --- makepanda/makepanda.py | 40 +---- panda/src/dxgsg9/wdxGraphicsPipe9.cxx | 20 ++- panda/src/windisplay/winGraphicsPipe.cxx | 76 ++-------- panda/src/windisplay/winGraphicsPipe.h | 11 -- panda/src/windisplay/winGraphicsWindow.cxx | 162 ++++++++++----------- panda/src/windisplay/winGraphicsWindow.h | 23 ++- 6 files changed, 132 insertions(+), 200 deletions(-) diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 2c26091ef4..956e8db52c 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -94,7 +94,6 @@ PkgListSet(["PYTHON", "DIRECT", # Python support "PANDAPARTICLESYSTEM", # Built in particle system "CONTRIB", # Experimental "SSE2", "NEON", # Compiler features - "TOUCHINPUT", # Touchinput interface (requires Windows 7) ]) CheckPandaSourceTree() @@ -170,7 +169,8 @@ def parseopts(args): "version=","lzma","no-python","threads=","outputdir=","override=", "static","host=","debversion=","rpmrelease=","p3dsuffix=","rtdist-version=", "directx-sdk=", "windows-sdk=", "msvc-version=", "clean", "use-icl", - "universal", "target=", "arch=", "git-commit="] + "universal", "target=", "arch=", "git-commit=", + "use-touchinput", "no-touchinput"] anything = 0 optimize = "" target = None @@ -316,18 +316,6 @@ def parseopts(args): print("No Windows SDK version specified. Defaulting to '7.1'.") WINDOWS_SDK = '7.1' - is_win7 = False - if sys.platform == 'win32': - # Note: not available in cygwin. - winver = sys.getwindowsversion() - if winver[0] >= 6 and winver[1] >= 1: - is_win7 = True - - if RUNTIME or not is_win7: - PkgDisable("TOUCHINPUT") - else: - PkgDisable("TOUCHINPUT") - if clean_build and os.path.isdir(GetOutputDir()): print("Deleting %s" % (GetOutputDir())) shutil.rmtree(GetOutputDir()) @@ -1055,14 +1043,11 @@ def CompileCxx(obj,src,opts): cmd += "/favor:blend " cmd += "/wd4996 /wd4275 /wd4273 " - # Enable Windows 7 interfaces if we need Touchinput. - if PkgSkip("TOUCHINPUT") == 0: - cmd += "/DWINVER=0x601 " - else: - cmd += "/DWINVER=0x501 " - # Work around a WinXP/2003 bug when using VS 2015+. - if SDK.get("VISUALSTUDIO_VERSION") == '14.0': - cmd += "/Zc:threadSafeInit- " + # We still target Windows XP. + cmd += "/DWINVER=0x501 " + # Work around a WinXP/2003 bug when using VS 2015+. + if SDK.get("VISUALSTUDIO_VERSION") == '14.0': + cmd += "/Zc:threadSafeInit- " cmd += "/Fo" + obj + " /nologo /c" if GetTargetArch() != 'x64' and (not PkgSkip("SSE2") or 'SSE2' in opts): @@ -1113,12 +1098,7 @@ def CompileCxx(obj,src,opts): if GetTargetArch() == 'x64': cmd += "/favor:blend " cmd += "/wd4996 /wd4275 /wd4267 /wd4101 /wd4273 " - - # Enable Windows 7 interfaces if we need Touchinput. - if PkgSkip("TOUCHINPUT") == 0: - cmd += "/DWINVER=0x601 " - else: - cmd += "/DWINVER=0x501 " + cmd += "/DWINVER=0x501 " cmd += "/Fo" + obj + " /c" for x in ipath: cmd += " /I" + x for (opt,dir) in INCDIRECTORIES: @@ -2129,7 +2109,6 @@ DTOOL_CONFIG=[ ("REPORT_OPENSSL_ERRORS", '1', '1'), ("USE_PANDAFILESTREAM", '1', '1'), ("USE_DELETED_CHAIN", '1', '1'), - ("HAVE_WIN_TOUCHINPUT", 'UNDEF', 'UNDEF'), ("HAVE_GLX", 'UNDEF', '1'), ("HAVE_WGL", '1', 'UNDEF'), ("HAVE_DX9", 'UNDEF', 'UNDEF'), @@ -2347,9 +2326,6 @@ def WriteConfigSettings(): if (PkgSkip("PYTHON") != 0): dtool_config["HAVE_ROCKET_PYTHON"] = 'UNDEF' - if (PkgSkip("TOUCHINPUT") == 0 and GetTarget() == "windows"): - dtool_config["HAVE_WIN_TOUCHINPUT"] = '1' - if (GetOptimize() <= 3): dtool_config["HAVE_ROCKET_DEBUGGER"] = '1' diff --git a/panda/src/dxgsg9/wdxGraphicsPipe9.cxx b/panda/src/dxgsg9/wdxGraphicsPipe9.cxx index 8174105f39..c3c0ee0099 100644 --- a/panda/src/dxgsg9/wdxGraphicsPipe9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsPipe9.cxx @@ -19,6 +19,16 @@ TypeHandle wdxGraphicsPipe9::_type_handle; +static bool MyGetProcAddr(HINSTANCE hDLL, FARPROC *pFn, const char *szExportedFnName) { + *pFn = (FARPROC) GetProcAddress(hDLL, szExportedFnName); + if (*pFn == NULL) { + wdxdisplay9_cat.error() + << "GetProcAddr failed for " << szExportedFnName << ", error=" << GetLastError() < 1MB, card is lying and I cant tell what it is #define UNKNOWN_VIDMEM_SIZE 0xFFFFFFFF @@ -154,7 +164,10 @@ make_output(const string &name, */ bool wdxGraphicsPipe9:: init() { - if (!MyLoadLib(_hDDrawDLL, "ddraw.dll")) { + _hDDrawDLL = LoadLibrary("ddraw.dll"); + if (_hDDrawDLL == NULL) { + wdxdisplay9_cat.error() + << "LoadLibrary failed for ddraw.dll, error=" << GetLastError() <_physical_memory = memory_status.ullTotalPhys; - display_information->_available_physical_memory = memory_status.ullAvailPhys; - display_information->_page_file_size = memory_status.ullTotalPageFile; - display_information->_available_page_file_size = memory_status.ullAvailPageFile; - display_information->_process_virtual_memory = memory_status.ullTotalVirtual; - display_information->_available_process_virtual_memory = memory_status.ullAvailVirtual; - display_information->_memory_load = memory_status.dwMemoryLoad; - } - } else { - MEMORYSTATUS memory_status; - - memory_status.dwLength = sizeof(MEMORYSTATUS); - GlobalMemoryStatus (&memory_status); - - display_information->_physical_memory = memory_status.dwTotalPhys; - display_information->_available_physical_memory = memory_status.dwAvailPhys; - display_information->_page_file_size = memory_status.dwTotalPageFile; - display_information->_available_page_file_size = memory_status.dwAvailPageFile; - display_information->_process_virtual_memory = memory_status.dwTotalVirtual; - display_information->_available_process_virtual_memory = memory_status.dwAvailVirtual; + memory_status.dwLength = sizeof(MEMORYSTATUSEX); + if (GlobalMemoryStatusEx(&memory_status)) { + display_information->_physical_memory = memory_status.ullTotalPhys; + display_information->_available_physical_memory = memory_status.ullAvailPhys; + display_information->_page_file_size = memory_status.ullTotalPageFile; + display_information->_available_page_file_size = memory_status.ullAvailPageFile; + display_information->_process_virtual_memory = memory_status.ullTotalVirtual; + display_information->_available_process_virtual_memory = memory_status.ullAvailVirtual; display_information->_memory_load = memory_status.dwMemoryLoad; } @@ -687,19 +664,12 @@ WinGraphicsPipe() { _supported_types = OT_window | OT_fullscreen_window; - // these fns arent defined on win95, so get dynamic ptrs to them to avoid - // ugly DLL loader failures on w95 - _pfnTrackMouseEvent = NULL; - - _hUser32 = (HINSTANCE)LoadLibrary("user32.dll"); - if (_hUser32 != NULL) { - _pfnTrackMouseEvent = - (PFN_TRACKMOUSEEVENT)GetProcAddress(_hUser32, "TrackMouseEvent"); - + HMODULE user32 = GetModuleHandleA("user32.dll"); + if (user32 != NULL) { if (dpi_aware) { typedef HRESULT (WINAPI *PFN_SETPROCESSDPIAWARENESS)(Process_DPI_Awareness); PFN_SETPROCESSDPIAWARENESS pfnSetProcessDpiAwareness = - (PFN_SETPROCESSDPIAWARENESS)GetProcAddress(_hUser32, "SetProcessDpiAwarenessInternal"); + (PFN_SETPROCESSDPIAWARENESS)GetProcAddress(user32, "SetProcessDpiAwarenessInternal"); if (pfnSetProcessDpiAwareness == NULL) { if (windisplay_cat.is_debug()) { @@ -908,26 +878,4 @@ lookup_cpu_data() { */ WinGraphicsPipe:: ~WinGraphicsPipe() { - if (_hUser32 != NULL) { - FreeLibrary(_hUser32); - _hUser32 = NULL; - } -} - -bool MyGetProcAddr(HINSTANCE hDLL, FARPROC *pFn, const char *szExportedFnName) { - *pFn = (FARPROC) GetProcAddress(hDLL, szExportedFnName); - if (*pFn == NULL) { - windisplay_cat.error() << "GetProcAddr failed for " << szExportedFnName << ", error=" << GetLastError() < 1)) { + if (_input_devices.size() > 1) { RAWINPUTDEVICE Rid; Rid.usUsagePage = 0x01; Rid.usUsage = 0x02; Rid.dwFlags = 0;// RIDEV_NOLEGACY; // adds HID mouse and also ignores legacy mouse messages Rid.hwndTarget = _hWnd; - pRegisterRawInputDevices(&Rid, 1, sizeof (Rid)); + RegisterRawInputDevices(&Rid, 1, sizeof (Rid)); } // Create a WindowHandle for ourselves @@ -535,10 +537,23 @@ open_window() { // set us as the focus window for keyboard input set_focus(); + // Try initializing the touch function pointers. + static bool initialized = false; + if (!initialized) { + initialized = true; + HMODULE user32 = GetModuleHandleA("user32.dll"); + if (user32) { + // Introduced in Windows 7. + pRegisterTouchWindow = (PFN_REGISTERTOUCHWINDOW)GetProcAddress(user32, "RegisterTouchWindow"); + pGetTouchInputInfo = (PFN_GETTOUCHINPUTINFO)GetProcAddress(user32, "GetTouchInputInfo"); + pCloseTouchInputHandle = (PFN_CLOSETOUCHINPUTHANDLE)GetProcAddress(user32, "CloseTouchInputHandle"); + } + } + // Register for Win7 touch events. -#ifdef HAVE_WIN_TOUCHINPUT - RegisterTouchWindow(_hWnd, 0); -#endif + if (pRegisterTouchWindow != NULL) { + pRegisterTouchWindow(_hWnd, 0); + } return true; } @@ -563,45 +578,35 @@ initialize_input_devices() { GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard_mouse"); add_input_device(device); - // Try initializing the Raw Input function pointers. - if (pRegisterRawInputDevices==0) { - HMODULE user32 = LoadLibrary("user32.dll"); - if (user32) { - pRegisterRawInputDevices = (tRegisterRawInputDevices)GetProcAddress(user32,"RegisterRawInputDevices"); - pGetRawInputDeviceList = (tGetRawInputDeviceList) GetProcAddress(user32,"GetRawInputDeviceList"); - pGetRawInputDeviceInfoA = (tGetRawInputDeviceInfoA) GetProcAddress(user32,"GetRawInputDeviceInfoA"); - pGetRawInputData = (tGetRawInputData) GetProcAddress(user32,"GetRawInputData"); - } - } - - if (pRegisterRawInputDevices==0) return; - if (pGetRawInputDeviceList==0) return; - if (pGetRawInputDeviceInfoA==0) return; - if (pGetRawInputData==0) return; - // Get the number of devices. - if (pGetRawInputDeviceList(NULL, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != 0) + if (GetRawInputDeviceList(NULL, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != 0) { return; + } // Allocate the array to hold the DeviceList pRawInputDeviceList = (PRAWINPUTDEVICELIST)alloca(sizeof(RAWINPUTDEVICELIST) * nInputDevices); - if (pRawInputDeviceList==0) return; + if (pRawInputDeviceList==0) { + return; + } // Fill the Array - if (pGetRawInputDeviceList(pRawInputDeviceList, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) == -1) + if (GetRawInputDeviceList(pRawInputDeviceList, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) == -1) { return; + } // Loop through all raw devices and find the raw mice for (int i = 0; i < (int)nInputDevices; i++) { if (pRawInputDeviceList[i].dwType == RIM_TYPEMOUSE) { // Fetch information about specified mouse device. UINT nSize; - if (pGetRawInputDeviceInfoA(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, (LPVOID)0, &nSize) != 0) + if (GetRawInputDeviceInfoA(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, (LPVOID)0, &nSize) != 0) { return; + } char *psName = (char*)alloca(sizeof(TCHAR) * nSize); if (psName == 0) return; - if (pGetRawInputDeviceInfoA(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, (LPVOID)psName, &nSize) < 0) + if (GetRawInputDeviceInfoA(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, (LPVOID)psName, &nSize) < 0) { return; + } // If it's not an RDP mouse, add it to the list of raw mice. if (strncmp(psName,"\\??\\Root#RDP_MOU#0000#",22)!=0) { @@ -1215,31 +1220,25 @@ adjust_z_order(WindowProperties::ZOrder last_z_order, */ void WinGraphicsWindow:: track_mouse_leaving(HWND hwnd) { - // Note: could use _TrackMouseEvent in comctrl32.dll (part of IE 3.0+) which - // emulates TrackMouseEvent on w95, but that requires another 500K of memory - // to hold that DLL, which is lame just to support w95, which probably has - // other issues anyway WinGraphicsPipe *winpipe; DCAST_INTO_V(winpipe, _pipe); - if (winpipe->_pfnTrackMouseEvent != NULL) { - TRACKMOUSEEVENT tme = { - sizeof(TRACKMOUSEEVENT), - TME_LEAVE, - hwnd, - 0 - }; + TRACKMOUSEEVENT tme = { + sizeof(TRACKMOUSEEVENT), + TME_LEAVE, + hwnd, + 0 + }; - // tell win32 to post WM_MOUSELEAVE msgs - BOOL bSucceeded = winpipe->_pfnTrackMouseEvent(&tme); + // tell win32 to post WM_MOUSELEAVE msgs + BOOL bSucceeded = TrackMouseEvent(&tme); - if ((!bSucceeded) && windisplay_cat.is_debug()) { - windisplay_cat.debug() - << "TrackMouseEvent failed!, LastError=" << GetLastError() << endl; - } - - _tracking_mouse_leaving = true; + if (!bSucceeded && windisplay_cat.is_debug()) { + windisplay_cat.debug() + << "TrackMouseEvent failed!, LastError=" << GetLastError() << endl; } + + _tracking_mouse_leaving = true; } /** @@ -2067,15 +2066,16 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { } break; -#ifdef HAVE_WIN_TOUCHINPUT case WM_TOUCH: - _numTouches = LOWORD(wparam); - if(_numTouches > MAX_TOUCHES) - _numTouches = MAX_TOUCHES; - GetTouchInputInfo((HTOUCHINPUT)lparam, _numTouches, _touches, sizeof(TOUCHINPUT)); - CloseTouchInputHandle((HTOUCHINPUT)lparam); + _num_touches = LOWORD(wparam); + if (_num_touches > MAX_TOUCHES) { + _num_touches = MAX_TOUCHES; + } + if (pGetTouchInputInfo != 0) { + pGetTouchInputInfo((HTOUCHINPUT)lparam, _num_touches, _touches, sizeof(TOUCHINPUT)); + pCloseTouchInputHandle((HTOUCHINPUT)lparam); + } break; -#endif } // do custom messages processing if any has been set @@ -2607,7 +2607,7 @@ handle_raw_input(HRAWINPUT hraw) { if (hraw == 0) { return; } - if (pGetRawInputData(hraw, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)) == -1) { + if (GetRawInputData(hraw, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)) == -1) { return; } @@ -2616,7 +2616,7 @@ handle_raw_input(HRAWINPUT hraw) { return; } - if (pGetRawInputData(hraw, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize) { + if (GetRawInputData(hraw, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize) { return; } @@ -2973,12 +2973,8 @@ bool WinGraphicsWindow::supports_window_procs() const{ * */ bool WinGraphicsWindow:: -is_touch_event(GraphicsWindowProcCallbackData* callbackData){ -#ifdef HAVE_WIN_TOUCHINPUT +is_touch_event(GraphicsWindowProcCallbackData *callbackData) { return callbackData->get_msg() == WM_TOUCH; -#else - return false; -#endif } /** @@ -2987,11 +2983,7 @@ is_touch_event(GraphicsWindowProcCallbackData* callbackData){ */ int WinGraphicsWindow:: get_num_touches(){ -#ifdef HAVE_WIN_TOUCHINPUT - return _numTouches; -#else - return 0; -#endif + return _num_touches; } /** @@ -2999,8 +2991,9 @@ get_num_touches(){ * */ TouchInfo WinGraphicsWindow:: -get_touch_info(int index){ -#ifdef HAVE_WIN_TOUCHINPUT +get_touch_info(int index) { + nassertr(index >= 0 && index < MAX_TOUCHES, TouchInfo()); + TOUCHINPUT ti = _touches[index]; POINT point; point.x = TOUCH_COORD_TO_PIXEL(ti.x); @@ -3013,7 +3006,4 @@ get_touch_info(int index){ ret.set_id(ti.dwID); ret.set_flags(ti.dwFlags); return ret; -#else - return TouchInfo(); -#endif } diff --git a/panda/src/windisplay/winGraphicsWindow.h b/panda/src/windisplay/winGraphicsWindow.h index 798218052a..ec7e1217ff 100644 --- a/panda/src/windisplay/winGraphicsWindow.h +++ b/panda/src/windisplay/winGraphicsWindow.h @@ -34,8 +34,23 @@ typedef struct { int y; int width; int height; -} -WINDOW_METRICS; +} WINDOW_METRICS; + +#if WINVER < 0x0601 +// Not used on Windows XP, but we still need to define it. +typedef struct tagTOUCHINPUT { + LONG x; + LONG y; + HANDLE hSource; + DWORD dwID; + DWORD dwFlags; + DWORD dwMask; + DWORD dwTime; + ULONG_PTR dwExtraInfo; + DWORD cxContact; + DWORD cyContact; +} TOUCHINPUT, *PTOUCHINPUT; +#endif /** * An abstract base class for glGraphicsWindow and dxGraphicsWindow (and, in @@ -177,10 +192,8 @@ private: typedef pset WinProcClasses; WinProcClasses _window_proc_classes; -#ifdef HAVE_WIN_TOUCHINPUT - UINT _numTouches; + UINT _num_touches; TOUCHINPUT _touches[MAX_TOUCHES]; -#endif private: // We need this map to support per-window calls to window_proc().