ozone-add-va-api-support-to-wayland.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. From: Maksim Sisov <msisov@igalia.com>
  2. Date: Wed, 20 Jan 2021 09:50:22 +0200
  3. Subject: [PATCH] ozone/wayland: add VA-API support.
  4. This patch ads VA-API support utilizing old VA-API path used for
  5. ChromeOS, which can be buggy on some devices (currently tested
  6. on Intel Gen8 and Gen9 with Gen8 having some minor bugs).
  7. It's known that a new VA-API is being developed atm and once it's ready,
  8. we will switch to a new path, which should be more stable.
  9. Upstream-Status: Inappropriate
  10. The patch is based on the old va-api path. ChromeOS
  11. team is working on the new path, which will be also employed
  12. by Wayland later.
  13. ---
  14. diff --git a/media/gpu/vaapi/vaapi_picture_factory.cc b/media/gpu/vaapi/vaapi_picture_factory.cc
  15. index 62e3a42..bde9c2d 100644
  16. --- a/media/gpu/vaapi/vaapi_picture_factory.cc
  17. +++ b/media/gpu/vaapi/vaapi_picture_factory.cc
  18. @@ -105,7 +105,7 @@ uint32_t VaapiPictureFactory::GetGLTextureTarget() {
  19. }
  20. gfx::BufferFormat VaapiPictureFactory::GetBufferFormat() {
  21. -#if BUILDFLAG(USE_VAAPI_X11)
  22. +#if BUILDFLAG(IS_LINUX)
  23. return gfx::BufferFormat::RGBX_8888;
  24. #else
  25. return gfx::BufferFormat::YUV_420_BIPLANAR;
  26. diff --git a/media/gpu/vaapi/vaapi_picture_native_pixmap.cc b/media/gpu/vaapi/vaapi_picture_native_pixmap.cc
  27. index 941f24c..a9c8035 100644
  28. --- a/media/gpu/vaapi/vaapi_picture_native_pixmap.cc
  29. +++ b/media/gpu/vaapi/vaapi_picture_native_pixmap.cc
  30. @@ -4,6 +4,7 @@
  31. #include "media/gpu/vaapi/vaapi_picture_native_pixmap.h"
  32. +#include "media/gpu/macros.h"
  33. #include "media/gpu/vaapi/va_surface.h"
  34. #include "media/gpu/vaapi/vaapi_wrapper.h"
  35. #include "ui/gfx/buffer_format_util.h"
  36. @@ -40,7 +41,21 @@ VaapiPictureNativePixmap::~VaapiPictureNativePixmap() = default;
  37. bool VaapiPictureNativePixmap::DownloadFromSurface(
  38. scoped_refptr<VASurface> va_surface) {
  39. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  40. - return vaapi_wrapper_->BlitSurface(*va_surface, *va_surface_);
  41. + if (!vaapi_wrapper_->SyncSurface(va_surface->id())) {
  42. + VLOGF(1) << "Cannot sync VPP input surface";
  43. + return false;
  44. + }
  45. + if (!vaapi_wrapper_->BlitSurface(*va_surface, *va_surface_)) {
  46. + VLOGF(1) << "Cannot convert decoded image into output buffer";
  47. + return false;
  48. + }
  49. +
  50. + // Sync target surface since the buffer is returning to client.
  51. + if (!vaapi_wrapper_->SyncSurface(va_surface_->id())) {
  52. + VLOGF(1) << "Cannot sync VPP output surface";
  53. + return false;
  54. + }
  55. + return true;
  56. }
  57. bool VaapiPictureNativePixmap::AllowOverlay() const {
  58. diff --git a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc
  59. index bf791d8..9e394eb 100644
  60. --- a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc
  61. +++ b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc
  62. @@ -560,12 +560,12 @@ void VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange(
  63. requested_visible_rect_ = visible_rect;
  64. if (buffer_allocation_mode_ == BufferAllocationMode::kSuperReduced) {
  65. // Add one to the reference frames for the one being currently egressed.
  66. - requested_num_reference_frames_ = num_reference_frames + 1;
  67. + requested_num_reference_frames_ = num_reference_frames + 4;
  68. requested_num_pics_ = num_pics - num_reference_frames;
  69. } else if (buffer_allocation_mode_ == BufferAllocationMode::kReduced) {
  70. // Add one to the reference frames for the one being currently egressed,
  71. // and an extra allocation for both |client_| and |decoder_|.
  72. - requested_num_reference_frames_ = num_reference_frames + 2;
  73. + requested_num_reference_frames_ = num_reference_frames + 5;
  74. requested_num_pics_ = num_pics - num_reference_frames + 1;
  75. } else {
  76. requested_num_reference_frames_ = 0;
  77. diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
  78. index 35378d1..68969d2 100644
  79. --- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
  80. +++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
  81. @@ -32,7 +32,9 @@ GbmPixmapWayland::GbmPixmapWayland(WaylandBufferManagerGpu* buffer_manager)
  82. buffer_id_(buffer_manager->AllocateBufferID()) {}
  83. GbmPixmapWayland::~GbmPixmapWayland() {
  84. - if (created_wl_buffer_)
  85. + // gfx::BufferUsage::SCANOUT_VDA_WRITE doesn't result in creation of
  86. + // wl_buffers.
  87. + if (created_wl_buffer_ && usage_ != gfx::BufferUsage::SCANOUT_VDA_WRITE)
  88. buffer_manager_->DestroyBuffer(buffer_id_);
  89. }
  90. diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h
  91. index 9e8b2fa..9918508 100644
  92. --- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h
  93. +++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h
  94. @@ -92,6 +92,9 @@ class GbmPixmapWayland : public gfx::NativePixmap {
  95. // Says a wl_buffer has been created and must removed.
  96. bool created_wl_buffer_ = false;
  97. +
  98. + // Tells the usage of this pixmap.
  99. + gfx::BufferUsage usage_ = gfx::BufferUsage::SCANOUT;
  100. };
  101. } // namespace ui
  102. diff --git a/ui/ozone/platform/wayland/ozone_platform_wayland.cc b/ui/ozone/platform/wayland/ozone_platform_wayland.cc
  103. index c13bd3a..04fa160 100644
  104. --- a/ui/ozone/platform/wayland/ozone_platform_wayland.cc
  105. +++ b/ui/ozone/platform/wayland/ozone_platform_wayland.cc
  106. @@ -297,6 +297,9 @@ class OzonePlatformWayland : public OzonePlatform,
  107. properties->supports_global_screen_coordinates =
  108. features::IsWaylandScreenCoordinatesEnabled();
  109. + // Let the media know this platform supports va-api.
  110. + properties->supports_vaapi = true;
  111. +
  112. initialised = true;
  113. }