OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_picture_buffer_win.h" | 5 #include "media/gpu/dxva_picture_buffer_win.h" |
6 | 6 |
7 #include "media/gpu/dxva_video_decode_accelerator_win.h" | 7 #include "media/gpu/dxva_video_decode_accelerator_win.h" |
8 #include "third_party/angle/include/EGL/egl.h" | 8 #include "third_party/angle/include/EGL/egl.h" |
9 #include "third_party/angle/include/EGL/eglext.h" | 9 #include "third_party/angle/include/EGL/eglext.h" |
10 #include "ui/gl/gl_bindings.h" | 10 #include "ui/gl/gl_bindings.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 desc.SampleDesc.Count = 1; | 230 desc.SampleDesc.Count = 1; |
231 desc.SampleDesc.Quality = 0; | 231 desc.SampleDesc.Quality = 0; |
232 desc.Usage = D3D11_USAGE_DEFAULT; | 232 desc.Usage = D3D11_USAGE_DEFAULT; |
233 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; | 233 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; |
234 desc.CPUAccessFlags = 0; | 234 desc.CPUAccessFlags = 0; |
235 desc.MiscFlags = decoder.use_keyed_mutex_ | 235 desc.MiscFlags = decoder.use_keyed_mutex_ |
236 ? D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | 236 ? D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX |
237 : D3D11_RESOURCE_MISC_SHARED; | 237 : D3D11_RESOURCE_MISC_SHARED; |
238 | 238 |
239 HRESULT hr = decoder.d3d11_device_->CreateTexture2D( | 239 HRESULT hr = decoder.d3d11_device_->CreateTexture2D( |
240 &desc, nullptr, dx11_decoding_texture_.Receive()); | 240 &desc, nullptr, dx11_decoding_texture_.GetAddressOf()); |
241 RETURN_ON_HR_FAILURE(hr, "Failed to create texture", false); | 241 RETURN_ON_HR_FAILURE(hr, "Failed to create texture", false); |
242 if (decoder.use_keyed_mutex_) { | 242 if (decoder.use_keyed_mutex_) { |
243 hr = dx11_keyed_mutex_.QueryFrom(dx11_decoding_texture_.Get()); | 243 hr = dx11_keyed_mutex_.QueryFrom(dx11_decoding_texture_.Get()); |
244 RETURN_ON_HR_FAILURE(hr, "Failed to get keyed mutex", false); | 244 RETURN_ON_HR_FAILURE(hr, "Failed to get keyed mutex", false); |
245 } | 245 } |
246 | 246 |
247 base::win::ScopedComPtr<IDXGIResource> resource; | 247 base::win::ScopedComPtr<IDXGIResource> resource; |
248 hr = resource.QueryFrom(dx11_decoding_texture_.Get()); | 248 hr = resource.QueryFrom(dx11_decoding_texture_.Get()); |
249 DCHECK(SUCCEEDED(hr)); | 249 DCHECK(SUCCEEDED(hr)); |
250 hr = resource->GetSharedHandle(&texture_share_handle_); | 250 hr = resource->GetSharedHandle(&texture_share_handle_); |
251 RETURN_ON_FAILURE(SUCCEEDED(hr) && texture_share_handle_, | 251 RETURN_ON_FAILURE(SUCCEEDED(hr) && texture_share_handle_, |
252 "Failed to query shared handle", false); | 252 "Failed to query shared handle", false); |
253 | 253 |
254 } else { | 254 } else { |
255 HRESULT hr = E_FAIL; | 255 HRESULT hr = E_FAIL; |
256 hr = decoder.d3d9_device_ex_->CreateTexture( | 256 hr = decoder.d3d9_device_ex_->CreateTexture( |
257 picture_buffer_.size().width(), picture_buffer_.size().height(), 1, | 257 picture_buffer_.size().width(), picture_buffer_.size().height(), 1, |
258 D3DUSAGE_RENDERTARGET, use_rgb ? D3DFMT_X8R8G8B8 : D3DFMT_A8R8G8B8, | 258 D3DUSAGE_RENDERTARGET, use_rgb ? D3DFMT_X8R8G8B8 : D3DFMT_A8R8G8B8, |
259 D3DPOOL_DEFAULT, decoding_texture_.Receive(), &texture_share_handle_); | 259 D3DPOOL_DEFAULT, decoding_texture_.GetAddressOf(), |
| 260 &texture_share_handle_); |
260 RETURN_ON_HR_FAILURE(hr, "Failed to create texture", false); | 261 RETURN_ON_HR_FAILURE(hr, "Failed to create texture", false); |
261 RETURN_ON_FAILURE(texture_share_handle_, "Failed to query shared handle", | 262 RETURN_ON_FAILURE(texture_share_handle_, "Failed to query shared handle", |
262 false); | 263 false); |
263 } | 264 } |
264 return true; | 265 return true; |
265 } | 266 } |
266 | 267 |
267 void PbufferPictureBuffer::ResetReuseFence() { | 268 void PbufferPictureBuffer::ResetReuseFence() { |
268 DCHECK_EQ(IN_CLIENT, state_); | 269 DCHECK_EQ(IN_CLIENT, state_); |
269 if (!reuse_fence_ || !reuse_fence_->ResetSupported()) | 270 if (!reuse_fence_ || !reuse_fence_->ResetSupported()) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 312 |
312 // The same picture buffer can be reused for a different frame. Release the | 313 // The same picture buffer can be reused for a different frame. Release the |
313 // target surface and the decoder references here. | 314 // target surface and the decoder references here. |
314 target_surface_.Reset(); | 315 target_surface_.Reset(); |
315 decoder_surface_.Reset(); | 316 decoder_surface_.Reset(); |
316 | 317 |
317 // Grab a reference on the decoder surface and the target surface. These | 318 // Grab a reference on the decoder surface and the target surface. These |
318 // references will be released when we receive a notification that the | 319 // references will be released when we receive a notification that the |
319 // copy was completed or when the DXVAPictureBuffer instance is destroyed. | 320 // copy was completed or when the DXVAPictureBuffer instance is destroyed. |
320 // We hold references here as it is easier to manage their lifetimes. | 321 // We hold references here as it is easier to manage their lifetimes. |
321 hr = decoding_texture_->GetSurfaceLevel(0, target_surface_.Receive()); | 322 hr = decoding_texture_->GetSurfaceLevel(0, target_surface_.GetAddressOf()); |
322 RETURN_ON_HR_FAILURE(hr, "Failed to get surface from texture", false); | 323 RETURN_ON_HR_FAILURE(hr, "Failed to get surface from texture", false); |
323 | 324 |
324 decoder_surface_ = dest_surface; | 325 decoder_surface_ = dest_surface; |
325 | 326 |
326 decoder->CopySurface(decoder_surface_.Get(), target_surface_.Get(), id(), | 327 decoder->CopySurface(decoder_surface_.Get(), target_surface_.Get(), id(), |
327 input_buffer_id, color_space_); | 328 input_buffer_id, color_space_); |
328 color_space_ = gfx::ColorSpace(); | 329 color_space_ = gfx::ColorSpace(); |
329 return true; | 330 return true; |
330 } | 331 } |
331 | 332 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 bool EGLStreamPictureBuffer::BindSampleToTexture( | 476 bool EGLStreamPictureBuffer::BindSampleToTexture( |
476 base::win::ScopedComPtr<IMFSample> sample) { | 477 base::win::ScopedComPtr<IMFSample> sample) { |
477 DCHECK_EQ(BOUND, state_); | 478 DCHECK_EQ(BOUND, state_); |
478 state_ = IN_CLIENT; | 479 state_ = IN_CLIENT; |
479 | 480 |
480 current_d3d_sample_ = sample; | 481 current_d3d_sample_ = sample; |
481 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); | 482 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); |
482 | 483 |
483 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; | 484 base::win::ScopedComPtr<IMFMediaBuffer> output_buffer; |
484 HRESULT hr = | 485 HRESULT hr = |
485 current_d3d_sample_->GetBufferByIndex(0, output_buffer.Receive()); | 486 current_d3d_sample_->GetBufferByIndex(0, output_buffer.GetAddressOf()); |
486 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", false); | 487 RETURN_ON_HR_FAILURE(hr, "Failed to get buffer from output sample", false); |
487 | 488 |
488 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; | 489 base::win::ScopedComPtr<IMFDXGIBuffer> dxgi_buffer; |
489 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); | 490 hr = dxgi_buffer.QueryFrom(output_buffer.Get()); |
490 RETURN_ON_HR_FAILURE(hr, "Failed to get DXGIBuffer from output sample", | 491 RETURN_ON_HR_FAILURE(hr, "Failed to get DXGIBuffer from output sample", |
491 false); | 492 false); |
492 hr = dxgi_buffer->GetResource(IID_PPV_ARGS(dx11_decoding_texture_.Receive())); | 493 hr = dxgi_buffer->GetResource( |
| 494 IID_PPV_ARGS(dx11_decoding_texture_.GetAddressOf())); |
493 RETURN_ON_HR_FAILURE(hr, "Failed to get texture from output sample", false); | 495 RETURN_ON_HR_FAILURE(hr, "Failed to get texture from output sample", false); |
494 UINT subresource; | 496 UINT subresource; |
495 dxgi_buffer->GetSubresourceIndex(&subresource); | 497 dxgi_buffer->GetSubresourceIndex(&subresource); |
496 | 498 |
497 EGLAttrib frame_attributes[] = { | 499 EGLAttrib frame_attributes[] = { |
498 EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, subresource, EGL_NONE, | 500 EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, subresource, EGL_NONE, |
499 }; | 501 }; |
500 | 502 |
501 EGLBoolean result = eglStreamPostD3DTextureNV12ANGLE( | 503 EGLBoolean result = eglStreamPostD3DTextureNV12ANGLE( |
502 egl_display, stream_, static_cast<void*>(dx11_decoding_texture_.Get()), | 504 egl_display, stream_, static_cast<void*>(dx11_decoding_texture_.Get()), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 desc.ArraySize = 1; | 580 desc.ArraySize = 1; |
579 desc.Format = DXGI_FORMAT_NV12; | 581 desc.Format = DXGI_FORMAT_NV12; |
580 desc.SampleDesc.Count = 1; | 582 desc.SampleDesc.Count = 1; |
581 desc.SampleDesc.Quality = 0; | 583 desc.SampleDesc.Quality = 0; |
582 desc.Usage = D3D11_USAGE_DEFAULT; | 584 desc.Usage = D3D11_USAGE_DEFAULT; |
583 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; | 585 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; |
584 desc.CPUAccessFlags = 0; | 586 desc.CPUAccessFlags = 0; |
585 desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX; | 587 desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX; |
586 | 588 |
587 HRESULT hr = decoder.d3d11_device_->CreateTexture2D( | 589 HRESULT hr = decoder.d3d11_device_->CreateTexture2D( |
588 &desc, nullptr, decoder_copy_texture_.Receive()); | 590 &desc, nullptr, decoder_copy_texture_.GetAddressOf()); |
589 RETURN_ON_HR_FAILURE(hr, "Failed to create texture", false); | 591 RETURN_ON_HR_FAILURE(hr, "Failed to create texture", false); |
590 DCHECK(decoder.use_keyed_mutex_); | 592 DCHECK(decoder.use_keyed_mutex_); |
591 hr = dx11_keyed_mutex_.QueryFrom(decoder_copy_texture_.Get()); | 593 hr = dx11_keyed_mutex_.QueryFrom(decoder_copy_texture_.Get()); |
592 RETURN_ON_HR_FAILURE(hr, "Failed to get keyed mutex", false); | 594 RETURN_ON_HR_FAILURE(hr, "Failed to get keyed mutex", false); |
593 | 595 |
594 base::win::ScopedComPtr<IDXGIResource> resource; | 596 base::win::ScopedComPtr<IDXGIResource> resource; |
595 hr = resource.QueryFrom(decoder_copy_texture_.Get()); | 597 hr = resource.QueryFrom(decoder_copy_texture_.Get()); |
596 DCHECK(SUCCEEDED(hr)); | 598 DCHECK(SUCCEEDED(hr)); |
597 hr = resource->GetSharedHandle(&texture_share_handle_); | 599 hr = resource->GetSharedHandle(&texture_share_handle_); |
598 RETURN_ON_FAILURE(SUCCEEDED(hr) && texture_share_handle_, | 600 RETURN_ON_FAILURE(SUCCEEDED(hr) && texture_share_handle_, |
599 "Failed to query shared handle", false); | 601 "Failed to query shared handle", false); |
600 | 602 |
601 hr = decoder.angle_device_->OpenSharedResource( | 603 hr = decoder.angle_device_->OpenSharedResource( |
602 texture_share_handle_, IID_PPV_ARGS(angle_copy_texture_.Receive())); | 604 texture_share_handle_, IID_PPV_ARGS(angle_copy_texture_.GetAddressOf())); |
603 RETURN_ON_HR_FAILURE(hr, "Failed to open shared resource", false); | 605 RETURN_ON_HR_FAILURE(hr, "Failed to open shared resource", false); |
604 hr = egl_keyed_mutex_.QueryFrom(angle_copy_texture_.Get()); | 606 hr = egl_keyed_mutex_.QueryFrom(angle_copy_texture_.Get()); |
605 RETURN_ON_HR_FAILURE(hr, "Failed to get ANGLE mutex", false); | 607 RETURN_ON_HR_FAILURE(hr, "Failed to get ANGLE mutex", false); |
606 return true; | 608 return true; |
607 } | 609 } |
608 | 610 |
609 bool EGLStreamCopyPictureBuffer::CopyOutputSampleDataToPictureBuffer( | 611 bool EGLStreamCopyPictureBuffer::CopyOutputSampleDataToPictureBuffer( |
610 DXVAVideoDecodeAccelerator* decoder, | 612 DXVAVideoDecodeAccelerator* decoder, |
611 IDirect3DSurface9* dest_surface, | 613 IDirect3DSurface9* dest_surface, |
612 ID3D11Texture2D* dx11_texture, | 614 ID3D11Texture2D* dx11_texture, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 RETURN_ON_FAILURE(result, "Could not release stream", false); | 679 RETURN_ON_FAILURE(result, "Could not release stream", false); |
678 } | 680 } |
679 return true; | 681 return true; |
680 } | 682 } |
681 | 683 |
682 bool EGLStreamCopyPictureBuffer::AllowOverlay() const { | 684 bool EGLStreamCopyPictureBuffer::AllowOverlay() const { |
683 return true; | 685 return true; |
684 } | 686 } |
685 | 687 |
686 } // namespace media | 688 } // namespace media |
OLD | NEW |