#include "components/viz/host/gpu_host_impl.h"
#include <utility>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/process/process_handle.h"
#include "base/strings/strcat.h"
#include "base/system/sys_info.h"
#include "base/task/sequenced_task_runner.h"
#include "base/threading/thread_checker.h"
#include "base/trace_event/trace_event.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/viz/common/buildflags.h"
#include "components/viz/common/features.h"
#include "gpu/config/gpu_driver_bug_workaround_type.h"
#include "gpu/config/gpu_feature_info.h"
#include "gpu/config/gpu_finch_features.h"
#include "gpu/config/gpu_info.h"
#include "gpu/ipc/common/gpu_client_ids.h"
#include "gpu/ipc/host/gpu_disk_cache.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "ui/gfx/font_render_params.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "ui/gfx/win/rendering_window_manager.h"
#elif BUILDFLAG(IS_MAC)
#include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
#endif
#if BUILDFLAG(IS_OZONE)
#include "ui/ozone/public/gpu_platform_support_host.h"
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace viz {
namespace {
class FontRenderParams { … };
FontRenderParams& GetFontRenderParams() { … }
}
GpuHostImpl::InitParams::InitParams() = default;
GpuHostImpl::InitParams::InitParams(InitParams&&) = default;
GpuHostImpl::InitParams::~InitParams() = default;
GpuHostImpl::GpuHostImpl(Delegate* delegate,
mojo::PendingRemote<mojom::VizMain> viz_main,
InitParams params)
: … { … }
GpuHostImpl::~GpuHostImpl() { … }
void GpuHostImpl::InitFontRenderParams(const gfx::FontRenderParams& params) { … }
void GpuHostImpl::SetProcessId(base::ProcessId pid) { … }
void GpuHostImpl::OnProcessCrashed() { … }
void GpuHostImpl::AddConnectionErrorHandler(base::OnceClosure handler) { … }
void GpuHostImpl::BlockLiveOffscreenContexts() { … }
void GpuHostImpl::ConnectFrameSinkManager(
mojo::PendingReceiver<mojom::FrameSinkManager> receiver,
mojo::PendingRemote<mojom::FrameSinkManagerClient> client,
const DebugRendererSettings& debug_renderer_settings) { … }
void GpuHostImpl::EstablishGpuChannel(int client_id,
uint64_t client_tracing_id,
bool is_gpu_host,
bool sync,
EstablishChannelCallback callback) { … }
void GpuHostImpl::SetChannelClientPid(int client_id,
base::ProcessId client_pid) { … }
void GpuHostImpl::SetChannelDiskCacheHandle(
int client_id,
const gpu::GpuDiskCacheHandle& handle) { … }
void GpuHostImpl::RemoveChannelDiskCacheHandles(int client_id) { … }
void GpuHostImpl::CloseChannel(int client_id) { … }
#if BUILDFLAG(USE_VIZ_DEBUGGER)
void GpuHostImpl::FilterVisualDebugStream(base::Value::Dict json) { … }
void GpuHostImpl::StartVisualDebugStream(
base::RepeatingCallback<void(base::Value)> callback) { … }
void GpuHostImpl::StopVisualDebugStream() { … }
#endif
void GpuHostImpl::SendOutstandingReplies() { … }
void GpuHostImpl::BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) { … }
mojom::GpuService* GpuHostImpl::gpu_service() { … }
#if BUILDFLAG(IS_WIN)
mojom::InfoCollectionGpuService* GpuHostImpl::info_collection_gpu_service() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(info_collection_gpu_service_remote_.is_bound());
return info_collection_gpu_service_remote_.get();
}
#endif
#if BUILDFLAG(IS_OZONE)
void GpuHostImpl::InitOzone() { … }
void GpuHostImpl::TerminateGpuProcess(const std::string& message) { … }
#endif
std::string GpuHostImpl::GetShaderPrefixKey() { … }
void GpuHostImpl::LoadedBlob(const gpu::GpuDiskCacheHandle& handle,
const std::string& key,
const std::string& data) { … }
void GpuHostImpl::OnDiskCacheHandleDestoyed(
const gpu::GpuDiskCacheHandle& handle) { … }
void GpuHostImpl::OnChannelEstablished(
int client_id,
bool sync,
mojo::ScopedMessagePipeHandle channel_handle,
const gpu::GPUInfo& gpu_info,
const gpu::GpuFeatureInfo& gpu_feature_info,
const gpu::SharedImageCapabilities& shared_image_capabilities) { … }
void GpuHostImpl::DidInitialize(
const gpu::GPUInfo& gpu_info,
const gpu::GpuFeatureInfo& gpu_feature_info,
const std::optional<gpu::GPUInfo>& gpu_info_for_hardware_gpu,
const std::optional<gpu::GpuFeatureInfo>& gpu_feature_info_for_hardware_gpu,
const gfx::GpuExtraInfo& gpu_extra_info) { … }
void GpuHostImpl::DidFailInitialize() { … }
void GpuHostImpl::DidCreateContextSuccessfully() { … }
void GpuHostImpl::DidCreateOffscreenContext(const GURL& url) { … }
void GpuHostImpl::DidDestroyOffscreenContext(const GURL& url) { … }
void GpuHostImpl::DidDestroyChannel(int32_t client_id) { … }
void GpuHostImpl::DidDestroyAllChannels() { … }
void GpuHostImpl::MaybeShutdownGpuProcess() { … }
void GpuHostImpl::DidLoseContext(gpu::error::ContextLostReason reason,
const GURL& active_url) { … }
void GpuHostImpl::DisableGpuCompositing() { … }
void GpuHostImpl::GetIsolationKey(
int32_t client_id,
const blink::WebGPUExecutionContextToken& token,
GetIsolationKeyCallback cb) { … }
void GpuHostImpl::DidUpdateGPUInfo(const gpu::GPUInfo& gpu_info) { … }
#if BUILDFLAG(IS_WIN)
void GpuHostImpl::DidUpdateOverlayInfo(const gpu::OverlayInfo& overlay_info) {
delegate_->DidUpdateOverlayInfo(overlay_info);
}
void GpuHostImpl::DidUpdateDXGIInfo(gfx::mojom::DXGIInfoPtr dxgi_info) {
delegate_->DidUpdateDXGIInfo(std::move(dxgi_info));
}
void GpuHostImpl::AddChildWindow(gpu::SurfaceHandle parent_window,
gpu::SurfaceHandle child_window) {
if (pid_ != base::kNullProcessId) {
gfx::RenderingWindowManager::GetInstance()->RegisterChild(
parent_window, child_window, pid_);
}
}
#endif
void GpuHostImpl::MaybeSendFontRenderParams() { … }
void GpuHostImpl::StoreBlobToDisk(const gpu::GpuDiskCacheHandle& handle,
const std::string& key,
const std::string& blob) { … }
void GpuHostImpl::RecordLogMessage(int32_t severity,
const std::string& header,
const std::string& message) { … }
void GpuHostImpl::ClearGrShaderDiskCache() { … }
#if BUILDFLAG(USE_VIZ_DEBUGGER)
void GpuHostImpl::LogFrame(base::Value frame_data) { … }
#endif
}