Commit 344a078a authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Chromium LUCI CQ

[ozone/x11] Extracted the GPU data manager visual proxy.

This is [1] replicated over the fresh ToT.

There is a proxy class that ensures that GPU sends back correct visuals
on X11.  The class was declared in the anonymous namespace in the
content/browser/browser_main_loop.cc, which made it impossible to use
on Ozone.

This CL extracts the proxy and makes it available to use through the
PlatformGLEGLUtility interface.

In addition, the obsolete VisualID type used in gfx::GpuExtraInfo is
replaced with the x11::VisualId.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2252102

Bug: 789065
Change-Id: I6390ef8bc89cf118944be42fde78fd64a6c3d36d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2562182Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Cr-Commit-Position: refs/heads/master@{#837069}
parent 47582a8f
...@@ -7,6 +7,7 @@ import("//build/config/chromeos/ui_mode.gni") ...@@ -7,6 +7,7 @@ import("//build/config/chromeos/ui_mode.gni")
import("//build/config/chromeos/ui_mode.gni") import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni") import("//build/config/features.gni")
import("//build/config/linux/pangocairo/pangocairo.gni") import("//build/config/linux/pangocairo/pangocairo.gni")
import("//build/config/ozone.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
import("//chromeos/assistant/assistant.gni") import("//chromeos/assistant/assistant.gni")
import("//components/ui_devtools/devtools.gni") import("//components/ui_devtools/devtools.gni")
...@@ -2095,6 +2096,10 @@ source_set("browser") { ...@@ -2095,6 +2096,10 @@ source_set("browser") {
deps += [ "//ui/base/x" ] deps += [ "//ui/base/x" ]
} }
if (use_ozone) {
deps += [ "//ui/ozone:buildflags" ]
}
if (is_linux || is_chromeos) { if (is_linux || is_chromeos) {
sources += [ sources += [
"child_process_launcher_helper_linux.cc", "child_process_launcher_helper_linux.cc",
...@@ -2112,6 +2117,16 @@ source_set("browser") { ...@@ -2112,6 +2117,16 @@ source_set("browser") {
"zygote_host/zygote_host_impl_linux.h", "zygote_host/zygote_host_impl_linux.h",
] ]
if (ozone_platform_x11 || use_x11) {
sources += [
"gpu_data_manager_visual_proxy_ozone_linux.cc",
"gpu_data_manager_visual_proxy_ozone_linux.h",
]
if (use_x11) {
deps += [ "//ui/base/x:gl" ]
}
}
public_deps += [ "//components/services/font/public/mojom" ] public_deps += [ "//components/services/font/public/mojom" ]
deps += [ deps += [
......
...@@ -135,9 +135,16 @@ specific_include_rules = { ...@@ -135,9 +135,16 @@ specific_include_rules = {
# TODO(crbug.com/1049894): Remove. # TODO(crbug.com/1049894): Remove.
"+services/network/transitional_url_loader_factory_owner.h", "+services/network/transitional_url_loader_factory_owner.h",
], ],
"browser_main_loop\.h": [
"+ui/ozone/buildflags.h",
],
"browsing_data_(filter_builder|remover)_impl_unittest\.cc": [ "browsing_data_(filter_builder|remover)_impl_unittest\.cc": [
"+services/network/cookie_manager.h", "+services/network/cookie_manager.h",
], ],
"gpu_data_manager_visual_proxy_ozone_linux\.(cc|h)": [
"+ui/ozone/public/ozone_platform.h",
"+ui/ozone/public/platform_gl_egl_utility.h",
],
"navigation_url_loader_impl_unittest\.cc": [ "navigation_url_loader_impl_unittest\.cc": [
"+services/network/resource_scheduler/resource_scheduler_client.h", "+services/network/resource_scheduler/resource_scheduler_client.h",
"+services/network/url_loader.h", "+services/network/url_loader.h",
......
...@@ -103,7 +103,6 @@ ...@@ -103,7 +103,6 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/browser/device_service.h" #include "content/public/browser/device_service.h"
#include "content/public/browser/gpu_data_manager_observer.h"
#include "content/public/browser/network_service_instance.h" #include "content/public/browser/network_service_instance.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/service_process_host.h" #include "content/public/browser/service_process_host.h"
...@@ -193,6 +192,10 @@ ...@@ -193,6 +192,10 @@
#include <glib-object.h> #include <glib-object.h>
#endif #endif
#if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
#include "content/browser/gpu_data_manager_visual_proxy_ozone_linux.h"
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
#include "media/device_monitors/system_message_window_win.h" #include "media/device_monitors/system_message_window_win.h"
#include "sandbox/win/src/process_mitigations.h" #include "sandbox/win/src/process_mitigations.h"
...@@ -430,51 +433,6 @@ void BindHidManager(mojo::PendingReceiver<device::mojom::HidManager> receiver) { ...@@ -430,51 +433,6 @@ void BindHidManager(mojo::PendingReceiver<device::mojom::HidManager> receiver) {
} // namespace } // namespace
#if defined(USE_X11)
namespace internal {
// Forwards GPUInfo updates to ui::XVisualManager
class GpuDataManagerVisualProxy : public GpuDataManagerObserver {
public:
explicit GpuDataManagerVisualProxy(GpuDataManagerImpl* gpu_data_manager)
: gpu_data_manager_(gpu_data_manager) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless))
data_manager_observation_.Observe(gpu_data_manager_);
}
~GpuDataManagerVisualProxy() override = default;
void OnGpuInfoUpdate() override { OnUpdate(); }
void OnGpuExtraInfoUpdate() override { OnUpdate(); }
private:
void OnUpdate() {
gpu::GPUInfo gpu_info = gpu_data_manager_->GetGPUInfo();
gfx::GpuExtraInfo gpu_extra_info = gpu_data_manager_->GetGpuExtraInfo();
if (!ui::XVisualManager::GetInstance()->OnGPUInfoChanged(
gpu_info.software_rendering ||
!gpu_data_manager_->GpuAccessAllowed(nullptr),
static_cast<x11::VisualId>(gpu_extra_info.system_visual),
static_cast<x11::VisualId>(gpu_extra_info.rgba_visual))) {
// The GPU process sent back bad visuals, which should never happen.
auto* gpu_process_host =
GpuProcessHost::Get(GPU_PROCESS_KIND_SANDBOXED, false);
if (gpu_process_host)
gpu_process_host->ForceShutdown();
}
}
GpuDataManagerImpl* gpu_data_manager_;
base::ScopedObservation<GpuDataManagerImpl, GpuDataManagerObserver>
data_manager_observation_{this};
DISALLOW_COPY_AND_ASSIGN(GpuDataManagerVisualProxy);
};
} // namespace internal
#endif
// The currently-running BrowserMainLoop. There can be one or zero. // The currently-running BrowserMainLoop. There can be one or zero.
BrowserMainLoop* g_current_browser_main_loop = nullptr; BrowserMainLoop* g_current_browser_main_loop = nullptr;
...@@ -827,12 +785,13 @@ int BrowserMainLoop::PreCreateThreads() { ...@@ -827,12 +785,13 @@ int BrowserMainLoop::PreCreateThreads() {
GpuDataManagerImpl::GetInstance(); GpuDataManagerImpl::GetInstance();
DCHECK(GpuDataManagerImpl::Initialized()); DCHECK(GpuDataManagerImpl::Initialized());
#if defined(USE_X11) // Temporarily used by both Ozone/Linux and X11/Linux. Once X11/Linux goes
if (!features::IsUsingOzonePlatform()) { // away, will be used only by Ozone/Linux.
gpu_data_manager_visual_proxy_.reset( // TODO(https://crbug.com/1085700): make sure it's only used by Ozone/Linux.
new internal::GpuDataManagerVisualProxy( #if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
GpuDataManagerImpl::GetInstance())); gpu_data_manager_visual_proxy_ =
} std::make_unique<GpuDataManagerVisualProxyOzoneLinux>(
GpuDataManagerImpl::GetInstance());
#endif #endif
#if !BUILDFLAG(GOOGLE_CHROME_BRANDING) || defined(OS_ANDROID) #if !BUILDFLAG(GOOGLE_CHROME_BRANDING) || defined(OS_ANDROID)
......
...@@ -30,6 +30,13 @@ class Env; ...@@ -30,6 +30,13 @@ class Env;
} }
#endif #endif
#if defined(USE_OZONE)
#include "ui/ozone/buildflags.h" // nogncheck
#if BUILDFLAG(OZONE_PLATFORM_X11)
#define USE_OZONE_PLATFORM_X11
#endif
#endif
namespace base { namespace base {
class CommandLine; class CommandLine;
class HighResolutionTimerManager; class HighResolutionTimerManager;
...@@ -102,10 +109,8 @@ class Watcher; ...@@ -102,10 +109,8 @@ class Watcher;
class ScreenOrientationDelegate; class ScreenOrientationDelegate;
#endif #endif
#if defined(USE_X11) #if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
namespace internal { class GpuDataManagerVisualProxyOzoneLinux;
class GpuDataManagerVisualProxy;
}
#endif #endif
// Implements the main browser loop stages called from BrowserMainRunner. // Implements the main browser loop stages called from BrowserMainRunner.
...@@ -331,8 +336,8 @@ class CONTENT_EXPORT BrowserMainLoop { ...@@ -331,8 +336,8 @@ class CONTENT_EXPORT BrowserMainLoop {
// Members initialized in |PreCreateThreads()| ------------------------------- // Members initialized in |PreCreateThreads()| -------------------------------
// Torn down in ShutdownThreadsAndCleanUp. // Torn down in ShutdownThreadsAndCleanUp.
std::unique_ptr<base::MemoryPressureMonitor> memory_pressure_monitor_; std::unique_ptr<base::MemoryPressureMonitor> memory_pressure_monitor_;
#if defined(USE_X11) #if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
std::unique_ptr<internal::GpuDataManagerVisualProxy> std::unique_ptr<GpuDataManagerVisualProxyOzoneLinux>
gpu_data_manager_visual_proxy_; gpu_data_manager_visual_proxy_;
#endif #endif
......
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
namespace content { namespace content {
namespace { namespace {
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
bool GetGmbConfigFromGpu() { bool GetGmbConfigFromGpu() {
#if defined(USE_OZONE) #if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) { if (features::IsUsingOzonePlatform()) {
...@@ -412,7 +412,7 @@ std::unique_ptr<base::ListValue> GpuMemoryBufferInfo( ...@@ -412,7 +412,7 @@ std::unique_ptr<base::ListValue> GpuMemoryBufferInfo(
gpu::GpuMemoryBufferSupport gpu_memory_buffer_support; gpu::GpuMemoryBufferSupport gpu_memory_buffer_support;
gpu::GpuMemoryBufferConfigurationSet native_config; gpu::GpuMemoryBufferConfigurationSet native_config;
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
if (GetGmbConfigFromGpu()) { if (GetGmbConfigFromGpu()) {
for (const auto& config : gpu_extra_info.gpu_memory_buffer_support_x11) { for (const auto& config : gpu_extra_info.gpu_memory_buffer_support_x11) {
native_config.emplace(config); native_config.emplace(config);
......
...@@ -33,7 +33,7 @@ viz::mojom::GpuService* GetGpuService( ...@@ -33,7 +33,7 @@ viz::mojom::GpuService* GetGpuService(
return nullptr; return nullptr;
} }
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
bool ShouldSetBufferFormatsFromGpuExtraInfo() { bool ShouldSetBufferFormatsFromGpuExtraInfo() {
#if defined(USE_OZONE) #if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) { if (features::IsUsingOzonePlatform()) {
...@@ -73,7 +73,7 @@ GpuMemoryBufferManagerSingleton::GetInstance() { ...@@ -73,7 +73,7 @@ GpuMemoryBufferManagerSingleton::GetInstance() {
} }
void GpuMemoryBufferManagerSingleton::OnGpuExtraInfoUpdate() { void GpuMemoryBufferManagerSingleton::OnGpuExtraInfoUpdate() {
#if defined(USE_X11) || defined(USE_OZONE) #if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
// X11 and non-Ozone/X11 fetch buffer formats on gpu and pass them via gpu // X11 and non-Ozone/X11 fetch buffer formats on gpu and pass them via gpu
// extra info. // extra info.
if (!ShouldSetBufferFormatsFromGpuExtraInfo()) if (!ShouldSetBufferFormatsFromGpuExtraInfo())
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/gpu_data_manager_visual_proxy_ozone_linux.h"
#include "base/command_line.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "ui/gfx/switches.h"
#if defined(USE_OZONE)
#include "ui/base/ui_base_features.h"
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/platform_gl_egl_utility.h"
#endif
#if defined(USE_X11)
#include "ui/base/x/x11_gl_egl_utility.h" // nogncheck
#endif
namespace content {
#if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
namespace {
void ShutdownGpuOnIO() {
// The GPU process sent back bad visuals, which should never happen.
auto* gpu_process_host =
GpuProcessHost::Get(GPU_PROCESS_KIND_SANDBOXED, false);
if (gpu_process_host)
gpu_process_host->ForceShutdown();
}
} // namespace
#endif // defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
GpuDataManagerVisualProxyOzoneLinux::GpuDataManagerVisualProxyOzoneLinux(
GpuDataManagerImpl* gpu_data_manager)
: gpu_data_manager_(gpu_data_manager) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless))
scoped_observer_.Observe(gpu_data_manager_);
}
GpuDataManagerVisualProxyOzoneLinux::~GpuDataManagerVisualProxyOzoneLinux() =
default;
void GpuDataManagerVisualProxyOzoneLinux::OnGpuInfoUpdate() {
OnUpdate();
}
void GpuDataManagerVisualProxyOzoneLinux::OnGpuExtraInfoUpdate() {
OnUpdate();
}
void GpuDataManagerVisualProxyOzoneLinux::OnUpdate() {
#if defined(USE_OZONE)
// Early return for Ozone/non-X11. Otherwise UpdateVisualsOnGpuInfoChanged()
// will return false, thus terminating the GPU process and ruining things.
if (features::IsUsingOzonePlatform() &&
!ui::OzonePlatform::GetInstance()->GetPlatformGLEGLUtility()) {
return;
}
#endif
#if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
gpu::GPUInfo gpu_info = gpu_data_manager_->GetGPUInfo();
gfx::GpuExtraInfo gpu_extra_info = gpu_data_manager_->GetGpuExtraInfo();
if (!UpdateVisualsOnGpuInfoChanged(
gpu_info.software_rendering ||
!gpu_data_manager_->GpuAccessAllowed(nullptr),
gpu_extra_info.system_visual, gpu_extra_info.rgba_visual)) {
GetIOThreadTaskRunner({})->PostTask(FROM_HERE,
base::BindOnce(&ShutdownGpuOnIO));
}
#endif
}
bool GpuDataManagerVisualProxyOzoneLinux::UpdateVisualsOnGpuInfoChanged(
bool software_rendering,
x11::VisualId default_visual_id,
x11::VisualId transparent_visual_id) {
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform() &&
ui::OzonePlatform::GetInstance()->GetPlatformGLEGLUtility()) {
return ui::OzonePlatform::GetInstance()
->GetPlatformGLEGLUtility()
->UpdateVisualsOnGpuInfoChanged(
software_rendering, static_cast<uint32_t>(default_visual_id),
static_cast<uint32_t>(transparent_visual_id));
}
#endif
#if defined(USE_X11)
return ui::UpdateVisualsOnGpuInfoChanged(
software_rendering, default_visual_id, transparent_visual_id);
#endif
NOTREACHED() << "Only X11 may invoke this!";
return false;
}
} // namespace content
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_GPU_DATA_MANAGER_VISUAL_PROXY_OZONE_LINUX_H_
#define CONTENT_BROWSER_GPU_DATA_MANAGER_VISUAL_PROXY_OZONE_LINUX_H_
#include "base/scoped_observation.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/public/browser/gpu_data_manager_observer.h"
#include "ui/gfx/gpu_extra_info.h"
namespace content {
// Forwards GPUInfo updates to ui::XVisualManager on X11 (will be removed as
// soon as Ozone is default on Linux) or PlatformEGLGLUtility.
class GpuDataManagerVisualProxyOzoneLinux : public GpuDataManagerObserver {
public:
explicit GpuDataManagerVisualProxyOzoneLinux(
GpuDataManagerImpl* gpu_data_manager);
GpuDataManagerVisualProxyOzoneLinux(
const GpuDataManagerVisualProxyOzoneLinux&) = delete;
GpuDataManagerVisualProxyOzoneLinux& operator=(
const GpuDataManagerVisualProxyOzoneLinux&) = delete;
~GpuDataManagerVisualProxyOzoneLinux() override;
void OnGpuInfoUpdate() override;
void OnGpuExtraInfoUpdate() override;
private:
void OnUpdate();
bool UpdateVisualsOnGpuInfoChanged(bool software_rendering,
x11::VisualId default_visual_id,
x11::VisualId transparent_visual_id);
GpuDataManagerImpl* gpu_data_manager_;
base::ScopedObservation<GpuDataManagerImpl, GpuDataManagerObserver>
scoped_observer_{this};
};
} // namespace content
#endif // CONTENT_BROWSER_GPU_DATA_MANAGER_VISUAL_PROXY_OZONE_LINUX_H_
...@@ -122,7 +122,13 @@ IN_PROC_BROWSER_TEST_F(AppWindowApiTest, SetShapeNoPerm) { ...@@ -122,7 +122,13 @@ IN_PROC_BROWSER_TEST_F(AppWindowApiTest, SetShapeNoPerm) {
<< message_; << message_;
} }
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlphaEnabledHasPermissions) { // Fails on Ozone/X11. https://crbug.com/1109112
#if defined(USE_OZONE)
#define MAYBE_AlphaEnabledHasPermissions DISABLED_AlphaEnabledHasPermissions
#else
#define MAYBE_AlphaEnabledHasPermissions AlphaEnabledHasPermissions
#endif
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, MAYBE_AlphaEnabledHasPermissions) {
const char kNoAlphaDir[] = const char kNoAlphaDir[] =
"platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha"; "platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha";
const char kHasAlphaDir[] = const char kHasAlphaDir[] =
......
...@@ -39,7 +39,7 @@ void GetPlatformExtraDisplayAttribs(EGLenum platform_type, ...@@ -39,7 +39,7 @@ void GetPlatformExtraDisplayAttribs(EGLenum platform_type,
// get it anyway. // get it anyway.
if (platform_type != EGL_PLATFORM_ANGLE_TYPE_NULL_ANGLE) { if (platform_type != EGL_PLATFORM_ANGLE_TYPE_NULL_ANGLE) {
x11::VisualId visual_id; x11::VisualId visual_id;
ui::XVisualManager::GetInstance()->ChooseVisualForWindow( XVisualManager::GetInstance()->ChooseVisualForWindow(
true, &visual_id, nullptr, nullptr, nullptr); true, &visual_id, nullptr, nullptr, nullptr);
attributes->push_back(EGL_X11_VISUAL_ID_ANGLE); attributes->push_back(EGL_X11_VISUAL_ID_ANGLE);
attributes->push_back(static_cast<EGLAttrib>(visual_id)); attributes->push_back(static_cast<EGLAttrib>(visual_id));
...@@ -54,8 +54,8 @@ void ChoosePlatformCustomAlphaAndBufferSize(EGLint* alpha_size, ...@@ -54,8 +54,8 @@ void ChoosePlatformCustomAlphaAndBufferSize(EGLint* alpha_size,
// can't use XVisualManager. // can't use XVisualManager.
if (gl::GLSurfaceEGL::GetNativeDisplay() != EGL_DEFAULT_DISPLAY) { if (gl::GLSurfaceEGL::GetNativeDisplay() != EGL_DEFAULT_DISPLAY) {
uint8_t depth; uint8_t depth;
ui::XVisualManager::GetInstance()->ChooseVisualForWindow( XVisualManager::GetInstance()->ChooseVisualForWindow(true, nullptr, &depth,
true, nullptr, &depth, nullptr, nullptr); nullptr, nullptr);
*buffer_size = depth; *buffer_size = depth;
*alpha_size = *buffer_size == 32 ? 8 : 0; *alpha_size = *buffer_size == 32 ? 8 : 0;
} }
...@@ -65,4 +65,11 @@ bool IsTransparentBackgroundSupported() { ...@@ -65,4 +65,11 @@ bool IsTransparentBackgroundSupported() {
return ui::XVisualManager::GetInstance()->ArgbVisualAvailable(); return ui::XVisualManager::GetInstance()->ArgbVisualAvailable();
} }
bool UpdateVisualsOnGpuInfoChanged(bool software_rendering,
x11::VisualId default_visual_id,
x11::VisualId transparent_visual_id) {
return XVisualManager::GetInstance()->UpdateVisualsOnGpuInfoChanged(
software_rendering, default_visual_id, transparent_visual_id);
}
} // namespace ui } // namespace ui
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include "third_party/khronos/EGL/egl.h" #include "third_party/khronos/EGL/egl.h"
#include "ui/gfx/x/xproto.h"
namespace ui { namespace ui {
...@@ -22,6 +23,12 @@ void ChoosePlatformCustomAlphaAndBufferSize(EGLint* alpha_size, ...@@ -22,6 +23,12 @@ void ChoosePlatformCustomAlphaAndBufferSize(EGLint* alpha_size,
// Returns whether transparent background is suppored. // Returns whether transparent background is suppored.
bool IsTransparentBackgroundSupported(); bool IsTransparentBackgroundSupported();
// Wraps XVisualManager::UpdateVisualsOnGpuInfoChanged(), passes parameters to
// it directly. Returns whether provided visuals are valid.
bool UpdateVisualsOnGpuInfoChanged(bool software_rendering,
x11::VisualId default_visual_id,
x11::VisualId transparent_visual_id);
} // namespace ui } // namespace ui
#endif // UI_BASE_X_X11_GL_EGL_UTILITY_H_ #endif // UI_BASE_X_X11_GL_EGL_UTILITY_H_
...@@ -1019,8 +1019,8 @@ void SuspendX11ScreenSaver(bool suspend) { ...@@ -1019,8 +1019,8 @@ void SuspendX11ScreenSaver(bool suspend) {
x11::Connection::Get()->screensaver().Suspend({suspend}); x11::Connection::Get()->screensaver().Suspend({suspend});
} }
base::Value GpuExtraInfoAsListValue(unsigned long system_visual, base::Value GpuExtraInfoAsListValue(x11::VisualId system_visual,
unsigned long rgba_visual) { x11::VisualId rgba_visual) {
base::Value result(base::Value::Type::LIST); base::Value result(base::Value::Type::LIST);
result.Append( result.Append(
NewDescriptionValuePair("Window manager", ui::GuessWindowManagerName())); NewDescriptionValuePair("Window manager", ui::GuessWindowManagerName()));
...@@ -1037,10 +1037,12 @@ base::Value GpuExtraInfoAsListValue(unsigned long system_visual, ...@@ -1037,10 +1037,12 @@ base::Value GpuExtraInfoAsListValue(unsigned long system_visual,
"Compositing manager", "Compositing manager",
ui::IsCompositingManagerPresent() ? "Yes" : "No")); ui::IsCompositingManagerPresent() ? "Yes" : "No"));
} }
result.Append(NewDescriptionValuePair("System visual ID", result.Append(NewDescriptionValuePair(
base::NumberToString(system_visual))); "System visual ID",
result.Append(NewDescriptionValuePair("RGBA visual ID", base::NumberToString(static_cast<uint32_t>(system_visual))));
base::NumberToString(rgba_visual))); result.Append(NewDescriptionValuePair(
"RGBA visual ID",
base::NumberToString(static_cast<uint32_t>(rgba_visual))));
return result; return result;
} }
...@@ -1239,9 +1241,10 @@ bool XVisualManager::GetVisualInfo(x11::VisualId visual_id, ...@@ -1239,9 +1241,10 @@ bool XVisualManager::GetVisualInfo(x11::VisualId visual_id,
return GetVisualInfoImpl(visual_id, depth, colormap, visual_has_alpha); return GetVisualInfoImpl(visual_id, depth, colormap, visual_has_alpha);
} }
bool XVisualManager::OnGPUInfoChanged(bool software_rendering, bool XVisualManager::UpdateVisualsOnGpuInfoChanged(
x11::VisualId system_visual_id, bool software_rendering,
x11::VisualId transparent_visual_id) { x11::VisualId system_visual_id,
x11::VisualId transparent_visual_id) {
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
// TODO(thomasanderson): Cache these visual IDs as a property of the root // TODO(thomasanderson): Cache these visual IDs as a property of the root
// window so that newly created browser processes can get them immediately. // window so that newly created browser processes can get them immediately.
......
...@@ -522,8 +522,8 @@ COMPONENT_EXPORT(UI_BASE_X) void SuspendX11ScreenSaver(bool suspend); ...@@ -522,8 +522,8 @@ COMPONENT_EXPORT(UI_BASE_X) void SuspendX11ScreenSaver(bool suspend);
// Returns human readable description of the window manager, desktop, and // Returns human readable description of the window manager, desktop, and
// other system properties related to the compositing. // other system properties related to the compositing.
COMPONENT_EXPORT(UI_BASE_X) COMPONENT_EXPORT(UI_BASE_X)
base::Value GpuExtraInfoAsListValue(unsigned long system_visual, base::Value GpuExtraInfoAsListValue(x11::VisualId system_visual,
unsigned long rgba_visual); x11::VisualId rgba_visual);
// Returns true if the window manager supports the given hint. // Returns true if the window manager supports the given hint.
COMPONENT_EXPORT(UI_BASE_X) bool WmSupportsHint(x11::Atom atom); COMPONENT_EXPORT(UI_BASE_X) bool WmSupportsHint(x11::Atom atom);
...@@ -579,9 +579,9 @@ class COMPONENT_EXPORT(UI_BASE_X) XVisualManager { ...@@ -579,9 +579,9 @@ class COMPONENT_EXPORT(UI_BASE_X) XVisualManager {
// necessary for the GPU process to find out which visuals are best for GL // necessary for the GPU process to find out which visuals are best for GL
// because we don't want to load GL in the browser process. Returns false iff // because we don't want to load GL in the browser process. Returns false iff
// |default_visual_id| or |transparent_visual_id| are invalid. // |default_visual_id| or |transparent_visual_id| are invalid.
bool OnGPUInfoChanged(bool software_rendering, bool UpdateVisualsOnGpuInfoChanged(bool software_rendering,
x11::VisualId default_visual_id, x11::VisualId default_visual_id,
x11::VisualId transparent_visual_id); x11::VisualId transparent_visual_id);
// Are all of the system requirements met for using transparent visuals? // Are all of the system requirements met for using transparent visuals?
bool ArgbVisualAvailable() const; bool ArgbVisualAvailable() const;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//build/config/ozone.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
import("//device/vr/buildflags/buildflags.gni") import("//device/vr/buildflags/buildflags.gni")
import("//testing/libfuzzer/fuzzer_test.gni") import("//testing/libfuzzer/fuzzer_test.gni")
...@@ -407,7 +408,11 @@ component("gfx") { ...@@ -407,7 +408,11 @@ component("gfx") {
] ]
} }
if (use_x11) { if (use_ozone) {
deps += [ "//ui/ozone:buildflags" ]
}
if (ozone_platform_x11 || use_x11) {
deps += [ "//ui/gfx/x" ] deps += [ "//ui/gfx/x" ]
} }
} }
......
...@@ -7,6 +7,7 @@ include_rules = [ ...@@ -7,6 +7,7 @@ include_rules = [
"+third_party/harfbuzz-ng", "+third_party/harfbuzz-ng",
"+third_party/skia", "+third_party/skia",
"+ui/ios", "+ui/ios",
"+ui/ozone/buildflags.h",
"-testing/gmock", "-testing/gmock",
] ]
...@@ -11,8 +11,15 @@ ...@@ -11,8 +11,15 @@
#include "ui/gfx/buffer_types.h" #include "ui/gfx/buffer_types.h"
#include "ui/gfx/gfx_export.h" #include "ui/gfx/gfx_export.h"
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_OZONE)
typedef unsigned long VisualID; #include "ui/ozone/buildflags.h"
#if BUILDFLAG(OZONE_PLATFORM_X11)
#define USE_OZONE_PLATFORM_X11
#endif
#endif
#if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
#include "ui/gfx/x/xproto.h"
#endif #endif
namespace gfx { namespace gfx {
...@@ -58,9 +65,9 @@ struct GFX_EXPORT GpuExtraInfo { ...@@ -58,9 +65,9 @@ struct GFX_EXPORT GpuExtraInfo {
// applicable. // applicable.
ANGLEFeatures angle_features; ANGLEFeatures angle_features;
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_X11) || defined(USE_OZONE_PLATFORM_X11)
VisualID system_visual = 0; x11::VisualId system_visual{};
VisualID rgba_visual = 0; x11::VisualId rgba_visual{};
std::vector<gfx::BufferUsageAndFormat> gpu_memory_buffer_support_x11; std::vector<gfx::BufferUsageAndFormat> gpu_memory_buffer_support_x11;
#endif #endif
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//build/config/ozone.gni")
import("//mojo/public/tools/bindings/mojom.gni") import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") { mojom("mojom") {
...@@ -33,7 +34,7 @@ mojom("mojom") { ...@@ -33,7 +34,7 @@ mojom("mojom") {
] ]
enabled_features = [] enabled_features = []
if (use_x11 || use_ozone) { if (use_x11 || ozone_platform_x11) {
enabled_features += [ "enable_x11_params" ] enabled_features += [ "enable_x11_params" ]
} }
...@@ -329,6 +330,9 @@ component("shared_mojom_traits") { ...@@ -329,6 +330,9 @@ component("shared_mojom_traits") {
":native_handle_types", ":native_handle_types",
"//ui/gfx", "//ui/gfx",
] ]
if (use_ozone) {
public_deps += [ "//ui/ozone:buildflags" ]
}
frameworks = [ frameworks = [
"CoreFoundation.framework", "CoreFoundation.framework",
"IOSurface.framework", "IOSurface.framework",
......
...@@ -24,9 +24,15 @@ bool StructTraits<gfx::mojom::GpuExtraInfoDataView, gfx::GpuExtraInfo>::Read( ...@@ -24,9 +24,15 @@ bool StructTraits<gfx::mojom::GpuExtraInfoDataView, gfx::GpuExtraInfo>::Read(
gfx::GpuExtraInfo* out) { gfx::GpuExtraInfo* out) {
if (!data.ReadAngleFeatures(&out->angle_features)) if (!data.ReadAngleFeatures(&out->angle_features))
return false; return false;
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_OZONE_PLATFORM_X11) || defined(USE_X11)
out->system_visual = data.system_visual(); // These visuals below are obtained via methods of gl::GLVisualPickerGLX class
out->rgba_visual = data.rgba_visual(); // and consumed by ui::XVisualManager::UpdateVisualsOnGpuInfoChanged(); should
// bad visuals come there, the GPU process will be shut down.
//
// See content::GpuDataManagerVisualProxyOzoneLinux and the ShutdownGpuOnIO()
// function there.
out->system_visual = static_cast<x11::VisualId>(data.system_visual());
out->rgba_visual = static_cast<x11::VisualId>(data.rgba_visual());
if (!data.ReadGpuMemoryBufferSupportX11(&out->gpu_memory_buffer_support_x11)) if (!data.ReadGpuMemoryBufferSupportX11(&out->gpu_memory_buffer_support_x11))
return false; return false;
#endif #endif
......
...@@ -10,6 +10,13 @@ ...@@ -10,6 +10,13 @@
#include "ui/gfx/mojom/buffer_types_mojom_traits.h" #include "ui/gfx/mojom/buffer_types_mojom_traits.h"
#include "ui/gfx/mojom/gpu_extra_info.mojom-shared.h" #include "ui/gfx/mojom/gpu_extra_info.mojom-shared.h"
#if defined(USE_OZONE)
#include "ui/ozone/buildflags.h"
#if BUILDFLAG(OZONE_PLATFORM_X11)
#define USE_OZONE_PLATFORM_X11
#endif
#endif
namespace mojo { namespace mojo {
template <> template <>
...@@ -54,13 +61,13 @@ struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS) ...@@ -54,13 +61,13 @@ struct COMPONENT_EXPORT(GFX_SHARED_MOJOM_TRAITS)
return input.angle_features; return input.angle_features;
} }
#if defined(USE_OZONE) || defined(USE_X11) #if defined(USE_OZONE_PLATFORM_X11) || defined(USE_X11)
static uint64_t system_visual(const gfx::GpuExtraInfo& input) { static uint64_t system_visual(const gfx::GpuExtraInfo& input) {
return input.system_visual; return static_cast<uint64_t>(input.system_visual);
} }
static uint64_t rgba_visual(const gfx::GpuExtraInfo& input) { static uint64_t rgba_visual(const gfx::GpuExtraInfo& input) {
return input.rgba_visual; return static_cast<uint64_t>(input.rgba_visual);
} }
static const std::vector<gfx::BufferUsageAndFormat>& static const std::vector<gfx::BufferUsageAndFormat>&
......
...@@ -167,8 +167,8 @@ void CollectX11GpuExtraInfo(bool enable_native_gpu_memory_buffers, ...@@ -167,8 +167,8 @@ void CollectX11GpuExtraInfo(bool enable_native_gpu_memory_buffers,
// singleton is busy being created on another thread. // singleton is busy being created on another thread.
GLVisualPickerGLX* visual_picker = GLVisualPickerGLX::GetInstance(); GLVisualPickerGLX* visual_picker = GLVisualPickerGLX::GetInstance();
info.system_visual = static_cast<uint32_t>(visual_picker->system_visual()); info.system_visual = visual_picker->system_visual();
info.rgba_visual = static_cast<uint32_t>(visual_picker->rgba_visual()); info.rgba_visual = visual_picker->rgba_visual();
// With GLX, only BGR(A) buffer formats are supported. EGL does not have // With GLX, only BGR(A) buffer formats are supported. EGL does not have
// this restriction. // this restriction.
......
...@@ -90,6 +90,7 @@ component("ozone_base") { ...@@ -90,6 +90,7 @@ component("ozone_base") {
"public/ozone_switches.cc", "public/ozone_switches.cc",
"public/ozone_switches.h", "public/ozone_switches.h",
"public/platform_clipboard.h", "public/platform_clipboard.h",
"public/platform_gl_egl_utility.cc",
"public/platform_gl_egl_utility.h", "public/platform_gl_egl_utility.h",
"public/platform_menu_utils.cc", "public/platform_menu_utils.cc",
"public/platform_menu_utils.h", "public/platform_menu_utils.h",
...@@ -372,7 +373,7 @@ if (ozone_platform_x11) { ...@@ -372,7 +373,7 @@ if (ozone_platform_x11) {
buildflag_header("buildflags") { buildflag_header("buildflags") {
header = "buildflags.h" header = "buildflags.h"
flags = [ "OZONE_PLATFORM_X11=$ozone_platform_x11" ] flags = [ "OZONE_PLATFORM_X11=$ozone_platform_x11" ]
visibility += [ "//ui/gl:gl" ] visibility += [ "*" ]
} }
group("unittests") { group("unittests") {
......
...@@ -38,4 +38,17 @@ bool GLEGLUtilityX11::X11DoesVisualHaveAlphaForTest() const { ...@@ -38,4 +38,17 @@ bool GLEGLUtilityX11::X11DoesVisualHaveAlphaForTest() const {
return ui::DoesVisualHaveAlphaForTest(); return ui::DoesVisualHaveAlphaForTest();
} }
bool GLEGLUtilityX11::HasVisualManager() {
return true;
}
bool GLEGLUtilityX11::UpdateVisualsOnGpuInfoChanged(
bool software_rendering,
uint32_t default_visual_id,
uint32_t transparent_visual_id) {
return ui::UpdateVisualsOnGpuInfoChanged(
software_rendering, static_cast<x11::VisualId>(default_visual_id),
static_cast<x11::VisualId>(transparent_visual_id));
}
} // namespace ui } // namespace ui
...@@ -27,6 +27,10 @@ class GLEGLUtilityX11 : public PlatformGLEGLUtility { ...@@ -27,6 +27,10 @@ class GLEGLUtilityX11 : public PlatformGLEGLUtility {
void CollectGpuExtraInfo(bool enable_native_gpu_memory_buffers, void CollectGpuExtraInfo(bool enable_native_gpu_memory_buffers,
gfx::GpuExtraInfo& gpu_extra_info) const override; gfx::GpuExtraInfo& gpu_extra_info) const override;
bool X11DoesVisualHaveAlphaForTest() const override; bool X11DoesVisualHaveAlphaForTest() const override;
bool HasVisualManager() override;
bool UpdateVisualsOnGpuInfoChanged(bool software_rendering,
uint32_t default_visual_id,
uint32_t transparent_visual_id) override;
}; };
} // namespace ui } // namespace ui
......
...@@ -127,6 +127,8 @@ class OzonePlatformX11 : public OzonePlatform, ...@@ -127,6 +127,8 @@ class OzonePlatformX11 : public OzonePlatform,
} }
PlatformGLEGLUtility* GetPlatformGLEGLUtility() override { PlatformGLEGLUtility* GetPlatformGLEGLUtility() override {
if (!gl_egl_utility_)
gl_egl_utility_ = std::make_unique<GLEGLUtilityX11>();
return gl_egl_utility_.get(); return gl_egl_utility_.get();
} }
...@@ -245,7 +247,6 @@ class OzonePlatformX11 : public OzonePlatform, ...@@ -245,7 +247,6 @@ class OzonePlatformX11 : public OzonePlatform,
connection->DetachFromSequence(); connection->DetachFromSequence();
surface_factory_ozone_ = surface_factory_ozone_ =
std::make_unique<X11SurfaceFactory>(std::move(connection)); std::make_unique<X11SurfaceFactory>(std::move(connection));
gl_egl_utility_ = std::make_unique<GLEGLUtilityX11>();
} }
void PostMainMessageLoopStart( void PostMainMessageLoopStart(
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/public/platform_gl_egl_utility.h"
#include "base/logging.h"
#include "base/notreached.h"
namespace ui {
PlatformGLEGLUtility::PlatformGLEGLUtility() = default;
PlatformGLEGLUtility::~PlatformGLEGLUtility() = default;
bool PlatformGLEGLUtility::HasVisualManager() {
return false;
}
bool PlatformGLEGLUtility::UpdateVisualsOnGpuInfoChanged(
bool software_rendering,
uint32_t default_visual_id,
uint32_t transparent_visual_id) {
NOTREACHED() << "This must not be called if the platform does not support "
"X11 visuals.";
return false;
}
} // namespace ui
...@@ -18,7 +18,8 @@ namespace ui { ...@@ -18,7 +18,8 @@ namespace ui {
// Provides platform specific EGL attributes/configs. // Provides platform specific EGL attributes/configs.
class COMPONENT_EXPORT(OZONE_BASE) PlatformGLEGLUtility { class COMPONENT_EXPORT(OZONE_BASE) PlatformGLEGLUtility {
public: public:
virtual ~PlatformGLEGLUtility() = default; PlatformGLEGLUtility();
virtual ~PlatformGLEGLUtility();
// Gets additional display attributes based on |platform_type|. // Gets additional display attributes based on |platform_type|.
virtual void GetAdditionalEGLAttributes( virtual void GetAdditionalEGLAttributes(
...@@ -41,6 +42,17 @@ class COMPONENT_EXPORT(OZONE_BASE) PlatformGLEGLUtility { ...@@ -41,6 +42,17 @@ class COMPONENT_EXPORT(OZONE_BASE) PlatformGLEGLUtility {
// X11 specific; returns whether the test configuration supports alpha for // X11 specific; returns whether the test configuration supports alpha for
// window visuals. // window visuals.
virtual bool X11DoesVisualHaveAlphaForTest() const = 0; virtual bool X11DoesVisualHaveAlphaForTest() const = 0;
// X11 specific; returns whether the platform supports visuals.
virtual bool HasVisualManager();
// X11 specific; sets new visuals.
// Must be called only if the X11 visual manager is available.
// Should be called when the updated GPU info is available.
// Returns whether the visuals provided were valid.
virtual bool UpdateVisualsOnGpuInfoChanged(bool software_rendering,
uint32_t default_visual_id,
uint32_t transparent_visual_id);
}; };
} // namespace ui } // namespace ui
......
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