OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/ipc/service/gpu_channel_manager.h" | 5 #include "gpu/ipc/service/gpu_channel_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "gpu/command_buffer/common/sync_token.h" | 18 #include "gpu/command_buffer/common/sync_token.h" |
19 #include "gpu/command_buffer/service/feature_info.h" | 19 #include "gpu/command_buffer/service/feature_info.h" |
20 #include "gpu/command_buffer/service/mailbox_manager.h" | 20 #include "gpu/command_buffer/service/mailbox_manager.h" |
21 #include "gpu/command_buffer/service/memory_program_cache.h" | 21 #include "gpu/command_buffer/service/memory_program_cache.h" |
22 #include "gpu/command_buffer/service/preemption_flag.h" | 22 #include "gpu/command_buffer/service/preemption_flag.h" |
23 #include "gpu/command_buffer/service/scheduler.h" | |
24 #include "gpu/command_buffer/service/shader_translator_cache.h" | 23 #include "gpu/command_buffer/service/shader_translator_cache.h" |
25 #include "gpu/command_buffer/service/sync_point_manager.h" | 24 #include "gpu/command_buffer/service/sync_point_manager.h" |
26 #include "gpu/ipc/common/gpu_messages.h" | 25 #include "gpu/ipc/common/gpu_messages.h" |
27 #include "gpu/ipc/service/gpu_channel.h" | 26 #include "gpu/ipc/service/gpu_channel.h" |
28 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" | 27 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" |
29 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 28 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
30 #include "gpu/ipc/service/gpu_memory_manager.h" | 29 #include "gpu/ipc/service/gpu_memory_manager.h" |
31 #include "ui/gl/gl_bindings.h" | 30 #include "ui/gl/gl_bindings.h" |
32 #include "ui/gl/gl_share_group.h" | 31 #include "ui/gl/gl_share_group.h" |
33 #include "ui/gl/init/gl_factory.h" | 32 #include "ui/gl/init/gl_factory.h" |
34 | 33 |
35 namespace gpu { | 34 namespace gpu { |
36 | 35 |
37 namespace { | 36 namespace { |
38 #if defined(OS_ANDROID) | 37 #if defined(OS_ANDROID) |
39 // Amount of time we expect the GPU to stay powered up without being used. | 38 // Amount of time we expect the GPU to stay powered up without being used. |
40 const int kMaxGpuIdleTimeMs = 40; | 39 const int kMaxGpuIdleTimeMs = 40; |
41 // Maximum amount of time we keep pinging the GPU waiting for the client to | 40 // Maximum amount of time we keep pinging the GPU waiting for the client to |
42 // draw. | 41 // draw. |
43 const int kMaxKeepAliveTimeMs = 200; | 42 const int kMaxKeepAliveTimeMs = 200; |
44 #endif | 43 #endif |
| 44 |
45 } | 45 } |
46 | 46 |
47 GpuChannelManager::GpuChannelManager( | 47 GpuChannelManager::GpuChannelManager( |
48 const GpuPreferences& gpu_preferences, | 48 const GpuPreferences& gpu_preferences, |
49 const GpuDriverBugWorkarounds& workarounds, | 49 const GpuDriverBugWorkarounds& workarounds, |
50 GpuChannelManagerDelegate* delegate, | 50 GpuChannelManagerDelegate* delegate, |
51 GpuWatchdogThread* watchdog, | 51 GpuWatchdogThread* watchdog, |
52 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 52 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
53 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 53 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
54 Scheduler* scheduler, | |
55 SyncPointManager* sync_point_manager, | 54 SyncPointManager* sync_point_manager, |
56 GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 55 GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
57 const GpuFeatureInfo& gpu_feature_info, | 56 const GpuFeatureInfo& gpu_feature_info, |
58 GpuProcessActivityFlags activity_flags) | 57 GpuProcessActivityFlags activity_flags) |
59 : task_runner_(task_runner), | 58 : task_runner_(task_runner), |
60 io_task_runner_(io_task_runner), | 59 io_task_runner_(io_task_runner), |
61 gpu_preferences_(gpu_preferences), | 60 gpu_preferences_(gpu_preferences), |
62 gpu_driver_bug_workarounds_(workarounds), | 61 gpu_driver_bug_workarounds_(workarounds), |
63 delegate_(delegate), | 62 delegate_(delegate), |
64 watchdog_(watchdog), | 63 watchdog_(watchdog), |
65 share_group_(new gl::GLShareGroup()), | 64 share_group_(new gl::GLShareGroup()), |
66 mailbox_manager_(gles2::MailboxManager::Create(gpu_preferences)), | 65 mailbox_manager_(gles2::MailboxManager::Create(gpu_preferences)), |
67 gpu_memory_manager_(this), | 66 gpu_memory_manager_(this), |
68 scheduler_(scheduler), | |
69 sync_point_manager_(sync_point_manager), | 67 sync_point_manager_(sync_point_manager), |
70 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 68 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
71 gpu_feature_info_(gpu_feature_info), | 69 gpu_feature_info_(gpu_feature_info), |
72 exiting_for_lost_context_(false), | 70 exiting_for_lost_context_(false), |
73 activity_flags_(std::move(activity_flags)), | 71 activity_flags_(std::move(activity_flags)), |
74 weak_factory_(this) { | 72 weak_factory_(this) { |
75 DCHECK(task_runner); | 73 DCHECK(task_runner); |
76 DCHECK(io_task_runner); | 74 DCHECK(io_task_runner); |
77 if (gpu_preferences.ui_prioritize_in_gpu_process) | 75 if (gpu_preferences_.ui_prioritize_in_gpu_process) |
78 preemption_flag_ = new PreemptionFlag; | 76 preemption_flag_ = new PreemptionFlag; |
79 } | 77 } |
80 | 78 |
81 GpuChannelManager::~GpuChannelManager() { | 79 GpuChannelManager::~GpuChannelManager() { |
82 // Destroy channels before anything else because of dependencies. | 80 // Destroy channels before anything else because of dependencies. |
83 gpu_channels_.clear(); | 81 gpu_channels_.clear(); |
84 if (default_offscreen_surface_.get()) { | 82 if (default_offscreen_surface_.get()) { |
85 default_offscreen_surface_->Destroy(); | 83 default_offscreen_surface_->Destroy(); |
86 default_offscreen_surface_ = NULL; | 84 default_offscreen_surface_ = NULL; |
87 } | 85 } |
88 } | 86 } |
89 | 87 |
90 gles2::ProgramCache* GpuChannelManager::program_cache() { | 88 gles2::ProgramCache* GpuChannelManager::program_cache() { |
91 if (!program_cache_.get() && | 89 if (!program_cache_.get() && |
92 !gpu_preferences_.disable_gpu_program_cache) { | 90 !gpu_preferences_.disable_gpu_program_cache) { |
93 const GpuDriverBugWorkarounds& workarounds = gpu_driver_bug_workarounds_; | 91 const GpuDriverBugWorkarounds& workarounds = gpu_driver_bug_workarounds_; |
94 bool disable_disk_cache = | 92 bool disable_disk_cache = |
95 gpu_preferences_.disable_gpu_shader_disk_cache || | 93 gpu_preferences_.disable_gpu_shader_disk_cache || |
96 workarounds.disable_program_disk_cache; | 94 workarounds.disable_program_disk_cache; |
97 program_cache_.reset(new gles2::MemoryProgramCache( | 95 program_cache_.reset(new gles2::MemoryProgramCache( |
98 gpu_preferences_.gpu_program_cache_size, disable_disk_cache, | 96 gpu_preferences_.gpu_program_cache_size, disable_disk_cache, |
99 workarounds.disable_program_caching_for_transform_feedback, | 97 workarounds.disable_program_caching_for_transform_feedback, |
100 &activity_flags_)); | 98 &activity_flags_)); |
101 } | 99 } |
102 return program_cache_.get(); | 100 return program_cache_.get(); |
103 } | 101 } |
104 | 102 |
105 gles2::ShaderTranslatorCache* GpuChannelManager::shader_translator_cache() { | 103 gles2::ShaderTranslatorCache* |
| 104 GpuChannelManager::shader_translator_cache() { |
106 if (!shader_translator_cache_.get()) { | 105 if (!shader_translator_cache_.get()) { |
107 shader_translator_cache_ = | 106 shader_translator_cache_ = |
108 new gles2::ShaderTranslatorCache(gpu_preferences_); | 107 new gles2::ShaderTranslatorCache(gpu_preferences_); |
109 } | 108 } |
110 return shader_translator_cache_.get(); | 109 return shader_translator_cache_.get(); |
111 } | 110 } |
112 | 111 |
113 gles2::FramebufferCompletenessCache* | 112 gles2::FramebufferCompletenessCache* |
114 GpuChannelManager::framebuffer_completeness_cache() { | 113 GpuChannelManager::framebuffer_completeness_cache() { |
115 if (!framebuffer_completeness_cache_.get()) | 114 if (!framebuffer_completeness_cache_.get()) |
116 framebuffer_completeness_cache_ = new gles2::FramebufferCompletenessCache; | 115 framebuffer_completeness_cache_ = |
| 116 new gles2::FramebufferCompletenessCache; |
117 return framebuffer_completeness_cache_.get(); | 117 return framebuffer_completeness_cache_.get(); |
118 } | 118 } |
119 | 119 |
120 void GpuChannelManager::RemoveChannel(int client_id) { | 120 void GpuChannelManager::RemoveChannel(int client_id) { |
121 delegate_->DidDestroyChannel(client_id); | 121 delegate_->DidDestroyChannel(client_id); |
122 gpu_channels_.erase(client_id); | 122 gpu_channels_.erase(client_id); |
123 } | 123 } |
124 | 124 |
125 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const { | 125 GpuChannel* GpuChannelManager::LookupChannel(int32_t client_id) const { |
126 const auto& it = gpu_channels_.find(client_id); | 126 const auto& it = gpu_channels_.find(client_id); |
127 return it != gpu_channels_.end() ? it->second.get() : nullptr; | 127 return it != gpu_channels_.end() ? it->second.get() : nullptr; |
128 } | 128 } |
129 | 129 |
130 GpuChannel* GpuChannelManager::EstablishChannel(int client_id, | 130 GpuChannel* GpuChannelManager::EstablishChannel(int client_id, |
131 uint64_t client_tracing_id, | 131 uint64_t client_tracing_id, |
132 bool is_gpu_host) { | 132 bool is_gpu_host) { |
133 std::unique_ptr<GpuChannel> gpu_channel = base::MakeUnique<GpuChannel>( | 133 std::unique_ptr<GpuChannel> gpu_channel = base::MakeUnique<GpuChannel>( |
134 this, scheduler_, sync_point_manager_, watchdog_, share_group_, | 134 this, sync_point_manager_, watchdog_, share_group_, mailbox_manager_, |
135 mailbox_manager_, is_gpu_host ? preemption_flag_ : nullptr, | 135 is_gpu_host ? preemption_flag_ : nullptr, |
136 is_gpu_host ? nullptr : preemption_flag_, task_runner_, io_task_runner_, | 136 is_gpu_host ? nullptr : preemption_flag_, task_runner_, io_task_runner_, |
137 client_id, client_tracing_id, is_gpu_host); | 137 client_id, client_tracing_id, is_gpu_host); |
138 | 138 |
139 GpuChannel* gpu_channel_ptr = gpu_channel.get(); | 139 GpuChannel* gpu_channel_ptr = gpu_channel.get(); |
140 gpu_channels_[client_id] = std::move(gpu_channel); | 140 gpu_channels_[client_id] = std::move(gpu_channel); |
141 return gpu_channel_ptr; | 141 return gpu_channel_ptr; |
142 } | 142 } |
143 | 143 |
144 void GpuChannelManager::InternalDestroyGpuMemoryBuffer( | 144 void GpuChannelManager::InternalDestroyGpuMemoryBuffer( |
145 gfx::GpuMemoryBufferId id, | 145 gfx::GpuMemoryBufferId id, |
146 int client_id) { | 146 int client_id) { |
147 io_task_runner_->PostTask( | 147 io_task_runner_->PostTask( |
148 FROM_HERE, | 148 FROM_HERE, |
149 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO, | 149 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO, |
150 base::Unretained(this), id, client_id)); | 150 base::Unretained(this), id, client_id)); |
151 } | 151 } |
152 | 152 |
153 void GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO( | 153 void GpuChannelManager::InternalDestroyGpuMemoryBufferOnIO( |
154 gfx::GpuMemoryBufferId id, | 154 gfx::GpuMemoryBufferId id, |
155 int client_id) { | 155 int client_id) { |
156 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); | 156 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(id, client_id); |
157 } | 157 } |
158 | 158 |
159 void GpuChannelManager::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 159 void GpuChannelManager::DestroyGpuMemoryBuffer( |
160 int client_id, | 160 gfx::GpuMemoryBufferId id, |
161 const SyncToken& sync_token) { | 161 int client_id, |
| 162 const SyncToken& sync_token) { |
162 if (!sync_point_manager_->WaitOutOfOrder( | 163 if (!sync_point_manager_->WaitOutOfOrder( |
163 sync_token, | 164 sync_token, |
164 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer, | 165 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer, |
165 base::Unretained(this), id, client_id))) { | 166 base::Unretained(this), id, client_id))) { |
166 // No sync token or invalid sync token, destroy immediately. | 167 // No sync token or invalid sync token, destroy immediately. |
167 InternalDestroyGpuMemoryBuffer(id, client_id); | 168 InternalDestroyGpuMemoryBuffer(id, client_id); |
168 } | 169 } |
169 } | 170 } |
170 | 171 |
171 void GpuChannelManager::PopulateShaderCache(const std::string& program_proto) { | 172 void GpuChannelManager::PopulateShaderCache(const std::string& program_proto) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 last_gpu_access_time_ = base::TimeTicks::Now(); | 211 last_gpu_access_time_ = base::TimeTicks::Now(); |
211 } | 212 } |
212 | 213 |
213 void GpuChannelManager::WakeUpGpu() { | 214 void GpuChannelManager::WakeUpGpu() { |
214 begin_wake_up_time_ = base::TimeTicks::Now(); | 215 begin_wake_up_time_ = base::TimeTicks::Now(); |
215 ScheduleWakeUpGpu(); | 216 ScheduleWakeUpGpu(); |
216 } | 217 } |
217 | 218 |
218 void GpuChannelManager::ScheduleWakeUpGpu() { | 219 void GpuChannelManager::ScheduleWakeUpGpu() { |
219 base::TimeTicks now = base::TimeTicks::Now(); | 220 base::TimeTicks now = base::TimeTicks::Now(); |
220 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", "idle_time", | 221 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", |
221 (now - last_gpu_access_time_).InMilliseconds(), | 222 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), |
222 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); | 223 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); |
223 if (now - last_gpu_access_time_ < | 224 if (now - last_gpu_access_time_ < |
224 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs)) | 225 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs)) |
225 return; | 226 return; |
226 if (now - begin_wake_up_time_ > | 227 if (now - begin_wake_up_time_ > |
227 base::TimeDelta::FromMilliseconds(kMaxKeepAliveTimeMs)) | 228 base::TimeDelta::FromMilliseconds(kMaxKeepAliveTimeMs)) |
228 return; | 229 return; |
229 | 230 |
230 DoWakeUpGpu(); | 231 DoWakeUpGpu(); |
231 | 232 |
(...skipping 14 matching lines...) Expand all Loading... |
246 } | 247 } |
247 } | 248 } |
248 if (!stub || !stub->decoder()->MakeCurrent()) | 249 if (!stub || !stub->decoder()->MakeCurrent()) |
249 return; | 250 return; |
250 glFinish(); | 251 glFinish(); |
251 DidAccessGpu(); | 252 DidAccessGpu(); |
252 } | 253 } |
253 #endif | 254 #endif |
254 | 255 |
255 } // namespace gpu | 256 } // namespace gpu |
OLD | NEW |