| 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" |
| 23 #include "gpu/command_buffer/service/shader_translator_cache.h" | 24 #include "gpu/command_buffer/service/shader_translator_cache.h" |
| 24 #include "gpu/command_buffer/service/sync_point_manager.h" | 25 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 25 #include "gpu/ipc/common/gpu_messages.h" | 26 #include "gpu/ipc/common/gpu_messages.h" |
| 26 #include "gpu/ipc/service/gpu_channel.h" | 27 #include "gpu/ipc/service/gpu_channel.h" |
| 27 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" | 28 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" |
| 28 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 29 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
| 29 #include "gpu/ipc/service/gpu_memory_manager.h" | 30 #include "gpu/ipc/service/gpu_memory_manager.h" |
| 30 #include "ui/gl/gl_bindings.h" | 31 #include "ui/gl/gl_bindings.h" |
| 31 #include "ui/gl/gl_share_group.h" | 32 #include "ui/gl/gl_share_group.h" |
| 32 #include "ui/gl/init/gl_factory.h" | 33 #include "ui/gl/init/gl_factory.h" |
| 33 | 34 |
| 34 namespace gpu { | 35 namespace gpu { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
| 38 // Amount of time we expect the GPU to stay powered up without being used. | 39 // Amount of time we expect the GPU to stay powered up without being used. |
| 39 const int kMaxGpuIdleTimeMs = 40; | 40 const int kMaxGpuIdleTimeMs = 40; |
| 40 // Maximum amount of time we keep pinging the GPU waiting for the client to | 41 // Maximum amount of time we keep pinging the GPU waiting for the client to |
| 41 // draw. | 42 // draw. |
| 42 const int kMaxKeepAliveTimeMs = 200; | 43 const int kMaxKeepAliveTimeMs = 200; |
| 43 #endif | 44 #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, |
| 54 SyncPointManager* sync_point_manager, | 55 SyncPointManager* sync_point_manager, |
| 55 GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 56 GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
| 56 const GpuFeatureInfo& gpu_feature_info, | 57 const GpuFeatureInfo& gpu_feature_info, |
| 57 GpuProcessActivityFlags activity_flags) | 58 GpuProcessActivityFlags activity_flags) |
| 58 : task_runner_(task_runner), | 59 : task_runner_(task_runner), |
| 59 io_task_runner_(io_task_runner), | 60 io_task_runner_(io_task_runner), |
| 60 gpu_preferences_(gpu_preferences), | 61 gpu_preferences_(gpu_preferences), |
| 61 gpu_driver_bug_workarounds_(workarounds), | 62 gpu_driver_bug_workarounds_(workarounds), |
| 62 delegate_(delegate), | 63 delegate_(delegate), |
| 63 watchdog_(watchdog), | 64 watchdog_(watchdog), |
| 64 share_group_(new gl::GLShareGroup()), | 65 share_group_(new gl::GLShareGroup()), |
| 65 mailbox_manager_(gles2::MailboxManager::Create(gpu_preferences)), | 66 mailbox_manager_(gles2::MailboxManager::Create(gpu_preferences)), |
| 66 gpu_memory_manager_(this), | 67 gpu_memory_manager_(this), |
| 68 scheduler_(scheduler), |
| 67 sync_point_manager_(sync_point_manager), | 69 sync_point_manager_(sync_point_manager), |
| 68 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 70 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
| 69 gpu_feature_info_(gpu_feature_info), | 71 gpu_feature_info_(gpu_feature_info), |
| 70 exiting_for_lost_context_(false), | 72 exiting_for_lost_context_(false), |
| 71 activity_flags_(std::move(activity_flags)), | 73 activity_flags_(std::move(activity_flags)), |
| 72 weak_factory_(this) { | 74 weak_factory_(this) { |
| 73 DCHECK(task_runner); | 75 DCHECK(task_runner); |
| 74 DCHECK(io_task_runner); | 76 DCHECK(io_task_runner); |
| 75 if (gpu_preferences_.ui_prioritize_in_gpu_process) | 77 if (gpu_preferences.ui_prioritize_in_gpu_process) |
| 76 preemption_flag_ = new PreemptionFlag; | 78 preemption_flag_ = new PreemptionFlag; |
| 77 } | 79 } |
| 78 | 80 |
| 79 GpuChannelManager::~GpuChannelManager() { | 81 GpuChannelManager::~GpuChannelManager() { |
| 80 // Destroy channels before anything else because of dependencies. | 82 // Destroy channels before anything else because of dependencies. |
| 81 gpu_channels_.clear(); | 83 gpu_channels_.clear(); |
| 82 if (default_offscreen_surface_.get()) { | 84 if (default_offscreen_surface_.get()) { |
| 83 default_offscreen_surface_->Destroy(); | 85 default_offscreen_surface_->Destroy(); |
| 84 default_offscreen_surface_ = NULL; | 86 default_offscreen_surface_ = NULL; |
| 85 } | 87 } |
| 86 } | 88 } |
| 87 | 89 |
| 88 gles2::ProgramCache* GpuChannelManager::program_cache() { | 90 gles2::ProgramCache* GpuChannelManager::program_cache() { |
| 89 if (!program_cache_.get() && | 91 if (!program_cache_.get() && |
| 90 !gpu_preferences_.disable_gpu_program_cache) { | 92 !gpu_preferences_.disable_gpu_program_cache) { |
| 91 const GpuDriverBugWorkarounds& workarounds = gpu_driver_bug_workarounds_; | 93 const GpuDriverBugWorkarounds& workarounds = gpu_driver_bug_workarounds_; |
| 92 bool disable_disk_cache = | 94 bool disable_disk_cache = |
| 93 gpu_preferences_.disable_gpu_shader_disk_cache || | 95 gpu_preferences_.disable_gpu_shader_disk_cache || |
| 94 workarounds.disable_program_disk_cache; | 96 workarounds.disable_program_disk_cache; |
| 95 program_cache_.reset(new gles2::MemoryProgramCache( | 97 program_cache_.reset(new gles2::MemoryProgramCache( |
| 96 gpu_preferences_.gpu_program_cache_size, disable_disk_cache, | 98 gpu_preferences_.gpu_program_cache_size, disable_disk_cache, |
| 97 workarounds.disable_program_caching_for_transform_feedback, | 99 workarounds.disable_program_caching_for_transform_feedback, |
| 98 &activity_flags_)); | 100 &activity_flags_)); |
| 99 } | 101 } |
| 100 return program_cache_.get(); | 102 return program_cache_.get(); |
| 101 } | 103 } |
| 102 | 104 |
| 103 gles2::ShaderTranslatorCache* | 105 gles2::ShaderTranslatorCache* GpuChannelManager::shader_translator_cache() { |
| 104 GpuChannelManager::shader_translator_cache() { | |
| 105 if (!shader_translator_cache_.get()) { | 106 if (!shader_translator_cache_.get()) { |
| 106 shader_translator_cache_ = | 107 shader_translator_cache_ = |
| 107 new gles2::ShaderTranslatorCache(gpu_preferences_); | 108 new gles2::ShaderTranslatorCache(gpu_preferences_); |
| 108 } | 109 } |
| 109 return shader_translator_cache_.get(); | 110 return shader_translator_cache_.get(); |
| 110 } | 111 } |
| 111 | 112 |
| 112 gles2::FramebufferCompletenessCache* | 113 gles2::FramebufferCompletenessCache* |
| 113 GpuChannelManager::framebuffer_completeness_cache() { | 114 GpuChannelManager::framebuffer_completeness_cache() { |
| 114 if (!framebuffer_completeness_cache_.get()) | 115 if (!framebuffer_completeness_cache_.get()) |
| 115 framebuffer_completeness_cache_ = | 116 framebuffer_completeness_cache_ = new gles2::FramebufferCompletenessCache; |
| 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, sync_point_manager_, watchdog_, share_group_, mailbox_manager_, | 134 this, scheduler_, sync_point_manager_, watchdog_, share_group_, |
| 135 is_gpu_host ? preemption_flag_ : nullptr, | 135 mailbox_manager_, 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( | 159 void GpuChannelManager::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 160 gfx::GpuMemoryBufferId id, | 160 int client_id, |
| 161 int client_id, | 161 const SyncToken& sync_token) { |
| 162 const SyncToken& sync_token) { | |
| 163 if (!sync_point_manager_->WaitOutOfOrder( | 162 if (!sync_point_manager_->WaitOutOfOrder( |
| 164 sync_token, | 163 sync_token, |
| 165 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer, | 164 base::Bind(&GpuChannelManager::InternalDestroyGpuMemoryBuffer, |
| 166 base::Unretained(this), id, client_id))) { | 165 base::Unretained(this), id, client_id))) { |
| 167 // No sync token or invalid sync token, destroy immediately. | 166 // No sync token or invalid sync token, destroy immediately. |
| 168 InternalDestroyGpuMemoryBuffer(id, client_id); | 167 InternalDestroyGpuMemoryBuffer(id, client_id); |
| 169 } | 168 } |
| 170 } | 169 } |
| 171 | 170 |
| 172 void GpuChannelManager::PopulateShaderCache(const std::string& program_proto) { | 171 void GpuChannelManager::PopulateShaderCache(const std::string& program_proto) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 last_gpu_access_time_ = base::TimeTicks::Now(); | 210 last_gpu_access_time_ = base::TimeTicks::Now(); |
| 212 } | 211 } |
| 213 | 212 |
| 214 void GpuChannelManager::WakeUpGpu() { | 213 void GpuChannelManager::WakeUpGpu() { |
| 215 begin_wake_up_time_ = base::TimeTicks::Now(); | 214 begin_wake_up_time_ = base::TimeTicks::Now(); |
| 216 ScheduleWakeUpGpu(); | 215 ScheduleWakeUpGpu(); |
| 217 } | 216 } |
| 218 | 217 |
| 219 void GpuChannelManager::ScheduleWakeUpGpu() { | 218 void GpuChannelManager::ScheduleWakeUpGpu() { |
| 220 base::TimeTicks now = base::TimeTicks::Now(); | 219 base::TimeTicks now = base::TimeTicks::Now(); |
| 221 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", | 220 TRACE_EVENT2("gpu", "GpuChannelManager::ScheduleWakeUp", "idle_time", |
| 222 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), | 221 (now - last_gpu_access_time_).InMilliseconds(), |
| 223 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); | 222 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); |
| 224 if (now - last_gpu_access_time_ < | 223 if (now - last_gpu_access_time_ < |
| 225 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs)) | 224 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs)) |
| 226 return; | 225 return; |
| 227 if (now - begin_wake_up_time_ > | 226 if (now - begin_wake_up_time_ > |
| 228 base::TimeDelta::FromMilliseconds(kMaxKeepAliveTimeMs)) | 227 base::TimeDelta::FromMilliseconds(kMaxKeepAliveTimeMs)) |
| 229 return; | 228 return; |
| 230 | 229 |
| 231 DoWakeUpGpu(); | 230 DoWakeUpGpu(); |
| 232 | 231 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 247 } | 246 } |
| 248 } | 247 } |
| 249 if (!stub || !stub->decoder()->MakeCurrent()) | 248 if (!stub || !stub->decoder()->MakeCurrent()) |
| 250 return; | 249 return; |
| 251 glFinish(); | 250 glFinish(); |
| 252 DidAccessGpu(); | 251 DidAccessGpu(); |
| 253 } | 252 } |
| 254 #endif | 253 #endif |
| 255 | 254 |
| 256 } // namespace gpu | 255 } // namespace gpu |
| OLD | NEW |