Leaked source code of windows server 2003
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.

191 lines
4.8 KiB

  1. /***************************************************************************\
  2. *
  3. * File: GdiCache.inl
  4. *
  5. * History:
  6. * 1/18/2000: JStall: Created
  7. *
  8. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  9. *
  10. \***************************************************************************/
  11. #if !defined(SERVICES__GdiCache_inl__INCLUDED)
  12. #define SERVICES__GdiCache_inl__INCLUDED
  13. #pragma once
  14. #include "OSAL.h"
  15. /***************************************************************************\
  16. *****************************************************************************
  17. *
  18. * class ObjectCache
  19. *
  20. *****************************************************************************
  21. \***************************************************************************/
  22. //------------------------------------------------------------------------------
  23. inline
  24. ObjectCache::ObjectCache()
  25. {
  26. #if ENABLE_DUMPCACHESTATS
  27. m_szName[0] = '\0';
  28. #endif // ENABLE_DUMPCACHESTATS
  29. m_cMaxFree = IsRemoteSession() ? 2 : 4;
  30. }
  31. //------------------------------------------------------------------------------
  32. inline
  33. ObjectCache::~ObjectCache()
  34. {
  35. AssertMsg(m_arAll.IsEmpty(), "Must have already free'd Context memory");
  36. AssertMsg(m_arFree.IsEmpty(), "Must have already free'd Context memory");
  37. }
  38. #if ENABLE_DUMPCACHESTATS
  39. //------------------------------------------------------------------------------
  40. inline void
  41. ObjectCache::SetName(LPCSTR pszName)
  42. {
  43. strcpy(m_szName, pszName);
  44. }
  45. #endif // ENABLE_DUMPCACHESTATS
  46. /***************************************************************************\
  47. *****************************************************************************
  48. *
  49. * GdiObjectCacheT<>
  50. *
  51. *****************************************************************************
  52. \***************************************************************************/
  53. //------------------------------------------------------------------------------
  54. template <class T>
  55. inline T
  56. GdiObjectCacheT<T>::Get()
  57. {
  58. return static_cast<T> (Pop());
  59. }
  60. //------------------------------------------------------------------------------
  61. template <class T>
  62. inline void
  63. GdiObjectCacheT<T>::Release(T hObj)
  64. {
  65. Push(hObj);
  66. }
  67. //------------------------------------------------------------------------------
  68. template <class T>
  69. void
  70. GdiObjectCacheT<T>::DestroyObject(void * pObj)
  71. {
  72. #if DBG
  73. SetLastError(0);
  74. BOOL fSuccess = ::DeleteObject((HGDIOBJ) pObj);
  75. if (!fSuccess) {
  76. DWORD dwErr = GetLastError();
  77. Trace("LastError: %d (0x%p)\n", dwErr, dwErr);
  78. }
  79. AssertMsg(fSuccess, "Ensure successfully deleted");
  80. #else // DBG
  81. ::DeleteObject((HGDIOBJ) pObj);
  82. #endif // DBG
  83. }
  84. /***************************************************************************\
  85. *****************************************************************************
  86. *
  87. * class GdiCache
  88. *
  89. *****************************************************************************
  90. \***************************************************************************/
  91. //------------------------------------------------------------------------------
  92. inline
  93. GdiCache::GdiCache()
  94. {
  95. #if ENABLE_DUMPCACHESTATS
  96. m_gocTempRgn.SetName("TempRgn");
  97. m_gocDisplayDC.SetName("DisplayDC");
  98. m_gocCompatDC.SetName("CompatDC");
  99. #endif // ENABLE_DUMPCACHESTATS
  100. }
  101. //------------------------------------------------------------------------------
  102. inline
  103. GdiCache::~GdiCache()
  104. {
  105. }
  106. //------------------------------------------------------------------------------
  107. inline void
  108. GdiCache::Destroy()
  109. {
  110. m_gocTempRgn.Destroy();
  111. m_gocDisplayDC.Destroy();
  112. m_gocCompatDC.Destroy();
  113. }
  114. //------------------------------------------------------------------------------
  115. inline HRGN
  116. GdiCache::GetTempRgn()
  117. {
  118. return m_gocTempRgn.Get();
  119. }
  120. //------------------------------------------------------------------------------
  121. inline void
  122. GdiCache::ReleaseTempRgn(HRGN hrgn)
  123. {
  124. m_gocTempRgn.Release(hrgn);
  125. }
  126. //------------------------------------------------------------------------------
  127. inline HDC
  128. GdiCache::GetTempDC()
  129. {
  130. return m_gocDisplayDC.Get();
  131. }
  132. //------------------------------------------------------------------------------
  133. inline void
  134. GdiCache::ReleaseTempDC(HDC hdc)
  135. {
  136. m_gocDisplayDC.Release(hdc);
  137. }
  138. //------------------------------------------------------------------------------
  139. inline HDC
  140. GdiCache::GetCompatibleDC()
  141. {
  142. return m_gocCompatDC.Get();
  143. }
  144. //------------------------------------------------------------------------------
  145. inline void
  146. GdiCache::ReleaseCompatibleDC(HDC hdc)
  147. {
  148. m_gocCompatDC.Release(hdc);
  149. }
  150. #endif // SERVICES__GdiCache_inl__INCLUDED