d3d11_video_processor_proxy_unittest.cc 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <random>
  5. #include <utility>
  6. #include "base/callback_helpers.h"
  7. #include "media/base/win/d3d11_mocks.h"
  8. #include "media/gpu/windows/d3d11_copying_texture_wrapper.h"
  9. #include "media/gpu/windows/d3d11_texture_wrapper.h"
  10. #include "media/gpu/windows/d3d11_video_processor_proxy.h"
  11. #include "testing/gmock/include/gmock/gmock.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. using ::testing::_;
  14. using ::testing::DoAll;
  15. using ::testing::Return;
  16. using ::testing::SetArgPointee;
  17. namespace media {
  18. using MockD3D11VideoDevice = Microsoft::WRL::ComPtr<D3D11VideoDeviceMock>;
  19. using MockD3D11DeviceContext = Microsoft::WRL::ComPtr<D3D11DeviceContextMock>;
  20. using MockD3D11VideoContext = Microsoft::WRL::ComPtr<D3D11VideoContextMock>;
  21. using MockD3D11VideoProcessor = Microsoft::WRL::ComPtr<D3D11VideoProcessorMock>;
  22. using MockD3D11VideoProcessorEnumerator =
  23. Microsoft::WRL::ComPtr<D3D11VideoProcessorEnumeratorMock>;
  24. class D3D11VideoProcessorProxyUnittest : public ::testing::Test {
  25. public:
  26. MockD3D11VideoDevice dev_;
  27. MockD3D11DeviceContext ctx_;
  28. MockD3D11VideoContext vctx_;
  29. MockD3D11VideoProcessorEnumerator enumerator_;
  30. MockD3D11VideoProcessor proc_;
  31. scoped_refptr<VideoProcessorProxy> CreateProxy() {
  32. dev_ = MakeComPtr<D3D11VideoDeviceMock>();
  33. ctx_ = MakeComPtr<D3D11DeviceContextMock>();
  34. vctx_ = MakeComPtr<D3D11VideoContextMock>();
  35. proc_ = MakeComPtr<D3D11VideoProcessorMock>();
  36. enumerator_ = MakeComPtr<D3D11VideoProcessorEnumeratorMock>();
  37. EXPECT_CALL(*dev_.Get(), CreateVideoProcessorEnumerator(_, _))
  38. .WillOnce(SetComPointeeAndReturnOk<1>(enumerator_.Get()));
  39. EXPECT_CALL(*dev_.Get(), CreateVideoProcessor(_, _, _))
  40. .WillOnce(SetComPointeeAndReturnOk<2>(proc_.Get()));
  41. EXPECT_CALL(*ctx_.Get(), QueryInterface(_, _))
  42. .WillOnce(SetComPointeeAndReturnOk<1>(vctx_.Get()));
  43. return base::MakeRefCounted<VideoProcessorProxy>(dev_, ctx_);
  44. }
  45. // Pull a random pointer off the stack, rather than relying on nullptrs.
  46. template <typename T>
  47. T* CreateGarbagePtr() {
  48. int foo;
  49. void* local = &foo;
  50. return static_cast<T*>(local);
  51. }
  52. };
  53. // The processor proxy wraps the VideoDevice/VideoContext and stores some of the
  54. // d3d11 types. Make sure that the arguments we give these methods are passed
  55. // through correctly.
  56. TEST_F(D3D11VideoProcessorProxyUnittest, EnsureMethodPassthrough) {
  57. auto proxy = CreateProxy();
  58. // Garbage pointers are used because the proxy just passes them along and does
  59. // absolutely nothing with them.
  60. auto* texture = CreateGarbagePtr<ID3D11Texture2D>();
  61. auto* out_desc = CreateGarbagePtr<D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC>();
  62. auto* in_desc = CreateGarbagePtr<D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC>();
  63. auto* out_view = CreateGarbagePtr<ID3D11VideoProcessorOutputView>();
  64. auto* streams = CreateGarbagePtr<D3D11_VIDEO_PROCESSOR_STREAM>();
  65. EXPECT_CALL(*dev_.Get(), CreateVideoProcessorOutputView(
  66. texture, enumerator_.Get(), out_desc, nullptr));
  67. EXPECT_CALL(*dev_.Get(), CreateVideoProcessorInputView(
  68. texture, enumerator_.Get(), in_desc, nullptr));
  69. EXPECT_CALL(*vctx_.Get(),
  70. VideoProcessorBlt(proc_.Get(), out_view, 6, 7, streams));
  71. EXPECT_TRUE(proxy->Init(0, 0).is_ok());
  72. proxy->CreateVideoProcessorOutputView(texture, out_desc, nullptr);
  73. proxy->CreateVideoProcessorInputView(texture, in_desc, nullptr);
  74. proxy->VideoProcessorBlt(out_view, 6, 7, streams);
  75. }
  76. } // namespace media