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.

109 lines
3.1 KiB

  1. #ifndef TEXMAN_INCLUDED
  2. #define TEXMAN_INCLUDED
  3. typedef class TextureCacheManager *LPTextureCacheManager;
  4. class TextureHeap
  5. {
  6. enum { InitialSize = 1023 };
  7. DWORD m_next, m_size;
  8. LPDIRECT3DTEXTUREI *m_data_p;
  9. DWORD parent(DWORD k) const { return k / 2; }
  10. DWORD lchild(DWORD k) const { return k * 2; }
  11. DWORD rchild(DWORD k) const { return k * 2 + 1; }
  12. void heapify(DWORD k);
  13. public:
  14. TextureHeap(DWORD size = InitialSize);
  15. ~TextureHeap();
  16. bool Initialize();
  17. DWORD length() const { return m_next - 1; }
  18. const LPDIRECT3DTEXTUREI minCost() const { return m_data_p[1]; }
  19. bool add(LPDIRECT3DTEXTUREI);
  20. LPDIRECT3DTEXTUREI extractMin();
  21. LPDIRECT3DTEXTUREI extractMax();
  22. LPDIRECT3DTEXTUREI extractNotInScene(DWORD dwScene);
  23. void del(DWORD k);
  24. void update(DWORD k, BOOL inuse, DWORD priority, DWORD ticks);
  25. void resetAllTimeStamps(DWORD ticks);
  26. };
  27. class TextureCacheManager {
  28. TextureHeap *m_heap_p;
  29. unsigned int tcm_ticks, m_dwScene, m_dwNumHeaps;
  30. LPDIRECT3DI lpDirect3DI;
  31. #if COLLECTSTATS
  32. D3DDEVINFO_TEXTUREMANAGER m_stats;
  33. #endif
  34. // Free the LRU texture
  35. BOOL FreeTextures(DWORD dwStage, DWORD dwCount);
  36. public:
  37. //remove all HW handles and release surface
  38. void remove(LPDIRECT3DTEXTUREI lpD3DTexI);
  39. HRESULT allocNode(LPDIRECT3DTEXTUREI lpD3DTexI, LPDIRECT3DDEVICEI lpDevI);
  40. TextureCacheManager(LPDIRECT3DI lpD3DI);
  41. ~TextureCacheManager();
  42. HRESULT Initialize();
  43. void RemoveFromHeap(LPDIRECT3DTEXTUREI lpD3DTexI)
  44. {
  45. m_heap_p[lpD3DTexI->ddsd.dwTextureStage].del(lpD3DTexI->m_dwHeapIndex);
  46. }
  47. void UpdatePriority(LPDIRECT3DTEXTUREI lpD3DTexI)
  48. {
  49. if(lpD3DTexI->m_dwHeapIndex)
  50. m_heap_p[lpD3DTexI->ddsd.dwTextureStage].update(lpD3DTexI->m_dwHeapIndex, lpD3DTexI->m_bInUse, lpD3DTexI->m_dwPriority, lpD3DTexI->m_dwTicks);
  51. }
  52. #if COLLECTSTATS
  53. void IncTotSz(DWORD dwSize)
  54. {
  55. ++m_stats.dwTotalManaged;
  56. m_stats.dwTotalBytes += dwSize;
  57. }
  58. void DecTotSz(DWORD dwSize)
  59. {
  60. --m_stats.dwTotalManaged;
  61. m_stats.dwTotalBytes -= dwSize;
  62. }
  63. void IncNumSetTexInVid()
  64. {
  65. ++m_stats.dwNumUsedTexInVid;
  66. }
  67. void IncNumTexturesSet()
  68. {
  69. ++m_stats.dwNumTexturesUsed;
  70. }
  71. void IncBytesDownloaded(LPDDRAWI_DDRAWSURFACE_LCL lpLcl, LPRECT lpRect)
  72. {
  73. m_stats.dwApproxBytesDownloaded += BytesDownloaded(lpLcl, lpRect);
  74. }
  75. void ResetStatCounters()
  76. {
  77. m_stats.bThrashing = 0;
  78. m_stats.dwApproxBytesDownloaded = 0;
  79. m_stats.dwNumEvicts = 0;
  80. m_stats.dwNumVidCreates = 0;
  81. m_stats.dwNumUsedTexInVid = 0;
  82. m_stats.dwNumTexturesUsed = 0;
  83. }
  84. void GetStats(LPD3DDEVINFO_TEXTUREMANAGER stats)
  85. {
  86. memcpy(stats, &m_stats, sizeof(D3DDEVINFO_TEXTUREMANAGER));
  87. }
  88. #endif
  89. void EvictTextures(); // Empty the entire cache
  90. BOOL CheckIfLost(); // check if any of the managed textures are lost
  91. void TimeStamp(LPDIRECT3DTEXTUREI);
  92. void SceneStamp() { ++m_dwScene; }
  93. };
  94. #endif