0

[MappableSI] Move NV12 gmb support logic into GpuServiceImpl.

Move NV12 gmb support logic from GpuMemoryBufferManagerSingleton into
GpuServiceImpl. This will allow removal of
GpuMemoryBufferManagerSingleton as part of MappableSI work.

The logic to determine whether NV12 GMBs are supported on linux platform
or not is similar and this CL only relocates it from browser process to
GPU process. This info will be sent as a part of GpuExtraInfo. Note that
the new logic looks at IsNativeBufferSupported() to weed out the fact
that true native handle (and not shmem) can be created.
gpu_memory_buffer_factory_->CreateGpuMemoryBuffer() then either creates
a native pixmap handle for linux or returns null and never creates a
shmem. Hence it is not required to check that the handle is native
pixmap.

In future, GpuServiceImpl::CreateGpuMemoryBuffer() will also be
refactored and this info will be updated accordingly.

Bug: 404887303
Change-Id: I507ddb227b7fcd0933d2d36e64401543a99128d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6497313
Reviewed-by: Colin Blundell <blundell@chromium.org>
Commit-Queue: vikas soni <vikassoni@chromium.org>
Auto-Submit: vikas soni <vikassoni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1454016}
This commit is contained in:
vikas soni
2025-04-30 10:10:09 -07:00
committed by Chromium LUCI CQ
parent 8e00bb9d25
commit 896c5387e3
10 changed files with 43 additions and 66 deletions

@ -647,6 +647,11 @@ void GpuServiceImpl::InitializeWithHostInternal(
shutdown_event_ = shutdown_event;
mojo::Remote<mojom::GpuHost> gpu_host(std::move(pending_gpu_host));
#if BUILDFLAG(IS_LINUX)
gpu_extra_info_.is_gmb_nv12_supported = IsGMBNV12Supported();
#endif
gpu_host->DidInitialize(gpu_info_, gpu_feature_info_,
gpu_info_for_hardware_gpu_,
gpu_feature_info_for_hardware_gpu_, gpu_extra_info_);
@ -1544,6 +1549,31 @@ bool GpuServiceImpl::OnBeginFrameDerivedImpl(const BeginFrameArgs& args) {
return true;
}
#if BUILDFLAG(IS_LINUX)
bool GpuServiceImpl::IsGMBNV12Supported() {
auto buffer_format = gfx::BufferFormat::YUV_420_BIPLANAR;
auto buffer_usage = gfx::BufferUsage::GPU_READ_CPU_READ_WRITE;
if (!IsNativeBufferSupported(buffer_format, buffer_usage)) {
return false;
}
auto size = gfx::Size(2, 2);
// Note that |gmb_id| and |client_id| does not matter here as this is the
// first GMB which will created and immediately destroyed.
auto gmb_id = gfx::GpuMemoryBufferId(
static_cast<int>(gpu::MappableSIClientGmbId::kGpuServiceImpl));
auto client_id = gpu::kMappableSIClientId;
auto gmb_handle = gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
gmb_id, size, /*framebuffer_size=*/size, buffer_format, buffer_usage,
client_id, gpu::kNullSurfaceHandle);
// Destroy the gmb_handle since it will be no longer needed.
DestroyGpuMemoryBuffer(gmb_id, client_id);
return !gmb_handle.is_null();
}
#endif
void GpuServiceImpl::OnBeginFrameSourcePausedChanged(bool paused) {}
void GpuServiceImpl::OnBeginFrameOnIO(const BeginFrameArgs& args) {

@ -509,6 +509,10 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl
void OnBeginFrameOnIO(const BeginFrameArgs& args);
#if BUILDFLAG(IS_LINUX)
bool IsGMBNV12Supported();
#endif
scoped_refptr<base::SingleThreadTaskRunner> main_runner_;
scoped_refptr<base::SingleThreadTaskRunner> io_runner_;

@ -417,10 +417,6 @@ bool GpuDataManagerImpl::IsGpuMemoryBufferNV12Supported() {
base::AutoLock auto_lock(lock_);
return private_->IsGpuMemoryBufferNV12Supported();
}
void GpuDataManagerImpl::SetGpuMemoryBufferNV12Supported(bool supported) {
base::AutoLock auto_lock(lock_);
private_->SetGpuMemoryBufferNV12Supported(supported);
}
#endif // BUILDFLAG(IS_LINUX)
// static

@ -227,7 +227,6 @@ class CONTENT_EXPORT GpuDataManagerImpl : public GpuDataManager,
#if BUILDFLAG(IS_LINUX)
bool IsGpuMemoryBufferNV12Supported();
void SetGpuMemoryBufferNV12Supported(bool supported);
#endif // BUILDFLAG(IS_LINUX)
// Binds a new Mojo receiver to handle requests from a renderer.

@ -1699,11 +1699,7 @@ void GpuDataManagerImplPrivate::RecordCompositingMode() {
#if BUILDFLAG(IS_LINUX)
bool GpuDataManagerImplPrivate::IsGpuMemoryBufferNV12Supported() {
return is_gpu_memory_buffer_NV12_supported_;
}
void GpuDataManagerImplPrivate::SetGpuMemoryBufferNV12Supported(
bool supported) {
is_gpu_memory_buffer_NV12_supported_ = supported;
return gpu_extra_info_.is_gmb_nv12_supported;
}
#endif // BUILDFLAG(IS_LINUX)

@ -151,7 +151,6 @@ class CONTENT_EXPORT GpuDataManagerImplPrivate {
#if BUILDFLAG(IS_LINUX)
bool IsGpuMemoryBufferNV12Supported();
void SetGpuMemoryBufferNV12Supported(bool supported);
#endif // BUILDFLAG(IS_LINUX)
void DisableDomainBlockingFor3DAPIsForTesting();

@ -9,7 +9,6 @@
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.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/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
@ -46,31 +45,6 @@ scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() {
#endif
}
#if BUILDFLAG(IS_LINUX)
bool IsGpuMemoryBufferNV12Supported() {
static bool is_computed = false;
static bool supported = false;
if (is_computed) {
return supported;
}
auto* gmb_mgr = GpuMemoryBufferManagerSingleton::GetInstance();
if (gmb_mgr) {
auto gmb = gmb_mgr->CreateGpuMemoryBuffer(
gfx::Size(2, 2), gfx::BufferFormat::YUV_420_BIPLANAR,
gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle,
nullptr);
if (gmb && gmb->GetType() == gfx::GpuMemoryBufferType::NATIVE_PIXMAP) {
supported = true;
}
}
is_computed = true;
return supported;
}
#endif // BUILDFLAG(IS_LINUX)
} // namespace
GpuMemoryBufferManagerSingleton::GpuMemoryBufferManagerSingleton(int client_id)
@ -78,18 +52,15 @@ GpuMemoryBufferManagerSingleton::GpuMemoryBufferManagerSingleton(int client_id)
base::BindRepeating(&content::GetGpuService),
client_id,
std::make_unique<gpu::GpuMemoryBufferSupport>(),
GetTaskRunner()),
gpu_data_manager_impl_(GpuDataManagerImpl::GetInstance()) {
GetTaskRunner()) {
DCHECK(!g_gpu_memory_buffer_manager);
g_gpu_memory_buffer_manager = this;
gpu_data_manager_impl_->AddObserver(this);
}
GpuMemoryBufferManagerSingleton::~GpuMemoryBufferManagerSingleton() {
DCHECK_EQ(this, g_gpu_memory_buffer_manager);
NotifyObservers();
g_gpu_memory_buffer_manager = nullptr;
gpu_data_manager_impl_->RemoveObserver(this);
}
// static
@ -110,14 +81,4 @@ void GpuMemoryBufferManagerSingleton::RemoveObserver(
observers_.RemoveObserver(observer);
}
void GpuMemoryBufferManagerSingleton::OnGpuExtraInfoUpdate() {
#if BUILDFLAG(IS_LINUX)
// Dynamic check whether the NV12 format is supported as it may be
// inconsistent between the system GBM (Generic Buffer Management) and
// chromium miniGBM.
gpu_data_manager_impl_->SetGpuMemoryBufferNV12Supported(
IsGpuMemoryBufferNV12Supported());
#endif // BUILDFLAG(IS_LINUX)
}
} // namespace content

@ -11,18 +11,11 @@
namespace content {
class GpuDataManagerImpl;
// This class ensures that there is at most one instance of
// |viz::HostGpuMemoryBufferManager| in content at any given time. Code in
// content must use this class to access the instance.
//
// 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 {
class GpuMemoryBufferManagerSingleton : public viz::HostGpuMemoryBufferManager {
public:
explicit GpuMemoryBufferManagerSingleton(int client_id);
GpuMemoryBufferManagerSingleton(const GpuMemoryBufferManagerSingleton&) =
@ -35,12 +28,6 @@ class GpuMemoryBufferManagerSingleton : public viz::HostGpuMemoryBufferManager,
void AddObserver(gpu::GpuMemoryBufferManagerObserver* observer) final;
void RemoveObserver(gpu::GpuMemoryBufferManagerObserver* observer) final;
private:
// GpuDataManagerObserver:
void OnGpuExtraInfoUpdate() override;
raw_ptr<GpuDataManagerImpl> gpu_data_manager_impl_ = nullptr;
};
} // namespace content

@ -27,6 +27,7 @@ namespace gpu {
enum class MappableSIClientGmbId : int {
kGpuChannel = 1,
kGmbVideoFramePoolContext = 2,
kGpuServiceImpl = 3,
kLast = 2
};

@ -50,6 +50,10 @@ struct COMPONENT_EXPORT(GFX) GpuExtraInfo {
#if BUILDFLAG(IS_OZONE_X11)
std::vector<gfx::BufferUsageAndFormat> gpu_memory_buffer_support_x11;
#endif // BUILDFLAG(IS_OZONE_X11)
#if BUILDFLAG(IS_LINUX)
bool is_gmb_nv12_supported = false;
#endif
};
} // namespace gfx