diff options
-rw-r--r-- | src/core/CMakeLists.txt | 18 | ||||
-rw-r--r-- | src/core/api/configure.cmake | 17 | ||||
-rw-r--r-- | src/core/compositor/vulkan_implementation_qt.cpp | 36 | ||||
-rw-r--r-- | src/core/configure/BUILD.root.gn.in | 14 | ||||
-rw-r--r-- | src/core/ozone/gl_ozone_egl_qt.cpp | 45 | ||||
-rw-r--r-- | src/core/ozone/gl_ozone_egl_qt.h | 9 | ||||
-rw-r--r-- | src/core/ozone/gl_ozone_glx_qt.cpp | 13 | ||||
-rw-r--r-- | src/core/ozone/gl_ozone_glx_qt.h | 2 | ||||
-rw-r--r-- | src/core/ozone/gl_surface_egl_qt.cpp | 14 | ||||
-rw-r--r-- | src/core/ozone/ozone_platform_qt.cpp | 74 | ||||
-rw-r--r-- | src/core/ozone/surface_factory_qt.cpp | 89 | ||||
-rw-r--r-- | src/core/ozone/surface_factory_qt.h | 20 |
12 files changed, 329 insertions, 22 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 792ad7e16..eb6e9a1f9 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -398,7 +398,6 @@ foreach(arch ${archs}) use_bundled_fontconfig=false use_glib=false use_bluez=false - use_vaapi=false use_udev=true enable_session_service=false is_cfi=false @@ -410,7 +409,7 @@ foreach(arch ${archs}) ozone_extra_path="${CMAKE_CURRENT_LIST_DIR}/ozone/ozone_extra.gni" ) set(systemLibs libjpeg libpng freetype harfbuzz libevent libwebp libxml - opus snappy libvpx icu ffmpeg re2 lcms2 libopenjpeg2 + opus snappy icu ffmpeg re2 lcms2 libopenjpeg2 ) foreach(slib ${systemLibs}) extend_gn_list(gnArgArg @@ -451,6 +450,17 @@ foreach(arch ${archs}) CONDITION QT_FEATURE_webengine_system_pulseaudio ) extend_gn_list(gnArgArg + ARGS use_vaapi + CONDITION QT_FEATURE_webengine_vaapi + ) + if(NOT QT_FEATURE_webengine_vaapi) + # hardware accelerated encoding requires bundled libvpx + extend_gn_list(gnArgArg + ARGS use_system_libvpx + CONDITION QT_FEATURE_webengine_system_libvpx + ) + endif() + extend_gn_list(gnArgArg ARGS ozone_platform_x11 use_xkbcommon CONDITION QT_FEATURE_webengine_ozone_x11 ) @@ -458,6 +468,10 @@ foreach(arch ${archs}) ARGS rtc_use_x11 CONDITION QT_FEATURE_webengine_ozone_x11 AND QT_FEATURE_webengine_webrtc ) + extend_gn_list(gnArgArg + ARGS use_vaapi_x11 + CONDITION QT_FEATURE_webengine_ozone_x11 AND QT_FEATURE_webengine_vaapi + ) if(QT_FEATURE_webengine_kerberos) list(APPEND gnArgArg diff --git a/src/core/api/configure.cmake b/src/core/api/configure.cmake index a35651b8b..df7583e25 100644 --- a/src/core/api/configure.cmake +++ b/src/core/api/configure.cmake @@ -12,6 +12,8 @@ if(NOT QT_CONFIGURE_RUNNING) pkg_check_modules(PULSEAUDIO libpulse>=0.9.10 libpulse-mainloop-glib) pkg_check_modules(XDAMAGE xdamage) pkg_check_modules(POPPLER_CPP poppler-cpp IMPORTED_TARGET) + pkg_check_modules(GBM gbm) + pkg_check_modules(LIBVA libva) if(NOT GIO_FOUND) pkg_check_modules(GIO gio-2.0) endif() @@ -152,6 +154,13 @@ qt_feature("webengine-vulkan" PRIVATE PURPOSE "Enables support for Vulkan rendering" CONDITION QT_FEATURE_vulkan ) +qt_feature("webengine-vaapi" PRIVATE + SECTION "WebEngine" + LABEL "VA-API support" + PURPOSE "Enables support for VA-API hardware acceleration" + AUTODETECT GBM_FOUND AND LIBVA_FOUND + CONDITION LINUX +) # internal testing feature qt_feature("webengine-system-poppler" PRIVATE LABEL "popler" @@ -184,12 +193,16 @@ qt_configure_add_summary_entry( CONDITION QT_FEATURE_vulkan ) qt_configure_add_summary_entry( + ARGS "webengine-vaapi" + CONDITION LINUX +) +qt_configure_add_summary_entry( ARGS "webengine-system-alsa" - CONDITION UNIX + CONDITION LINUX ) qt_configure_add_summary_entry( ARGS "webengine-system-pulseaudio" - CONDITION UNIX + CONDITION LINUX ) qt_configure_end_summary_section() # end of "Qt WebEngineCore" section if(CMAKE_CROSSCOMPILING) diff --git a/src/core/compositor/vulkan_implementation_qt.cpp b/src/core/compositor/vulkan_implementation_qt.cpp index f24ec334b..28d5d7b01 100644 --- a/src/core/compositor/vulkan_implementation_qt.cpp +++ b/src/core/compositor/vulkan_implementation_qt.cpp @@ -82,6 +82,8 @@ std::vector<const char *> VulkanImplementationQt::GetOptionalDeviceExtensions() VK_KHR_EXTERNAL_SEMAPHORE_WIN32_EXTENSION_NAME, #else VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, + VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME, + VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME, #endif }; } @@ -136,18 +138,42 @@ VkExternalMemoryHandleTypeFlagBits VulkanImplementationQt::GetExternalImageHandl } bool VulkanImplementationQt::CanImportGpuMemoryBuffer( - VulkanDeviceQueue* /*device_queue*/, - gfx::GpuMemoryBufferType /*memory_buffer_type*/) + VulkanDeviceQueue *device_queue, + gfx::GpuMemoryBufferType memory_buffer_type) { +#if BUILDFLAG(IS_LINUX) + const auto &enabled_extensions = device_queue->enabled_extensions(); + return gfx::HasExtension(enabled_extensions, + VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME) && + gfx::HasExtension(enabled_extensions, + VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) && + memory_buffer_type == gfx::GpuMemoryBufferType::NATIVE_PIXMAP; +#else return false; +#endif } -std::unique_ptr<VulkanImage> VulkanImplementationQt::CreateImageFromGpuMemoryHandle(VulkanDeviceQueue *, gfx::GpuMemoryBufferHandle, - gfx::Size, VkFormat, +std::unique_ptr<VulkanImage> VulkanImplementationQt::CreateImageFromGpuMemoryHandle(VulkanDeviceQueue *device_queue, + gfx::GpuMemoryBufferHandle gmb_handle, + gfx::Size size, + VkFormat vk_format, const gfx::ColorSpace &) { - NOTREACHED(); +#if BUILDFLAG(IS_LINUX) + constexpr auto kUsage = + VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + auto tiling = gmb_handle.native_pixmap_handle.modifier == + gfx::NativePixmapHandle::kNoModifier + ? VK_IMAGE_TILING_OPTIMAL + : VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT; + return gpu::VulkanImage::CreateFromGpuMemoryBufferHandle( + device_queue, std::move(gmb_handle), size, vk_format, kUsage, /*flags=*/0, + tiling, VK_QUEUE_FAMILY_EXTERNAL); +#else + NOTIMPLEMENTED(); return nullptr; +#endif } } // namespace gpu diff --git a/src/core/configure/BUILD.root.gn.in b/src/core/configure/BUILD.root.gn.in index d38e84973..c55101bcb 100644 --- a/src/core/configure/BUILD.root.gn.in +++ b/src/core/configure/BUILD.root.gn.in @@ -326,6 +326,20 @@ source_set("qtwebengine_sources") { "//components/embedder_support/user_agent_utils.cc", "//components/embedder_support/user_agent_utils.h", ] + if (use_ozone && use_vaapi) { + deps += [ + "//ui/base/x:gl", + "//ui/gfx/linux:gpu_memory_buffer_support_x11", + ] + sources += [ + "//ui/ozone/platform/wayland/gpu/wayland_gl_egl_utility.cc", + "//ui/ozone/platform/wayland/gpu/wayland_gl_egl_utility.h", + "//ui/ozone/platform/x11/gl_egl_utility_x11.cc", + "//ui/ozone/platform/x11/gl_egl_utility_x11.h", + "//ui/ozone/platform/x11/native_pixmap_glx_binding.cc", + "//ui/ozone/platform/x11/native_pixmap_glx_binding.h", + ] + } if (enable_extensions) { deps += [ ":qtwebengine_extensions_features", diff --git a/src/core/ozone/gl_ozone_egl_qt.cpp b/src/core/ozone/gl_ozone_egl_qt.cpp index c0348e833..5e2540af8 100644 --- a/src/core/ozone/gl_ozone_egl_qt.cpp +++ b/src/core/ozone/gl_ozone_egl_qt.cpp @@ -8,11 +8,17 @@ #include "base/files/file_path.h" #include "base/native_library.h" +#include "media/gpu/buildflags.h" +#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_context_egl.h" +#include "ui/gl/gl_display.h" #include "ui/gl/gl_implementation.h" +#include "ui/gl/gl_egl_api_implementation.h" #include "ui/gl/gl_surface.h" +#include "ui/gl/gl_utils.h" #include "ui/gl/init/gl_factory.h" #include "ui/gl/init/gl_initializer.h" +#include "ui/ozone/common/native_pixmap_egl_binding.h" #include <EGL/egl.h> #include <dlfcn.h> @@ -50,13 +56,19 @@ bool GLOzoneEGLQt::LoadGLES2Bindings(const gl::GLImplementationParts & /*impleme gl::GLDisplay *GLOzoneEGLQt::InitializeGLOneOffPlatform(uint64_t system_device_id) { - return gl::GLSurfaceEGLQt::InitializeOneOff(system_device_id); + if (auto display = gl::GLSurfaceEGLQt::InitializeOneOff(system_device_id)) { + if (!static_cast<gl::GLDisplayEGL*>(display)->Initialize(GetNativeDisplay())) { + LOG(ERROR) << "GLDisplayEGL::Initialize failed."; + return nullptr; + } + return display; + } + return nullptr; } bool GLOzoneEGLQt::InitializeExtensionSettingsOneOffPlatform(gl::GLDisplay *display) { - Q_UNUSED(display); - return gl::GLSurfaceEGLQt::InitializeExtensionSettingsOneOff(); + return static_cast<gl::GLDisplayEGL*>(display)->InitializeExtensionSettings(); } scoped_refptr<gl::GLSurface> GLOzoneEGLQt::CreateViewGLSurface(gl::GLDisplay* display, gfx::AcceleratedWidget window) @@ -87,6 +99,33 @@ gl::EGLDisplayPlatform GLOzoneEGLQt::GetNativeDisplay() return platform; } +bool GLOzoneEGLQt::CanImportNativePixmap() +{ +#if BUILDFLAG(USE_VAAPI) + return gl::GLSurfaceEGL::GetGLDisplayEGL()->ext->b_EGL_EXT_image_dma_buf_import; +#else + return false; +#endif +} + +std::unique_ptr<NativePixmapGLBinding> GLOzoneEGLQt::ImportNativePixmap( + scoped_refptr<gfx::NativePixmap> pixmap, + gfx::BufferFormat plane_format, + gfx::BufferPlane plane, + gfx::Size plane_size, + const gfx::ColorSpace &color_space, + GLenum target, + GLuint texture_id) +{ +#if BUILDFLAG(USE_VAAPI) + return NativePixmapEGLBinding::Create(pixmap, plane_format, plane, + plane_size, color_space, target, + texture_id); +#else + return nullptr; +#endif +} + } // namespace ui #endif // defined(USE_OZONE) diff --git a/src/core/ozone/gl_ozone_egl_qt.h b/src/core/ozone/gl_ozone_egl_qt.h index 4619fc714..6a313c8fa 100644 --- a/src/core/ozone/gl_ozone_egl_qt.h +++ b/src/core/ozone/gl_ozone_egl_qt.h @@ -20,6 +20,15 @@ public: scoped_refptr<gl::GLSurface> CreateOffscreenGLSurface( gl::GLDisplay *display, const gfx::Size &size) override; + bool CanImportNativePixmap() override; + std::unique_ptr<NativePixmapGLBinding> ImportNativePixmap( + scoped_refptr<gfx::NativePixmap> pixmap, + gfx::BufferFormat plane_format, + gfx::BufferPlane plane, + gfx::Size plane_size, + const gfx::ColorSpace &color_space, + GLenum target, + GLuint texture_id) override; protected: // Returns native platform display handle. This is used to obtain the EGL diff --git a/src/core/ozone/gl_ozone_glx_qt.cpp b/src/core/ozone/gl_ozone_glx_qt.cpp index c610862f6..e9946806a 100644 --- a/src/core/ozone/gl_ozone_glx_qt.cpp +++ b/src/core/ozone/gl_ozone_glx_qt.cpp @@ -9,9 +9,13 @@ #include "gl_ozone_glx_qt.h" #include "gl_surface_glx_qt.h" #include "gl_context_qt.h" + +#include "media/gpu/buildflags.h" #include "ui/gl/gl_context_glx.h" #include "ui/gl/gl_gl_api_implementation.h" #include "ui/gl/gl_glx_api_implementation.h" +#include "ui/ozone/platform/x11/native_pixmap_glx_binding.h" + #include <dlfcn.h> namespace ui { @@ -109,10 +113,15 @@ bool GLOzoneGLXQt::CanImportNativePixmap() } std::unique_ptr<ui::NativePixmapGLBinding> GLOzoneGLXQt::ImportNativePixmap( - scoped_refptr<gfx::NativePixmap>, gfx::BufferFormat, gfx::BufferPlane, - gfx::Size, const gfx::ColorSpace&, GLenum, GLuint) + scoped_refptr<gfx::NativePixmap> pixmap, gfx::BufferFormat plane_format, gfx::BufferPlane plane, + gfx::Size plane_size, const gfx::ColorSpace &, GLenum target, GLuint texture_id) { +#if BUILDFLAG(USE_VAAPI_X11) + return NativePixmapGLXBinding::Create(pixmap, plane_format, plane, plane_size, + target, texture_id); +#else return nullptr; +#endif } bool GLOzoneGLXQt::InitializeExtensionSettingsOneOffPlatform(gl::GLDisplay *) diff --git a/src/core/ozone/gl_ozone_glx_qt.h b/src/core/ozone/gl_ozone_glx_qt.h index 777de352e..cc0feb563 100644 --- a/src/core/ozone/gl_ozone_glx_qt.h +++ b/src/core/ozone/gl_ozone_glx_qt.h @@ -28,7 +28,7 @@ public: bool CanImportNativePixmap() override; std::unique_ptr<ui::NativePixmapGLBinding> ImportNativePixmap( scoped_refptr<gfx::NativePixmap>, gfx::BufferFormat, gfx::BufferPlane, - gfx::Size, const gfx::ColorSpace&, GLenum, GLuint) override; + gfx::Size, const gfx::ColorSpace &, GLenum, GLuint) override; scoped_refptr<gl::GLContext> CreateGLContext( gl::GLShareGroup* share_group, diff --git a/src/core/ozone/gl_surface_egl_qt.cpp b/src/core/ozone/gl_surface_egl_qt.cpp index 7f00ea6ed..de973e390 100644 --- a/src/core/ozone/gl_surface_egl_qt.cpp +++ b/src/core/ozone/gl_surface_egl_qt.cpp @@ -28,7 +28,10 @@ namespace gl { bool GLDisplayEGL::InitializeExtensionSettings() { - return GLSurfaceEGLQt::InitializeExtensionSettingsOneOff(); + if (display_ == EGL_NO_DISPLAY) + return false; + ext->UpdateConditionalExtensionSettings(display_); + return true; } GLDisplayEGL *GLDisplayEGL::GetDisplayForCurrentContext() @@ -54,6 +57,13 @@ bool GLDisplayEGL::Initialize(gl::EGLDisplayPlatform native_display) if (glDisplay) { display_ = glDisplay->GetDisplay(); native_display_ = native_display; + std::string platform_extensions(ext->GetPlatformExtensions(display_)); + gfx::ExtensionSet extensions(gfx::MakeExtensionSet(platform_extensions)); + ext->b_EGL_EXT_image_dma_buf_import = + gfx::HasExtension(extensions, "EGL_EXT_image_dma_buf_import"); + ext->b_EGL_EXT_image_dma_buf_import_modifiers = + gfx::HasExtension(extensions, "EGL_EXT_image_dma_buf_import_modifiers"); +// ext->InitializeExtensionSettings(display_); Not functional for us at this moment } return glDisplay; @@ -265,7 +275,7 @@ void* GLSurfacelessQtEGL::GetShareHandle() namespace gl { -std::string DisplayExtensionsEGL::GetPlatformExtensions(void*) +std::string DisplayExtensionsEGL::GetPlatformExtensions(EGLDisplay) { EGLDisplay display = GLContextHelper::getEGLDisplay(); if (display == EGL_NO_DISPLAY) 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 diff --git a/src/core/ozone/surface_factory_qt.cpp b/src/core/ozone/surface_factory_qt.cpp index 13c1a7b11..1b37c4a68 100644 --- a/src/core/ozone/surface_factory_qt.cpp +++ b/src/core/ozone/surface_factory_qt.cpp @@ -6,8 +6,15 @@ #include "ozone/gl_context_qt.h" #include "ozone/gl_ozone_egl_qt.h" + +#include "media/gpu/buildflags.h" +#include "ui/gfx/linux/native_pixmap_dmabuf.h" + #if defined(USE_GLX) #include "ozone/gl_ozone_glx_qt.h" + +#include "ui/gfx/linux/gbm_buffer.h" +#include "ui/gfx/linux/gpu_memory_buffer_support_x11.h" #endif #include "qtwebenginecoreglobal_p.h" @@ -28,8 +35,8 @@ SurfaceFactoryQt::SurfaceFactoryQt() } else #endif if (GLContextHelper::getEglPlatformInterface()) { - m_impl = { gl::GLImplementationParts(gl::kGLImplementationDesktopGL), - gl::GLImplementationParts(gl::kGLImplementationEGLGLES2), + m_impl = { gl::GLImplementationParts(gl::kGLImplementationEGLGLES2), + gl::GLImplementationParts(gl::kGLImplementationDesktopGL), gl::GLImplementationParts(gl::kGLImplementationDisabled) }; m_ozone.reset(new ui::GLOzoneEGLQt()); } else { @@ -59,6 +66,84 @@ SurfaceFactoryQt::CreateVulkanImplementation(bool /*allow_protected_memory*/, } #endif +bool SurfaceFactoryQt::CanCreateNativePixmapForFormat(gfx::BufferFormat format) +{ +#if BUILDFLAG(USE_VAAPI) +#if defined(USE_GLX) + if (GLContextHelper::getGlxPlatformInterface()) + return ui::GpuMemoryBufferSupportX11::GetInstance()->CanCreateNativePixmapForFormat(format); +#endif + return ui::SurfaceFactoryOzone::CanCreateNativePixmapForFormat(format); +#else // !BUILDFLAG(USE_VAAPI) + return false; +#endif // BUILDFLAG(USE_VAAPI) +} + +scoped_refptr<gfx::NativePixmap> SurfaceFactoryQt::CreateNativePixmap( + gfx::AcceleratedWidget widget, + gpu::VulkanDeviceQueue *device_queue, + gfx::Size size, + gfx::BufferFormat format, + gfx::BufferUsage usage, + absl::optional<gfx::Size> framebuffer_size) +{ + if (framebuffer_size && !gfx::Rect(size).Contains(gfx::Rect(*framebuffer_size))) + return nullptr; +#if defined(USE_GLX) && BUILDFLAG(USE_VAAPI) + if (GLContextHelper::getGlxPlatformInterface()) { + scoped_refptr<gfx::NativePixmapDmaBuf> pixmap; + auto buffer = ui::GpuMemoryBufferSupportX11::GetInstance()->CreateBuffer(format, size, usage); + if (buffer) { + gfx::NativePixmapHandle handle = buffer->ExportHandle(); + pixmap = base::MakeRefCounted<gfx::NativePixmapDmaBuf>(size, format, std::move(handle)); + } + // CreateNativePixmap is non-blocking operation. Thus, it is safe to call it + // and return the result with the provided callback. + return pixmap; + } +#endif + // FIXME: No EGL implementation. + return nullptr; +} + +void SurfaceFactoryQt::CreateNativePixmapAsync( + gfx::AcceleratedWidget widget, + gpu::VulkanDeviceQueue *device_queue, + gfx::Size size, + gfx::BufferFormat format, + gfx::BufferUsage usage, + NativePixmapCallback callback) +{ + // CreateNativePixmap is non-blocking operation. Thus, it is safe to call it + // and return the result with the provided callback. + std::move(callback).Run(CreateNativePixmap(widget, device_queue, size, format, usage)); +} + +scoped_refptr<gfx::NativePixmap> +SurfaceFactoryQt::CreateNativePixmapFromHandle( + gfx::AcceleratedWidget /*widget*/, + gfx::Size size, + gfx::BufferFormat format, + gfx::NativePixmapHandle handle) +{ +#if BUILDFLAG(USE_VAAPI) +#if defined(USE_GLX) + if (GLContextHelper::getGlxPlatformInterface()) { + scoped_refptr<gfx::NativePixmapDmaBuf> pixmap; + auto buffer = ui::GpuMemoryBufferSupportX11::GetInstance()->CreateBufferFromHandle(size, format, std::move(handle)); + if (buffer) { + gfx::NativePixmapHandle buffer_handle = buffer->ExportHandle(); + pixmap = base::MakeRefCounted<gfx::NativePixmapDmaBuf>(size, format, std::move(buffer_handle)); + } + return pixmap; + } +#endif + if (GLContextHelper::getEglPlatformInterface()) + return base::MakeRefCounted<gfx::NativePixmapDmaBuf>(size, format, std::move(handle)); +#endif + return nullptr; +} + } // namespace QtWebEngineCore #endif // defined(USE_OZONE) diff --git a/src/core/ozone/surface_factory_qt.h b/src/core/ozone/surface_factory_qt.h index bfcfa014b..f85e3e0b4 100644 --- a/src/core/ozone/surface_factory_qt.h +++ b/src/core/ozone/surface_factory_qt.h @@ -20,6 +20,26 @@ public: std::unique_ptr<gpu::VulkanImplementation> CreateVulkanImplementation(bool allow_protected_memory, bool enforce_protected_memory) override; #endif + bool CanCreateNativePixmapForFormat(gfx::BufferFormat format) override; + scoped_refptr<gfx::NativePixmap> CreateNativePixmap( + gfx::AcceleratedWidget widget, + gpu::VulkanDeviceQueue* device_queue, + gfx::Size size, + gfx::BufferFormat format, + gfx::BufferUsage usage, + absl::optional<gfx::Size> framebuffer_size = absl::nullopt) override; + void CreateNativePixmapAsync(gfx::AcceleratedWidget widget, + gpu::VulkanDeviceQueue* device_queue, + gfx::Size size, + gfx::BufferFormat format, + gfx::BufferUsage usage, + NativePixmapCallback callback) override; + scoped_refptr<gfx::NativePixmap> CreateNativePixmapFromHandle( + gfx::AcceleratedWidget widget, + gfx::Size size, + gfx::BufferFormat format, + gfx::NativePixmapHandle handle) override; + private: std::vector<gl::GLImplementationParts> m_impl; std::unique_ptr<ui::GLOzone> m_ozone; |