Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/renderer_host/context_provider_factory_impl_android.h" | 5 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 11 #include "cc/output/context_provider.h" | 12 #include "cc/output/context_provider.h" |
| 12 #include "cc/output/vulkan_in_process_context_provider.h" | 13 #include "cc/output/vulkan_in_process_context_provider.h" |
| 13 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
| 14 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 15 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 15 #include "content/browser/gpu/compositor_util.h" | 16 #include "content/browser/gpu/compositor_util.h" |
| 16 #include "content/browser/gpu/gpu_surface_tracker.h" | 17 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 17 #include "content/common/gpu/client/context_provider_command_buffer.h" | 18 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 18 #include "content/common/host_shared_bitmap_manager.h" | 19 #include "content/common/host_shared_bitmap_manager.h" |
| 19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 : gpu_channel_factory_(gpu_channel_factory), | 66 : gpu_channel_factory_(gpu_channel_factory), |
| 66 in_handle_pending_requests_(false), | 67 in_handle_pending_requests_(false), |
| 67 in_shutdown_(false), | 68 in_shutdown_(false), |
| 68 surface_client_id_(0), | 69 surface_client_id_(0), |
| 69 weak_factory_(this) { | 70 weak_factory_(this) { |
| 70 DCHECK(gpu_channel_factory_); | 71 DCHECK(gpu_channel_factory_); |
| 71 } | 72 } |
| 72 | 73 |
| 73 ContextProviderFactoryImpl::~ContextProviderFactoryImpl() { | 74 ContextProviderFactoryImpl::~ContextProviderFactoryImpl() { |
| 74 in_shutdown_ = true; | 75 in_shutdown_ = true; |
| 75 if (!context_provider_requests_.empty()) | 76 if (!gpu_channel_requests_.empty()) |
| 76 HandlePendingRequests(nullptr, | 77 HandlePendingRequests(nullptr, |
| 77 ContextCreationResult::FAILURE_FACTORY_SHUTDOWN); | 78 GpuChannelHostResult::FAILURE_FACTORY_SHUTDOWN); |
| 78 } | 79 } |
| 79 | 80 |
| 80 ContextProviderFactoryImpl::ContextProvidersRequest::ContextProvidersRequest() | |
| 81 : context_type(command_buffer_metrics::CONTEXT_TYPE_UNKNOWN), | |
| 82 surface_handle(gpu::kNullSurfaceHandle), | |
| 83 support_locking(false), | |
| 84 automatic_flushes(false), | |
| 85 shared_context_provider(nullptr) {} | |
| 86 | |
| 87 ContextProviderFactoryImpl::ContextProvidersRequest::ContextProvidersRequest( | |
| 88 const ContextProvidersRequest& other) = default; | |
| 89 | |
| 90 ContextProviderFactoryImpl::ContextProvidersRequest:: | |
| 91 ~ContextProvidersRequest() = default; | |
| 92 | |
| 93 scoped_refptr<cc::VulkanContextProvider> | 81 scoped_refptr<cc::VulkanContextProvider> |
| 94 ContextProviderFactoryImpl::GetSharedVulkanContextProvider() { | 82 ContextProviderFactoryImpl::GetSharedVulkanContextProvider() { |
| 95 if (!shared_vulkan_context_provider_) | 83 if (!shared_vulkan_context_provider_) |
| 96 shared_vulkan_context_provider_ = | 84 shared_vulkan_context_provider_ = |
| 97 cc::VulkanInProcessContextProvider::Create(); | 85 cc::VulkanInProcessContextProvider::Create(); |
| 98 | 86 |
| 99 return shared_vulkan_context_provider_.get(); | 87 return shared_vulkan_context_provider_.get(); |
| 100 } | 88 } |
| 101 | 89 |
| 102 void ContextProviderFactoryImpl::CreateDisplayContextProvider( | 90 void ContextProviderFactoryImpl::RequestGpuChannelHost( |
| 91 GpuChannelHostCallback callback) { | |
| 92 DCHECK(!in_shutdown_) | |
| 93 << "The factory is shutting down, can't handle new requests"; | |
| 94 | |
| 95 gpu_channel_requests_.push(callback); | |
| 96 // If the channel is available, the factory will run the callback | |
| 97 // synchronously so we'll handle this request there. | |
| 98 EstablishGpuChannel(); | |
| 99 } | |
| 100 | |
| 101 scoped_refptr<cc::ContextProvider> | |
| 102 ContextProviderFactoryImpl::CreateDisplayContextProvider( | |
| 103 gpu::SurfaceHandle surface_handle, | 103 gpu::SurfaceHandle surface_handle, |
| 104 gpu::SharedMemoryLimits shared_memory_limits, | 104 gpu::SharedMemoryLimits shared_memory_limits, |
| 105 gpu::gles2::ContextCreationAttribHelper attributes, | 105 gpu::gles2::ContextCreationAttribHelper attributes, |
| 106 bool support_locking, | 106 bool support_locking, |
| 107 bool automatic_flushes, | 107 bool automatic_flushes, |
| 108 ContextProviderCallback result_callback) { | 108 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { |
| 109 DCHECK(!in_shutdown_) | |
| 110 << "The factory is shutting down, can't handle new requests"; | |
| 111 DCHECK(surface_handle != gpu::kNullSurfaceHandle); | 109 DCHECK(surface_handle != gpu::kNullSurfaceHandle); |
| 112 CreateContextProviderInternal( | 110 return CreateContextProviderInternal( |
| 113 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT, | 111 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT, |
| 114 surface_handle, shared_memory_limits, attributes, support_locking, | 112 surface_handle, shared_memory_limits, attributes, support_locking, |
| 115 automatic_flushes, nullptr, result_callback); | 113 automatic_flushes, nullptr, std::move(gpu_channel_host)); |
| 116 } | 114 } |
| 117 | 115 |
| 118 void ContextProviderFactoryImpl::CreateOffscreenContextProvider( | 116 scoped_refptr<cc::ContextProvider> |
| 117 ContextProviderFactoryImpl::CreateOffscreenContextProvider( | |
| 119 ContextType context_type, | 118 ContextType context_type, |
| 120 gpu::SharedMemoryLimits shared_memory_limits, | 119 gpu::SharedMemoryLimits shared_memory_limits, |
| 121 gpu::gles2::ContextCreationAttribHelper attributes, | 120 gpu::gles2::ContextCreationAttribHelper attributes, |
| 122 bool support_locking, | 121 bool support_locking, |
| 123 bool automatic_flushes, | 122 bool automatic_flushes, |
| 124 cc::ContextProvider* shared_context_provider, | 123 cc::ContextProvider* shared_context_provider, |
| 125 ContextProviderCallback result_callback) { | 124 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { |
| 126 DCHECK(!in_shutdown_) | 125 return CreateContextProviderInternal( |
| 127 << "The factory is shutting down, can't handle new requests"; | 126 ToCommandBufferContextType(context_type), gpu::kNullSurfaceHandle, |
| 128 CreateContextProviderInternal(ToCommandBufferContextType(context_type), | 127 shared_memory_limits, attributes, support_locking, automatic_flushes, |
| 129 gpu::kNullSurfaceHandle, shared_memory_limits, | 128 shared_context_provider, std::move(gpu_channel_host)); |
| 130 attributes, support_locking, automatic_flushes, | |
| 131 shared_context_provider, result_callback); | |
| 132 } | 129 } |
| 133 | 130 |
| 134 cc::SurfaceManager* ContextProviderFactoryImpl::GetSurfaceManager() { | 131 cc::SurfaceManager* ContextProviderFactoryImpl::GetSurfaceManager() { |
| 135 if (!surface_manager_) | 132 if (!surface_manager_) |
| 136 surface_manager_ = base::WrapUnique(new cc::SurfaceManager); | 133 surface_manager_ = base::WrapUnique(new cc::SurfaceManager); |
| 137 | 134 |
| 138 return surface_manager_.get(); | 135 return surface_manager_.get(); |
| 139 } | 136 } |
| 140 | 137 |
| 141 uint32_t ContextProviderFactoryImpl::AllocateSurfaceClientId() { | 138 uint32_t ContextProviderFactoryImpl::AllocateSurfaceClientId() { |
| 142 return ++surface_client_id_; | 139 return ++surface_client_id_; |
| 143 } | 140 } |
| 144 | 141 |
| 145 cc::SharedBitmapManager* ContextProviderFactoryImpl::GetSharedBitmapManager() { | 142 cc::SharedBitmapManager* ContextProviderFactoryImpl::GetSharedBitmapManager() { |
| 146 return HostSharedBitmapManager::current(); | 143 return HostSharedBitmapManager::current(); |
| 147 } | 144 } |
| 148 | 145 |
| 149 gpu::GpuMemoryBufferManager* | 146 gpu::GpuMemoryBufferManager* |
| 150 ContextProviderFactoryImpl::GetGpuMemoryBufferManager() { | 147 ContextProviderFactoryImpl::GetGpuMemoryBufferManager() { |
| 151 return BrowserGpuMemoryBufferManager::current(); | 148 return BrowserGpuMemoryBufferManager::current(); |
| 152 } | 149 } |
| 153 | 150 |
| 154 void ContextProviderFactoryImpl::CreateContextProviderInternal( | 151 scoped_refptr<cc::ContextProvider> |
| 152 ContextProviderFactoryImpl::CreateContextProviderInternal( | |
| 155 command_buffer_metrics::ContextType context_type, | 153 command_buffer_metrics::ContextType context_type, |
| 156 gpu::SurfaceHandle surface_handle, | 154 gpu::SurfaceHandle surface_handle, |
| 157 gpu::SharedMemoryLimits shared_memory_limits, | 155 gpu::SharedMemoryLimits shared_memory_limits, |
| 158 gpu::gles2::ContextCreationAttribHelper attributes, | 156 gpu::gles2::ContextCreationAttribHelper attributes, |
| 159 bool support_locking, | 157 bool support_locking, |
| 160 bool automatic_flushes, | 158 bool automatic_flushes, |
| 161 cc::ContextProvider* shared_context_provider, | 159 cc::ContextProvider* shared_context_provider, |
| 162 ContextProviderCallback result_callback) { | 160 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { |
| 163 DCHECK(!result_callback.is_null()); | 161 return make_scoped_refptr(new ContextProviderCommandBuffer( |
| 164 | 162 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, |
| 165 ContextProvidersRequest context_request; | 163 gpu::GpuStreamPriority::NORMAL, surface_handle, |
| 166 context_request.context_type = context_type; | 164 GURL(std::string("chrome://gpu/ContextProviderFactoryImpl::") + |
| 167 context_request.surface_handle = surface_handle; | 165 std::string("CompositorContextProvider")), |
| 168 context_request.shared_memory_limits = shared_memory_limits; | 166 automatic_flushes, support_locking, shared_memory_limits, attributes, |
| 169 context_request.attributes = attributes; | 167 static_cast<ContextProviderCommandBuffer*>(shared_context_provider), |
| 170 context_request.support_locking = support_locking; | 168 context_type)); |
| 171 context_request.automatic_flushes = automatic_flushes; | |
| 172 context_request.shared_context_provider = shared_context_provider; | |
| 173 context_request.result_callback = result_callback; | |
| 174 | |
| 175 context_provider_requests_.push_back(context_request); | |
| 176 | |
| 177 // If the channel is available, the factory will run the callback | |
| 178 // synchronously so we'll handle this request there. | |
| 179 EstablishGpuChannel(); | |
| 180 } | 169 } |
| 181 | 170 |
| 182 void ContextProviderFactoryImpl::HandlePendingRequests( | 171 void ContextProviderFactoryImpl::HandlePendingRequests( |
| 183 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 172 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| 184 ContextCreationResult result) { | 173 GpuChannelHostResult result) { |
| 185 DCHECK(!context_provider_requests_.empty()) | 174 DCHECK(!gpu_channel_requests_.empty()) |
| 186 << "We don't have any pending requests?"; | 175 << "We don't have any pending requests?"; |
| 176 DCHECK(gpu_channel_host || result != GpuChannelHostResult::SUCCESS); | |
| 187 | 177 |
| 188 // Failure to initialize the context could result in new requests. Handle | 178 // Failure to initialize the channel could result in new requests. Handle |
| 189 // them after going through the current list. | 179 // them after going through the current list. |
| 190 if (in_handle_pending_requests_) | 180 if (in_handle_pending_requests_) |
| 191 return; | 181 return; |
| 192 | 182 |
| 193 { | 183 { |
| 194 base::AutoReset<bool> auto_reset_in_handle_requests( | 184 base::AutoReset<bool> auto_reset_in_handle_requests( |
| 195 &in_handle_pending_requests_, true); | 185 &in_handle_pending_requests_, true); |
| 196 | 186 |
| 197 std::list<ContextProvidersRequest> context_requests = | 187 std::queue<GpuChannelHostCallback> gpu_channel_requests; |
|
danakj
2016/09/02 00:35:29
nitty-nit: i like when variables don't have the sa
Khushal
2016/09/02 16:26:47
Done.
| |
| 198 context_provider_requests_; | 188 gpu_channel_requests.swap(gpu_channel_requests_); |
| 199 context_provider_requests_.clear(); | |
| 200 | 189 |
| 201 for (ContextProvidersRequest& context_request : context_requests) { | 190 while (!gpu_channel_requests.empty()) { |
| 202 scoped_refptr<cc::ContextProvider> context_provider; | 191 gpu_channel_requests.front().Run(gpu_channel_host, result); |
| 203 ContextCreationResult result_to_report = result; | 192 gpu_channel_requests.pop(); |
| 204 | |
| 205 const bool create_onscreen_context = | |
| 206 context_request.surface_handle != gpu::kNullSurfaceHandle; | |
| 207 | |
| 208 // Is the request for an onscreen context? Make sure the surface is | |
| 209 // still valid in that case. | |
| 210 if (create_onscreen_context && | |
| 211 !GpuSurfaceTracker::GetInstance()->IsValidSurfaceHandle( | |
| 212 context_request.surface_handle)) { | |
| 213 // Choose what to report based on severity, factory shutdown trumps | |
| 214 // everything, otherwise report GpuSurfaceHandle loss. | |
| 215 result_to_report = | |
| 216 result_to_report == ContextCreationResult::FAILURE_FACTORY_SHUTDOWN | |
| 217 ? result_to_report | |
| 218 : ContextCreationResult::FAILURE_GPU_SURFACE_HANDLE_LOST; | |
| 219 } else if (gpu_channel_host) { | |
| 220 DCHECK_EQ(ContextCreationResult::SUCCESS, result); | |
| 221 | |
| 222 context_provider = new ContextProviderCommandBuffer( | |
| 223 gpu_channel_host, gpu::GPU_STREAM_DEFAULT, | |
| 224 gpu::GpuStreamPriority::NORMAL, context_request.surface_handle, | |
| 225 GURL(std::string("chrome://gpu/ContextProviderFactoryImpl::") + | |
| 226 std::string("CompositorContextProvider")), | |
| 227 context_request.automatic_flushes, context_request.support_locking, | |
| 228 context_request.shared_memory_limits, context_request.attributes, | |
| 229 static_cast<ContextProviderCommandBuffer*>( | |
| 230 context_request.shared_context_provider), | |
| 231 context_request.context_type); | |
| 232 } | |
| 233 | |
| 234 context_request.result_callback.Run(context_provider, result_to_report); | |
| 235 } | 193 } |
| 236 } | 194 } |
| 237 | 195 |
| 238 if (!context_provider_requests_.empty()) | 196 if (!gpu_channel_requests_.empty()) |
| 239 EstablishGpuChannel(); | 197 EstablishGpuChannel(); |
| 240 } | 198 } |
| 241 | 199 |
| 242 void ContextProviderFactoryImpl::EstablishGpuChannel() { | 200 void ContextProviderFactoryImpl::EstablishGpuChannel() { |
| 243 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ | 201 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ |
| 244 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION) | 202 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION) |
| 245 const int64_t kGpuChannelTimeoutInSeconds = 40; | 203 const int64_t kGpuChannelTimeoutInSeconds = 40; |
| 246 #else | 204 #else |
| 247 const int64_t kGpuChannelTimeoutInSeconds = 10; | 205 const int64_t kGpuChannelTimeoutInSeconds = 10; |
| 248 #endif | 206 #endif |
| 249 | 207 |
| 250 // Start the timer first, if the result comes synchronously, we want it to | 208 // Start the timer first, if the result comes synchronously, we want it to |
| 251 // stop in the callback. | 209 // stop in the callback. |
| 252 establish_gpu_channel_timeout_.Start( | 210 establish_gpu_channel_timeout_.Start( |
| 253 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds), | 211 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds), |
| 254 this, &ContextProviderFactoryImpl::OnGpuChannelTimeout); | 212 this, &ContextProviderFactoryImpl::OnGpuChannelTimeout); |
| 255 | 213 |
| 256 gpu_channel_factory_->EstablishGpuChannel( | 214 gpu_channel_factory_->EstablishGpuChannel( |
| 257 base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished, | 215 base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished, |
| 258 weak_factory_.GetWeakPtr())); | 216 weak_factory_.GetWeakPtr())); |
| 259 } | 217 } |
| 260 | 218 |
| 261 void ContextProviderFactoryImpl::OnGpuChannelEstablished( | 219 void ContextProviderFactoryImpl::OnGpuChannelEstablished( |
| 262 scoped_refptr<gpu::GpuChannelHost> gpu_channel) { | 220 scoped_refptr<gpu::GpuChannelHost> gpu_channel) { |
| 263 establish_gpu_channel_timeout_.Stop(); | 221 establish_gpu_channel_timeout_.Stop(); |
| 264 | 222 |
| 265 // We can queue the Gpu Channel initialization requests multiple times as | 223 // We can queue the Gpu Channel initialization requests multiple times as |
| 266 // we get context requests. So we might have already handled any pending | 224 // we get context requests. So we might have already handled any pending |
| 267 // requests when this callback runs. | 225 // requests when this callback runs. |
| 268 if (context_provider_requests_.empty()) | 226 if (gpu_channel_requests_.empty()) |
| 269 return; | 227 return; |
| 270 | 228 |
| 271 if (gpu_channel) { | 229 if (gpu_channel) { |
| 272 HandlePendingRequests(std::move(gpu_channel), | 230 HandlePendingRequests(std::move(gpu_channel), |
| 273 ContextCreationResult::SUCCESS); | 231 GpuChannelHostResult::SUCCESS); |
| 274 } else { | 232 } else { |
| 275 HandlePendingRequests( | 233 HandlePendingRequests( |
| 276 nullptr, | 234 nullptr, |
| 277 ContextCreationResult::FAILURE_GPU_PROCESS_INITIALIZATION_FAILED); | 235 GpuChannelHostResult::FAILURE_GPU_PROCESS_INITIALIZATION_FAILED); |
| 278 } | 236 } |
| 279 } | 237 } |
| 280 | 238 |
| 281 void ContextProviderFactoryImpl::OnGpuChannelTimeout() { | 239 void ContextProviderFactoryImpl::OnGpuChannelTimeout() { |
| 282 LOG(FATAL) << "Timed out waiting for GPU channel."; | 240 LOG(FATAL) << "Timed out waiting for GPU channel."; |
| 283 } | 241 } |
| 284 | 242 |
| 285 } // namespace content | 243 } // namespace content |
| OLD | NEW |