Commit 0206e5d5 authored by Ted Meyer's avatar Ted Meyer Committed by Commit Bot

Add logic to determine which picture types need processor wrappers.

Bug: 1136730

R=andrescj

Change-Id: I60f2704313adfae0f76ce0d1c55e30051a48267b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2506770
Commit-Queue: Ted Meyer <tmathmeyer@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825284}
parent 6a08334d
...@@ -22,6 +22,25 @@ ...@@ -22,6 +22,25 @@
namespace media { namespace media {
namespace {
template <typename PictureType>
std::unique_ptr<VaapiPicture> CreateVaapiPictureNativeImpl(
scoped_refptr<VaapiWrapper> vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb,
const BindGLImageCallback& bind_image_cb,
const PictureBuffer& picture_buffer,
const gfx::Size& visible_size,
uint32_t client_texture_id,
uint32_t service_texture_id) {
return std::make_unique<PictureType>(
std::move(vaapi_wrapper), make_context_current_cb, bind_image_cb,
picture_buffer.id(), picture_buffer.size(), visible_size,
service_texture_id, client_texture_id, picture_buffer.texture_target());
}
} // namespace
VaapiPictureFactory::VaapiPictureFactory() { VaapiPictureFactory::VaapiPictureFactory() {
vaapi_impl_pairs_.insert( vaapi_impl_pairs_.insert(
std::make_pair(gl::kGLImplementationEGLGLES2, std::make_pair(gl::kGLImplementationEGLGLES2,
...@@ -36,6 +55,8 @@ VaapiPictureFactory::VaapiPictureFactory() { ...@@ -36,6 +55,8 @@ VaapiPictureFactory::VaapiPictureFactory() {
VaapiPictureFactory::kVaapiImplementationX11)); VaapiPictureFactory::kVaapiImplementationX11));
} }
#endif #endif
DeterminePictureCreationAndDownloadingMechanism();
} }
VaapiPictureFactory::~VaapiPictureFactory() = default; VaapiPictureFactory::~VaapiPictureFactory() = default;
...@@ -61,13 +82,6 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create( ...@@ -61,13 +82,6 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create(
: 0; : 0;
// Select DRM(egl) / TFP(glx) at runtime with --use-gl=egl / --use-gl=desktop // Select DRM(egl) / TFP(glx) at runtime with --use-gl=egl / --use-gl=desktop
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform())
return CreateVaapiPictureNativeForOzone(
vaapi_wrapper, make_context_current_cb, bind_image_cb, picture_buffer,
visible_size, client_texture_id, service_texture_id);
#endif
return CreateVaapiPictureNative(vaapi_wrapper, make_context_current_cb, return CreateVaapiPictureNative(vaapi_wrapper, make_context_current_cb,
bind_image_cb, picture_buffer, visible_size, bind_image_cb, picture_buffer, visible_size,
client_texture_id, service_texture_id); client_texture_id, service_texture_id);
...@@ -96,37 +110,62 @@ gfx::BufferFormat VaapiPictureFactory::GetBufferFormat() { ...@@ -96,37 +110,62 @@ gfx::BufferFormat VaapiPictureFactory::GetBufferFormat() {
return gfx::BufferFormat::RGBX_8888; return gfx::BufferFormat::RGBX_8888;
} }
#if defined(USE_OZONE) void VaapiPictureFactory::DeterminePictureCreationAndDownloadingMechanism() {
std::unique_ptr<VaapiPicture>
VaapiPictureFactory::CreateVaapiPictureNativeForOzone(
scoped_refptr<VaapiWrapper> vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb,
const BindGLImageCallback& bind_image_cb,
const PictureBuffer& picture_buffer,
const gfx::Size& visible_size,
uint32_t client_texture_id,
uint32_t service_texture_id) {
DCHECK(features::IsUsingOzonePlatform());
switch (GetVaapiImplementation(gl::GetGLImplementation())) { switch (GetVaapiImplementation(gl::GetGLImplementation())) {
#if defined(USE_OZONE)
// We can be called without GL initialized, which is valid if we use Ozone. // We can be called without GL initialized, which is valid if we use Ozone.
case kVaapiImplementationNone: case kVaapiImplementationNone:
FALLTHROUGH; if (features::IsUsingOzonePlatform()) {
create_picture_cb_ = base::BindRepeating(
&CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapOzone>);
needs_vpp_for_downloading_ = true;
}
// This is reached by unit tests which don't require create_picture_cb_
// to be initialized or called.
break;
#endif // defined(USE_OZONE)
#if defined(USE_X11)
case kVaapiImplementationX11:
DCHECK(!features::IsUsingOzonePlatform());
create_picture_cb_ =
base::BindRepeating(&CreateVaapiPictureNativeImpl<VaapiTFPPicture>);
// Neither VaapiTFPPicture or VaapiPictureNativePixmapAngle needs the VPP.
needs_vpp_for_downloading_ = false;
break;
case kVaapiImplementationAngle:
DCHECK(!features::IsUsingOzonePlatform());
create_picture_cb_ = base::BindRepeating(
&CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapAngle>);
// Neither VaapiTFPPicture or VaapiPictureNativePixmapAngle needs the VPP.
needs_vpp_for_downloading_ = false;
break;
#endif // defined(USE_X11)
case kVaapiImplementationDrm: case kVaapiImplementationDrm:
return std::make_unique<VaapiPictureNativePixmapOzone>( #if defined(USE_OZONE)
std::move(vaapi_wrapper), make_context_current_cb, bind_image_cb, if (features::IsUsingOzonePlatform()) {
picture_buffer.id(), picture_buffer.size(), visible_size, create_picture_cb_ = base::BindRepeating(
service_texture_id, client_texture_id, &CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapOzone>);
picture_buffer.texture_target()); needs_vpp_for_downloading_ = true;
break; break;
}
#endif // defined(USE_OZONE)
#if defined(USE_EGL)
create_picture_cb_ = base::BindRepeating(
&CreateVaapiPictureNativeImpl<VaapiPictureNativePixmapEgl>);
needs_vpp_for_downloading_ = true;
break;
#endif // defined(USE_EGL)
// ozone or egl must be used to use the DRM implementation.
NOTREACHED();
default: default:
NOTREACHED(); NOTREACHED();
return nullptr;
} }
}
return nullptr; bool VaapiPictureFactory::NeedsProcessingPipelineForDownloading() const {
return needs_vpp_for_downloading_;
} }
#endif // USE_OZONE
std::unique_ptr<VaapiPicture> VaapiPictureFactory::CreateVaapiPictureNative( std::unique_ptr<VaapiPicture> VaapiPictureFactory::CreateVaapiPictureNative(
scoped_refptr<VaapiWrapper> vaapi_wrapper, scoped_refptr<VaapiWrapper> vaapi_wrapper,
...@@ -136,40 +175,10 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::CreateVaapiPictureNative( ...@@ -136,40 +175,10 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::CreateVaapiPictureNative(
const gfx::Size& visible_size, const gfx::Size& visible_size,
uint32_t client_texture_id, uint32_t client_texture_id,
uint32_t service_texture_id) { uint32_t service_texture_id) {
switch (GetVaapiImplementation(gl::GetGLImplementation())) { CHECK(create_picture_cb_);
#if defined(USE_EGL) return create_picture_cb_.Run(
case kVaapiImplementationDrm:
return std::make_unique<VaapiPictureNativePixmapEgl>(
std::move(vaapi_wrapper), make_context_current_cb, bind_image_cb, std::move(vaapi_wrapper), make_context_current_cb, bind_image_cb,
picture_buffer.id(), picture_buffer.size(), visible_size, picture_buffer, visible_size, client_texture_id, service_texture_id);
service_texture_id, client_texture_id,
picture_buffer.texture_target());
#endif // USE_EGL
#if defined(USE_X11)
case kVaapiImplementationX11:
DCHECK(!features::IsUsingOzonePlatform());
return std::make_unique<VaapiTFPPicture>(
std::move(vaapi_wrapper), make_context_current_cb, bind_image_cb,
picture_buffer.id(), picture_buffer.size(), visible_size,
service_texture_id, client_texture_id,
picture_buffer.texture_target());
break;
case kVaapiImplementationAngle:
return std::make_unique<VaapiPictureNativePixmapAngle>(
std::move(vaapi_wrapper), make_context_current_cb, bind_image_cb,
picture_buffer.id(), picture_buffer.size(), visible_size,
service_texture_id, client_texture_id,
picture_buffer.texture_target());
break;
#endif // USE_X11
default:
NOTREACHED();
return nullptr;
}
return nullptr;
} }
} // namespace media } // namespace media
...@@ -18,6 +18,15 @@ namespace media { ...@@ -18,6 +18,15 @@ namespace media {
class PictureBuffer; class PictureBuffer;
class VaapiWrapper; class VaapiWrapper;
using CreatePictureCB = base::RepeatingCallback<std::unique_ptr<VaapiPicture>(
scoped_refptr<VaapiWrapper>,
const MakeGLContextCurrentCallback&,
const BindGLImageCallback&,
const PictureBuffer&,
const gfx::Size&,
uint32_t,
uint32_t)>;
// Factory of platform dependent VaapiPictures. // Factory of platform dependent VaapiPictures.
class MEDIA_GPU_EXPORT VaapiPictureFactory { class MEDIA_GPU_EXPORT VaapiPictureFactory {
public: public:
...@@ -44,6 +53,10 @@ class MEDIA_GPU_EXPORT VaapiPictureFactory { ...@@ -44,6 +53,10 @@ class MEDIA_GPU_EXPORT VaapiPictureFactory {
// implementation. // implementation.
VaapiImplementation GetVaapiImplementation(gl::GLImplementation gl_impl); VaapiImplementation GetVaapiImplementation(gl::GLImplementation gl_impl);
// Determines whether the DownloadFromSurface() method of the VaapiPictures
// created by this factory requires a processing pipeline VaapiWrapper.
bool NeedsProcessingPipelineForDownloading() const;
// Gets the texture target used to bind EGLImages (either GL_TEXTURE_2D on X11 // Gets the texture target used to bind EGLImages (either GL_TEXTURE_2D on X11
// or GL_TEXTURE_EXTERNAL_OES on DRM). // or GL_TEXTURE_EXTERNAL_OES on DRM).
uint32_t GetGLTextureTarget(); uint32_t GetGLTextureTarget();
...@@ -52,17 +65,6 @@ class MEDIA_GPU_EXPORT VaapiPictureFactory { ...@@ -52,17 +65,6 @@ class MEDIA_GPU_EXPORT VaapiPictureFactory {
// the format decoded frames in VASurfaces are converted into. // the format decoded frames in VASurfaces are converted into.
gfx::BufferFormat GetBufferFormat(); gfx::BufferFormat GetBufferFormat();
#if defined(USE_OZONE)
std::unique_ptr<VaapiPicture> CreateVaapiPictureNativeForOzone(
scoped_refptr<VaapiWrapper> vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb,
const BindGLImageCallback& bind_image_cb,
const PictureBuffer& picture_buffer,
const gfx::Size& visible_size,
uint32_t client_texture_id,
uint32_t service_texture_id);
#endif
std::unique_ptr<VaapiPicture> CreateVaapiPictureNative( std::unique_ptr<VaapiPicture> CreateVaapiPictureNative(
scoped_refptr<VaapiWrapper> vaapi_wrapper, scoped_refptr<VaapiWrapper> vaapi_wrapper,
const MakeGLContextCurrentCallback& make_context_current_cb, const MakeGLContextCurrentCallback& make_context_current_cb,
...@@ -76,6 +78,11 @@ class MEDIA_GPU_EXPORT VaapiPictureFactory { ...@@ -76,6 +78,11 @@ class MEDIA_GPU_EXPORT VaapiPictureFactory {
vaapi_impl_pairs_; vaapi_impl_pairs_;
private: private:
void DeterminePictureCreationAndDownloadingMechanism();
CreatePictureCB create_picture_cb_;
bool needs_vpp_for_downloading_ = false;
DISALLOW_COPY_AND_ASSIGN(VaapiPictureFactory); DISALLOW_COPY_AND_ASSIGN(VaapiPictureFactory);
}; };
......
...@@ -699,14 +699,13 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers( ...@@ -699,14 +699,13 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers(
std::vector<VASurfaceID> va_surface_ids; std::vector<VASurfaceID> va_surface_ids;
scoped_refptr<VaapiWrapper> vaapi_wrapper_for_picture = vaapi_wrapper_; scoped_refptr<VaapiWrapper> vaapi_wrapper_for_picture = vaapi_wrapper_;
// The X11/ANGLE implementation can use |vaapi_wrapper_| to copy from an const bool requires_vpp =
// internal libva buffer into an X Pixmap without having to use a processing vaapi_picture_factory_->NeedsProcessingPipelineForDownloading();
// wrapper. // If we aren't in BufferAllocationMode::kNone mode and the VaapiPicture
#if !defined(USE_X11) // implementation we get from |vaapi_picture_factory_| requires the video
// If we aren't in BufferAllocationMode::kNone, we have to allocate a // processing pipeline for downloading the decoded frame from the internal
// |vpp_vaapi_wrapper_| for VaapiPicture to DownloadFromSurface() the VA's // surface, we need to create a |vpp_vaapi_wrapper_|.
// internal decoded frame. if (requires_vpp && buffer_allocation_mode_ != BufferAllocationMode::kNone) {
if (buffer_allocation_mode_ != BufferAllocationMode::kNone) {
if (!vpp_vaapi_wrapper_) { if (!vpp_vaapi_wrapper_) {
vpp_vaapi_wrapper_ = VaapiWrapper::Create( vpp_vaapi_wrapper_ = VaapiWrapper::Create(
VaapiWrapper::kVideoProcess, VAProfileNone, VaapiWrapper::kVideoProcess, VAProfileNone,
...@@ -724,8 +723,6 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers( ...@@ -724,8 +723,6 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers(
vaapi_wrapper_for_picture = vpp_vaapi_wrapper_; vaapi_wrapper_for_picture = vpp_vaapi_wrapper_;
} }
#endif // !defined(USE_X11)
for (size_t i = 0; i < buffers.size(); ++i) { for (size_t i = 0; i < buffers.size(); ++i) {
// TODO(b/139460315): Create with buffers[i] once the AMD driver issue is // TODO(b/139460315): Create with buffers[i] once the AMD driver issue is
// resolved. // resolved.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment