ozone-x11-fix-VA-API.patch 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. From a4de986102a45e29c3ef596f22704bdca244c26c Mon Sep 17 00:00:00 2001
  2. From: Maksim Sisov <msisov@igalia.com>
  3. Date: Fri, 17 Sep 2021 08:45:55 +0000
  4. Subject: [PATCH] ozone/x11: fix VA-API.
  5. This patch fixes VA-API usage with Ozone/X11 backend (which
  6. is our default backend now as X11 has been deprecated -
  7. crrev.com/c/3114071)).
  8. non-Ozone X11 is disabled now and Ozone is always used
  9. on Linux. However, VA-API implementation is not Ozone friendly
  10. yet and requires major refactoring. But given that VA-API
  11. implementation on Linux worked only with X11, it's fine for
  12. now to change USE_X11 and !IsUsingOzonePlatform to
  13. BUILDFLAG(OZONE_PLATFORM_X11) and fail VA-API initialization
  14. in VADisplayState::Initialize for Ozone/Linux other than
  15. non-X11 backends.
  16. Bug: 1121948
  17. Change-Id: If85d289235e6d358103d9fa2bbe0f741fb599a26
  18. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3141878
  19. Commit-Queue: Maksim Sisov <msisov@igalia.com>
  20. Reviewed-by: Andres Calderon Jaramillo <andrescj@chromium.org>
  21. Reviewed-by: Robert Kroeger <rjkroege@chromium.org>
  22. Reviewed-by: Xiaohan Wang <xhwang@chromium.org>
  23. Reviewed-by: Alexander Dunaev <adunaev@igalia.com>
  24. Cr-Commit-Position: refs/heads/main@{#922466}
  25. ---
  26. media/BUILD.gn | 3 -
  27. media/gpu/BUILD.gn | 5 +-
  28. media/gpu/args.gni | 13 +++-
  29. media/gpu/vaapi/BUILD.gn | 8 +-
  30. media/gpu/vaapi/va_stub_header.fragment | 6 +-
  31. media/gpu/vaapi/vaapi_picture_factory.cc | 72 ++++++++----------
  32. .../vaapi_picture_native_pixmap_angle.cc | 2 -
  33. media/gpu/vaapi/vaapi_picture_tfp.cc | 2 -
  34. .../vaapi/vaapi_video_decode_accelerator.cc | 9 +--
  35. ...vaapi_video_decode_accelerator_unittest.cc | 11 +--
  36. media/gpu/vaapi/vaapi_wrapper.cc | 76 +++++++++----------
  37. media/gpu/vaapi/vaapi_wrapper.h | 8 +-
  38. ui/ozone/platform/x11/ozone_platform_x11.cc | 3 +
  39. ui/ozone/public/ozone_platform.h | 10 +++
  40. 14 files changed, 108 insertions(+), 120 deletions(-)
  41. diff --git a/media/BUILD.gn b/media/BUILD.gn
  42. index dbee1d4338..d5c158c08f 100644
  43. --- a/media/BUILD.gn
  44. +++ b/media/BUILD.gn
  45. @@ -130,9 +130,6 @@ component("media") {
  46. public_deps += [ "//media/base/mac" ]
  47. }
  48. - if (use_x11) {
  49. - deps += [ "//ui/base/x" ]
  50. - }
  51. if (use_ozone) {
  52. deps += [ "//ui/ozone" ]
  53. }
  54. diff --git a/media/gpu/BUILD.gn b/media/gpu/BUILD.gn
  55. index c7499485ac..3fedc78948 100644
  56. --- a/media/gpu/BUILD.gn
  57. +++ b/media/gpu/BUILD.gn
  58. @@ -20,6 +20,7 @@ buildflag_header("buildflags") {
  59. "USE_VAAPI_IMAGE_CODECS=$use_vaapi_image_codecs",
  60. "USE_V4L2_CODEC=$use_v4l2_codec",
  61. "USE_LIBV4L2=$use_v4lplugin",
  62. + "USE_VAAPI_X11=$use_vaapi_x11",
  63. ]
  64. }
  65. @@ -215,9 +216,7 @@ component("gpu") {
  66. "windows/supported_profile_helpers.cc",
  67. "windows/supported_profile_helpers.h",
  68. ]
  69. - configs += [
  70. - "//third_party/khronos:khronos_headers",
  71. - ]
  72. + configs += [ "//third_party/khronos:khronos_headers" ]
  73. public_deps += [ "//media/base/win:media_foundation_util" ]
  74. deps += [
  75. "//gpu/ipc/common:common",
  76. diff --git a/media/gpu/args.gni b/media/gpu/args.gni
  77. index 4004937949..2f53843918 100644
  78. --- a/media/gpu/args.gni
  79. +++ b/media/gpu/args.gni
  80. @@ -3,7 +3,15 @@
  81. # found in the LICENSE file.
  82. import("//build/config/chromeos/ui_mode.gni")
  83. -import("//build/config/ui.gni")
  84. +import("//build/config/ozone.gni")
  85. +
  86. +declare_args() {
  87. + # Indicates if X11 VA-API-based hardware acceleration is to be used.
  88. + # See also the comment near the |use_vaapi| arg.
  89. + use_vaapi_x11 =
  90. + is_linux && ozone_platform_x11 && !is_chromecast && !is_chromeos_lacros &&
  91. + (target_cpu == "x86" || target_cpu == "x64")
  92. +}
  93. declare_args() {
  94. # Indicates if V4L plugin is used.
  95. @@ -21,8 +29,7 @@ declare_args() {
  96. # is typically the case on x86-based ChromeOS devices.
  97. # VA-API should also be compiled by default on x11-using linux devices
  98. # using x86/x64.
  99. - use_vaapi =
  100. - is_linux && use_x11 && (target_cpu == "x86" || target_cpu == "x64")
  101. + use_vaapi = use_vaapi_x11
  102. # Indicates if ChromeOS protected media support exists. This is used
  103. # to enable the CDM daemon in Chrome OS as well as support for
  104. diff --git a/media/gpu/vaapi/BUILD.gn b/media/gpu/vaapi/BUILD.gn
  105. index b11d2c60fa..0c2520dd6b 100644
  106. --- a/media/gpu/vaapi/BUILD.gn
  107. +++ b/media/gpu/vaapi/BUILD.gn
  108. @@ -17,7 +17,7 @@ assert(use_vaapi)
  109. generate_stubs("libva_stubs") {
  110. extra_header = "va_stub_header.fragment"
  111. sigs = [ "va.sigs" ]
  112. - if (use_x11) {
  113. + if (use_vaapi_x11) {
  114. sigs += [ "va_x11.sigs" ]
  115. }
  116. if (is_chromeos_ash) {
  117. @@ -131,14 +131,14 @@ source_set("vaapi") {
  118. ]
  119. }
  120. - if (use_x11 || use_ozone || use_egl) {
  121. + if (use_ozone || use_egl) {
  122. sources += [
  123. "vaapi_picture_native_pixmap.cc",
  124. "vaapi_picture_native_pixmap.h",
  125. ]
  126. }
  127. - if (use_x11) {
  128. + if (use_vaapi_x11) {
  129. deps += [ "//ui/gfx/x" ]
  130. sources += [
  131. "vaapi_picture_native_pixmap_angle.cc",
  132. @@ -197,7 +197,7 @@ source_set("common") {
  133. deps += [ "//ui/ozone" ]
  134. }
  135. - if (use_x11) {
  136. + if (use_vaapi_x11) {
  137. deps += [ "//ui/gfx/x" ]
  138. }
  139. diff --git a/media/gpu/vaapi/va_stub_header.fragment b/media/gpu/vaapi/va_stub_header.fragment
  140. index bed198484d..e8c46c5e81 100644
  141. --- a/media/gpu/vaapi/va_stub_header.fragment
  142. +++ b/media/gpu/vaapi/va_stub_header.fragment
  143. @@ -1,12 +1,14 @@
  144. // The extra include header needed in the generated stub file for defining
  145. // various libva types.
  146. +#include "media/gpu/buildflags.h"
  147. +
  148. extern "C" {
  149. #include <va/va_drm.h>
  150. #include <va/va.h>
  151. -#if defined(USE_X11)
  152. +#if BUILDFLAG(USE_VAAPI_X11)
  153. #include <va/va_x11.h>
  154. -#endif
  155. +#endif // BUILDFLAG(USE_VAAPI_X11)
  156. }
  157. diff --git a/media/gpu/vaapi/vaapi_picture_factory.cc b/media/gpu/vaapi/vaapi_picture_factory.cc
  158. index 719035b87c..9c7d7387d2 100644
  159. --- a/media/gpu/vaapi/vaapi_picture_factory.cc
  160. +++ b/media/gpu/vaapi/vaapi_picture_factory.cc
  161. @@ -10,13 +10,13 @@
  162. #include "ui/base/ui_base_features.h"
  163. #include "ui/gl/gl_bindings.h"
  164. -#if defined(USE_X11)
  165. -#include "media/gpu/vaapi/vaapi_picture_native_pixmap_angle.h"
  166. -#include "media/gpu/vaapi/vaapi_picture_tfp.h"
  167. -#endif
  168. #if defined(USE_OZONE)
  169. #include "media/gpu/vaapi/vaapi_picture_native_pixmap_ozone.h"
  170. -#endif
  171. +#endif // defined(USE_OZONE)
  172. +#if BUILDFLAG(USE_VAAPI_X11)
  173. +#include "media/gpu/vaapi/vaapi_picture_native_pixmap_angle.h"
  174. +#include "media/gpu/vaapi/vaapi_picture_tfp.h"
  175. +#endif // BUILDFLAG(USE_VAAPI_X11)
  176. #if defined(USE_EGL)
  177. #include "media/gpu/vaapi/vaapi_picture_native_pixmap_egl.h"
  178. #endif
  179. @@ -46,15 +46,13 @@ VaapiPictureFactory::VaapiPictureFactory() {
  180. vaapi_impl_pairs_.insert(
  181. std::make_pair(gl::kGLImplementationEGLGLES2,
  182. VaapiPictureFactory::kVaapiImplementationDrm));
  183. -#if defined(USE_X11)
  184. +#if BUILDFLAG(USE_VAAPI_X11)
  185. vaapi_impl_pairs_.insert(
  186. std::make_pair(gl::kGLImplementationEGLANGLE,
  187. VaapiPictureFactory::kVaapiImplementationAngle));
  188. - if (!features::IsUsingOzonePlatform()) {
  189. - vaapi_impl_pairs_.insert(
  190. - std::make_pair(gl::kGLImplementationDesktopGL,
  191. - VaapiPictureFactory::kVaapiImplementationX11));
  192. - }
  193. + vaapi_impl_pairs_.insert(
  194. + std::make_pair(gl::kGLImplementationDesktopGL,
  195. + VaapiPictureFactory::kVaapiImplementationX11));
  196. #endif
  197. DeterminePictureCreationAndDownloadingMechanism();
  198. @@ -96,19 +94,19 @@ VaapiPictureFactory::GetVaapiImplementation(gl::GLImplementation gl_impl) {
  199. }
  200. uint32_t VaapiPictureFactory::GetGLTextureTarget() {
  201. -#if defined(USE_OZONE)
  202. - if (features::IsUsingOzonePlatform())
  203. - return GL_TEXTURE_EXTERNAL_OES;
  204. -#endif
  205. +#if BUILDFLAG(USE_VAAPI_X11)
  206. return GL_TEXTURE_2D;
  207. +#else
  208. + return GL_TEXTURE_EXTERNAL_OES;
  209. +#endif
  210. }
  211. gfx::BufferFormat VaapiPictureFactory::GetBufferFormat() {
  212. -#if defined(USE_OZONE)
  213. - if (features::IsUsingOzonePlatform())
  214. - return gfx::BufferFormat::YUV_420_BIPLANAR;
  215. -#endif
  216. +#if BUILDFLAG(USE_VAAPI_X11)
  217. return gfx::BufferFormat::RGBX_8888;
  218. +#else
  219. + return gfx::BufferFormat::YUV_420_BIPLANAR;
  220. +#endif
  221. }
  222. void VaapiPictureFactory::DeterminePictureCreationAndDownloadingMechanism() {
  223. @@ -116,51 +114,43 @@ void VaapiPictureFactory::DeterminePictureCreationAndDownloadingMechanism() {
  224. #if defined(USE_OZONE)
  225. // We can be called without GL initialized, which is valid if we use Ozone.
  226. case kVaapiImplementationNone:
  227. - if (features::IsUsingOzonePlatform()) {
  228. - create_picture_cb_ = base::BindRepeating(
  229. - &CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapOzone>);
  230. - needs_vpp_for_downloading_ = true;
  231. - }
  232. -
  233. - // This is reached by unit tests which don't require create_picture_cb_
  234. - // to be initialized or called.
  235. + create_picture_cb_ = base::BindRepeating(
  236. + &CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapOzone>);
  237. + needs_vpp_for_downloading_ = true;
  238. break;
  239. #endif // defined(USE_OZONE)
  240. -#if defined(USE_X11)
  241. +#if BUILDFLAG(USE_VAAPI_X11)
  242. case kVaapiImplementationX11:
  243. - DCHECK(!features::IsUsingOzonePlatform());
  244. create_picture_cb_ =
  245. base::BindRepeating(&CreateVaapiPictureNativeImpl<VaapiTFPPicture>);
  246. // Neither VaapiTFPPicture or VaapiPictureNativePixmapAngle needs the VPP.
  247. needs_vpp_for_downloading_ = false;
  248. break;
  249. case kVaapiImplementationAngle:
  250. - DCHECK(!features::IsUsingOzonePlatform());
  251. create_picture_cb_ = base::BindRepeating(
  252. &CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapAngle>);
  253. // Neither VaapiTFPPicture or VaapiPictureNativePixmapAngle needs the VPP.
  254. needs_vpp_for_downloading_ = false;
  255. break;
  256. -#endif // defined(USE_X11)
  257. +#endif // BUILDFLAG(USE_VAAPI_X11)
  258. case kVaapiImplementationDrm:
  259. #if defined(USE_OZONE)
  260. - if (features::IsUsingOzonePlatform()) {
  261. - create_picture_cb_ = base::BindRepeating(
  262. - &CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapOzone>);
  263. - needs_vpp_for_downloading_ = true;
  264. - break;
  265. - }
  266. -#endif // defined(USE_OZONE)
  267. -#if defined(USE_EGL)
  268. + create_picture_cb_ = base::BindRepeating(
  269. + &CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapOzone>);
  270. + needs_vpp_for_downloading_ = true;
  271. + break;
  272. +#elif defined(USE_EGL)
  273. create_picture_cb_ = base::BindRepeating(
  274. &CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapEgl>);
  275. needs_vpp_for_downloading_ = true;
  276. break;
  277. -#endif // defined(USE_EGL)
  278. +#else
  279. // ozone or egl must be used to use the DRM implementation.
  280. - NOTREACHED();
  281. + FALLTHROUGH;
  282. +#endif
  283. default:
  284. NOTREACHED();
  285. + break;
  286. }
  287. }
  288. diff --git a/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.cc b/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.cc
  289. index 9de0c93b44..e5b9908490 100644
  290. --- a/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.cc
  291. +++ b/media/gpu/vaapi/vaapi_picture_native_pixmap_angle.cc
  292. @@ -6,7 +6,6 @@
  293. #include "media/gpu/vaapi/va_surface.h"
  294. #include "media/gpu/vaapi/vaapi_wrapper.h"
  295. -#include "ui/base/ui_base_features.h"
  296. #include "ui/gfx/x/connection.h"
  297. #include "ui/gfx/x/future.h"
  298. #include "ui/gfx/x/xproto.h"
  299. @@ -92,7 +91,6 @@ Status VaapiPictureNativePixmapAngle::Allocate(gfx::BufferFormat format) {
  300. if (!make_context_current_cb_ || !make_context_current_cb_.Run())
  301. return StatusCode::kVaapiBadContext;
  302. - DCHECK(!features::IsUsingOzonePlatform());
  303. auto image =
  304. base::MakeRefCounted<gl::GLImageEGLPixmap>(visible_size_, format);
  305. if (!image)
  306. diff --git a/media/gpu/vaapi/vaapi_picture_tfp.cc b/media/gpu/vaapi/vaapi_picture_tfp.cc
  307. index 3f7e221d8a..11914e3640 100644
  308. --- a/media/gpu/vaapi/vaapi_picture_tfp.cc
  309. +++ b/media/gpu/vaapi/vaapi_picture_tfp.cc
  310. @@ -6,7 +6,6 @@
  311. #include "media/gpu/vaapi/va_surface.h"
  312. #include "media/gpu/vaapi/vaapi_wrapper.h"
  313. -#include "ui/base/ui_base_features.h"
  314. #include "ui/gfx/x/connection.h"
  315. #include "ui/gfx/x/future.h"
  316. #include "ui/gl/gl_bindings.h"
  317. @@ -37,7 +36,6 @@ VaapiTFPPicture::VaapiTFPPicture(
  318. connection_(x11::Connection::Get()),
  319. x_pixmap_(x11::Pixmap::None) {
  320. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  321. - DCHECK(!features::IsUsingOzonePlatform());
  322. DCHECK(texture_id);
  323. DCHECK(client_texture_id);
  324. }
  325. diff --git a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc
  326. index 7514fe4fdd..e4cd7c8d89 100644
  327. --- a/media/gpu/vaapi/vaapi_video_decode_accelerator.cc
  328. +++ b/media/gpu/vaapi/vaapi_video_decode_accelerator.cc
  329. @@ -184,12 +184,6 @@ bool VaapiVideoDecodeAccelerator::Initialize(const Config& config,
  330. Client* client) {
  331. DCHECK(task_runner_->BelongsToCurrentThread());
  332. -#if defined(USE_X11)
  333. - // TODO(crbug/1116701): implement decode acceleration when running with Ozone.
  334. - if (features::IsUsingOzonePlatform())
  335. - return false;
  336. -#endif
  337. -
  338. vaapi_picture_factory_ = std::make_unique<VaapiPictureFactory>();
  339. if (config.is_encrypted()) {
  340. @@ -1213,12 +1207,11 @@ VaapiVideoDecodeAccelerator::GetSupportedProfiles() {
  341. VaapiVideoDecodeAccelerator::BufferAllocationMode
  342. VaapiVideoDecodeAccelerator::DecideBufferAllocationMode() {
  343. -#if defined(USE_X11)
  344. +#if BUILDFLAG(USE_VAAPI_X11)
  345. // The IMPORT mode is used for Android on Chrome OS, so this doesn't apply
  346. // here.
  347. DCHECK_NE(output_mode_, VideoDecodeAccelerator::Config::OutputMode::IMPORT);
  348. // TODO(crbug/1116701): get video decode acceleration working with ozone.
  349. - DCHECK(!features::IsUsingOzonePlatform());
  350. // For H.264 on older devices, another +1 is experimentally needed for
  351. // high-to-high resolution changes.
  352. // TODO(mcasas): Figure out why and why only H264, see crbug.com/912295 and
  353. diff --git a/media/gpu/vaapi/vaapi_video_decode_accelerator_unittest.cc b/media/gpu/vaapi/vaapi_video_decode_accelerator_unittest.cc
  354. index 5b9a543386..826bb103b1 100644
  355. --- a/media/gpu/vaapi/vaapi_video_decode_accelerator_unittest.cc
  356. +++ b/media/gpu/vaapi/vaapi_video_decode_accelerator_unittest.cc
  357. @@ -17,7 +17,6 @@
  358. #include "media/gpu/vaapi/vaapi_wrapper.h"
  359. #include "testing/gmock/include/gmock/gmock.h"
  360. #include "testing/gtest/include/gtest/gtest.h"
  361. -#include "ui/base/ui_base_features.h"
  362. using base::test::RunClosure;
  363. using ::testing::_;
  364. @@ -416,12 +415,10 @@ TEST_P(VaapiVideoDecodeAcceleratorTest, SupportedPlatforms) {
  365. mock_vaapi_picture_factory_->GetVaapiImplementation(
  366. gl::kGLImplementationEGLGLES2));
  367. -#if defined(USE_X11)
  368. - if (!features::IsUsingOzonePlatform()) {
  369. - EXPECT_EQ(VaapiPictureFactory::kVaapiImplementationX11,
  370. - mock_vaapi_picture_factory_->GetVaapiImplementation(
  371. - gl::kGLImplementationDesktopGL));
  372. - }
  373. +#if BUILDFLAG(USE_VAAPI_X11)
  374. + EXPECT_EQ(VaapiPictureFactory::kVaapiImplementationX11,
  375. + mock_vaapi_picture_factory_->GetVaapiImplementation(
  376. + gl::kGLImplementationDesktopGL));
  377. #endif
  378. }
  379. diff --git a/media/gpu/vaapi/vaapi_wrapper.cc b/media/gpu/vaapi/vaapi_wrapper.cc
  380. index 754d258848..e528b0f84d 100644
  381. --- a/media/gpu/vaapi/vaapi_wrapper.cc
  382. +++ b/media/gpu/vaapi/vaapi_wrapper.cc
  383. @@ -65,7 +65,7 @@
  384. #include "ui/gl/gl_bindings.h"
  385. #include "ui/gl/gl_implementation.h"
  386. -#if defined(USE_X11)
  387. +#if BUILDFLAG(USE_VAAPI_X11)
  388. typedef XID Drawable;
  389. extern "C" {
  390. @@ -73,7 +73,7 @@ extern "C" {
  391. }
  392. #include "ui/gfx/x/connection.h" // nogncheck
  393. -#endif
  394. +#endif // BUILDFLAG(USE_VAAPI_X11)
  395. #if defined(USE_OZONE)
  396. #include "ui/ozone/public/ozone_platform.h"
  397. @@ -87,14 +87,14 @@ using media_gpu_vaapi::kModuleVa_prot;
  398. using media_gpu_vaapi::kModuleVa;
  399. using media_gpu_vaapi::kModuleVa_drm;
  400. -#if defined(USE_X11)
  401. +#if BUILDFLAG(USE_VAAPI_X11)
  402. using media_gpu_vaapi::kModuleVa_x11;
  403. -#endif
  404. +#endif // BUILDFLAG(USE_VAAPI_X11)
  405. using media_gpu_vaapi::InitializeStubs;
  406. using media_gpu_vaapi::IsVaInitialized;
  407. -#if defined(USE_X11)
  408. +#if BUILDFLAG(USE_VAAPI_X11)
  409. using media_gpu_vaapi::IsVa_x11Initialized;
  410. -#endif
  411. +#endif // BUILDFLAG(USE_VAAPI_X11)
  412. using media_gpu_vaapi::IsVa_drmInitialized;
  413. using media_gpu_vaapi::StubPathMap;
  414. @@ -559,10 +559,20 @@ VADisplayState::VADisplayState()
  415. bool VADisplayState::Initialize() {
  416. base::AutoLock auto_lock(va_lock_);
  417. +#if defined(USE_OZONE) && defined(OS_LINUX)
  418. + // TODO(crbug.com/1116701): add vaapi support for other Ozone platforms on
  419. + // Linux. See comment in OzonePlatform::PlatformProperties::supports_vaapi
  420. + // for more details. This will also require revisiting everything that's
  421. + // guarded by USE_VAAPI_X11. For example, if USE_VAAPI_X11 is true, but the
  422. + // user chooses the Wayland backend for Ozone at runtime, then many things (if
  423. + // not all) that we do for X11 won't apply.
  424. + if (!ui::OzonePlatform::GetInstance()->GetPlatformProperties().supports_vaapi)
  425. + return false;
  426. +#endif
  427. +
  428. bool libraries_initialized = IsVaInitialized() && IsVa_drmInitialized();
  429. -#if defined(USE_X11)
  430. - if (!features::IsUsingOzonePlatform())
  431. - libraries_initialized = libraries_initialized && IsVa_x11Initialized();
  432. +#if BUILDFLAG(USE_VAAPI_X11)
  433. + libraries_initialized = libraries_initialized && IsVa_x11Initialized();
  434. #endif
  435. if (!libraries_initialized)
  436. return false;
  437. @@ -577,34 +587,25 @@ bool VADisplayState::Initialize() {
  438. return success;
  439. }
  440. -#if defined(USE_X11)
  441. +#if BUILDFLAG(USE_VAAPI_X11)
  442. absl::optional<VADisplay> GetVADisplayStateX11(const base::ScopedFD& drm_fd) {
  443. - bool use_drm_as_fallback = false;
  444. switch (gl::GetGLImplementation()) {
  445. case gl::kGLImplementationEGLGLES2:
  446. return vaGetDisplayDRM(drm_fd.get());
  447. case gl::kGLImplementationNone:
  448. - use_drm_as_fallback = true;
  449. - FALLTHROUGH;
  450. case gl::kGLImplementationDesktopGL: {
  451. - if (!features::IsUsingOzonePlatform()) {
  452. - VADisplay display =
  453. - vaGetDisplay(x11::Connection::Get()->GetXlibDisplay());
  454. - if (vaDisplayIsValid(display))
  455. - return display;
  456. - return vaGetDisplayDRM(drm_fd.get());
  457. - }
  458. - break;
  459. + VADisplay display =
  460. + vaGetDisplay(x11::Connection::Get()->GetXlibDisplay());
  461. + if (vaDisplayIsValid(display))
  462. + return display;
  463. + return vaGetDisplayDRM(drm_fd.get());
  464. }
  465. - case gl::kGLImplementationEGLANGLE: {
  466. - if (!features::IsUsingOzonePlatform())
  467. - return vaGetDisplay(x11::Connection::Get()->GetXlibDisplay());
  468. - break;
  469. - }
  470. + case gl::kGLImplementationEGLANGLE:
  471. + return vaGetDisplay(x11::Connection::Get()->GetXlibDisplay());
  472. default:
  473. LOG(WARNING) << "VAAPI video acceleration not available for "
  474. @@ -612,10 +613,6 @@ absl::optional<VADisplay> GetVADisplayStateX11(const base::ScopedFD& drm_fd) {
  475. gl::GetGLImplementationParts());
  476. return absl::nullopt;
  477. }
  478. -
  479. - if (use_drm_as_fallback)
  480. - return vaGetDisplayDRM(drm_fd.get());
  481. - return absl::nullopt;
  482. }
  483. #else
  484. @@ -633,11 +630,11 @@ absl::optional<VADisplay> GetVADisplayState(const base::ScopedFD& drm_fd) {
  485. }
  486. }
  487. -#endif // defined(USE_X11)
  488. +#endif // BUILDFLAG(USE_VAAPI_X11)
  489. bool VADisplayState::InitializeVaDisplay_Locked() {
  490. absl::optional<VADisplay> display =
  491. -#if defined(USE_X11)
  492. +#if BUILDFLAG(USE_VAAPI_X11)
  493. GetVADisplayStateX11(drm_fd_);
  494. #else
  495. GetVADisplayState(drm_fd_);
  496. @@ -702,10 +699,9 @@ bool VADisplayState::InitializeOnce() {
  497. if (!InitializeVaDisplay_Locked() || !InitializeVaDriver_Locked())
  498. return false;
  499. -#if defined(USE_X11)
  500. +#if BUILDFLAG(USE_VAAPI_X11)
  501. if (gl::GetGLImplementation() == gl::kGLImplementationEGLANGLE &&
  502. implementation_type_ == VAImplementation::kIntelIHD) {
  503. - DCHECK(!features::IsUsingOzonePlatform());
  504. constexpr char libva_driver_impl_env[] = "LIBVA_DRIVER_NAME";
  505. // TODO(crbug/1116703) The libva intel-media driver has a known segfault in
  506. // vaPutSurface, so until this is fixed, fall back to the i965 driver. There
  507. @@ -722,7 +718,7 @@ bool VADisplayState::InitializeOnce() {
  508. if (!InitializeVaDisplay_Locked() || !InitializeVaDriver_Locked())
  509. return false;
  510. }
  511. -#endif // USE_X11
  512. +#endif // BUILDFLAG(USE_VAAPI_X11)
  513. return true;
  514. }
  515. @@ -2452,11 +2448,10 @@ bool VaapiWrapper::MapAndCopyAndExecute(
  516. return Execute_Locked(va_surface_id, va_buffer_ids);
  517. }
  518. -#if defined(USE_X11)
  519. +#if BUILDFLAG(USE_VAAPI_X11)
  520. bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
  521. x11::Pixmap x_pixmap,
  522. gfx::Size dest_size) {
  523. - DCHECK(!features::IsUsingOzonePlatform());
  524. base::AutoLock auto_lock(*va_lock_);
  525. VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
  526. @@ -2470,7 +2465,7 @@ bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
  527. VA_SUCCESS_OR_RETURN(va_res, VaapiFunctions::kVAPutSurface, false);
  528. return true;
  529. }
  530. -#endif // USE_X11
  531. +#endif // BUILDFLAG(USE_VAAPI_X11)
  532. std::unique_ptr<ScopedVAImage> VaapiWrapper::CreateVaImage(
  533. VASurfaceID va_surface_id,
  534. @@ -2844,9 +2839,8 @@ void VaapiWrapper::PreSandboxInitialization() {
  535. paths[kModuleVa].push_back(std::string("libva.so.") + va_suffix);
  536. paths[kModuleVa_drm].push_back(std::string("libva-drm.so.") + va_suffix);
  537. -#if defined(USE_X11)
  538. - if (!features::IsUsingOzonePlatform())
  539. - paths[kModuleVa_x11].push_back(std::string("libva-x11.so.") + va_suffix);
  540. +#if BUILDFLAG(USE_VAAPI_X11)
  541. + paths[kModuleVa_x11].push_back(std::string("libva-x11.so.") + va_suffix);
  542. #endif
  543. #if BUILDFLAG(IS_CHROMEOS_ASH)
  544. paths[kModuleVa_prot].push_back(std::string("libva.so.") + va_suffix);
  545. diff --git a/media/gpu/vaapi/vaapi_wrapper.h b/media/gpu/vaapi/vaapi_wrapper.h
  546. index 0e3da53624..88ffcd0799 100644
  547. --- a/media/gpu/vaapi/vaapi_wrapper.h
  548. +++ b/media/gpu/vaapi/vaapi_wrapper.h
  549. @@ -36,9 +36,9 @@
  550. #include "third_party/abseil-cpp/absl/types/optional.h"
  551. #include "ui/gfx/geometry/size.h"
  552. -#if defined(USE_X11)
  553. +#if BUILDFLAG(USE_VAAPI_X11)
  554. #include "ui/gfx/x/xproto.h" // nogncheck
  555. -#endif // USE_X11
  556. +#endif // BUILDFLAG(USE_VAAPI_X11)
  557. namespace gfx {
  558. enum class BufferFormat;
  559. @@ -426,13 +426,13 @@ class MEDIA_GPU_EXPORT VaapiWrapper
  560. const std::vector<std::pair<VABufferID, VABufferDescriptor>>& va_buffers)
  561. WARN_UNUSED_RESULT;
  562. -#if defined(USE_X11)
  563. +#if BUILDFLAG(USE_VAAPI_X11)
  564. // Put data from |va_surface_id| into |x_pixmap| of size
  565. // |dest_size|, converting/scaling to it.
  566. bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
  567. x11::Pixmap x_pixmap,
  568. gfx::Size dest_size) WARN_UNUSED_RESULT;
  569. -#endif // USE_X11
  570. +#endif // BUILDFLAG(USE_VAAPI_X11)
  571. // Creates a ScopedVAImage from a VASurface |va_surface_id| and map it into
  572. // memory with the given |format| and |size|. If |format| is not equal to the
  573. diff --git a/ui/ozone/platform/x11/ozone_platform_x11.cc b/ui/ozone/platform/x11/ozone_platform_x11.cc
  574. index 8889828e0f..963dc7a0cd 100644
  575. --- a/ui/ozone/platform/x11/ozone_platform_x11.cc
  576. +++ b/ui/ozone/platform/x11/ozone_platform_x11.cc
  577. @@ -208,6 +208,9 @@ class OzonePlatformX11 : public OzonePlatform,
  578. properties->supports_global_application_menus = true;
  579. properties->app_modal_dialogs_use_event_blocker = true;
  580. properties->fetch_buffer_formats_for_gmb_on_gpu = true;
  581. +#if defined(OS_LINUX)
  582. + properties->supports_vaapi = true;
  583. +#endif
  584. initialised = true;
  585. }
  586. diff --git a/ui/ozone/public/ozone_platform.h b/ui/ozone/public/ozone_platform.h
  587. index df95f07486..2d7f44bbfa 100644
  588. --- a/ui/ozone/public/ozone_platform.h
  589. +++ b/ui/ozone/public/ozone_platform.h
  590. @@ -15,6 +15,7 @@
  591. #include "base/macros.h"
  592. #include "base/message_loop/message_pump_type.h"
  593. #include "base/single_thread_task_runner.h"
  594. +#include "build/build_config.h"
  595. #include "mojo/public/cpp/bindings/binder_map.h"
  596. #include "ui/gfx/buffer_types.h"
  597. #include "ui/gfx/native_widget_types.h"
  598. @@ -154,6 +155,15 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform {
  599. // Determines whether buffer formats should be fetched on GPU and passed
  600. // back via gpu extra info.
  601. bool fetch_buffer_formats_for_gmb_on_gpu = false;
  602. +
  603. +#if defined(OS_LINUX)
  604. + // TODO(crbug.com/1116701): add vaapi support for other Ozone platforms on
  605. + // Linux. At the moment, VA-API Linux implementation supports only X11
  606. + // backend. This implementation must be refactored to support Ozone
  607. + // properly. As a temporary solution, VA-API on Linux checks if vaapi is
  608. + // supported (which implicitly means that it is Ozone/X11).
  609. + bool supports_vaapi = false;
  610. +#endif
  611. };
  612. // Groups platform properties that can only be known at run time.