| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 return composition_count < (PresentationHistory::kPresentsToStore * 3 / 4); | 340 return composition_count < (PresentationHistory::kPresentsToStore * 3 / 4); |
| 341 } else { | 341 } else { |
| 342 // Switch to YUY2 once 3/4 are using overlays (or unknown). | 342 // Switch to YUY2 once 3/4 are using overlays (or unknown). |
| 343 return composition_count < (PresentationHistory::kPresentsToStore / 4); | 343 return composition_count < (PresentationHistory::kPresentsToStore / 4); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 | 346 |
| 347 void DCLayerTree::SwapChainPresenter::PresentToSwapChain( | 347 void DCLayerTree::SwapChainPresenter::PresentToSwapChain( |
| 348 const ui::DCRendererLayerParams& params) { | 348 const ui::DCRendererLayerParams& params) { |
| 349 gl::GLImageDXGI* image_dxgi = | 349 gl::GLImageDXGI* image_dxgi = |
| 350 gl::GLImageDXGI::FromGLImage(params.image.get()); | 350 gl::GLImageDXGI::FromGLImage(params.image[0].get()); |
| 351 DCHECK(image_dxgi); | 351 DCHECK(image_dxgi); |
| 352 | 352 |
| 353 // Swap chain size is the minimum of the on-screen size and the source | 353 // Swap chain size is the minimum of the on-screen size and the source |
| 354 // size so the video processor can do the minimal amount of work and | 354 // size so the video processor can do the minimal amount of work and |
| 355 // the overlay has to read the minimal amount of data. | 355 // the overlay has to read the minimal amount of data. |
| 356 // DWM is also less likely to promote a surface to an overlay if it's | 356 // DWM is also less likely to promote a surface to an overlay if it's |
| 357 // much larger than its area on-screen. | 357 // much larger than its area on-screen. |
| 358 gfx::Rect bounds_rect = params.rect; | 358 gfx::Rect bounds_rect = params.rect; |
| 359 gfx::Size ceiled_input_size = gfx::ToCeiledSize(params.contents_rect.size()); | 359 gfx::Size ceiled_input_size = gfx::ToCeiledSize(params.contents_rect.size()); |
| 360 gfx::Size swap_chain_size = bounds_rect.size(); | 360 gfx::Size swap_chain_size = bounds_rect.size(); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 } | 724 } |
| 725 | 725 |
| 726 bool DCLayerTree::CommitAndClearPendingOverlays() { | 726 bool DCLayerTree::CommitAndClearPendingOverlays() { |
| 727 TRACE_EVENT1("gpu", "DCLayerTree::CommitAndClearPendingOverlays", "size", | 727 TRACE_EVENT1("gpu", "DCLayerTree::CommitAndClearPendingOverlays", "size", |
| 728 pending_overlays_.size()); | 728 pending_overlays_.size()); |
| 729 UMA_HISTOGRAM_BOOLEAN("GPU.DirectComposition.OverlaysUsed", | 729 UMA_HISTOGRAM_BOOLEAN("GPU.DirectComposition.OverlaysUsed", |
| 730 !pending_overlays_.empty()); | 730 !pending_overlays_.empty()); |
| 731 // Add an overlay with z-order 0 representing the main plane. | 731 // Add an overlay with z-order 0 representing the main plane. |
| 732 gfx::Size surface_size = surface_->GetSize(); | 732 gfx::Size surface_size = surface_->GetSize(); |
| 733 pending_overlays_.push_back(base::MakeUnique<ui::DCRendererLayerParams>( | 733 pending_overlays_.push_back(base::MakeUnique<ui::DCRendererLayerParams>( |
| 734 false, gfx::Rect(), 0, gfx::Transform(), nullptr, | 734 false, gfx::Rect(), 0, gfx::Transform(), |
| 735 std::vector<scoped_refptr<gl::GLImage>>(), |
| 735 gfx::RectF(gfx::SizeF(surface_size)), gfx::Rect(surface_size), 0, 0, 1.0, | 736 gfx::RectF(gfx::SizeF(surface_size)), gfx::Rect(surface_size), 0, 0, 1.0, |
| 736 0)); | 737 0)); |
| 737 | 738 |
| 738 // TODO(jbauman): Reuse swapchains that are switched between overlays and | 739 // TODO(jbauman): Reuse swapchains that are switched between overlays and |
| 739 // underlays. | 740 // underlays. |
| 740 std::sort(pending_overlays_.begin(), pending_overlays_.end(), | 741 std::sort(pending_overlays_.begin(), pending_overlays_.end(), |
| 741 [](const auto& a, const auto& b) -> bool { | 742 [](const auto& a, const auto& b) -> bool { |
| 742 return a->z_order < b->z_order; | 743 return a->z_order < b->z_order; |
| 743 }); | 744 }); |
| 744 | 745 |
| 745 while (visual_info_.size() > pending_overlays_.size()) { | 746 while (visual_info_.size() > pending_overlays_.size()) { |
| 746 visual_info_.back().clip_visual->RemoveAllVisuals(); | 747 visual_info_.back().clip_visual->RemoveAllVisuals(); |
| 747 root_visual_->RemoveVisual(visual_info_.back().clip_visual.Get()); | 748 root_visual_->RemoveVisual(visual_info_.back().clip_visual.Get()); |
| 748 visual_info_.pop_back(); | 749 visual_info_.pop_back(); |
| 749 } | 750 } |
| 750 | 751 |
| 751 visual_info_.resize(pending_overlays_.size()); | 752 visual_info_.resize(pending_overlays_.size()); |
| 752 | 753 |
| 753 // The overall visual tree has one clip visual for every overlay (including | 754 // The overall visual tree has one clip visual for every overlay (including |
| 754 // the main plane). The clip visuals are in z_order and are all children of | 755 // the main plane). The clip visuals are in z_order and are all children of |
| 755 // a root visual. Each clip visual has a child visual that has the actual | 756 // a root visual. Each clip visual has a child visual that has the actual |
| 756 // plane content. | 757 // plane content. |
| 757 | 758 |
| 758 for (size_t i = 0; i < pending_overlays_.size(); i++) { | 759 for (size_t i = 0; i < pending_overlays_.size(); i++) { |
| 759 ui::DCRendererLayerParams& params = *pending_overlays_[i]; | 760 ui::DCRendererLayerParams& params = *pending_overlays_[i]; |
| 760 VisualInfo* visual_info = &visual_info_[i]; | 761 VisualInfo* visual_info = &visual_info_[i]; |
| 761 | 762 |
| 762 InitVisual(i); | 763 InitVisual(i); |
| 763 if (params.image && | 764 if (params.image.size() > 0 && params.image[0] && |
| 764 params.image->GetType() == gl::GLImage::Type::DXGI_IMAGE) { | 765 params.image[0]->GetType() == gl::GLImage::Type::DXGI_IMAGE) { |
| 765 UpdateVisualForVideo(visual_info, params); | 766 UpdateVisualForVideo(visual_info, params); |
| 766 } else if (!params.image) { | 767 } else if (params.image.empty()) { |
| 767 UpdateVisualForBackbuffer(visual_info, params); | 768 UpdateVisualForBackbuffer(visual_info, params); |
| 768 } else { | 769 } else { |
| 769 CHECK(false); | 770 CHECK(false); |
| 770 } | 771 } |
| 771 UpdateVisualClip(visual_info, params); | 772 UpdateVisualClip(visual_info, params); |
| 772 } | 773 } |
| 773 | 774 |
| 774 HRESULT hr = dcomp_device_->Commit(); | 775 HRESULT hr = dcomp_device_->Commit(); |
| 775 CHECK(SUCCEEDED(hr)); | 776 CHECK(SUCCEEDED(hr)); |
| 776 | 777 |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { | 1158 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { |
| 1158 return child_window_.GetTaskRunnerForTesting(); | 1159 return child_window_.GetTaskRunnerForTesting(); |
| 1159 } | 1160 } |
| 1160 | 1161 |
| 1161 base::win::ScopedComPtr<IDXGISwapChain1> | 1162 base::win::ScopedComPtr<IDXGISwapChain1> |
| 1162 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { | 1163 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { |
| 1163 return layer_tree_->GetLayerSwapChainForTesting(index); | 1164 return layer_tree_->GetLayerSwapChainForTesting(index); |
| 1164 } | 1165 } |
| 1165 | 1166 |
| 1166 } // namespace gpu | 1167 } // namespace gpu |
| OLD | NEW |