Update vaapi_wrapper.cc

This commit is contained in:
Alexander David Frick 2021-11-11 11:17:31 -06:00 committed by GitHub
parent 23e39b65e6
commit 3f92964906
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,7 +41,6 @@
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "ui/base/ui_base_features.h"
#include "media/base/media_switches.h"
#include "media/base/video_frame.h"
@ -690,7 +689,6 @@ bool VADisplayState::InitializeVaDriver_Locked() {
}
bool VADisplayState::InitializeOnce() {
// Set VA logging level, unless already set.
constexpr char libva_log_level_env[] = "LIBVA_MESSAGING_LEVEL";
std::unique_ptr<base::Environment> env(base::Environment::Create());
@ -2102,8 +2100,13 @@ bool VaapiWrapper::CreateContext(const gfx::Size& size) {
if (va_res != VA_STATUS_SUCCESS)
return false;
if (IsModeEncoding(mode_) && IsLowPowerIntelProcessor())
// TODO(b/200779101): Remove low resolution i965 condition. This was
// added to avoid a duplicated frame specific to quality 7 at ~400kbps.
if (IsModeEncoding(mode_) && IsLowPowerIntelProcessor() &&
!(GetImplementationType() == VAImplementation::kIntelI965 &&
picture_size.GetArea() <= gfx::Size(320, 240).GetArea())) {
MaybeSetLowQualityEncoding_Locked();
}
// If we have a protected session already, attach it to this new context.
return MaybeAttachProtectedSession_Locked();
@ -2245,16 +2248,27 @@ scoped_refptr<VASurface> VaapiWrapper::CreateVASurfaceForUserPtr(
base::BindOnce(&VaapiWrapper::DestroySurface, this));
}
std::unique_ptr<NativePixmapAndSizeInfo>
VaapiWrapper::ExportVASurfaceAsNativePixmapDmaBuf(
const ScopedVASurface& scoped_va_surface) {
scoped_refptr<VASurface> VaapiWrapper::CreateVASurfaceWithUsageHints(
unsigned int va_rt_format,
const gfx::Size& size,
const std::vector<SurfaceUsageHint>& usage_hints) {
CHECK(!enforce_sequence_affinity_ ||
sequence_checker_.CalledOnValidSequence());
if (!scoped_va_surface.IsValid()) {
LOG(ERROR) << "Cannot export an invalid surface";
std::vector<VASurfaceID> surfaces;
if (!CreateSurfaces(va_rt_format, size, usage_hints, 1, &surfaces))
return nullptr;
}
return new VASurface(surfaces[0], size, va_rt_format,
base::BindOnce(&VaapiWrapper::DestroySurface, this));
}
std::unique_ptr<NativePixmapAndSizeInfo>
VaapiWrapper::ExportVASurfaceAsNativePixmapDmaBufUnwrapped(
VASurfaceID va_surface_id,
const gfx::Size& va_surface_size) {
CHECK(!enforce_sequence_affinity_ ||
sequence_checker_.CalledOnValidSequence());
DCHECK_NE(va_surface_id, VA_INVALID_SURFACE);
DCHECK(!va_surface_size.IsEmpty());
if (GetImplementationType() == VAImplementation::kNVIDIAVDPAU) {
LOG(ERROR) << "Disabled due to potential breakage.";
return nullptr;
@ -2263,11 +2277,10 @@ VaapiWrapper::ExportVASurfaceAsNativePixmapDmaBuf(
VADRMPRIMESurfaceDescriptor descriptor;
{
base::AutoLock auto_lock(*va_lock_);
VAStatus va_res = vaSyncSurface(va_display_, scoped_va_surface.id());
VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
VA_SUCCESS_OR_RETURN(va_res, VaapiFunctions::kVASyncSurface, nullptr);
va_res = vaExportSurfaceHandle(
va_display_, scoped_va_surface.id(),
VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
va_display_, va_surface_id, VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
VA_EXPORT_SURFACE_READ_ONLY | VA_EXPORT_SURFACE_SEPARATE_LAYERS,
&descriptor);
VA_SUCCESS_OR_RETURN(va_res, VaapiFunctions::kVAExportSurfaceHandle,
@ -2343,18 +2356,44 @@ VaapiWrapper::ExportVASurfaceAsNativePixmapDmaBuf(
exported_pixmap->byte_size =
base::strict_cast<size_t>(descriptor.objects[0].size);
if (!gfx::Rect(exported_pixmap->va_surface_resolution)
.Contains(gfx::Rect(scoped_va_surface.size()))) {
LOG(ERROR) << "A " << scoped_va_surface.size().ToString()
<< " ScopedVASurface cannot be contained by a "
.Contains(gfx::Rect(va_surface_size))) {
LOG(ERROR) << "A " << va_surface_size.ToString()
<< " surface cannot be contained by a "
<< exported_pixmap->va_surface_resolution.ToString()
<< " buffer";
return nullptr;
}
exported_pixmap->pixmap = base::MakeRefCounted<gfx::NativePixmapDmaBuf>(
scoped_va_surface.size(), buffer_format, std::move(handle));
va_surface_size, buffer_format, std::move(handle));
return exported_pixmap;
}
std::unique_ptr<NativePixmapAndSizeInfo>
VaapiWrapper::ExportVASurfaceAsNativePixmapDmaBuf(const VASurface& va_surface) {
CHECK(!enforce_sequence_affinity_ ||
sequence_checker_.CalledOnValidSequence());
if (va_surface.id() == VA_INVALID_SURFACE || va_surface.size().IsEmpty() ||
va_surface.format() == kInvalidVaRtFormat) {
LOG(ERROR) << "Cannot export an invalid surface";
return nullptr;
}
return ExportVASurfaceAsNativePixmapDmaBufUnwrapped(va_surface.id(),
va_surface.size());
}
std::unique_ptr<NativePixmapAndSizeInfo>
VaapiWrapper::ExportVASurfaceAsNativePixmapDmaBuf(
const ScopedVASurface& scoped_va_surface) {
CHECK(!enforce_sequence_affinity_ ||
sequence_checker_.CalledOnValidSequence());
if (!scoped_va_surface.IsValid()) {
LOG(ERROR) << "Cannot export an invalid surface";
return nullptr;
}
return ExportVASurfaceAsNativePixmapDmaBufUnwrapped(scoped_va_surface.id(),
scoped_va_surface.size());
}
bool VaapiWrapper::SyncSurface(VASurfaceID va_surface_id) {
CHECK(!enforce_sequence_affinity_ ||
sequence_checker_.CalledOnValidSequence());
@ -2589,10 +2628,9 @@ bool VaapiWrapper::UploadVideoFrameToSurface(const VideoFrame& frame,
}
}
if (needs_va_put_image) {
const VAStatus va_res =
vaPutImage(va_display_, va_surface_id, image.image_id, 0, 0,
visible_size.width(), visible_size.height(), 0, 0,
visible_size.width(), visible_size.height());
va_res = vaPutImage(va_display_, va_surface_id, image.image_id, 0, 0,
visible_size.width(), visible_size.height(), 0, 0,
visible_size.width(), visible_size.height());
VA_SUCCESS_OR_RETURN(va_res, VaapiFunctions::kVAPutImage, false);
}
return ret == 0;