| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/ipc/service/direct_composition_surface_win.h" | 5 #include "gpu/ipc/service/direct_composition_surface_win.h" |
| 6 | 6 |
| 7 #include <d3d11_1.h> | 7 #include <d3d11_1.h> |
| 8 #include <dcomptypes.h> | 8 #include <dcomptypes.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 bool valid() const { return presents_.size() >= kPresentsToStore; } | 97 bool valid() const { return presents_.size() >= kPresentsToStore; } |
| 98 int composed_count() const { return composed_count_; } | 98 int composed_count() const { return composed_count_; } |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 std::deque<DXGI_FRAME_PRESENTATION_MODE> presents_; | 101 std::deque<DXGI_FRAME_PRESENTATION_MODE> presents_; |
| 102 int composed_count_ = 0; | 102 int composed_count_ = 0; |
| 103 | 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(PresentationHistory); | 104 DISALLOW_COPY_AND_ASSIGN(PresentationHistory); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 // This is the raw support info, which shouldn't depend on field trial state. |
| 108 bool HardwareSupportsOverlays() { |
| 109 if (!gl::GLSurfaceEGL::IsDirectCompositionSupported()) |
| 110 return false; |
| 111 |
| 112 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 113 if (command_line->HasSwitch(switches::kEnableDirectCompositionLayers)) |
| 114 return true; |
| 115 if (command_line->HasSwitch(switches::kDisableDirectCompositionLayers)) |
| 116 return false; |
| 117 |
| 118 // Before Windows 10 Anniversary Update (Redstone 1), overlay planes |
| 119 // wouldn't be assigned to non-UWP apps. |
| 120 if (base::win::GetVersion() < base::win::VERSION_WIN10_R1) |
| 121 return false; |
| 122 |
| 123 base::win::ScopedComPtr<ID3D11Device> d3d11_device = |
| 124 gl::QueryD3D11DeviceObjectFromANGLE(); |
| 125 DCHECK(d3d11_device); |
| 126 |
| 127 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; |
| 128 d3d11_device.QueryInterface(dxgi_device.Receive()); |
| 129 base::win::ScopedComPtr<IDXGIAdapter> dxgi_adapter; |
| 130 dxgi_device->GetAdapter(dxgi_adapter.Receive()); |
| 131 |
| 132 unsigned int i = 0; |
| 133 while (true) { |
| 134 base::win::ScopedComPtr<IDXGIOutput> output; |
| 135 if (FAILED(dxgi_adapter->EnumOutputs(i++, output.Receive()))) |
| 136 break; |
| 137 base::win::ScopedComPtr<IDXGIOutput3> output3; |
| 138 if (FAILED(output.QueryInterface(output3.Receive()))) |
| 139 continue; |
| 140 |
| 141 UINT flags = 0; |
| 142 if (FAILED(output3->CheckOverlaySupport(DXGI_FORMAT_YUY2, |
| 143 d3d11_device.Get(), &flags))) |
| 144 continue; |
| 145 |
| 146 // Direct-only support might be ok in some circumstances, but since the |
| 147 // overlay processor isn't set up to try to distinguish, only try to use |
| 148 // overlays when scaling's enabled. |
| 149 if (flags & DXGI_OVERLAY_SUPPORT_FLAG_SCALING) |
| 150 return true; |
| 151 } |
| 152 return false; |
| 153 } |
| 154 |
| 107 // Only one DirectComposition surface can be rendered into at a time. Track | 155 // Only one DirectComposition surface can be rendered into at a time. Track |
| 108 // here which IDCompositionSurface is being rendered into. If another context | 156 // here which IDCompositionSurface is being rendered into. If another context |
| 109 // is made current, then this surface will be suspended. | 157 // is made current, then this surface will be suspended. |
| 110 IDCompositionSurface* g_current_surface; | 158 IDCompositionSurface* g_current_surface; |
| 111 | 159 |
| 112 } // namespace | 160 } // namespace |
| 113 | 161 |
| 114 class DCLayerTree { | 162 class DCLayerTree { |
| 115 public: | 163 public: |
| 116 DCLayerTree(DirectCompositionSurfaceWin* surface, | 164 DCLayerTree(DirectCompositionSurfaceWin* surface, |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 : gl::GLSurfaceEGL(), | 839 : gl::GLSurfaceEGL(), |
| 792 child_window_(delegate, parent_window), | 840 child_window_(delegate, parent_window), |
| 793 vsync_provider_(std::move(vsync_provider)) {} | 841 vsync_provider_(std::move(vsync_provider)) {} |
| 794 | 842 |
| 795 DirectCompositionSurfaceWin::~DirectCompositionSurfaceWin() { | 843 DirectCompositionSurfaceWin::~DirectCompositionSurfaceWin() { |
| 796 Destroy(); | 844 Destroy(); |
| 797 } | 845 } |
| 798 | 846 |
| 799 // static | 847 // static |
| 800 bool DirectCompositionSurfaceWin::AreOverlaysSupported() { | 848 bool DirectCompositionSurfaceWin::AreOverlaysSupported() { |
| 801 if (!base::FeatureList::IsEnabled(switches::kDirectCompositionOverlays)) | 849 if (!HardwareSupportsOverlays()) |
| 802 return false; | 850 return false; |
| 803 | 851 |
| 804 if (!gl::GLSurfaceEGL::IsDirectCompositionSupported()) | 852 return base::FeatureList::IsEnabled(switches::kDirectCompositionOverlays); |
| 805 return false; | |
| 806 | |
| 807 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 808 if (command_line->HasSwitch(switches::kEnableDirectCompositionLayers)) | |
| 809 return true; | |
| 810 if (command_line->HasSwitch(switches::kDisableDirectCompositionLayers)) | |
| 811 return false; | |
| 812 | |
| 813 // Before Windows 10 Anniversary Update (Redstone 1), overlay planes | |
| 814 // wouldn't be assigned to non-UWP apps. | |
| 815 if (base::win::GetVersion() < base::win::VERSION_WIN10_R1) | |
| 816 return false; | |
| 817 | |
| 818 base::win::ScopedComPtr<ID3D11Device> d3d11_device = | |
| 819 gl::QueryD3D11DeviceObjectFromANGLE(); | |
| 820 DCHECK(d3d11_device); | |
| 821 | |
| 822 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; | |
| 823 d3d11_device.QueryInterface(dxgi_device.Receive()); | |
| 824 base::win::ScopedComPtr<IDXGIAdapter> dxgi_adapter; | |
| 825 dxgi_device->GetAdapter(dxgi_adapter.Receive()); | |
| 826 | |
| 827 unsigned int i = 0; | |
| 828 while (true) { | |
| 829 base::win::ScopedComPtr<IDXGIOutput> output; | |
| 830 if (FAILED(dxgi_adapter->EnumOutputs(i++, output.Receive()))) | |
| 831 break; | |
| 832 base::win::ScopedComPtr<IDXGIOutput3> output3; | |
| 833 if (FAILED(output.QueryInterface(output3.Receive()))) | |
| 834 continue; | |
| 835 | |
| 836 UINT flags = 0; | |
| 837 if (FAILED(output3->CheckOverlaySupport(DXGI_FORMAT_YUY2, | |
| 838 d3d11_device.Get(), &flags))) | |
| 839 continue; | |
| 840 | |
| 841 // Direct-only support might be ok in some circumstances, but since the | |
| 842 // overlay processor isn't set up to try to distinguish, only try to use | |
| 843 // overlays when scaling's enabled. | |
| 844 if (flags & DXGI_OVERLAY_SUPPORT_FLAG_SCALING) | |
| 845 return true; | |
| 846 } | |
| 847 return false; | |
| 848 } | 853 } |
| 849 | 854 |
| 850 bool DirectCompositionSurfaceWin::InitializeNativeWindow() { | 855 bool DirectCompositionSurfaceWin::InitializeNativeWindow() { |
| 851 if (window_) | 856 if (window_) |
| 852 return true; | 857 return true; |
| 853 | 858 |
| 854 bool result = child_window_.Initialize(); | 859 bool result = child_window_.Initialize(); |
| 855 window_ = child_window_.window(); | 860 window_ = child_window_.window(); |
| 856 return result; | 861 return result; |
| 857 } | 862 } |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { | 1170 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { |
| 1166 return child_window_.GetTaskRunnerForTesting(); | 1171 return child_window_.GetTaskRunnerForTesting(); |
| 1167 } | 1172 } |
| 1168 | 1173 |
| 1169 base::win::ScopedComPtr<IDXGISwapChain1> | 1174 base::win::ScopedComPtr<IDXGISwapChain1> |
| 1170 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { | 1175 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { |
| 1171 return layer_tree_->GetLayerSwapChainForTesting(index); | 1176 return layer_tree_->GetLayerSwapChainForTesting(index); |
| 1172 } | 1177 } |
| 1173 | 1178 |
| 1174 } // namespace gpu | 1179 } // namespace gpu |
| OLD | NEW |