directx.hpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of the copyright holders may not be used to endorse or promote products
  27. // derived from this software without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors as is and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall the copyright holders or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. // (including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort (including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. //M*/
  41. #ifndef OPENCV_CORE_DIRECTX_HPP
  42. #define OPENCV_CORE_DIRECTX_HPP
  43. #include "mat.hpp"
  44. #include "ocl.hpp"
  45. #if !defined(__d3d11_h__)
  46. struct ID3D11Device;
  47. struct ID3D11Texture2D;
  48. #endif
  49. #if !defined(__d3d10_h__)
  50. struct ID3D10Device;
  51. struct ID3D10Texture2D;
  52. #endif
  53. #if !defined(_D3D9_H_)
  54. struct IDirect3DDevice9;
  55. struct IDirect3DDevice9Ex;
  56. struct IDirect3DSurface9;
  57. #endif
  58. namespace cv { namespace directx {
  59. namespace ocl {
  60. using namespace cv::ocl;
  61. //! @addtogroup core_directx
  62. // This section describes OpenCL and DirectX interoperability.
  63. //
  64. // To enable DirectX support, configure OpenCV using CMake with WITH_DIRECTX=ON . Note, DirectX is
  65. // supported only on Windows.
  66. //
  67. // To use OpenCL functionality you should first initialize OpenCL context from DirectX resource.
  68. //
  69. //! @{
  70. // TODO static functions in the Context class
  71. //! @brief Creates OpenCL context from D3D11 device
  72. //
  73. //! @param pD3D11Device - pointer to D3D11 device
  74. //! @return Returns reference to OpenCL Context
  75. CV_EXPORTS Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device);
  76. //! @brief Creates OpenCL context from D3D10 device
  77. //
  78. //! @param pD3D10Device - pointer to D3D10 device
  79. //! @return Returns reference to OpenCL Context
  80. CV_EXPORTS Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device);
  81. //! @brief Creates OpenCL context from Direct3DDevice9Ex device
  82. //
  83. //! @param pDirect3DDevice9Ex - pointer to Direct3DDevice9Ex device
  84. //! @return Returns reference to OpenCL Context
  85. CV_EXPORTS Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex);
  86. //! @brief Creates OpenCL context from Direct3DDevice9 device
  87. //
  88. //! @param pDirect3DDevice9 - pointer to Direct3Device9 device
  89. //! @return Returns reference to OpenCL Context
  90. CV_EXPORTS Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9);
  91. //! @}
  92. } // namespace cv::directx::ocl
  93. //! @addtogroup core_directx
  94. //! @{
  95. //! @brief Converts InputArray to ID3D11Texture2D. If destination texture format is DXGI_FORMAT_NV12 then
  96. //! input UMat expected to be in BGR format and data will be downsampled and color-converted to NV12.
  97. //
  98. //! @note Note: Destination texture must be allocated by application. Function does memory copy from src to
  99. //! pD3D11Texture2D
  100. //
  101. //! @param src - source InputArray
  102. //! @param pD3D11Texture2D - destination D3D11 texture
  103. CV_EXPORTS void convertToD3D11Texture2D(InputArray src, ID3D11Texture2D* pD3D11Texture2D);
  104. //! @brief Converts ID3D11Texture2D to OutputArray. If input texture format is DXGI_FORMAT_NV12 then
  105. //! data will be upsampled and color-converted to BGR format.
  106. //
  107. //! @note Note: Destination matrix will be re-allocated if it has not enough memory to match texture size.
  108. //! function does memory copy from pD3D11Texture2D to dst
  109. //
  110. //! @param pD3D11Texture2D - source D3D11 texture
  111. //! @param dst - destination OutputArray
  112. CV_EXPORTS void convertFromD3D11Texture2D(ID3D11Texture2D* pD3D11Texture2D, OutputArray dst);
  113. //! @brief Converts InputArray to ID3D10Texture2D
  114. //
  115. //! @note Note: function does memory copy from src to
  116. //! pD3D10Texture2D
  117. //
  118. //! @param src - source InputArray
  119. //! @param pD3D10Texture2D - destination D3D10 texture
  120. CV_EXPORTS void convertToD3D10Texture2D(InputArray src, ID3D10Texture2D* pD3D10Texture2D);
  121. //! @brief Converts ID3D10Texture2D to OutputArray
  122. //
  123. //! @note Note: function does memory copy from pD3D10Texture2D
  124. //! to dst
  125. //
  126. //! @param pD3D10Texture2D - source D3D10 texture
  127. //! @param dst - destination OutputArray
  128. CV_EXPORTS void convertFromD3D10Texture2D(ID3D10Texture2D* pD3D10Texture2D, OutputArray dst);
  129. //! @brief Converts InputArray to IDirect3DSurface9
  130. //
  131. //! @note Note: function does memory copy from src to
  132. //! pDirect3DSurface9
  133. //
  134. //! @param src - source InputArray
  135. //! @param pDirect3DSurface9 - destination D3D10 texture
  136. //! @param surfaceSharedHandle - shared handle
  137. CV_EXPORTS void convertToDirect3DSurface9(InputArray src, IDirect3DSurface9* pDirect3DSurface9, void* surfaceSharedHandle = NULL);
  138. //! @brief Converts IDirect3DSurface9 to OutputArray
  139. //
  140. //! @note Note: function does memory copy from pDirect3DSurface9
  141. //! to dst
  142. //
  143. //! @param pDirect3DSurface9 - source D3D10 texture
  144. //! @param dst - destination OutputArray
  145. //! @param surfaceSharedHandle - shared handle
  146. CV_EXPORTS void convertFromDirect3DSurface9(IDirect3DSurface9* pDirect3DSurface9, OutputArray dst, void* surfaceSharedHandle = NULL);
  147. //! @brief Get OpenCV type from DirectX type
  148. //! @param iDXGI_FORMAT - enum DXGI_FORMAT for D3D10/D3D11
  149. //! @return OpenCV type or -1 if there is no equivalent
  150. CV_EXPORTS int getTypeFromDXGI_FORMAT(const int iDXGI_FORMAT); // enum DXGI_FORMAT for D3D10/D3D11
  151. //! @brief Get OpenCV type from DirectX type
  152. //! @param iD3DFORMAT - enum D3DTYPE for D3D9
  153. //! @return OpenCV type or -1 if there is no equivalent
  154. CV_EXPORTS int getTypeFromD3DFORMAT(const int iD3DFORMAT); // enum D3DTYPE for D3D9
  155. //! @}
  156. } } // namespace cv::directx
  157. #endif // OPENCV_CORE_DIRECTX_HPP