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