Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Unified Diff: content/common/gpu/media/vaapi_drm_picture.cc

Issue 1422563002: [Ozone] Enables overlay render format setting path and by default use UYVY (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/vaapi_drm_picture.cc
diff --git a/content/common/gpu/media/vaapi_drm_picture.cc b/content/common/gpu/media/vaapi_drm_picture.cc
index d344a1b5138a97c986e13709283e2bce9fb1e18b..dfa4124eaa5ca53fda215d95bd90b63a01ee7111 100644
--- a/content/common/gpu/media/vaapi_drm_picture.cc
+++ b/content/common/gpu/media/vaapi_drm_picture.cc
@@ -17,6 +17,37 @@
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/surface_factory_ozone.h"
+namespace {
+// We decode video into YUV420, but for usage with GLImages we have to convert
+// to BGRX_8888.
+const gfx::BufferFormat kPictureForGLImageFormat = gfx::BufferFormat::BGRX_8888;
+
+uint32_t BufferFormatToVAFourCC(gfx::BufferFormat fmt) {
+ switch (fmt) {
+ case gfx::BufferFormat::BGRX_8888:
+ return VA_FOURCC_BGRX;
+ case gfx::BufferFormat::UYVY_422:
+ return VA_FOURCC_UYVY;
+ default:
+ NOTREACHED();
+ return 0;
+ }
+}
+
+uint32_t BufferFormatToVARTFormat(gfx::BufferFormat fmt) {
+ switch (fmt) {
+ case gfx::BufferFormat::UYVY_422:
+ return VA_RT_FORMAT_YUV422;
+ case gfx::BufferFormat::BGRX_8888:
+ return VA_RT_FORMAT_RGB32;
+ default:
+ NOTREACHED();
+ return 0;
+ }
+}
+
+} // namespace
+
namespace content {
VaapiDrmPicture::VaapiDrmPicture(
@@ -54,7 +85,8 @@ scoped_refptr<VASurface> VaapiDrmPicture::CreateVASurfaceForPixmap(
// Create a VASurface out of the created buffer using the dmabuf.
VASurfaceAttribExternalBuffers va_attrib_extbuf;
memset(&va_attrib_extbuf, 0, sizeof(va_attrib_extbuf));
- va_attrib_extbuf.pixel_format = VA_FOURCC_BGRX;
+ va_attrib_extbuf.pixel_format =
+ BufferFormatToVAFourCC(pixmap->GetBufferFormat());
va_attrib_extbuf.width = pixmap_size.width();
va_attrib_extbuf.height = pixmap_size.height();
va_attrib_extbuf.data_size = pixmap_size.height() * dmabuf_pitch;
@@ -80,7 +112,8 @@ scoped_refptr<VASurface> VaapiDrmPicture::CreateVASurfaceForPixmap(
va_attribs[1].value.value.p = &va_attrib_extbuf;
scoped_refptr<VASurface> va_surface = vaapi_wrapper_->CreateUnownedSurface(
- VA_RT_FORMAT_RGB32, pixmap_size, va_attribs);
+ BufferFormatToVARTFormat(pixmap->GetBufferFormat()), pixmap_size,
+ va_attribs);
if (!va_surface) {
LOG(ERROR) << "Failed to create VASurface for an Ozone NativePixmap";
return nullptr;
@@ -90,13 +123,13 @@ scoped_refptr<VASurface> VaapiDrmPicture::CreateVASurfaceForPixmap(
}
scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CreateNativePixmap(
- gfx::Size size) {
+ gfx::Size size,
+ gfx::BufferFormat format) {
ui::OzonePlatform* platform = ui::OzonePlatform::GetInstance();
ui::SurfaceFactoryOzone* factory = platform->GetSurfaceFactoryOzone();
// Create a buffer from Ozone.
- return factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size,
- gfx::BufferFormat::BGRX_8888,
+ return factory->CreateNativePixmap(gfx::kNullAcceleratedWidget, size, format,
gfx::BufferUsage::SCANOUT);
}
@@ -104,7 +137,7 @@ bool VaapiDrmPicture::Initialize() {
// We want to create a VASurface and an EGLImage out of the same
// memory buffer, so we can output decoded pictures to it using
// VAAPI and also use it to paint with GL.
- pixmap_ = CreateNativePixmap(size());
+ pixmap_ = CreateNativePixmap(size(), kPictureForGLImageFormat);
if (!pixmap_) {
LOG(ERROR) << "Failed creating an Ozone NativePixmap";
return false;
@@ -117,10 +150,10 @@ bool VaapiDrmPicture::Initialize() {
}
// Weak pointers can only bind to methods without return values,
- // hence we cannot bind ScalePixmap here. Instead we use a
+ // hence we cannot bind ProcessPixmap here. Instead we use a
// static function to solve this problem.
- pixmap_->SetScalingCallback(base::Bind(&VaapiDrmPicture::CallScalePixmap,
- weak_this_factory_.GetWeakPtr()));
+ pixmap_->SetProcessingCallback(base::Bind(&VaapiDrmPicture::CallProcessPixmap,
+ weak_this_factory_.GetWeakPtr()));
if (!make_context_current_.Run())
return false;
@@ -129,7 +162,7 @@ bool VaapiDrmPicture::Initialize() {
texture_id());
scoped_refptr<gfx::GLImageOzoneNativePixmap> image(
new gfx::GLImageOzoneNativePixmap(size(), GL_BGRA_EXT));
- if (!image->Initialize(pixmap_.get(), gfx::BufferFormat::BGRX_8888)) {
+ if (!image->Initialize(pixmap_.get())) {
LOG(ERROR) << "Failed to create GLImage";
return false;
}
@@ -148,45 +181,51 @@ bool VaapiDrmPicture::DownloadFromSurface(
}
// static
-scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CallScalePixmap(
+scoped_refptr<ui::NativePixmap> VaapiDrmPicture::CallProcessPixmap(
base::WeakPtr<VaapiDrmPicture> weak_ptr,
- gfx::Size new_size) {
+ gfx::Size target_size,
+ gfx::BufferFormat target_format) {
if (!weak_ptr.get()) {
- LOG(ERROR) << "Failed scaling NativePixmap as scaling "
+ LOG(ERROR) << "Failed processing NativePixmap as processing "
"unit(VaapiDrmPicture) is deleted";
return nullptr;
}
- return weak_ptr->ScalePixmap(new_size);
+ return weak_ptr->ProcessPixmap(target_size, target_format);
}
-scoped_refptr<ui::NativePixmap> VaapiDrmPicture::ScalePixmap(
- gfx::Size new_size) {
- if (!scaled_va_surface_.get() || scaled_va_surface_->size() != new_size) {
- scaled_pixmap_ = CreateNativePixmap(new_size);
- if (!scaled_pixmap_) {
- LOG(ERROR) << "Failed creating an Ozone NativePixmap for scaling";
- scaled_va_surface_ = nullptr;
+scoped_refptr<ui::NativePixmap> VaapiDrmPicture::ProcessPixmap(
+ gfx::Size target_size,
+ gfx::BufferFormat target_format) {
+ if (!processed_va_surface_.get() ||
+ processed_va_surface_->size() != target_size ||
+ processed_va_surface_->format() !=
+ BufferFormatToVARTFormat(target_format)) {
+ processed_pixmap_ = CreateNativePixmap(target_size, target_format);
+ if (!processed_pixmap_) {
+ LOG(ERROR) << "Failed creating an Ozone NativePixmap for processing";
+ processed_va_surface_ = nullptr;
return nullptr;
}
- scaled_va_surface_ = CreateVASurfaceForPixmap(scaled_pixmap_, new_size);
- if (!scaled_va_surface_) {
+ processed_va_surface_ =
+ CreateVASurfaceForPixmap(processed_pixmap_, target_size);
+ if (!processed_va_surface_) {
LOG(ERROR) << "Failed creating VA Surface for pixmap";
- scaled_pixmap_ = nullptr;
+ processed_pixmap_ = nullptr;
return nullptr;
}
}
- DCHECK(scaled_pixmap_);
+ DCHECK(processed_pixmap_);
bool vpp_result =
- vaapi_wrapper_->BlitSurface(va_surface_, scaled_va_surface_);
+ vaapi_wrapper_->BlitSurface(va_surface_, processed_va_surface_);
if (!vpp_result) {
LOG(ERROR) << "Failed scaling NativePixmap";
- scaled_pixmap_ = nullptr;
- scaled_va_surface_ = nullptr;
+ processed_pixmap_ = nullptr;
+ processed_va_surface_ = nullptr;
return nullptr;
}
- return scaled_pixmap_;
+ return processed_pixmap_;
}
scoped_refptr<gl::GLImage> VaapiDrmPicture::GetImageToBind() {
« no previous file with comments | « content/common/gpu/media/vaapi_drm_picture.h ('k') | content/common/gpu/media/vaapi_video_decode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698