From a56ea1e9cf1004d475932dc954c9cc494fbf32b1 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Thu, 6 Mar 2025 09:56:13 +0100 Subject: [PATCH] Add "default" and "gl" ANGLE implementation support to Ozone The EGL_EXT_image_dma_buf_import display extension is not available for non EGL display thus importing NativePixmap with EGL is not possible. Make possible to import NativePixmap as X11 pixmap. This makes --webEngineArgs --use-gl=angle --webEngineArgs --use-gl=angle --use-angle=default --webEngineArgs --use-gl=angle --use-angle=gl configurations work on Linux. Pick-to: 6.8 Task-number: QTBUG-129769 Task-number: QTBUG-133570 Change-Id: Ic6a40de373c5fd27c62abc3effb2f3ddee9210a8 Reviewed-by: Moss Heim Reviewed-by: Allan Sandfeld Jensen (cherry picked from commit 75b0d12f6a7f506d8d06a96ab4aa77d89358becd) Reviewed-by: Qt Cherry-pick Bot --- src/core/configure/BUILD.root.gn.in | 3 ++ src/core/ozone/gl_ozone_angle_qt.cpp | 62 ++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/core/configure/BUILD.root.gn.in b/src/core/configure/BUILD.root.gn.in index a63d9d8db..214ef6e71 100644 --- a/src/core/configure/BUILD.root.gn.in +++ b/src/core/configure/BUILD.root.gn.in @@ -405,11 +405,14 @@ source_set("qtwebengine_sources") { deps += [ "//ui/base/x:gl", "//ui/gfx/linux:gpu_memory_buffer_support_x11", + "//ui/gfx/x", ] sources += [ "//ui/ozone/platform/x11/gl_egl_utility_x11.cc", "//ui/ozone/platform/x11/gl_egl_utility_x11.h", + "//ui/ozone/platform/x11/native_pixmap_egl_x11_binding.cc", + "//ui/ozone/platform/x11/native_pixmap_egl_x11_binding.h", ] } } diff --git a/src/core/ozone/gl_ozone_angle_qt.cpp b/src/core/ozone/gl_ozone_angle_qt.cpp index b23f3c60f..359d04a45 100644 --- a/src/core/ozone/gl_ozone_angle_qt.cpp +++ b/src/core/ozone/gl_ozone_angle_qt.cpp @@ -1,6 +1,10 @@ -// Copyright (C) 2024 The Qt Company Ltd. +// Copyright (C) 2025 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// Copyright 2016 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #include "gl_ozone_angle_qt.h" #include "ui/base/ozone_buildflags.h" @@ -12,6 +16,8 @@ #if BUILDFLAG(IS_OZONE_X11) #include "ozone_util_qt.h" + +#include "ui/ozone/platform/x11/native_pixmap_egl_x11_binding.h" #endif extern "C" { @@ -20,6 +26,34 @@ extern __eglMustCastToProperFunctionPointerType EGL_GetProcAddress(const char *p } namespace ui { +namespace { +// Based on //ui/ozone/platform/x11/x11_surface_factory.cc +enum class NativePixmapSupportType { + // Importing native pixmaps not supported. + kNone, + + // Native pixmaps are imported directly into EGL using the + // EGL_EXT_image_dma_buf_import extension. + kDMABuf, + + // Native pixmaps are first imported as X11 pixmaps using DRI3 and then into + // EGL. + kX11Pixmap, +}; + +NativePixmapSupportType GetNativePixmapSupportType() +{ + if (gl::GLSurfaceEGL::GetGLDisplayEGL()->ext->b_EGL_EXT_image_dma_buf_import) + return NativePixmapSupportType::kDMABuf; + +#if BUILDFLAG(IS_OZONE_X11) + if (NativePixmapEGLX11Binding::CanImportNativeGLXPixmap()) + return NativePixmapSupportType::kX11Pixmap; +#endif + + return NativePixmapSupportType::kNone; +} +} // namespace bool GLOzoneANGLEQt::LoadGLES2Bindings(const gl::GLImplementationParts & /*implementation*/) { @@ -73,7 +107,16 @@ gl::EGLDisplayPlatform GLOzoneANGLEQt::GetNativeDisplay() bool GLOzoneANGLEQt::CanImportNativePixmap(gfx::BufferFormat format) { - return gl::GLSurfaceEGL::GetGLDisplayEGL()->ext->b_EGL_EXT_image_dma_buf_import; + switch (GetNativePixmapSupportType()) { + case NativePixmapSupportType::kDMABuf: + return NativePixmapEGLBinding::IsBufferFormatSupported(format); +#if BUILDFLAG(IS_OZONE_X11) + case NativePixmapSupportType::kX11Pixmap: + return NativePixmapEGLX11Binding::IsBufferFormatSupported(format); +#endif + default: + return false; + } } std::unique_ptr @@ -82,8 +125,19 @@ GLOzoneANGLEQt::ImportNativePixmap(scoped_refptr pixmap, gfx::Size plane_size, const gfx::ColorSpace &color_space, GLenum target, GLuint texture_id) { - return NativePixmapEGLBinding::Create(pixmap, plane_format, plane, plane_size, color_space, - target, texture_id); + switch (GetNativePixmapSupportType()) { + case NativePixmapSupportType::kDMABuf: + return NativePixmapEGLBinding::Create(pixmap, plane_format, plane, plane_size, color_space, + target, texture_id); +#if BUILDFLAG(IS_OZONE_X11) + case NativePixmapSupportType::kX11Pixmap: + return NativePixmapEGLX11Binding::Create(pixmap, plane_format, plane_size, target, + texture_id); +#endif + default: + NOTREACHED(); + return nullptr; + } } } // namespace ui -- 2.49.0