# # Taken from: # https://code.launchpad.net/~saiarcot895o # To be precise: https://bazaar.launchpad.net/~saiarcot895/chromium-browser/chromium-browser.utopic.beta/view/head:/debian/patches/enable_vaapi_on_linux.diff # And rebased against chromium-43.0.2357.65 source. # diff -uarN chromium-43.0.2357.65.orig/chrome/browser/about_flags.cc chromium-43.0.2357.65/chrome/browser/about_flags.cc --- chromium-43.0.2357.65.orig/chrome/browser/about_flags.cc 2015-05-14 00:35:45.000000000 +0200 +++ chromium-43.0.2357.65/chrome/browser/about_flags.cc 2015-05-21 11:41:29.223180021 +0200 @@ -986,7 +986,7 @@ { "disable-accelerated-video-decode", IDS_FLAGS_DISABLE_ACCELERATED_VIDEO_DECODE_NAME, IDS_FLAGS_DISABLE_ACCELERATED_VIDEO_DECODE_DESCRIPTION, - kOsMac | kOsWin | kOsCrOS, + kOsAll, SINGLE_VALUE_TYPE(switches::kDisableAcceleratedVideoDecode), }, #if defined(USE_ASH) diff -uarN chromium-43.0.2357.65.orig/content/common/gpu/media/gpu_video_decode_accelerator.cc chromium-43.0.2357.65/content/common/gpu/media/gpu_video_decode_accelerator.cc --- chromium-43.0.2357.65.orig/content/common/gpu/media/gpu_video_decode_accelerator.cc 2015-05-14 00:35:46.000000000 +0200 +++ chromium-43.0.2357.65/content/common/gpu/media/gpu_video_decode_accelerator.cc 2015-05-21 11:41:29.231181350 +0200 @@ -30,7 +30,7 @@ #include "content/common/gpu/media/dxva_video_decode_accelerator.h" #elif defined(OS_MACOSX) #include "content/common/gpu/media/vt_video_decode_accelerator.h" -#elif defined(OS_CHROMEOS) +#elif defined(OS_CHROMEOS) || defined(OS_LINUX) #if defined(USE_V4L2_CODEC) #include "content/common/gpu/media/v4l2_device.h" #include "content/common/gpu/media/v4l2_slice_video_decode_accelerator.h" @@ -342,7 +342,7 @@ scoped_ptr GpuVideoDecodeAccelerator::CreateVaapiVDA() { scoped_ptr decoder; -#if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) +#if (defined(OS_CHROMEOS) || defined(OS_LINUX)) && defined(ARCH_CPU_X86_FAMILY) decoder.reset(new VaapiVideoDecodeAccelerator( make_context_current_, base::Bind(&GpuVideoDecodeAccelerator::BindImage, base::Unretained(this)))); diff -uarN chromium-43.0.2357.65.orig/content/common/gpu/media/vaapi_wrapper.cc chromium-43.0.2357.65/content/common/gpu/media/vaapi_wrapper.cc --- chromium-43.0.2357.65.orig/content/common/gpu/media/vaapi_wrapper.cc 2015-05-14 00:35:46.000000000 +0200 +++ chromium-43.0.2357.65/content/common/gpu/media/vaapi_wrapper.cc 2015-05-21 11:41:29.231181350 +0200 @@ -142,7 +142,7 @@ VAProfile va_profile, const base::Closure& report_error_to_uma_cb) { if (!profile_infos_.Get().IsProfileSupported(mode, va_profile)) { - DVLOG(1) << "Unsupported va_profile: " << va_profile; + VLOG(1) << "Unsupported va_profile: " << va_profile; return nullptr; } @@ -360,7 +360,7 @@ if (std::find(supported_entrypoints.begin(), supported_entrypoints.end(), entrypoint) == supported_entrypoints.end()) { - DVLOG(1) << "Unsupported entrypoint"; + VLOG(1) << "Unsupported entrypoint"; return false; } return true; @@ -384,8 +384,8 @@ if (attribs[i].type != required_attribs[i].type || (attribs[i].value & required_attribs[i].value) != required_attribs[i].value) { - DVLOG(1) << "Unsupported value " << required_attribs[i].value - << " for attribute type " << required_attribs[i].type; + VLOG(1) << "Unsupported value " << required_attribs[i].value + << " for attribute type " << required_attribs[i].type; return false; } } diff -uarN chromium-43.0.2357.65.orig/content/common/sandbox_linux/bpf_gpu_policy_linux.cc chromium-43.0.2357.65/content/common/sandbox_linux/bpf_gpu_policy_linux.cc --- chromium-43.0.2357.65.orig/content/common/sandbox_linux/bpf_gpu_policy_linux.cc 2015-05-14 00:35:46.000000000 +0200 +++ chromium-43.0.2357.65/content/common/sandbox_linux/bpf_gpu_policy_linux.cc 2015-05-21 11:41:29.242183176 +0200 @@ -21,6 +21,8 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "build/build_config.h" +// Auto-generated for dlopen libva libraries +#include "content/common/gpu/media/va_stubs.h" #include "content/common/sandbox_linux/sandbox_bpf_base_policy_linux.h" #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" #include "content/common/set_process_title.h" @@ -31,6 +33,8 @@ #include "sandbox/linux/syscall_broker/broker_file_permission.h" #include "sandbox/linux/syscall_broker/broker_process.h" #include "sandbox/linux/system_headers/linux_syscalls.h" +#include "third_party/libva/va/va.h" +#include "third_party/libva/va/va_x11.h" using sandbox::arch_seccomp_data; using sandbox::bpf_dsl::Allow; @@ -40,6 +44,11 @@ using sandbox::syscall_broker::BrokerProcess; using sandbox::SyscallSets; +using content_common_gpu_media::kModuleVa; +using content_common_gpu_media::kModuleVa_x11; +using content_common_gpu_media::InitializeStubs; +using content_common_gpu_media::StubPathMap; + namespace content { namespace { @@ -94,7 +103,7 @@ bool IsAcceleratedVaapiVideoEncodeEnabled() { bool accelerated_encode_enabled = false; -#if defined(OS_CHROMEOS) +#if defined(OS_CHROMEOS) || defined(OS_LINUX) const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); accelerated_encode_enabled = @@ -295,23 +304,41 @@ // inside the sandbox, so preload them now. if (IsAcceleratedVaapiVideoEncodeEnabled() || IsAcceleratedVideoDecodeEnabled()) { - const char* I965DrvVideoPath = NULL; + VLOG(1) << "Attempting to enable hardware video acceleration."; + StubPathMap paths; + paths[kModuleVa].push_back("libva.so.1"); + paths[kModuleVa_x11].push_back("libva-x11.so.1"); + if (!InitializeStubs(paths)) { + VLOG(1) << "Failed to initialize stubs"; + return false; + } - if (IsArchitectureX86_64()) { - I965DrvVideoPath = "/usr/lib64/va/drivers/i965_drv_video.so"; - } else if (IsArchitectureI386()) { - I965DrvVideoPath = "/usr/lib/va/drivers/i965_drv_video.so"; + // libva drivers won't get loaded even above two libraries get dlopened. + // Thus, libva calls will fail after post sandbox stage. + // + // To get the va driver loaded before sandboxing, upstream simply dlopen + // the hard-coded va driver path because ChromeOS is the only platform + // that Google want to support libva. + // + // While generic linux distros ship va driver as anywhere they want. + // Fortunately, the va driver will be loadded when vaInitialize() get + // called. + // So the following code is to call vaInitialize() before sandboxing. + Display* x_display = XOpenDisplay(NULL); + VADisplay va_display = vaGetDisplay(x_display); + if (!vaDisplayIsValid(va_display)) { + VLOG(1) << "Failed to call vaGetDisplay()"; + return false; } - dlopen(I965DrvVideoPath, RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); - dlopen("libva.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); -#if defined(USE_OZONE) - dlopen("libva-drm.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); -#elif defined(USE_X11) - dlopen("libva-x11.so.1", RTLD_NOW|RTLD_GLOBAL|RTLD_NODELETE); -#endif - } - } + int major_version, minor_version; + if (vaInitialize(va_display, &major_version, &minor_version) + != VA_STATUS_SUCCESS) { + VLOG(1) << "Failed to call vaInitialize()"; + return false; + } + } // end of IsAcceleratedVaapiVideoEncodeEnabled() || IsAcceleratedVideoDecodeEnabled() + } // end of IsArchitectureX86_64() || IsArchitectureI386() return true; } diff -uarN chromium-43.0.2357.65.orig/content/content_common.gypi chromium-43.0.2357.65/content/content_common.gypi --- chromium-43.0.2357.65.orig/content/content_common.gypi 2015-05-14 00:35:46.000000000 +0200 +++ chromium-43.0.2357.65/content/content_common.gypi 2015-05-21 11:41:29.254185168 +0200 @@ -863,7 +863,7 @@ 'common/gpu/media/tegra_v4l2_device.h', ], }], - ['target_arch != "arm" and chromeos == 1', { + ['target_arch != "arm" and (chromeos == 1 or desktop_linux == 1)', { 'dependencies': [ '../media/media.gyp:media', '../third_party/libyuv/libyuv.gyp:libyuv', diff -uarN chromium-43.0.2357.65.orig/content/content_gpu.gypi chromium-43.0.2357.65/content/content_gpu.gypi --- chromium-43.0.2357.65.orig/content/content_gpu.gypi 2015-05-14 00:23:07.000000000 +0200 +++ chromium-43.0.2357.65/content/content_gpu.gypi 2015-05-21 11:41:29.255185335 +0200 @@ -36,7 +36,7 @@ ], }, }], - ['target_arch!="arm" and chromeos == 1', { + ['target_arch!="arm" and (chromeos == 1 or desktop_linux == 1)', { 'include_dirs': [ '<(DEPTH)/third_party/libva', ], diff -uarN chromium-43.0.2357.65.orig/content/content_tests.gypi chromium-43.0.2357.65/content/content_tests.gypi --- chromium-43.0.2357.65.orig/content/content_tests.gypi 2015-05-14 00:35:46.000000000 +0200 +++ chromium-43.0.2357.65/content/content_tests.gypi 2015-05-21 11:41:29.257185668 +0200 @@ -1661,7 +1661,7 @@ }, ] }], - ['chromeos==1 and target_arch != "arm"', { + ['(chromeos==1 or desktop_linux==1) and target_arch != "arm"', { 'targets': [ { 'target_name': 'vaapi_h264_decoder_unittest', diff -uarN chromium-43.0.2357.65.orig/content/public/common/content_switches.cc chromium-43.0.2357.65/content/public/common/content_switches.cc --- chromium-43.0.2357.65.orig/content/public/common/content_switches.cc 2015-05-14 00:35:46.000000000 +0200 +++ chromium-43.0.2357.65/content/public/common/content_switches.cc 2015-05-21 11:41:29.283189983 +0200 @@ -935,7 +935,7 @@ // Disable web audio API. const char kDisableWebAudio[] = "disable-webaudio"; -#if defined(OS_CHROMEOS) +#if defined(OS_CHROMEOS) || defined(OS_LINUX) // Disables panel fitting (used for mirror mode). const char kDisablePanelFitting[] = "disable-panel-fitting"; diff -uarN chromium-43.0.2357.65.orig/content/public/common/content_switches.h chromium-43.0.2357.65/content/public/common/content_switches.h --- chromium-43.0.2357.65.orig/content/public/common/content_switches.h 2015-05-14 00:35:46.000000000 +0200 +++ chromium-43.0.2357.65/content/public/common/content_switches.h 2015-05-21 11:41:29.292191479 +0200 @@ -269,7 +269,7 @@ CONTENT_EXPORT extern const char kDisableWebAudio[]; -#if defined(OS_CHROMEOS) +#if defined(OS_CHROMEOS) || defined(OS_LINUX) CONTENT_EXPORT extern const char kDisablePanelFitting[]; CONTENT_EXPORT extern const char kDisableVaapiAcceleratedVideoEncode[]; #endif diff -uarN chromium-43.0.2357.65.orig/gpu/config/software_rendering_list_json.cc chromium-43.0.2357.65/gpu/config/software_rendering_list_json.cc --- chromium-43.0.2357.65.orig/gpu/config/software_rendering_list_json.cc 2015-05-14 00:35:46.000000000 +0200 +++ chromium-43.0.2357.65/gpu/config/software_rendering_list_json.cc 2015-05-21 11:41:29.293191645 +0200 @@ -481,17 +481,6 @@ ] }, { - "id": 48, - "description": "Accelerated video decode is unavailable on Linux", - "cr_bugs": [137247], - "os": { - "type": "linux" - }, - "features": [ - "accelerated_video_decode" - ] - }, - { "id": 49, "description": "NVidia GeForce GT 650M can cause the system to hang with flash 3D", "cr_bugs": [140175], @@ -1056,6 +1045,11 @@ "os": { "type": "android" } + }, + { + "os": { + "type": "linux" + } } ], "features": [ diff -uarN chromium-43.0.2357.65.orig/media/media.gyp chromium-43.0.2357.65/media/media.gyp --- chromium-43.0.2357.65.orig/media/media.gyp 2015-05-14 00:35:46.000000000 +0200 +++ chromium-43.0.2357.65/media/media.gyp 2015-05-21 11:41:29.294191811 +0200 @@ -739,7 +739,7 @@ ], }], # For VaapiVideoEncodeAccelerator. - ['target_arch != "arm" and chromeos == 1', { + ['target_arch != "arm" and (chromeos == 1 or desktop_linux == 1)', { 'sources': [ 'filters/h264_bitstream_buffer.cc', 'filters/h264_bitstream_buffer.h',