diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-01-18 11:02:53 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-02-15 13:40:30 +0100 |
commit | 1b7aaf1c7d98482cd6dc3d80aa0140fe9dd2c7d3 (patch) | |
tree | f8aab87736bc017bbc7933df7ce64ce541d10aec /src/core/ozone/ozone_platform_qt.cpp | |
parent | 47564e329a71fed8b73be403bbdc30fbf684f7a4 (diff) |
Enable VAAPI and gpu memory buffers on Linux
Only seen working in vulkan and EGL modes so far.
Does not work with system libvpx
Fixes: QTBUG-91677
Change-Id: Ie2956c2b841854c78fc1af3c1010fb877728acb1
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'src/core/ozone/ozone_platform_qt.cpp')
-rw-r--r-- | src/core/ozone/ozone_platform_qt.cpp | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/src/core/ozone/ozone_platform_qt.cpp b/src/core/ozone/ozone_platform_qt.cpp index 5b7e9b4d7..8dcb56446 100644 --- a/src/core/ozone/ozone_platform_qt.cpp +++ b/src/core/ozone/ozone_platform_qt.cpp @@ -5,11 +5,16 @@ #if defined(USE_OZONE) #include "base/no_destructor.h" +#include "base/task/thread_pool.h" +#include "media/gpu/buildflags.h" #include "ui/base/buildflags.h" #include "ui/base/ime/input_method.h" #include "ui/display/types/native_display_delegate.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" +#include "ui/gfx/linux/client_native_pixmap_dmabuf.h" +#include "ui/gfx/linux/client_native_pixmap_factory_dmabuf.h" +#include "ui/gfx/linux/gpu_memory_buffer_support_x11.h" #include "ui/ozone/common/bitmap_cursor_factory.h" #include "ui/ozone/common/stub_client_native_pixmap_factory.h" #include "ui/ozone/common/stub_overlay_manager.h" @@ -18,6 +23,8 @@ #include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/platform_screen.h" #include "ui/ozone/public/system_input_injector.h" +#include "ui/ozone/platform/x11/gl_egl_utility_x11.h" +#include "ui/ozone/platform/wayland/gpu/wayland_gl_egl_utility.h" #include "ui/platform_window/platform_window_delegate.h" #include "ui/platform_window/platform_window_init_properties.h" @@ -56,6 +63,25 @@ public: std::unique_ptr<InputMethod> CreateInputMethod(ImeKeyEventDispatcher *ime_key_event_dispatcher, gfx::AcceleratedWidget widget) override; std::unique_ptr<ui::PlatformScreen> CreateScreen() override { return nullptr; } const PlatformProperties &GetPlatformProperties() override; + PlatformGLEGLUtility *GetPlatformGLEGLUtility() override; + + const PlatformRuntimeProperties &GetPlatformRuntimeProperties() override + { + static OzonePlatform::PlatformRuntimeProperties properties; +#if BUILDFLAG(USE_VAAPI) + if (has_initialized_gpu()) { + if (GetQtXDisplay()) { + // This property is set when the GetPlatformRuntimeProperties is + // called on the gpu process side. + properties.supports_native_pixmaps = ui::GpuMemoryBufferSupportX11::GetInstance()->has_gbm_device(); + } else { + properties.supports_native_pixmaps = true; // buffer_manager_->GetGbmDevice() != nullptr + } + } +#endif + return properties; + } + bool IsNativePixmapConfigSupported(gfx::BufferFormat format, gfx::BufferUsage usage) const override; private: bool InitializeUI(const ui::OzonePlatform::InitParams &) override; @@ -74,6 +100,7 @@ private: XkbEvdevCodes m_xkbEvdevCodeConverter; #endif std::unique_ptr<KeyboardLayoutEngine> m_keyboardLayoutEngine; + std::unique_ptr<PlatformGLEGLUtility> gl_egl_utility_; }; @@ -87,7 +114,9 @@ const ui::OzonePlatform::PlatformProperties &OzonePlatformQt::GetPlatformPropert static bool initialized = false; if (!initialized) { properties->fetch_buffer_formats_for_gmb_on_gpu = true; - +#if BUILDFLAG(USE_VAAPI) + properties->supports_vaapi = true; +#endif initialized = true; } @@ -205,9 +234,19 @@ bool OzonePlatformQt::InitializeUI(const ui::OzonePlatform::InitParams &) return true; } -void OzonePlatformQt::InitializeGPU(const ui::OzonePlatform::InitParams &) +void OzonePlatformQt::InitializeGPU(const ui::OzonePlatform::InitParams ¶ms) { surface_factory_ozone_.reset(new QtWebEngineCore::SurfaceFactoryQt()); + +#if BUILDFLAG(OZONE_PLATFORM_X11) && BUILDFLAG(USE_VAAPI_X11) + if (params.enable_native_gpu_memory_buffers) { + base::ThreadPool::PostTask(FROM_HERE, + base::BindOnce([]() + { + ui::GpuMemoryBufferSupportX11::GetInstance(); + })); + } +#endif } std::unique_ptr<InputMethod> OzonePlatformQt::CreateInputMethod(ImeKeyEventDispatcher *, gfx::AcceleratedWidget) @@ -216,13 +255,42 @@ std::unique_ptr<InputMethod> OzonePlatformQt::CreateInputMethod(ImeKeyEventDispa return nullptr; } +bool OzonePlatformQt::IsNativePixmapConfigSupported(gfx::BufferFormat format, gfx::BufferUsage usage) const +{ +#if BUILDFLAG(USE_VAAPI) + return gfx::ClientNativePixmapDmaBuf::IsConfigurationSupported(format, usage); +#else + return false; +#endif +} + +PlatformGLEGLUtility *OzonePlatformQt::GetPlatformGLEGLUtility() +{ +#if BUILDFLAG(USE_VAAPI) + if (!gl_egl_utility_) { +#if BUILDFLAG(OZONE_PLATFORM_X11) + if (GetQtXDisplay()) + gl_egl_utility_ = std::make_unique<GLEGLUtilityX11>(); + else +#endif + gl_egl_utility_ = std::make_unique<WaylandGLEGLUtility>(); + } +#endif + return gl_egl_utility_.get(); +} + + } // namespace OzonePlatform* CreateOzonePlatformQt() { return new OzonePlatformQt; } -gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryQt() +gfx::ClientNativePixmapFactory *CreateClientNativePixmapFactoryQt() { +#if BUILDFLAG(USE_VAAPI) + return gfx::CreateClientNativePixmapFactoryDmabuf(); +#else return CreateStubClientNativePixmapFactory(); +#endif } } // namespace ui |