Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.6 KiB

  1. /*++
  2. * File name:
  3. * bmpcache.c
  4. * Contents:
  5. * Bitmap cache interface for tclinet
  6. * Bitmap compare code
  7. *
  8. * Copyright (C) 1998-1999 Microsoft Corp.
  9. --*/
  10. #include <windows.h>
  11. #include <memory.h>
  12. #include "protocol.h"
  13. #include "tclient.h"
  14. #include "gdata.h"
  15. #include "bmpdb.h"
  16. PGROUPENTRY g_pCache = NULL;
  17. // The bitmap manager is not thread safe
  18. #define ENTER_CRIT EnterCriticalSection(g_lpcsGuardWaitQueue);
  19. #define LEAVE_CRIT LeaveCriticalSection(g_lpcsGuardWaitQueue);
  20. /*++
  21. * Function:
  22. * InitCache
  23. * Description:
  24. * Inits global data and the cache manager
  25. * Called by:
  26. * InitDone
  27. --*/
  28. VOID InitCache(VOID)
  29. {
  30. ENTER_CRIT
  31. OpenDB(FALSE);
  32. g_pCache = GetGroupList();
  33. LEAVE_CRIT
  34. }
  35. /*++
  36. * Function:
  37. * DeleteCache
  38. * Description:
  39. * Deletes all linked lists and closes the manager opened
  40. * by InitCache
  41. * Called by:
  42. * InitDone
  43. --*/
  44. VOID DeleteCache(VOID)
  45. {
  46. PGROUPENTRY pIter;
  47. ENTER_CRIT
  48. // Clean the cache
  49. pIter = g_pCache;
  50. while(pIter)
  51. {
  52. FreeBitmapList(pIter->pBitmap);
  53. pIter = pIter->pNext;
  54. }
  55. FreeGroupList(g_pCache);
  56. g_pCache = NULL;
  57. CloseDB();
  58. LEAVE_CRIT
  59. }
  60. /*++
  61. * Function:
  62. * BitmapCacheLookup
  63. * Description:
  64. * Retrieves all bitmaps with specific ID
  65. --*/
  66. PBMPENTRY BitmapCacheLookup(LPCWSTR szWText)
  67. {
  68. PGROUPENTRY pIter;
  69. PBMPENTRY rv = NULL;
  70. FOFFSET lGrpOffs;
  71. ENTER_CRIT
  72. pIter = g_pCache;
  73. while(pIter && wcscmp(pIter->WText, szWText))
  74. {
  75. pIter = pIter->pNext;
  76. }
  77. if (!pIter)
  78. goto exitpt;
  79. if (!pIter->pBitmap)
  80. pIter->pBitmap = GetBitmapList(NULL, pIter->FOffsBmp);
  81. rv = pIter->pBitmap;
  82. exitpt:
  83. LEAVE_CRIT
  84. return rv;
  85. }
  86. /*++
  87. * Function:
  88. * Glyph2String
  89. * Description:
  90. * Gets the ID for matching bimtap
  91. * Arguments:
  92. * pBmpFeed - Bitmap
  93. * wszString - buffer for the ID
  94. * max - buffer length
  95. * Return value:
  96. * TRUE if matching bitmap is found
  97. * Called by:
  98. * GlyphReceived running within feedback thread
  99. --*/
  100. BOOL Glyph2String(PBMPFEEDBACK pBmpFeed, LPWSTR wszString, UINT max)
  101. {
  102. UINT nChkSum, nFeedSize;
  103. PGROUPENTRY pGroup;
  104. PBMPENTRY pBitmap;
  105. BOOL rv = FALSE;
  106. nFeedSize = pBmpFeed->bmpsize + pBmpFeed->bmiSize;
  107. nChkSum = CheckSum(&(pBmpFeed->BitmapInfo), nFeedSize);
  108. ENTER_CRIT
  109. pGroup = g_pCache;
  110. // Go thru all groups
  111. while (pGroup)
  112. {
  113. pBitmap = pGroup->pBitmap;
  114. if (!pBitmap)
  115. // Read the bitmap list if necessesary
  116. pBitmap = pGroup->pBitmap = GetBitmapList(NULL, pGroup->FOffsBmp);
  117. // and bitmaps
  118. while(pBitmap)
  119. {
  120. // Compare the bitmaps
  121. if (pBitmap->nChkSum == nChkSum &&
  122. pBitmap->xSize == pBmpFeed->xSize &&
  123. pBitmap->ySize == pBmpFeed->ySize &&
  124. pBitmap->bmiSize == pBmpFeed->bmiSize &&
  125. pBitmap->bmpSize == pBmpFeed->bmpsize &&
  126. !memcmp(pBitmap->pData, &(pBmpFeed->BitmapInfo), nFeedSize))
  127. {
  128. // OK, copy the string
  129. UINT strl = wcslen(pGroup->WText);
  130. if (strl > max - 1)
  131. strl = max - 1;
  132. wcsncpy(wszString, pGroup->WText, strl);
  133. wszString[strl] = 0;
  134. rv = TRUE;
  135. goto exitpt;
  136. }
  137. pBitmap = pBitmap->pNext;
  138. }
  139. pGroup = pGroup->pNext;
  140. }
  141. exitpt:
  142. LEAVE_CRIT
  143. return rv;
  144. }