OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/gpu/media/vaapi_wrapper.h" | 5 #include "content/common/gpu/media/vaapi_wrapper.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #if defined (USE_OZONE) |
| 9 #include <wayland-client.h> |
| 10 #endif |
8 | 11 |
9 #include "base/bind.h" | 12 #include "base/bind.h" |
10 #include "base/logging.h" | 13 #include "base/logging.h" |
11 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
12 // Auto-generated for dlopen libva libraries | 15 // Auto-generated for dlopen libva libraries |
13 #include "content/common/gpu/media/va_stubs.h" | 16 #include "content/common/gpu/media/va_stubs.h" |
14 | 17 |
| 18 #if defined (USE_OZONE) |
| 19 #include "third_party/libva/va/wayland/va_wayland.h" |
| 20 |
| 21 using content_common_gpu_media::kModuleVa_wayland; |
| 22 #else |
15 using content_common_gpu_media::kModuleVa; | 23 using content_common_gpu_media::kModuleVa; |
| 24 #endif |
16 using content_common_gpu_media::InitializeStubs; | 25 using content_common_gpu_media::InitializeStubs; |
17 using content_common_gpu_media::StubPathMap; | 26 using content_common_gpu_media::StubPathMap; |
18 | 27 |
19 // libva-x11 depends on libva, so dlopen libva-x11 is enough | 28 // libva-x11 depends on libva, so dlopen libva-x11 is enough |
20 static const base::FilePath::CharType kVaLib[] = | 29 static const base::FilePath::CharType kVaLib[] = |
| 30 #if defined (USE_OZONE) |
| 31 FILE_PATH_LITERAL("libva-wayland.so.1"); |
| 32 #else |
21 FILE_PATH_LITERAL("libva-x11.so.1"); | 33 FILE_PATH_LITERAL("libva-x11.so.1"); |
| 34 #endif |
22 | 35 |
23 #define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \ | 36 #define LOG_VA_ERROR_AND_REPORT(va_error, err_msg) \ |
24 do { \ | 37 do { \ |
25 DVLOG(1) << err_msg \ | 38 DVLOG(1) << err_msg \ |
26 << " VA error: " << vaErrorStr(va_error); \ | 39 << " VA error: " << vaErrorStr(va_error); \ |
27 report_error_to_uma_cb_.Run(); \ | 40 report_error_to_uma_cb_.Run(); \ |
28 } while (0) | 41 } while (0) |
29 | 42 |
30 #define VA_LOG_ON_ERROR(va_error, err_msg) \ | 43 #define VA_LOG_ON_ERROR(va_error, err_msg) \ |
31 do { \ | 44 do { \ |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 118 } |
106 | 119 |
107 VaapiWrapper::~VaapiWrapper() { | 120 VaapiWrapper::~VaapiWrapper() { |
108 DestroyPendingBuffers(); | 121 DestroyPendingBuffers(); |
109 DestroySurfaces(); | 122 DestroySurfaces(); |
110 Deinitialize(); | 123 Deinitialize(); |
111 } | 124 } |
112 | 125 |
113 scoped_ptr<VaapiWrapper> VaapiWrapper::Create( | 126 scoped_ptr<VaapiWrapper> VaapiWrapper::Create( |
114 media::VideoCodecProfile profile, | 127 media::VideoCodecProfile profile, |
115 Display* x_display, | 128 void* display, |
116 const base::Closure& report_error_to_uma_cb) { | 129 const base::Closure& report_error_to_uma_cb) { |
117 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); | 130 scoped_ptr<VaapiWrapper> vaapi_wrapper(new VaapiWrapper()); |
118 | 131 |
119 if (!vaapi_wrapper->Initialize(profile, x_display, report_error_to_uma_cb)) | 132 if (!vaapi_wrapper->Initialize(profile, display, report_error_to_uma_cb)) |
120 vaapi_wrapper.reset(); | 133 vaapi_wrapper.reset(); |
121 | 134 |
122 return vaapi_wrapper.Pass(); | 135 return vaapi_wrapper.Pass(); |
123 } | 136 } |
124 | 137 |
125 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { | 138 void VaapiWrapper::TryToSetVADisplayAttributeToLocalGPU() { |
126 VADisplayAttribute item = {VADisplayAttribRenderMode, | 139 VADisplayAttribute item = {VADisplayAttribRenderMode, |
127 1, // At least support '_LOCAL_OVERLAY'. | 140 1, // At least support '_LOCAL_OVERLAY'. |
128 -1, // The maximum possible support 'ALL'. | 141 -1, // The maximum possible support 'ALL'. |
129 VA_RENDER_MODE_LOCAL_GPU, | 142 VA_RENDER_MODE_LOCAL_GPU, |
130 VA_DISPLAY_ATTRIB_SETTABLE}; | 143 VA_DISPLAY_ATTRIB_SETTABLE}; |
131 | 144 |
132 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1); | 145 VAStatus va_res = vaSetDisplayAttributes(va_display_, &item, 1); |
133 if (va_res != VA_STATUS_SUCCESS) | 146 if (va_res != VA_STATUS_SUCCESS) |
134 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default."; | 147 DVLOG(2) << "vaSetDisplayAttributes unsupported, ignoring by default."; |
135 } | 148 } |
136 | 149 |
137 bool VaapiWrapper::Initialize(media::VideoCodecProfile profile, | 150 bool VaapiWrapper::Initialize(media::VideoCodecProfile profile, |
138 Display* x_display, | 151 void* display, |
139 const base::Closure& report_error_to_uma_cb) { | 152 const base::Closure& report_error_to_uma_cb) { |
140 static bool vaapi_functions_initialized = PostSandboxInitialization(); | 153 static bool vaapi_functions_initialized = PostSandboxInitialization(); |
141 if (!vaapi_functions_initialized) { | 154 if (!vaapi_functions_initialized) { |
142 DVLOG(1) << "Failed to initialize VAAPI libs"; | 155 DVLOG(1) << "Failed to initialize VAAPI libs"; |
143 return false; | 156 return false; |
144 } | 157 } |
145 | 158 |
146 report_error_to_uma_cb_ = report_error_to_uma_cb; | 159 report_error_to_uma_cb_ = report_error_to_uma_cb; |
147 | 160 |
148 base::AutoLock auto_lock(va_lock_); | 161 base::AutoLock auto_lock(va_lock_); |
149 | 162 #if defined (USE_OZONE) |
150 va_display_ = vaGetDisplay(x_display); | 163 va_display_ = vaGetDisplayWl(static_cast<wl_display *>(display)); |
| 164 #else |
| 165 va_display_ = vaGetDisplay(static_cast<Display *>(display)); |
| 166 #endif |
151 if (!vaDisplayIsValid(va_display_)) { | 167 if (!vaDisplayIsValid(va_display_)) { |
152 DVLOG(1) << "Could not get a valid VA display"; | 168 DVLOG(1) << "Could not get a valid VA display"; |
153 return false; | 169 return false; |
154 } | 170 } |
155 | 171 |
156 VAStatus va_res = vaInitialize(va_display_, &major_version_, &minor_version_); | 172 VAStatus va_res = vaInitialize(va_display_, &major_version_, &minor_version_); |
157 VA_SUCCESS_OR_RETURN(va_res, "vaInitialize failed", false); | 173 VA_SUCCESS_OR_RETURN(va_res, "vaInitialize failed", false); |
158 DVLOG(1) << "VAAPI version: " << major_version_ << "." << minor_version_; | 174 DVLOG(1) << "VAAPI version: " << major_version_ << "." << minor_version_; |
159 | 175 |
160 if (VAAPIVersionLessThan(0, 34)) { | 176 if (VAAPIVersionLessThan(0, 34)) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 VA_SUCCESS_OR_RETURN(va_res, "vaEndPicture failed", false); | 371 VA_SUCCESS_OR_RETURN(va_res, "vaEndPicture failed", false); |
356 | 372 |
357 return true; | 373 return true; |
358 } | 374 } |
359 | 375 |
360 bool VaapiWrapper::DecodeAndDestroyPendingBuffers(VASurfaceID va_surface_id) { | 376 bool VaapiWrapper::DecodeAndDestroyPendingBuffers(VASurfaceID va_surface_id) { |
361 bool result = SubmitDecode(va_surface_id); | 377 bool result = SubmitDecode(va_surface_id); |
362 DestroyPendingBuffers(); | 378 DestroyPendingBuffers(); |
363 return result; | 379 return result; |
364 } | 380 } |
| 381 #if defined (USE_OZONE) |
| 382 bool VaapiWrapper::CreateRGBImage(gfx::Size size, VAImage* image) { |
| 383 base::AutoLock auto_lock(va_lock_); |
| 384 VAStatus va_res; |
| 385 VAImageFormat format; |
| 386 format.fourcc = VA_FOURCC_RGBX; |
| 387 format.byte_order = VA_LSB_FIRST; |
| 388 format.bits_per_pixel = 32; |
| 389 format.depth = 24; |
| 390 format.red_mask = 0xff; |
| 391 format.green_mask = 0xff00; |
| 392 format.blue_mask = 0xff0000; |
| 393 format.alpha_mask = 0; |
| 394 va_res = vaCreateImage(va_display_, |
| 395 &format, |
| 396 size.width(), |
| 397 size.height(), |
| 398 image); |
| 399 VA_SUCCESS_OR_RETURN(va_res, "Failed to create image", false); |
| 400 return true; |
| 401 } |
365 | 402 |
| 403 void VaapiWrapper::DestroyImage(VAImage* image) { |
| 404 base::AutoLock auto_lock(va_lock_); |
| 405 vaDestroyImage(va_display_, image->image_id); |
| 406 } |
| 407 |
| 408 bool VaapiWrapper::MapImage(VAImage* image, void** buffer) { |
| 409 base::AutoLock auto_lock(va_lock_); |
| 410 |
| 411 VAStatus va_res = vaMapBuffer(va_display_, image->buf, buffer); |
| 412 VA_SUCCESS_OR_RETURN(va_res, "Failed to map image", false); |
| 413 return true; |
| 414 } |
| 415 |
| 416 void VaapiWrapper::UnmapImage(VAImage* image) { |
| 417 base::AutoLock auto_lock(va_lock_); |
| 418 vaUnmapBuffer(va_display_, image->buf); |
| 419 } |
| 420 |
| 421 bool VaapiWrapper::PutSurfaceIntoImage(VASurfaceID va_surface_id, |
| 422 VAImage* image) { |
| 423 base::AutoLock auto_lock(va_lock_); |
| 424 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); |
| 425 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
| 426 |
| 427 va_res = vaGetImage(va_display_, |
| 428 va_surface_id, |
| 429 0, |
| 430 0, |
| 431 image->width, |
| 432 image->height, |
| 433 image->image_id); |
| 434 VA_SUCCESS_OR_RETURN(va_res, "Failed to put surface into image", false); |
| 435 return true; |
| 436 } |
| 437 #else |
366 bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, | 438 bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
367 Pixmap x_pixmap, | 439 Pixmap x_pixmap, |
368 gfx::Size dest_size) { | 440 gfx::Size dest_size) { |
369 base::AutoLock auto_lock(va_lock_); | 441 base::AutoLock auto_lock(va_lock_); |
370 | 442 |
371 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); | 443 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); |
372 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); | 444 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
373 | 445 |
374 // Put the data into an X Pixmap. | 446 // Put the data into an X Pixmap. |
375 va_res = vaPutSurface(va_display_, | 447 va_res = vaPutSurface(va_display_, |
376 va_surface_id, | 448 va_surface_id, |
377 x_pixmap, | 449 x_pixmap, |
378 0, 0, dest_size.width(), dest_size.height(), | 450 0, 0, dest_size.width(), dest_size.height(), |
379 0, 0, dest_size.width(), dest_size.height(), | 451 0, 0, dest_size.width(), dest_size.height(), |
380 NULL, 0, 0); | 452 NULL, 0, 0); |
381 VA_SUCCESS_OR_RETURN(va_res, "Failed putting decode surface to pixmap", | 453 VA_SUCCESS_OR_RETURN(va_res, "Failed putting decode surface to pixmap", |
382 false); | 454 false); |
383 return true; | 455 return true; |
384 } | 456 } |
385 | 457 #endif |
386 bool VaapiWrapper::GetVaImageForTesting(VASurfaceID va_surface_id, | 458 bool VaapiWrapper::GetVaImageForTesting(VASurfaceID va_surface_id, |
387 VAImage* image, | 459 VAImage* image, |
388 void** mem) { | 460 void** mem) { |
389 base::AutoLock auto_lock(va_lock_); | 461 base::AutoLock auto_lock(va_lock_); |
390 | 462 |
391 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); | 463 VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); |
392 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); | 464 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false); |
393 | 465 |
394 // Derive a VAImage from the VASurface | 466 // Derive a VAImage from the VASurface |
395 va_res = vaDeriveImage(va_display_, va_surface_id, image); | 467 va_res = vaDeriveImage(va_display_, va_surface_id, image); |
(...skipping 14 matching lines...) Expand all Loading... |
410 void VaapiWrapper::ReturnVaImageForTesting(VAImage* image) { | 482 void VaapiWrapper::ReturnVaImageForTesting(VAImage* image) { |
411 base::AutoLock auto_lock(va_lock_); | 483 base::AutoLock auto_lock(va_lock_); |
412 | 484 |
413 vaUnmapBuffer(va_display_, image->buf); | 485 vaUnmapBuffer(va_display_, image->buf); |
414 vaDestroyImage(va_display_, image->image_id); | 486 vaDestroyImage(va_display_, image->image_id); |
415 } | 487 } |
416 | 488 |
417 // static | 489 // static |
418 bool VaapiWrapper::PostSandboxInitialization() { | 490 bool VaapiWrapper::PostSandboxInitialization() { |
419 StubPathMap paths; | 491 StubPathMap paths; |
| 492 #if defined (USE_OZONE) |
| 493 paths[kModuleVa_wayland].push_back(kVaLib); |
| 494 #else |
420 paths[kModuleVa].push_back(kVaLib); | 495 paths[kModuleVa].push_back(kVaLib); |
421 | 496 #endif |
422 return InitializeStubs(paths); | 497 return InitializeStubs(paths); |
423 } | 498 } |
424 | 499 |
425 } // namespace content | 500 } // namespace content |
OLD | NEW |