Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: gpu/ipc/service/direct_composition_surface_win.cc

Issue 2968503003: Allow presenting DXGI share handles as overlays. (Closed)
Patch Set: fix build Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gpu/ipc/service/direct_composition_surface_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 uv_image_memory->memory() + y * uv_image_memory->stride(); 458 uv_image_memory->memory() + y * uv_image_memory->stride();
459 uint8_t* dest = uv_dest_plane_start + dest_stride * y; 459 uint8_t* dest = uv_dest_plane_start + dest_stride * y;
460 memcpy(dest, uv_source, texture_size.width()); 460 memcpy(dest, uv_source, texture_size.width());
461 } 461 }
462 context->Unmap(staging_texture_.Get(), 0); 462 context->Unmap(staging_texture_.Get(), 0);
463 return true; 463 return true;
464 } 464 }
465 465
466 void DCLayerTree::SwapChainPresenter::PresentToSwapChain( 466 void DCLayerTree::SwapChainPresenter::PresentToSwapChain(
467 const ui::DCRendererLayerParams& params) { 467 const ui::DCRendererLayerParams& params) {
468 gl::GLImageDXGI* image_dxgi = 468 gl::GLImageDXGIBase* image_dxgi =
469 gl::GLImageDXGI::FromGLImage(params.image[0].get()); 469 gl::GLImageDXGIBase::FromGLImage(params.image[0].get());
470 gl::GLImageMemory* y_image_memory = nullptr; 470 gl::GLImageMemory* y_image_memory = nullptr;
471 gl::GLImageMemory* uv_image_memory = nullptr; 471 gl::GLImageMemory* uv_image_memory = nullptr;
472 if (params.image.size() >= 2) { 472 if (params.image.size() >= 2) {
473 y_image_memory = gl::GLImageMemory::FromGLImage(params.image[0].get()); 473 y_image_memory = gl::GLImageMemory::FromGLImage(params.image[0].get());
474 uv_image_memory = gl::GLImageMemory::FromGLImage(params.image[1].get()); 474 uv_image_memory = gl::GLImageMemory::FromGLImage(params.image[1].get());
475 } 475 }
476 476
477 if (!image_dxgi && (!y_image_memory || !uv_image_memory)) { 477 if (!image_dxgi && (!y_image_memory || !uv_image_memory)) {
478 DLOG(ERROR) << "Video GLImages are missing"; 478 DLOG(ERROR) << "Video GLImages are missing";
479 last_gl_images_.clear(); 479 last_gl_images_.clear();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 // The swap chain is presenting the same images as last swap, which means 541 // The swap chain is presenting the same images as last swap, which means
542 // that the images were never returned to the video decoder and should 542 // that the images were never returned to the video decoder and should
543 // have the same contents as last time. It shouldn't need to be redrawn. 543 // have the same contents as last time. It shouldn't need to be redrawn.
544 return; 544 return;
545 } 545 }
546 546
547 last_gl_images_ = params.image; 547 last_gl_images_ = params.image;
548 548
549 base::win::ScopedComPtr<ID3D11Texture2D> input_texture; 549 base::win::ScopedComPtr<ID3D11Texture2D> input_texture;
550 UINT input_level; 550 UINT input_level;
551 base::win::ScopedComPtr<IDXGIKeyedMutex> keyed_mutex;
551 if (image_dxgi) { 552 if (image_dxgi) {
552 input_texture = image_dxgi->texture(); 553 input_texture = image_dxgi->texture();
553 input_level = (UINT)image_dxgi->level(); 554 input_level = (UINT)image_dxgi->level();
555 if (!input_texture)
556 return;
557 input_texture.CopyTo(keyed_mutex.GetAddressOf());
554 staging_texture_.Reset(); 558 staging_texture_.Reset();
555 } else { 559 } else {
556 DCHECK(y_image_memory); 560 DCHECK(y_image_memory);
557 DCHECK(uv_image_memory); 561 DCHECK(uv_image_memory);
558 if (!UploadVideoImages(y_image_memory, uv_image_memory)) 562 if (!UploadVideoImages(y_image_memory, uv_image_memory))
559 return; 563 return;
560 DCHECK(staging_texture_); 564 DCHECK(staging_texture_);
561 input_texture = staging_texture_; 565 input_texture = staging_texture_;
562 input_level = 0; 566 input_level = 0;
563 } 567 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 color_space); 612 color_space);
609 } else { 613 } else {
610 D3D11_VIDEO_PROCESSOR_COLOR_SPACE d3d11_color_space = 614 D3D11_VIDEO_PROCESSOR_COLOR_SPACE d3d11_color_space =
611 gfx::ColorSpaceWin::GetD3D11ColorSpace(output_color_space); 615 gfx::ColorSpaceWin::GetD3D11ColorSpace(output_color_space);
612 video_context_->VideoProcessorSetOutputColorSpace(video_processor_.Get(), 616 video_context_->VideoProcessorSetOutputColorSpace(video_processor_.Get(),
613 &d3d11_color_space); 617 &d3d11_color_space);
614 } 618 }
615 } 619 }
616 620
617 { 621 {
622 if (keyed_mutex) {
sunnyps 2017/07/11 01:56:28 nit: Can you add a comment about this?
623 const int kMaxSyncTime = 1000; // ms
624 HRESULT hr = keyed_mutex->AcquireSync(0, kMaxSyncTime);
625 if (FAILED(hr)) {
626 DLOG(ERROR) << "Error acquiring keyed mutex: " << std::hex << hr;
627 return;
628 }
629 }
618 D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC in_desc = {}; 630 D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC in_desc = {};
619 in_desc.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D; 631 in_desc.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D;
620 in_desc.Texture2D.ArraySlice = input_level; 632 in_desc.Texture2D.ArraySlice = input_level;
621 base::win::ScopedComPtr<ID3D11VideoProcessorInputView> in_view; 633 base::win::ScopedComPtr<ID3D11VideoProcessorInputView> in_view;
622 HRESULT hr = video_device_->CreateVideoProcessorInputView( 634 HRESULT hr = video_device_->CreateVideoProcessorInputView(
623 input_texture.Get(), video_processor_enumerator_.Get(), &in_desc, 635 input_texture.Get(), video_processor_enumerator_.Get(), &in_desc,
624 in_view.GetAddressOf()); 636 in_view.GetAddressOf());
625 CHECK(SUCCEEDED(hr)); 637 CHECK(SUCCEEDED(hr));
626 638
627 D3D11_VIDEO_PROCESSOR_STREAM stream = {}; 639 D3D11_VIDEO_PROCESSOR_STREAM stream = {};
(...skipping 11 matching lines...) Expand all
639 RECT source_rect = gfx::Rect(ceiled_input_size).ToRECT(); 651 RECT source_rect = gfx::Rect(ceiled_input_size).ToRECT();
640 video_context_->VideoProcessorSetStreamSourceRect(video_processor_.Get(), 0, 652 video_context_->VideoProcessorSetStreamSourceRect(video_processor_.Get(), 0,
641 TRUE, &source_rect); 653 TRUE, &source_rect);
642 654
643 video_context_->VideoProcessorSetStreamAutoProcessingMode( 655 video_context_->VideoProcessorSetStreamAutoProcessingMode(
644 video_processor_.Get(), 0, FALSE); 656 video_processor_.Get(), 0, FALSE);
645 657
646 hr = video_context_->VideoProcessorBlt(video_processor_.Get(), 658 hr = video_context_->VideoProcessorBlt(video_processor_.Get(),
647 out_view_.Get(), 0, 1, &stream); 659 out_view_.Get(), 0, 1, &stream);
648 CHECK(SUCCEEDED(hr)); 660 CHECK(SUCCEEDED(hr));
661 if (keyed_mutex) {
662 HRESULT hr = keyed_mutex->ReleaseSync(0);
663 DCHECK(SUCCEEDED(hr));
664 }
649 } 665 }
650 666
651 if (first_present) { 667 if (first_present) {
652 swap_chain_->Present(0, 0); 668 swap_chain_->Present(0, 0);
653 669
654 // DirectComposition can display black for a swapchain between the first 670 // DirectComposition can display black for a swapchain between the first
655 // and second time it's presented to - maybe the first Present can get 671 // and second time it's presented to - maybe the first Present can get
656 // lost somehow and it shows the wrong buffer. In that case copy the 672 // lost somehow and it shows the wrong buffer. In that case copy the
657 // buffers so both have the correct contents, which seems to help. The 673 // buffers so both have the correct contents, which seems to help. The
658 // first Present() after this needs to have SyncInterval > 0, or else the 674 // first Present() after this needs to have SyncInterval > 0, or else the
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() { 1184 DirectCompositionSurfaceWin::GetWindowTaskRunnerForTesting() {
1169 return child_window_.GetTaskRunnerForTesting(); 1185 return child_window_.GetTaskRunnerForTesting();
1170 } 1186 }
1171 1187
1172 base::win::ScopedComPtr<IDXGISwapChain1> 1188 base::win::ScopedComPtr<IDXGISwapChain1>
1173 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const { 1189 DirectCompositionSurfaceWin::GetLayerSwapChainForTesting(size_t index) const {
1174 return layer_tree_->GetLayerSwapChainForTesting(index); 1190 return layer_tree_->GetLayerSwapChainForTesting(index);
1175 } 1191 }
1176 1192
1177 } // namespace gpu 1193 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/ipc/service/direct_composition_surface_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698