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

Side by Side Diff: media/gpu/dxva_picture_buffer_win.cc

Issue 2742593002: Add GLImageDXGI (Closed)
Patch Set: centralize cast Created 3 years, 9 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 | ui/gl/BUILD.gn » ('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 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"
11 #include "ui/gl/gl_context.h" 11 #include "ui/gl/gl_context.h"
12 #include "ui/gl/gl_fence.h" 12 #include "ui/gl/gl_fence.h"
13 #include "ui/gl/gl_image.h" 13 #include "ui/gl/gl_image.h"
14 #include "ui/gl/gl_image_dxgi.h"
14 #include "ui/gl/gl_surface_egl.h" 15 #include "ui/gl/gl_surface_egl.h"
15 #include "ui/gl/scoped_binders.h" 16 #include "ui/gl/scoped_binders.h"
16 17
17 namespace media { 18 namespace media {
18 19
19 namespace { 20 namespace {
20 21
21 void LogDXVAError(int line) { 22 void LogDXVAError(int line) {
22 LOG(ERROR) << "Error in dxva_picture_buffer_win.cc on line " << line; 23 LOG(ERROR) << "Error in dxva_picture_buffer_win.cc on line " << line;
23 } 24 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); 69 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay();
69 70
70 eglReleaseTexImage(egl_display, surface_, EGL_BACK_BUFFER); 71 eglReleaseTexImage(egl_display, surface_, EGL_BACK_BUFFER);
71 72
72 eglDestroySurface(egl_display, surface_); 73 eglDestroySurface(egl_display, surface_);
73 } 74 }
74 75
75 EGLSurface surface_; 76 EGLSurface surface_;
76 }; 77 };
77 78
78 class GLImageEGLStream : public DummyGLImage {
79 public:
80 GLImageEGLStream(const gfx::Size& size, EGLStreamKHR stream)
81 : DummyGLImage(size), stream_(stream) {}
82
83 private:
84 ~GLImageEGLStream() override {
85 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay();
86 eglDestroyStreamKHR(egl_display, stream_);
87 }
88
89 EGLStreamKHR stream_;
90 };
91
92 } // namespace 79 } // namespace
93 80
94 #define RETURN_ON_FAILURE(result, log, ret) \ 81 #define RETURN_ON_FAILURE(result, log, ret) \
95 do { \ 82 do { \
96 if (!(result)) { \ 83 if (!(result)) { \
97 DLOG(ERROR) << log; \ 84 DLOG(ERROR) << log; \
98 LogDXVAError(__LINE__); \ 85 LogDXVAError(__LINE__); \
99 return ret; \ 86 return ret; \
100 } \ 87 } \
101 } while (0) 88 } while (0)
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); 412 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay();
426 const EGLint stream_attributes[] = { 413 const EGLint stream_attributes[] = {
427 EGL_CONSUMER_LATENCY_USEC_KHR, 414 EGL_CONSUMER_LATENCY_USEC_KHR,
428 0, 415 0,
429 EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR, 416 EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR,
430 0, 417 0,
431 EGL_NONE, 418 EGL_NONE,
432 }; 419 };
433 stream_ = eglCreateStreamKHR(egl_display, stream_attributes); 420 stream_ = eglCreateStreamKHR(egl_display, stream_attributes);
434 RETURN_ON_FAILURE(!!stream_, "Could not create stream", false); 421 RETURN_ON_FAILURE(!!stream_, "Could not create stream", false);
435 gl_image_ = make_scoped_refptr(new GLImageEGLStream(size(), stream_)); 422 gl_image_ = make_scoped_refptr(new gl::GLImageDXGI(size(), stream_));
436 gl::ScopedActiveTexture texture0(GL_TEXTURE0); 423 gl::ScopedActiveTexture texture0(GL_TEXTURE0);
437 gl::ScopedTextureBinder texture0_binder( 424 gl::ScopedTextureBinder texture0_binder(
438 GL_TEXTURE_EXTERNAL_OES, picture_buffer_.service_texture_ids()[0]); 425 GL_TEXTURE_EXTERNAL_OES, picture_buffer_.service_texture_ids()[0]);
439 gl::ScopedActiveTexture texture1(GL_TEXTURE1); 426 gl::ScopedActiveTexture texture1(GL_TEXTURE1);
440 gl::ScopedTextureBinder texture1_binder( 427 gl::ScopedTextureBinder texture1_binder(
441 GL_TEXTURE_EXTERNAL_OES, picture_buffer_.service_texture_ids()[1]); 428 GL_TEXTURE_EXTERNAL_OES, picture_buffer_.service_texture_ids()[1]);
442 429
443 EGLAttrib consumer_attributes[] = { 430 EGLAttrib consumer_attributes[] = {
444 EGL_COLOR_BUFFER_TYPE, 431 EGL_COLOR_BUFFER_TYPE,
445 EGL_YUV_BUFFER_EXT, 432 EGL_YUV_BUFFER_EXT,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 EGLAttrib frame_attributes[] = { 493 EGLAttrib frame_attributes[] = {
507 EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, subresource, EGL_NONE, 494 EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, subresource, EGL_NONE,
508 }; 495 };
509 496
510 EGLBoolean result = eglStreamPostD3DTextureNV12ANGLE( 497 EGLBoolean result = eglStreamPostD3DTextureNV12ANGLE(
511 egl_display, stream_, static_cast<void*>(dx11_decoding_texture_.get()), 498 egl_display, stream_, static_cast<void*>(dx11_decoding_texture_.get()),
512 frame_attributes); 499 frame_attributes);
513 RETURN_ON_FAILURE(result, "Could not post texture", false); 500 RETURN_ON_FAILURE(result, "Could not post texture", false);
514 result = eglStreamConsumerAcquireKHR(egl_display, stream_); 501 result = eglStreamConsumerAcquireKHR(egl_display, stream_);
515 RETURN_ON_FAILURE(result, "Could not post acquire stream", false); 502 RETURN_ON_FAILURE(result, "Could not post acquire stream", false);
503 gl::GLImageDXGI* gl_image_dxgi =
504 gl::GLImageDXGI::FromGLImage(gl_image_.get());
505 DCHECK(gl_image_dxgi);
506
507 gl_image_dxgi->SetTexture(dx11_decoding_texture_, subresource);
516 return true; 508 return true;
517 } 509 }
518 510
519 EGLStreamCopyPictureBuffer::EGLStreamCopyPictureBuffer( 511 EGLStreamCopyPictureBuffer::EGLStreamCopyPictureBuffer(
520 const PictureBuffer& buffer) 512 const PictureBuffer& buffer)
521 : DXVAPictureBuffer(buffer), stream_(nullptr) {} 513 : DXVAPictureBuffer(buffer), stream_(nullptr) {}
522 514
523 EGLStreamCopyPictureBuffer::~EGLStreamCopyPictureBuffer() { 515 EGLStreamCopyPictureBuffer::~EGLStreamCopyPictureBuffer() {
524 // stream_ will be deleted by gl_image_. 516 // stream_ will be deleted by gl_image_.
525 } 517 }
526 518
527 bool EGLStreamCopyPictureBuffer::Initialize( 519 bool EGLStreamCopyPictureBuffer::Initialize(
528 const DXVAVideoDecodeAccelerator& decoder) { 520 const DXVAVideoDecodeAccelerator& decoder) {
529 RETURN_ON_FAILURE(picture_buffer_.service_texture_ids().size() >= 2, 521 RETURN_ON_FAILURE(picture_buffer_.service_texture_ids().size() >= 2,
530 "Not enough texture ids provided", false); 522 "Not enough texture ids provided", false);
531 523
532 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); 524 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay();
533 const EGLint stream_attributes[] = { 525 const EGLint stream_attributes[] = {
534 EGL_CONSUMER_LATENCY_USEC_KHR, 526 EGL_CONSUMER_LATENCY_USEC_KHR,
535 0, 527 0,
536 EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR, 528 EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR,
537 0, 529 0,
538 EGL_NONE, 530 EGL_NONE,
539 }; 531 };
540 stream_ = eglCreateStreamKHR(egl_display, stream_attributes); 532 stream_ = eglCreateStreamKHR(egl_display, stream_attributes);
541 RETURN_ON_FAILURE(!!stream_, "Could not create stream", false); 533 RETURN_ON_FAILURE(!!stream_, "Could not create stream", false);
542 gl_image_ = make_scoped_refptr(new GLImageEGLStream(size(), stream_)); 534 gl_image_ = make_scoped_refptr(new gl::GLImageDXGI(size(), stream_));
543 gl::ScopedActiveTexture texture0(GL_TEXTURE0); 535 gl::ScopedActiveTexture texture0(GL_TEXTURE0);
544 gl::ScopedTextureBinder texture0_binder( 536 gl::ScopedTextureBinder texture0_binder(
545 GL_TEXTURE_EXTERNAL_OES, picture_buffer_.service_texture_ids()[0]); 537 GL_TEXTURE_EXTERNAL_OES, picture_buffer_.service_texture_ids()[0]);
546 gl::ScopedActiveTexture texture1(GL_TEXTURE1); 538 gl::ScopedActiveTexture texture1(GL_TEXTURE1);
547 gl::ScopedTextureBinder texture1_binder( 539 gl::ScopedTextureBinder texture1_binder(
548 GL_TEXTURE_EXTERNAL_OES, picture_buffer_.service_texture_ids()[1]); 540 GL_TEXTURE_EXTERNAL_OES, picture_buffer_.service_texture_ids()[1]);
549 541
550 EGLAttrib consumer_attributes[] = { 542 EGLAttrib consumer_attributes[] = {
551 EGL_COLOR_BUFFER_TYPE, 543 EGL_COLOR_BUFFER_TYPE,
552 EGL_YUV_BUFFER_EXT, 544 EGL_YUV_BUFFER_EXT,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 }; 638 };
647 639
648 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); 640 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay();
649 641
650 EGLBoolean result = eglStreamPostD3DTextureNV12ANGLE( 642 EGLBoolean result = eglStreamPostD3DTextureNV12ANGLE(
651 egl_display, stream_, static_cast<void*>(angle_copy_texture_.get()), 643 egl_display, stream_, static_cast<void*>(angle_copy_texture_.get()),
652 frame_attributes); 644 frame_attributes);
653 RETURN_ON_FAILURE(result, "Could not post stream", false); 645 RETURN_ON_FAILURE(result, "Could not post stream", false);
654 result = eglStreamConsumerAcquireKHR(egl_display, stream_); 646 result = eglStreamConsumerAcquireKHR(egl_display, stream_);
655 RETURN_ON_FAILURE(result, "Could not post acquire stream", false); 647 RETURN_ON_FAILURE(result, "Could not post acquire stream", false);
648 gl::GLImageDXGI* gl_image_dxgi =
649 gl::GLImageDXGI::FromGLImage(gl_image_.get());
650 DCHECK(gl_image_dxgi);
651
652 gl_image_dxgi->SetTexture(angle_copy_texture_, 0);
656 653
657 return true; 654 return true;
658 } 655 }
659 656
660 bool EGLStreamCopyPictureBuffer::ReusePictureBuffer() { 657 bool EGLStreamCopyPictureBuffer::ReusePictureBuffer() {
661 DCHECK_NE(UNUSED, state_); 658 DCHECK_NE(UNUSED, state_);
662 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay(); 659 EGLDisplay egl_display = gl::GLSurfaceEGL::GetHardwareDisplay();
663 660
664 if (state_ == IN_CLIENT) { 661 if (state_ == IN_CLIENT) {
665 HRESULT hr = egl_keyed_mutex_->ReleaseSync(++keyed_mutex_value_); 662 HRESULT hr = egl_keyed_mutex_->ReleaseSync(++keyed_mutex_value_);
666 RETURN_ON_FAILURE(hr == S_OK, "Could not release sync mutex", false); 663 RETURN_ON_FAILURE(hr == S_OK, "Could not release sync mutex", false);
667 } 664 }
668 state_ = UNUSED; 665 state_ = UNUSED;
669 666
670 if (stream_) { 667 if (stream_) {
671 EGLBoolean result = eglStreamConsumerReleaseKHR(egl_display, stream_); 668 EGLBoolean result = eglStreamConsumerReleaseKHR(egl_display, stream_);
672 RETURN_ON_FAILURE(result, "Could not release stream", false); 669 RETURN_ON_FAILURE(result, "Could not release stream", false);
673 } 670 }
674 return true; 671 return true;
675 } 672 }
676 673
677 } // namespace media 674 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | ui/gl/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698