Source code of Windows XP (NT5)
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.

114 lines
2.6 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: d3dmem.h
  6. * Content: Direct3D memory access include file
  7. *
  8. ***************************************************************************/
  9. #ifndef _D3DMEM_H_
  10. #define _D3DMEM_H_
  11. #include "vbuffer.hpp"
  12. class CD3DHal;
  13. /*
  14. * Register a set of functions to be used in place of malloc
  15. * and free for memory allocation. The functions D3DMalloc
  16. * and D3DFree will use these functions. The default is to use the
  17. * ANSI C library routines malloc and free.
  18. */
  19. typedef LPVOID (*D3DMALLOCFUNCTION)(size_t);
  20. typedef VOID (*D3DFREEFUNCTION)(LPVOID);
  21. /*
  22. * Allocate size bytes of memory and return a pointer to it in *p_return.
  23. * Returns D3DERR_BADALLOC with *p_return unchanged if the allocation fails.
  24. */
  25. HRESULT D3DAPI D3DMalloc(LPVOID* p_return, size_t size);
  26. /*
  27. * Free a block of memory previously allocated with D3DMalloc
  28. */
  29. VOID D3DAPI D3DFree(LPVOID p);
  30. HRESULT MallocAligned(void** p_return, size_t size);
  31. void FreeAligned(void* p);
  32. #define __USEGLOBALNEWANDDELETE
  33. #ifndef __USEGLOBALNEWANDDELETE
  34. /* Base class for all D3D classes to use our special allocation functions everywhere */
  35. class CD3DAlloc
  36. {
  37. public:
  38. void* operator new(size_t s) const
  39. {
  40. void *p;
  41. MallocAligned(&p,s);
  42. return p;
  43. };
  44. void operator delete(void* p) const
  45. {
  46. FreeAligned(p);
  47. };
  48. };
  49. #define D3DNEW CD3DAlloc::new
  50. #define D3DDELETE CD3DAlloc::delete
  51. #else
  52. void* operator new(size_t s);
  53. void operator delete(void* p);
  54. #define D3DNEW ::new
  55. #define D3DDELETE ::delete
  56. #endif
  57. //---------------------------------------------------------------------
  58. // This class manages growing buffer, aligned to 32 byte boundary
  59. // Number if bytes should be power of 2.
  60. // D3DMalloc is used to allocate memory
  61. //
  62. class CAlignedBuffer32
  63. {
  64. public:
  65. CAlignedBuffer32()
  66. {
  67. size = 0;
  68. allocatedBuf = 0;
  69. alignedBuf = 0;
  70. }
  71. ~CAlignedBuffer32()
  72. {
  73. if (allocatedBuf)
  74. D3DFree(allocatedBuf);
  75. }
  76. // Returns aligned buffer address
  77. LPVOID GetAddress()
  78. {
  79. return alignedBuf;
  80. }
  81. // Returns aligned buffer size
  82. DWORD GetSize()
  83. {
  84. return size;
  85. }
  86. HRESULT Grow(DWORD dwSize);
  87. HRESULT CheckAndGrow(DWORD dwSize)
  88. {
  89. if (dwSize > size)
  90. return Grow(dwSize + 1024);
  91. else
  92. return D3D_OK;
  93. }
  94. protected:
  95. LPVOID allocatedBuf;
  96. LPVOID alignedBuf;
  97. DWORD size;
  98. };
  99. // Forward declarations
  100. class CD3DHal;
  101. class CD3DHalDP2;
  102. #endif //_D3DMEM_H_