IGraphicsDevice.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include <memory>
  3. #include <IUnityRenderingExtensions.h>
  4. #include <api/video/i420_buffer.h>
  5. #include "PlatformBase.h"
  6. #include "ProfilerMarkerFactory.h"
  7. #include "ScopedProfiler.h"
  8. #if CUDA_PLATFORM
  9. #include "Cuda/ICudaDevice.h"
  10. #endif
  11. namespace unity
  12. {
  13. namespace webrtc
  14. {
  15. using NativeTexPtr = void*;
  16. class ITexture2D;
  17. struct GpuMemoryBufferHandle;
  18. class ProfilerMarkerFactory;
  19. class IGraphicsDevice
  20. #if CUDA_PLATFORM
  21. : public ICudaDevice
  22. #endif
  23. {
  24. public:
  25. IGraphicsDevice(UnityGfxRenderer renderer, ProfilerMarkerFactory* profiler)
  26. : m_gfxRenderer(renderer)
  27. , m_profiler(profiler)
  28. {
  29. }
  30. #if CUDA_PLATFORM
  31. virtual ~IGraphicsDevice() override = default;
  32. #else
  33. virtual ~IGraphicsDevice() = default;
  34. #endif
  35. virtual bool InitV() = 0;
  36. virtual void ShutdownV() = 0;
  37. virtual ITexture2D*
  38. CreateDefaultTextureV(uint32_t width, uint32_t height, UnityRenderingExtTextureFormat textureFormat) = 0;
  39. virtual void* GetEncodeDevicePtrV() = 0;
  40. virtual bool CopyResourceV(ITexture2D* dest, ITexture2D* src) = 0;
  41. virtual bool CopyResourceFromNativeV(ITexture2D* dest, NativeTexPtr nativeTexturePtr) = 0;
  42. virtual UnityGfxRenderer GetGfxRenderer() const { return m_gfxRenderer; }
  43. virtual std::unique_ptr<GpuMemoryBufferHandle> Map(ITexture2D* texture) = 0;
  44. virtual bool WaitSync(const ITexture2D* texture, uint64_t nsTimeout = 0) { return true; }
  45. virtual bool ResetSync(const ITexture2D* texture) { return true; }
  46. virtual bool WaitIdleForTest() { return true; }
  47. // Required for software encoding
  48. virtual ITexture2D*
  49. CreateCPUReadTextureV(uint32_t width, uint32_t height, UnityRenderingExtTextureFormat textureFormat) = 0;
  50. virtual rtc::scoped_refptr<::webrtc::I420Buffer> ConvertRGBToI420(ITexture2D* tex) = 0;
  51. protected:
  52. UnityGfxRenderer m_gfxRenderer;
  53. ProfilerMarkerFactory* m_profiler;
  54. };
  55. } // end namespace webrtc
  56. } // end namespace unity