Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/gpu/media/vaapi_wrapper.h" | 5 #include "content/common/gpu/media/vaapi_wrapper.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 required_attribs.insert( | 107 required_attribs.insert( |
| 108 required_attribs.end(), | 108 required_attribs.end(), |
| 109 kEncodeVAConfigAttribs, | 109 kEncodeVAConfigAttribs, |
| 110 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs)); | 110 kEncodeVAConfigAttribs + arraysize(kEncodeVAConfigAttribs)); |
| 111 } | 111 } |
| 112 return required_attribs; | 112 return required_attribs; |
| 113 } | 113 } |
| 114 | 114 |
| 115 VASurface::VASurface(VASurfaceID va_surface_id, | 115 VASurface::VASurface(VASurfaceID va_surface_id, |
| 116 const gfx::Size& size, | 116 const gfx::Size& size, |
| 117 const unsigned int format, | |
| 117 const ReleaseCB& release_cb) | 118 const ReleaseCB& release_cb) |
| 118 : va_surface_id_(va_surface_id), size_(size), release_cb_(release_cb) { | 119 : va_surface_id_(va_surface_id), |
| 120 size_(size), | |
| 121 format_(format), | |
| 122 release_cb_(release_cb) { | |
| 119 DCHECK(!release_cb_.is_null()); | 123 DCHECK(!release_cb_.is_null()); |
| 120 } | 124 } |
| 121 | 125 |
| 122 VASurface::~VASurface() { | 126 VASurface::~VASurface() { |
| 123 release_cb_.Run(va_surface_id_); | 127 release_cb_.Run(va_surface_id_); |
| 124 } | 128 } |
| 125 | 129 |
| 126 VaapiWrapper::VaapiWrapper() | 130 VaapiWrapper::VaapiWrapper() |
| 127 : va_display_(NULL), | 131 : va_surface_format_(0), |
| 132 va_display_(NULL), | |
| 128 va_config_id_(VA_INVALID_ID), | 133 va_config_id_(VA_INVALID_ID), |
| 129 va_context_id_(VA_INVALID_ID), | 134 va_context_id_(VA_INVALID_ID), |
| 130 va_vpp_config_id_(VA_INVALID_ID), | 135 va_vpp_config_id_(VA_INVALID_ID), |
| 131 va_vpp_context_id_(VA_INVALID_ID), | 136 va_vpp_context_id_(VA_INVALID_ID), |
| 132 va_vpp_buffer_id_(VA_INVALID_ID) { | 137 va_vpp_buffer_id_(VA_INVALID_ID) { |
| 133 va_lock_ = va_display_state_.Get().va_lock(); | 138 va_lock_ = va_display_state_.Get().va_lock(); |
| 134 } | 139 } |
| 135 | 140 |
| 136 VaapiWrapper::~VaapiWrapper() { | 141 VaapiWrapper::~VaapiWrapper() { |
| 137 DestroyPendingBuffers(); | 142 DestroyPendingBuffers(); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 } | 508 } |
| 504 | 509 |
| 505 bool VaapiWrapper::CreateSurfaces(unsigned int va_format, | 510 bool VaapiWrapper::CreateSurfaces(unsigned int va_format, |
| 506 const gfx::Size& size, | 511 const gfx::Size& size, |
| 507 size_t num_surfaces, | 512 size_t num_surfaces, |
| 508 std::vector<VASurfaceID>* va_surfaces) { | 513 std::vector<VASurfaceID>* va_surfaces) { |
| 509 base::AutoLock auto_lock(*va_lock_); | 514 base::AutoLock auto_lock(*va_lock_); |
| 510 DVLOG(2) << "Creating " << num_surfaces << " surfaces"; | 515 DVLOG(2) << "Creating " << num_surfaces << " surfaces"; |
| 511 | 516 |
| 512 DCHECK(va_surfaces->empty()); | 517 DCHECK(va_surfaces->empty()); |
| 513 DCHECK(va_surface_ids_.empty()); | 518 DCHECK(va_surface_ids_.empty()); |
|
Pawel Osciak
2015/11/09 03:52:06
DCHECK_EQ(va_surface_format_, 0);
william.xie1
2015/11/09 04:58:01
Done.
| |
| 514 va_surface_ids_.resize(num_surfaces); | 519 va_surface_ids_.resize(num_surfaces); |
| 520 va_surface_format_ = va_format; | |
|
Pawel Osciak
2015/11/09 03:52:06
Please set this at l.546.
william.xie1
2015/11/09 04:58:01
Done.
| |
| 515 | 521 |
| 516 // Allocate surfaces in driver. | 522 // Allocate surfaces in driver. |
| 517 VAStatus va_res = | 523 VAStatus va_res = |
| 518 vaCreateSurfaces(va_display_, va_format, size.width(), size.height(), | 524 vaCreateSurfaces(va_display_, va_format, size.width(), size.height(), |
| 519 &va_surface_ids_[0], va_surface_ids_.size(), NULL, 0); | 525 &va_surface_ids_[0], va_surface_ids_.size(), NULL, 0); |
| 520 | 526 |
| 521 VA_LOG_ON_ERROR(va_res, "vaCreateSurfaces failed"); | 527 VA_LOG_ON_ERROR(va_res, "vaCreateSurfaces failed"); |
| 522 if (va_res != VA_STATUS_SUCCESS) { | 528 if (va_res != VA_STATUS_SUCCESS) { |
| 523 va_surface_ids_.clear(); | 529 va_surface_ids_.clear(); |
| 524 return false; | 530 return false; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 549 VA_LOG_ON_ERROR(va_res, "vaDestroyContext failed"); | 555 VA_LOG_ON_ERROR(va_res, "vaDestroyContext failed"); |
| 550 } | 556 } |
| 551 | 557 |
| 552 if (!va_surface_ids_.empty()) { | 558 if (!va_surface_ids_.empty()) { |
| 553 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_ids_[0], | 559 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_ids_[0], |
| 554 va_surface_ids_.size()); | 560 va_surface_ids_.size()); |
| 555 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces failed"); | 561 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces failed"); |
| 556 } | 562 } |
| 557 | 563 |
| 558 va_surface_ids_.clear(); | 564 va_surface_ids_.clear(); |
| 559 va_context_id_ = VA_INVALID_ID; | 565 va_context_id_ = VA_INVALID_ID; |
|
Pawel Osciak
2015/11/09 03:52:06
va_surface_format_ = 0;
| |
| 560 } | 566 } |
| 561 | 567 |
| 562 scoped_refptr<VASurface> VaapiWrapper::CreateUnownedSurface( | 568 scoped_refptr<VASurface> VaapiWrapper::CreateUnownedSurface( |
| 563 unsigned int va_format, | 569 unsigned int va_format, |
| 564 const gfx::Size& size, | 570 const gfx::Size& size, |
| 565 const std::vector<VASurfaceAttrib>& va_attribs) { | 571 const std::vector<VASurfaceAttrib>& va_attribs) { |
| 566 base::AutoLock auto_lock(*va_lock_); | 572 base::AutoLock auto_lock(*va_lock_); |
| 567 | 573 |
| 568 std::vector<VASurfaceAttrib> attribs(va_attribs); | 574 std::vector<VASurfaceAttrib> attribs(va_attribs); |
| 569 VASurfaceID va_surface_id; | 575 VASurfaceID va_surface_id; |
| 570 VAStatus va_res = | 576 VAStatus va_res = |
| 571 vaCreateSurfaces(va_display_, va_format, size.width(), size.height(), | 577 vaCreateSurfaces(va_display_, va_format, size.width(), size.height(), |
| 572 &va_surface_id, 1, &attribs[0], attribs.size()); | 578 &va_surface_id, 1, &attribs[0], attribs.size()); |
| 573 | 579 |
| 574 scoped_refptr<VASurface> va_surface; | 580 scoped_refptr<VASurface> va_surface; |
| 575 VA_SUCCESS_OR_RETURN(va_res, "Failed to create unowned VASurface", | 581 VA_SUCCESS_OR_RETURN(va_res, "Failed to create unowned VASurface", |
| 576 va_surface); | 582 va_surface); |
| 577 | 583 |
| 578 // This is safe to use Unretained() here, because the VDA takes care | 584 // This is safe to use Unretained() here, because the VDA takes care |
| 579 // of the destruction order. All the surfaces will be destroyed | 585 // of the destruction order. All the surfaces will be destroyed |
| 580 // before VaapiWrapper. | 586 // before VaapiWrapper. |
| 581 va_surface = new VASurface( | 587 va_surface = new VASurface( |
| 582 va_surface_id, size, | 588 va_surface_id, size, va_format, |
| 583 base::Bind(&VaapiWrapper::DestroyUnownedSurface, base::Unretained(this))); | 589 base::Bind(&VaapiWrapper::DestroyUnownedSurface, base::Unretained(this))); |
| 584 | 590 |
| 585 return va_surface; | 591 return va_surface; |
| 586 } | 592 } |
| 587 | 593 |
| 588 void VaapiWrapper::DestroyUnownedSurface(VASurfaceID va_surface_id) { | 594 void VaapiWrapper::DestroyUnownedSurface(VASurfaceID va_surface_id) { |
| 589 base::AutoLock auto_lock(*va_lock_); | 595 base::AutoLock auto_lock(*va_lock_); |
| 590 | 596 |
| 591 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_id, 1); | 597 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_id, 1); |
| 592 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces on surface failed"); | 598 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces on surface failed"); |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1150 drm_fd_.reset(HANDLE_EINTR(dup(fd))); | 1156 drm_fd_.reset(HANDLE_EINTR(dup(fd))); |
| 1151 } | 1157 } |
| 1152 #endif // USE_OZONE | 1158 #endif // USE_OZONE |
| 1153 | 1159 |
| 1154 bool VaapiWrapper::VADisplayState::VAAPIVersionLessThan(int major, int minor) { | 1160 bool VaapiWrapper::VADisplayState::VAAPIVersionLessThan(int major, int minor) { |
| 1155 return (major_version_ < major) || | 1161 return (major_version_ < major) || |
| 1156 (major_version_ == major && minor_version_ < minor); | 1162 (major_version_ == major && minor_version_ < minor); |
| 1157 } | 1163 } |
| 1158 | 1164 |
| 1159 } // namespace content | 1165 } // namespace content |
| OLD | NEW |