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)) { ...@@ -408,6 +408,7 @@ if (is_win || is_mac || (is_linux && !is_chromeos)) {
"//build/win:default_exe_manifest", "//build/win:default_exe_manifest",
"//media:test_support", "//media:test_support",
"//net", "//net",
"//ui/base:features",
"//ui/gfx/geometry", "//ui/gfx/geometry",
] ]
......
...@@ -4,5 +4,6 @@ include_rules = [ ...@@ -4,5 +4,6 @@ include_rules = [
"+net", "+net",
"+third_party/libyuv", "+third_party/libyuv",
"+third_party/zlib", "+third_party/zlib",
"+ui/base",
"+ui/gfx", "+ui/gfx",
] ]
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "media/cast/test/utility/input_builder.h" #include "media/cast/test/utility/input_builder.h"
#include "media/cast/test/utility/standalone_cast_environment.h" #include "media/cast/test/utility/standalone_cast_environment.h"
#include "net/base/ip_address.h" #include "net/base/ip_address.h"
#include "ui/base/ui_base_features.h"
#if defined(USE_X11) #if defined(USE_X11)
#include "media/cast/test/linux_output_window.h" #include "media/cast/test/linux_output_window.h"
...@@ -424,7 +425,8 @@ class NaivePlayer : public InProcessReceiver, ...@@ -424,7 +425,8 @@ class NaivePlayer : public InProcessReceiver,
if (!video_playout_queue_.empty()) { if (!video_playout_queue_.empty()) {
const scoped_refptr<VideoFrame> video_frame = PopOneVideoFrame(false); const scoped_refptr<VideoFrame> video_frame = PopOneVideoFrame(false);
#if defined(USE_X11) #if defined(USE_X11)
render_.RenderFrame(*video_frame); if (!features::IsUsingOzonePlatform())
render_.RenderFrame(*video_frame);
#endif // defined(USE_X11) #endif // defined(USE_X11)
} }
ScheduleVideoPlayout(); ScheduleVideoPlayout();
...@@ -595,7 +597,8 @@ int main(int argc, char** argv) { ...@@ -595,7 +597,8 @@ int main(int argc, char** argv) {
int window_width = 0; int window_width = 0;
int window_height = 0; int window_height = 0;
#if defined(USE_X11) #if defined(USE_X11)
media::cast::GetWindowSize(&window_width, &window_height); if (!features::IsUsingOzonePlatform())
media::cast::GetWindowSize(&window_width, &window_height);
#endif // defined(USE_X11) #endif // defined(USE_X11)
media::cast::NaivePlayer player(cast_environment, media::cast::NaivePlayer player(cast_environment,
local_end_point, local_end_point,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#endif #endif
#if defined(USE_OZONE) #if defined(USE_OZONE)
#include "ui/base/ui_base_features.h"
#include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/ozone_platform.h"
#endif #endif
...@@ -58,12 +59,14 @@ VideoTestEnvironment::VideoTestEnvironment( ...@@ -58,12 +59,14 @@ VideoTestEnvironment::VideoTestEnvironment(
#if defined(USE_OZONE) #if defined(USE_OZONE)
// Initialize Ozone. This is necessary to gain access to the GPU for hardware // Initialize Ozone. This is necessary to gain access to the GPU for hardware
// video decode acceleration. // video decode acceleration.
LOG(WARNING) << "Initializing Ozone Platform...\n" if (features::IsUsingOzonePlatform()) {
"If this hangs indefinitely please call 'stop ui' first!"; LOG(WARNING) << "Initializing Ozone Platform...\n"
ui::OzonePlatform::InitParams params; "If this hangs indefinitely please call 'stop ui' first!";
params.single_process = true; ui::OzonePlatform::InitParams params;
ui::OzonePlatform::InitializeForUI(params); params.single_process = true;
ui::OzonePlatform::InitializeForGPU(params); ui::OzonePlatform::InitializeForUI(params);
ui::OzonePlatform::InitializeForGPU(params);
}
#endif #endif
} }
......
...@@ -166,6 +166,7 @@ source_set("common") { ...@@ -166,6 +166,7 @@ source_set("common") {
deps = [ deps = [
":libva_stubs", ":libva_stubs",
"//third_party/libyuv", "//third_party/libyuv",
"//ui/base:features",
"//ui/gfx:memory_buffer", "//ui/gfx:memory_buffer",
"//ui/gl", "//ui/gl",
] ]
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "media/gpu/vaapi/vaapi_wrapper.h" #include "media/gpu/vaapi/vaapi_wrapper.h"
#include "media/video/picture.h" #include "media/video/picture.h"
#include "ui/base/ui_base_features.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#if defined(USE_X11) #if defined(USE_X11)
...@@ -20,23 +21,18 @@ ...@@ -20,23 +21,18 @@
namespace media { namespace media {
namespace { VaapiPictureFactory::VaapiPictureFactory() {
vaapi_impl_pairs_.insert(
const struct { std::make_pair(gl::kGLImplementationEGLGLES2,
gl::GLImplementation gl_impl; VaapiPictureFactory::kVaapiImplementationDrm));
VaapiPictureFactory::VaapiImplementation va_impl;
} kVaapiImplementationPairs[] = {{gl::kGLImplementationEGLGLES2,
VaapiPictureFactory::kVaapiImplementationDrm}
#if defined(USE_X11) #if defined(USE_X11)
, if (!features::IsUsingOzonePlatform()) {
{gl::kGLImplementationDesktopGL, vaapi_impl_pairs_.insert(
VaapiPictureFactory::kVaapiImplementationX11} std::make_pair(gl::kGLImplementationDesktopGL,
#endif // USE_X11 VaapiPictureFactory::kVaapiImplementationX11));
}; }
#endif
} // namespace }
VaapiPictureFactory::VaapiPictureFactory() = default;
VaapiPictureFactory::~VaapiPictureFactory() = default; VaapiPictureFactory::~VaapiPictureFactory() = default;
...@@ -60,38 +56,100 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create( ...@@ -60,38 +56,100 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create(
? picture_buffer.service_texture_ids()[0] ? picture_buffer.service_texture_ids()[0]
: 0; : 0;
std::unique_ptr<VaapiPicture> picture;
// 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
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) #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. // We can be called without GL initialized, which is valid if we use Ozone.
case kVaapiImplementationNone: case kVaapiImplementationNone:
FALLTHROUGH; FALLTHROUGH;
case kVaapiImplementationDrm: case kVaapiImplementationDrm:
picture.reset(new VaapiPictureNativePixmapOzone( return std::make_unique<VaapiPictureNativePixmapOzone>(
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.id(), picture_buffer.size(), visible_size,
service_texture_id, client_texture_id, service_texture_id, client_texture_id,
picture_buffer.texture_target())); picture_buffer.texture_target());
break; 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: case kVaapiImplementationDrm:
picture.reset(new VaapiPictureNativePixmapEgl( 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.id(), picture_buffer.size(), visible_size,
service_texture_id, client_texture_id, service_texture_id, client_texture_id,
picture_buffer.texture_target())); picture_buffer.texture_target());
break; #endif // USE_EGL
#endif
#if defined(USE_X11) #if defined(USE_X11)
case kVaapiImplementationX11: 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, std::move(vaapi_wrapper), make_context_current_cb, bind_image_cb,
picture_buffer.id(), picture_buffer.size(), visible_size, picture_buffer.id(), picture_buffer.size(), visible_size,
service_texture_id, client_texture_id, service_texture_id, client_texture_id,
picture_buffer.texture_target())); picture_buffer.texture_target());
break; break;
#endif // USE_X11 #endif // USE_X11
...@@ -100,33 +158,7 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create( ...@@ -100,33 +158,7 @@ std::unique_ptr<VaapiPicture> VaapiPictureFactory::Create(
return nullptr; return nullptr;
} }
return picture; return nullptr;
}
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
} }
} // namespace media } // namespace media
...@@ -51,6 +51,29 @@ class MEDIA_GPU_EXPORT VaapiPictureFactory { ...@@ -51,6 +51,29 @@ 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(
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: private:
DISALLOW_COPY_AND_ASSIGN(VaapiPictureFactory); DISALLOW_COPY_AND_ASSIGN(VaapiPictureFactory);
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "media/gpu/vaapi/va_surface.h" #include "media/gpu/vaapi/va_surface.h"
#include "media/gpu/vaapi/vaapi_wrapper.h" #include "media/gpu/vaapi/vaapi_wrapper.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_glx.h" #include "ui/gl/gl_image_glx.h"
...@@ -35,6 +36,7 @@ VaapiTFPPicture::VaapiTFPPicture( ...@@ -35,6 +36,7 @@ VaapiTFPPicture::VaapiTFPPicture(
x_display_(gfx::GetXDisplay()), x_display_(gfx::GetXDisplay()),
x_pixmap_(0) { x_pixmap_(0) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!features::IsUsingOzonePlatform());
DCHECK(texture_id); DCHECK(texture_id);
DCHECK(client_texture_id); DCHECK(client_texture_id);
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "media/gpu/vaapi/vaapi_wrapper.h" #include "media/gpu/vaapi/vaapi_wrapper.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ui_base_features.h"
using base::test::RunClosure; using base::test::RunClosure;
using ::testing::_; using ::testing::_;
...@@ -405,9 +406,11 @@ TEST_P(VaapiVideoDecodeAcceleratorTest, SupportedPlatforms) { ...@@ -405,9 +406,11 @@ TEST_P(VaapiVideoDecodeAcceleratorTest, SupportedPlatforms) {
gl::kGLImplementationEGLGLES2)); gl::kGLImplementationEGLGLES2));
#if defined(USE_X11) #if defined(USE_X11)
EXPECT_EQ(VaapiPictureFactory::kVaapiImplementationX11, if (!features::IsUsingOzonePlatform()) {
mock_vaapi_picture_factory_->GetVaapiImplementation( EXPECT_EQ(VaapiPictureFactory::kVaapiImplementationX11,
gl::kGLImplementationDesktopGL)); mock_vaapi_picture_factory_->GetVaapiImplementation(
gl::kGLImplementationDesktopGL));
}
#endif #endif
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/base/ui_base_features.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
...@@ -380,13 +381,13 @@ VADisplayState::VADisplayState() ...@@ -380,13 +381,13 @@ VADisplayState::VADisplayState()
bool VADisplayState::Initialize() { bool VADisplayState::Initialize() {
base::AutoLock auto_lock(va_lock_); base::AutoLock auto_lock(va_lock_);
if (!IsVaInitialized() || bool libraries_initialized = IsVaInitialized() && IsVa_drmInitialized();
#if defined(USE_X11) #if defined(USE_X11)
!IsVa_x11Initialized() || if (!features::IsUsingOzonePlatform())
libraries_initialized = libraries_initialized && IsVa_x11Initialized();
#endif #endif
!IsVa_drmInitialized()) { if (!libraries_initialized)
return false; return false;
}
// Manual refcounting to ensure the rest of the method is called only once. // Manual refcounting to ensure the rest of the method is called only once.
if (refcount_++ > 0) if (refcount_++ > 0)
...@@ -409,7 +410,8 @@ bool VADisplayState::InitializeOnce() { ...@@ -409,7 +410,8 @@ bool VADisplayState::InitializeOnce() {
break; break;
case gl::kGLImplementationDesktopGL: case gl::kGLImplementationDesktopGL:
#if defined(USE_X11) #if defined(USE_X11)
va_display_ = vaGetDisplay(gfx::GetXDisplay()); if (!features::IsUsingOzonePlatform())
va_display_ = vaGetDisplay(gfx::GetXDisplay());
#else #else
LOG(WARNING) << "VAAPI video acceleration not available without " LOG(WARNING) << "VAAPI video acceleration not available without "
"DesktopGL (GLX)."; "DesktopGL (GLX).";
...@@ -418,9 +420,11 @@ bool VADisplayState::InitializeOnce() { ...@@ -418,9 +420,11 @@ bool VADisplayState::InitializeOnce() {
// Cannot infer platform from GL, try all available displays // Cannot infer platform from GL, try all available displays
case gl::kGLImplementationNone: case gl::kGLImplementationNone:
#if defined(USE_X11) #if defined(USE_X11)
va_display_ = vaGetDisplay(gfx::GetXDisplay()); if (!features::IsUsingOzonePlatform()) {
if (vaDisplayIsValid(va_display_)) va_display_ = vaGetDisplay(gfx::GetXDisplay());
break; if (vaDisplayIsValid(va_display_))
break;
}
#endif // USE_X11 #endif // USE_X11
va_display_ = vaGetDisplayDRM(drm_fd_.get()); va_display_ = vaGetDisplayDRM(drm_fd_.get());
break; break;
...@@ -1770,6 +1774,7 @@ bool VaapiWrapper::ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id) { ...@@ -1770,6 +1774,7 @@ bool VaapiWrapper::ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id) {
bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id, bool VaapiWrapper::PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
Pixmap x_pixmap, Pixmap x_pixmap,
gfx::Size dest_size) { gfx::Size dest_size) {
DCHECK(!features::IsUsingOzonePlatform());
base::AutoLock auto_lock(*va_lock_); base::AutoLock auto_lock(*va_lock_);
VAStatus va_res = vaSyncSurface(va_display_, va_surface_id); VAStatus va_res = vaSyncSurface(va_display_, va_surface_id);
...@@ -2143,7 +2148,8 @@ void VaapiWrapper::PreSandboxInitialization() { ...@@ -2143,7 +2148,8 @@ void VaapiWrapper::PreSandboxInitialization() {
paths[kModuleVa].push_back(std::string("libva.so.") + va_suffix); paths[kModuleVa].push_back(std::string("libva.so.") + va_suffix);
paths[kModuleVa_drm].push_back(std::string("libva-drm.so.") + va_suffix); paths[kModuleVa_drm].push_back(std::string("libva-drm.so.") + va_suffix);
#if defined(USE_X11) #if defined(USE_X11)
paths[kModuleVa_x11].push_back(std::string("libva-x11.so.") + va_suffix); if (!features::IsUsingOzonePlatform())
paths[kModuleVa_x11].push_back(std::string("libva-x11.so.") + va_suffix);
#endif #endif
// InitializeStubs dlopen() VA-API libraries // InitializeStubs dlopen() VA-API libraries
......
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