sadrul | 6ffb1ab | 2016-09-13 04:03:25 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 5 | #include "components/viz/service/main/viz_main_impl.h" |
sadrul | 6ffb1ab | 2016-09-13 04:03:25 | [diff] [blame] | 6 | |
Jinho Bang | 24ca9cd | 2018-01-02 22:01:00 | [diff] [blame] | 7 | #include <memory> |
Claudio DeSouza | 591a997 | 2018-02-21 17:27:16 | [diff] [blame] | 8 | #include <utility> |
Jinho Bang | 24ca9cd | 2018-01-02 22:01:00 | [diff] [blame] | 9 | |
sadrul | 6ffb1ab | 2016-09-13 04:03:25 | [diff] [blame] | 10 | #include "base/command_line.h" |
sadrul | 5b860bd | 2016-09-26 20:15:34 | [diff] [blame] | 11 | #include "base/message_loop/message_loop.h" |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 12 | #include "base/power_monitor/power_monitor_device_source.h" |
Gabriel Charette | 5ff87ce | 2017-05-16 18:03:45 | [diff] [blame] | 13 | #include "base/single_thread_task_runner.h" |
kylechar | ee7cefd | 2017-07-13 16:05:03 | [diff] [blame] | 14 | #include "base/threading/sequenced_task_runner_handle.h" |
danakj | 7167a9ea | 2018-05-31 15:25:10 | [diff] [blame] | 15 | #include "base/trace_event/memory_dump_manager.h" |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 16 | #include "build/build_config.h" |
Eric Seckler | ad1de10 | 2018-03-15 14:51:56 | [diff] [blame] | 17 | #include "components/viz/common/switches.h" |
danakj | f595b91 | 2017-06-30 22:37:25 | [diff] [blame] | 18 | #include "components/viz/service/display_embedder/gpu_display_provider.h" |
danakj | 7167a9ea | 2018-05-31 15:25:10 | [diff] [blame] | 19 | #include "components/viz/service/display_embedder/server_shared_bitmap_manager.h" |
danakj | 4def4a24 | 2017-06-24 01:18:37 | [diff] [blame] | 20 | #include "components/viz/service/frame_sinks/frame_sink_manager_impl.h" |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 21 | #include "components/viz/service/gl/gpu_service_impl.h" |
ericrk | 8c0b7bf6 | 2017-03-17 20:07:23 | [diff] [blame] | 22 | #include "gpu/command_buffer/common/activity_flags.h" |
Jonathan Backer | 16cc8fd | 2018-05-31 19:59:22 | [diff] [blame] | 23 | #include "gpu/config/gpu_preferences.h" |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 24 | #include "gpu/config/gpu_switches.h" |
sadrul | 6ffb1ab | 2016-09-13 04:03:25 | [diff] [blame] | 25 | #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
fsamuel | 2a2351a9 | 2016-12-01 01:08:04 | [diff] [blame] | 26 | #include "gpu/ipc/gpu_in_process_thread_service.h" |
sadrul | 6ffb1ab | 2016-09-13 04:03:25 | [diff] [blame] | 27 | #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
| 28 | #include "gpu/ipc/service/gpu_watchdog_thread.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 29 | #include "media/gpu/buildflags.h" |
Mikhail Fomitchev | 742e391 | 2017-11-13 19:55:00 | [diff] [blame] | 30 | #include "services/metrics/public/cpp/delegating_ukm_recorder.h" |
| 31 | #include "services/metrics/public/cpp/mojo_ukm_recorder.h" |
Ken Rockot | 2d00d82 | 2018-02-10 17:54:42 | [diff] [blame] | 32 | #include "services/metrics/public/mojom/constants.mojom.h" |
Mikhail Fomitchev | 742e391 | 2017-11-13 19:55:00 | [diff] [blame] | 33 | #include "services/service_manager/public/cpp/connector.h" |
Khushal | 08d7c3d | 2018-05-29 03:23:56 | [diff] [blame] | 34 | #include "third_party/skia/include/core/SkFontLCDConfig.h" |
Eric Seckler | ad1de10 | 2018-03-15 14:51:56 | [diff] [blame] | 35 | #include "ui/gfx/switches.h" |
sadrul | 6ffb1ab | 2016-09-13 04:03:25 | [diff] [blame] | 36 | |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 37 | #if defined(OS_CHROMEOS) && BUILDFLAG(USE_VAAPI) |
Miguel Casas | 42e955c | 2017-12-04 14:18:12 | [diff] [blame] | 38 | #include "media/gpu/vaapi/vaapi_wrapper.h" |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 39 | #endif |
| 40 | |
Robert Kroeger | 2460e71 | 2018-01-26 23:33:07 | [diff] [blame] | 41 | #if defined(USE_OZONE) |
| 42 | #include "ui/ozone/public/ozone_platform.h" |
| 43 | #include "ui/ozone/public/ozone_switches.h" |
| 44 | #endif |
| 45 | |
sadrul | 5b860bd | 2016-09-26 20:15:34 | [diff] [blame] | 46 | namespace { |
| 47 | |
Eric Karl | b2ce020 | 2018-06-21 18:36:29 | [diff] [blame] | 48 | std::unique_ptr<viz::CompositorThreadType> CreateAndStartCompositorThread() { |
| 49 | const char* thread_name = "VizCompositorThread"; |
| 50 | |
| 51 | #if defined(OS_ANDROID) |
| 52 | auto thread = std::make_unique<base::android::JavaHandlerThread>( |
| 53 | thread_name, base::ThreadPriority::DISPLAY); |
| 54 | thread->Start(); |
| 55 | return thread; |
| 56 | #else |
| 57 | auto thread = std::make_unique<base::Thread>(thread_name); |
sadrul | 5b860bd | 2016-09-26 20:15:34 | [diff] [blame] | 58 | base::Thread::Options thread_options; |
kylechar | cd157cc | 2018-05-30 17:30:02 | [diff] [blame] | 59 | #if defined(OS_WIN) |
| 60 | // Windows needs a UI message loop for child HWND. Other platforms can use the |
| 61 | // default message loop type. |
| 62 | thread_options.message_loop_type = base::MessageLoop::TYPE_UI; |
| 63 | #endif |
| 64 | |
Eric Karl | b2ce020 | 2018-06-21 18:36:29 | [diff] [blame] | 65 | #if defined(OS_CHROMEOS) |
sadrul | 5b860bd | 2016-09-26 20:15:34 | [diff] [blame] | 66 | thread_options.priority = base::ThreadPriority::DISPLAY; |
| 67 | #endif |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 68 | CHECK(thread->StartWithOptions(thread_options)); |
| 69 | return thread; |
Eric Karl | b2ce020 | 2018-06-21 18:36:29 | [diff] [blame] | 70 | #endif |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 71 | } |
| 72 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 73 | std::unique_ptr<base::Thread> CreateAndStartIOThread() { |
| 74 | // TODO(sad): We do not need the IO thread once gpu has a separate process. |
| 75 | // It should be possible to use |main_task_runner_| for doing IO tasks. |
| 76 | base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 77 | thread_options.priority = base::ThreadPriority::NORMAL; |
| 78 | #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 79 | // TODO(reveman): Remove this in favor of setting it explicitly for each |
| 80 | // type of process. |
| 81 | thread_options.priority = base::ThreadPriority::DISPLAY; |
| 82 | #endif |
| 83 | auto io_thread = std::make_unique<base::Thread>("GpuIOThread"); |
| 84 | CHECK(io_thread->StartWithOptions(thread_options)); |
| 85 | return io_thread; |
| 86 | } |
| 87 | |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 88 | } // namespace |
| 89 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 90 | namespace viz { |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 91 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 92 | VizMainImpl::ExternalDependencies::ExternalDependencies() = default; |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 93 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 94 | VizMainImpl::ExternalDependencies::~ExternalDependencies() = default; |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 95 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 96 | VizMainImpl::ExternalDependencies::ExternalDependencies( |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 97 | ExternalDependencies&& other) = default; |
| 98 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 99 | VizMainImpl::ExternalDependencies& VizMainImpl::ExternalDependencies::operator=( |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 100 | ExternalDependencies&& other) = default; |
| 101 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 102 | VizMainImpl::VizMainImpl(Delegate* delegate, |
| 103 | ExternalDependencies dependencies, |
| 104 | std::unique_ptr<gpu::GpuInit> gpu_init) |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 105 | : delegate_(delegate), |
| 106 | dependencies_(std::move(dependencies)), |
| 107 | gpu_init_(std::move(gpu_init)), |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 108 | gpu_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 109 | binding_(this), |
| 110 | associated_binding_(this) { |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 111 | // TODO(crbug.com/609317): Remove this when Mus Window Server and GPU are |
| 112 | // split into separate processes. Until then this is necessary to be able to |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 113 | // run Mushrome (chrome with mus) with Mus running in the browser process. |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 114 | if (!base::PowerMonitor::Get()) { |
Jinho Bang | 24ca9cd | 2018-01-02 22:01:00 | [diff] [blame] | 115 | power_monitor_ = std::make_unique<base::PowerMonitor>( |
| 116 | std::make_unique<base::PowerMonitorDeviceSource>()); |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 117 | } |
sadrul | 5b860bd | 2016-09-26 20:15:34 | [diff] [blame] | 118 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 119 | if (!gpu_init_) { |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 120 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 121 | gpu::GpuPreferences gpu_preferences; |
| 122 | if (command_line->HasSwitch(switches::kGpuPreferences)) { |
| 123 | std::string value = |
| 124 | command_line->GetSwitchValueASCII(switches::kGpuPreferences); |
Jonathan Backer | 16cc8fd | 2018-05-31 19:59:22 | [diff] [blame] | 125 | bool success = gpu_preferences.FromSwitchValue(value); |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 126 | CHECK(success); |
| 127 | } |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 128 | #if defined(OS_CHROMEOS) && BUILDFLAG(USE_VAAPI) |
| 129 | // Initialize media codec. The UI service is running in a priviliged |
| 130 | // process. We don't need care when to initialize media codec. When we have |
| 131 | // a separate GPU (or VIZ) service process, we should initialize them |
| 132 | // before sandboxing |
| 133 | media::VaapiWrapper::PreSandboxInitialization(); |
| 134 | #endif |
| 135 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 136 | // Initialize GpuInit before starting the IO or compositor threads. |
| 137 | gpu_init_ = std::make_unique<gpu::GpuInit>(); |
| 138 | gpu_init_->set_sandbox_helper(this); |
Robert Kroeger | 2460e71 | 2018-01-26 23:33:07 | [diff] [blame] | 139 | |
| 140 | #if defined(USE_OZONE) |
| 141 | command_line->AppendSwitch(switches::kEnableDrmMojo); |
| 142 | #endif |
| 143 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 144 | // TODO(crbug.com/609317): Use InitializeAndStartSandbox() when gpu-mus is |
| 145 | // split into a separate process. |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 146 | gpu_init_->InitializeInProcess(command_line, gpu_preferences); |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 147 | } |
fsamuel | 5059e49 | 2016-11-24 10:28:09 | [diff] [blame] | 148 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 149 | if (!dependencies_.io_thread_task_runner) |
| 150 | io_thread_ = CreateAndStartIOThread(); |
| 151 | if (dependencies_.create_display_compositor) { |
| 152 | compositor_thread_ = CreateAndStartCompositorThread(); |
| 153 | compositor_thread_task_runner_ = compositor_thread_->task_runner(); |
Sadrul Habib Chowdhury | 97c6f1f | 2018-03-02 01:21:16 | [diff] [blame] | 154 | if (delegate_) |
| 155 | delegate_->PostCompositorThreadCreated( |
| 156 | compositor_thread_task_runner_.get()); |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 157 | } |
| 158 | |
Mikhail Fomitchev | 742e391 | 2017-11-13 19:55:00 | [diff] [blame] | 159 | CreateUkmRecorderIfNeeded(dependencies.connector); |
| 160 | |
kylechar | 56ddcdc2 | 2018-05-28 16:45:38 | [diff] [blame] | 161 | // We need to provide GpuServiceImpl a callback to exit the GPU process. With |
| 162 | // OOP-D this requires destroying RootCompositorFrameSinkImpls on the |
| 163 | // compositor thread while the GPU thread is still running to avoid deadlock. |
| 164 | // For non OOP-D we can simply quit the GPU thread RunLoop. |
| 165 | base::OnceClosure exit_callback = |
| 166 | compositor_thread_ |
| 167 | ? base::BindOnce(&VizMainImpl::ExitProcess, base::Unretained(this)) |
| 168 | : base::BindOnce(&base::RunLoop::QuitCurrentDeprecated); |
Jinho Bang | 24ca9cd | 2018-01-02 22:01:00 | [diff] [blame] | 169 | gpu_service_ = std::make_unique<GpuServiceImpl>( |
Khushal | 538adf1 | 2018-02-25 04:08:08 | [diff] [blame] | 170 | gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), io_task_runner(), |
Zhenyao Mo | 68ef56d | 2018-04-21 01:05:10 | [diff] [blame] | 171 | gpu_init_->gpu_feature_info(), gpu_init_->gpu_preferences(), |
| 172 | gpu_init_->gpu_info_for_hardware_gpu(), |
kylechar | 56ddcdc2 | 2018-05-28 16:45:38 | [diff] [blame] | 173 | gpu_init_->gpu_feature_info_for_hardware_gpu(), std::move(exit_callback)); |
Sadrul Habib Chowdhury | 7102df0b | 2018-05-30 03:04:17 | [diff] [blame] | 174 | if (dependencies_.create_display_compositor) |
| 175 | gpu_service_->set_oopd_enabled(); |
sadrul | 5b860bd | 2016-09-26 20:15:34 | [diff] [blame] | 176 | } |
| 177 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 178 | VizMainImpl::~VizMainImpl() { |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 179 | DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread()); |
kylechar | e0046373 | 2018-02-01 01:19:10 | [diff] [blame] | 180 | |
| 181 | // The compositor holds on to some resources from gpu service. So destroy the |
| 182 | // compositor first, before destroying the gpu service. However, before the |
| 183 | // compositor is destroyed, close the binding, so that the gpu service doesn't |
| 184 | // need to process commands from the host as it is shutting down. |
| 185 | binding_.Close(); |
| 186 | associated_binding_.Close(); |
| 187 | |
| 188 | if (compositor_thread_) { |
| 189 | // Destroy all objects owned on the compositor thread before shutting down |
| 190 | // the thread. All RootCompositorFrameSinks must be destroyed before now, |
| 191 | // otherwise the compositor thread will deadlock waiting for a response from |
| 192 | // the blocked GPU thread. |
| 193 | compositor_thread_task_runner_->PostTask( |
| 194 | FROM_HERE, base::BindOnce(&VizMainImpl::TearDownOnCompositorThread, |
| 195 | base::Unretained(this))); |
Eric Karl | b139512 | 2018-06-26 20:15:41 | [diff] [blame] | 196 | compositor_thread_->Stop(); |
kylechar | e0046373 | 2018-02-01 01:19:10 | [diff] [blame] | 197 | compositor_thread_.reset(); |
| 198 | compositor_thread_task_runner_ = nullptr; |
| 199 | } |
| 200 | |
Mikhail Fomitchev | 742e391 | 2017-11-13 19:55:00 | [diff] [blame] | 201 | if (ukm_recorder_) |
| 202 | ukm::DelegatingUkmRecorder::Get()->RemoveDelegate(ukm_recorder_.get()); |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 203 | } |
| 204 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 205 | void VizMainImpl::SetLogMessagesForHost(LogMessages log_messages) { |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 206 | log_messages_ = std::move(log_messages); |
| 207 | } |
| 208 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 209 | void VizMainImpl::Bind(mojom::VizMainRequest request) { |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 210 | binding_.Bind(std::move(request)); |
| 211 | } |
| 212 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 213 | void VizMainImpl::BindAssociated(mojom::VizMainAssociatedRequest request) { |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 214 | associated_binding_.Bind(std::move(request)); |
Sadrul Habib Chowdhury | 6869b788 | 2017-10-04 18:24:10 | [diff] [blame] | 215 | } |
| 216 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 217 | void VizMainImpl::CreateGpuService( |
| 218 | mojom::GpuServiceRequest request, |
| 219 | mojom::GpuHostPtr gpu_host, |
Khushal | 538adf1 | 2018-02-25 04:08:08 | [diff] [blame] | 220 | discardable_memory::mojom::DiscardableSharedMemoryManagerPtr |
| 221 | discardable_memory_manager, |
Khushal | 08d7c3d | 2018-05-29 03:23:56 | [diff] [blame] | 222 | mojo::ScopedSharedBufferHandle activity_flags, |
| 223 | gfx::FontRenderParams::SubpixelRendering subpixel_rendering) { |
sadrul | 4d29154 | 2017-05-09 05:15:43 | [diff] [blame] | 224 | DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread()); |
kylechar | b12bef3 | 2018-06-25 12:42:41 | [diff] [blame] | 225 | |
| 226 | // If GL is disabled then don't try to collect GPUInfo, we're not using GPU. |
| 227 | if (gl::GetGLImplementation() != gl::kGLImplementationDisabled) |
| 228 | gpu_service_->UpdateGPUInfo(); |
| 229 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 230 | for (const LogMessage& log : log_messages_) |
| 231 | gpu_host->RecordLogMessage(log.severity, log.header, log.message); |
| 232 | log_messages_.clear(); |
| 233 | if (!gpu_init_->init_successful()) { |
| 234 | LOG(ERROR) << "Exiting GPU process due to errors during initialization"; |
| 235 | gpu_service_.reset(); |
| 236 | gpu_host->DidFailInitialize(); |
| 237 | if (delegate_) |
| 238 | delegate_->OnInitializationFailed(); |
| 239 | return; |
| 240 | } |
| 241 | |
Khushal | 538adf1 | 2018-02-25 04:08:08 | [diff] [blame] | 242 | if (!gpu_init_->gpu_info().in_process_gpu) { |
| 243 | // If the GPU is running in the browser process, discardable memory manager |
| 244 | // has already been initialized. |
| 245 | discardable_shared_memory_manager_ = std::make_unique< |
| 246 | discardable_memory::ClientDiscardableSharedMemoryManager>( |
| 247 | std::move(discardable_memory_manager), io_task_runner()); |
| 248 | base::DiscardableMemoryAllocator::SetInstance( |
| 249 | discardable_shared_memory_manager_.get()); |
| 250 | } |
| 251 | |
Khushal | 08d7c3d | 2018-05-29 03:23:56 | [diff] [blame] | 252 | SkFontLCDConfig::SetSubpixelOrder( |
| 253 | gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrder( |
| 254 | subpixel_rendering)); |
| 255 | SkFontLCDConfig::SetSubpixelOrientation( |
| 256 | gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrientation( |
| 257 | subpixel_rendering)); |
| 258 | |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 259 | gpu_service_->Bind(std::move(request)); |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 260 | gpu_service_->InitializeWithHost( |
| 261 | std::move(gpu_host), |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 262 | gpu::GpuProcessActivityFlags(std::move(activity_flags)), |
| 263 | dependencies_.sync_point_manager, dependencies_.shutdown_event); |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 264 | |
kylechar | 9aa229ee | 2017-11-17 18:06:13 | [diff] [blame] | 265 | if (!pending_frame_sink_manager_params_.is_null()) { |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 266 | CreateFrameSinkManagerInternal( |
kylechar | 9aa229ee | 2017-11-17 18:06:13 | [diff] [blame] | 267 | std::move(pending_frame_sink_manager_params_)); |
| 268 | pending_frame_sink_manager_params_.reset(); |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 269 | } |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 270 | if (delegate_) |
| 271 | delegate_->OnGpuServiceConnection(gpu_service_.get()); |
fsamuel | 2a2351a9 | 2016-12-01 01:08:04 | [diff] [blame] | 272 | } |
| 273 | |
Mikhail Fomitchev | 742e391 | 2017-11-13 19:55:00 | [diff] [blame] | 274 | void VizMainImpl::CreateUkmRecorderIfNeeded( |
| 275 | service_manager::Connector* connector) { |
| 276 | // If GPU is running in the browser process, we can use browser's UKMRecorder. |
| 277 | if (gpu_init_->gpu_info().in_process_gpu) |
| 278 | return; |
| 279 | |
| 280 | DCHECK(connector) << "Unable to initialize UKMRecorder in the GPU process - " |
| 281 | << "no valid connector."; |
| 282 | ukm_recorder_ = ukm::MojoUkmRecorder::Create(connector); |
| 283 | ukm::DelegatingUkmRecorder::Get()->AddDelegate(ukm_recorder_->GetWeakPtr()); |
| 284 | } |
| 285 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 286 | void VizMainImpl::CreateFrameSinkManager( |
kylechar | 9aa229ee | 2017-11-17 18:06:13 | [diff] [blame] | 287 | mojom::FrameSinkManagerParamsPtr params) { |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 288 | DCHECK(compositor_thread_task_runner_); |
sadrul | 4d29154 | 2017-05-09 05:15:43 | [diff] [blame] | 289 | DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread()); |
| 290 | if (!gpu_service_ || !gpu_service_->is_initialized()) { |
kylechar | 9aa229ee | 2017-11-17 18:06:13 | [diff] [blame] | 291 | DCHECK(pending_frame_sink_manager_params_.is_null()); |
| 292 | pending_frame_sink_manager_params_ = std::move(params); |
fsamuel | 2a2351a9 | 2016-12-01 01:08:04 | [diff] [blame] | 293 | return; |
| 294 | } |
kylechar | 9aa229ee | 2017-11-17 18:06:13 | [diff] [blame] | 295 | CreateFrameSinkManagerInternal(std::move(params)); |
sadrul | 5b860bd | 2016-09-26 20:15:34 | [diff] [blame] | 296 | } |
| 297 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 298 | void VizMainImpl::CreateFrameSinkManagerInternal( |
kylechar | 9aa229ee | 2017-11-17 18:06:13 | [diff] [blame] | 299 | mojom::FrameSinkManagerParamsPtr params) { |
kylechar | 2fdaa04 | 2018-07-03 17:36:23 | [diff] [blame^] | 300 | DCHECK(!task_executor_); |
jonross | 1973201a | 2017-04-20 22:22:14 | [diff] [blame] | 301 | DCHECK(gpu_service_); |
sadrul | 4d29154 | 2017-05-09 05:15:43 | [diff] [blame] | 302 | DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread()); |
kylechar | 47df630 | 2018-02-14 01:45:48 | [diff] [blame] | 303 | |
kylechar | 2fdaa04 | 2018-07-03 17:36:23 | [diff] [blame^] | 304 | task_executor_ = base::MakeRefCounted<gpu::GpuInProcessThreadService>( |
Jonathan Backer | f277692 | 2018-04-25 18:31:26 | [diff] [blame] | 305 | gpu_thread_task_runner_, gpu_service_->sync_point_manager(), |
| 306 | gpu_service_->mailbox_manager(), gpu_service_->share_group(), |
| 307 | gpu_service_->gpu_feature_info(), |
kylechar | 47df630 | 2018-02-14 01:45:48 | [diff] [blame] | 308 | gpu_service_->gpu_channel_manager()->gpu_preferences()); |
fsamuel | 2a2351a9 | 2016-12-01 01:08:04 | [diff] [blame] | 309 | |
fsamuel | cd2a7b5c | 2017-03-06 18:24:14 | [diff] [blame] | 310 | compositor_thread_task_runner_->PostTask( |
sadrul | 1f51373d | 2017-06-21 17:24:53 | [diff] [blame] | 311 | FROM_HERE, |
Claudio DeSouza | 591a997 | 2018-02-21 17:27:16 | [diff] [blame] | 312 | base::BindOnce(&VizMainImpl::CreateFrameSinkManagerOnCompositorThread, |
| 313 | base::Unretained(this), std::move(params))); |
fsamuel | 2a2351a9 | 2016-12-01 01:08:04 | [diff] [blame] | 314 | } |
| 315 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 316 | void VizMainImpl::CreateFrameSinkManagerOnCompositorThread( |
kylechar | 9aa229ee | 2017-11-17 18:06:13 | [diff] [blame] | 317 | mojom::FrameSinkManagerParamsPtr params) { |
kylechar | 56ddcdc2 | 2018-05-28 16:45:38 | [diff] [blame] | 318 | DCHECK(compositor_thread_task_runner_->BelongsToCurrentThread()); |
kylechar | 486c455 | 2017-04-04 15:31:44 | [diff] [blame] | 319 | DCHECK(!frame_sink_manager_); |
fsamuel | 2a2351a9 | 2016-12-01 01:08:04 | [diff] [blame] | 320 | |
Eric Seckler | ad1de10 | 2018-03-15 14:51:56 | [diff] [blame] | 321 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 322 | |
danakj | 7167a9ea | 2018-05-31 15:25:10 | [diff] [blame] | 323 | server_shared_bitmap_manager_ = std::make_unique<ServerSharedBitmapManager>(); |
| 324 | base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 325 | server_shared_bitmap_manager_.get(), "viz::ServerSharedBitmapManager", |
| 326 | base::ThreadTaskRunnerHandle::Get()); |
| 327 | |
danakj | 4ee301c | 2017-11-29 16:19:43 | [diff] [blame] | 328 | display_provider_ = std::make_unique<GpuDisplayProvider>( |
kylechar | 2fdaa04 | 2018-07-03 17:36:23 | [diff] [blame^] | 329 | params->restart_id, gpu_service_.get(), task_executor_, |
danakj | 7167a9ea | 2018-05-31 15:25:10 | [diff] [blame] | 330 | gpu_service_->gpu_channel_manager(), server_shared_bitmap_manager_.get(), |
Eric Seckler | ad1de10 | 2018-03-15 14:51:56 | [diff] [blame] | 331 | command_line->HasSwitch(switches::kHeadless), |
| 332 | command_line->HasSwitch(switches::kRunAllCompositorStagesBeforeDraw)); |
kylechar | 9c1b2cf6 | 2017-03-28 17:21:15 | [diff] [blame] | 333 | |
danakj | 4ee301c | 2017-11-29 16:19:43 | [diff] [blame] | 334 | mojom::FrameSinkManagerClientPtr client( |
| 335 | std::move(params->frame_sink_manager_client)); |
Fady Samuel | 6e8310d | 2018-02-14 21:25:54 | [diff] [blame] | 336 | base::Optional<uint32_t> activation_deadline_in_frames; |
| 337 | if (params->use_activation_deadline) |
| 338 | activation_deadline_in_frames = params->activation_deadline_in_frames; |
danakj | 4ee301c | 2017-11-29 16:19:43 | [diff] [blame] | 339 | frame_sink_manager_ = std::make_unique<FrameSinkManagerImpl>( |
danakj | 7167a9ea | 2018-05-31 15:25:10 | [diff] [blame] | 340 | server_shared_bitmap_manager_.get(), activation_deadline_in_frames, |
| 341 | display_provider_.get()); |
kylechar | 9aa229ee | 2017-11-17 18:06:13 | [diff] [blame] | 342 | frame_sink_manager_->BindAndSetClient(std::move(params->frame_sink_manager), |
| 343 | nullptr, std::move(client)); |
sadrul | 6ffb1ab | 2016-09-13 04:03:25 | [diff] [blame] | 344 | } |
| 345 | |
kylechar | e0046373 | 2018-02-01 01:19:10 | [diff] [blame] | 346 | void VizMainImpl::TearDownOnCompositorThread() { |
kylechar | 56ddcdc2 | 2018-05-28 16:45:38 | [diff] [blame] | 347 | DCHECK(compositor_thread_task_runner_->BelongsToCurrentThread()); |
| 348 | |
danakj | 7167a9ea | 2018-05-31 15:25:10 | [diff] [blame] | 349 | base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 350 | server_shared_bitmap_manager_.get()); |
| 351 | |
Sadrul Habib Chowdhury | baaed53a | 2017-10-06 05:14:39 | [diff] [blame] | 352 | frame_sink_manager_.reset(); |
| 353 | display_provider_.reset(); |
danakj | 7167a9ea | 2018-05-31 15:25:10 | [diff] [blame] | 354 | server_shared_bitmap_manager_.reset(); |
sadrul | b92e8e93 | 2016-12-08 20:59:24 | [diff] [blame] | 355 | } |
fsamuel | 2a2351a9 | 2016-12-01 01:08:04 | [diff] [blame] | 356 | |
kylechar | 56ddcdc2 | 2018-05-28 16:45:38 | [diff] [blame] | 357 | void VizMainImpl::CleanupForShutdownOnCompositorThread() { |
| 358 | DCHECK(compositor_thread_task_runner_->BelongsToCurrentThread()); |
| 359 | |
| 360 | if (frame_sink_manager_) |
| 361 | frame_sink_manager_->ForceShutdown(); |
| 362 | } |
| 363 | |
| 364 | void VizMainImpl::ExitProcess() { |
| 365 | DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread()); |
| 366 | DCHECK(compositor_thread_task_runner_); |
| 367 | |
| 368 | // Close mojom::VizMain bindings first so the browser can't try to reconnect. |
| 369 | binding_.Close(); |
| 370 | associated_binding_.Close(); |
| 371 | |
| 372 | // PostTask to the compositor thread to cleanup and then exit the GPU thread |
| 373 | // RunLoop once that is finished. Unretained is safe here because |this| owns |
| 374 | // |compositor_thread_|. |
| 375 | compositor_thread_task_runner_->PostTaskAndReply( |
| 376 | FROM_HERE, |
| 377 | base::BindOnce(&VizMainImpl::CleanupForShutdownOnCompositorThread, |
| 378 | base::Unretained(this)), |
| 379 | base::BindOnce([]() { base::RunLoop::QuitCurrentDeprecated(); })); |
| 380 | } |
| 381 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 382 | void VizMainImpl::PreSandboxStartup() { |
sadrul | 6ffb1ab | 2016-09-13 04:03:25 | [diff] [blame] | 383 | // TODO(sad): https://crbug.com/645602 |
| 384 | } |
| 385 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 386 | bool VizMainImpl::EnsureSandboxInitialized( |
| 387 | gpu::GpuWatchdogThread* watchdog_thread, |
| 388 | const gpu::GPUInfo* gpu_info, |
| 389 | const gpu::GpuPreferences& gpu_prefs) { |
sadrul | 6ffb1ab | 2016-09-13 04:03:25 | [diff] [blame] | 390 | // TODO(sad): https://crbug.com/645602 |
| 391 | return true; |
| 392 | } |
| 393 | |
Sadrul Habib Chowdhury | 55fc2f0 | 2017-10-27 02:40:06 | [diff] [blame] | 394 | } // namespace viz |