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.

184 lines
5.4 KiB

  1. /***************************************************************************\
  2. *
  3. * File: GdiCache.h
  4. *
  5. * Description:
  6. * GdiCache.h defines the process-wide GDI cache that manages cached and
  7. * temporary GDI objects.
  8. *
  9. *
  10. * History:
  11. * 1/18/2000: JStall: Created
  12. *
  13. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  14. *
  15. \***************************************************************************/
  16. #if !defined(SERVICES__GdiCache_h__INCLUDED)
  17. #define SERVICES__GdiCache_h__INCLUDED
  18. #pragma once
  19. #define ENABLE_DUMPCACHESTATS 0 // Dump ObjectCache statistics
  20. /***************************************************************************\
  21. *****************************************************************************
  22. *
  23. * class ObjectCache
  24. *
  25. * ObjectCache declares a standard container used to cache temporary objects.
  26. * As new objects are requested, objects will be returned from the free list
  27. * of cached objects. If this list is empty, new objects will be created.
  28. * When an object is released, it is added to the free list, ready to be used
  29. * again.
  30. *
  31. *****************************************************************************
  32. \***************************************************************************/
  33. class ObjectCache
  34. {
  35. // Construction
  36. public:
  37. inline ObjectCache();
  38. inline ~ObjectCache();
  39. void Destroy();
  40. // Operations
  41. public:
  42. #if ENABLE_DUMPCACHESTATS
  43. inline void SetName(LPCSTR pszName);
  44. #endif
  45. // Implementation
  46. protected:
  47. void * Pop();
  48. void Push(void * pObj);
  49. virtual void * Build() PURE;
  50. virtual void DestroyObject(void * pObj) PURE;
  51. // Data
  52. private:
  53. GArrayF<void *>
  54. m_arAll; // Collection of all temporary objects
  55. GArrayF<void *>
  56. m_arFree; // Indicies of available temporary objects
  57. int m_cMaxFree; // Maximum number of free objects
  58. #if ENABLE_DUMPCACHESTATS
  59. char m_szName[256];
  60. #endif
  61. };
  62. /***************************************************************************\
  63. *****************************************************************************
  64. *
  65. * class GdiObjectCacheT
  66. *
  67. * GdiObjectCacheT implements an ObjectCache for GDI objects. To use this
  68. * class, derive from GdiObjectCacheT and provide a Build() function to
  69. * create new object instance.
  70. *
  71. *****************************************************************************
  72. \***************************************************************************/
  73. template <class T>
  74. class GdiObjectCacheT : public ObjectCache
  75. {
  76. public:
  77. inline T Get();
  78. inline void Release(T hObj);
  79. protected:
  80. virtual void DestroyObject(void * pObj);
  81. };
  82. /***************************************************************************\
  83. *****************************************************************************
  84. *
  85. * Specific implementations of GdiObjectCacheT<>
  86. *
  87. *****************************************************************************
  88. \***************************************************************************/
  89. //------------------------------------------------------------------------------
  90. class RgnCache : public GdiObjectCacheT<HRGN>
  91. {
  92. protected:
  93. virtual void * Build()
  94. {
  95. return ::CreateRectRgn(0, 0, 0, 0);
  96. }
  97. };
  98. //------------------------------------------------------------------------------
  99. class DisplayDCCache : public GdiObjectCacheT<HDC>
  100. {
  101. protected:
  102. virtual void * Build()
  103. {
  104. return CreateDC("DISPLAY", NULL, NULL, NULL);
  105. }
  106. };
  107. //------------------------------------------------------------------------------
  108. class CompatibleDCCache : public GdiObjectCacheT<HDC>
  109. {
  110. protected:
  111. virtual void * Build()
  112. {
  113. HDC hdcDesk = ::GetDC(NULL);
  114. HDC hdc = ::CreateCompatibleDC(hdcDesk);
  115. ::ReleaseDC(NULL, hdcDesk);
  116. return hdc;
  117. }
  118. };
  119. /***************************************************************************\
  120. *****************************************************************************
  121. *
  122. * class GdiCache
  123. *
  124. * GdiCache caches frequently used GDI objects. By abstracting out how these
  125. * objects are created and maintained, the large number of temporary objects
  126. * used in DirectUser can be easily tweaked for performance and memory tuning.
  127. *
  128. *****************************************************************************
  129. \***************************************************************************/
  130. //------------------------------------------------------------------------------
  131. class GdiCache
  132. {
  133. // Construction
  134. public:
  135. inline GdiCache();
  136. inline ~GdiCache();
  137. inline void Destroy();
  138. // Operations
  139. public:
  140. inline HRGN GetTempRgn();
  141. inline void ReleaseTempRgn(HRGN hrgn);
  142. inline HDC GetTempDC();
  143. inline void ReleaseTempDC(HDC hdc);
  144. inline HDC GetCompatibleDC();
  145. inline void ReleaseCompatibleDC(HDC hdc);
  146. // Data
  147. private:
  148. RgnCache m_gocTempRgn; // Temporary regions
  149. DisplayDCCache m_gocDisplayDC; // Display DC's
  150. CompatibleDCCache m_gocCompatDC; // Compatible DC's
  151. };
  152. #include "GdiCache.inl"
  153. #endif // SERVICES__GdiCache_h__INCLUDED