| 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 "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 5 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "third_party/khronos/GLES2/gl2.h" |
| 8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
| 9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
| 10 #endif | 10 #endif |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 const Attributes& attributes, | 90 const Attributes& attributes, |
| 91 bool lose_context_when_out_of_memory, | 91 bool lose_context_when_out_of_memory, |
| 92 const SharedMemoryLimits& limits, | 92 const SharedMemoryLimits& limits, |
| 93 WebGraphicsContext3DCommandBufferImpl* share_context) | 93 WebGraphicsContext3DCommandBufferImpl* share_context) |
| 94 : lose_context_when_out_of_memory_(lose_context_when_out_of_memory), | 94 : lose_context_when_out_of_memory_(lose_context_when_out_of_memory), |
| 95 attributes_(attributes), | 95 attributes_(attributes), |
| 96 visible_(false), | 96 visible_(false), |
| 97 host_(host), | 97 host_(host), |
| 98 surface_id_(surface_id), | 98 surface_id_(surface_id), |
| 99 active_url_(active_url), | 99 active_url_(active_url), |
| 100 context_type_(CONTEXT_TYPE_UNKNOWN), |
| 100 gpu_preference_(attributes.preferDiscreteGPU ? gfx::PreferDiscreteGpu | 101 gpu_preference_(attributes.preferDiscreteGPU ? gfx::PreferDiscreteGpu |
| 101 : gfx::PreferIntegratedGpu), | 102 : gfx::PreferIntegratedGpu), |
| 102 mem_limits_(limits), | 103 mem_limits_(limits), |
| 103 weak_ptr_factory_(this) { | 104 weak_ptr_factory_(this) { |
| 105 if (attributes_.webGL) |
| 106 context_type_ = OFFSCREEN_CONTEXT_FOR_WEBGL; |
| 104 if (share_context) { | 107 if (share_context) { |
| 105 DCHECK(!attributes_.shareResources); | 108 DCHECK(!attributes_.shareResources); |
| 106 share_group_ = share_context->share_group_; | 109 share_group_ = share_context->share_group_; |
| 107 } else { | 110 } else { |
| 108 share_group_ = attributes_.shareResources | 111 share_group_ = attributes_.shareResources |
| 109 ? GetDefaultShareGroupForHost(host) | 112 ? GetDefaultShareGroupForHost(host) |
| 110 : scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>( | 113 : scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>( |
| 111 new ShareGroup()); | 114 new ShareGroup()); |
| 112 } | 115 } |
| 113 } | 116 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 138 if (!CreateContext(surface_id_ != 0)) { | 141 if (!CreateContext(surface_id_ != 0)) { |
| 139 Destroy(); | 142 Destroy(); |
| 140 | 143 |
| 141 initialize_failed_ = true; | 144 initialize_failed_ = true; |
| 142 return false; | 145 return false; |
| 143 } | 146 } |
| 144 | 147 |
| 145 if (gl_ && attributes_.webGL) | 148 if (gl_ && attributes_.webGL) |
| 146 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); | 149 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); |
| 147 | 150 |
| 148 command_buffer_->SetChannelErrorCallback( | 151 command_buffer_->SetContextLostCallback( |
| 149 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnGpuChannelLost, | 152 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnContextLost, |
| 150 weak_ptr_factory_.GetWeakPtr())); | 153 weak_ptr_factory_.GetWeakPtr())); |
| 151 | 154 |
| 152 command_buffer_->SetOnConsoleMessageCallback( | 155 command_buffer_->SetOnConsoleMessageCallback( |
| 153 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnErrorMessage, | 156 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnErrorMessage, |
| 154 weak_ptr_factory_.GetWeakPtr())); | 157 weak_ptr_factory_.GetWeakPtr())); |
| 155 | 158 |
| 156 real_gl_->SetErrorMessageCallback(getErrorMessageCallback()); | 159 real_gl_->SetErrorMessageCallback(getErrorMessageCallback()); |
| 157 | 160 |
| 158 visible_ = true; | 161 visible_ = true; |
| 159 initialized_ = true; | 162 initialized_ = true; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 command_buffer_.reset(host_->CreateOffscreenCommandBuffer( | 194 command_buffer_.reset(host_->CreateOffscreenCommandBuffer( |
| 192 gfx::Size(1, 1), | 195 gfx::Size(1, 1), |
| 193 share_group_command_buffer, | 196 share_group_command_buffer, |
| 194 attribs, | 197 attribs, |
| 195 active_url_, | 198 active_url_, |
| 196 gpu_preference_)); | 199 gpu_preference_)); |
| 197 } | 200 } |
| 198 | 201 |
| 199 if (!command_buffer_) { | 202 if (!command_buffer_) { |
| 200 DLOG(ERROR) << "GpuChannelHost failed to create command buffer."; | 203 DLOG(ERROR) << "GpuChannelHost failed to create command buffer."; |
| 204 UmaRecordContextInitFailed(context_type_); |
| 201 return false; | 205 return false; |
| 202 } | 206 } |
| 203 | 207 |
| 204 DVLOG_IF(1, gpu::error::IsError(command_buffer_->GetLastError())) | 208 DVLOG_IF(1, gpu::error::IsError(command_buffer_->GetLastError())) |
| 205 << "Context dead on arrival. Last error: " | 209 << "Context dead on arrival. Last error: " |
| 206 << command_buffer_->GetLastError(); | 210 << command_buffer_->GetLastError(); |
| 207 // Initialize the command buffer. | 211 // Initialize the command buffer. |
| 208 bool result = command_buffer_->Initialize(); | 212 bool result = command_buffer_->Initialize(); |
| 209 LOG_IF(ERROR, !result) << "CommandBufferProxy::Initialize failed."; | 213 LOG_IF(ERROR, !result) << "CommandBufferProxy::Initialize failed."; |
| 214 if (!result) |
| 215 UmaRecordContextInitFailed(context_type_); |
| 210 return result; | 216 return result; |
| 211 } | 217 } |
| 212 | 218 |
| 213 bool WebGraphicsContext3DCommandBufferImpl::CreateContext(bool onscreen) { | 219 bool WebGraphicsContext3DCommandBufferImpl::CreateContext(bool onscreen) { |
| 214 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::CreateContext"); | 220 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::CreateContext"); |
| 215 scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group; | 221 scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group; |
| 216 | 222 |
| 217 scoped_ptr<base::AutoLock> share_group_lock; | 223 scoped_ptr<base::AutoLock> share_group_lock; |
| 218 bool add_to_share_group = false; | 224 bool add_to_share_group = false; |
| 219 if (!command_buffer_) { | 225 if (!command_buffer_) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 350 |
| 345 return context_lost_reason_; | 351 return context_lost_reason_; |
| 346 } | 352 } |
| 347 | 353 |
| 348 bool WebGraphicsContext3DCommandBufferImpl::IsCommandBufferContextLost() { | 354 bool WebGraphicsContext3DCommandBufferImpl::IsCommandBufferContextLost() { |
| 349 // If the channel shut down unexpectedly, let that supersede the | 355 // If the channel shut down unexpectedly, let that supersede the |
| 350 // command buffer's state. | 356 // command buffer's state. |
| 351 if (host_.get() && host_->IsLost()) | 357 if (host_.get() && host_->IsLost()) |
| 352 return true; | 358 return true; |
| 353 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 359 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
| 354 return state.error == gpu::error::kLostContext; | 360 return gpu::error::IsError(state.error); |
| 355 } | 361 } |
| 356 | 362 |
| 357 // static | 363 // static |
| 358 WebGraphicsContext3DCommandBufferImpl* | 364 WebGraphicsContext3DCommandBufferImpl* |
| 359 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | 365 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( |
| 360 GpuChannelHost* host, | 366 GpuChannelHost* host, |
| 361 const WebGraphicsContext3D::Attributes& attributes, | 367 const WebGraphicsContext3D::Attributes& attributes, |
| 362 bool lose_context_when_out_of_memory, | 368 bool lose_context_when_out_of_memory, |
| 363 const GURL& active_url, | 369 const GURL& active_url, |
| 364 const SharedMemoryLimits& limits, | 370 const SharedMemoryLimits& limits, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 380 } | 386 } |
| 381 | 387 |
| 382 namespace { | 388 namespace { |
| 383 | 389 |
| 384 WGC3Denum convertReason(gpu::error::ContextLostReason reason) { | 390 WGC3Denum convertReason(gpu::error::ContextLostReason reason) { |
| 385 switch (reason) { | 391 switch (reason) { |
| 386 case gpu::error::kGuilty: | 392 case gpu::error::kGuilty: |
| 387 return GL_GUILTY_CONTEXT_RESET_ARB; | 393 return GL_GUILTY_CONTEXT_RESET_ARB; |
| 388 case gpu::error::kInnocent: | 394 case gpu::error::kInnocent: |
| 389 return GL_INNOCENT_CONTEXT_RESET_ARB; | 395 return GL_INNOCENT_CONTEXT_RESET_ARB; |
| 396 case gpu::error::kOutOfMemory: |
| 397 case gpu::error::kMakeCurrentFailed: |
| 390 case gpu::error::kUnknown: | 398 case gpu::error::kUnknown: |
| 391 return GL_UNKNOWN_CONTEXT_RESET_ARB; | 399 return GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 392 } | 400 } |
| 393 | 401 |
| 394 NOTREACHED(); | 402 NOTREACHED(); |
| 395 return GL_UNKNOWN_CONTEXT_RESET_ARB; | 403 return GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 396 } | 404 } |
| 397 | 405 |
| 398 } // anonymous namespace | 406 } // anonymous namespace |
| 399 | 407 |
| 400 void WebGraphicsContext3DCommandBufferImpl::OnGpuChannelLost() { | 408 void WebGraphicsContext3DCommandBufferImpl::OnContextLost() { |
| 401 context_lost_reason_ = convertReason( | 409 context_lost_reason_ = |
| 402 command_buffer_->GetLastState().context_lost_reason); | 410 convertReason(command_buffer_->GetLastState().context_lost_reason); |
| 403 if (context_lost_callback_) { | 411 if (context_lost_callback_) { |
| 404 context_lost_callback_->onContextLost(); | 412 context_lost_callback_->onContextLost(); |
| 405 } | 413 } |
| 406 | 414 |
| 407 share_group_->RemoveAllContexts(); | 415 share_group_->RemoveAllContexts(); |
| 408 | 416 |
| 409 DCHECK(host_.get()); | 417 DCHECK(host_.get()); |
| 410 { | 418 { |
| 411 base::AutoLock lock(g_default_share_groups_lock.Get()); | 419 base::AutoLock lock(g_default_share_groups_lock.Get()); |
| 412 g_default_share_groups.Get().erase(host_.get()); | 420 g_default_share_groups.Get().erase(host_.get()); |
| 413 } | 421 } |
| 422 |
| 423 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
| 424 UmaRecordContextLost(context_type_, state.error, state.context_lost_reason); |
| 414 } | 425 } |
| 415 | 426 |
| 416 } // namespace content | 427 } // namespace content |
| OLD | NEW |