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 5 #ifndef UI_GL_GL_IMAGE_D3D_H_ 6 #define UI_GL_GL_IMAGE_D3D_H_ 7 8 #include <d3d11.h> 9 #include <dxgi1_2.h> 10 #include <windows.h> 11 #include <wrl/client.h> 12 13 #include "ui/gl/gl_export.h" 14 #include "ui/gl/gl_image.h" 15 16 namespace gl { 17 18 class GL_EXPORT GLImageD3D : public GLImage { 19 public: 20 // Creates a GLImage backed by a D3D11 |texture| with given |size| and GL 21 // unsized |internal_format|, optionally associated with |swap_chain|. The 22 // |internal_format| and |data_type| are passed to ANGLE and used for GL 23 // operations. |internal_format| may be different from the internal format 24 // associated with the DXGI_FORMAT of the texture (e.g. RGB instead of 25 // BGRA_EXT for DXGI_FORMAT_B8G8R8A8_UNORM). |data_type| should match the 26 // data type accociated with the DXGI_FORMAT of the texture. 27 GLImageD3D(const gfx::Size& size, 28 unsigned internal_format, 29 unsigned data_type, 30 Microsoft::WRL::ComPtr<ID3D11Texture2D> texture, 31 Microsoft::WRL::ComPtr<IDXGISwapChain1> swap_chain); 32 33 // Safe downcast. Returns nullptr on failure. 34 static GLImageD3D* FromGLImage(GLImage* image); 35 36 bool Initialize(); 37 38 // GLImage implementation 39 Type GetType() const override; 40 BindOrCopy ShouldBindOrCopy() override; 41 gfx::Size GetSize() override; 42 unsigned GetInternalFormat() override; 43 unsigned GetDataType() override; 44 bool BindTexImage(unsigned target) override; ReleaseTexImage(unsigned target)45 void ReleaseTexImage(unsigned target) override {} 46 bool CopyTexImage(unsigned target) override; 47 bool CopyTexSubImage(unsigned target, 48 const gfx::Point& offset, 49 const gfx::Rect& rect) override; Flush()50 void Flush() override {} 51 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 52 uint64_t process_tracing_id, 53 const std::string& dump_name) override; 54 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, 55 int z_order, 56 gfx::OverlayTransform transform, 57 const gfx::Rect& bounds_rect, 58 const gfx::RectF& crop_rect, 59 bool enable_blend, 60 std::unique_ptr<gfx::GpuFence> gpu_fence) override; 61 texture()62 const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture() const { 63 return texture_; 64 } 65 swap_chain()66 const Microsoft::WRL::ComPtr<IDXGISwapChain1>& swap_chain() const { 67 return swap_chain_; 68 } 69 70 private: 71 ~GLImageD3D() override; 72 73 const gfx::Size size_; 74 const unsigned internal_format_; // GLenum 75 const unsigned data_type_; // GLenum 76 void* egl_image_ = nullptr; // EGLImageKHR 77 Microsoft::WRL::ComPtr<ID3D11Texture2D> texture_; 78 Microsoft::WRL::ComPtr<IDXGISwapChain1> swap_chain_; 79 80 DISALLOW_COPY_AND_ASSIGN(GLImageD3D); 81 }; 82 83 } // namespace gl 84 85 #endif // UI_GL_GL_IMAGE_D3D_H_ 86