[email protected] | f091824 | 2012-02-18 00:30:50 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[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> |
dcheng | f63a125 | 2015-12-26 20:43:13 | [diff] [blame] | 8 | #include <utility> |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 9 | |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 10 | #include "base/allocator/allocator_extension.h" |
[email protected] | 8075105 | 2011-11-12 17:10:58 | [diff] [blame] | 11 | #include "base/bind.h" |
Sebastien Marchand | 17fa278 | 2019-01-25 19:28:10 | [diff] [blame] | 12 | #include "base/bind_helpers.h" |
rockot | caccf78 | 2016-06-29 23:39:16 | [diff] [blame] | 13 | #include "base/callback_helpers.h" |
kylechar | 150e09e1 | 2017-10-19 13:57:52 | [diff] [blame] | 14 | #include "base/command_line.h" |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
Tom McKee | 1467915 | 2020-01-20 16:06:52 | [diff] [blame] | 16 | #include "base/power_monitor/power_monitor.h" |
| 17 | #include "base/power_monitor/power_monitor_device_source.h" |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 18 | #include "base/run_loop.h" |
Gabriel Charette | 5ff87ce | 2017-05-16 18:03:45 | [diff] [blame] | 19 | #include "base/sequenced_task_runner.h" |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 20 | #include "base/threading/thread_checker.h" |
[email protected] | 274aa588 | 2010-07-15 21:12:23 | [diff] [blame] | 21 | #include "build/build_config.h" |
[email protected] | 10208ea | 2013-06-06 20:08:03 | [diff] [blame] | 22 | #include "content/child/child_process.h" |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 23 | #include "content/gpu/browser_exposed_gpu_interfaces.h" |
ben | 507aa81 | 2016-08-10 23:26:19 | [diff] [blame] | 24 | #include "content/gpu/gpu_service_factory.h" |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 25 | #include "content/public/common/content_client.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 26 | #include "content/public/common/content_switches.h" |
chiniforooshan | 701fa21 | 2017-04-06 22:22:49 | [diff] [blame] | 27 | #include "content/public/common/service_names.mojom.h" |
kcwu | 08377ad | 2016-02-18 19:12:42 | [diff] [blame] | 28 | #include "content/public/gpu/content_gpu_client.h" |
ericrk | 8c0b7bf6 | 2017-03-17 20:07:23 | [diff] [blame] | 29 | #include "gpu/command_buffer/common/activity_flags.h" |
Dan Sanders | 0134bec | 2018-04-17 20:12:12 | [diff] [blame] | 30 | #include "gpu/ipc/service/gpu_channel_manager.h" |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 31 | #include "gpu/ipc/service/gpu_init.h" |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame] | 32 | #include "gpu/ipc/service/gpu_watchdog_thread.h" |
[email protected] | 8c81e9ecc | 2012-04-25 00:42:27 | [diff] [blame] | 33 | #include "ipc/ipc_sync_message_filter.h" |
xhwang | b2402d9 | 2016-10-15 07:29:37 | [diff] [blame] | 34 | #include "media/gpu/ipc/service/media_gpu_channel_manager.h" |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 35 | #include "mojo/public/cpp/bindings/binder_map.h" |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 36 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
| 37 | #include "mojo/public/cpp/bindings/pending_remote.h" |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 38 | #include "services/metrics/public/cpp/mojo_ukm_recorder.h" |
| 39 | #include "services/metrics/public/mojom/ukm_interface.mojom.h" |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 40 | #include "services/service_manager/public/cpp/binder_registry.h" |
Miyoung Shin | 2be27f5 | 2019-07-27 15:35:39 | [diff] [blame] | 41 | #include "services/viz/privileged/mojom/gl/gpu_service.mojom.h" |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 42 | #include "third_party/skia/include/core/SkGraphics.h" |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 43 | |
watk | ad8743d | 2016-04-27 20:27:49 | [diff] [blame] | 44 | #if defined(OS_ANDROID) |
chcunningham | a4a8efb | 2017-03-22 16:55:02 | [diff] [blame] | 45 | #include "media/base/android/media_drm_bridge_client.h" |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 46 | #include "media/mojo/clients/mojo_android_overlay.h" |
watk | ad8743d | 2016-04-27 20:27:49 | [diff] [blame] | 47 | #endif |
| 48 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 49 | namespace content { |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 50 | namespace { |
| 51 | |
sadrul | 16d3632 | 2017-03-29 00:57:16 | [diff] [blame] | 52 | ChildThreadImpl::Options GetOptions() { |
skyostil | f28ccd0b | 2015-03-04 20:20:46 | [diff] [blame] | 53 | ChildThreadImpl::Options::Builder builder; |
alexst | 6154ce77 | 2015-01-21 12:41:41 | [diff] [blame] | 54 | |
wittman | 757af87 | 2016-08-16 00:13:46 | [diff] [blame] | 55 | builder.ConnectToBrowser(true); |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 56 | builder.ExposesInterfacesToBrowser(); |
wittman | 757af87 | 2016-08-16 00:13:46 | [diff] [blame] | 57 | |
skyostil | f28ccd0b | 2015-03-04 20:20:46 | [diff] [blame] | 58 | return builder.Build(); |
alexst | 6154ce77 | 2015-01-21 12:41:41 | [diff] [blame] | 59 | } |
| 60 | |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 61 | viz::VizMainImpl::ExternalDependencies CreateVizMainDependencies() { |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 62 | viz::VizMainImpl::ExternalDependencies deps; |
Tom McKee | 1467915 | 2020-01-20 16:06:52 | [diff] [blame] | 63 | if (!base::PowerMonitor::IsInitialized()) { |
| 64 | deps.power_monitor_source = |
| 65 | std::make_unique<base::PowerMonitorDeviceSource>(); |
| 66 | } |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 67 | if (GetContentClient()->gpu()) { |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 68 | deps.sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 69 | deps.shared_image_manager = |
| 70 | GetContentClient()->gpu()->GetSharedImageManager(); |
Bo Liu | a7b2ce6 | 2019-08-02 22:16:23 | [diff] [blame] | 71 | deps.viz_compositor_thread_runner = |
| 72 | GetContentClient()->gpu()->GetVizCompositorThreadRunner(); |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 73 | } |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 74 | auto* process = ChildProcess::current(); |
| 75 | deps.shutdown_event = process->GetShutDownEvent(); |
| 76 | deps.io_thread_task_runner = process->io_task_runner(); |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 77 | |
| 78 | mojo::PendingRemote<ukm::mojom::UkmRecorderInterface> ukm_recorder; |
| 79 | ChildThread::Get()->BindHostReceiver( |
| 80 | ukm_recorder.InitWithNewPipeAndPassReceiver()); |
| 81 | deps.ukm_recorder = |
| 82 | std::make_unique<ukm::MojoUkmRecorder>(std::move(ukm_recorder)); |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 83 | return deps; |
| 84 | } |
| 85 | |
[email protected] | e6ff5a3 | 2011-01-31 20:36:22 | [diff] [blame] | 86 | } // namespace |
[email protected] | 9158f2f | 2011-01-27 21:08:57 | [diff] [blame] | 87 | |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 88 | GpuChildThread::GpuChildThread(base::RepeatingClosure quit_closure, |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 89 | std::unique_ptr<gpu::GpuInit> gpu_init) |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 90 | : GpuChildThread(std::move(quit_closure), |
| 91 | GetOptions(), |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 92 | std::move(gpu_init)) {} |
[email protected] | 9158f2f | 2011-01-27 21:08:57 | [diff] [blame] | 93 | |
sadrul | 6d41b82 | 2017-04-02 03:38:50 | [diff] [blame] | 94 | GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 95 | std::unique_ptr<gpu::GpuInit> gpu_init) |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 96 | : GpuChildThread(base::DoNothing(), |
| 97 | ChildThreadImpl::Options::Builder() |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 98 | .InBrowserProcess(params) |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 99 | .ConnectToBrowser(true) |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 100 | .ExposesInterfacesToBrowser() |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 101 | .Build(), |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 102 | std::move(gpu_init)) {} |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 103 | |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 104 | GpuChildThread::GpuChildThread(base::RepeatingClosure quit_closure, |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 105 | ChildThreadImpl::Options options, |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 106 | std::unique_ptr<gpu::GpuInit> gpu_init) |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 107 | : ChildThreadImpl(MakeQuitSafelyClosure(), std::move(options)), |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 108 | viz_main_(this, CreateVizMainDependencies(), std::move(gpu_init)), |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 109 | quit_closure_(std::move(quit_closure)) { |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 110 | if (in_process_gpu()) { |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 111 | DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 112 | switches::kSingleProcess) || |
| 113 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 114 | switches::kInProcessGPU)); |
| 115 | } |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 116 | } |
| 117 | |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 118 | GpuChildThread::~GpuChildThread() = default; |
[email protected] | ce79d851 | 2013-04-22 22:44:41 | [diff] [blame] | 119 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 120 | void GpuChildThread::Init(const base::Time& process_start_time) { |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 121 | viz_main_.gpu_service()->set_start_time(process_start_time); |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 122 | |
xhwang | ded3b6e | 2016-05-25 05:24:51 | [diff] [blame] | 123 | // When running in in-process mode, this has been set in the browser at |
| 124 | // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 125 | #if defined(OS_ANDROID) |
| 126 | if (!in_process_gpu()) { |
chcunningham | a4a8efb | 2017-03-22 16:55:02 | [diff] [blame] | 127 | media::SetMediaDrmBridgeClient( |
| 128 | GetContentClient()->GetMediaDrmBridgeClient()); |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 129 | } |
xhwang | ded3b6e | 2016-05-25 05:24:51 | [diff] [blame] | 130 | #endif |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 131 | |
Sam McNally | 52e5028 | 2017-11-29 00:54:02 | [diff] [blame] | 132 | blink::AssociatedInterfaceRegistry* associated_registry = |
| 133 | &associated_interfaces_; |
kylechar | ed18a48 | 2019-02-07 14:07:21 | [diff] [blame] | 134 | associated_registry->AddInterface(base::BindRepeating( |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 135 | &GpuChildThread::CreateVizMainService, base::Unretained(this))); |
ben | d623444 | 2017-04-24 22:51:13 | [diff] [blame] | 136 | |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 137 | memory_pressure_listener_ = |
| 138 | std::make_unique<base::MemoryPressureListener>(base::BindRepeating( |
| 139 | &GpuChildThread::OnMemoryPressure, base::Unretained(this))); |
asvitkine | 5dc812a | 2016-06-07 18:20:30 | [diff] [blame] | 140 | } |
| 141 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 142 | void GpuChildThread::CreateVizMainService( |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 143 | mojo::PendingAssociatedReceiver<viz::mojom::VizMain> pending_receiver) { |
| 144 | viz_main_.BindAssociated(std::move(pending_receiver)); |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | bool GpuChildThread::in_process_gpu() const { |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 148 | return viz_main_.gpu_service()->gpu_info().in_process_gpu; |
sadrul | 6c5aed8c | 2017-01-11 23:11:44 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 151 | bool GpuChildThread::Send(IPC::Message* msg) { |
| 152 | // The GPU process must never send a synchronous IPC message to the browser |
[email protected] | 4c0e289d | 2011-06-01 03:45:51 | [diff] [blame] | 153 | // process. This could result in deadlock. |
| 154 | DCHECK(!msg->is_sync()); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 155 | |
jam | 8a021512a | 2015-02-03 18:16:08 | [diff] [blame] | 156 | return ChildThreadImpl::Send(msg); |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 157 | } |
| 158 | |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 159 | void GpuChildThread::OnAssociatedInterfaceRequest( |
| 160 | const std::string& name, |
| 161 | mojo::ScopedInterfaceEndpointHandle handle) { |
Ken Rockot | 26e4e80 | 2018-07-31 15:03:33 | [diff] [blame] | 162 | if (!associated_interfaces_.TryBindInterface(name, &handle)) |
rockot | 70bbb5949 | 2017-01-25 00:56:51 | [diff] [blame] | 163 | ChildThreadImpl::OnAssociatedInterfaceRequest(name, std::move(handle)); |
markdittmer | 43e79f0 | 2016-03-11 14:50:08 | [diff] [blame] | 164 | } |
| 165 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 166 | void GpuChildThread::OnInitializationFailed() { |
| 167 | OnChannelError(); |
| 168 | } |
[email protected] | 9665973 | 2012-08-24 01:55:17 | [diff] [blame] | 169 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 170 | void GpuChildThread::OnGpuServiceConnection(viz::GpuServiceImpl* gpu_service) { |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 171 | media::AndroidOverlayMojoFactoryCB overlay_factory_cb; |
| 172 | #if defined(OS_ANDROID) |
kylechar | ed18a48 | 2019-02-07 14:07:21 | [diff] [blame] | 173 | overlay_factory_cb = |
| 174 | base::BindRepeating(&GpuChildThread::CreateAndroidOverlay, |
| 175 | base::ThreadTaskRunnerHandle::Get()); |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 176 | gpu_service->media_gpu_channel_manager()->SetOverlayFactory( |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 177 | overlay_factory_cb); |
| 178 | #endif |
| 179 | |
piman | 223a53c | 2016-07-21 03:41:52 | [diff] [blame] | 180 | // Only set once per process instance. |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 181 | service_factory_.reset(new GpuServiceFactory( |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 182 | gpu_service->gpu_preferences(), |
Dan Sanders | 0134bec | 2018-04-17 20:12:12 | [diff] [blame] | 183 | gpu_service->gpu_channel_manager()->gpu_driver_bug_workarounds(), |
Khushal | a55414a | 2018-10-09 17:13:53 | [diff] [blame] | 184 | gpu_service->gpu_feature_info(), |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 185 | gpu_service->media_gpu_channel_manager()->AsWeakPtr(), |
Jeffrey Kardatzke | 67d88fb5 | 2019-10-08 19:02:05 | [diff] [blame] | 186 | gpu_service->gpu_memory_buffer_factory(), std::move(overlay_factory_cb))); |
Ken Rockot | a292417 | 2019-12-18 03:27:05 | [diff] [blame] | 187 | for (auto& receiver : pending_service_receivers_) |
| 188 | BindServiceInterface(std::move(receiver)); |
| 189 | pending_service_receivers_.clear(); |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 190 | |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 191 | if (GetContentClient()->gpu()) // Null in tests. |
| 192 | GetContentClient()->gpu()->GpuServiceInitialized(); |
piman | 223a53c | 2016-07-21 03:41:52 | [diff] [blame] | 193 | |
Ken Rockot | 6d9ed9503 | 2019-11-13 17:20:47 | [diff] [blame] | 194 | // Start allowing browser-exposed interfaces to be bound. |
| 195 | // |
| 196 | // NOTE: Do not add new binders within this method. Instead modify |
| 197 | // |ExposeGpuInterfacesToBrowser()| in browser_exposed_gpu_interfaces.cc, as |
| 198 | // that will ensure security review coverage. |
| 199 | mojo::BinderMap binders; |
| 200 | content::ExposeGpuInterfacesToBrowser(gpu_service->gpu_preferences(), |
| 201 | &binders); |
| 202 | ExposeInterfacesToBrowser(std::move(binders)); |
[email protected] | 7709e71 | 2011-01-07 17:57:31 | [diff] [blame] | 203 | } |
| 204 | |
Sadrul Habib Chowdhury | 97c6f1f | 2018-03-02 01:21:16 | [diff] [blame] | 205 | void GpuChildThread::PostCompositorThreadCreated( |
| 206 | base::SingleThreadTaskRunner* task_runner) { |
| 207 | auto* gpu_client = GetContentClient()->gpu(); |
| 208 | if (gpu_client) |
| 209 | gpu_client->PostCompositorThreadCreated(task_runner); |
| 210 | } |
| 211 | |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 212 | void GpuChildThread::QuitMainMessageLoop() { |
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 213 | quit_closure_.Run(); |
Wez | 6979109b | 2018-09-07 17:30:56 | [diff] [blame] | 214 | } |
| 215 | |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 216 | void GpuChildThread::OnMemoryPressure( |
| 217 | base::MemoryPressureListener::MemoryPressureLevel level) { |
Takashi Sakamoto | bb07480 | 2018-10-15 07:35:27 | [diff] [blame] | 218 | if (level != base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) |
| 219 | return; |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 220 | |
Khushal | 0aac6207 | 2018-06-01 19:33:17 | [diff] [blame] | 221 | base::allocator::ReleaseFreeMemory(); |
| 222 | if (viz_main_.discardable_shared_memory_manager()) |
| 223 | viz_main_.discardable_shared_memory_manager()->ReleaseFreeMemory(); |
| 224 | SkGraphics::PurgeAllCaches(); |
| 225 | } |
| 226 | |
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 227 | void GpuChildThread::QuitSafelyHelper( |
| 228 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 229 | // Post a new task (even if we're called on the |task_runner|'s thread) to |
| 230 | // ensure that we are post-init. |
| 231 | task_runner->PostTask( |
| 232 | FROM_HERE, base::BindOnce([]() { |
| 233 | ChildThreadImpl* current_child_thread = ChildThreadImpl::current(); |
| 234 | if (!current_child_thread) |
| 235 | return; |
| 236 | GpuChildThread* gpu_child_thread = |
| 237 | static_cast<GpuChildThread*>(current_child_thread); |
Patrick To | df5911c | 2020-05-12 19:31:42 | [diff] [blame] | 238 | gpu_child_thread->viz_main_.ExitProcess( |
| 239 | viz::ExitCode::RESULT_CODE_NORMAL_EXIT); |
Eric Karl | 23af711f | 2018-11-02 20:47:34 | [diff] [blame] | 240 | })); |
| 241 | } |
| 242 | |
| 243 | // Returns a closure which calls into the VizMainImpl to perform shutdown |
| 244 | // before quitting the main message loop. Must be called on the main thread. |
| 245 | base::RepeatingClosure GpuChildThread::MakeQuitSafelyClosure() { |
| 246 | return base::BindRepeating(&GpuChildThread::QuitSafelyHelper, |
| 247 | base::ThreadTaskRunnerHandle::Get()); |
| 248 | } |
| 249 | |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 250 | #if defined(OS_ANDROID) |
| 251 | // static |
| 252 | std::unique_ptr<media::AndroidOverlay> GpuChildThread::CreateAndroidOverlay( |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 253 | scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 254 | const base::UnguessableToken& routing_token, |
| 255 | media::AndroidOverlayConfig config) { |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 256 | mojo::PendingRemote<media::mojom::AndroidOverlayProvider> overlay_provider; |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 257 | if (main_task_runner->RunsTasksInCurrentSequence()) { |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 258 | ChildThread::Get()->BindHostReceiver( |
| 259 | overlay_provider.InitWithNewPipeAndPassReceiver()); |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 260 | } else { |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 261 | main_task_runner->PostTask( |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 262 | FROM_HERE, |
| 263 | base::BindOnce( |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 264 | [](mojo::PendingReceiver<media::mojom::AndroidOverlayProvider> |
| 265 | receiver) { |
| 266 | ChildThread::Get()->BindHostReceiver(std::move(receiver)); |
Ken Rockot | 47c47d86 | 2019-09-26 17:38:07 | [diff] [blame] | 267 | }, |
Miyoung Shin | 18de6bf | 2019-10-17 07:06:24 | [diff] [blame] | 268 | overlay_provider.InitWithNewPipeAndPassReceiver())); |
Chris Watkins | 88a4000 | 2017-09-28 01:16:42 | [diff] [blame] | 269 | } |
| 270 | |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 271 | return std::make_unique<media::MojoAndroidOverlay>( |
[email protected] | 9a635ee | 2017-12-01 21:38:50 | [diff] [blame] | 272 | std::move(overlay_provider), std::move(config), routing_token); |
liberato | 441ca70 | 2017-05-13 16:50:38 | [diff] [blame] | 273 | } |
| 274 | #endif |
| 275 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 276 | } // namespace content |