Commit 939c65cc authored by Maksim Sisov's avatar Maksim Sisov Committed by Commit Bot

Ozone/X11: Share non-Ozone/X11's GMBX11 support with Ozone/X11.

In the first take, I thought buffer formats could be determined from
the browser process side as early as possible, but several problems
were identified in the end -

1) glx's bindings' initialization is required.
And it's done on the gpu process side

2) gl implementation can be
determined after gl is set (it's temporarily required before
angle + gmb support is added, though).

I also thought to make fetching gmb formats asynchronous, but it would
require rewriting some important clients, which is non-trivial,
unfortunately.

Thus, that approach didn't work well and I had to reuse the existing
approach to pass support buffer formats for gmb via gpu extra info.

Now, OzonePlatform has fetch_buffer_formats_for_gmb_on_gpu variable
that clients can use to determine the way that they are able to fetch
supported buffer formats. All the previous logic that non-Ozone/X11
had stayed the same except that it's also used by OzonePlatform
that has fetch_buffer_formats_for_gmb_on_gpu set to true. In this
case, CollectGpuExtraInfo collects supported buffer formats.


Bug: 1099183
Change-Id: I56c1323af54ae5bec4a5f9152aca47a21035d6b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2540286Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Commit-Queue: Maksim Sisov (GMT+2) <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#829205}
parent 838b8e2e
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#include "ui/gfx/buffer_format_util.h" #include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/buffer_usage_util.h" #include "ui/gfx/buffer_usage_util.h"
#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace viz { namespace viz {
namespace { namespace {
...@@ -31,6 +35,27 @@ void OnGpuMemoryBufferDestroyed( ...@@ -31,6 +35,27 @@ void OnGpuMemoryBufferDestroyed(
base::BindOnce(std::move(callback), sync_token)); base::BindOnce(std::move(callback), sync_token));
} }
bool WillGetGmbConfigFromGpu() {
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) {
// Ozone/X11 (same as non-Ozone/X11) cannot get buffer formats in the
// browser process and requires gpu initialization to be done before it can
// determine what formats gmb can use. This limitation comes from the
// requirement to have GLX bindings initialized. The buffer formats will be
// passed through gpu extra info.
return ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.fetch_buffer_formats_for_gmb_on_gpu;
}
#endif
#if defined(USE_X11)
// non-Ozone/X11 must always get native configs on gpu.
DCHECK(!features::IsUsingOzonePlatform());
return true;
#endif
return false;
}
} // namespace } // namespace
HostGpuMemoryBufferManager::PendingBufferInfo::PendingBufferInfo() = default; HostGpuMemoryBufferManager::PendingBufferInfo::PendingBufferInfo() = default;
...@@ -47,11 +72,7 @@ HostGpuMemoryBufferManager::HostGpuMemoryBufferManager( ...@@ -47,11 +72,7 @@ HostGpuMemoryBufferManager::HostGpuMemoryBufferManager(
client_id_(client_id), client_id_(client_id),
gpu_memory_buffer_support_(std::move(gpu_memory_buffer_support)), gpu_memory_buffer_support_(std::move(gpu_memory_buffer_support)),
task_runner_(std::move(task_runner)) { task_runner_(std::move(task_runner)) {
bool should_get_native_configs = true; if (!WillGetGmbConfigFromGpu()) {
#if defined(USE_X11)
should_get_native_configs = features::IsUsingOzonePlatform();
#endif
if (should_get_native_configs) {
native_configurations_ = gpu::GetNativeGpuMemoryBufferConfigurations( native_configurations_ = gpu::GetNativeGpuMemoryBufferConfigurations(
gpu_memory_buffer_support_.get()); gpu_memory_buffer_support_.get());
native_configurations_initialized_.Signal(); native_configurations_initialized_.Signal();
......
...@@ -37,6 +37,24 @@ namespace viz { ...@@ -37,6 +37,24 @@ namespace viz {
namespace { namespace {
bool MustSignalGmbConfigReadyForTest() {
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) {
// Some Ozone platforms (Ozone/X11) require GPU process initialization to
// determine GMB support.
return ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.fetch_buffer_formats_for_gmb_on_gpu;
}
#endif
#if defined(USE_X11)
// X11 requires GPU process initialization to determine GMB support.
DCHECK(!features::IsUsingOzonePlatform());
return true;
#endif
return false;
}
class TestGpuService : public mojom::GpuService { class TestGpuService : public mojom::GpuService {
public: public:
TestGpuService() = default; TestGpuService() = default;
...@@ -235,11 +253,8 @@ class HostGpuMemoryBufferManagerTest : public ::testing::Test { ...@@ -235,11 +253,8 @@ class HostGpuMemoryBufferManagerTest : public ::testing::Test {
std::move(gpu_service_provider), 1, std::move(gpu_service_provider), 1,
std::move(gpu_memory_buffer_support), std::move(gpu_memory_buffer_support),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
#if defined(USE_X11) if (MustSignalGmbConfigReadyForTest())
// X11 requires GPU process initialization to determine GMB support.
if (!features::IsUsingOzonePlatform())
gpu_memory_buffer_manager_->native_configurations_initialized_.Signal(); gpu_memory_buffer_manager_->native_configurations_initialized_.Signal();
#endif
} }
// Not all platforms support native configurations (currently only Windows, // Not all platforms support native configurations (currently only Windows,
......
...@@ -2435,10 +2435,6 @@ source_set("browser") { ...@@ -2435,10 +2435,6 @@ source_set("browser") {
"//ui/events/platform/x11", "//ui/events/platform/x11",
"//ui/gfx/x", "//ui/gfx/x",
] ]
sources += [
"gpu/gpu_memory_buffer_manager_singleton_x11.cc",
"gpu/gpu_memory_buffer_manager_singleton_x11.h",
]
} }
if (use_pangocairo) { if (use_pangocairo) {
......
...@@ -2,17 +2,10 @@ include_rules = [ ...@@ -2,17 +2,10 @@ include_rules = [
"+chromecast/chromecast_buildflags.h", "+chromecast/chromecast_buildflags.h",
"+components/metal_util", "+components/metal_util",
"+components/ui_devtools/buildflags.h", "+components/ui_devtools/buildflags.h",
"+ui/ozone/public",
] ]
# TODO(crbug.com/734668): Dependencies on ozone should be removed, as content
# embedded in mus won't be able to talk to the native ozone.
specific_include_rules = { specific_include_rules = {
"gpu_data_manager_impl_private\.cc": [
"+ui/ozone/public",
],
"gpu_process_host\.cc": [
"+ui/ozone/public",
],
"viz_devtools_connector\.cc": [ "viz_devtools_connector\.cc": [
"+components/ui_devtools", "+components/ui_devtools",
], ],
......
...@@ -42,11 +42,6 @@ ...@@ -42,11 +42,6 @@
#include "ui/accelerated_widget_mac/window_resize_helper_mac.h" #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
#endif #endif
#if defined(USE_X11)
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton_x11.h" // nogncheck
#include "ui/base/ui_base_features.h"
#endif
namespace content { namespace content {
namespace { namespace {
...@@ -71,15 +66,6 @@ void TimerFired() { ...@@ -71,15 +66,6 @@ void TimerFired() {
} }
#endif // OS_ANDROID #endif // OS_ANDROID
GpuMemoryBufferManagerSingleton* CreateGpuMemoryBufferManagerSingleton(
int gpu_client_id) {
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform())
return new GpuMemoryBufferManagerSingletonX11(gpu_client_id);
#endif
return new GpuMemoryBufferManagerSingleton(gpu_client_id);
}
} // namespace } // namespace
BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = nullptr; BrowserGpuChannelHostFactory* BrowserGpuChannelHostFactory::instance_ = nullptr;
...@@ -298,7 +284,7 @@ BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() ...@@ -298,7 +284,7 @@ BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory()
gpu_client_tracing_id_( gpu_client_tracing_id_(
memory_instrumentation::mojom::kServiceTracingProcessId), memory_instrumentation::mojom::kServiceTracingProcessId),
gpu_memory_buffer_manager_( gpu_memory_buffer_manager_(
CreateGpuMemoryBufferManagerSingleton(gpu_client_id_)) { new GpuMemoryBufferManagerSingleton(gpu_client_id_)) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch( if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGpuShaderDiskCache)) { switches::kDisableGpuShaderDiskCache)) {
DCHECK(GetContentClient()); DCHECK(GetContentClient());
......
...@@ -98,6 +98,23 @@ namespace content { ...@@ -98,6 +98,23 @@ namespace content {
namespace { namespace {
// On X11 (Ozone and non-Ozone), we do not know GpuMemoryBuffer configuration
// support until receiving the initial GPUInfo.
bool CanUpdateGmbGpuPreferences() {
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) {
return !ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.fetch_buffer_formats_for_gmb_on_gpu;
}
#endif
#if defined(USE_X11)
DCHECK(!features::IsUsingOzonePlatform());
return false;
#endif
return true;
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// NOINLINE to ensure this function is used in crash reports. // NOINLINE to ensure this function is used in crash reports.
NOINLINE void FatalGpuProcessLaunchFailureOnBackground() { NOINLINE void FatalGpuProcessLaunchFailureOnBackground() {
...@@ -1152,20 +1169,13 @@ void GpuDataManagerImplPrivate::UpdateGpuPreferences( ...@@ -1152,20 +1169,13 @@ void GpuDataManagerImplPrivate::UpdateGpuPreferences(
// For performance reasons, discourage storing VideoFrames in a biplanar // For performance reasons, discourage storing VideoFrames in a biplanar
// GpuMemoryBuffer if this is not native, see https://crbug.com/791676. // GpuMemoryBuffer if this is not native, see https://crbug.com/791676.
if (auto* gpu_memory_buffer_manager = auto* gpu_memory_buffer_manager =
GpuMemoryBufferManagerSingleton::GetInstance()) { GpuMemoryBufferManagerSingleton::GetInstance();
// On X11, we do not know GpuMemoryBuffer configuration support until if (gpu_memory_buffer_manager && CanUpdateGmbGpuPreferences()) {
// receiving the initial GPUInfo. gpu_preferences->disable_biplanar_gpu_memory_buffers_for_video_frames =
bool should_update = true; !gpu_memory_buffer_manager->IsNativeGpuMemoryBufferConfiguration(
#if defined(USE_X11) gfx::BufferFormat::YUV_420_BIPLANAR,
should_update = features::IsUsingOzonePlatform(); gfx::BufferUsage::GPU_READ_CPU_READ_WRITE);
#endif
if (should_update) {
gpu_preferences->disable_biplanar_gpu_memory_buffers_for_video_frames =
!gpu_memory_buffer_manager->IsNativeGpuMemoryBufferConfiguration(
gfx::BufferFormat::YUV_420_BIPLANAR,
gfx::BufferUsage::GPU_READ_CPU_READ_WRITE);
}
} }
gpu_preferences->gpu_program_cache_size = gpu_preferences->gpu_program_cache_size =
......
...@@ -69,11 +69,25 @@ ...@@ -69,11 +69,25 @@
#if defined(USE_OZONE) #if defined(USE_OZONE)
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/ozone/public/ozone_platform.h"
#endif #endif
namespace content { namespace content {
namespace { namespace {
#if defined(USE_OZONE) || defined(USE_X11)
bool GetGmbConfigFromGpu() {
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) {
return ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.fetch_buffer_formats_for_gmb_on_gpu;
}
#endif
return true;
}
#endif
WebUIDataSource* CreateGpuHTMLSource() { WebUIDataSource* CreateGpuHTMLSource() {
WebUIDataSource* source = WebUIDataSource::Create(kChromeUIGpuHost); WebUIDataSource* source = WebUIDataSource::Create(kChromeUIGpuHost);
source->OverrideContentSecurityPolicy( source->OverrideContentSecurityPolicy(
...@@ -393,8 +407,8 @@ std::unique_ptr<base::ListValue> GpuMemoryBufferInfo( ...@@ -393,8 +407,8 @@ 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_X11) #if defined(USE_OZONE) || defined(USE_X11)
if (!features::IsUsingOzonePlatform()) { 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);
} }
......
...@@ -7,10 +7,16 @@ ...@@ -7,10 +7,16 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "components/viz/host/gpu_host_impl.h" #include "components/viz/host/gpu_host_impl.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_process_host.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "gpu/ipc/common/gpu_memory_buffer_support.h" #include "gpu/ipc/common/gpu_memory_buffer_support.h"
#include "ui/base/ui_base_features.h"
#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace content { namespace content {
namespace { namespace {
...@@ -27,6 +33,19 @@ viz::mojom::GpuService* GetGpuService( ...@@ -27,6 +33,19 @@ viz::mojom::GpuService* GetGpuService(
return nullptr; return nullptr;
} }
#if defined(USE_OZONE) || defined(USE_X11)
bool ShouldSetBufferFormatsFromGpuExtraInfo() {
#if defined(USE_OZONE)
if (features::IsUsingOzonePlatform()) {
return ui::OzonePlatform::GetInstance()
->GetPlatformProperties()
.fetch_buffer_formats_for_gmb_on_gpu;
}
#endif
return true;
}
#endif
} // namespace } // namespace
GpuMemoryBufferManagerSingleton::GpuMemoryBufferManagerSingleton(int client_id) GpuMemoryBufferManagerSingleton::GpuMemoryBufferManagerSingleton(int client_id)
...@@ -34,14 +53,17 @@ GpuMemoryBufferManagerSingleton::GpuMemoryBufferManagerSingleton(int client_id) ...@@ -34,14 +53,17 @@ GpuMemoryBufferManagerSingleton::GpuMemoryBufferManagerSingleton(int client_id)
base::BindRepeating(&content::GetGpuService), base::BindRepeating(&content::GetGpuService),
client_id, client_id,
std::make_unique<gpu::GpuMemoryBufferSupport>(), std::make_unique<gpu::GpuMemoryBufferSupport>(),
GetIOThreadTaskRunner({})) { GetIOThreadTaskRunner({})),
gpu_data_manager_impl_(GpuDataManagerImpl::GetInstance()) {
DCHECK(!g_gpu_memory_buffer_manager); DCHECK(!g_gpu_memory_buffer_manager);
g_gpu_memory_buffer_manager = this; g_gpu_memory_buffer_manager = this;
gpu_data_manager_impl_->AddObserver(this);
} }
GpuMemoryBufferManagerSingleton::~GpuMemoryBufferManagerSingleton() { GpuMemoryBufferManagerSingleton::~GpuMemoryBufferManagerSingleton() {
DCHECK_EQ(this, g_gpu_memory_buffer_manager); DCHECK_EQ(this, g_gpu_memory_buffer_manager);
g_gpu_memory_buffer_manager = nullptr; g_gpu_memory_buffer_manager = nullptr;
gpu_data_manager_impl_->RemoveObserver(this);
} }
// static // static
...@@ -50,4 +72,20 @@ GpuMemoryBufferManagerSingleton::GetInstance() { ...@@ -50,4 +72,20 @@ GpuMemoryBufferManagerSingleton::GetInstance() {
return g_gpu_memory_buffer_manager; return g_gpu_memory_buffer_manager;
} }
void GpuMemoryBufferManagerSingleton::OnGpuExtraInfoUpdate() {
#if defined(USE_X11) || defined(USE_OZONE)
// X11 and non-Ozone/X11 fetch buffer formats on gpu and pass them via gpu
// extra info.
if (!ShouldSetBufferFormatsFromGpuExtraInfo())
return;
gpu::GpuMemoryBufferConfigurationSet configs;
for (const auto& config : gpu_data_manager_impl_->GetGpuExtraInfo()
.gpu_memory_buffer_support_x11) {
configs.insert(config);
}
SetNativeConfigurations(std::move(configs));
#endif
}
} // namespace content } // namespace content
...@@ -6,21 +6,37 @@ ...@@ -6,21 +6,37 @@
#define CONTENT_BROWSER_GPU_GPU_MEMORY_BUFFER_MANAGER_SINGLETON_H_ #define CONTENT_BROWSER_GPU_GPU_MEMORY_BUFFER_MANAGER_SINGLETON_H_
#include "components/viz/host/host_gpu_memory_buffer_manager.h" #include "components/viz/host/host_gpu_memory_buffer_manager.h"
#include "content/public/browser/gpu_data_manager_observer.h"
namespace content { namespace content {
class GpuDataManagerImpl;
// This class ensures that there is at most one instance of // This class ensures that there is at most one instance of
// |viz::HostGpuMemoryBufferManager| in content at any given time. Code in // |viz::HostGpuMemoryBufferManager| in content at any given time. Code in
// content must use this class to access the instance. // content must use this class to access the instance.
class GpuMemoryBufferManagerSingleton : public viz::HostGpuMemoryBufferManager { //
// With non-Ozone/X11 and Ozone/X11, the supported buffer configurations can
// only be determined at runtime, with help from the GPU process.
// GpuDataManagerObserver adds functionality for updating the supported
// configuration list when new GPUInfo is received.
class GpuMemoryBufferManagerSingleton : public viz::HostGpuMemoryBufferManager,
public GpuDataManagerObserver {
public: public:
explicit GpuMemoryBufferManagerSingleton(int client_id); explicit GpuMemoryBufferManagerSingleton(int client_id);
GpuMemoryBufferManagerSingleton(const GpuMemoryBufferManagerSingleton&) =
delete;
GpuMemoryBufferManagerSingleton& operator=(
const GpuMemoryBufferManagerSingleton&) = delete;
~GpuMemoryBufferManagerSingleton() override; ~GpuMemoryBufferManagerSingleton() override;
static GpuMemoryBufferManagerSingleton* GetInstance(); static GpuMemoryBufferManagerSingleton* GetInstance();
private: private:
DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferManagerSingleton); // GpuDataManagerObserver:
void OnGpuExtraInfoUpdate() override;
GpuDataManagerImpl* gpu_data_manager_impl_ = nullptr;
}; };
} // namespace content } // 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.
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton_x11.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
namespace content {
GpuMemoryBufferManagerSingletonX11::GpuMemoryBufferManagerSingletonX11(
int client_id)
: GpuMemoryBufferManagerSingleton(client_id),
gpu_data_manager_impl_(GpuDataManagerImpl::GetInstance()) {
gpu_data_manager_impl_->AddObserver(this);
}
GpuMemoryBufferManagerSingletonX11::~GpuMemoryBufferManagerSingletonX11() {
gpu_data_manager_impl_->RemoveObserver(this);
}
void GpuMemoryBufferManagerSingletonX11::OnGpuExtraInfoUpdate() {
have_gpu_info_ = true;
gpu::GpuMemoryBufferConfigurationSet configs;
for (const auto& config : gpu_data_manager_impl_->GetGpuExtraInfo()
.gpu_memory_buffer_support_x11) {
configs.insert(config);
}
SetNativeConfigurations(std::move(configs));
}
} // 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_GPU_MEMORY_BUFFER_MANAGER_SINGLETON_X11_H_
#define CONTENT_BROWSER_GPU_GPU_MEMORY_BUFFER_MANAGER_SINGLETON_X11_H_
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "content/public/browser/gpu_data_manager_observer.h"
namespace content {
class GpuDataManagerImpl;
// With X11, the supported buffer configurations can only be determined at
// runtime, with help from the GPU process. This class adds functionality for
// updating the supported configuration list when new GPUInfo is received.
class GpuMemoryBufferManagerSingletonX11
: public GpuMemoryBufferManagerSingleton,
public GpuDataManagerObserver {
public:
explicit GpuMemoryBufferManagerSingletonX11(int client_id);
~GpuMemoryBufferManagerSingletonX11() override;
GpuMemoryBufferManagerSingletonX11(
const GpuMemoryBufferManagerSingletonX11&) = delete;
GpuMemoryBufferManagerSingletonX11& operator=(
const GpuMemoryBufferManagerSingletonX11&) = delete;
private:
// GpuDataManagerObserver:
void OnGpuExtraInfoUpdate() override;
bool have_gpu_info_ = false;
GpuDataManagerImpl* gpu_data_manager_impl_ = nullptr;
};
} // namespace content
#endif // CONTENT_BROWSER_GPU_GPU_MEMORY_BUFFER_MANAGER_SINGLETON_X11_H_
...@@ -317,6 +317,8 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line, ...@@ -317,6 +317,8 @@ bool GpuInit::InitializeAndStartSandbox(base::CommandLine* command_line,
if (features::IsUsingOzonePlatform()) { if (features::IsUsingOzonePlatform()) {
ui::OzonePlatform::InitParams params; ui::OzonePlatform::InitParams params;
params.single_process = false; params.single_process = false;
params.enable_native_gpu_memory_buffers =
gpu_preferences.enable_native_gpu_memory_buffers;
ui::OzonePlatform::InitializeForGPU(params); ui::OzonePlatform::InitializeForGPU(params);
// We need to get supported formats before sandboxing to avoid an known // We need to get supported formats before sandboxing to avoid an known
// issue which breaks the camera preview. (b/166850715) // issue which breaks the camera preview. (b/166850715)
......
...@@ -57,6 +57,8 @@ source_set("x11") { ...@@ -57,6 +57,8 @@ source_set("x11") {
"//ui/events/x", "//ui/events/x",
"//ui/gfx", "//ui/gfx",
"//ui/gfx/geometry", "//ui/gfx/geometry",
"//ui/gfx/linux:gbm",
"//ui/gfx/linux:gpu_memory_buffer_support_x11",
"//ui/gfx/x", "//ui/gfx/x",
"//ui/gl", "//ui/gl",
"//ui/ozone:ozone_base", "//ui/ozone:ozone_base",
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
#include "ui/ozone/platform/x11/client_native_pixmap_factory_x11.h" #include "ui/ozone/platform/x11/client_native_pixmap_factory_x11.h"
#include "ui/ozone/common/stub_client_native_pixmap_factory.h" #include "ui/gfx/linux/client_native_pixmap_factory_dmabuf.h"
namespace ui { namespace ui {
gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryX11() { gfx::ClientNativePixmapFactory* CreateClientNativePixmapFactoryX11() {
return CreateStubClientNativePixmapFactory(); return gfx::CreateClientNativePixmapFactoryDmabuf();
} }
} // namespace ui } // namespace ui
...@@ -9,9 +9,11 @@ ...@@ -9,9 +9,11 @@
#include "base/message_loop/message_pump_type.h" #include "base/message_loop/message_pump_type.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/base/buildflags.h" #include "ui/base/buildflags.h"
#include "ui/base/cursor/cursor_factory.h" #include "ui/base/cursor/cursor_factory.h"
...@@ -25,6 +27,7 @@ ...@@ -25,6 +27,7 @@
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/linux/gpu_memory_buffer_support_x11.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/ozone/common/stub_overlay_manager.h" #include "ui/ozone/common/stub_overlay_manager.h"
#include "ui/ozone/platform/x11/gl_egl_utility_x11.h" #include "ui/ozone/platform/x11/gl_egl_utility_x11.h"
...@@ -172,6 +175,7 @@ class OzonePlatformX11 : public OzonePlatform, ...@@ -172,6 +175,7 @@ class OzonePlatformX11 : public OzonePlatform,
properties->platform_shows_drag_image = false; properties->platform_shows_drag_image = false;
properties->supports_global_application_menus = true; properties->supports_global_application_menus = true;
properties->app_modal_dialogs_use_event_blocker = true; properties->app_modal_dialogs_use_event_blocker = true;
properties->fetch_buffer_formats_for_gmb_on_gpu = true;
initialised = true; initialised = true;
} }
...@@ -179,6 +183,13 @@ class OzonePlatformX11 : public OzonePlatform, ...@@ -179,6 +183,13 @@ class OzonePlatformX11 : public OzonePlatform,
return *properties; return *properties;
} }
bool IsNativePixmapConfigSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) const override {
// Native pixmap support is determined on gpu process via gpu extra info
// that gets this information from GpuMemoryBufferSupportX11.
return false;
}
void InitializeUI(const InitParams& params) override { void InitializeUI(const InitParams& params) override {
InitializeCommon(params); InitializeCommon(params);
CreatePlatformEventSource(); CreatePlatformEventSource();
...@@ -215,7 +226,13 @@ class OzonePlatformX11 : public OzonePlatform, ...@@ -215,7 +226,13 @@ class OzonePlatformX11 : public OzonePlatform,
void InitializeGPU(const InitParams& params) override { void InitializeGPU(const InitParams& params) override {
InitializeCommon(params); InitializeCommon(params);
if (params.enable_native_gpu_memory_buffers) {
base::ThreadPool::PostTask(
FROM_HERE, base::BindOnce([]() {
SCOPED_UMA_HISTOGRAM_TIMER("Linux.X11.GbmSupportX11CreationTime");
ui::GpuMemoryBufferSupportX11::GetInstance();
}));
}
// In single process mode either the UI thread will create an event source // In single process mode either the UI thread will create an event source
// or it's a test and an event source isn't desired. // or it's a test and an event source isn't desired.
if (!params.single_process) if (!params.single_process)
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
#include "gpu/vulkan/buildflags.h" #include "gpu/vulkan/buildflags.h"
#include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/linux/gbm_buffer.h"
#include "ui/gfx/linux/gpu_memory_buffer_support_x11.h"
#include "ui/gfx/linux/native_pixmap_dmabuf.h"
#include "ui/gfx/x/connection.h" #include "ui/gfx/x/connection.h"
#include "ui/gl/gl_surface_egl.h" #include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_surface_egl_x11_gles2.h" #include "ui/gl/gl_surface_egl_x11_gles2.h"
...@@ -121,4 +124,37 @@ std::unique_ptr<SurfaceOzoneCanvas> X11SurfaceFactory::CreateCanvasForWidget( ...@@ -121,4 +124,37 @@ std::unique_ptr<SurfaceOzoneCanvas> X11SurfaceFactory::CreateCanvasForWidget(
return std::make_unique<X11CanvasSurface>(widget); return std::make_unique<X11CanvasSurface>(widget);
} }
scoped_refptr<gfx::NativePixmap> X11SurfaceFactory::CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
base::Optional<gfx::Size> framebuffer_size) {
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;
}
void X11SurfaceFactory::CreateNativePixmapAsync(gfx::AcceleratedWidget widget,
VkDevice vk_device,
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, vk_device, size, format, usage));
}
} // namespace ui } // namespace ui
...@@ -33,6 +33,19 @@ class X11SurfaceFactory : public SurfaceFactoryOzone { ...@@ -33,6 +33,19 @@ class X11SurfaceFactory : public SurfaceFactoryOzone {
#endif #endif
std::unique_ptr<SurfaceOzoneCanvas> CreateCanvasForWidget( std::unique_ptr<SurfaceOzoneCanvas> CreateCanvasForWidget(
gfx::AcceleratedWidget widget) override; gfx::AcceleratedWidget widget) override;
scoped_refptr<gfx::NativePixmap> CreateNativePixmap(
gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
base::Optional<gfx::Size> framebuffer_size = base::nullopt) override;
void CreateNativePixmapAsync(gfx::AcceleratedWidget widget,
VkDevice vk_device,
gfx::Size size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
NativePixmapCallback callback) override;
private: private:
std::unique_ptr<GLOzone> glx_implementation_; std::unique_ptr<GLOzone> glx_implementation_;
......
...@@ -70,6 +70,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform { ...@@ -70,6 +70,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform {
// operate as a single process for platforms (i.e. drm) that are usually // operate as a single process for platforms (i.e. drm) that are usually
// split between a host and viz specific portion. // split between a host and viz specific portion.
bool single_process = false; bool single_process = false;
// Setting this to true indicates the the platform can do additional
// initialization for the GpuMemoryBuffer framework.
bool enable_native_gpu_memory_buffers = false;
}; };
// Struct used to indicate platform properties. // Struct used to indicate platform properties.
...@@ -122,6 +126,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform { ...@@ -122,6 +126,10 @@ class COMPONENT_EXPORT(OZONE) OzonePlatform {
// Determines if the application modal dialogs should use the event blocker // Determines if the application modal dialogs should use the event blocker
// to allow the only browser window receiving UI events. // to allow the only browser window receiving UI events.
bool app_modal_dialogs_use_event_blocker = false; bool app_modal_dialogs_use_event_blocker = false;
// Determines whether buffer formats should be fetched on GPU and passed
// back via gpu extra info.
bool fetch_buffer_formats_for_gmb_on_gpu = false;
}; };
// Properties available in the host process after initialization. // Properties available in the host process after initialization.
......
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