windows: Try to unify all the GUID comparison code into a core helper function.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 13 Feb 2017 17:00:46 -0500
changeset 108854528f2a99fb7
parent 10884 ef3983cd6645
child 10886 b2d018b8d9ba
windows: Try to unify all the GUID comparison code into a core helper function.

There are likely several more I missed.
src/core/windows/SDL_windows.c
src/core/windows/SDL_windows.h
src/haptic/windows/SDL_dinputhaptic.c
src/video/windows/SDL_windowskeyboard.c
     1.1 --- a/src/core/windows/SDL_windows.c	Mon Feb 13 16:59:02 2017 -0500
     1.2 +++ b/src/core/windows/SDL_windows.c	Mon Feb 13 17:00:46 2017 -0500
     1.3 @@ -158,7 +158,7 @@
     1.4      DWORD len = 0;
     1.5      char *retval = NULL;
     1.6  
     1.7 -    if (SDL_memcmp(guid, &nullguid, sizeof (*guid)) == 0) {
     1.8 +    if (WIN_IsEqualGUID(guid, &nullguid)) {
     1.9          return WIN_StringToUTF8(name);  /* No GUID, go with what we've got. */
    1.10      }
    1.11  
    1.12 @@ -202,6 +202,18 @@
    1.13  #endif /* if __WINRT__ / else */
    1.14  }
    1.15  
    1.16 +BOOL
    1.17 +WIN_IsEqualGUID(const GUID * a, const GUID * b)
    1.18 +{
    1.19 +    return (SDL_memcmp(a, b, sizeof (*a)) == 0);
    1.20 +}
    1.21 +
    1.22 +BOOL
    1.23 +WIN_IsEqualIID(REFIID a, REFIID b)
    1.24 +{
    1.25 +    return (SDL_memcmp(a, b, sizeof (*a)) == 0);
    1.26 +}
    1.27 +
    1.28  #endif /* __WIN32__ || __WINRT__ */
    1.29  
    1.30  /* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/core/windows/SDL_windows.h	Mon Feb 13 16:59:02 2017 -0500
     2.2 +++ b/src/core/windows/SDL_windows.h	Mon Feb 13 17:00:46 2017 -0500
     2.3 @@ -62,6 +62,10 @@
     2.4  /* You need to SDL_free() the result of this call. */
     2.5  extern char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid);
     2.6  
     2.7 +/* Checks to see if two GUID are the same. */
     2.8 +extern BOOL WIN_IsEqualGUID(const GUID * a, const GUID * b);
     2.9 +extern BOOL WIN_IsEqualIID(REFIID a, REFIID b);
    2.10 +
    2.11  #endif /* _INCLUDED_WINDOWS_H */
    2.12  
    2.13  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/haptic/windows/SDL_dinputhaptic.c	Mon Feb 13 16:59:02 2017 -0500
     3.2 +++ b/src/haptic/windows/SDL_dinputhaptic.c	Mon Feb 13 17:00:46 2017 -0500
     3.3 @@ -59,15 +59,6 @@
     3.4  }
     3.5  
     3.6  /*
     3.7 - * Checks to see if two GUID are the same.
     3.8 - */
     3.9 -static int
    3.10 -DI_GUIDIsSame(const GUID * a, const GUID * b)
    3.11 -{
    3.12 -    return (SDL_memcmp(a, b, sizeof (GUID)) == 0);
    3.13 -}
    3.14 -
    3.15 -/*
    3.16   * Callback to find the haptic devices.
    3.17   */
    3.18  static BOOL CALLBACK
    3.19 @@ -219,17 +210,17 @@
    3.20      if ((dev->dwType & DIDFT_AXIS) && (dev->dwFlags & DIDOI_FFACTUATOR)) {
    3.21          const GUID *guid = &dev->guidType;
    3.22          DWORD offset = 0;
    3.23 -        if (DI_GUIDIsSame(guid, &GUID_XAxis)) {
    3.24 +        if (WIN_IsEqualGUID(guid, &GUID_XAxis)) {
    3.25              offset = DIJOFS_X;
    3.26 -        } else if (DI_GUIDIsSame(guid, &GUID_YAxis)) {
    3.27 +        } else if (WIN_IsEqualGUID(guid, &GUID_YAxis)) {
    3.28              offset = DIJOFS_Y;
    3.29 -        } else if (DI_GUIDIsSame(guid, &GUID_ZAxis)) {
    3.30 +        } else if (WIN_IsEqualGUID(guid, &GUID_ZAxis)) {
    3.31              offset = DIJOFS_Z;
    3.32 -        } else if (DI_GUIDIsSame(guid, &GUID_RxAxis)) {
    3.33 +        } else if (WIN_IsEqualGUID(guid, &GUID_RxAxis)) {
    3.34              offset = DIJOFS_RX;
    3.35 -        } else if (DI_GUIDIsSame(guid, &GUID_RyAxis)) {
    3.36 +        } else if (WIN_IsEqualGUID(guid, &GUID_RyAxis)) {
    3.37              offset = DIJOFS_RY;
    3.38 -        } else if (DI_GUIDIsSame(guid, &GUID_RzAxis)) {
    3.39 +        } else if (WIN_IsEqualGUID(guid, &GUID_RzAxis)) {
    3.40              offset = DIJOFS_RZ;
    3.41          } else {
    3.42              return DIENUM_CONTINUE;   /* can't use this, go on. */
    3.43 @@ -251,7 +242,7 @@
    3.44   * Callback to get all supported effects.
    3.45   */
    3.46  #define EFFECT_TEST(e,s)               \
    3.47 -if (DI_GUIDIsSame(&pei->guid, &(e)))   \
    3.48 +if (WIN_IsEqualGUID(&pei->guid, &(e)))   \
    3.49     haptic->supported |= (s)
    3.50  static BOOL CALLBACK
    3.51  DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv)
    3.52 @@ -481,7 +472,7 @@
    3.53          return 0;
    3.54      }
    3.55  
    3.56 -    return DI_GUIDIsSame(&hap_instance.guidInstance, &joy_instance.guidInstance);
    3.57 +    return WIN_IsEqualGUID(&hap_instance.guidInstance, &joy_instance.guidInstance);
    3.58  }
    3.59  
    3.60  int
    3.61 @@ -500,7 +491,7 @@
    3.62  
    3.63      /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
    3.64      for (item = SDL_hapticlist; item != NULL; item = item->next) {
    3.65 -        if (!item->bXInputHaptic && DI_GUIDIsSame(&item->instance.guidInstance, &joy_instance.guidInstance)) {
    3.66 +        if (!item->bXInputHaptic && WIN_IsEqualGUID(&item->instance.guidInstance, &joy_instance.guidInstance)) {
    3.67              haptic->index = index;
    3.68              return SDL_DINPUT_HapticOpenFromDevice(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
    3.69          }
     4.1 --- a/src/video/windows/SDL_windowskeyboard.c	Mon Feb 13 16:59:02 2017 -0500
     4.2 +++ b/src/video/windows/SDL_windowskeyboard.c	Mon Feb 13 17:00:46 2017 -0500
     4.3 @@ -331,9 +331,6 @@
     4.4  static void IME_SendEditingEvent(SDL_VideoData *videodata);
     4.5  static void IME_DestroyTextures(SDL_VideoData *videodata);
     4.6  
     4.7 -#define SDL_IsEqualIID(riid1, riid2) SDL_IsEqualGUID(riid1, riid2)
     4.8 -#define SDL_IsEqualGUID(rguid1, rguid2) (!SDL_memcmp(rguid1, rguid2, sizeof(GUID)))
     4.9 -
    4.10  static SDL_bool UILess_SetupSinks(SDL_VideoData *videodata);
    4.11  static void UILess_ReleaseSinks(SDL_VideoData *videodata);
    4.12  static void UILess_EnableUIUpdates(SDL_VideoData *videodata);
    4.13 @@ -1052,9 +1049,9 @@
    4.14          return E_INVALIDARG;
    4.15  
    4.16      *ppv = 0;
    4.17 -    if (SDL_IsEqualIID(riid, &IID_IUnknown))
    4.18 +    if (WIN_IsEqualIID(riid, &IID_IUnknown))
    4.19          *ppv = (IUnknown *)sink;
    4.20 -    else if (SDL_IsEqualIID(riid, &IID_ITfUIElementSink))
    4.21 +    else if (WIN_IsEqualIID(riid, &IID_ITfUIElementSink))
    4.22          *ppv = (ITfUIElementSink *)sink;
    4.23  
    4.24      if (*ppv) {
    4.25 @@ -1158,9 +1155,9 @@
    4.26          return E_INVALIDARG;
    4.27  
    4.28      *ppv = 0;
    4.29 -    if (SDL_IsEqualIID(riid, &IID_IUnknown))
    4.30 +    if (WIN_IsEqualIID(riid, &IID_IUnknown))
    4.31          *ppv = (IUnknown *)sink;
    4.32 -    else if (SDL_IsEqualIID(riid, &IID_ITfInputProcessorProfileActivationSink))
    4.33 +    else if (WIN_IsEqualIID(riid, &IID_ITfInputProcessorProfileActivationSink))
    4.34          *ppv = (ITfInputProcessorProfileActivationSink *)sink;
    4.35  
    4.36      if (*ppv) {
    4.37 @@ -1174,8 +1171,8 @@
    4.38  {
    4.39      static const GUID TF_PROFILE_DAYI = { 0x037B2C25, 0x480C, 0x4D7F, { 0xB0, 0x27, 0xD6, 0xCA, 0x6B, 0x69, 0x78, 0x8A } };
    4.40      SDL_VideoData *videodata = (SDL_VideoData *)sink->data;
    4.41 -    videodata->ime_candlistindexbase = SDL_IsEqualGUID(&TF_PROFILE_DAYI, guidProfile) ? 0 : 1;
    4.42 -    if (SDL_IsEqualIID(catid, &GUID_TFCAT_TIP_KEYBOARD) && (dwFlags & TF_IPSINK_FLAG_ACTIVE))
    4.43 +    videodata->ime_candlistindexbase = WIN_IsEqualGUID(&TF_PROFILE_DAYI, guidProfile) ? 0 : 1;
    4.44 +    if (WIN_IsEqualIID(catid, &GUID_TFCAT_TIP_KEYBOARD) && (dwFlags & TF_IPSINK_FLAG_ACTIVE))
    4.45          IME_InputLangChanged((SDL_VideoData *)sink->data);
    4.46  
    4.47      IME_HideCandidateList(videodata);