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

Side by Side Diff: content/common/gpu/media/vaapi_wrapper.cc

Issue 1422563002: [Ozone] Enables overlay render format setting path and by default use UYVY (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
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
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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
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());
519 DCHECK_EQ(va_surface_format_, 0u);
514 va_surface_ids_.resize(num_surfaces); 520 va_surface_ids_.resize(num_surfaces);
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;
525 } 531 }
526 532
527 // And create a context associated with them. 533 // And create a context associated with them.
528 va_res = vaCreateContext(va_display_, va_config_id_, 534 va_res = vaCreateContext(va_display_, va_config_id_,
529 size.width(), size.height(), VA_PROGRESSIVE, 535 size.width(), size.height(), VA_PROGRESSIVE,
530 &va_surface_ids_[0], va_surface_ids_.size(), 536 &va_surface_ids_[0], va_surface_ids_.size(),
531 &va_context_id_); 537 &va_context_id_);
532 538
533 VA_LOG_ON_ERROR(va_res, "vaCreateContext failed"); 539 VA_LOG_ON_ERROR(va_res, "vaCreateContext failed");
534 if (va_res != VA_STATUS_SUCCESS) { 540 if (va_res != VA_STATUS_SUCCESS) {
535 DestroySurfaces(); 541 DestroySurfaces();
536 return false; 542 return false;
537 } 543 }
538 544
539 *va_surfaces = va_surface_ids_; 545 *va_surfaces = va_surface_ids_;
546 va_surface_format_ = va_format;
540 return true; 547 return true;
541 } 548 }
542 549
543 void VaapiWrapper::DestroySurfaces() { 550 void VaapiWrapper::DestroySurfaces() {
544 base::AutoLock auto_lock(*va_lock_); 551 base::AutoLock auto_lock(*va_lock_);
545 DVLOG(2) << "Destroying " << va_surface_ids_.size() << " surfaces"; 552 DVLOG(2) << "Destroying " << va_surface_ids_.size() << " surfaces";
546 553
547 if (va_context_id_ != VA_INVALID_ID) { 554 if (va_context_id_ != VA_INVALID_ID) {
548 VAStatus va_res = vaDestroyContext(va_display_, va_context_id_); 555 VAStatus va_res = vaDestroyContext(va_display_, va_context_id_);
549 VA_LOG_ON_ERROR(va_res, "vaDestroyContext failed"); 556 VA_LOG_ON_ERROR(va_res, "vaDestroyContext failed");
550 } 557 }
551 558
552 if (!va_surface_ids_.empty()) { 559 if (!va_surface_ids_.empty()) {
553 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_ids_[0], 560 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_ids_[0],
554 va_surface_ids_.size()); 561 va_surface_ids_.size());
555 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces failed"); 562 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces failed");
556 } 563 }
557 564
558 va_surface_ids_.clear(); 565 va_surface_ids_.clear();
559 va_context_id_ = VA_INVALID_ID; 566 va_context_id_ = VA_INVALID_ID;
Pawel Osciak 2015/11/10 06:09:25 We are still missing va_surface_format_ = 0; here.
560 } 567 }
561 568
562 scoped_refptr<VASurface> VaapiWrapper::CreateUnownedSurface( 569 scoped_refptr<VASurface> VaapiWrapper::CreateUnownedSurface(
563 unsigned int va_format, 570 unsigned int va_format,
564 const gfx::Size& size, 571 const gfx::Size& size,
565 const std::vector<VASurfaceAttrib>& va_attribs) { 572 const std::vector<VASurfaceAttrib>& va_attribs) {
566 base::AutoLock auto_lock(*va_lock_); 573 base::AutoLock auto_lock(*va_lock_);
567 574
568 std::vector<VASurfaceAttrib> attribs(va_attribs); 575 std::vector<VASurfaceAttrib> attribs(va_attribs);
569 VASurfaceID va_surface_id; 576 VASurfaceID va_surface_id;
570 VAStatus va_res = 577 VAStatus va_res =
571 vaCreateSurfaces(va_display_, va_format, size.width(), size.height(), 578 vaCreateSurfaces(va_display_, va_format, size.width(), size.height(),
572 &va_surface_id, 1, &attribs[0], attribs.size()); 579 &va_surface_id, 1, &attribs[0], attribs.size());
573 580
574 scoped_refptr<VASurface> va_surface; 581 scoped_refptr<VASurface> va_surface;
575 VA_SUCCESS_OR_RETURN(va_res, "Failed to create unowned VASurface", 582 VA_SUCCESS_OR_RETURN(va_res, "Failed to create unowned VASurface",
576 va_surface); 583 va_surface);
577 584
578 // This is safe to use Unretained() here, because the VDA takes care 585 // This is safe to use Unretained() here, because the VDA takes care
579 // of the destruction order. All the surfaces will be destroyed 586 // of the destruction order. All the surfaces will be destroyed
580 // before VaapiWrapper. 587 // before VaapiWrapper.
581 va_surface = new VASurface( 588 va_surface = new VASurface(
582 va_surface_id, size, 589 va_surface_id, size, va_format,
583 base::Bind(&VaapiWrapper::DestroyUnownedSurface, base::Unretained(this))); 590 base::Bind(&VaapiWrapper::DestroyUnownedSurface, base::Unretained(this)));
584 591
585 return va_surface; 592 return va_surface;
586 } 593 }
587 594
588 void VaapiWrapper::DestroyUnownedSurface(VASurfaceID va_surface_id) { 595 void VaapiWrapper::DestroyUnownedSurface(VASurfaceID va_surface_id) {
589 base::AutoLock auto_lock(*va_lock_); 596 base::AutoLock auto_lock(*va_lock_);
590 597
591 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_id, 1); 598 VAStatus va_res = vaDestroySurfaces(va_display_, &va_surface_id, 1);
592 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces on surface failed"); 599 VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces on surface failed");
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 drm_fd_.reset(HANDLE_EINTR(dup(fd))); 1158 drm_fd_.reset(HANDLE_EINTR(dup(fd)));
1152 } 1159 }
1153 #endif // USE_OZONE 1160 #endif // USE_OZONE
1154 1161
1155 bool VaapiWrapper::VADisplayState::VAAPIVersionLessThan(int major, int minor) { 1162 bool VaapiWrapper::VADisplayState::VAAPIVersionLessThan(int major, int minor) {
1156 return (major_version_ < major) || 1163 return (major_version_ < major) ||
1157 (major_version_ == major && minor_version_ < minor); 1164 (major_version_ == major && minor_version_ < minor);
1158 } 1165 }
1159 1166
1160 } // namespace content 1167 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698