Commit 8580c222 authored by Julien Isorce's avatar Julien Isorce Committed by Commit Bot

Can select DRM(egl) or TFP(glx) at runtime for vaapi video decoding

Fixes overlap with https://chromium-review.googlesource.com/767375

Added unit test this time.

This is a preliminary step for the subsequent CL
https://chromium-review.googlesource.com/c/chromium/src/+/766787

Bug: 785201, 788123
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I70620697109fdef7d036be4c26fcecb763ddb4ba
Tests: media_unittests --gtest_filter=*Vaapi*SupportedPlatforms*
Reviewed-on: https://chromium-review.googlesource.com/788051Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Commit-Queue: Julien Isorce <julien.isorce@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519657}
parent 47135813
......@@ -8,10 +8,6 @@
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_implementation.h"
#if defined(USE_X11)
#include "media/gpu/vaapi/vaapi_tfp_picture.h"
#endif
namespace media {
VaapiPicture::VaapiPicture(
......
......@@ -6,16 +6,31 @@
#include "media/gpu/vaapi_wrapper.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_implementation.h"
#if defined(USE_OZONE)
#include "media/gpu/vaapi/vaapi_drm_picture.h"
#elif defined(USE_X11)
#if defined(USE_X11)
#include "media/gpu/vaapi/vaapi_tfp_picture.h"
#endif
namespace media {
namespace {
const struct {
gl::GLImplementation gl_impl;
VaapiPictureFactory::VaapiImplementation va_impl;
} kVaapiImplementationPairs[] = {{gl::kGLImplementationEGLGLES2,
VaapiPictureFactory::kVaapiImplementationDrm}
#if defined(USE_X11)
,
{gl::kGLImplementationDesktopGL,
VaapiPictureFactory::kVaapiImplementationX11}
#endif // USE_X11
};
} // namespace
VaapiPictureFactory::VaapiPictureFactory() = default;
VaapiPictureFactory::~VaapiPictureFactory() = default;
......@@ -28,28 +43,48 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create(
const gfx::Size& size,
uint32_t texture_id,
uint32_t client_texture_id) {
#if defined(USE_OZONE)
DCHECK_EQ(gl::kGLImplementationEGLGLES2, gl::GetGLImplementation());
return std::make_unique<VaapiDrmPicture>(
vaapi_wrapper, make_context_current_cb, bind_image_cb, picture_buffer_id,
size, texture_id, client_texture_id);
#elif defined(USE_X11)
DCHECK_EQ(gl::kGLImplementationDesktopGL, gl::GetGLImplementation());
return std::make_unique<VaapiTFPPicture>(
vaapi_wrapper, make_context_current_cb, bind_image_cb, picture_buffer_id,
size, texture_id, client_texture_id);
#else
#error Unsupported platform
#endif
std::unique_ptr<VaapiPicture> picture;
// Select DRM(egl) / TFP(glx) at runtime with --use-gl=egl / --use-gl=desktop
switch (GetVaapiImplementation(gl::GetGLImplementation())) {
case kVaapiImplementationDrm:
picture.reset(new VaapiDrmPicture(vaapi_wrapper, make_context_current_cb,
bind_image_cb, picture_buffer_id, size,
texture_id, client_texture_id));
break;
#if defined(USE_X11)
case kVaapiImplementationX11:
picture.reset(new VaapiTFPPicture(vaapi_wrapper, make_context_current_cb,
bind_image_cb, picture_buffer_id, size,
texture_id, client_texture_id));
break;
#endif // USE_X11
default:
NOTREACHED();
return nullptr;
}
return picture;
}
VaapiPictureFactory::VaapiImplementation
VaapiPictureFactory::GetVaapiImplementation(gl::GLImplementation gl_impl) {
for (const auto& implementation_pair : kVaapiImplementationPairs) {
if (gl_impl == implementation_pair.gl_impl)
return implementation_pair.va_impl;
}
return kVaapiImplementationNone;
}
uint32_t VaapiPictureFactory::GetGLTextureTarget() {
#if defined(USE_OZONE)
return GL_TEXTURE_EXTERNAL_OES;
#elif defined(USE_X11)
return GL_TEXTURE_2D;
#else
#error Unsupported platform
return GL_TEXTURE_2D;
#endif
}
......
......@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h"
#include "media/gpu/vaapi/vaapi_picture.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_implementation.h"
namespace media {
......@@ -19,6 +20,12 @@ class VaapiWrapper;
// Factory of platform dependent VaapiPictures.
class MEDIA_GPU_EXPORT VaapiPictureFactory {
public:
enum VaapiImplementation {
kVaapiImplementationNone = 0,
kVaapiImplementationDrm,
kVaapiImplementationX11
};
VaapiPictureFactory();
virtual ~VaapiPictureFactory();
......@@ -34,6 +41,10 @@ class MEDIA_GPU_EXPORT VaapiPictureFactory {
uint32_t texture_id,
uint32_t client_texture_id);
// Return the type of the VaapiPicture implementation for the given GL
// implementation.
VaapiImplementation GetVaapiImplementation(gl::GLImplementation gl_impl);
// Gets the texture target used to bind EGLImages (either GL_TEXTURE_2D on X11
// or GL_TEXTURE_EXTERNAL_OES on DRM).
uint32_t GetGLTextureTarget();
......
......@@ -322,6 +322,22 @@ TEST_P(VaapiVideoDecodeAcceleratorTest, QueueInputBufferAndDecodeFinished) {
ResetSequence();
}
// Verify that it is possible to select DRM(egl) and TFP(glx) at runtime.
TEST_P(VaapiVideoDecodeAcceleratorTest, SupportedPlatforms) {
EXPECT_EQ(VaapiPictureFactory::kVaapiImplementationNone,
mock_vaapi_picture_factory_->GetVaapiImplementation(
gl::kGLImplementationNone));
EXPECT_EQ(VaapiPictureFactory::kVaapiImplementationDrm,
mock_vaapi_picture_factory_->GetVaapiImplementation(
gl::kGLImplementationEGLGLES2));
#if defined(USE_X11)
EXPECT_EQ(VaapiPictureFactory::kVaapiImplementationX11,
mock_vaapi_picture_factory_->GetVaapiImplementation(
gl::kGLImplementationDesktopGL));
#endif
}
INSTANTIATE_TEST_CASE_P(/* No prefix. */,
VaapiVideoDecodeAcceleratorTest,
ValuesIn(kCodecProfiles));
......
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