blob: fb22228c62308f430765e8f069d39d94aa057b9d [file] [log] [blame]
[email protected]d7a2d892013-08-16 07:45:361// Copyright 2013 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
[email protected]8707caa2013-09-04 16:41:305#include "content/gpu/in_process_gpu_thread.h"
[email protected]d7a2d892013-08-16 07:45:366
Thoren Paulson6dcf39e2017-08-02 16:33:297#include "base/command_line.h"
xhwang9c8e1282015-10-10 01:54:078#include "base/time/time.h"
avi66a07722015-12-25 23:38:129#include "build/build_config.h"
Joe Mason94bebf12022-06-03 15:03:5310#include "content/child/child_process.h"
[email protected]d7a2d892013-08-16 07:45:3611#include "content/gpu/gpu_child_thread.h"
Zhenyao Modb2790b2017-08-30 00:10:1512#include "content/public/common/content_client.h"
Thoren Paulson6dcf39e2017-08-02 16:33:2913#include "content/public/common/content_switches.h"
Jonathan Backer0af509962018-05-30 16:05:0714#include "gpu/config/gpu_preferences.h"
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5715#include "gpu/ipc/service/gpu_init.h"
Simeon Kuran372454c2019-12-11 19:02:1716#include "media/gpu/buildflags.h"
17
18#if BUILDFLAG(USE_VAAPI)
19#include "media/gpu/vaapi/vaapi_wrapper.h"
20#endif
[email protected]d7a2d892013-08-16 07:45:3621
Xiaohan Wang62737b52022-01-15 18:09:0222#if BUILDFLAG(IS_ANDROID)
hush5380add2015-12-18 00:41:4223#include "base/android/jni_android.h"
hush5380add2015-12-18 00:41:4224#endif
25
[email protected]d7a2d892013-08-16 07:45:3626namespace content {
27
Zhenyao Mo83b895e2017-10-18 18:50:5428InProcessGpuThread::InProcessGpuThread(
29 const InProcessChildThreadParams& params,
30 const gpu::GpuPreferences& gpu_preferences)
[email protected]d7a2d892013-08-16 07:45:3631 : base::Thread("Chrome_InProcGpuThread"),
morritac6238ab2015-03-18 01:48:2932 params_(params),
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2833 gpu_process_(nullptr),
Zhenyao Mo83b895e2017-10-18 18:50:5434 gpu_preferences_(gpu_preferences) {}
[email protected]d7a2d892013-08-16 07:45:3635
[email protected]8707caa2013-09-04 16:41:3036InProcessGpuThread::~InProcessGpuThread() {
[email protected]d7a2d892013-08-16 07:45:3637 Stop();
38}
39
[email protected]8707caa2013-09-04 16:41:3040void InProcessGpuThread::Init() {
reveman7caf8cf2016-02-16 02:39:0541 base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL;
42
Xiaohan Wang62737b52022-01-15 18:09:0243#if BUILDFLAG(IS_ANDROID)
hush5380add2015-12-18 00:41:4244 // Call AttachCurrentThreadWithName, before any other AttachCurrentThread()
45 // calls. The latter causes Java VM to assign Thread-??? to the thread name.
46 // Please note calls to AttachCurrentThreadWithName after AttachCurrentThread
47 // will not change the thread name kept in Java VM.
hush5380add2015-12-18 00:41:4248 base::android::AttachCurrentThreadWithName(thread_name());
reveman7caf8cf2016-02-16 02:39:0549 // Up the priority of the |io_thread_| on Android.
50 io_thread_priority = base::ThreadPriority::DISPLAY;
hush5380add2015-12-18 00:41:4251#endif
52
Joe Mason94bebf12022-06-03 15:03:5353 gpu_process_ = new ChildProcess(io_thread_priority);
xhwang9c8e1282015-10-10 01:54:0754
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5755 auto gpu_init = std::make_unique<gpu::GpuInit>();
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5756 gpu_init->InitializeInProcess(base::CommandLine::ForCurrentProcess(),
Zhenyao Moe23f75262018-02-07 02:15:0057 gpu_preferences_);
kylechar002b2ee2017-03-15 23:50:1258
Simeon Kuran372454c2019-12-11 19:02:1759#if BUILDFLAG(USE_VAAPI)
60 media::VaapiWrapper::PreSandboxInitialization();
61#endif
62
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5763 GetContentClient()->SetGpuInfo(gpu_init->gpu_info());
ericrk41a1579e2017-02-10 20:56:2864
[email protected]d7a2d892013-08-16 07:45:3665 // The process object takes ownership of the thread object, so do not
66 // save and delete the pointer.
sadrul6d41b822017-04-02 03:38:5067 GpuChildThread* child_thread =
Sadrul Habib Chowdhurydb9021e2017-10-03 03:07:5768 new GpuChildThread(params_, std::move(gpu_init));
xhwang9c8e1282015-10-10 01:54:0769
70 // Since we are in the browser process, use the thread start time as the
71 // process start time.
72 child_thread->Init(base::Time::Now());
73
74 gpu_process_->set_main_thread(child_thread);
[email protected]d7a2d892013-08-16 07:45:3675}
76
[email protected]8707caa2013-09-04 16:41:3077void InProcessGpuThread::CleanUp() {
[email protected]242f6cf2014-06-09 20:24:5878 SetThreadWasQuitProperly(true);
[email protected]d7a2d892013-08-16 07:45:3679 delete gpu_process_;
80}
81
morritac6238ab2015-03-18 01:48:2982base::Thread* CreateInProcessGpuThread(
Zhenyao Mo83b895e2017-10-18 18:50:5483 const InProcessChildThreadParams& params,
84 const gpu::GpuPreferences& gpu_preferences) {
85 return new InProcessGpuThread(params, gpu_preferences);
[email protected]d7a2d892013-08-16 07:45:3686}
87
88} // namespace content