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.

136 lines
2.9 KiB

  1. #include "pch.cpp"
  2. #pragma hdrstop
  3. CHandleFactory::CHandleFactory() : m_Handles()
  4. {
  5. m_Free = __INVALIDHANDLE;
  6. }
  7. CHandleFactory::CHandleFactory(DWORD dwGrowSize) : m_Handles()
  8. {
  9. m_Free = __INVALIDHANDLE;
  10. m_Handles.SetGrowSize(dwGrowSize);
  11. }
  12. DWORD
  13. CHandleFactory::CreateNewHandle( LPD3DBASEOBJ pObj )
  14. {
  15. DWORD handle = m_Free;
  16. if (m_Free != __INVALIDHANDLE)
  17. {
  18. m_Free = m_Handles[m_Free].m_Next;
  19. }
  20. else
  21. {
  22. handle = m_Handles.GetSize();
  23. m_Free = handle + 1;
  24. if( FAILED(m_Handles.Grow( m_Free )) )
  25. return __INVALIDHANDLE;
  26. DWORD dwSize = m_Handles.GetSize();
  27. for( DWORD i = handle; i<dwSize; i++ )
  28. {
  29. m_Handles[i].m_Next = i+1;
  30. }
  31. m_Handles[dwSize-1].m_Next = __INVALIDHANDLE;
  32. }
  33. #if DBG
  34. DDASSERT(m_Handles[handle].m_tag == 0);
  35. m_Handles[handle].m_tag = 1;
  36. #endif
  37. DDASSERT(m_Handles[handle].m_pObj == NULL);
  38. m_Handles[handle].m_pObj = pObj;
  39. return handle;
  40. }
  41. LPD3DBASEOBJ
  42. CHandleFactory::GetObject( DWORD dwHandle ) const
  43. {
  44. if( m_Handles.Check( dwHandle ) )
  45. {
  46. return m_Handles[dwHandle].m_pObj;
  47. }
  48. else
  49. {
  50. // The handle doesnt exist
  51. return NULL;
  52. }
  53. }
  54. BOOL
  55. CHandleFactory::SetObject( DWORD dwHandle, LPD3DBASEOBJ pObject)
  56. {
  57. if( m_Handles.Check( dwHandle ) )
  58. {
  59. m_Handles[dwHandle].m_pObj = pObject;
  60. return TRUE;
  61. }
  62. else
  63. {
  64. // The handle doesnt exist
  65. return FALSE;
  66. }
  67. }
  68. void
  69. CHandleFactory::ReleaseHandle(DWORD handle, BOOL bDeleteObject)
  70. {
  71. DDASSERT(handle < m_Handles.GetSize());
  72. #if DBG
  73. DDASSERT(m_Handles[handle].m_tag != 0);
  74. m_Handles[handle].m_tag = 0;
  75. #endif
  76. if( m_Handles[handle].m_pObj)
  77. {
  78. if (bDeleteObject)
  79. delete m_Handles[handle].m_pObj;
  80. m_Handles[handle].m_pObj = NULL;
  81. }
  82. m_Handles[handle].m_Next = m_Free;
  83. m_Free = handle;
  84. }
  85. //////////////////////////////////////////////////////////////////////////////
  86. DWORD
  87. CVShaderHandleFactory::CreateNewHandle( LPVSHADER pVShader )
  88. {
  89. DWORD dwHandle = CHandleFactory::CreateNewHandle( (LPD3DBASEOBJ)pVShader );
  90. // Now munge the handle. The algorithm is to shift left by one and
  91. // set the LSB to 1.
  92. dwHandle <<= 1;
  93. return (dwHandle | 0x1);
  94. }
  95. LPD3DBASEOBJ
  96. CVShaderHandleFactory::GetObject( DWORD dwHandle ) const
  97. {
  98. DWORD dwIndex = dwHandle >> 1;
  99. return CHandleFactory::GetObject( dwIndex );
  100. }
  101. BOOL
  102. CVShaderHandleFactory::SetObject( DWORD dwHandle, LPD3DBASEOBJ pObject)
  103. {
  104. DWORD dwIndex = dwHandle >> 1;
  105. return CHandleFactory::SetObject( dwIndex, pObject );
  106. }
  107. void
  108. CVShaderHandleFactory::ReleaseHandle(DWORD dwHandle, BOOL bDeleteObject)
  109. {
  110. DWORD dwIndex = dwHandle >> 1;
  111. CHandleFactory::ReleaseHandle( dwIndex, bDeleteObject );
  112. }