#include "content/gpu/gpu_child_thread.h"
#include <stddef.h>
#include <memory>
#include <utility>
#include "base/command_line.h"
#include "base/debug/dump_without_crashing.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/weak_ptr.h"
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_monitor_device_source.h"
#include "base/run_loop.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_checker.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/child/child_process.h"
#include "content/common/process_visibility_tracker.h"
#include "content/gpu/browser_exposed_gpu_interfaces.h"
#include "content/gpu/gpu_service_factory.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/gpu/content_gpu_client.h"
#include "gpu/command_buffer/common/shm_count.h"
#include "gpu/ipc/service/gpu_channel_manager.h"
#include "gpu/ipc/service/gpu_init.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h"
#include "ipc/ipc_sync_message_filter.h"
#include "media/gpu/ipc/service/media_gpu_channel_manager.h"
#include "mojo/public/cpp/bindings/binder_map.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/scoped_message_error_crash_key.h"
#include "mojo/public/cpp/system/functions.h"
#include "services/metrics/public/cpp/mojo_ukm_recorder.h"
#include "services/metrics/public/mojom/ukm_interface.mojom.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/viz/privileged/mojom/gl/gpu_service.mojom.h"
#include "third_party/skia/include/core/SkGraphics.h"
#if BUILDFLAG(IS_ANDROID)
#include "media/base/android/media_drm_bridge_client.h"
#include "media/mojo/clients/mojo_android_overlay.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "components/services/font/public/cpp/font_loader.h"
#include "components/services/font/public/mojom/font_service.mojom.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/ports/SkFontConfigInterface.h"
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "content/child/sandboxed_process_thread_type_handler.h"
#endif
namespace content {
namespace {
void HandleBadMessage(const std::string& error) { … }
ChildThreadImpl::Options GetOptions(
const InProcessChildThreadParams* in_process_params = nullptr) { … }
viz::VizMainImpl::ExternalDependencies CreateVizMainDependencies() { … }
}
GpuChildThread::GpuChildThread(base::RepeatingClosure quit_closure,
std::unique_ptr<gpu::GpuInit> gpu_init)
: … { … }
GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params,
std::unique_ptr<gpu::GpuInit> gpu_init)
: … { … }
GpuChildThread::GpuChildThread(base::RepeatingClosure quit_closure,
ChildThreadImpl::Options options,
std::unique_ptr<gpu::GpuInit> gpu_init)
: … { … }
GpuChildThread::~GpuChildThread() = default;
void GpuChildThread::Init(const base::TimeTicks& process_start_time) { … }
bool GpuChildThread::in_process_gpu() const { … }
void GpuChildThread::OnInitializationFailed() { … }
void GpuChildThread::OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) { … }
void GpuChildThread::PostCompositorThreadCreated(
base::SingleThreadTaskRunner* task_runner) { … }
void GpuChildThread::QuitMainMessageLoop() { … }
void GpuChildThread::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level) { … }
void GpuChildThread::QuitSafelyHelper(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
base::RepeatingClosure GpuChildThread::MakeQuitSafelyClosure() { … }
#if BUILDFLAG(IS_ANDROID)
std::unique_ptr<media::AndroidOverlay> GpuChildThread::CreateAndroidOverlay(
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
const base::UnguessableToken& routing_token,
media::AndroidOverlayConfig config) {
mojo::PendingRemote<media::mojom::AndroidOverlayProvider> overlay_provider;
if (main_task_runner->RunsTasksInCurrentSequence()) {
ChildThread::Get()->BindHostReceiver(
overlay_provider.InitWithNewPipeAndPassReceiver());
} else {
main_task_runner->PostTask(
FROM_HERE,
base::BindOnce(
[](mojo::PendingReceiver<media::mojom::AndroidOverlayProvider>
receiver) {
ChildThread::Get()->BindHostReceiver(std::move(receiver));
},
overlay_provider.InitWithNewPipeAndPassReceiver()));
}
return std::make_unique<media::MojoAndroidOverlay>(
std::move(overlay_provider), std::move(config), routing_token);
}
#endif
}