[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 1 | // 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] | 8707caa | 2013-09-04 16:41:30 | [diff] [blame] | 5 | #include "content/gpu/in_process_gpu_thread.h" |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 6 | |
Thoren Paulson | 6dcf39e | 2017-08-02 16:33:29 | [diff] [blame] | 7 | #include "base/command_line.h" |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 8 | #include "base/time/time.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 9 | #include "build/build_config.h" |
Joe Mason | 94bebf1 | 2022-06-03 15:03:53 | [diff] [blame^] | 10 | #include "content/child/child_process.h" |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 11 | #include "content/gpu/gpu_child_thread.h" |
Zhenyao Mo | db2790b | 2017-08-30 00:10:15 | [diff] [blame] | 12 | #include "content/public/common/content_client.h" |
Thoren Paulson | 6dcf39e | 2017-08-02 16:33:29 | [diff] [blame] | 13 | #include "content/public/common/content_switches.h" |
Jonathan Backer | 0af50996 | 2018-05-30 16:05:07 | [diff] [blame] | 14 | #include "gpu/config/gpu_preferences.h" |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 15 | #include "gpu/ipc/service/gpu_init.h" |
Simeon Kuran | 372454c | 2019-12-11 19:02:17 | [diff] [blame] | 16 | #include "media/gpu/buildflags.h" |
| 17 | |
| 18 | #if BUILDFLAG(USE_VAAPI) |
| 19 | #include "media/gpu/vaapi/vaapi_wrapper.h" |
| 20 | #endif |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 21 | |
Xiaohan Wang | 62737b5 | 2022-01-15 18:09:02 | [diff] [blame] | 22 | #if BUILDFLAG(IS_ANDROID) |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 23 | #include "base/android/jni_android.h" |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 24 | #endif |
| 25 | |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 26 | namespace content { |
| 27 | |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 28 | InProcessGpuThread::InProcessGpuThread( |
| 29 | const InProcessChildThreadParams& params, |
| 30 | const gpu::GpuPreferences& gpu_preferences) |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 31 | : base::Thread("Chrome_InProcGpuThread"), |
morrita | c6238ab | 2015-03-18 01:48:29 | [diff] [blame] | 32 | params_(params), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 33 | gpu_process_(nullptr), |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 34 | gpu_preferences_(gpu_preferences) {} |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 35 | |
[email protected] | 8707caa | 2013-09-04 16:41:30 | [diff] [blame] | 36 | InProcessGpuThread::~InProcessGpuThread() { |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 37 | Stop(); |
| 38 | } |
| 39 | |
[email protected] | 8707caa | 2013-09-04 16:41:30 | [diff] [blame] | 40 | void InProcessGpuThread::Init() { |
reveman | 7caf8cf | 2016-02-16 02:39:05 | [diff] [blame] | 41 | base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL; |
| 42 | |
Xiaohan Wang | 62737b5 | 2022-01-15 18:09:02 | [diff] [blame] | 43 | #if BUILDFLAG(IS_ANDROID) |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 44 | // 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. |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 48 | base::android::AttachCurrentThreadWithName(thread_name()); |
reveman | 7caf8cf | 2016-02-16 02:39:05 | [diff] [blame] | 49 | // Up the priority of the |io_thread_| on Android. |
| 50 | io_thread_priority = base::ThreadPriority::DISPLAY; |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 51 | #endif |
| 52 | |
Joe Mason | 94bebf1 | 2022-06-03 15:03:53 | [diff] [blame^] | 53 | gpu_process_ = new ChildProcess(io_thread_priority); |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 54 | |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 55 | auto gpu_init = std::make_unique<gpu::GpuInit>(); |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 56 | gpu_init->InitializeInProcess(base::CommandLine::ForCurrentProcess(), |
Zhenyao Mo | e23f7526 | 2018-02-07 02:15:00 | [diff] [blame] | 57 | gpu_preferences_); |
kylechar | 002b2ee | 2017-03-15 23:50:12 | [diff] [blame] | 58 | |
Simeon Kuran | 372454c | 2019-12-11 19:02:17 | [diff] [blame] | 59 | #if BUILDFLAG(USE_VAAPI) |
| 60 | media::VaapiWrapper::PreSandboxInitialization(); |
| 61 | #endif |
| 62 | |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 63 | GetContentClient()->SetGpuInfo(gpu_init->gpu_info()); |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 64 | |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 65 | // The process object takes ownership of the thread object, so do not |
| 66 | // save and delete the pointer. |
sadrul | 6d41b82 | 2017-04-02 03:38:50 | [diff] [blame] | 67 | GpuChildThread* child_thread = |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 68 | new GpuChildThread(params_, std::move(gpu_init)); |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 69 | |
| 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] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 75 | } |
| 76 | |
[email protected] | 8707caa | 2013-09-04 16:41:30 | [diff] [blame] | 77 | void InProcessGpuThread::CleanUp() { |
[email protected] | 242f6cf | 2014-06-09 20:24:58 | [diff] [blame] | 78 | SetThreadWasQuitProperly(true); |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 79 | delete gpu_process_; |
| 80 | } |
| 81 | |
morrita | c6238ab | 2015-03-18 01:48:29 | [diff] [blame] | 82 | base::Thread* CreateInProcessGpuThread( |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 83 | const InProcessChildThreadParams& params, |
| 84 | const gpu::GpuPreferences& gpu_preferences) { |
| 85 | return new InProcessGpuThread(params, gpu_preferences); |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | } // namespace content |