[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 | |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 7 | #include "base/time/time.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 8 | #include "build/build_config.h" |
grt | 8c64842 | 2015-06-29 18:17:17 | [diff] [blame] | 9 | #include "content/common/gpu/gpu_memory_buffer_factory.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" |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 12 | #include "gpu/command_buffer/service/sync_point_manager.h" |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 13 | |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 14 | #if defined(OS_ANDROID) |
| 15 | #include "base/android/jni_android.h" |
| 16 | #endif |
| 17 | |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 18 | namespace content { |
| 19 | |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 20 | InProcessGpuThread::InProcessGpuThread( |
| 21 | const InProcessChildThreadParams& params, |
| 22 | gpu::SyncPointManager* sync_point_manager_override) |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 23 | : base::Thread("Chrome_InProcGpuThread"), |
morrita | c6238ab | 2015-03-18 01:48:29 | [diff] [blame] | 24 | params_(params), |
grt | 8c64842 | 2015-06-29 18:17:17 | [diff] [blame] | 25 | gpu_process_(NULL), |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 26 | sync_point_manager_override_(sync_point_manager_override), |
reveman | fb8c8e10 | 2015-10-07 20:26:32 | [diff] [blame] | 27 | gpu_memory_buffer_factory_( |
| 28 | GpuMemoryBufferFactory::GetNativeType() != gfx::EMPTY_BUFFER |
| 29 | ? GpuMemoryBufferFactory::CreateNativeType() |
| 30 | : nullptr) { |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 31 | if (!sync_point_manager_override_) { |
| 32 | sync_point_manager_.reset(new gpu::SyncPointManager(false)); |
| 33 | sync_point_manager_override_ = sync_point_manager_.get(); |
| 34 | } |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 35 | } |
| 36 | |
[email protected] | 8707caa | 2013-09-04 16:41:30 | [diff] [blame] | 37 | InProcessGpuThread::~InProcessGpuThread() { |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 38 | Stop(); |
| 39 | } |
| 40 | |
[email protected] | 8707caa | 2013-09-04 16:41:30 | [diff] [blame] | 41 | void InProcessGpuThread::Init() { |
reveman | 7caf8cf | 2016-02-16 02:39:05 | [diff] [blame^] | 42 | base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL; |
| 43 | |
| 44 | #if defined(OS_ANDROID) |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 45 | // Call AttachCurrentThreadWithName, before any other AttachCurrentThread() |
| 46 | // calls. The latter causes Java VM to assign Thread-??? to the thread name. |
| 47 | // Please note calls to AttachCurrentThreadWithName after AttachCurrentThread |
| 48 | // will not change the thread name kept in Java VM. |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 49 | base::android::AttachCurrentThreadWithName(thread_name()); |
reveman | 7caf8cf | 2016-02-16 02:39:05 | [diff] [blame^] | 50 | // Up the priority of the |io_thread_| on Android. |
| 51 | io_thread_priority = base::ThreadPriority::DISPLAY; |
hush | 5380add | 2015-12-18 00:41:42 | [diff] [blame] | 52 | #endif |
| 53 | |
reveman | 7caf8cf | 2016-02-16 02:39:05 | [diff] [blame^] | 54 | gpu_process_ = new GpuProcess(io_thread_priority); |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [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. |
xhwang | 9c8e128 | 2015-10-10 01:54:07 | [diff] [blame] | 58 | GpuChildThread* child_thread = new GpuChildThread( |
| 59 | params_, gpu_memory_buffer_factory_.get(), sync_point_manager_override_); |
| 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( |
| 74 | const InProcessChildThreadParams& params) { |
boliu | c5befe7 | 2015-07-21 19:08:56 | [diff] [blame] | 75 | return new InProcessGpuThread(params, nullptr); |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | } // namespace content |