| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 return false; | 304 return false; |
| 305 } | 305 } |
| 306 | 306 |
| 307 hr = decoder->d3d9_->CheckDeviceFormatConversion( | 307 hr = decoder->d3d9_->CheckDeviceFormatConversion( |
| 308 D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, surface_desc.Format, | 308 D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, surface_desc.Format, |
| 309 use_rgb_ ? D3DFMT_X8R8G8B8 : D3DFMT_A8R8G8B8); | 309 use_rgb_ ? D3DFMT_X8R8G8B8 : D3DFMT_A8R8G8B8); |
| 310 RETURN_ON_HR_FAILURE(hr, "Device does not support format converision", false); | 310 RETURN_ON_HR_FAILURE(hr, "Device does not support format converision", false); |
| 311 | 311 |
| 312 // The same picture buffer can be reused for a different frame. Release the | 312 // The same picture buffer can be reused for a different frame. Release the |
| 313 // target surface and the decoder references here. | 313 // target surface and the decoder references here. |
| 314 target_surface_.Release(); | 314 target_surface_.Reset(); |
| 315 decoder_surface_.Release(); | 315 decoder_surface_.Reset(); |
| 316 | 316 |
| 317 // Grab a reference on the decoder surface and the target surface. These | 317 // Grab a reference on the decoder surface and the target surface. These |
| 318 // references will be released when we receive a notification that the | 318 // references will be released when we receive a notification that the |
| 319 // copy was completed or when the DXVAPictureBuffer instance is destroyed. | 319 // copy was completed or when the DXVAPictureBuffer instance is destroyed. |
| 320 // We hold references here as it is easier to manage their lifetimes. | 320 // We hold references here as it is easier to manage their lifetimes. |
| 321 hr = decoding_texture_->GetSurfaceLevel(0, target_surface_.Receive()); | 321 hr = decoding_texture_->GetSurfaceLevel(0, target_surface_.Receive()); |
| 322 RETURN_ON_HR_FAILURE(hr, "Failed to get surface from texture", false); | 322 RETURN_ON_HR_FAILURE(hr, "Failed to get surface from texture", false); |
| 323 | 323 |
| 324 decoder_surface_ = dest_surface; | 324 decoder_surface_ = dest_surface; |
| 325 | 325 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 342 GLint current_texture = 0; | 342 GLint current_texture = 0; |
| 343 glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture); | 343 glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture); |
| 344 | 344 |
| 345 glBindTexture(GL_TEXTURE_2D, picture_buffer_.service_texture_ids()[0]); | 345 glBindTexture(GL_TEXTURE_2D, picture_buffer_.service_texture_ids()[0]); |
| 346 | 346 |
| 347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 348 | 348 |
| 349 if (src_surface && dest_surface) { | 349 if (src_surface && dest_surface) { |
| 350 DCHECK_EQ(src_surface, decoder_surface_.get()); | 350 DCHECK_EQ(src_surface, decoder_surface_.get()); |
| 351 DCHECK_EQ(dest_surface, target_surface_.get()); | 351 DCHECK_EQ(dest_surface, target_surface_.get()); |
| 352 decoder_surface_.Release(); | 352 decoder_surface_.Reset(); |
| 353 target_surface_.Release(); | 353 target_surface_.Reset(); |
| 354 } else { | 354 } else { |
| 355 DCHECK(decoder_dx11_texture_.get()); | 355 DCHECK(decoder_dx11_texture_.get()); |
| 356 decoder_dx11_texture_.Release(); | 356 decoder_dx11_texture_.Reset(); |
| 357 } | 357 } |
| 358 if (egl_keyed_mutex_) { | 358 if (egl_keyed_mutex_) { |
| 359 keyed_mutex_value_++; | 359 keyed_mutex_value_++; |
| 360 HRESULT result = | 360 HRESULT result = |
| 361 egl_keyed_mutex_->AcquireSync(keyed_mutex_value_, kAcquireSyncWaitMs); | 361 egl_keyed_mutex_->AcquireSync(keyed_mutex_value_, kAcquireSyncWaitMs); |
| 362 RETURN_ON_FAILURE(result == S_OK, "Could not acquire sync mutex", false); | 362 RETURN_ON_FAILURE(result == S_OK, "Could not acquire sync mutex", false); |
| 363 } | 363 } |
| 364 | 364 |
| 365 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); | 365 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); |
| 366 eglBindTexImage(egl_display, decoding_surface_, EGL_BACK_BUFFER); | 366 eglBindTexImage(egl_display, decoding_surface_, EGL_BACK_BUFFER); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 384 PbufferPictureBuffer::~PbufferPictureBuffer() { | 384 PbufferPictureBuffer::~PbufferPictureBuffer() { |
| 385 // decoding_surface_ will be deleted by gl_image_. | 385 // decoding_surface_ will be deleted by gl_image_. |
| 386 } | 386 } |
| 387 | 387 |
| 388 bool PbufferPictureBuffer::ReusePictureBuffer() { | 388 bool PbufferPictureBuffer::ReusePictureBuffer() { |
| 389 DCHECK_NE(UNUSED, state_); | 389 DCHECK_NE(UNUSED, state_); |
| 390 DCHECK(decoding_surface_); | 390 DCHECK(decoding_surface_); |
| 391 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); | 391 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); |
| 392 eglReleaseTexImage(egl_display, decoding_surface_, EGL_BACK_BUFFER); | 392 eglReleaseTexImage(egl_display, decoding_surface_, EGL_BACK_BUFFER); |
| 393 | 393 |
| 394 decoder_surface_.Release(); | 394 decoder_surface_.Reset(); |
| 395 target_surface_.Release(); | 395 target_surface_.Reset(); |
| 396 decoder_dx11_texture_.Release(); | 396 decoder_dx11_texture_.Reset(); |
| 397 state_ = UNUSED; | 397 state_ = UNUSED; |
| 398 if (egl_keyed_mutex_) { | 398 if (egl_keyed_mutex_) { |
| 399 HRESULT hr = egl_keyed_mutex_->ReleaseSync(++keyed_mutex_value_); | 399 HRESULT hr = egl_keyed_mutex_->ReleaseSync(++keyed_mutex_value_); |
| 400 RETURN_ON_FAILURE(hr == S_OK, "Could not release sync mutex", false); | 400 RETURN_ON_FAILURE(hr == S_OK, "Could not release sync mutex", false); |
| 401 } | 401 } |
| 402 return true; | 402 return true; |
| 403 } | 403 } |
| 404 | 404 |
| 405 EGLStreamPictureBuffer::EGLStreamPictureBuffer(const PictureBuffer& buffer) | 405 EGLStreamPictureBuffer::EGLStreamPictureBuffer(const PictureBuffer& buffer) |
| 406 : DXVAPictureBuffer(buffer), stream_(nullptr) {} | 406 : DXVAPictureBuffer(buffer), stream_(nullptr) {} |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 458 |
| 459 bool EGLStreamPictureBuffer::ReusePictureBuffer() { | 459 bool EGLStreamPictureBuffer::ReusePictureBuffer() { |
| 460 DCHECK_NE(UNUSED, state_); | 460 DCHECK_NE(UNUSED, state_); |
| 461 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); | 461 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); |
| 462 | 462 |
| 463 if (stream_) { | 463 if (stream_) { |
| 464 EGLBoolean result = eglStreamConsumerReleaseKHR(egl_display, stream_); | 464 EGLBoolean result = eglStreamConsumerReleaseKHR(egl_display, stream_); |
| 465 RETURN_ON_FAILURE(result, "Could not release stream", false); | 465 RETURN_ON_FAILURE(result, "Could not release stream", false); |
| 466 } | 466 } |
| 467 if (current_d3d_sample_) { | 467 if (current_d3d_sample_) { |
| 468 dx11_decoding_texture_.Release(); | 468 dx11_decoding_texture_.Reset(); |
| 469 current_d3d_sample_.Release(); | 469 current_d3d_sample_.Reset(); |
| 470 } | 470 } |
| 471 state_ = UNUSED; | 471 state_ = UNUSED; |
| 472 return true; | 472 return true; |
| 473 } | 473 } |
| 474 | 474 |
| 475 bool EGLStreamPictureBuffer::BindSampleToTexture( | 475 bool EGLStreamPictureBuffer::BindSampleToTexture( |
| 476 base::win::ScopedComPtr<IMFSample> sample) { | 476 base::win::ScopedComPtr<IMFSample> sample) { |
| 477 DCHECK_EQ(BOUND, state_); | 477 DCHECK_EQ(BOUND, state_); |
| 478 state_ = IN_CLIENT; | 478 state_ = IN_CLIENT; |
| 479 | 479 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 } | 628 } |
| 629 | 629 |
| 630 bool EGLStreamCopyPictureBuffer::CopySurfaceComplete( | 630 bool EGLStreamCopyPictureBuffer::CopySurfaceComplete( |
| 631 IDirect3DSurface9* src_surface, | 631 IDirect3DSurface9* src_surface, |
| 632 IDirect3DSurface9* dest_surface) { | 632 IDirect3DSurface9* dest_surface) { |
| 633 DCHECK(!src_surface); | 633 DCHECK(!src_surface); |
| 634 DCHECK(!dest_surface); | 634 DCHECK(!dest_surface); |
| 635 DCHECK_EQ(COPYING, state_); | 635 DCHECK_EQ(COPYING, state_); |
| 636 state_ = IN_CLIENT; | 636 state_ = IN_CLIENT; |
| 637 | 637 |
| 638 dx11_decoding_texture_.Release(); | 638 dx11_decoding_texture_.Reset(); |
| 639 | 639 |
| 640 HRESULT hr = | 640 HRESULT hr = |
| 641 egl_keyed_mutex_->AcquireSync(keyed_mutex_value_, kAcquireSyncWaitMs); | 641 egl_keyed_mutex_->AcquireSync(keyed_mutex_value_, kAcquireSyncWaitMs); |
| 642 RETURN_ON_FAILURE(hr == S_OK, "Could not acquire sync mutex", false); | 642 RETURN_ON_FAILURE(hr == S_OK, "Could not acquire sync mutex", false); |
| 643 | 643 |
| 644 EGLAttrib frame_attributes[] = { | 644 EGLAttrib frame_attributes[] = { |
| 645 EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, 0, EGL_NONE, | 645 EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, 0, EGL_NONE, |
| 646 }; | 646 }; |
| 647 | 647 |
| 648 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); | 648 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 677 RETURN_ON_FAILURE(result, "Could not release stream", false); | 677 RETURN_ON_FAILURE(result, "Could not release stream", false); |
| 678 } | 678 } |
| 679 return true; | 679 return true; |
| 680 } | 680 } |
| 681 | 681 |
| 682 bool EGLStreamCopyPictureBuffer::AllowOverlay() const { | 682 bool EGLStreamCopyPictureBuffer::AllowOverlay() const { |
| 683 return true; | 683 return true; |
| 684 } | 684 } |
| 685 | 685 |
| 686 } // namespace media | 686 } // namespace media |
| OLD | NEW |