Commit 40c1c95a authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

X11 and Ozone: cleanup //media for use_x11 && use_ozone build.

We need to avoid using non-Ozone/X11 code when OzonePlatform feature
is enabled for Linux once use_x11 && use_ozone are set together.

-----

PS: Please note that this is a temp solution that will help to choose
between ozone and non-ozone X11 build. The switch that will be used
to choose the path is --enable-features=UseOzonePlatform. Once
non-Ozone X11 path is removed (hopefully by Q1 2021 depending on how
th finch trial goes), the wrapper will be removed.

Please also note that it's impossible to build use_x11 && use_ozone
without some hacks in PlatformCursor code. The changes to that are
on their way to upstream.

----

Bug: 1085700
Change-Id: Ia1b9234cffdd6e40e50f39a6e35900c9f42e221e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2315685Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Commit-Queue: Maksim Sisov (GMT+3) <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#796411}
parent 466d92e0
......@@ -408,6 +408,7 @@ if (is_win || is_mac || (is_linux && !is_chromeos)) {
"//build/win:default_exe_manifest",
"//media:test_support",
"//net",
"//ui/base:features",
"//ui/gfx/geometry",
]
......
......@@ -4,5 +4,6 @@ include_rules = [
"+net",
"+third_party/libyuv",
"+third_party/zlib",
"+ui/base",
"+ui/gfx",
]
......@@ -49,6 +49,7 @@
#include "media/cast/test/utility/input_builder.h"
#include "media/cast/test/utility/standalone_cast_environment.h"
#include "net/base/ip_address.h"
#include "ui/base/ui_base_features.h"
#if defined(USE_X11)
#include "media/cast/test/linux_output_window.h"
......@@ -424,6 +425,7 @@ class NaivePlayer : public InProcessReceiver,
if (!video_playout_queue_.empty()) {
const scoped_refptr<VideoFrame> video_frame = PopOneVideoFrame(false);
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform())
render_.RenderFrame(*video_frame);
#endif // defined(USE_X11)
}
......@@ -595,6 +597,7 @@ int main(int argc, char** argv) {
int window_width = 0;
int window_height = 0;
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform())
media::cast::GetWindowSize(&window_width, &window_height);
#endif // defined(USE_X11)
media::cast::NaivePlayer player(cast_environment,
......
......@@ -17,6 +17,7 @@
#endif
#if defined(USE_OZONE)
#include "ui/base/ui_base_features.h"
#include "ui/ozone/public/ozone_platform.h"
#endif
......@@ -58,12 +59,14 @@ VideoTestEnvironment::VideoTestEnvironment(
#if defined(USE_OZONE)
// Initialize Ozone. This is necessary to gain access to the GPU for hardware
// video decode acceleration.
if (features::IsUsingOzonePlatform()) {
LOG(WARNING) << "Initializing Ozone Platform...\n"
"If this hangs indefinitely please call 'stop ui' first!";
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForUI(params);
ui::OzonePlatform::InitializeForGPU(params);
}
#endif
}
......
......@@ -166,6 +166,7 @@ source_set("common") {
deps = [
":libva_stubs",
"//third_party/libyuv",
"//ui/base:features",
"//ui/gfx:memory_buffer",
"//ui/gl",
]
......
......@@ -6,6 +6,7 @@
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "media/video/picture.h"
#include "ui/base/ui_base_features.h"
#include "ui/gl/gl_bindings.h"
#if defined(USE_X11)
......@@ -20,23 +21,18 @@
namespace media {
namespace {
const struct {
gl::GLImplementation gl_impl;
VaapiPictureFactory::VaapiImplementation va_impl;
} kVaapiImplementationPairs[] = {{gl::kGLImplementationEGLGLES2,
VaapiPictureFactory::kVaapiImplementationDrm}
VaapiPictureFactory::VaapiPictureFactory() {
vaapi_impl_pairs_.insert(
std::make_pair(gl::kGLImplementationEGLGLES2,
VaapiPictureFactory::kVaapiImplementationDrm));
#if defined(USE_X11)
,
{gl::kGLImplementationDesktopGL,
VaapiPictureFactory::kVaapiImplementationX11}
#endif // USE_X11
};
} // namespace
VaapiPictureFactory::VaapiPictureFactory() = default;
if (!features::IsUsingOzonePlatform()) {
vaapi_impl_pairs_.insert(
std::make_pair(gl::kGLImplementationDesktopGL,
VaapiPictureFactory::kVaapiImplementationX11));
}
#endif
}
VaapiPictureFactory::~VaapiPictureFactory() = default;
......@@ -60,38 +56,100 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create(
? picture_buffer.service_texture_ids()[0]
: 0;
std::unique_ptr<VaapiPicture> picture;
// Select DRM(egl) / TFP(glx) at runtime with --use-gl=egl / --use-gl=desktop
switch (GetVaapiImplementation(gl::GetGLImplementation())) {
#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,
bind_image_cb, picture_buffer, visible_size,
client_texture_id, service_texture_id);
}
VaapiPictureFactory::VaapiImplementation
VaapiPictureFactory::GetVaapiImplementation(gl::GLImplementation gl_impl) {
if (base::Contains(vaapi_impl_pairs_, gl_impl))
return vaapi_impl_pairs_[gl_impl];
return kVaapiImplementationNone;
}
uint32_t VaapiPictureFactory::GetGLTextureTarget() {
#if defined(USE_OZONE)
return GL_TEXTURE_EXTERNAL_OES;
#else
return GL_TEXTURE_2D;
#endif
}
gfx::BufferFormat VaapiPictureFactory::GetBufferFormat() {
#if defined(USE_OZONE)
return gfx::BufferFormat::YUV_420_BIPLANAR;
#else
return gfx::BufferFormat::RGBX_8888;
#endif
}
#if defined(USE_OZONE)
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())) {
// We can be called without GL initialized, which is valid if we use Ozone.
case kVaapiImplementationNone:
FALLTHROUGH;
case kVaapiImplementationDrm:
picture.reset(new VaapiPictureNativePixmapOzone(
return std::make_unique<VaapiPictureNativePixmapOzone>(
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()));
picture_buffer.texture_target());
break;
#elif defined(USE_EGL)
default:
NOTREACHED();
return nullptr;
}
return nullptr;
}
#endif // USE_OZONE
std::unique_ptr<VaapiPicture> VaapiPictureFactory::CreateVaapiPictureNative(
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) {
switch (GetVaapiImplementation(gl::GetGLImplementation())) {
#if defined(USE_EGL)
case kVaapiImplementationDrm:
picture.reset(new VaapiPictureNativePixmapEgl(
return std::make_unique<VaapiPictureNativePixmapEgl>(
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
picture_buffer.texture_target());
#endif // USE_EGL
#if defined(USE_X11)
case kVaapiImplementationX11:
picture.reset(new VaapiTFPPicture(
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()));
picture_buffer.texture_target());
break;
#endif // USE_X11
......@@ -100,33 +158,7 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create(
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;
#else
return GL_TEXTURE_2D;
#endif
}
gfx::BufferFormat VaapiPictureFactory::GetBufferFormat() {
#if defined(USE_OZONE)
return gfx::BufferFormat::YUV_420_BIPLANAR;
#else
return gfx::BufferFormat::RGBX_8888;
#endif
return nullptr;
}
} // namespace media
......@@ -51,6 +51,29 @@ class MEDIA_GPU_EXPORT VaapiPictureFactory {
// the format decoded frames in VASurfaces are converted into.
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(
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);
std::map<gl::GLImplementation, VaapiPictureFactory::VaapiImplementation>
vaapi_impl_pairs_;
private:
DISALLOW_COPY_AND_ASSIGN(VaapiPictureFactory);
};
......
......@@ -6,6 +6,7 @@
#include "media/gpu/vaapi/va_surface.h"
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_glx.h"
......@@ -35,6 +36,7 @@ VaapiTFPPicture::VaapiTFPPicture(
x_display_(gfx::GetXDisplay()),
x_pixmap_(0) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!features::IsUsingOzonePlatform());
DCHECK(texture_id);
DCHECK(client_texture_id);
}
......
......@@ -15,6 +15,7 @@
#include "media/gpu/vaapi/vaapi_wrapper.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ui_base_features.h"
using base::test::RunClosure;
using ::testing::_;
......@@ -405,9 +406,11 @@ TEST_P(VaapiVideoDecodeAcceleratorTest, SupportedPlatforms) {
gl::kGLImplementationEGLGLES2));
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform()) {
EXPECT_EQ(VaapiPictureFactory::kVaapiImplementationX11,
mock_vaapi_picture_factory_->GetVaapiImplementation(
gl::kGLImplementationDesktopGL));
}
#endif
}
......
......@@ -37,6 +37,7 @@
#include "base/system/sys_info.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "ui/base/ui_base_features.h"
#include "media/base/media_switches.h"
#include "media/base/video_frame.h"
......@@ -380,13 +381,13 @@ VADisplayState::VADisplayState()
bool VADisplayState::Initialize() {
base::AutoLock auto_lock(va_lock_);
if (!IsVaInitialized() ||
bool libraries_initialized = IsVaInitialized() && IsVa_drmInitialized();
#if defined(USE_X11)
!IsVa_x11Initialized() ||
if (!features::IsUsingOzonePlatform())
libraries_initialized = libraries_initialized && IsVa_x11Initialized();
#endif
!IsVa_drmInitialized()) {
if (!libraries_initialized)
return false;
}
// Manual refcounting to ensure the rest of the method is called only once.
if (refcount_++ > 0)
......@@ -409,6 +410,7 @@ bool VADisplayState::InitializeOnce() {
break;
case gl::kGLImplementationDesktopGL:
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform())
va_display_ = vaGetDisplay(gfx::GetXDisplay());
#else
LOG(WARNING) << "VAAPI video acceleration not available without "
......@@ -418,9 +420,11 @@ bool VADisplayState::InitializeOnce() {
// Cannot infer platform from GL, try all available displays
case gl::kGLImplementationNone:
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform()) {
va_display_ = vaGetDisplay(gfx::GetXDisplay());
if (vaDisplayIsValid(va_display_))
break;
}
#endif // USE_X11
va_display_ = vaGetDisplayDRM(drm_fd_.get());
break;
......@@ -1770,6 +1774,7 @@ bool VaapiWrapper::ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id) {
bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
Pixmap x_pixmap,
gfx::Size dest_size) {
DCHECK(!features::IsUsingOzonePlatform());
base::AutoLock auto_lock(*va_lock_);
VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
......@@ -2143,6 +2148,7 @@ void VaapiWrapper::PreSandboxInitialization() {
paths[kModuleVa].push_back(std::string("libva.so.") + va_suffix);
paths[kModuleVa_drm].push_back(std::string("libva-drm.so.") + va_suffix);
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform())
paths[kModuleVa_x11].push_back(std::string("libva-x11.so.") + va_suffix);
#endif
......
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