OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/gpu/in_process_gpu_thread.h" | 5 #include "content/gpu/in_process_gpu_thread.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "content/gpu/gpu_child_thread.h" | 9 #include "content/gpu/gpu_child_thread.h" |
10 #include "content/gpu/gpu_process.h" | 10 #include "content/gpu/gpu_process.h" |
11 #include "gpu/command_buffer/service/sync_point_manager.h" | |
12 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 11 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
13 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 12 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
14 | 13 |
15 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
16 #include "base/android/jni_android.h" | 15 #include "base/android/jni_android.h" |
17 #endif | 16 #endif |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 | 19 |
21 InProcessGpuThread::InProcessGpuThread( | 20 InProcessGpuThread::InProcessGpuThread( |
22 const InProcessChildThreadParams& params, | 21 const InProcessChildThreadParams& params, |
23 const gpu::GpuPreferences& gpu_preferences, | 22 const gpu::GpuPreferences& gpu_preferences) |
24 gpu::SyncPointManager* sync_point_manager_override) | |
25 : base::Thread("Chrome_InProcGpuThread"), | 23 : base::Thread("Chrome_InProcGpuThread"), |
26 params_(params), | 24 params_(params), |
27 gpu_process_(NULL), | 25 gpu_process_(NULL), |
28 gpu_preferences_(gpu_preferences), | 26 gpu_preferences_(gpu_preferences), |
29 sync_point_manager_override_(sync_point_manager_override), | |
30 gpu_memory_buffer_factory_( | 27 gpu_memory_buffer_factory_( |
31 gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER | 28 gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER |
32 ? gpu::GpuMemoryBufferFactory::CreateNativeType() | 29 ? gpu::GpuMemoryBufferFactory::CreateNativeType() |
33 : nullptr) { | 30 : nullptr) {} |
34 if (!sync_point_manager_override_) { | |
35 sync_point_manager_.reset(new gpu::SyncPointManager(false)); | |
36 sync_point_manager_override_ = sync_point_manager_.get(); | |
37 } | |
38 } | |
39 | 31 |
40 InProcessGpuThread::~InProcessGpuThread() { | 32 InProcessGpuThread::~InProcessGpuThread() { |
41 Stop(); | 33 Stop(); |
42 } | 34 } |
43 | 35 |
44 void InProcessGpuThread::Init() { | 36 void InProcessGpuThread::Init() { |
45 base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL; | 37 base::ThreadPriority io_thread_priority = base::ThreadPriority::NORMAL; |
46 | 38 |
47 #if defined(OS_ANDROID) | 39 #if defined(OS_ANDROID) |
48 // Call AttachCurrentThreadWithName, before any other AttachCurrentThread() | 40 // Call AttachCurrentThreadWithName, before any other AttachCurrentThread() |
49 // calls. The latter causes Java VM to assign Thread-??? to the thread name. | 41 // calls. The latter causes Java VM to assign Thread-??? to the thread name. |
50 // Please note calls to AttachCurrentThreadWithName after AttachCurrentThread | 42 // Please note calls to AttachCurrentThreadWithName after AttachCurrentThread |
51 // will not change the thread name kept in Java VM. | 43 // will not change the thread name kept in Java VM. |
52 base::android::AttachCurrentThreadWithName(thread_name()); | 44 base::android::AttachCurrentThreadWithName(thread_name()); |
53 // Up the priority of the |io_thread_| on Android. | 45 // Up the priority of the |io_thread_| on Android. |
54 io_thread_priority = base::ThreadPriority::DISPLAY; | 46 io_thread_priority = base::ThreadPriority::DISPLAY; |
55 #endif | 47 #endif |
56 | 48 |
57 gpu_process_ = new GpuProcess(io_thread_priority); | 49 gpu_process_ = new GpuProcess(io_thread_priority); |
58 | 50 |
59 // The process object takes ownership of the thread object, so do not | 51 // The process object takes ownership of the thread object, so do not |
60 // save and delete the pointer. | 52 // save and delete the pointer. |
61 GpuChildThread* child_thread = new GpuChildThread( | 53 GpuChildThread* child_thread = new GpuChildThread( |
62 gpu_preferences_, params_, gpu_memory_buffer_factory_.get(), | 54 gpu_preferences_, params_, gpu_memory_buffer_factory_.get()); |
63 sync_point_manager_override_); | |
64 | 55 |
65 // Since we are in the browser process, use the thread start time as the | 56 // Since we are in the browser process, use the thread start time as the |
66 // process start time. | 57 // process start time. |
67 child_thread->Init(base::Time::Now()); | 58 child_thread->Init(base::Time::Now()); |
68 | 59 |
69 gpu_process_->set_main_thread(child_thread); | 60 gpu_process_->set_main_thread(child_thread); |
70 } | 61 } |
71 | 62 |
72 void InProcessGpuThread::CleanUp() { | 63 void InProcessGpuThread::CleanUp() { |
73 SetThreadWasQuitProperly(true); | 64 SetThreadWasQuitProperly(true); |
74 delete gpu_process_; | 65 delete gpu_process_; |
75 } | 66 } |
76 | 67 |
77 base::Thread* CreateInProcessGpuThread( | 68 base::Thread* CreateInProcessGpuThread( |
78 const InProcessChildThreadParams& params, | 69 const InProcessChildThreadParams& params, |
79 const gpu::GpuPreferences& gpu_preferences) { | 70 const gpu::GpuPreferences& gpu_preferences) { |
80 return new InProcessGpuThread( | 71 return new InProcessGpuThread(params, gpu_preferences); |
81 params, gpu_preferences, nullptr); | |
82 } | 72 } |
83 | 73 |
84 } // namespace content | 74 } // namespace content |
OLD | NEW |