[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" |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 10 | #include "content/gpu/gpu_child_thread.h" |
| 11 | #include "content/gpu/gpu_process.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" |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 16 | |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 17 | #if defined(OS_ANDROID) |
| 18 | #include "base/android/jni_android.h" |
| 19 | #endif |
| 20 | |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 21 | namespace content { |
| 22 | |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 23 | InProcessGpuThread::InProcessGpuThread( |
| 24 | const InProcessChildThreadParams& params, |
| 25 | const gpu::GpuPreferences& gpu_preferences) |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 26 | : base::Thread("Chrome_InProcGpuThread"), |
morrita | c6238ab | 2015-03-18 01:48:29 | [diff] [blame] | 27 | params_(params), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 28 | gpu_process_(nullptr), |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 29 | gpu_preferences_(gpu_preferences) {} |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 30 | |
[email protected] | 8707caa | 2013-09-04 16:41:30 | [diff] [blame] | 31 | InProcessGpuThread::~InProcessGpuThread() { |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 32 | Stop(); |
| 33 | } |
| 34 | |
[email protected] | 8707caa | 2013-09-04 16:41:30 | [diff] [blame] | 35 | void InProcessGpuThread::Init() { |
reveman | 7caf8cf | 2016-02-16 02:39:05 | [diff] [blame] | 36 | base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL; |
| 37 | |
| 38 | #if defined(OS_ANDROID) |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 39 | // Call AttachCurrentThreadWithName, before any other AttachCurrentThread() |
| 40 | // calls. The latter causes Java VM to assign Thread-??? to the thread name. |
| 41 | // Please note calls to AttachCurrentThreadWithName after AttachCurrentThread |
| 42 | // will not change the thread name kept in Java VM. |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 43 | base::android::AttachCurrentThreadWithName(thread_name()); |
reveman | 7caf8cf | 2016-02-16 02:39:05 | [diff] [blame] | 44 | // Up the priority of the |io_thread_| on Android. |
| 45 | io_thread_priority = base::ThreadPriority::DISPLAY; |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 46 | #endif |
| 47 | |
reveman | 7caf8cf | 2016-02-16 02:39:05 | [diff] [blame] | 48 | gpu_process_ = new GpuProcess(io_thread_priority); |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 49 | |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 50 | auto gpu_init = std::make_unique<gpu::GpuInit>(); |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 51 | gpu_init->InitializeInProcess(base::CommandLine::ForCurrentProcess(), |
Zhenyao Mo | e23f7526 | 2018-02-07 02:15:00 | [diff] [blame] | 52 | gpu_preferences_); |
kylechar | 002b2ee | 2017-03-15 23:50:12 | [diff] [blame] | 53 | |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 54 | GetContentClient()->SetGpuInfo(gpu_init->gpu_info()); |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 55 | |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 56 | // The process object takes ownership of the thread object, so do not |
| 57 | // save and delete the pointer. |
sadrul | 6d41b82 | 2017-04-02 03:38:50 | [diff] [blame] | 58 | GpuChildThread* child_thread = |
Sadrul Habib Chowdhury | db9021e | 2017-10-03 03:07:57 | [diff] [blame] | 59 | new GpuChildThread(params_, std::move(gpu_init)); |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 60 | |
| 61 | // Since we are in the browser process, use the thread start time as the |
| 62 | // process start time. |
| 63 | child_thread->Init(base::Time::Now()); |
| 64 | |
| 65 | gpu_process_->set_main_thread(child_thread); |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 66 | } |
| 67 | |
[email protected] | 8707caa | 2013-09-04 16:41:30 | [diff] [blame] | 68 | void InProcessGpuThread::CleanUp() { |
[email protected] | 242f6cf | 2014-06-09 20:24:58 | [diff] [blame] | 69 | SetThreadWasQuitProperly(true); |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 70 | delete gpu_process_; |
| 71 | } |
| 72 | |
morrita | c6238ab | 2015-03-18 01:48:29 | [diff] [blame] | 73 | base::Thread* CreateInProcessGpuThread( |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 74 | const InProcessChildThreadParams& params, |
| 75 | const gpu::GpuPreferences& gpu_preferences) { |
| 76 | return new InProcessGpuThread(params, gpu_preferences); |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | } // namespace content |