From: Maksim Sisov Date: Wed, 20 Jan 2021 09:50:22 +0200 Subject: [PATCH] ozone/wayland: add VA-API support. This patch ads VA-API support utilizing old VA-API path used for ChromeOS, which can be buggy on some devices (currently tested on Intel Gen8 and Gen9 with Gen8 having some minor bugs). It's known that a new VA-API is being developed atm and once it's ready, we will switch to a new path, which should be more stable. Upstream-Status: Inappropriate The patch is based on the old va-api path. ChromeOS team is working on the new path, which will be also employed by Wayland later. --- diff --git a/media/gpu/vaapi/vaapi_picture_factory.cc b/media/gpu/vaapi/vaapi_picture_factory.cc index 62e3a42..bde9c2d 100644 --- a/media/gpu/vaapi/vaapi_picture_factory.cc +++ b/media/gpu/vaapi/vaapi_picture_factory.cc @@ -105,7 +105,7 @@ uint32_t VaapiPictureFactory::GetGLTextureTarget() { } gfx::BufferFormat VaapiPictureFactory::GetBufferFormat() { -#if BUILDFLAG(USE_VAAPI_X11) +#if BUILDFLAG(IS_LINUX) return gfx::BufferFormat::RGBX_8888; #else return gfx::BufferFormat::YUV_420_BIPLANAR; diff --git a/media/gpu/vaapi/vaapi_picture_native_pixmap.cc b/media/gpu/vaapi/vaapi_picture_native_pixmap.cc index 941f24c..a9c8035 100644 --- a/media/gpu/vaapi/vaapi_picture_native_pixmap.cc +++ b/media/gpu/vaapi/vaapi_picture_native_pixmap.cc @@ -4,6 +4,7 @@ #include "media/gpu/vaapi/vaapi_picture_native_pixmap.h" +#include "media/gpu/macros.h" #include "media/gpu/vaapi/va_surface.h" #include "media/gpu/vaapi/vaapi_wrapper.h" #include "ui/gfx/buffer_format_util.h" @@ -40,7 +41,21 @@ VaapiPictureNativePixmap::~VaapiPictureNativePixmap() = default; bool VaapiPictureNativePixmap::DownloadFromSurface( scoped_refptr va_surface) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - return vaapi_wrapper_->BlitSurface(*va_surface, *va_surface_); + if (!vaapi_wrapper_->SyncSurface(va_surface->id())) { + VLOGF(1) << "Cannot sync VPP input surface"; + return false; + } + if (!vaapi_wrapper_->BlitSurface(*va_surface, *va_surface_)) { + VLOGF(1) << "Cannot convert decoded image into output buffer"; + return false; + } + + // Sync target surface since the buffer is returning to client. + if (!vaapi_wrapper_->SyncSurface(va_surface_->id())) { + VLOGF(1) << "Cannot sync VPP output surface"; + return false; + } + return true; } bool VaapiPictureNativePixmap::AllowOverlay() const { diff --git a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc index bf791d8..9e394eb 100644 --- a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc +++ b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc @@ -560,12 +560,12 @@ void VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange( requested_visible_rect_ = visible_rect; if (buffer_allocation_mode_ == BufferAllocationMode::kSuperReduced) { // Add one to the reference frames for the one being currently egressed. - requested_num_reference_frames_ = num_reference_frames + 1; + requested_num_reference_frames_ = num_reference_frames + 4; requested_num_pics_ = num_pics - num_reference_frames; } else if (buffer_allocation_mode_ == BufferAllocationMode::kReduced) { // Add one to the reference frames for the one being currently egressed, // and an extra allocation for both |client_| and |decoder_|. - requested_num_reference_frames_ = num_reference_frames + 2; + requested_num_reference_frames_ = num_reference_frames + 5; requested_num_pics_ = num_pics - num_reference_frames + 1; } else { requested_num_reference_frames_ = 0; diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc index 35378d1..68969d2 100644 --- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc +++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc @@ -32,7 +32,9 @@ GbmPixmapWayland::GbmPixmapWayland(WaylandBufferManagerGpu* buffer_manager) buffer_id_(buffer_manager->AllocateBufferID()) {} GbmPixmapWayland::~GbmPixmapWayland() { - if (created_wl_buffer_) + // gfx::BufferUsage::SCANOUT_VDA_WRITE doesn't result in creation of + // wl_buffers. + if (created_wl_buffer_ && usage_ != gfx::BufferUsage::SCANOUT_VDA_WRITE) buffer_manager_->DestroyBuffer(buffer_id_); } diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h index 9e8b2fa..9918508 100644 --- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h +++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h @@ -92,6 +92,9 @@ class GbmPixmapWayland : public gfx::NativePixmap { // Says a wl_buffer has been created and must removed. bool created_wl_buffer_ = false; + + // Tells the usage of this pixmap. + gfx::BufferUsage usage_ = gfx::BufferUsage::SCANOUT; }; } // namespace ui diff --git a/ui/ozone/platform/wayland/ozone_platform_wayland.cc b/ui/ozone/platform/wayland/ozone_platform_wayland.cc index c13bd3a..04fa160 100644 --- a/ui/ozone/platform/wayland/ozone_platform_wayland.cc +++ b/ui/ozone/platform/wayland/ozone_platform_wayland.cc @@ -297,6 +297,9 @@ class OzonePlatformWayland : public OzonePlatform, properties->supports_global_screen_coordinates = features::IsWaylandScreenCoordinatesEnabled(); + // Let the media know this platform supports va-api. + properties->supports_vaapi = true; + initialised = true; }