| 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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 gfx::Size ceiled_input_size = gfx::ToCeiledSize(params.contents_rect.size()); | 513 gfx::Size ceiled_input_size = gfx::ToCeiledSize(params.contents_rect.size()); |
| 514 gfx::Size swap_chain_size = bounds_rect.size(); | 514 gfx::Size swap_chain_size = bounds_rect.size(); |
| 515 swap_chain_size.SetToMin(ceiled_input_size); | 515 swap_chain_size.SetToMin(ceiled_input_size); |
| 516 | 516 |
| 517 // YUY2 surfaces must have an even width. | 517 // YUY2 surfaces must have an even width. |
| 518 if (swap_chain_size.width() % 2 == 1) | 518 if (swap_chain_size.width() % 2 == 1) |
| 519 swap_chain_size.set_width(swap_chain_size.width() + 1); | 519 swap_chain_size.set_width(swap_chain_size.width() + 1); |
| 520 | 520 |
| 521 InitializeVideoProcessor(ceiled_input_size, swap_chain_size); | 521 InitializeVideoProcessor(ceiled_input_size, swap_chain_size); |
| 522 | 522 |
| 523 if (surface_->workarounds().disable_larger_than_screen_overlays) { |
| 524 // Because of the rounding when converting between pixels and DIPs, a |
| 525 // fullscreen video can become slightly larger than the monitor - e.g. on |
| 526 // a 3000x2000 monitor with a scale factor of 1.75 a 1920x1079 video can |
| 527 // become 3002x1689. |
| 528 // On older Intel drivers, swapchains that are bigger than the monitor |
| 529 // won't be put into overlays, which will hurt power usage a lot. On those |
| 530 // systems, the scaling can be adjusted very slightly so that it's less |
| 531 // than the monitor size. This should be close to imperceptible. |
| 532 // TODO(jbauman): Remove when http://crbug.com/668278 is fixed. |
| 533 const int kOversizeMargin = 3; |
| 534 |
| 535 if ((bounds_rect.x() >= 0) && |
| 536 (bounds_rect.width() > g_overlay_monitor_size.width()) && |
| 537 (bounds_rect.width() <= |
| 538 g_overlay_monitor_size.width() + kOversizeMargin)) { |
| 539 bounds_rect.set_width(g_overlay_monitor_size.width()); |
| 540 } |
| 541 |
| 542 if ((bounds_rect.y() >= 0) && |
| 543 (bounds_rect.height() > g_overlay_monitor_size.height()) && |
| 544 (bounds_rect.height() <= |
| 545 g_overlay_monitor_size.height() + kOversizeMargin)) { |
| 546 bounds_rect.set_height(g_overlay_monitor_size.height()); |
| 547 } |
| 548 } |
| 549 |
| 550 swap_chain_scale_x_ = bounds_rect.width() * 1.0f / swap_chain_size.width(); |
| 551 swap_chain_scale_y_ = bounds_rect.height() * 1.0f / swap_chain_size.height(); |
| 552 |
| 523 bool yuy2_swapchain = ShouldBeYUY2(); | 553 bool yuy2_swapchain = ShouldBeYUY2(); |
| 524 bool first_present = false; | 554 bool first_present = false; |
| 525 if (!swap_chain_ || swap_chain_size_ != swap_chain_size || | 555 if (!swap_chain_ || swap_chain_size_ != swap_chain_size || |
| 526 ((yuy2_swapchain != is_yuy2_swapchain_) && | 556 ((yuy2_swapchain != is_yuy2_swapchain_) && |
| 527 !failed_to_create_yuy2_swapchain_)) { | 557 !failed_to_create_yuy2_swapchain_)) { |
| 528 first_present = true; | 558 first_present = true; |
| 529 swap_chain_size_ = swap_chain_size; | 559 swap_chain_size_ = swap_chain_size; |
| 530 swap_chain_.Reset(); | 560 swap_chain_.Reset(); |
| 531 ReallocateSwapChain(yuy2_swapchain); | 561 ReallocateSwapChain(yuy2_swapchain); |
| 532 } else if (last_gl_images_ == params.image) { | 562 } else if (last_gl_images_ == params.image) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 TRUE, &source_rect); | 663 TRUE, &source_rect); |
| 634 | 664 |
| 635 video_context_->VideoProcessorSetStreamAutoProcessingMode( | 665 video_context_->VideoProcessorSetStreamAutoProcessingMode( |
| 636 video_processor_.Get(), 0, FALSE); | 666 video_processor_.Get(), 0, FALSE); |
| 637 | 667 |
| 638 hr = video_context_->VideoProcessorBlt(video_processor_.Get(), | 668 hr = video_context_->VideoProcessorBlt(video_processor_.Get(), |
| 639 out_view_.Get(), 0, 1, &stream); | 669 out_view_.Get(), 0, 1, &stream); |
| 640 CHECK(SUCCEEDED(hr)); | 670 CHECK(SUCCEEDED(hr)); |
| 641 } | 671 } |
| 642 | 672 |
| 643 if (surface_->workarounds().disable_larger_than_screen_overlays) { | |
| 644 // Because of the rounding when converting between pixels and DIPs, a | |
| 645 // fullscreen video can become slightly larger than the monitor - e.g. on | |
| 646 // a 3000x2000 monitor with a scale factor of 1.75 a 1920x1079 video can | |
| 647 // become 3002x1689. | |
| 648 // On older Intel drivers, swapchains that are bigger than the monitor | |
| 649 // won't be put into overlays, which will hurt power usage a lot. On those | |
| 650 // systems, the scaling can be adjusted very slightly so that it's less | |
| 651 // than the monitor size. This should be close to imperceptible. | |
| 652 // TODO(jbauman): Remove when http://crbug.com/668278 is fixed. | |
| 653 const int kOversizeMargin = 3; | |
| 654 | |
| 655 if ((bounds_rect.x() >= 0) && | |
| 656 (bounds_rect.width() > g_overlay_monitor_size.width()) && | |
| 657 (bounds_rect.width() <= | |
| 658 g_overlay_monitor_size.width() + kOversizeMargin)) { | |
| 659 bounds_rect.set_width(g_overlay_monitor_size.width()); | |
| 660 } | |
| 661 | |
| 662 if ((bounds_rect.y() >= 0) && | |
| 663 (bounds_rect.height() > g_overlay_monitor_size.height()) && | |
| 664 (bounds_rect.height() <= | |
| 665 g_overlay_monitor_size.height() + kOversizeMargin)) { | |
| 666 bounds_rect.set_height(g_overlay_monitor_size.height()); | |
| 667 } | |
| 668 } | |
| 669 | |
| 670 swap_chain_scale_x_ = bounds_rect.width() * 1.0f / swap_chain_size.width(); | |
| 671 swap_chain_scale_y_ = bounds_rect.height() * 1.0f / swap_chain_size.height(); | |
| 672 | |
| 673 if (first_present) { | 673 if (first_present) { |
| 674 swap_chain_->Present(0, 0); | 674 swap_chain_->Present(0, 0); |
| 675 | 675 |
| 676 // DirectComposition can display black for a swapchain between the first | 676 // DirectComposition can display black for a swapchain between the first |
| 677 // and second time it's presented to - maybe the first Present can get | 677 // and second time it's presented to - maybe the first Present can get |
| 678 // lost somehow and it shows the wrong buffer. In that case copy the | 678 // lost somehow and it shows the wrong buffer. In that case copy the |
| 679 // buffers so both have the correct contents, which seems to help. The | 679 // buffers so both have the correct contents, which seems to help. The |
| 680 // first Present() after this needs to have SyncInterval > 0, or else the | 680 // first Present() after this needs to have SyncInterval > 0, or else the |
| 681 // workaround doesn't help. | 681 // workaround doesn't help. |
| 682 base::win::ScopedComPtr<ID3D11Texture2D> dest_texture; | 682 base::win::ScopedComPtr<ID3D11Texture2D> dest_texture; |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { | 1320 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { |
| 1321 return child_window_.GetTaskRunnerForTesting(); | 1321 return child_window_.GetTaskRunnerForTesting(); |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 base::win::ScopedComPtr<IDXGISwapChain1> | 1324 base::win::ScopedComPtr<IDXGISwapChain1> |
| 1325 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { | 1325 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { |
| 1326 return layer_tree_->GetLayerSwapChainForTesting(index); | 1326 return layer_tree_->GetLayerSwapChainForTesting(index); |
| 1327 } | 1327 } |
| 1328 | 1328 |
| 1329 } // namespace gpu | 1329 } // namespace gpu |
| OLD | NEW |