[DINPUT] Sync with Wine Staging 2.2. CORE-12823
authorAmine Khaldi <amine.khaldi@reactos.org>
Sun, 26 Feb 2017 16:36:28 +0000 (16:36 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 26 Feb 2017 16:36:28 +0000 (16:36 +0000)
f921b63 dinput: Do not wait for hook thread startup in IDirectInput8::Initialize.
f9b4be5 dinput: Allocate correct amount of memory in IDirectInput8AImpl_EnumDevicesBySemantics.
04bddb6 dinput: Give correct count of devices still to be enumerated.
8339de0 dinput: Simplify JoystickWImpl_Unacquire for Linux.
27f4568 dinput: DISFFC_RESET will not release the effects.
2d2d833 dinput: Downgrade a FIXME to WARN in JoystickWImpl_SendForceFeedbackCommand.
cc37322 dinput: Fix GetEffectStatus for Linux when effect was not downloaded.
6bb2c4c dinput: Skip events that are not useful currently.
49d4261 dinput: Spelling and case fixes in comments.

svn path=/trunk/; revision=73934

reactos/dll/directx/wine/dinput/dinput.rc
reactos/dll/directx/wine/dinput/dinput_main.c
reactos/dll/directx/wine/dinput/effect_linuxinput.c
reactos/dll/directx/wine/dinput/joystick_linuxinput.c
reactos/media/doc/README.WINE

index 3b598e0..e677561 100644 (file)
@@ -32,6 +32,8 @@
 
 #include <wine/wine_common_ver.rc>
 
+#pragma makedep po
+
 LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
 
 STRINGTABLE
index c725d63..5127371 100644 (file)
@@ -911,7 +911,9 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics(
     LPDIRECTINPUTDEVICE8A lpdid;
     DWORD callbackFlags;
     int i, j;
-
+    int device_count = 0;
+    int remain;
+    DIDEVICEINSTANCEA *didevis = 0;
 
     FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, debugstr_a(ptszUserName), lpdiActionFormat,
           lpCallback, pvRef, dwFlags);
@@ -939,19 +941,37 @@ static HRESULT WINAPI IDirectInput8AImpl_EnumDevicesBySemantics(
         {
             TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name);
 
-            callbackFlags = diactionformat_priorityA(lpdiActionFormat, lpdiActionFormat->dwGenre);
             /* Default behavior is to enumerate attached game controllers */
             enumSuccess = dinput_devices[i]->enum_deviceA(DI8DEVCLASS_GAMECTRL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j);
             if (enumSuccess == S_OK)
             {
-                IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL);
-
-                if (lpCallback(&didevi, lpdid, callbackFlags, 0, pvRef) == DIENUM_STOP)
-                    return DI_OK;
+                if (device_count++)
+                    didevis = HeapReAlloc(GetProcessHeap(), 0, didevis, sizeof(DIDEVICEINSTANCEA)*device_count);
+                else
+                    didevis = HeapAlloc(GetProcessHeap(), 0, sizeof(DIDEVICEINSTANCEA)*device_count);
+                didevis[device_count-1] = didevi;
             }
         }
     }
 
+    remain = device_count;
+    if (!(dwFlags & DIEDBSFL_FORCEFEEDBACK))
+        remain += sizeof(guids)/sizeof(guids[0]);
+
+    for (i = 0; i < device_count; i++)
+    {
+        callbackFlags = diactionformat_priorityA(lpdiActionFormat, lpdiActionFormat->dwGenre);
+        IDirectInput_CreateDevice(iface, &didevis[i].guidInstance, &lpdid, NULL);
+
+        if (lpCallback(&didevis[i], lpdid, callbackFlags, --remain, pvRef) == DIENUM_STOP)
+        {
+            HeapFree(GetProcessHeap(), 0, didevis);
+            return DI_OK;
+        }
+    }
+
+    HeapFree(GetProcessHeap(), 0, didevis);
+
     if (dwFlags & DIEDBSFL_FORCEFEEDBACK) return DI_OK;
 
     /* Enumerate keyboard and mouse */
@@ -982,6 +1002,9 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
     LPDIRECTINPUTDEVICE8W lpdid;
     DWORD callbackFlags;
     int i, j;
+    int device_count = 0;
+    int remain;
+    DIDEVICEINSTANCEW *didevis = 0;
 
     FIXME("(this=%p,%s,%p,%p,%p,%04x): semi-stub\n", This, debugstr_w(ptszUserName), lpdiActionFormat,
           lpCallback, pvRef, dwFlags);
@@ -999,19 +1022,37 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
         {
             TRACE(" - checking device %u ('%s')\n", i, dinput_devices[i]->name);
 
-            callbackFlags = diactionformat_priorityW(lpdiActionFormat, lpdiActionFormat->dwGenre);
             /* Default behavior is to enumerate attached game controllers */
             enumSuccess = dinput_devices[i]->enum_deviceW(DI8DEVCLASS_GAMECTRL, DIEDFL_ATTACHEDONLY | dwFlags, &didevi, This->dwVersion, j);
             if (enumSuccess == S_OK)
             {
-                IDirectInput_CreateDevice(iface, &didevi.guidInstance, &lpdid, NULL);
-
-                if (lpCallback(&didevi, lpdid, callbackFlags, 0, pvRef) == DIENUM_STOP)
-                    return DI_OK;
+                if (device_count++)
+                    didevis = HeapReAlloc(GetProcessHeap(), 0, didevis, sizeof(DIDEVICEINSTANCEW)*device_count);
+                else
+                    didevis = HeapAlloc(GetProcessHeap(), 0, sizeof(DIDEVICEINSTANCEW)*device_count);
+                didevis[device_count-1] = didevi;
             }
         }
     }
 
+    remain = device_count;
+    if (!(dwFlags & DIEDBSFL_FORCEFEEDBACK))
+        remain += sizeof(guids)/sizeof(guids[0]);
+
+    for (i = 0; i < device_count; i++)
+    {
+        callbackFlags = diactionformat_priorityW(lpdiActionFormat, lpdiActionFormat->dwGenre);
+        IDirectInput_CreateDevice(iface, &didevis[i].guidInstance, &lpdid, NULL);
+
+        if (lpCallback(&didevis[i], lpdid, callbackFlags, --remain, pvRef) == DIENUM_STOP)
+        {
+            HeapFree(GetProcessHeap(), 0, didevis);
+            return DI_OK;
+        }
+    }
+
+    HeapFree(GetProcessHeap(), 0, didevis);
+
     if (dwFlags & DIEDBSFL_FORCEFEEDBACK) return DI_OK;
 
     /* Enumerate keyboard and mouse */
index d3fede5..7477bc7 100644 (file)
@@ -234,11 +234,16 @@ static HRESULT WINAPI LinuxInputEffectImpl_GetEffectStatus(
         LPDIRECTINPUTEFFECT iface,
        LPDWORD pdwFlags)
 {
-    TRACE("(this=%p,%p)\n", iface, pdwFlags);
+    LinuxInputEffectImpl *This = impl_from_IDirectInputEffect(iface);
+
+    TRACE("(this=%p,%p)\n", This, pdwFlags);
 
     if (!pdwFlags)
         return E_POINTER;
 
+    if (This->effect.id == -1)
+        return DIERR_NOTDOWNLOADED;
+
     /* linux sends the effect status through an event.
      * that event is trapped by our parent joystick driver
      * and there is no clean way to pass it back to us. */
@@ -633,9 +638,9 @@ static HRESULT WINAPI LinuxInputEffectImpl_SetParameters(
 
             This->effect.u.periodic.magnitude = (tsp->dwMagnitude / 10) * 32;
             This->effect.u.periodic.offset = (tsp->lOffset / 10) * 32;
-            /* phase ranges from 0 - 35999 in dinput and 0 - 65535 on linux */
+            /* phase ranges from 0 - 35999 in dinput and 0 - 65535 on Linux */
             This->effect.u.periodic.phase = (tsp->dwPhase / 36) * 65;
-            /* dinput uses microseconds, linux uses miliseconds */
+            /* dinput uses microseconds, Linux uses milliseconds */
             if (tsp->dwPeriod <= 1000)
                 This->effect.u.periodic.period = 1;
             else
index a962b56..2cd01e8 100644 (file)
@@ -69,6 +69,8 @@ HRESULT linuxinput_create_effect(int* fd, REFGUID rguid, struct list *parent_lis
 HRESULT linuxinput_get_info_A(int fd, REFGUID rguid, LPDIEFFECTINFOA info);
 HRESULT linuxinput_get_info_W(int fd, REFGUID rguid, LPDIEFFECTINFOW info);
 
+static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags);
+
 typedef struct JoystickImpl JoystickImpl;
 static const IDirectInputDevice8AVtbl JoystickAvt;
 static const IDirectInputDevice8WVtbl JoystickWvt;
@@ -726,18 +728,10 @@ static HRESULT WINAPI JoystickWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
     TRACE("(this=%p)\n",This);
     res = IDirectInputDevice2WImpl_Unacquire(iface);
     if (res==DI_OK && This->joyfd!=-1) {
-      effect_list_item *itr;
       struct input_event event;
 
-      /* For each known effect:
-       * - stop it
-       * - unload it
-       * But, unlike DISFFC_RESET, do not release the effect.
-       */
-      LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry) {
-          IDirectInputEffect_Stop(itr->ref);
-          IDirectInputEffect_Unload(itr->ref);
-      }
+      /* Stop and unload all effects */
+      JoystickWImpl_SendForceFeedbackCommand(iface, DISFFC_RESET);
 
       /* Enable autocenter. */
       event.type = EV_FF;
@@ -883,7 +877,7 @@ static void joy_polldev(LPDIRECTINPUTDEVICE8A iface)
             break;
 #endif
        default:
-           FIXME("joystick cannot handle type %d event (code %d)\n",ie.type,ie.code);
+           TRACE("skipping event\n");
            break;
        }
         if (inst_id >= 0)
@@ -1312,9 +1306,9 @@ static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE
     {
     case DISFFC_STOPALL:
     {
-       /* Stop all effects */
         effect_list_item *itr;
 
+        /* Stop all effects */
         LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry)
             IDirectInputEffect_Stop(itr->ref);
         break;
@@ -1322,17 +1316,19 @@ static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE
 
     case DISFFC_RESET:
     {
-        effect_list_item *itr, *ptr;
+        effect_list_item *itr;
 
-       /* Stop, unload, release and free all effects */
-       /* This returns the device to its "bare" state */
-        LIST_FOR_EACH_ENTRY_SAFE(itr, ptr, &This->ff_effects, effect_list_item, entry)
-            IDirectInputEffect_Release(itr->ref);
+        /* Stop and unload all effects. It is not true that effects are released */
+        LIST_FOR_EACH_ENTRY(itr, &This->ff_effects, effect_list_item, entry)
+        {
+            IDirectInputEffect_Stop(itr->ref);
+            IDirectInputEffect_Unload(itr->ref);
+        }
         break;
     }
     case DISFFC_PAUSE:
     case DISFFC_CONTINUE:
-       FIXME("No support for Pause or Continue in linux\n");
+        FIXME("No support for Pause or Continue in linux\n");
         break;
 
     case DISFFC_SETACTUATORSOFF:
@@ -1341,8 +1337,8 @@ static HRESULT WINAPI JoystickWImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE
         break;
 
     default:
-       FIXME("Unknown Force Feedback Command!\n");
-       return DIERR_INVALIDPARAM;
+        WARN("Unknown Force Feedback Command %u!\n", dwFlags);
+        return DIERR_INVALIDPARAM;
     }
     return DI_OK;
 #else
index da01487..62ec236 100644 (file)
@@ -30,7 +30,7 @@ reactos/dll/directx/wine/d3dx9_24 => 43 # Synced to WineStaging-1.9.4
 reactos/dll/directx/wine/d3dxof         # Synced to WineStaging-1.9.23
 reactos/dll/directx/wine/ddraw          # Synced to WineStaging-1.9.4
 reactos/dll/directx/wine/devenum        # Synced to WineStaging-1.9.23
-reactos/dll/directx/wine/dinput         # Synced to WineStaging-1.9.23
+reactos/dll/directx/wine/dinput         # Synced to WineStaging-2.2
 reactos/dll/directx/wine/dinput8        # Synced to WineStaging-1.9.23
 reactos/dll/directx/wine/dmusic         # Synced to WineStaging-1.9.23
 reactos/dll/directx/wine/dplay          # Synced to WineStaging-1.9.23