Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 5 | #include "content/gpu/gpu_child_thread.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 6 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 7 | #include <stddef.h> |
Peter Boström | dd7e40ec | 2021-04-05 20:40:10 | [diff] [blame] | 8 | |
| 9 | #include <memory> |
dcheng | f63a125 | 2015-12-26 20:43:13 | [diff] [blame] | 10 | #include <utility> |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 11 | |
kylechar | 150e09e1 | 2017-10-19 13:57:52 | [diff] [blame] | 12 | #include "base/command_line.h" |
kylechar | 4664a16 | 2020-09-15 03:19:34 | [diff] [blame] | 13 | #include "base/debug/dump_without_crashing.h" |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 14 | #include "base/functional/bind.h" |
| 15 | #include "base/functional/callback_helpers.h" |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
Tom McKee | 1467915 | 2020-01-20 16:06:52 | [diff] [blame] | 17 | #include "base/power_monitor/power_monitor.h" |
| 18 | #include "base/power_monitor/power_monitor_device_source.h" |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 19 | #include "base/run_loop.h" |
Patrick Monette | 643cdf6 | 2021-10-15 19:13:42 | [diff] [blame] | 20 | #include "base/task/sequenced_task_runner.h" |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 21 | #include "base/task/single_thread_task_runner.h" |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 22 | #include "base/threading/thread_checker.h" |
[email protected] | 274aa588 | 2010-07-15 21:12:23 | [diff] [blame] | 23 | #include "build/build_config.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 24 | #include "content/child/child_process.h" |
Oksana Zhuravlova | 0465118 | 2021-03-02 20:52:20 | [diff] [blame] | 25 | #include "content/common/process_visibility_tracker.h" |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 26 | #include "content/gpu/browser_exposed_gpu_interfaces.h" |
ben | 507aa81 | 2016-08-10 23:26:19 | [diff] [blame] | 27 | #include "content/gpu/gpu_service_factory.h" |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 28 | #include "content/public/common/content_client.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 29 | #include "content/public/common/content_switches.h" |
kcwu | 08377ad | 2016-02-18 19:12:42 | [diff] [blame] | 30 | #include "content/public/gpu/content_gpu_client.h" |
Bo Liu | 01d003e4e | 2023-08-16 19:46:50 | [diff] [blame] | 31 | #include "gpu/command_buffer/common/shm_count.h" |
Dan Sanders | 0134bec | 2018-04-17 20:12:12 | [diff] [blame] | 32 | #include "gpu/ipc/service/gpu_channel_manager.h" |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 33 | #include "gpu/ipc/service/gpu_init.h" |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame] | 34 | #include "gpu/ipc/service/gpu_watchdog_thread.h" |
xhwang | b2402d9 | 2016-10-15 07:29:37 | [diff] [blame] | 35 | #include "media/gpu/ipc/service/media_gpu_channel_manager.h" |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 36 | #include "mojo/public/cpp/bindings/binder_map.h" |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 37 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
| 38 | #include "mojo/public/cpp/bindings/pending_remote.h" |
kylechar | 4664a16 | 2020-09-15 03:19:34 | [diff] [blame] | 39 | #include "mojo/public/cpp/bindings/scoped_message_error_crash_key.h" |
| 40 | #include "mojo/public/cpp/system/functions.h" |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 41 | #include "services/metrics/public/cpp/mojo_ukm_recorder.h" |
| 42 | #include "services/metrics/public/mojom/ukm_interface.mojom.h" |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 43 | #include "services/service_manager/public/cpp/binder_registry.h" |
Miyoung Shin | 2be27f5 | 2019-07-27 15:35:39 | [diff] [blame] | 44 | #include "services/viz/privileged/mojom/gl/gpu_service.mojom.h" |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 45 | #include "third_party/skia/include/core/SkGraphics.h" |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 46 | |
Xiaohan Wang | 62737b5 | 2022-01-15 18:09:02 | [diff] [blame] | 47 | #if BUILDFLAG(IS_ANDROID) |
chcunningham | a4a8efb | 2017-03-22 16:55:02 | [diff] [blame] | 48 | #include "media/base/android/media_drm_bridge_client.h" |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 49 | #include "media/mojo/clients/mojo_android_overlay.h" |
watk | ad8743d | 2016-04-27 20:27:49 | [diff] [blame] | 50 | #endif |
| 51 | |
Georg Neis | 18fc514 | 2024-12-18 00:58:41 | [diff] [blame] | 52 | #if BUILDFLAG(IS_CHROMEOS) |
Eric Sum | c8607e7 | 2022-02-18 00:48:03 | [diff] [blame] | 53 | #include "components/services/font/public/cpp/font_loader.h" // nogncheck |
| 54 | #include "components/services/font/public/mojom/font_service.mojom.h" // nogncheck |
| 55 | #include "third_party/skia/include/core/SkRefCnt.h" |
| 56 | #include "third_party/skia/include/ports/SkFontConfigInterface.h" |
| 57 | #endif |
| 58 | |
Matthew Denton | 66b2fa5 | 2023-10-17 00:54:22 | [diff] [blame] | 59 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
| 60 | #include "content/child/sandboxed_process_thread_type_handler.h" |
| 61 | #endif |
| 62 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 63 | namespace content { |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 64 | namespace { |
| 65 | |
kylechar | 4664a16 | 2020-09-15 03:19:34 | [diff] [blame] | 66 | // Called when the GPU process receives a bad IPC message. |
| 67 | void HandleBadMessage(const std::string& error) { |
| 68 | LOG(ERROR) << "Mojo error in GPU process: " << error; |
| 69 | mojo::debug::ScopedMessageErrorCrashKey crash_key_value(error); |
| 70 | base::debug::DumpWithoutCrashing(); |
| 71 | } |
| 72 | |
Ken Rockot | 2d483bc | 2021-06-17 22:39:02 | [diff] [blame] | 73 | ChildThreadImpl::Options GetOptions( |
| 74 | const InProcessChildThreadParams* in_process_params = nullptr) { |
skyostil | f28ccd0b | 2015-03-04 20:20:46 | [diff] [blame] | 75 | ChildThreadImpl::Options::Builder builder; |
wittman | 757af87 | 2016-08-16 00:13:46 | [diff] [blame] | 76 | builder.ConnectToBrowser(true); |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 77 | builder.ExposesInterfacesToBrowser(); |
Ken Rockot | 2d483bc | 2021-06-17 22:39:02 | [diff] [blame] | 78 | if (in_process_params) |
| 79 | builder.InBrowserProcess(*in_process_params); |
skyostil | f28ccd0b | 2015-03-04 20:20:46 | [diff] [blame] | 80 | return builder.Build(); |
alexst | 6154ce77 | 2015-01-21 12:41:41 | [diff] [blame] | 81 | } |
| 82 | |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 83 | viz::VizMainImpl::ExternalDependencies CreateVizMainDependencies() { |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 84 | viz::VizMainImpl::ExternalDependencies deps; |
Helmut Januschka | bcf7321 | 2024-09-03 23:49:18 | [diff] [blame] | 85 | if (!base::PowerMonitor::GetInstance()->IsInitialized()) { |
Tom McKee | 1467915 | 2020-01-20 16:06:52 | [diff] [blame] | 86 | deps.power_monitor_source = |
| 87 | std::make_unique<base::PowerMonitorDeviceSource>(); |
| 88 | } |
Colin Blundell | 7eb345b | 2024-11-05 13:20:14 | [diff] [blame] | 89 | |
| 90 | #if BUILDFLAG(IS_ANDROID) |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 91 | if (GetContentClient()->gpu()) { |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 92 | deps.sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 93 | deps.shared_image_manager = |
| 94 | GetContentClient()->gpu()->GetSharedImageManager(); |
Bo Liu | eca0009f | 2022-08-25 22:59:32 | [diff] [blame] | 95 | deps.scheduler = GetContentClient()->gpu()->GetScheduler(); |
Bo Liu | a7b2ce6 | 2019-08-02 22:16:23 | [diff] [blame] | 96 | deps.viz_compositor_thread_runner = |
| 97 | GetContentClient()->gpu()->GetVizCompositorThreadRunner(); |
Alex Mitra | c246bcc | 2024-11-29 16:22:10 | [diff] [blame] | 98 | deps.gr_context_options_provider = |
| 99 | GetContentClient()->gpu()->GetGrContextOptionsProvider(); |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 100 | } |
Colin Blundell | 7eb345b | 2024-11-05 13:20:14 | [diff] [blame] | 101 | #endif |
| 102 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 103 | auto* process = ChildProcess::current(); |
| 104 | deps.shutdown_event = process->GetShutDownEvent(); |
| 105 | deps.io_thread_task_runner = process->io_task_runner(); |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 106 | |
Aman Verma | 8c1c5e61 | 2023-04-03 23:33:58 | [diff] [blame] | 107 | mojo::Remote<ukm::mojom::UkmRecorderFactory> factory; |
| 108 | ChildThread::Get()->BindHostReceiver(factory.BindNewPipeAndPassReceiver()); |
| 109 | deps.ukm_recorder = ukm::MojoUkmRecorder::Create(*factory); |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 110 | return deps; |
| 111 | } |
| 112 | |
[email protected] | e6ff5a31f | 2011-01-31 20:36:22 | [diff] [blame] | 113 | } // namespace |
[email protected] | 9158f2f | 2011-01-27 21:08:57 | [diff] [blame] | 114 | |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 115 | GpuChildThread::GpuChildThread(base::RepeatingClosure quit_closure, |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 116 | std::unique_ptr<gpu::GpuInit> gpu_init) |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 117 | : GpuChildThread(std::move(quit_closure), |
| 118 | GetOptions(), |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 119 | std::move(gpu_init)) {} |
[email protected] | 9158f2f | 2011-01-27 21:08:57 | [diff] [blame] | 120 | |
sadrul | 6d41b82 | 2017-04-02 03:38:50 | [diff] [blame] | 121 | GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 122 | std::unique_ptr<gpu::GpuInit> gpu_init) |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 123 | : GpuChildThread(base::DoNothing(), |
Ken Rockot | 2d483bc | 2021-06-17 22:39:02 | [diff] [blame] | 124 | GetOptions(¶ms), |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 125 | std::move(gpu_init)) {} |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 126 | |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 127 | GpuChildThread::GpuChildThread(base::RepeatingClosure quit_closure, |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 128 | ChildThreadImpl::Options options, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 129 | std::unique_ptr<gpu::GpuInit> gpu_init) |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 130 | : ChildThreadImpl(MakeQuitSafelyClosure(), std::move(options)), |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 131 | viz_main_(this, CreateVizMainDependencies(), std::move(gpu_init)), |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 132 | quit_closure_(std::move(quit_closure)) { |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 133 | if (in_process_gpu()) { |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 134 | DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 135 | switches::kSingleProcess) || |
| 136 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 137 | switches::kInProcessGPU)); |
| 138 | } |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 139 | } |
| 140 | |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 141 | GpuChildThread::~GpuChildThread() = default; |
[email protected] | ce79d851 | 2013-04-22 22:44:41 | [diff] [blame] | 142 | |
Sean Maher | f36d812 | 2022-08-05 02:33:35 | [diff] [blame] | 143 | void GpuChildThread::Init(const base::TimeTicks& process_start_time) { |
kylechar | 4664a16 | 2020-09-15 03:19:34 | [diff] [blame] | 144 | if (!in_process_gpu()) |
| 145 | mojo::SetDefaultProcessErrorHandler(base::BindRepeating(&HandleBadMessage)); |
| 146 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 147 | viz_main_.gpu_service()->set_start_time(process_start_time); |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 148 | |
Matthew Denton | 66b2fa5 | 2023-10-17 00:54:22 | [diff] [blame] | 149 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
| 150 | SandboxedProcessThreadTypeHandler::NotifyMainChildThreadCreated(); |
| 151 | #endif |
| 152 | |
xhwang | ded3b6e | 2016-05-25 05:24:51 | [diff] [blame] | 153 | // When running in in-process mode, this has been set in the browser at |
| 154 | // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). |
Xiaohan Wang | 62737b5 | 2022-01-15 18:09:02 | [diff] [blame] | 155 | #if BUILDFLAG(IS_ANDROID) |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 156 | if (!in_process_gpu()) { |
chcunningham | a4a8efb | 2017-03-22 16:55:02 | [diff] [blame] | 157 | media::SetMediaDrmBridgeClient( |
| 158 | GetContentClient()->GetMediaDrmBridgeClient()); |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 159 | } |
xhwang | ded3b6e | 2016-05-25 05:24:51 | [diff] [blame] | 160 | #endif |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 161 | |
Georg Neis | 18fc514 | 2024-12-18 00:58:41 | [diff] [blame] | 162 | #if BUILDFLAG(IS_CHROMEOS) |
Eric Sum | c8607e7 | 2022-02-18 00:48:03 | [diff] [blame] | 163 | if (!in_process_gpu()) { |
| 164 | mojo::PendingRemote<font_service::mojom::FontService> font_service; |
| 165 | BindHostReceiver(font_service.InitWithNewPipeAndPassReceiver()); |
| 166 | SkFontConfigInterface::SetGlobal( |
| 167 | sk_make_sp<font_service::FontLoader>(std::move(font_service))); |
| 168 | } |
| 169 | #endif |
| 170 | |
Sebastien Marchand | 17797d9 | 2020-06-23 20:27:59 | [diff] [blame] | 171 | memory_pressure_listener_ = std::make_unique<base::MemoryPressureListener>( |
| 172 | FROM_HERE, base::BindRepeating(&GpuChildThread::OnMemoryPressure, |
| 173 | base::Unretained(this))); |
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 174 | } |
| 175 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 176 | bool GpuChildThread::in_process_gpu() const { |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 177 | return viz_main_.gpu_service()->gpu_info().in_process_gpu; |
sadrul | 6c5aed8c | 2017-01-11 23:11:44 | [diff] [blame] | 178 | } |
| 179 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 180 | void GpuChildThread::OnInitializationFailed() { |
| 181 | OnChannelError(); |
| 182 | } |
[email protected] | 9665973 | 2012-08-24 01:55:17 | [diff] [blame] | 183 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 184 | void GpuChildThread::OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) { |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 185 | media::AndroidOverlayMojoFactoryCB overlay_factory_cb; |
Xiaohan Wang | 62737b5 | 2022-01-15 18:09:02 | [diff] [blame] | 186 | #if BUILDFLAG(IS_ANDROID) |
kylechar | ed18a48 | 2019-02-07 14:07:21 | [diff] [blame] | 187 | overlay_factory_cb = |
| 188 | base::BindRepeating(&GpuChildThread::CreateAndroidOverlay, |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 189 | base::SingleThreadTaskRunner::GetCurrentDefault()); |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 190 | gpu_service->media_gpu_channel_manager()->SetOverlayFactory( |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 191 | overlay_factory_cb); |
| 192 | #endif |
| 193 | |
Oksana Zhuravlova | 0465118 | 2021-03-02 20:52:20 | [diff] [blame] | 194 | if (!IsInBrowserProcess()) { |
| 195 | gpu_service->SetVisibilityChangedCallback( |
| 196 | base::BindRepeating([](bool visible) { |
| 197 | ProcessVisibilityTracker::GetInstance()->OnProcessVisibilityChanged( |
| 198 | visible); |
| 199 | })); |
| 200 | } |
| 201 | |
piman | 223a53c | 2016-07-21 03:41:52 | [diff] [blame] | 202 | // Only set once per process instance. |
Peter Boström | dd7e40ec | 2021-04-05 20:40:10 | [diff] [blame] | 203 | service_factory_ = std::make_unique<GpuServiceFactory>( |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 204 | gpu_service->gpu_preferences(), |
Dan Sanders | 0134bec | 2018-04-17 20:12:12 | [diff] [blame] | 205 | gpu_service->gpu_channel_manager()->gpu_driver_bug_workarounds(), |
Ted Meyer | 68b35b9 | 2021-11-20 02:35:23 | [diff] [blame] | 206 | gpu_service->gpu_feature_info(), gpu_service->gpu_info(), |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 207 | gpu_service->media_gpu_channel_manager()->AsWeakPtr(), |
Colin Blundell | da71730 | 2025-07-08 17:10:52 | [diff] [blame] | 208 | std::move(overlay_factory_cb)); |
Ken Rockot | a292417 | 2019-12-18 03:27:05 | [diff] [blame] | 209 | for (auto& receiver : pending_service_receivers_) |
| 210 | BindServiceInterface(std::move(receiver)); |
| 211 | pending_service_receivers_.clear(); |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 212 | |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 213 | if (GetContentClient()->gpu()) // Null in tests. |
| 214 | GetContentClient()->gpu()->GpuServiceInitialized(); |
piman | 223a53c | 2016-07-21 03:41:52 | [diff] [blame] | 215 | |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 216 | // Start allowing browser-exposed interfaces to be bound. |
| 217 | // |
| 218 | // NOTE: Do not add new binders within this method. Instead modify |
| 219 | // |ExposeGpuInterfacesToBrowser()| in browser_exposed_gpu_interfaces.cc, as |
| 220 | // that will ensure security review coverage. |
| 221 | mojo::BinderMap binders; |
Chunbo Hua | d90bffb2 | 2020-09-28 15:34:36 | [diff] [blame] | 222 | content::ExposeGpuInterfacesToBrowser( |
Colin Blundell | 8b1809e | 2025-07-09 08:01:11 | [diff] [blame] | 223 | gpu_service, gpu_service->gpu_preferences(), |
Chunbo Hua | d90bffb2 | 2020-09-28 15:34:36 | [diff] [blame] | 224 | gpu_service->gpu_channel_manager()->gpu_driver_bug_workarounds(), |
| 225 | &binders); |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 226 | ExposeInterfacesToBrowser(std::move(binders)); |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 227 | } |
| 228 | |
Sadrul Habib Chowdhury | 97c6f1f | 2018-03-02 01:21:16 | [diff] [blame] | 229 | void GpuChildThread::PostCompositorThreadCreated( |
| 230 | base::SingleThreadTaskRunner* task_runner) { |
| 231 | auto* gpu_client = GetContentClient()->gpu(); |
| 232 | if (gpu_client) |
| 233 | gpu_client->PostCompositorThreadCreated(task_runner); |
| 234 | } |
| 235 | |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 236 | void GpuChildThread::QuitMainMessageLoop() { |
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 237 | quit_closure_.Run(); |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 238 | } |
| 239 | |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 240 | void GpuChildThread::OnMemoryPressure( |
| 241 | base::MemoryPressureListener::MemoryPressureLevel level) { |
Takashi Sakamoto | bb07480 | 2018-10-15 07:35:27 | [diff] [blame] | 242 | if (level != base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) |
| 243 | return; |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 244 | |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 245 | if (viz_main_.discardable_shared_memory_manager()) |
| 246 | viz_main_.discardable_shared_memory_manager()->ReleaseFreeMemory(); |
| 247 | SkGraphics::PurgeAllCaches(); |
| 248 | } |
| 249 | |
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 250 | void GpuChildThread::QuitSafelyHelper( |
| 251 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 252 | // Post a new task (even if we're called on the |task_runner|'s thread) to |
| 253 | // ensure that we are post-init. |
| 254 | task_runner->PostTask( |
| 255 | FROM_HERE, base::BindOnce([]() { |
| 256 | ChildThreadImpl* current_child_thread = ChildThreadImpl::current(); |
| 257 | if (!current_child_thread) |
| 258 | return; |
| 259 | GpuChildThread* gpu_child_thread = |
| 260 | static_cast<GpuChildThread*>(current_child_thread); |
Patrick To | df5911c | 2020-05-12 19:31:42 | [diff] [blame] | 261 | gpu_child_thread->viz_main_.ExitProcess( |
| 262 | viz::ExitCode::RESULT_CODE_NORMAL_EXIT); |
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 263 | })); |
| 264 | } |
| 265 | |
| 266 | // Returns a closure which calls into the VizMainImpl to perform shutdown |
| 267 | // before quitting the main message loop. Must be called on the main thread. |
| 268 | base::RepeatingClosure GpuChildThread::MakeQuitSafelyClosure() { |
| 269 | return base::BindRepeating(&GpuChildThread::QuitSafelyHelper, |
Sean Maher | 5b9af51f | 2022-11-21 15:32:47 | [diff] [blame] | 270 | base::SingleThreadTaskRunner::GetCurrentDefault()); |
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 271 | } |
| 272 | |
Xiaohan Wang | 62737b5 | 2022-01-15 18:09:02 | [diff] [blame] | 273 | #if BUILDFLAG(IS_ANDROID) |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 274 | // static |
| 275 | std::unique_ptr<media::AndroidOverlay> GpuChildThread::CreateAndroidOverlay( |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 276 | scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 277 | const base::UnguessableToken& routing_token, |
| 278 | media::AndroidOverlayConfig config) { |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 279 | mojo::PendingRemote<media::mojom::AndroidOverlayProvider> overlay_provider; |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 280 | if (main_task_runner->RunsTasksInCurrentSequence()) { |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 281 | ChildThread::Get()->BindHostReceiver( |
| 282 | overlay_provider.InitWithNewPipeAndPassReceiver()); |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 283 | } else { |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 284 | main_task_runner->PostTask( |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 285 | FROM_HERE, |
| 286 | base::BindOnce( |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 287 | [](mojo::PendingReceiver<media::mojom::AndroidOverlayProvider> |
| 288 | receiver) { |
| 289 | ChildThread::Get()->BindHostReceiver(std::move(receiver)); |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 290 | }, |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 291 | overlay_provider.InitWithNewPipeAndPassReceiver())); |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 292 | } |
| 293 | |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 294 | return std::make_unique<media::MojoAndroidOverlay>( |
[email protected] | 9a635ee | 2017-12-01 21:38:50 | [diff] [blame] | 295 | std::move(overlay_provider), std::move(config), routing_token); |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 296 | } |
| 297 | #endif |
| 298 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 299 | } // namespace content |