From https://github.com/saiarcot895/chromium-ubuntu-build/blob/branch-3325/debian/patches/enable_vaapi_on_linux_2.diff
From 53b93dfe87fd10cced5d2a2a63072dfc7a2af6e4 Mon Sep 17 00:00:00 2001
From: Daniel Charles <daniel.charles@intel.com>
Date: Fri, 28 Jul 2017 16:31:47 -0700
Subject: [PATCH] Enable VAVDA, VAVEA and VAJDA on linux with VAAPI only

This patch contains all the changes necessary to use VA-API along with
vaapi-driver to run all media use cases supported with hardware acceleration.

It is intended to remain as experimental accessible from chrome://flags on linux.
It requires libva/intel-vaapi-driver to be installed on the system path where
chrome is executed.  Other drivers could be tested if available. Flags are
kept independent for linux, where this feature has to be enabled before
actually using it.  This should not change how other OSes use the flags
already, the new flags will show at the buttom on the section of unavailable
experiments

The changes cover a range of compiler pre-processor flags to enable the stack.
It moves the presandbox operations to the vaapi_wrapper class as the hook function
is available there. vaInit will open driver on the correct installed folder.

chrome flags consolidtation into only two flags for linux.  Mjpeg and accelerated
video are used.  The other flags are kept for ChromeOS and other OSes.

Developer testing was made on skylake hardware, ChromeOS and Ubuntu.

BUG=NONE
TEST="subjective testing with VAVDA,VAVEA and VAJDA, autotest for encoder"
TEST="and decoder hardware accelerated"
TEST="have libva/intel-vaapi-driver installed and not installed in the system"
TEST="repeat on different hardware families"
R=posciak@chromium.org
R=kcwu@chromium.org

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ifbbf5c9e5221a8b5733fc6d4d0cf984a1f103171
Signed-off-by: Daniel Charles <daniel.charles@intel.com>
---

Index: beta/content/browser/gpu/compositor_util.cc
===================================================================
--- beta.orig/content/browser/gpu/compositor_util.cc
+++ beta/content/browser/gpu/compositor_util.cc
@@ -98,7 +98,11 @@ const GpuFeatureData GetGpuFeatureData(s
       {"video_decode",
        manager->GetFeatureStatus(
            gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE),
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
+       !command_line.HasSwitch(switches::kEnableAcceleratedVideo),
+#else
        command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode),
+#endif
        "Accelerated video decode has been disabled, either via blacklist,"
        " about:flags or the command line.",
        true},
Index: beta/content/browser/gpu/gpu_data_manager_impl_private.cc
===================================================================
--- beta.orig/content/browser/gpu/gpu_data_manager_impl_private.cc
+++ beta/content/browser/gpu/gpu_data_manager_impl_private.cc
@@ -597,7 +597,7 @@ void GpuDataManagerImplPrivate::AppendRe
     base::CommandLine* command_line) const {
   DCHECK(command_line);
 
-#if defined(OS_ANDROID)
+#if !defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID)
   // TODO(zmo): Move this to renderer side checking with GPU channel.
   if (blacklist_accelerated_video_decode_) {
     command_line->AppendSwitch(switches::kDisableAcceleratedVideoDecode);
Index: beta/content/browser/gpu/gpu_process_host.cc
===================================================================
--- beta.orig/content/browser/gpu/gpu_process_host.cc
+++ beta/content/browser/gpu/gpu_process_host.cc
@@ -120,7 +120,7 @@ static const char* const kSwitchNames[]
     switches::kDisableGLExtensions,
     switches::kDisableLogging,
     switches::kDisableShaderNameHashing,
-#if BUILDFLAG(ENABLE_WEBRTC)
+#if BUILDFLAG(ENABLE_WEBRTC) && !defined(OS_LINUX)
     switches::kDisableWebRtcHWEncoding,
 #endif
 #if defined(OS_WIN)
Index: beta/content/browser/renderer_host/media/video_capture_browsertest.cc
===================================================================
--- beta.orig/content/browser/renderer_host/media/video_capture_browsertest.cc
+++ beta/content/browser/renderer_host/media/video_capture_browsertest.cc
@@ -164,8 +164,13 @@ class VideoCaptureBrowserTest : public C
       base::CommandLine::ForCurrentProcess()->AppendSwitch(
           switches::kUseFakeJpegDecodeAccelerator);
     } else {
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
+      base::CommandLine::ForCurrentProcess()->AppendSwitch(
+          switches::kEnableAcceleratedMjpegDecode);
+#else
       base::CommandLine::ForCurrentProcess()->AppendSwitch(
           switches::kDisableAcceleratedMjpegDecode);
+#endif
     }
   }
 
Index: beta/content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.cc
===================================================================
--- beta.orig/content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.cc
+++ beta/content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.cc
@@ -65,15 +65,21 @@ void VideoCaptureGpuJpegDecoder::Initial
   bool is_platform_supported =
       base::CommandLine::ForCurrentProcess()->HasSwitch(
           switches::kUseFakeJpegDecodeAccelerator);
-#if defined(OS_CHROMEOS)
-  // Non-ChromeOS platforms do not support HW JPEG decode now. Do not establish
-  // gpu channel to avoid introducing overhead.
+#if !defined(OS_ANDROID) && defined(OS_LINUX)
+  // Non-ChromeOS or Non-Linux platforms do not support HW JPEG decode now. Do
+  // not establish gpu channel to avoid introducing overhead.
   is_platform_supported = true;
 #endif
 
   if (!is_platform_supported ||
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
+      !base::CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kEnableAcceleratedMjpegDecode)
+#else
       base::CommandLine::ForCurrentProcess()->HasSwitch(
-          switches::kDisableAcceleratedMjpegDecode)) {
+          switches::kDisableAcceleratedMjpegDecode)
+#endif
+          ) {
     decoder_status_ = FAILED;
     RecordInitDecodeUMA_Locked();
     return;
Index: beta/content/browser/renderer_host/render_process_host_impl.cc
===================================================================
--- beta.orig/content/browser/renderer_host/render_process_host_impl.cc
+++ beta/content/browser/renderer_host/render_process_host_impl.cc
@@ -2530,7 +2530,11 @@ void RenderProcessHostImpl::PropagateBro
     switches::kDefaultTileHeight,
     switches::kDisable2dCanvasImageChromium,
     switches::kDisableAcceleratedJpegDecoding,
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+    switches::kEnableAcceleratedVideo,
+#else
     switches::kDisableAcceleratedVideoDecode,
+#endif
     switches::kDisableBackgroundTimerThrottling,
     switches::kDisableBreakpad,
     switches::kDisableCompositorUkmForTests,
@@ -2663,8 +2667,10 @@ void RenderProcessHostImpl::PropagateBro
     switches::kDisableMojoRenderer,
 #endif
 #if BUILDFLAG(ENABLE_WEBRTC)
+#if !defined(OS_LINUX) || defined(OS_CHROMEOS)
     switches::kDisableWebRtcHWDecoding,
     switches::kDisableWebRtcHWEncoding,
+#endif
     switches::kEnableWebRtcSrtpAesGcm,
     switches::kEnableWebRtcSrtpEncryptedHeaders,
     switches::kEnableWebRtcStunOrigin,
Index: beta/content/browser/webrtc/webrtc_media_recorder_browsertest.cc
===================================================================
--- beta.orig/content/browser/webrtc/webrtc_media_recorder_browsertest.cc
+++ beta/content/browser/webrtc/webrtc_media_recorder_browsertest.cc
@@ -58,7 +58,12 @@ class WebRtcMediaRecorderTest
       return;
     // This flag is also used for encoding, https://crbug.com/616640.
     base::CommandLine::ForCurrentProcess()->AppendSwitch(
-        switches::kDisableAcceleratedVideoDecode);
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+        switches::kEnableAcceleratedVideo
+#else
+        switches::kDisableAcceleratedVideoDecode
+#endif
+        );
   }
 
  private:
Index: beta/content/gpu/gpu_sandbox_hook_linux.cc
===================================================================
--- beta.orig/content/gpu/gpu_sandbox_hook_linux.cc
+++ beta/content/gpu/gpu_sandbox_hook_linux.cc
@@ -48,22 +48,6 @@ inline bool IsChromeOS() {
 #endif
 }
 
-inline bool IsArchitectureX86_64() {
-#if defined(__x86_64__)
-  return true;
-#else
-  return false;
-#endif
-}
-
-inline bool IsArchitectureI386() {
-#if defined(__i386__)
-  return true;
-#else
-  return false;
-#endif
-}
-
 inline bool IsArchitectureArm() {
 #if defined(ARCH_CPU_ARM_FAMILY)
   return true;
@@ -270,50 +254,6 @@ void LoadV4L2Libraries(
   }
 }
 
-void LoadStandardLibraries(
-    const service_manager::SandboxSeccompBPF::Options& options) {
-  if (IsArchitectureX86_64() || IsArchitectureI386()) {
-    // Accelerated video dlopen()'s some shared objects
-    // inside the sandbox, so preload them now.
-    if (IsAcceleratedVideoEnabled(options)) {
-      if (IsLibVAVersion2()) {
-        if (IsArchitectureX86_64()) {
-          dlopen("/usr/lib64/va/drivers/i965_drv_video.so", dlopen_flag);
-          dlopen("/usr/lib64/va/drivers/hybrid_drv_video.so", dlopen_flag);
-        } else if (IsArchitectureI386()) {
-          dlopen("/usr/lib/va/drivers/i965_drv_video.so", dlopen_flag);
-        }
-        dlopen("libva.so.2", dlopen_flag);
-#if defined(USE_OZONE)
-        dlopen("libva-drm.so.2", dlopen_flag);
-#endif
-      } else {
-        // If we are linked against libva 1, we have two cases to handle:
-        // - the sysroot includes both libva 1 and 2, in which case the drivers
-        //   are in /usr/lib{64}/va1/
-        // - the sysroot only includes libva 1, in which case the drivers are
-        //   are in /usr/lib{64}/va/
-        // This is ugly, but temporary until all builds have switched to libva 2.
-        if (IsArchitectureX86_64()) {
-          if (!dlopen("/usr/lib64/va1/drivers/i965_drv_video.so", dlopen_flag))
-            dlopen("/usr/lib64/va/drivers/i965_drv_video.so", dlopen_flag);
-          if (!dlopen("/usr/lib64/va1/drivers/hybrid_drv_video.so", dlopen_flag))
-            dlopen("/usr/lib64/va/drivers/hybrid_drv_video.so", dlopen_flag);
-        } else if (IsArchitectureI386()) {
-          if (!dlopen("/usr/lib/va1/drivers/i965_drv_video.so", dlopen_flag))
-            dlopen("/usr/lib/va/drivers/i965_drv_video.so", dlopen_flag);
-        }
-        dlopen("libva.so.1", dlopen_flag);
-#if defined(USE_OZONE)
-        dlopen("libva-drm.so.1", dlopen_flag);
-#elif defined(USE_X11)
-        dlopen("libva-x11.so.1", dlopen_flag);
-#endif
-      }
-    }
-  }
-}
-
 bool LoadLibrariesForGpu(
     const service_manager::SandboxSeccompBPF::Options& options) {
   if (IsChromeOS()) {
@@ -326,7 +266,6 @@ bool LoadLibrariesForGpu(
     if (options.use_amd_specific_policies)
       return LoadAmdGpuLibraries();
   }
-  LoadStandardLibraries(options);
   return true;
 }
 
Index: beta/content/gpu/BUILD.gn
===================================================================
--- beta.orig/content/gpu/BUILD.gn
+++ beta/content/gpu/BUILD.gn
@@ -6,6 +6,7 @@ import("//build/config/jumbo.gni")
 import("//build/config/ui.gni")
 import("//gpu/vulkan/features.gni")
 import("//media/media_options.gni")
+import("//media/gpu/args.gni")
 import("//ui/ozone/ozone.gni")
 
 # See //content/BUILD.gn for how this works.
@@ -49,7 +50,6 @@ target(link_target_type, "gpu_sources")
   ]
 
   configs += [ "//content:content_implementation" ]
-
   deps = [
     "//base",
     "//base/third_party/dynamic_annotations",
@@ -125,4 +125,8 @@ target(link_target_type, "gpu_sources")
   if (is_desktop_linux && (!is_chromecast || is_cast_desktop_build)) {
     configs += [ "//build/config/linux/dri" ]
   }
+
+  if (is_desktop_linux && use_vaapi) {
+    public_configs = [ "//media/gpu:libva_config" ]
+  }
 }
Index: beta/content/gpu/gpu_main.cc
===================================================================
--- beta.orig/content/gpu/gpu_main.cc
+++ beta/content/gpu/gpu_main.cc
@@ -273,7 +273,7 @@ int GpuMain(const MainFunctionParams& pa
 
   base::PlatformThread::SetName("CrGpuMain");
 
-#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
+#if defined(OS_LINUX)
   // Set thread priority before sandbox initialization.
   base::PlatformThread::SetCurrentThreadPriority(base::ThreadPriority::DISPLAY);
 #endif
@@ -302,7 +302,7 @@ int GpuMain(const MainFunctionParams& pa
   GetContentClient()->SetGpuInfo(gpu_init->gpu_info());
 
   base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL;
-#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
+#if defined(OS_LINUX)
   io_thread_priority = base::ThreadPriority::DISPLAY;
 #endif
 
Index: beta/content/public/browser/gpu_utils.cc
===================================================================
--- beta.orig/content/public/browser/gpu_utils.cc
+++ beta/content/public/browser/gpu_utils.cc
@@ -7,6 +7,7 @@
 #include "base/command_line.h"
 #include "base/single_thread_task_runner.h"
 #include "base/strings/string_number_conversions.h"
+#include "build/build_config.h"
 #include "content/browser/gpu/gpu_process_host.h"
 #include "content/public/common/content_features.h"
 #include "content/public/common/content_switches.h"
@@ -55,10 +56,18 @@ const gpu::GpuPreferences GetGpuPreferen
   gpu_preferences.in_process_gpu =
       command_line->HasSwitch(switches::kInProcessGPU);
   gpu_preferences.disable_accelerated_video_decode =
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+      !command_line->HasSwitch(switches::kEnableAcceleratedVideo);
+#else
       command_line->HasSwitch(switches::kDisableAcceleratedVideoDecode);
+#endif
   gpu_preferences.disable_accelerated_video_encode =
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+     !command_line->HasSwitch(switches::kEnableAcceleratedVideo);
+#else
       command_line->HasSwitch(switches::kDisableAcceleratedVideoEncode);
-#if BUILDFLAG(ENABLE_WEBRTC)
+#endif
+#if BUILDFLAG(ENABLE_WEBRTC) && (!defined(OS_LINUX) || defined(OS_CHROMEOS))
   gpu_preferences.disable_web_rtc_hw_encoding =
       command_line->HasSwitch(switches::kDisableWebRtcHWEncoding);
 #endif
Index: beta/content/public/common/content_switches.cc
===================================================================
--- beta.orig/content/public/common/content_switches.cc
+++ beta/content/public/common/content_switches.cc
@@ -78,12 +78,21 @@ const char kDisable3DAPIs[]
 
 // Disable gpu-accelerated 2d canvas.
 const char kDisableAccelerated2dCanvas[]    = "disable-accelerated-2d-canvas";
-
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+// Enable hardware accelerated mjpeg decode on linux
+const char kEnableAcceleratedMjpegDecode[] = "enable-accelerated-mjpeg-decode";
+#else
 // Disable hardware acceleration of mjpeg decode for captured frame, where
 // available.
 const char kDisableAcceleratedMjpegDecode[] =
     "disable-accelerated-mjpeg-decode";
+#endif
 
+#if defined(OS_LINUX)
+// Enables hardware acceleration of video for Linux only. VA-API driver
+// is required to be present on the system installation.
+const char kEnableAcceleratedVideo[] = "enable-accelerated-video";
+#endif
 // Disables hardware acceleration of video decode, where available.
 const char kDisableAcceleratedVideoDecode[] =
     "disable-accelerated-video-decode";
@@ -888,11 +897,13 @@ const char kZygoteProcess[]
 // ignores this switch on its stable and beta channels.
 const char kDisableWebRtcEncryption[]      = "disable-webrtc-encryption";
 
+#if defined(OS_CHROMEOS)
 // Disables HW decode acceleration for WebRTC.
 const char kDisableWebRtcHWDecoding[]       = "disable-webrtc-hw-decoding";
 
 // Disables HW encode acceleration for WebRTC.
 const char kDisableWebRtcHWEncoding[] = "disable-webrtc-hw-encoding";
+#endif
 
 // Enables negotiation of GCM cipher suites from RFC 7714 for SRTP in WebRTC.
 // See https://tools.ietf.org/html/rfc7714 for further information.
Index: beta/content/public/common/content_switches.h
===================================================================
--- beta.orig/content/public/common/content_switches.h
+++ beta/content/public/common/content_switches.h
@@ -33,7 +33,11 @@ CONTENT_EXPORT extern const char kDisabl
 CONTENT_EXPORT extern const char kDisable3DAPIs[];
 CONTENT_EXPORT extern const char kDisableAccelerated2dCanvas[];
 CONTENT_EXPORT extern const char kDisableAcceleratedJpegDecoding[];
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+CONTENT_EXPORT extern const char kEnableAcceleratedMjpegDecode[];
+#else
 CONTENT_EXPORT extern const char kDisableAcceleratedMjpegDecode[];
+#endif
 CONTENT_EXPORT extern const char kDisableAcceleratedVideoDecode[];
 CONTENT_EXPORT extern const char kDisableAcceleratedVideoEncode[];
 CONTENT_EXPORT extern const char kDisableAudioSupportForDesktopShare[];
@@ -107,6 +111,9 @@ CONTENT_EXPORT extern const char kDisabl
 CONTENT_EXPORT extern const char kDomAutomationController[];
 extern const char kDisable2dCanvasClipAntialiasing[];
 CONTENT_EXPORT extern const char kDumpBlinkRuntimeCallStats[];
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
+CONTENT_EXPORT extern const char kEnableAcceleratedVideo[];
+#endif
 CONTENT_EXPORT extern const char kEnableAggressiveDOMStorageFlushing[];
 CONTENT_EXPORT extern const char kEnableAutomation[];
 CONTENT_EXPORT extern const char kEnablePreferCompositingToLCDText[];
@@ -244,8 +251,10 @@ CONTENT_EXPORT extern const char kZygote
 
 #if BUILDFLAG(ENABLE_WEBRTC)
 CONTENT_EXPORT extern const char kDisableWebRtcEncryption[];
+#if defined(OS_CHROMEOS)
 CONTENT_EXPORT extern const char kDisableWebRtcHWDecoding[];
 CONTENT_EXPORT extern const char kDisableWebRtcHWEncoding[];
+#endif
 CONTENT_EXPORT extern const char kEnableWebRtcSrtpAesGcm[];
 CONTENT_EXPORT extern const char kEnableWebRtcSrtpEncryptedHeaders[];
 CONTENT_EXPORT extern const char kEnableWebRtcStunOrigin[];
Index: beta/content/renderer/media/webrtc/peer_connection_dependency_factory.cc
===================================================================
--- beta.orig/content/renderer/media/webrtc/peer_connection_dependency_factory.cc
+++ beta/content/renderer/media/webrtc/peer_connection_dependency_factory.cc
@@ -245,10 +245,19 @@ void PeerConnectionDependencyFactory::In
 
   const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
   if (gpu_factories && gpu_factories->IsGpuVideoAcceleratorEnabled()) {
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+    if (cmd_line->HasSwitch(switches::kEnableAcceleratedVideo))
+#else
     if (!cmd_line->HasSwitch(switches::kDisableWebRtcHWDecoding))
+#endif
       decoder_factory.reset(new RTCVideoDecoderFactory(gpu_factories));
 
-    if (!cmd_line->HasSwitch(switches::kDisableWebRtcHWEncoding)) {
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+    if (cmd_line->HasSwitch(switches::kEnableAcceleratedVideo))
+#else
+    if (!cmd_line->HasSwitch(switches::kDisableWebRtcHWEncoding))
+#endif
+    {
       encoder_factory.reset(new RTCVideoEncoderFactory(gpu_factories));
     }
   }
Index: beta/content/renderer/render_thread_impl.cc
===================================================================
--- beta.orig/content/renderer/render_thread_impl.cc
+++ beta/content/renderer/render_thread_impl.cc
@@ -1485,7 +1485,11 @@ media::GpuVideoAcceleratorFactories* Ren
   scoped_refptr<base::SingleThreadTaskRunner> media_task_runner =
       GetMediaThreadTaskRunner();
   const bool enable_video_accelerator =
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+      cmd_line->HasSwitch(switches::kEnableAcceleratedVideo) &&
+#else
       !cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode) &&
+#endif
       (gpu_channel_host->gpu_feature_info()
            .status_values[gpu::GPU_FEATURE_TYPE_ACCELERATED_VIDEO_DECODE] ==
        gpu::kGpuFeatureStatusEnabled);
Index: beta/gpu/config/software_rendering_list.json
===================================================================
--- beta.orig/gpu/config/software_rendering_list.json
+++ beta/gpu/config/software_rendering_list.json
@@ -373,17 +373,6 @@
       ]
     },
     {
-      "id": 48,
-      "description": "Accelerated video decode is unavailable on Linux",
-      "cr_bugs": [137247],
-      "os": {
-        "type": "linux"
-      },
-      "features": [
-        "accelerated_video_decode"
-      ]
-    },
-    {
       "id": 50,
       "description": "Disable VMware software renderer on older Mesa",
       "cr_bugs": [145531, 332596, 571899, 629434],
Index: beta/media/filters/BUILD.gn
===================================================================
--- beta.orig/media/filters/BUILD.gn
+++ beta/media/filters/BUILD.gn
@@ -4,6 +4,7 @@
 
 import("//media/media_options.gni")
 import("//third_party/libaom/options.gni")
+import("//media/gpu/args.gni")
 
 source_set("filters") {
   # Do not expand the visibility here without double-checking with OWNERS, this
@@ -203,7 +204,7 @@ source_set("filters") {
     deps += [ "//media/base/android" ]
   }
 
-  if (current_cpu != "arm" && is_linux) {
+  if (use_vaapi) {
     sources += [
       "h264_bitstream_buffer.cc",
       "h264_bitstream_buffer.h",
Index: beta/media/gpu/BUILD.gn
===================================================================
--- beta.orig/media/gpu/BUILD.gn
+++ beta/media/gpu/BUILD.gn
@@ -24,6 +24,12 @@ if (is_mac) {
   import("//build/config/mac/mac_sdk.gni")
 }
 
+import("//build/config/linux/pkg_config.gni")
+
+pkg_config("libva_config") {
+  packages = [ "libva" ]
+}
+
 if (use_vaapi) {
   action("libva_generate_stubs") {
     extra_header = "vaapi/va_stub_header.fragment"
@@ -303,6 +309,7 @@ component("gpu") {
         "v4l2/tegra_v4l2_device.h",
       ]
     }
+    public_configs = [ ":libva_config" ]
   }
 
   if (use_vaapi) {
Index: beta/media/gpu/gpu_video_decode_accelerator_factory.cc
===================================================================
--- beta.orig/media/gpu/gpu_video_decode_accelerator_factory.cc
+++ beta/media/gpu/gpu_video_decode_accelerator_factory.cc
@@ -88,6 +88,7 @@ GpuVideoDecodeAcceleratorFactory::GetDec
 // profile (instead of calculating a superset).
 // TODO(posciak,henryhsu): improve this so that we choose a superset of
 // resolutions and other supported profile parameters.
+  DVLOG(1) << "Get Supported profiles";
 #if defined(OS_WIN)
   capabilities.supported_profiles =
       DXVAVideoDecodeAccelerator::GetSupportedProfiles(gpu_preferences,
Index: beta/media/gpu/vaapi/vaapi_wrapper.cc
===================================================================
--- beta.orig/media/gpu/vaapi/vaapi_wrapper.cc
+++ beta/media/gpu/vaapi/vaapi_wrapper.cc
@@ -194,26 +194,14 @@ VADisplayState* VADisplayState::Get() {
 }
 
 // static
-void VADisplayState::PreSandboxInitialization() {
-  const char kDriRenderNode0Path[] = "/dev/dri/renderD128";
-  base::File drm_file = base::File(
-      base::FilePath::FromUTF8Unsafe(kDriRenderNode0Path),
-      base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE);
-  if (drm_file.IsValid())
-    VADisplayState::Get()->SetDrmFd(drm_file.GetPlatformFile());
-}
-
-// static
 bool VADisplayState::PostSandboxInitialization() {
   const std::string va_suffix(std::to_string(VA_MAJOR_VERSION + 1));
   StubPathMap paths;
 
   paths[kModuleVa].push_back(std::string("libva.so.") + va_suffix);
   paths[kModuleVa_drm].push_back(std::string("libva-drm.so.") + va_suffix);
-#if defined(USE_X11)
-  // libva-x11 does not exist on libva >= 2
-  if (VA_MAJOR_VERSION == 0)
-    paths[kModuleVa_x11].push_back("libva-x11.so.1");
+#if defined(USE_X11)  
+  paths[kModuleVa_x11].push_back(std::string("libva-x11.so.") + va_suffix);
 #endif
 
   const bool success = InitializeStubs(paths);
@@ -250,10 +240,10 @@ bool VADisplayState::Initialize() {
     case gl::kGLImplementationDesktopGL:
 #if defined(USE_X11)
       va_display_ = vaGetDisplay(gfx::GetXDisplay());
-#else
-      LOG(WARNING) << "VAAPI video acceleration not available without "
-                      "DesktopGL (GLX).";
 #endif  // USE_X11
+      if (vaDisplayIsValid(va_display_))
+        break;
+      va_display_ = vaGetDisplayDRM(drm_fd_.get());
       break;
     // Cannot infer platform from GL, try all available displays
     case gl::kGLImplementationNone:
@@ -601,6 +591,17 @@ bool VASupportedProfiles::GetMaxResoluti
   return true;
 }
 
+// static
+void VADisplayState::PreSandboxInitialization() {
+  const char kDriRenderNode0Path[] = "/dev/dri/renderD128";
+  base::File drm_file = base::File(
+      base::FilePath::FromUTF8Unsafe(kDriRenderNode0Path),
+      base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE);
+  if (drm_file.IsValid())
+    VADisplayState::Get()->SetDrmFd(drm_file.GetPlatformFile());
+  VASupportedProfiles::Get();  // dlopen all necessary libraries
+}
+
 // Maps VideoCodecProfile enum values to VaProfile values. This function
 // includes a workaround for https://crbug.com/345569: if va_profile is h264
 // baseline and it is not supported, we try constrained baseline.
@@ -802,7 +803,11 @@ scoped_refptr<VASurface> VaapiWrapper::C
   }
   va_attrib_extbuf.num_planes = num_planes;
 
+#if VA_CHECK_VERSION(1, 0, 0)
+  std::vector<uintptr_t> fds(num_fds);
+#else
   std::vector<unsigned long> fds(num_fds);
+#endif
   for (size_t i = 0; i < num_fds; ++i) {
     int dmabuf_fd = pixmap->GetDmaBufFd(i);
     if (dmabuf_fd < 0) {
Index: beta/components/viz/service/main/viz_main_impl.cc
===================================================================
--- beta.orig/components/viz/service/main/viz_main_impl.cc
+++ beta/components/viz/service/main/viz_main_impl.cc
@@ -39,7 +39,7 @@ std::unique_ptr<base::Thread> CreateAndS
   auto thread = std::make_unique<base::Thread>("CompositorThread");
   base::Thread::Options thread_options;
   thread_options.message_loop_type = base::MessageLoop::TYPE_DEFAULT;
-#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
+#if defined(OS_LINUX)
   thread_options.priority = base::ThreadPriority::DISPLAY;
 #endif
   CHECK(thread->StartWithOptions(thread_options));
@@ -51,7 +51,7 @@ std::unique_ptr<base::Thread> CreateAndS
   // It should be possible to use |main_task_runner_| for doing IO tasks.
   base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
   thread_options.priority = base::ThreadPriority::NORMAL;
-#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
+#if defined(OS_LINUX)
   // TODO(reveman): Remove this in favor of setting it explicitly for each
   // type of process.
   thread_options.priority = base::ThreadPriority::DISPLAY;
Index: beta/content/browser/renderer_host/render_view_host_impl.cc
===================================================================
--- beta.orig/content/browser/renderer_host/render_view_host_impl.cc
+++ beta/content/browser/renderer_host/render_view_host_impl.cc
@@ -433,7 +433,11 @@ WebPreferences RenderViewHostImpl::Compu
   prefs.save_previous_document_resources = GetSavePreviousDocumentResources();
 
   prefs.accelerated_video_decode_enabled =
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
+      command_line.HasSwitch(switches::kEnableAcceleratedVideo);
+#else
       !command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode);
+#endif
 
   std::string autoplay_policy = media::GetEffectiveAutoplayPolicy(command_line);
   if (autoplay_policy == switches::autoplay::kNoUserGestureRequiredPolicy) {
Index: beta/ui/gfx/BUILD.gn
===================================================================
--- beta.orig/ui/gfx/BUILD.gn
+++ beta/ui/gfx/BUILD.gn
@@ -7,6 +7,7 @@ import("//build/config/ui.gni")
 import("//device/vr/features/features.gni")
 import("//testing/test.gni")
 import("//testing/libfuzzer/fuzzer_test.gni")
+import("//media/gpu/args.gni")
 
 if (is_android) {
   import("//build/config/android/config.gni")
@@ -553,7 +554,7 @@ source_set("memory_buffer_sources") {
     "//ui/gfx/geometry",
   ]
 
-  if (is_linux && !use_qt) {
+  if (is_linux && use_vaapi) {
     sources += [
       "linux/client_native_pixmap_dmabuf.cc",
       "linux/client_native_pixmap_dmabuf.h",


