gl_image_dxgi.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2017 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. #ifndef UI_GL_GL_IMAGE_DXGI_H_
  5. #define UI_GL_GL_IMAGE_DXGI_H_
  6. #include <DXGI1_2.h>
  7. #include <d3d11.h>
  8. #include <wrl/client.h>
  9. #include "base/win/scoped_handle.h"
  10. #include "ui/gfx/buffer_types.h"
  11. #include "ui/gl/gl_export.h"
  12. #include "ui/gl/gl_image.h"
  13. typedef void* EGLStreamKHR;
  14. typedef void* EGLConfig;
  15. typedef void* EGLSurface;
  16. namespace gl {
  17. class GL_EXPORT GLImageDXGI : public GLImage {
  18. public:
  19. GLImageDXGI(const gfx::Size& size, EGLStreamKHR stream);
  20. // Safe downcast. Returns nullptr on failure.
  21. static GLImageDXGI* FromGLImage(GLImage* image);
  22. // GLImage implementation.
  23. BindOrCopy ShouldBindOrCopy() override;
  24. bool BindTexImage(unsigned target) override;
  25. bool CopyTexImage(unsigned target) override;
  26. bool CopyTexSubImage(unsigned target,
  27. const gfx::Point& offset,
  28. const gfx::Rect& rect) override;
  29. void Flush() override;
  30. unsigned GetInternalFormat() override;
  31. unsigned GetDataType() override;
  32. gfx::Size GetSize() override;
  33. Type GetType() const override;
  34. void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
  35. uint64_t process_tracing_id,
  36. const std::string& dump_name) override;
  37. void ReleaseTexImage(unsigned target) override;
  38. const gfx::ColorSpace& color_space() const { return color_space_; }
  39. Microsoft::WRL::ComPtr<IDXGIKeyedMutex> keyed_mutex() { return keyed_mutex_; }
  40. size_t level() const { return level_; }
  41. Microsoft::WRL::ComPtr<ID3D11Texture2D> texture() { return texture_; }
  42. bool InitializeHandle(base::win::ScopedHandle handle,
  43. uint32_t level,
  44. gfx::BufferFormat format);
  45. void SetTexture(const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture,
  46. size_t level);
  47. protected:
  48. ~GLImageDXGI() override;
  49. gfx::BufferFormat buffer_format_ = gfx::BufferFormat::BGRA_8888;
  50. base::win::ScopedHandle handle_;
  51. Microsoft::WRL::ComPtr<IDXGIKeyedMutex> keyed_mutex_;
  52. size_t level_ = 0;
  53. gfx::Size size_;
  54. EGLSurface surface_ = nullptr;
  55. EGLStreamKHR stream_ = nullptr;
  56. Microsoft::WRL::ComPtr<ID3D11Texture2D> texture_;
  57. };
  58. // This copies to a new texture on bind.
  59. class GL_EXPORT CopyingGLImageDXGI : public GLImageDXGI {
  60. public:
  61. CopyingGLImageDXGI(const Microsoft::WRL::ComPtr<ID3D11Device>& d3d11_device,
  62. const gfx::Size& size,
  63. EGLStreamKHR stream);
  64. bool Initialize();
  65. bool InitializeVideoProcessor(
  66. const Microsoft::WRL::ComPtr<ID3D11VideoProcessor>& video_processor,
  67. const Microsoft::WRL::ComPtr<ID3D11VideoProcessorEnumerator>& enumerator);
  68. void UnbindFromTexture();
  69. // GLImage implementation.
  70. bool BindTexImage(unsigned target) override;
  71. private:
  72. ~CopyingGLImageDXGI() override;
  73. bool copied_ = false;
  74. Microsoft::WRL::ComPtr<ID3D11VideoDevice> video_device_;
  75. Microsoft::WRL::ComPtr<ID3D11VideoContext> video_context_;
  76. Microsoft::WRL::ComPtr<ID3D11VideoProcessor> d3d11_processor_;
  77. Microsoft::WRL::ComPtr<ID3D11VideoProcessorEnumerator> enumerator_;
  78. Microsoft::WRL::ComPtr<ID3D11Device> d3d11_device_;
  79. Microsoft::WRL::ComPtr<ID3D11Texture2D> decoder_copy_texture_;
  80. Microsoft::WRL::ComPtr<ID3D11VideoProcessorOutputView> output_view_;
  81. };
  82. }
  83. #endif // UI_GL_GL_IMAGE_DXGI_H_