| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/gpu/dxva_video_decode_accelerator_win.h" | 5 #include "media/gpu/dxva_video_decode_accelerator_win.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #if !defined(OS_WIN) | 9 #if !defined(OS_WIN) |
| 10 #error This file should only be built on Windows. | 10 #error This file should only be built on Windows. |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 static_cast<D3DFORMAT>(MAKEFOURCC('N', 'V', '1', '2')), D3DFMT_X8R8G8B8); | 664 static_cast<D3DFORMAT>(MAKEFOURCC('N', 'V', '1', '2')), D3DFMT_X8R8G8B8); |
| 665 RETURN_ON_HR_FAILURE(hr, "D3D9 driver does not support H/W format conversion", | 665 RETURN_ON_HR_FAILURE(hr, "D3D9 driver does not support H/W format conversion", |
| 666 false); | 666 false); |
| 667 | 667 |
| 668 base::win::ScopedComPtr<IDirect3DDevice9> angle_device = | 668 base::win::ScopedComPtr<IDirect3DDevice9> angle_device = |
| 669 gl::QueryD3D9DeviceObjectFromANGLE(); | 669 gl::QueryD3D9DeviceObjectFromANGLE(); |
| 670 if (angle_device.Get()) | 670 if (angle_device.Get()) |
| 671 using_angle_device_ = true; | 671 using_angle_device_ = true; |
| 672 | 672 |
| 673 if (using_angle_device_) { | 673 if (using_angle_device_) { |
| 674 hr = d3d9_device_ex_.QueryFrom(angle_device.Get()); | 674 hr = angle_device.CopyTo(d3d9_device_ex_.GetAddressOf()); |
| 675 RETURN_ON_HR_FAILURE( | 675 RETURN_ON_HR_FAILURE( |
| 676 hr, "QueryInterface for IDirect3DDevice9Ex from angle device failed", | 676 hr, "QueryInterface for IDirect3DDevice9Ex from angle device failed", |
| 677 false); | 677 false); |
| 678 } else { | 678 } else { |
| 679 D3DPRESENT_PARAMETERS present_params = {0}; | 679 D3DPRESENT_PARAMETERS present_params = {0}; |
| 680 present_params.BackBufferWidth = 1; | 680 present_params.BackBufferWidth = 1; |
| 681 present_params.BackBufferHeight = 1; | 681 present_params.BackBufferHeight = 1; |
| 682 present_params.BackBufferFormat = D3DFMT_UNKNOWN; | 682 present_params.BackBufferFormat = D3DFMT_UNKNOWN; |
| 683 present_params.BackBufferCount = 1; | 683 present_params.BackBufferCount = 1; |
| 684 present_params.SwapEffect = D3DSWAPEFFECT_DISCARD; | 684 present_params.SwapEffect = D3DSWAPEFFECT_DISCARD; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 hr = D3D11Device()->CheckFormatSupport(DXGI_FORMAT_R16G16B16A16_FLOAT, | 880 hr = D3D11Device()->CheckFormatSupport(DXGI_FORMAT_R16G16B16A16_FLOAT, |
| 881 &fp16_format_support); | 881 &fp16_format_support); |
| 882 if (FAILED(hr) || | 882 if (FAILED(hr) || |
| 883 !(fp16_format_support & D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT)) | 883 !(fp16_format_support & D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT)) |
| 884 use_fp16_ = false; | 884 use_fp16_ = false; |
| 885 | 885 |
| 886 // Enable multithreaded mode on the device. This ensures that accesses to | 886 // Enable multithreaded mode on the device. This ensures that accesses to |
| 887 // context are synchronized across threads. We have multiple threads | 887 // context are synchronized across threads. We have multiple threads |
| 888 // accessing the context, the media foundation decoder threads and the | 888 // accessing the context, the media foundation decoder threads and the |
| 889 // decoder thread via the video format conversion transform. | 889 // decoder thread via the video format conversion transform. |
| 890 hr = multi_threaded_.QueryFrom(D3D11Device()); | 890 hr = D3D11Device()->QueryInterface(IID_PPV_ARGS(&multi_threaded_)); |
| 891 RETURN_ON_HR_FAILURE(hr, "Failed to query ID3D10Multithread", false); | 891 RETURN_ON_HR_FAILURE(hr, "Failed to query ID3D10Multithread", false); |
| 892 multi_threaded_->SetMultithreadProtected(TRUE); | 892 multi_threaded_->SetMultithreadProtected(TRUE); |
| 893 | 893 |
| 894 hr = d3d11_device_manager_->ResetDevice(D3D11Device(), | 894 hr = d3d11_device_manager_->ResetDevice(D3D11Device(), |
| 895 dx11_dev_manager_reset_token_); | 895 dx11_dev_manager_reset_token_); |
| 896 RETURN_ON_HR_FAILURE(hr, "Failed to reset device", false); | 896 RETURN_ON_HR_FAILURE(hr, "Failed to reset device", false); |
| 897 | 897 |
| 898 D3D11_QUERY_DESC query_desc; | 898 D3D11_QUERY_DESC query_desc; |
| 899 query_desc.Query = D3D11_QUERY_EVENT; | 899 query_desc.Query = D3D11_QUERY_EVENT; |
| 900 query_desc.MiscFlags = 0; | 900 query_desc.MiscFlags = 0; |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 static bool legacy_gpu = true; | 1397 static bool legacy_gpu = true; |
| 1398 // This flag ensures that we determine the GPU type once. | 1398 // This flag ensures that we determine the GPU type once. |
| 1399 static bool legacy_gpu_determined = false; | 1399 static bool legacy_gpu_determined = false; |
| 1400 | 1400 |
| 1401 if (legacy_gpu_determined) | 1401 if (legacy_gpu_determined) |
| 1402 return legacy_gpu; | 1402 return legacy_gpu; |
| 1403 | 1403 |
| 1404 legacy_gpu_determined = true; | 1404 legacy_gpu_determined = true; |
| 1405 | 1405 |
| 1406 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; | 1406 base::win::ScopedComPtr<IDXGIDevice> dxgi_device; |
| 1407 HRESULT hr = dxgi_device.QueryFrom(device); | 1407 HRESULT hr = device->QueryInterface(IID_PPV_ARGS(&dxgi_device)); |
| 1408 if (FAILED(hr)) | 1408 if (FAILED(hr)) |
| 1409 return legacy_gpu; | 1409 return legacy_gpu; |
| 1410 | 1410 |
| 1411 base::win::ScopedComPtr<IDXGIAdapter> adapter; | 1411 base::win::ScopedComPtr<IDXGIAdapter> adapter; |
| 1412 hr = dxgi_device->GetAdapter(adapter.GetAddressOf()); | 1412 hr = dxgi_device->GetAdapter(adapter.GetAddressOf()); |
| 1413 if (FAILED(hr)) | 1413 if (FAILED(hr)) |
| 1414 return legacy_gpu; | 1414 return legacy_gpu; |
| 1415 | 1415 |
| 1416 DXGI_ADAPTER_DESC adapter_desc = {}; | 1416 DXGI_ADAPTER_DESC adapter_desc = {}; |
| 1417 hr = adapter->GetDesc(&adapter_desc); | 1417 hr = adapter->GetDesc(&adapter_desc); |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1952 HRESULT hr = pending_sample->output_sample->GetBufferByIndex( | 1952 HRESULT hr = pending_sample->output_sample->GetBufferByIndex( |
| 1953 0, output_buffer.GetAddressOf()); | 1953 0, output_buffer.GetAddressOf()); |
| 1954 RETURN_AND_NOTIFY_ON_HR_FAILURE( | 1954 RETURN_AND_NOTIFY_ON_HR_FAILURE( |
| 1955 hr, "Failed to get buffer from output sample", PLATFORM_FAILURE, ); | 1955 hr, "Failed to get buffer from output sample", PLATFORM_FAILURE, ); |
| 1956 | 1956 |
| 1957 base::win::ScopedComPtr<IDirect3DSurface9> surface; | 1957 base::win::ScopedComPtr<IDirect3DSurface9> surface; |
| 1958 base::win::ScopedComPtr<ID3D11Texture2D> d3d11_texture; | 1958 base::win::ScopedComPtr<ID3D11Texture2D> d3d11_texture; |
| 1959 | 1959 |
| 1960 if (use_dx11_) { | 1960 if (use_dx11_) { |
| 1961 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; | 1961 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; |
| 1962 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); | 1962 hr = output_buffer.CopyTo(dxgi_buffer.GetAddressOf()); |
| 1963 RETURN_AND_NOTIFY_ON_HR_FAILURE( | 1963 RETURN_AND_NOTIFY_ON_HR_FAILURE( |
| 1964 hr, "Failed to get DXGIBuffer from output sample", | 1964 hr, "Failed to get DXGIBuffer from output sample", |
| 1965 PLATFORM_FAILURE, ); | 1965 PLATFORM_FAILURE, ); |
| 1966 hr = dxgi_buffer->GetResource( | 1966 hr = dxgi_buffer->GetResource( |
| 1967 __uuidof(ID3D11Texture2D), | 1967 __uuidof(ID3D11Texture2D), |
| 1968 reinterpret_cast<void**>(d3d11_texture.GetAddressOf())); | 1968 reinterpret_cast<void**>(d3d11_texture.GetAddressOf())); |
| 1969 } else { | 1969 } else { |
| 1970 hr = MFGetService(output_buffer.Get(), MR_BUFFER_SERVICE, | 1970 hr = MFGetService(output_buffer.Get(), MR_BUFFER_SERVICE, |
| 1971 IID_PPV_ARGS(surface.GetAddressOf())); | 1971 IID_PPV_ARGS(surface.GetAddressOf())); |
| 1972 } | 1972 } |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2687 hr == S_OK, "D3D11 failed to acquire keyed mutex for texture.", | 2687 hr == S_OK, "D3D11 failed to acquire keyed mutex for texture.", |
| 2688 PLATFORM_FAILURE, ); | 2688 PLATFORM_FAILURE, ); |
| 2689 } | 2689 } |
| 2690 | 2690 |
| 2691 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; | 2691 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; |
| 2692 hr = input_sample->GetBufferByIndex(0, output_buffer.GetAddressOf()); | 2692 hr = input_sample->GetBufferByIndex(0, output_buffer.GetAddressOf()); |
| 2693 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", | 2693 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", |
| 2694 PLATFORM_FAILURE, ); | 2694 PLATFORM_FAILURE, ); |
| 2695 | 2695 |
| 2696 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; | 2696 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; |
| 2697 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); | 2697 hr = output_buffer.CopyTo(dxgi_buffer.GetAddressOf()); |
| 2698 RETURN_AND_NOTIFY_ON_HR_FAILURE( | 2698 RETURN_AND_NOTIFY_ON_HR_FAILURE( |
| 2699 hr, "Failed to get DXGIBuffer from output sample", PLATFORM_FAILURE, ); | 2699 hr, "Failed to get DXGIBuffer from output sample", PLATFORM_FAILURE, ); |
| 2700 UINT index = 0; | 2700 UINT index = 0; |
| 2701 hr = dxgi_buffer->GetSubresourceIndex(&index); | 2701 hr = dxgi_buffer->GetSubresourceIndex(&index); |
| 2702 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get resource index", | 2702 RETURN_AND_NOTIFY_ON_HR_FAILURE(hr, "Failed to get resource index", |
| 2703 PLATFORM_FAILURE, ); | 2703 PLATFORM_FAILURE, ); |
| 2704 | 2704 |
| 2705 base::win::ScopedComPtr<ID3D11Texture2D> dx11_decoding_texture; | 2705 base::win::ScopedComPtr<ID3D11Texture2D> dx11_decoding_texture; |
| 2706 hr = dxgi_buffer->GetResource( | 2706 hr = dxgi_buffer->GetResource( |
| 2707 IID_PPV_ARGS(dx11_decoding_texture.GetAddressOf())); | 2707 IID_PPV_ARGS(dx11_decoding_texture.GetAddressOf())); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2925 bool DXVAVideoDecodeAccelerator::GetVideoFrameDimensions(IMFSample* sample, | 2925 bool DXVAVideoDecodeAccelerator::GetVideoFrameDimensions(IMFSample* sample, |
| 2926 int* width, | 2926 int* width, |
| 2927 int* height) { | 2927 int* height) { |
| 2928 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; | 2928 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; |
| 2929 HRESULT hr = sample->GetBufferByIndex(0, output_buffer.GetAddressOf()); | 2929 HRESULT hr = sample->GetBufferByIndex(0, output_buffer.GetAddressOf()); |
| 2930 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", false); | 2930 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", false); |
| 2931 | 2931 |
| 2932 if (use_dx11_) { | 2932 if (use_dx11_) { |
| 2933 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; | 2933 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; |
| 2934 base::win::ScopedComPtr<ID3D11Texture2D> d3d11_texture; | 2934 base::win::ScopedComPtr<ID3D11Texture2D> d3d11_texture; |
| 2935 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); | 2935 hr = output_buffer.CopyTo(dxgi_buffer.GetAddressOf()); |
| 2936 RETURN_ON_HR_FAILURE(hr, "Failed to get DXGIBuffer from output sample", | 2936 RETURN_ON_HR_FAILURE(hr, "Failed to get DXGIBuffer from output sample", |
| 2937 false); | 2937 false); |
| 2938 hr = dxgi_buffer->GetResource( | 2938 hr = dxgi_buffer->GetResource( |
| 2939 __uuidof(ID3D11Texture2D), | 2939 __uuidof(ID3D11Texture2D), |
| 2940 reinterpret_cast<void**>(d3d11_texture.GetAddressOf())); | 2940 reinterpret_cast<void**>(d3d11_texture.GetAddressOf())); |
| 2941 RETURN_ON_HR_FAILURE(hr, "Failed to get D3D11Texture from output buffer", | 2941 RETURN_ON_HR_FAILURE(hr, "Failed to get D3D11Texture from output buffer", |
| 2942 false); | 2942 false); |
| 2943 D3D11_TEXTURE2D_DESC d3d11_texture_desc; | 2943 D3D11_TEXTURE2D_DESC d3d11_texture_desc; |
| 2944 d3d11_texture->GetDesc(&d3d11_texture_desc); | 2944 d3d11_texture->GetDesc(&d3d11_texture_desc); |
| 2945 *width = d3d11_texture_desc.Width; | 2945 *width = d3d11_texture_desc.Width; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3024 uint32_t DXVAVideoDecodeAccelerator::GetTextureTarget() const { | 3024 uint32_t DXVAVideoDecodeAccelerator::GetTextureTarget() const { |
| 3025 bool provide_nv12_textures = share_nv12_textures_ || copy_nv12_textures_; | 3025 bool provide_nv12_textures = share_nv12_textures_ || copy_nv12_textures_; |
| 3026 return provide_nv12_textures ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; | 3026 return provide_nv12_textures ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; |
| 3027 } | 3027 } |
| 3028 | 3028 |
| 3029 ID3D11Device* DXVAVideoDecodeAccelerator::D3D11Device() const { | 3029 ID3D11Device* DXVAVideoDecodeAccelerator::D3D11Device() const { |
| 3030 return share_nv12_textures_ ? angle_device_.Get() : d3d11_device_.Get(); | 3030 return share_nv12_textures_ ? angle_device_.Get() : d3d11_device_.Get(); |
| 3031 } | 3031 } |
| 3032 | 3032 |
| 3033 } // namespace media | 3033 } // namespace media |
| OLD | NEW |