| 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/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 video_processor_.get(), 0, FALSE); | 406 video_processor_.get(), 0, FALSE); |
| 407 | 407 |
| 408 hr = video_context_->VideoProcessorBlt(video_processor_.get(), | 408 hr = video_context_->VideoProcessorBlt(video_processor_.get(), |
| 409 out_view_.get(), 0, 1, &stream); | 409 out_view_.get(), 0, 1, &stream); |
| 410 CHECK(SUCCEEDED(hr)); | 410 CHECK(SUCCEEDED(hr)); |
| 411 } | 411 } |
| 412 | 412 |
| 413 swap_chain_scale_x_ = bounds_rect.width() * 1.0f / swap_chain_size.width(); | 413 swap_chain_scale_x_ = bounds_rect.width() * 1.0f / swap_chain_size.width(); |
| 414 swap_chain_scale_y_ = bounds_rect.height() * 1.0f / swap_chain_size.height(); | 414 swap_chain_scale_y_ = bounds_rect.height() * 1.0f / swap_chain_size.height(); |
| 415 | 415 |
| 416 swap_chain_->Present(first_present ? 0 : 1, 0); | 416 if (first_present) { |
| 417 swap_chain_->Present(0, 0); |
| 418 |
| 419 // DirectComposition can display black for a swapchain between the first |
| 420 // and second time it's presented to - maybe the first Present can get |
| 421 // lost somehow and it shows the wrong buffer. In that case copy the |
| 422 // buffers so both have the correct contents, which seems to help. The |
| 423 // first Present() after this needs to have SyncInterval > 0, or else the |
| 424 // workaround doesn't help. |
| 425 base::win::ScopedComPtr<ID3D11Texture2D> dest_texture; |
| 426 HRESULT hr = |
| 427 swap_chain_->GetBuffer(0, IID_PPV_ARGS(dest_texture.Receive())); |
| 428 DCHECK(SUCCEEDED(hr)); |
| 429 base::win::ScopedComPtr<ID3D11Texture2D> src_texture; |
| 430 hr = swap_chain_->GetBuffer(1, IID_PPV_ARGS(src_texture.Receive())); |
| 431 DCHECK(SUCCEEDED(hr)); |
| 432 base::win::ScopedComPtr<ID3D11DeviceContext> context; |
| 433 d3d11_device_->GetImmediateContext(context.Receive()); |
| 434 context->CopyResource(dest_texture.get(), src_texture.get()); |
| 435 } |
| 436 |
| 437 swap_chain_->Present(1, 0); |
| 417 | 438 |
| 418 base::win::ScopedComPtr<IDXGISwapChainMedia> swap_chain_media; | 439 base::win::ScopedComPtr<IDXGISwapChainMedia> swap_chain_media; |
| 419 if (SUCCEEDED(swap_chain_.QueryInterface(swap_chain_media.Receive()))) { | 440 if (SUCCEEDED(swap_chain_.QueryInterface(swap_chain_media.Receive()))) { |
| 420 DXGI_FRAME_STATISTICS_MEDIA stats = {}; | 441 DXGI_FRAME_STATISTICS_MEDIA stats = {}; |
| 421 if (SUCCEEDED(swap_chain_media->GetFrameStatisticsMedia(&stats))) { | 442 if (SUCCEEDED(swap_chain_media->GetFrameStatisticsMedia(&stats))) { |
| 422 UMA_HISTOGRAM_SPARSE_SLOWLY("GPU.DirectComposition.CompositionMode", | 443 UMA_HISTOGRAM_SPARSE_SLOWLY("GPU.DirectComposition.CompositionMode", |
| 423 stats.CompositionMode); | 444 stats.CompositionMode); |
| 424 } | 445 } |
| 425 } | 446 } |
| 426 } | 447 } |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { | 1082 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { |
| 1062 return child_window_.GetTaskRunnerForTesting(); | 1083 return child_window_.GetTaskRunnerForTesting(); |
| 1063 } | 1084 } |
| 1064 | 1085 |
| 1065 base::win::ScopedComPtr<IDXGISwapChain1> | 1086 base::win::ScopedComPtr<IDXGISwapChain1> |
| 1066 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { | 1087 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { |
| 1067 return layer_tree_->GetLayerSwapChainForTesting(index); | 1088 return layer_tree_->GetLayerSwapChainForTesting(index); |
| 1068 } | 1089 } |
| 1069 | 1090 |
| 1070 } // namespace gpu | 1091 } // namespace gpu |
| OLD | NEW |