blob: c0dd5619babcc3dde24fa07c20cd42f33603ea09 [file] [log] [blame]
sadrul6ffb1ab2016-09-13 04:03:251// 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 Chowdhury55fc2f02017-10-27 02:40:065#include "components/viz/service/main/viz_main_impl.h"
sadrul6ffb1ab2016-09-13 04:03:256
Jinho Bang24ca9cd2018-01-02 22:01:007#include <memory>
Claudio DeSouza591a9972018-02-21 17:27:168#include <utility>
Jinho Bang24ca9cd2018-01-02 22:01:009
sadrul6ffb1ab2016-09-13 04:03:2510#include "base/command_line.h"
sadrul5b860bd2016-09-26 20:15:3411#include "base/message_loop/message_loop.h"
sadrul041ca722017-03-24 22:35:3512#include "base/power_monitor/power_monitor_device_source.h"
Gabriel Charette5ff87ce2017-05-16 18:03:4513#include "base/single_thread_task_runner.h"
kylecharee7cefd2017-07-13 16:05:0314#include "base/threading/sequenced_task_runner_handle.h"
danakj7167a9ea2018-05-31 15:25:1015#include "base/trace_event/memory_dump_manager.h"
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1516#include "build/build_config.h"
Eric Secklerad1de102018-03-15 14:51:5617#include "components/viz/common/switches.h"
danakjf595b912017-06-30 22:37:2518#include "components/viz/service/display_embedder/gpu_display_provider.h"
danakj7167a9ea2018-05-31 15:25:1019#include "components/viz/service/display_embedder/server_shared_bitmap_manager.h"
danakj4def4a242017-06-24 01:18:3720#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
Sadrul Habib Chowdhuryef1abe782017-08-01 17:20:3821#include "components/viz/service/gl/gpu_service_impl.h"
ericrk8c0b7bf62017-03-17 20:07:2322#include "gpu/command_buffer/common/activity_flags.h"
Jonathan Backer16cc8fd2018-05-31 19:59:2223#include "gpu/config/gpu_preferences.h"
Zhenyao Mo83b895e2017-10-18 18:50:5424#include "gpu/config/gpu_switches.h"
sadrul6ffb1ab2016-09-13 04:03:2525#include "gpu/ipc/common/gpu_memory_buffer_support.h"
fsamuel2a2351a92016-12-01 01:08:0426#include "gpu/ipc/gpu_in_process_thread_service.h"
sadrul6ffb1ab2016-09-13 04:03:2527#include "gpu/ipc/service/gpu_memory_buffer_factory.h"
28#include "gpu/ipc/service/gpu_watchdog_thread.h"
Scott Violeta35f9a42018-03-22 22:00:4429#include "media/gpu/buildflags.h"
Mikhail Fomitchev742e3912017-11-13 19:55:0030#include "services/metrics/public/cpp/delegating_ukm_recorder.h"
31#include "services/metrics/public/cpp/mojo_ukm_recorder.h"
Ken Rockot2d00d822018-02-10 17:54:4232#include "services/metrics/public/mojom/constants.mojom.h"
Mikhail Fomitchev742e3912017-11-13 19:55:0033#include "services/service_manager/public/cpp/connector.h"
Khushal08d7c3d2018-05-29 03:23:5634#include "third_party/skia/include/core/SkFontLCDConfig.h"
Eric Secklerad1de102018-03-15 14:51:5635#include "ui/gfx/switches.h"
sadrul6ffb1ab2016-09-13 04:03:2536
Peng Huang417f0cf72017-11-20 20:06:1637#if defined(OS_CHROMEOS) && BUILDFLAG(USE_VAAPI)
Miguel Casas42e955c2017-12-04 14:18:1238#include "media/gpu/vaapi/vaapi_wrapper.h"
Peng Huang417f0cf72017-11-20 20:06:1639#endif
40
Robert Kroeger2460e712018-01-26 23:33:0741#if defined(USE_OZONE)
42#include "ui/ozone/public/ozone_platform.h"
43#include "ui/ozone/public/ozone_switches.h"
44#endif
45
sadrul5b860bd2016-09-26 20:15:3446namespace {
47
Eric Karlb2ce0202018-06-21 18:36:2948std::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);
sadrul5b860bd2016-09-26 20:15:3458 base::Thread::Options thread_options;
kylecharcd157cc2018-05-30 17:30:0259#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 Karlb2ce0202018-06-21 18:36:2965#if defined(OS_CHROMEOS)
sadrul5b860bd2016-09-26 20:15:3466 thread_options.priority = base::ThreadPriority::DISPLAY;
67#endif
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:3968 CHECK(thread->StartWithOptions(thread_options));
69 return thread;
Eric Karlb2ce0202018-06-21 18:36:2970#endif
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:3971}
72
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1573std::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 Chowdhurybaaed53a2017-10-06 05:14:3988} // namespace
89
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0690namespace viz {
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:3991
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0692VizMainImpl::ExternalDependencies::ExternalDependencies() = default;
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1593
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0694VizMainImpl::ExternalDependencies::~ExternalDependencies() = default;
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1595
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0696VizMainImpl::ExternalDependencies::ExternalDependencies(
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:1597 ExternalDependencies&& other) = default;
98
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:0699VizMainImpl::ExternalDependencies& VizMainImpl::ExternalDependencies::operator=(
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15100 ExternalDependencies&& other) = default;
101
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06102VizMainImpl::VizMainImpl(Delegate* delegate,
103 ExternalDependencies dependencies,
104 std::unique_ptr<gpu::GpuInit> gpu_init)
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15105 : delegate_(delegate),
106 dependencies_(std::move(dependencies)),
107 gpu_init_(std::move(gpu_init)),
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39108 gpu_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15109 binding_(this),
110 associated_binding_(this) {
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39111 // 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 Violet8ff9c302018-02-22 22:28:35113 // run Mushrome (chrome with mus) with Mus running in the browser process.
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39114 if (!base::PowerMonitor::Get()) {
Jinho Bang24ca9cd2018-01-02 22:01:00115 power_monitor_ = std::make_unique<base::PowerMonitor>(
116 std::make_unique<base::PowerMonitorDeviceSource>());
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39117 }
sadrul5b860bd2016-09-26 20:15:34118
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15119 if (!gpu_init_) {
Zhenyao Mo83b895e2017-10-18 18:50:54120 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 Backer16cc8fd2018-05-31 19:59:22125 bool success = gpu_preferences.FromSwitchValue(value);
Zhenyao Mo83b895e2017-10-18 18:50:54126 CHECK(success);
127 }
Peng Huang417f0cf72017-11-20 20:06:16128#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 Chowdhurydbe4da92017-10-12 15:53:15136 // 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 Kroeger2460e712018-01-26 23:33:07139
140#if defined(USE_OZONE)
141 command_line->AppendSwitch(switches::kEnableDrmMojo);
142#endif
143
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15144 // TODO(crbug.com/609317): Use InitializeAndStartSandbox() when gpu-mus is
145 // split into a separate process.
Zhenyao Mo83b895e2017-10-18 18:50:54146 gpu_init_->InitializeInProcess(command_line, gpu_preferences);
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15147 }
fsamuel5059e492016-11-24 10:28:09148
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15149 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 Chowdhury97c6f1f2018-03-02 01:21:16154 if (delegate_)
155 delegate_->PostCompositorThreadCreated(
156 compositor_thread_task_runner_.get());
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15157 }
158
Mikhail Fomitchev742e3912017-11-13 19:55:00159 CreateUkmRecorderIfNeeded(dependencies.connector);
160
kylechar56ddcdc22018-05-28 16:45:38161 // 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 Bang24ca9cd2018-01-02 22:01:00169 gpu_service_ = std::make_unique<GpuServiceImpl>(
Khushal538adf12018-02-25 04:08:08170 gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), io_task_runner(),
Zhenyao Mo68ef56d2018-04-21 01:05:10171 gpu_init_->gpu_feature_info(), gpu_init_->gpu_preferences(),
172 gpu_init_->gpu_info_for_hardware_gpu(),
kylechar56ddcdc22018-05-28 16:45:38173 gpu_init_->gpu_feature_info_for_hardware_gpu(), std::move(exit_callback));
Sadrul Habib Chowdhury7102df0b2018-05-30 03:04:17174 if (dependencies_.create_display_compositor)
175 gpu_service_->set_oopd_enabled();
sadrul5b860bd2016-09-26 20:15:34176}
177
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06178VizMainImpl::~VizMainImpl() {
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39179 DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread());
kylechare00463732018-02-01 01:19:10180
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 Karlb1395122018-06-26 20:15:41196 compositor_thread_->Stop();
kylechare00463732018-02-01 01:19:10197 compositor_thread_.reset();
198 compositor_thread_task_runner_ = nullptr;
199 }
200
Mikhail Fomitchev742e3912017-11-13 19:55:00201 if (ukm_recorder_)
202 ukm::DelegatingUkmRecorder::Get()->RemoveDelegate(ukm_recorder_.get());
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15203}
204
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06205void VizMainImpl::SetLogMessagesForHost(LogMessages log_messages) {
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15206 log_messages_ = std::move(log_messages);
207}
208
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06209void VizMainImpl::Bind(mojom::VizMainRequest request) {
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15210 binding_.Bind(std::move(request));
211}
212
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06213void VizMainImpl::BindAssociated(mojom::VizMainAssociatedRequest request) {
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15214 associated_binding_.Bind(std::move(request));
Sadrul Habib Chowdhury6869b7882017-10-04 18:24:10215}
216
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06217void VizMainImpl::CreateGpuService(
218 mojom::GpuServiceRequest request,
219 mojom::GpuHostPtr gpu_host,
Khushal538adf12018-02-25 04:08:08220 discardable_memory::mojom::DiscardableSharedMemoryManagerPtr
221 discardable_memory_manager,
Khushal08d7c3d2018-05-29 03:23:56222 mojo::ScopedSharedBufferHandle activity_flags,
223 gfx::FontRenderParams::SubpixelRendering subpixel_rendering) {
sadrul4d291542017-05-09 05:15:43224 DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread());
kylecharb12bef32018-06-25 12:42:41225
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 Chowdhurydbe4da92017-10-12 15:53:15230 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
Khushal538adf12018-02-25 04:08:08242 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
Khushal08d7c3d2018-05-29 03:23:56252 SkFontLCDConfig::SetSubpixelOrder(
253 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrder(
254 subpixel_rendering));
255 SkFontLCDConfig::SetSubpixelOrientation(
256 gfx::FontRenderParams::SubpixelRenderingToSkiaLCDOrientation(
257 subpixel_rendering));
258
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15259 gpu_service_->Bind(std::move(request));
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39260 gpu_service_->InitializeWithHost(
261 std::move(gpu_host),
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15262 gpu::GpuProcessActivityFlags(std::move(activity_flags)),
263 dependencies_.sync_point_manager, dependencies_.shutdown_event);
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39264
kylechar9aa229ee2017-11-17 18:06:13265 if (!pending_frame_sink_manager_params_.is_null()) {
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39266 CreateFrameSinkManagerInternal(
kylechar9aa229ee2017-11-17 18:06:13267 std::move(pending_frame_sink_manager_params_));
268 pending_frame_sink_manager_params_.reset();
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39269 }
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15270 if (delegate_)
271 delegate_->OnGpuServiceConnection(gpu_service_.get());
fsamuel2a2351a92016-12-01 01:08:04272}
273
Mikhail Fomitchev742e3912017-11-13 19:55:00274void 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 Chowdhury55fc2f02017-10-27 02:40:06286void VizMainImpl::CreateFrameSinkManager(
kylechar9aa229ee2017-11-17 18:06:13287 mojom::FrameSinkManagerParamsPtr params) {
Sadrul Habib Chowdhurydbe4da92017-10-12 15:53:15288 DCHECK(compositor_thread_task_runner_);
sadrul4d291542017-05-09 05:15:43289 DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread());
290 if (!gpu_service_ || !gpu_service_->is_initialized()) {
kylechar9aa229ee2017-11-17 18:06:13291 DCHECK(pending_frame_sink_manager_params_.is_null());
292 pending_frame_sink_manager_params_ = std::move(params);
fsamuel2a2351a92016-12-01 01:08:04293 return;
294 }
kylechar9aa229ee2017-11-17 18:06:13295 CreateFrameSinkManagerInternal(std::move(params));
sadrul5b860bd2016-09-26 20:15:34296}
297
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06298void VizMainImpl::CreateFrameSinkManagerInternal(
kylechar9aa229ee2017-11-17 18:06:13299 mojom::FrameSinkManagerParamsPtr params) {
kylechar2fdaa042018-07-03 17:36:23300 DCHECK(!task_executor_);
jonross1973201a2017-04-20 22:22:14301 DCHECK(gpu_service_);
sadrul4d291542017-05-09 05:15:43302 DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread());
kylechar47df6302018-02-14 01:45:48303
kylechar2fdaa042018-07-03 17:36:23304 task_executor_ = base::MakeRefCounted<gpu::GpuInProcessThreadService>(
Jonathan Backerf2776922018-04-25 18:31:26305 gpu_thread_task_runner_, gpu_service_->sync_point_manager(),
306 gpu_service_->mailbox_manager(), gpu_service_->share_group(),
307 gpu_service_->gpu_feature_info(),
kylechar47df6302018-02-14 01:45:48308 gpu_service_->gpu_channel_manager()->gpu_preferences());
fsamuel2a2351a92016-12-01 01:08:04309
fsamuelcd2a7b5c2017-03-06 18:24:14310 compositor_thread_task_runner_->PostTask(
sadrul1f51373d2017-06-21 17:24:53311 FROM_HERE,
Claudio DeSouza591a9972018-02-21 17:27:16312 base::BindOnce(&VizMainImpl::CreateFrameSinkManagerOnCompositorThread,
313 base::Unretained(this), std::move(params)));
fsamuel2a2351a92016-12-01 01:08:04314}
315
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06316void VizMainImpl::CreateFrameSinkManagerOnCompositorThread(
kylechar9aa229ee2017-11-17 18:06:13317 mojom::FrameSinkManagerParamsPtr params) {
kylechar56ddcdc22018-05-28 16:45:38318 DCHECK(compositor_thread_task_runner_->BelongsToCurrentThread());
kylechar486c4552017-04-04 15:31:44319 DCHECK(!frame_sink_manager_);
fsamuel2a2351a92016-12-01 01:08:04320
Eric Secklerad1de102018-03-15 14:51:56321 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
322
danakj7167a9ea2018-05-31 15:25:10323 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
danakj4ee301c2017-11-29 16:19:43328 display_provider_ = std::make_unique<GpuDisplayProvider>(
kylechar2fdaa042018-07-03 17:36:23329 params->restart_id, gpu_service_.get(), task_executor_,
danakj7167a9ea2018-05-31 15:25:10330 gpu_service_->gpu_channel_manager(), server_shared_bitmap_manager_.get(),
Eric Secklerad1de102018-03-15 14:51:56331 command_line->HasSwitch(switches::kHeadless),
332 command_line->HasSwitch(switches::kRunAllCompositorStagesBeforeDraw));
kylechar9c1b2cf62017-03-28 17:21:15333
danakj4ee301c2017-11-29 16:19:43334 mojom::FrameSinkManagerClientPtr client(
335 std::move(params->frame_sink_manager_client));
Fady Samuel6e8310d2018-02-14 21:25:54336 base::Optional<uint32_t> activation_deadline_in_frames;
337 if (params->use_activation_deadline)
338 activation_deadline_in_frames = params->activation_deadline_in_frames;
danakj4ee301c2017-11-29 16:19:43339 frame_sink_manager_ = std::make_unique<FrameSinkManagerImpl>(
danakj7167a9ea2018-05-31 15:25:10340 server_shared_bitmap_manager_.get(), activation_deadline_in_frames,
341 display_provider_.get());
kylechar9aa229ee2017-11-17 18:06:13342 frame_sink_manager_->BindAndSetClient(std::move(params->frame_sink_manager),
343 nullptr, std::move(client));
sadrul6ffb1ab2016-09-13 04:03:25344}
345
kylechare00463732018-02-01 01:19:10346void VizMainImpl::TearDownOnCompositorThread() {
kylechar56ddcdc22018-05-28 16:45:38347 DCHECK(compositor_thread_task_runner_->BelongsToCurrentThread());
348
danakj7167a9ea2018-05-31 15:25:10349 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
350 server_shared_bitmap_manager_.get());
351
Sadrul Habib Chowdhurybaaed53a2017-10-06 05:14:39352 frame_sink_manager_.reset();
353 display_provider_.reset();
danakj7167a9ea2018-05-31 15:25:10354 server_shared_bitmap_manager_.reset();
sadrulb92e8e932016-12-08 20:59:24355}
fsamuel2a2351a92016-12-01 01:08:04356
kylechar56ddcdc22018-05-28 16:45:38357void VizMainImpl::CleanupForShutdownOnCompositorThread() {
358 DCHECK(compositor_thread_task_runner_->BelongsToCurrentThread());
359
360 if (frame_sink_manager_)
361 frame_sink_manager_->ForceShutdown();
362}
363
364void 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 Chowdhury55fc2f02017-10-27 02:40:06382void VizMainImpl::PreSandboxStartup() {
sadrul6ffb1ab2016-09-13 04:03:25383 // TODO(sad): https://crbug.com/645602
384}
385
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06386bool VizMainImpl::EnsureSandboxInitialized(
387 gpu::GpuWatchdogThread* watchdog_thread,
388 const gpu::GPUInfo* gpu_info,
389 const gpu::GpuPreferences& gpu_prefs) {
sadrul6ffb1ab2016-09-13 04:03:25390 // TODO(sad): https://crbug.com/645602
391 return true;
392}
393
Sadrul Habib Chowdhury55fc2f02017-10-27 02:40:06394} // namespace viz