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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. From ddb186d8904d6ec80d1084a1cc495b824381a565 Mon Sep 17 00:00:00 2001
  2. From: Maksim Sisov <msisov@igalia.com>
  3. Date: Wed, 20 Jan 2021 09:50:22 +0200
  4. Subject: [PATCH] ozone/wayland: add VA-API support.
  5. This patch ads VA-API support utilizing old VA-API path used for
  6. ChromeOS, which can be buggy on some devices (currently tested
  7. on Intel Gen8 and Gen9 with Gen8 having some minor bugs).
  8. It's known that a new VA-API is being developed atm and once it's ready,
  9. we will switch to a new path, which should be more stable.
  10. Upstream-Status: Inappropriate
  11. The patch is based on the old va-api path. ChromeOS
  12. team is working on the new path, which will be also employed
  13. by Wayland later.
  14. Signed-off-by: Maksim Sisov <msisov@igalia.com>
  15. ---
  16. media/gpu/vaapi/vaapi_picture_factory.cc | 2 +-
  17. media/gpu/vaapi/vaapi_picture_native_pixmap.cc | 17 ++++++++++++++++-
  18. .../gpu/vaapi/vaapi_video_decode_accelerator.cc | 4 ++--
  19. .../platform/wayland/gpu/gbm_pixmap_wayland.cc | 14 ++++++++++++--
  20. .../platform/wayland/gpu/gbm_pixmap_wayland.h | 3 +++
  21. .../platform/wayland/ozone_platform_wayland.cc | 3 +++
  22. 6 files changed, 37 insertions(+), 6 deletions(-)
  23. diff --git a/media/gpu/vaapi/vaapi_picture_factory.cc b/media/gpu/vaapi/vaapi_picture_factory.cc
  24. index 62e3a429239eb..df4905a10f68b 100644
  25. --- a/media/gpu/vaapi/vaapi_picture_factory.cc
  26. +++ b/media/gpu/vaapi/vaapi_picture_factory.cc
  27. @@ -105,7 +105,7 @@ uint32_t VaapiPictureFactory::GetGLTextureTarget() {
  28. }
  29. gfx::BufferFormat VaapiPictureFactory::GetBufferFormat() {
  30. -#if BUILDFLAG(USE_VAAPI_X11)
  31. +#if defined(OS_LINUX)
  32. return gfx::BufferFormat::RGBX_8888;
  33. #else
  34. return gfx::BufferFormat::YUV_420_BIPLANAR;
  35. diff --git a/media/gpu/vaapi/vaapi_picture_native_pixmap.cc b/media/gpu/vaapi/vaapi_picture_native_pixmap.cc
  36. index 941f24cc59590..a9c80356e7109 100644
  37. --- a/media/gpu/vaapi/vaapi_picture_native_pixmap.cc
  38. +++ b/media/gpu/vaapi/vaapi_picture_native_pixmap.cc
  39. @@ -4,6 +4,7 @@
  40. #include "media/gpu/vaapi/vaapi_picture_native_pixmap.h"
  41. +#include "media/gpu/macros.h"
  42. #include "media/gpu/vaapi/va_surface.h"
  43. #include "media/gpu/vaapi/vaapi_wrapper.h"
  44. #include "ui/gfx/buffer_format_util.h"
  45. @@ -40,7 +41,21 @@ VaapiPictureNativePixmap::~VaapiPictureNativePixmap() = default;
  46. bool VaapiPictureNativePixmap::DownloadFromSurface(
  47. scoped_refptr<VASurface> va_surface) {
  48. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  49. - return vaapi_wrapper_->BlitSurface(*va_surface, *va_surface_);
  50. + if (!vaapi_wrapper_->SyncSurface(va_surface->id())) {
  51. + VLOGF(1) << "Cannot sync VPP input surface";
  52. + return false;
  53. + }
  54. + if (!vaapi_wrapper_->BlitSurface(*va_surface, *va_surface_)) {
  55. + VLOGF(1) << "Cannot convert decoded image into output buffer";
  56. + return false;
  57. + }
  58. +
  59. + // Sync target surface since the buffer is returning to client.
  60. + if (!vaapi_wrapper_->SyncSurface(va_surface_->id())) {
  61. + VLOGF(1) << "Cannot sync VPP output surface";
  62. + return false;
  63. + }
  64. + return true;
  65. }
  66. bool VaapiPictureNativePixmap::AllowOverlay() const {
  67. diff --git a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc
  68. index baaf2ae468d36..4d6933d869933 100644
  69. --- a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc
  70. +++ b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc
  71. @@ -562,12 +562,12 @@ void VaapiVideoDecodeAccelerator::InitiateSurfaceSetChange(
  72. requested_visible_rect_ = visible_rect;
  73. if (buffer_allocation_mode_ == BufferAllocationMode::kSuperReduced) {
  74. // Add one to the reference frames for the one being currently egressed.
  75. - requested_num_reference_frames_ = num_reference_frames + 1;
  76. + requested_num_reference_frames_ = num_reference_frames + 4;
  77. requested_num_pics_ = num_pics - num_reference_frames;
  78. } else if (buffer_allocation_mode_ == BufferAllocationMode::kReduced) {
  79. // Add one to the reference frames for the one being currently egressed,
  80. // and an extra allocation for both |client_| and |decoder_|.
  81. - requested_num_reference_frames_ = num_reference_frames + 2;
  82. + requested_num_reference_frames_ = num_reference_frames + 5;
  83. requested_num_pics_ = num_pics - num_reference_frames + 1;
  84. } else {
  85. requested_num_reference_frames_ = 0;
  86. diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
  87. index 2ec4e4e01729e..e73af1fe781c6 100644
  88. --- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
  89. +++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
  90. @@ -33,8 +33,12 @@ GbmPixmapWayland::GbmPixmapWayland(WaylandBufferManagerGpu* buffer_manager)
  91. buffer_id_(buffer_manager->AllocateBufferID()) {}
  92. GbmPixmapWayland::~GbmPixmapWayland() {
  93. - if (gbm_bo_ && widget_ != gfx::kNullAcceleratedWidget)
  94. + // gfx::BufferUsage::SCANOUT_VDA_WRITE doesn't result in creation of
  95. + // wl_buffers.
  96. + if (gbm_bo_ && usage_ != gfx::BufferUsage::SCANOUT_VDA_WRITE &&
  97. + widget_ != gfx::kNullAcceleratedWidget) {
  98. buffer_manager_->DestroyBuffer(buffer_id_);
  99. + }
  100. }
  101. bool GbmPixmapWayland::InitializeBuffer(
  102. @@ -83,8 +87,14 @@ bool GbmPixmapWayland::InitializeBuffer(
  103. << " usage=" << gfx::BufferUsageToString(usage);
  104. visible_area_size_ = visible_area_size ? visible_area_size.value() : size;
  105. - if (widget_ != gfx::kNullAcceleratedWidget)
  106. + usage_ = usage;
  107. + // Do not create wl_buffers for SCANOUT_VDA_WRITE usages. These buffers are
  108. + // only used by video decoders and are not going to be requested to be
  109. + // attached to Wayland surfaces.
  110. + if (usage_ != gfx::BufferUsage::SCANOUT_VDA_WRITE &&
  111. + widget_ != gfx::kNullAcceleratedWidget) {
  112. CreateDmabufBasedBuffer();
  113. + }
  114. return true;
  115. }
  116. diff --git a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h
  117. index e9b25a7452882..3eb91765eba30 100644
  118. --- a/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h
  119. +++ b/ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.h
  120. @@ -87,6 +87,9 @@ class GbmPixmapWayland : public gfx::NativePixmap {
  121. // Size of the visible area of the buffer.
  122. gfx::Size visible_area_size_;
  123. +
  124. + // Tells the usage of this pixmap.
  125. + gfx::BufferUsage usage_ = gfx::BufferUsage::SCANOUT;
  126. };
  127. } // namespace ui
  128. diff --git a/ui/ozone/platform/wayland/ozone_platform_wayland.cc b/ui/ozone/platform/wayland/ozone_platform_wayland.cc
  129. index 661859754cd80..665e6de2616bb 100644
  130. --- a/ui/ozone/platform/wayland/ozone_platform_wayland.cc
  131. +++ b/ui/ozone/platform/wayland/ozone_platform_wayland.cc
  132. @@ -289,6 +289,9 @@ class OzonePlatformWayland : public OzonePlatform,
  133. // arbitrary position.
  134. properties->supports_global_screen_coordinates = false;
  135. + // Let the media know this platform supports va-api.
  136. + properties->supports_vaapi = true;
  137. +
  138. initialised = true;
  139. }