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 "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 void DirectCompositionSurfaceWin::InitializeSurface() { | 715 void DirectCompositionSurfaceWin::InitializeSurface() { |
716 TRACE_EVENT1("gpu", "DirectCompositionSurfaceWin::InitializeSurface()", | 716 TRACE_EVENT1("gpu", "DirectCompositionSurfaceWin::InitializeSurface()", |
717 "enable_dc_layers_", enable_dc_layers_); | 717 "enable_dc_layers_", enable_dc_layers_); |
718 DCHECK(!dcomp_surface_); | 718 DCHECK(!dcomp_surface_); |
719 DCHECK(!swap_chain_); | 719 DCHECK(!swap_chain_); |
720 DXGI_FORMAT output_format = | 720 DXGI_FORMAT output_format = |
721 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableHDR) | 721 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableHDR) |
722 ? DXGI_FORMAT_R16G16B16A16_FLOAT | 722 ? DXGI_FORMAT_R16G16B16A16_FLOAT |
723 : DXGI_FORMAT_B8G8R8A8_UNORM; | 723 : DXGI_FORMAT_B8G8R8A8_UNORM; |
724 if (enable_dc_layers_) { | 724 if (enable_dc_layers_) { |
| 725 // Always treat as premultiplied, because an underlay could cause it to |
| 726 // become transparent. |
725 HRESULT hr = dcomp_device_->CreateSurface( | 727 HRESULT hr = dcomp_device_->CreateSurface( |
726 size_.width(), size_.height(), output_format, | 728 size_.width(), size_.height(), output_format, |
727 DXGI_ALPHA_MODE_PREMULTIPLIED, dcomp_surface_.Receive()); | 729 DXGI_ALPHA_MODE_PREMULTIPLIED, dcomp_surface_.Receive()); |
728 has_been_rendered_to_ = false; | 730 has_been_rendered_to_ = false; |
729 CHECK(SUCCEEDED(hr)); | 731 CHECK(SUCCEEDED(hr)); |
730 } else { | 732 } else { |
| 733 DXGI_ALPHA_MODE alpha_mode = |
| 734 has_alpha_ ? DXGI_ALPHA_MODE_PREMULTIPLIED : DXGI_ALPHA_MODE_IGNORE; |
731 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; | 735 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; |
732 d3d11_device_.QueryInterface(dxgi_device.Receive()); | 736 d3d11_device_.QueryInterface(dxgi_device.Receive()); |
733 base::win::ScopedComPtr<IDXGIAdapter> dxgi_adapter; | 737 base::win::ScopedComPtr<IDXGIAdapter> dxgi_adapter; |
734 dxgi_device->GetAdapter(dxgi_adapter.Receive()); | 738 dxgi_device->GetAdapter(dxgi_adapter.Receive()); |
735 base::win::ScopedComPtr<IDXGIFactory2> dxgi_factory; | 739 base::win::ScopedComPtr<IDXGIFactory2> dxgi_factory; |
736 dxgi_adapter->GetParent(IID_PPV_ARGS(dxgi_factory.Receive())); | 740 dxgi_adapter->GetParent(IID_PPV_ARGS(dxgi_factory.Receive())); |
737 | 741 |
738 DXGI_SWAP_CHAIN_DESC1 desc = {}; | 742 DXGI_SWAP_CHAIN_DESC1 desc = {}; |
739 desc.Width = size_.width(); | 743 desc.Width = size_.width(); |
740 desc.Height = size_.height(); | 744 desc.Height = size_.height(); |
741 desc.Format = output_format; | 745 desc.Format = output_format; |
742 desc.Stereo = FALSE; | 746 desc.Stereo = FALSE; |
743 desc.SampleDesc.Count = 1; | 747 desc.SampleDesc.Count = 1; |
744 desc.BufferCount = 2; | 748 desc.BufferCount = 2; |
745 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; | 749 desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; |
746 desc.Scaling = DXGI_SCALING_STRETCH; | 750 desc.Scaling = DXGI_SCALING_STRETCH; |
747 desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; | 751 desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; |
748 desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED; | 752 desc.AlphaMode = alpha_mode; |
749 desc.Flags = 0; | 753 desc.Flags = 0; |
750 HRESULT hr = dxgi_factory->CreateSwapChainForComposition( | 754 HRESULT hr = dxgi_factory->CreateSwapChainForComposition( |
751 d3d11_device_.get(), &desc, nullptr, swap_chain_.Receive()); | 755 d3d11_device_.get(), &desc, nullptr, swap_chain_.Receive()); |
752 has_been_rendered_to_ = false; | 756 has_been_rendered_to_ = false; |
753 first_swap_ = true; | 757 first_swap_ = true; |
754 CHECK(SUCCEEDED(hr)); | 758 CHECK(SUCCEEDED(hr)); |
755 } | 759 } |
756 } | 760 } |
757 | 761 |
758 void DirectCompositionSurfaceWin::ReleaseDrawTexture(bool will_discard) { | 762 void DirectCompositionSurfaceWin::ReleaseDrawTexture(bool will_discard) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 return false; | 827 return false; |
824 } | 828 } |
825 | 829 |
826 void* DirectCompositionSurfaceWin::GetHandle() { | 830 void* DirectCompositionSurfaceWin::GetHandle() { |
827 return real_surface_ ? real_surface_ : default_surface_; | 831 return real_surface_ ? real_surface_ : default_surface_; |
828 } | 832 } |
829 | 833 |
830 bool DirectCompositionSurfaceWin::Resize(const gfx::Size& size, | 834 bool DirectCompositionSurfaceWin::Resize(const gfx::Size& size, |
831 float scale_factor, | 835 float scale_factor, |
832 bool has_alpha) { | 836 bool has_alpha) { |
833 if (size == GetSize()) | 837 if ((size == GetSize()) && (has_alpha == has_alpha_)) |
834 return true; | 838 return true; |
835 | 839 |
836 // Force a resize and redraw (but not a move, activate, etc.). | 840 // Force a resize and redraw (but not a move, activate, etc.). |
837 if (!SetWindowPos(window_, nullptr, 0, 0, size.width(), size.height(), | 841 if (!SetWindowPos(window_, nullptr, 0, 0, size.width(), size.height(), |
838 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOCOPYBITS | | 842 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOCOPYBITS | |
839 SWP_NOOWNERZORDER | SWP_NOZORDER)) { | 843 SWP_NOOWNERZORDER | SWP_NOZORDER)) { |
840 return false; | 844 return false; |
841 } | 845 } |
842 size_ = size; | 846 size_ = size; |
| 847 has_alpha_ = has_alpha; |
843 ScopedReleaseCurrent release_current(this); | 848 ScopedReleaseCurrent release_current(this); |
844 // New surface will be initialized in SetDrawRectangle. | 849 // New surface will be initialized in SetDrawRectangle. |
845 ReleaseCurrentSurface(); | 850 ReleaseCurrentSurface(); |
846 | 851 |
847 return true; | 852 return true; |
848 } | 853 } |
849 | 854 |
850 gfx::SwapResult DirectCompositionSurfaceWin::SwapBuffers() { | 855 gfx::SwapResult DirectCompositionSurfaceWin::SwapBuffers() { |
851 { | 856 { |
852 ScopedReleaseCurrent release_current(this); | 857 ScopedReleaseCurrent release_current(this); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 gfx::Vector2d DirectCompositionSurfaceWin::GetDrawOffset() const { | 977 gfx::Vector2d DirectCompositionSurfaceWin::GetDrawOffset() const { |
973 return draw_offset_; | 978 return draw_offset_; |
974 } | 979 } |
975 | 980 |
976 scoped_refptr<base::TaskRunner> | 981 scoped_refptr<base::TaskRunner> |
977 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { | 982 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { |
978 return child_window_.GetTaskRunnerForTesting(); | 983 return child_window_.GetTaskRunnerForTesting(); |
979 } | 984 } |
980 | 985 |
981 } // namespace gpu | 986 } // namespace gpu |
OLD | NEW |