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.

53 lines
2.3 KiB

  1. #ifndef TEXMAN_INCLUDED
  2. #define TEXMAN_INCLUDED
  3. #define MAXLOGTEXSIZE 25
  4. typedef class TextureCacheManager *LPTextureCacheManager;
  5. /*
  6. The texture cache manager does all cache management. The data structure used is
  7. a hash table with the hash variable being the log (base 2) of the total size of
  8. the texture in pixels. Each bucket corresponding to a texture size is a list of
  9. CacheInfos. The LRU algorithm works as follows:
  10. 1. Is the texture corresponding to the GL handle in the cache?
  11. 2. If it is, increment the timestamp and return the D3D handle.
  12. 3. If not, attempt to allocate a DirectDraw surface. If there is no memory,
  13. we need to free some texture and try again (see step 4), else add a CacheInfo
  14. corresponding to this newly allocated DirectDraw surface, QI it for a texture
  15. object and return the D3D handle.
  16. 4. We have to reuse some old textures, so try to find the oldest texture of the
  17. same size. If we find such a texture, just Blt the new texture onto the old.
  18. If a texture of the same size is not available, we freeup some bigger textures
  19. and go to step 3.
  20. */
  21. class TextureCacheManager {
  22. LPD3DBUCKET tcm_bucket[MAXLOGTEXSIZE];
  23. unsigned int tcm_ticks, numvidtex;
  24. LPDIRECT3DI lpDirect3DI;
  25. // Replace a texture of size k with a new texture corresponding to glhandle
  26. //LPD3DBUCKET replace(int k, LPDIRECT3DTEXTUREI lpD3DTexI);
  27. // Free the oldest texture of same size as lpD3DTexI
  28. BOOL freeNode(LPD3DI_TEXTUREBLOCK lpBlock, LPD3DBUCKET* lplpBucket);
  29. //remove any HW handle that's not with lpBlock->lpDevI,save lpBlock->hTex,keep surface
  30. void replace(LPD3DBUCKET bucket,LPD3DI_TEXTUREBLOCK lpBlock);
  31. public:
  32. HRESULT allocNode(LPD3DI_TEXTUREBLOCK lpBlock);
  33. TextureCacheManager(LPDIRECT3DI lpD3DI);
  34. ~TextureCacheManager();
  35. //remove all HW handles and release surface
  36. void remove(LPD3DBUCKET bucket);
  37. // Empty the entire cache
  38. void EvictTextures();
  39. void cleanup(); // clean up invalidated nodes by destructors of texture/texture3
  40. BOOL CheckIfLost(); // check if any of the managed textures are lost
  41. inline void TimeStamp(LPD3DBUCKET bucket){bucket->ticks=tcm_ticks++;}
  42. inline void TimeStamp(){++tcm_ticks;}
  43. };
  44. #endif