| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } else if (share_resources) { | 113 } else if (share_resources) { |
| 114 share_group_ = GetDefaultShareGroupForHost(host); | 114 share_group_ = GetDefaultShareGroupForHost(host); |
| 115 } else { | 115 } else { |
| 116 share_group_ = make_scoped_refptr(new ShareGroup); | 116 share_group_ = make_scoped_refptr(new ShareGroup); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 WebGraphicsContext3DCommandBufferImpl:: | 120 WebGraphicsContext3DCommandBufferImpl:: |
| 121 ~WebGraphicsContext3DCommandBufferImpl() { | 121 ~WebGraphicsContext3DCommandBufferImpl() { |
| 122 if (real_gl_) { | 122 if (real_gl_) { |
| 123 real_gl_->SetErrorMessageCallback(NULL); | 123 real_gl_->SetErrorMessageCallback( |
| 124 base::Callback<void(const char*, int32_t)>()); |
| 125 real_gl_->SetLostContextCallback(base::Closure()); |
| 124 } | 126 } |
| 125 | 127 |
| 126 Destroy(); | 128 Destroy(); |
| 127 } | 129 } |
| 128 | 130 |
| 129 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() { | 131 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() { |
| 130 if (initialized_) | 132 if (initialized_) |
| 131 return true; | 133 return true; |
| 132 | 134 |
| 133 if (initialize_failed_) | 135 if (initialize_failed_) |
| 134 return false; | 136 return false; |
| 135 | 137 |
| 136 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); | 138 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL"); |
| 137 | 139 |
| 138 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. | 140 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. |
| 139 tracked_objects::ScopedTracker tracking_profile( | 141 tracked_objects::ScopedTracker tracking_profile( |
| 140 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 142 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 141 "125248 WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL")); | 143 "125248 WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL")); |
| 142 | 144 |
| 143 if (!CreateContext()) { | 145 if (!CreateContext()) { |
| 144 Destroy(); | 146 Destroy(); |
| 145 | 147 |
| 146 initialize_failed_ = true; | 148 initialize_failed_ = true; |
| 147 return false; | 149 return false; |
| 148 } | 150 } |
| 149 | 151 |
| 150 command_buffer_->SetContextLostCallback( | 152 real_gl_->SetErrorMessageCallback( |
| 153 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnErrorMessage, |
| 154 // The callback is unset in the destructor. |
| 155 base::Unretained(this))); |
| 156 real_gl_->SetLostContextCallback( |
| 151 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnContextLost, | 157 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnContextLost, |
| 152 weak_ptr_factory_.GetWeakPtr())); | 158 // The callback is unset in the destructor. |
| 159 base::Unretained(this))); |
| 153 | 160 |
| 154 command_buffer_->SetOnConsoleMessageCallback( | |
| 155 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnErrorMessage, | |
| 156 weak_ptr_factory_.GetWeakPtr())); | |
| 157 | |
| 158 real_gl_->SetErrorMessageCallback(getErrorMessageCallback()); | |
| 159 real_gl_->TraceBeginCHROMIUM("WebGraphicsContext3D", | 161 real_gl_->TraceBeginCHROMIUM("WebGraphicsContext3D", |
| 160 "CommandBufferContext"); | 162 "CommandBufferContext"); |
| 161 | 163 |
| 162 initialized_ = true; | 164 initialized_ = true; |
| 163 return true; | 165 return true; |
| 164 } | 166 } |
| 165 | 167 |
| 166 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer( | 168 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer( |
| 167 WebGraphicsContext3DCommandBufferImpl* share_context) { | 169 WebGraphicsContext3DCommandBufferImpl* share_context) { |
| 168 if (!host_.get()) | 170 if (!host_.get()) |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 DCHECK(host_.get()); | 357 DCHECK(host_.get()); |
| 356 { | 358 { |
| 357 base::AutoLock lock(g_default_share_groups_lock.Get()); | 359 base::AutoLock lock(g_default_share_groups_lock.Get()); |
| 358 g_default_share_groups.Get().erase(host_.get()); | 360 g_default_share_groups.Get().erase(host_.get()); |
| 359 } | 361 } |
| 360 | 362 |
| 361 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 363 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
| 362 UmaRecordContextLost(context_type_, state.error, state.context_lost_reason); | 364 UmaRecordContextLost(context_type_, state.error, state.context_lost_reason); |
| 363 } | 365 } |
| 364 | 366 |
| 367 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage(const char* message, |
| 368 int id) { |
| 369 if (error_message_callback_) { |
| 370 blink::WebString str = blink::WebString::fromUTF8(message); |
| 371 error_message_callback_->onErrorMessage(str, id); |
| 372 } |
| 373 } |
| 374 |
| 365 } // namespace content | 375 } // namespace content |
| OLD | NEW |