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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 swap_chain_->GetBuffer(0, IID_PPV_ARGS(texture.GetAddressOf())); | 547 swap_chain_->GetBuffer(0, IID_PPV_ARGS(texture.GetAddressOf())); |
548 D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC out_desc = {}; | 548 D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC out_desc = {}; |
549 out_desc.ViewDimension = D3D11_VPOV_DIMENSION_TEXTURE2D; | 549 out_desc.ViewDimension = D3D11_VPOV_DIMENSION_TEXTURE2D; |
550 out_desc.Texture2D.MipSlice = 0; | 550 out_desc.Texture2D.MipSlice = 0; |
551 HRESULT hr = video_device_->CreateVideoProcessorOutputView( | 551 HRESULT hr = video_device_->CreateVideoProcessorOutputView( |
552 texture.Get(), video_processor_enumerator_.Get(), &out_desc, | 552 texture.Get(), video_processor_enumerator_.Get(), &out_desc, |
553 out_view_.GetAddressOf()); | 553 out_view_.GetAddressOf()); |
554 CHECK(SUCCEEDED(hr)); | 554 CHECK(SUCCEEDED(hr)); |
555 } | 555 } |
556 | 556 |
557 // TODO(jbauman): Use correct colorspace. | 557 gfx::ColorSpace src_color_space = params.color_space; |
558 gfx::ColorSpace src_color_space = gfx::ColorSpace::CreateREC709(); | |
559 base::win::ScopedComPtr<ID3D11VideoContext1> context1; | 558 base::win::ScopedComPtr<ID3D11VideoContext1> context1; |
560 if (SUCCEEDED(video_context_.CopyTo(context1.GetAddressOf()))) { | 559 if (SUCCEEDED(video_context_.CopyTo(context1.GetAddressOf()))) { |
561 context1->VideoProcessorSetStreamColorSpace1( | 560 context1->VideoProcessorSetStreamColorSpace1( |
562 video_processor_.Get(), 0, | 561 video_processor_.Get(), 0, |
563 gfx::ColorSpaceWin::GetDXGIColorSpace(src_color_space)); | 562 gfx::ColorSpaceWin::GetDXGIColorSpace(src_color_space)); |
564 } else { | 563 } else { |
565 // This can't handle as many different types of color spaces, so use it | 564 // This can't handle as many different types of color spaces, so use it |
566 // only if ID3D11VideoContext1 isn't available. | 565 // only if ID3D11VideoContext1 isn't available. |
567 D3D11_VIDEO_PROCESSOR_COLOR_SPACE color_space = | 566 D3D11_VIDEO_PROCESSOR_COLOR_SPACE color_space = |
568 gfx::ColorSpaceWin::GetD3D11ColorSpace(src_color_space); | 567 gfx::ColorSpaceWin::GetD3D11ColorSpace(src_color_space); |
569 video_context_->VideoProcessorSetStreamColorSpace(video_processor_.Get(), 0, | 568 video_context_->VideoProcessorSetStreamColorSpace(video_processor_.Get(), 0, |
570 &color_space); | 569 &color_space); |
571 } | 570 } |
572 | 571 |
573 gfx::ColorSpace output_color_space = | 572 gfx::ColorSpace output_color_space = |
574 is_yuy2_swapchain_ ? src_color_space : gfx::ColorSpace::CreateSRGB(); | 573 is_yuy2_swapchain_ ? src_color_space : gfx::ColorSpace::CreateSRGB(); |
575 if (base::FeatureList::IsEnabled(kFallbackBT709VideoToBT601) && | 574 if (base::FeatureList::IsEnabled(kFallbackBT709VideoToBT601) && |
576 (output_color_space == gfx::ColorSpace::CreateREC709())) { | 575 (output_color_space == gfx::ColorSpace::CreateREC709())) { |
577 output_color_space = gfx::ColorSpace::CreateREC601(); | 576 output_color_space = gfx::ColorSpace::CreateREC601(); |
578 } | 577 } |
579 | 578 |
580 base::win::ScopedComPtr<IDXGISwapChain3> swap_chain3; | 579 base::win::ScopedComPtr<IDXGISwapChain3> swap_chain3; |
581 if (SUCCEEDED(swap_chain_.CopyTo(swap_chain3.GetAddressOf()))) { | 580 if (SUCCEEDED(swap_chain_.CopyTo(swap_chain3.GetAddressOf()))) { |
582 DXGI_COLOR_SPACE_TYPE color_space = | 581 DXGI_COLOR_SPACE_TYPE color_space = |
583 gfx::ColorSpaceWin::GetDXGIColorSpace(output_color_space); | 582 gfx::ColorSpaceWin::GetDXGIColorSpace(output_color_space); |
| 583 if (is_yuy2_swapchain_) { |
| 584 // Swapchains with YUY2 textures can't have RGB color spaces. |
| 585 switch (color_space) { |
| 586 case DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709: |
| 587 case DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709: |
| 588 color_space = DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709; |
| 589 break; |
| 590 |
| 591 case DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709: |
| 592 color_space = DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709; |
| 593 break; |
| 594 |
| 595 case DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020: |
| 596 color_space = DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020; |
| 597 break; |
| 598 |
| 599 case DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020: |
| 600 case DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020: |
| 601 color_space = DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020; |
| 602 break; |
| 603 |
| 604 case DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020: |
| 605 color_space = DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020; |
| 606 break; |
| 607 |
| 608 default: |
| 609 break; |
| 610 } |
| 611 } |
584 HRESULT hr = swap_chain3->SetColorSpace1(color_space); | 612 HRESULT hr = swap_chain3->SetColorSpace1(color_space); |
585 CHECK(SUCCEEDED(hr)); | 613 if (SUCCEEDED(hr)) { |
586 if (context1) { | 614 if (context1) { |
587 context1->VideoProcessorSetOutputColorSpace1(video_processor_.Get(), | 615 context1->VideoProcessorSetOutputColorSpace1(video_processor_.Get(), |
588 color_space); | 616 color_space); |
589 } else { | 617 } else { |
590 D3D11_VIDEO_PROCESSOR_COLOR_SPACE d3d11_color_space = | 618 D3D11_VIDEO_PROCESSOR_COLOR_SPACE d3d11_color_space = |
591 gfx::ColorSpaceWin::GetD3D11ColorSpace(output_color_space); | 619 gfx::ColorSpaceWin::GetD3D11ColorSpace(output_color_space); |
592 video_context_->VideoProcessorSetOutputColorSpace(video_processor_.Get(), | 620 video_context_->VideoProcessorSetOutputColorSpace( |
593 &d3d11_color_space); | 621 video_processor_.Get(), &d3d11_color_space); |
| 622 } |
594 } | 623 } |
595 } | 624 } |
596 | 625 |
597 { | 626 { |
598 D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC in_desc = {}; | 627 D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC in_desc = {}; |
599 in_desc.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D; | 628 in_desc.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D; |
600 in_desc.Texture2D.ArraySlice = input_level; | 629 in_desc.Texture2D.ArraySlice = input_level; |
601 base::win::ScopedComPtr<ID3D11VideoProcessorInputView> in_view; | 630 base::win::ScopedComPtr<ID3D11VideoProcessorInputView> in_view; |
602 HRESULT hr = video_device_->CreateVideoProcessorInputView( | 631 HRESULT hr = video_device_->CreateVideoProcessorInputView( |
603 input_texture.Get(), video_processor_enumerator_.Get(), &in_desc, | 632 input_texture.Get(), video_processor_enumerator_.Get(), &in_desc, |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 TRACE_EVENT1("gpu", "DCLayerTree::CommitAndClearPendingOverlays", "size", | 914 TRACE_EVENT1("gpu", "DCLayerTree::CommitAndClearPendingOverlays", "size", |
886 pending_overlays_.size()); | 915 pending_overlays_.size()); |
887 UMA_HISTOGRAM_BOOLEAN("GPU.DirectComposition.OverlaysUsed", | 916 UMA_HISTOGRAM_BOOLEAN("GPU.DirectComposition.OverlaysUsed", |
888 !pending_overlays_.empty()); | 917 !pending_overlays_.empty()); |
889 // Add an overlay with z-order 0 representing the main plane. | 918 // Add an overlay with z-order 0 representing the main plane. |
890 gfx::Size surface_size = surface_->GetSize(); | 919 gfx::Size surface_size = surface_->GetSize(); |
891 pending_overlays_.push_back(base::MakeUnique<ui::DCRendererLayerParams>( | 920 pending_overlays_.push_back(base::MakeUnique<ui::DCRendererLayerParams>( |
892 false, gfx::Rect(), 0, gfx::Transform(), | 921 false, gfx::Rect(), 0, gfx::Transform(), |
893 std::vector<scoped_refptr<gl::GLImage>>(), | 922 std::vector<scoped_refptr<gl::GLImage>>(), |
894 gfx::RectF(gfx::SizeF(surface_size)), gfx::Rect(surface_size), 0, 0, 1.0, | 923 gfx::RectF(gfx::SizeF(surface_size)), gfx::Rect(surface_size), 0, 0, 1.0, |
895 0)); | 924 0, gfx::ColorSpace())); |
896 | 925 |
897 // TODO(jbauman): Reuse swapchains that are switched between overlays and | 926 // TODO(jbauman): Reuse swapchains that are switched between overlays and |
898 // underlays. | 927 // underlays. |
899 std::sort(pending_overlays_.begin(), pending_overlays_.end(), | 928 std::sort(pending_overlays_.begin(), pending_overlays_.end(), |
900 [](const auto& a, const auto& b) -> bool { | 929 [](const auto& a, const auto& b) -> bool { |
901 return a->z_order < b->z_order; | 930 return a->z_order < b->z_order; |
902 }); | 931 }); |
903 | 932 |
904 while (visual_info_.size() > pending_overlays_.size()) { | 933 while (visual_info_.size() > pending_overlays_.size()) { |
905 visual_info_.back().clip_visual->RemoveAllVisuals(); | 934 visual_info_.back().clip_visual->RemoveAllVisuals(); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { | 1309 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { |
1281 return child_window_.GetTaskRunnerForTesting(); | 1310 return child_window_.GetTaskRunnerForTesting(); |
1282 } | 1311 } |
1283 | 1312 |
1284 base::win::ScopedComPtr<IDXGISwapChain1> | 1313 base::win::ScopedComPtr<IDXGISwapChain1> |
1285 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { | 1314 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { |
1286 return layer_tree_->GetLayerSwapChainForTesting(index); | 1315 return layer_tree_->GetLayerSwapChainForTesting(index); |
1287 } | 1316 } |
1288 | 1317 |
1289 } // namespace gpu | 1318 } // namespace gpu |
OLD | NEW |