VideoFrameTest.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "pch.h"
  2. #include "GpuMemoryBuffer.h"
  3. #include "VideoFrameUtil.h"
  4. #include "GraphicsDevice/ITexture2D.h"
  5. #include "GraphicsDeviceContainer.h"
  6. namespace unity
  7. {
  8. namespace webrtc
  9. {
  10. class VideoFrameTest : public testing::TestWithParam<UnityGfxRenderer>
  11. {
  12. public:
  13. explicit VideoFrameTest()
  14. : container_(CreateGraphicsDeviceContainer(GetParam()))
  15. , device_(container_->device())
  16. {
  17. }
  18. protected:
  19. void SetUp() override
  20. {
  21. if (!device_)
  22. GTEST_SKIP() << "The graphics driver is not installed on the device.";
  23. std::unique_ptr<ITexture2D> texture(device_->CreateDefaultTextureV(kWidth, kHeight, kFormat));
  24. EXPECT_TRUE(device_->WaitIdleForTest());
  25. if (!texture)
  26. GTEST_SKIP() << "The graphics driver cannot create a texture resource.";
  27. }
  28. std::unique_ptr<GraphicsDeviceContainer> container_;
  29. IGraphicsDevice* device_;
  30. const uint32_t kWidth = 256;
  31. const uint32_t kHeight = 256;
  32. const Size kSize = { static_cast<int>(kWidth), static_cast<int>(kHeight) };
  33. const UnityRenderingExtTextureFormat kFormat = kUnityRenderingExtFormatR8G8B8A8_SRGB;
  34. };
  35. TEST_P(VideoFrameTest, WrapExternalGpuMemoryBuffer)
  36. {
  37. std::unique_ptr<ITexture2D> tex = std::unique_ptr<ITexture2D>(
  38. device_->CreateDefaultTextureV(kWidth, kHeight, kFormat));
  39. EXPECT_TRUE(device_->WaitIdleForTest());
  40. rtc::scoped_refptr<VideoFrame> videoFrame = CreateTestFrame(device_, tex.get(), kFormat);
  41. EXPECT_TRUE(device_->WaitIdleForTest());
  42. ASSERT_NE(videoFrame, nullptr);
  43. }
  44. INSTANTIATE_TEST_SUITE_P(GfxDevice, VideoFrameTest, testing::ValuesIn(supportedGfxDevices));
  45. } // end namespace webrtc
  46. } // end namespace unity