Index: content/common/gpu/media/vaapi_wrapper.cc |
diff --git a/content/common/gpu/media/vaapi_wrapper.cc b/content/common/gpu/media/vaapi_wrapper.cc |
index 5e93b994db02dcf52301327e0c285b82a148e001..9a092e1c7c5ee17dead6e91d7878c61f608785a5 100644 |
--- a/content/common/gpu/media/vaapi_wrapper.cc |
+++ b/content/common/gpu/media/vaapi_wrapper.cc |
@@ -14,13 +14,21 @@ |
#include "content/common/gpu/media/va_stubs.h" |
#include "third_party/libyuv/include/libyuv.h" |
+#if defined(USE_X11) |
using content_common_gpu_media::kModuleVa; |
+#else |
+using content_common_gpu_media::kModuleVa_drm; |
+#endif |
using content_common_gpu_media::InitializeStubs; |
using content_common_gpu_media::StubPathMap; |
// libva-x11 depends on libva, so dlopen libva-x11 is enough |
static const base::FilePath::CharType kVaLib[] = |
+#if defined(USE_X11) |
FILE_PATH_LITERAL("libva-x11.so.1"); |
+#else |
+ FILE_PATH_LITERAL("libva-drm.so.1"); |
+#endif |
#define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \ |
do { \ |
@@ -128,12 +136,16 @@ VaapiWrapper::~VaapiWrapper() { |
scoped_ptr<VaapiWrapper> VaapiWrapper::Create( |
CodecMode mode, |
media::VideoCodecProfile profile, |
- Display* x_display, |
+#if defined(USE_X11) |
+ Display* display, |
+#else |
+ int display, |
+#endif |
const base::Closure& report_error_to_uma_cb) { |
scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); |
if (!vaapi_wrapper->Initialize( |
- mode, profile, x_display, report_error_to_uma_cb)) |
+ mode, profile, display, report_error_to_uma_cb)) |
vaapi_wrapper.reset(); |
return vaapi_wrapper.Pass(); |
@@ -153,7 +165,11 @@ void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { |
bool VaapiWrapper::Initialize(CodecMode mode, |
media::VideoCodecProfile profile, |
+#if defined(USE_X11) |
Display* x_display, |
+#else |
+ int display, |
+#endif |
const base::Closure& report_error_to_uma_cb) { |
static bool vaapi_functions_initialized = PostSandboxInitialization(); |
if (!vaapi_functions_initialized) { |
@@ -164,8 +180,11 @@ bool VaapiWrapper::Initialize(CodecMode mode, |
report_error_to_uma_cb_ = report_error_to_uma_cb; |
base::AutoLock auto_lock(va_lock_); |
- |
+#if defined(USE_X11) |
va_display_ = vaGetDisplay(x_display); |
+#else |
+ va_display_ = vaGetDisplayDRM(display); |
+#endif |
if (!vaDisplayIsValid(va_display_)) { |
DVLOG(1) << "Could not get a valid VA display"; |
return false; |
@@ -506,6 +525,7 @@ bool VaapiWrapper::ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id) { |
return result; |
} |
+#if defined(USE_X11) |
bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
Pixmap x_pixmap, |
gfx::Size dest_size) { |
@@ -524,6 +544,63 @@ bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
VA_SUCCESS_OR_RETURN(va_res, "Failed putting surface to pixmap", false); |
return true; |
} |
+#else |
+bool VaapiWrapper::CreateRGBImage(gfx::Size size, VAImage* image) { |
+ base::AutoLock auto_lock(va_lock_); |
+ VAStatus va_res; |
+ VAImageFormat format; |
+ format.fourcc = VA_FOURCC_RGBX; |
+ format.byte_order = VA_LSB_FIRST; |
+ format.bits_per_pixel = 32; |
+ format.depth = 24; |
+ format.red_mask = 0xff; |
+ format.green_mask = 0xff00; |
+ format.blue_mask = 0xff0000; |
+ format.alpha_mask = 0; |
+ va_res = vaCreateImage(va_display_, |
+ &format, |
+ size.width(), |
+ size.height(), |
+ image); |
+ VA_SUCCESS_OR_RETURN(va_res, "Failed to create image", false); |
+ return true; |
+} |
+ |
+void VaapiWrapper::DestroyImage(VAImage* image) { |
+ base::AutoLock auto_lock(va_lock_); |
+ vaDestroyImage(va_display_, image->image_id); |
+} |
+ |
+bool VaapiWrapper::MapImage(VAImage* image, void** buffer) { |
+ base::AutoLock auto_lock(va_lock_); |
+ |
+ VAStatus va_res = vaMapBuffer(va_display_, image->buf, buffer); |
+ VA_SUCCESS_OR_RETURN(va_res, "Failed to map image", false); |
+ return true; |
+} |
+ |
+void VaapiWrapper::UnmapImage(VAImage* image) { |
+ base::AutoLock auto_lock(va_lock_); |
+ vaUnmapBuffer(va_display_, image->buf); |
+} |
+ |
+bool VaapiWrapper::PutSurfaceIntoImage(VASurfaceID va_surface_id, |
+ VAImage* image) { |
+ base::AutoLock auto_lock(va_lock_); |
+ VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); |
+ VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
+ |
+ va_res = vaGetImage(va_display_, |
+ va_surface_id, |
+ 0, |
+ 0, |
+ image->width, |
+ image->height, |
+ image->image_id); |
+ VA_SUCCESS_OR_RETURN(va_res, "Failed to put surface into image", false); |
+ return true; |
+} |
+#endif |
bool VaapiWrapper::GetVaImageForTesting(VASurfaceID va_surface_id, |
VAImage* image, |
@@ -668,7 +745,11 @@ bool VaapiWrapper::DownloadAndDestroyCodedBuffer(VABufferID buffer_id, |
// static |
bool VaapiWrapper::PostSandboxInitialization() { |
StubPathMap paths; |
+#if defined(USE_X11) |
paths[kModuleVa].push_back(kVaLib); |
+#else |
+ paths[kModuleVa_drm].push_back(kVaLib); |
+#endif |
return InitializeStubs(paths); |
} |