| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 share_group_ = attributes_.shareResources | 105 share_group_ = attributes_.shareResources |
| 106 ? GetDefaultShareGroupForHost(host) | 106 ? GetDefaultShareGroupForHost(host) |
| 107 : scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>( | 107 : scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>( |
| 108 new ShareGroup()); | 108 new ShareGroup()); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 WebGraphicsContext3DCommandBufferImpl:: | 112 WebGraphicsContext3DCommandBufferImpl:: |
| 113 ~WebGraphicsContext3DCommandBufferImpl() { | 113 ~WebGraphicsContext3DCommandBufferImpl() { |
| 114 if (real_gl_) { | 114 if (real_gl_) { |
| 115 real_gl_->SetErrorMessageCallback(NULL); | 115 real_gl_->SetErrorMessageCallback(nullptr); |
| 116 } | 116 } |
| 117 | 117 |
| 118 Destroy(); | 118 Destroy(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() { | 121 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() { |
| 122 if (initialized_) | 122 if (initialized_) |
| 123 return true; | 123 return true; |
| 124 | 124 |
| 125 if (initialize_failed_) | 125 if (initialize_failed_) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 149 visible_ = true; | 149 visible_ = true; |
| 150 initialized_ = true; | 150 initialized_ = true; |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer( | 154 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer( |
| 155 bool onscreen, WebGraphicsContext3DCommandBufferImpl* share_context) { | 155 bool onscreen, WebGraphicsContext3DCommandBufferImpl* share_context) { |
| 156 if (!host_.get()) | 156 if (!host_.get()) |
| 157 return false; | 157 return false; |
| 158 | 158 |
| 159 CommandBufferProxyImpl* share_group_command_buffer = NULL; | 159 CommandBufferProxyImpl* share_group_command_buffer = nullptr; |
| 160 | 160 |
| 161 if (share_context) { | 161 if (share_context) { |
| 162 share_group_command_buffer = share_context->command_buffer_.get(); | 162 share_group_command_buffer = share_context->command_buffer_.get(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 ::gpu::gles2::ContextCreationAttribHelper attribs_for_gles2; | 165 ::gpu::gles2::ContextCreationAttribHelper attribs_for_gles2; |
| 166 ConvertAttributes(attributes_, &attribs_for_gles2); | 166 ConvertAttributes(attributes_, &attribs_for_gles2); |
| 167 attribs_for_gles2.lose_context_when_out_of_memory = | 167 attribs_for_gles2.lose_context_when_out_of_memory = |
| 168 lose_context_when_out_of_memory_; | 168 lose_context_when_out_of_memory_; |
| 169 DCHECK(attribs_for_gles2.buffer_preserved); | 169 DCHECK(attribs_for_gles2.buffer_preserved); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return result; | 201 return result; |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool WebGraphicsContext3DCommandBufferImpl::CreateContext(bool onscreen) { | 204 bool WebGraphicsContext3DCommandBufferImpl::CreateContext(bool onscreen) { |
| 205 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::CreateContext"); | 205 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::CreateContext"); |
| 206 scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group; | 206 scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group; |
| 207 | 207 |
| 208 scoped_ptr<base::AutoLock> share_group_lock; | 208 scoped_ptr<base::AutoLock> share_group_lock; |
| 209 bool add_to_share_group = false; | 209 bool add_to_share_group = false; |
| 210 if (!command_buffer_) { | 210 if (!command_buffer_) { |
| 211 WebGraphicsContext3DCommandBufferImpl* share_context = NULL; | 211 WebGraphicsContext3DCommandBufferImpl* share_context = nullptr; |
| 212 | 212 |
| 213 share_group_lock.reset(new base::AutoLock(share_group_->lock())); | 213 share_group_lock.reset(new base::AutoLock(share_group_->lock())); |
| 214 share_context = share_group_->GetAnyContextLocked(); | 214 share_context = share_group_->GetAnyContextLocked(); |
| 215 | 215 |
| 216 if (!InitializeCommandBuffer(onscreen, share_context)) { | 216 if (!InitializeCommandBuffer(onscreen, share_context)) { |
| 217 LOG(ERROR) << "Failed to initialize command buffer."; | 217 LOG(ERROR) << "Failed to initialize command buffer."; |
| 218 return false; | 218 return false; |
| 219 } | 219 } |
| 220 | 220 |
| 221 if (share_context) | 221 if (share_context) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 share_group_->RemoveContext(this); | 288 share_group_->RemoveContext(this); |
| 289 | 289 |
| 290 gpu::gles2::GLES2Interface* gl = GetGLInterface(); | 290 gpu::gles2::GLES2Interface* gl = GetGLInterface(); |
| 291 if (gl) { | 291 if (gl) { |
| 292 // First flush the context to ensure that any pending frees of resources | 292 // First flush the context to ensure that any pending frees of resources |
| 293 // are completed. Otherwise, if this context is part of a share group, | 293 // are completed. Otherwise, if this context is part of a share group, |
| 294 // those resources might leak. Also, any remaining side effects of commands | 294 // those resources might leak. Also, any remaining side effects of commands |
| 295 // issued on this context might not be visible to other contexts in the | 295 // issued on this context might not be visible to other contexts in the |
| 296 // share group. | 296 // share group. |
| 297 gl->Flush(); | 297 gl->Flush(); |
| 298 setGLInterface(NULL); | 298 setGLInterface(nullptr); |
| 299 } | 299 } |
| 300 | 300 |
| 301 trace_gl_.reset(); | 301 trace_gl_.reset(); |
| 302 real_gl_.reset(); | 302 real_gl_.reset(); |
| 303 transfer_buffer_.reset(); | 303 transfer_buffer_.reset(); |
| 304 gles2_helper_.reset(); | 304 gles2_helper_.reset(); |
| 305 real_gl_.reset(); | 305 real_gl_.reset(); |
| 306 | 306 |
| 307 if (command_buffer_) { | 307 if (command_buffer_) { |
| 308 if (host_.get()) | 308 if (host_.get()) |
| 309 host_->DestroyCommandBuffer(command_buffer_.release()); | 309 host_->DestroyCommandBuffer(command_buffer_.release()); |
| 310 command_buffer_.reset(); | 310 command_buffer_.reset(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 host_ = NULL; | 313 host_ = nullptr; |
| 314 } | 314 } |
| 315 | 315 |
| 316 gpu::ContextSupport* | 316 gpu::ContextSupport* |
| 317 WebGraphicsContext3DCommandBufferImpl::GetContextSupport() { | 317 WebGraphicsContext3DCommandBufferImpl::GetContextSupport() { |
| 318 return real_gl_.get(); | 318 return real_gl_.get(); |
| 319 } | 319 } |
| 320 | 320 |
| 321 bool WebGraphicsContext3DCommandBufferImpl::isContextLost() { | 321 bool WebGraphicsContext3DCommandBufferImpl::isContextLost() { |
| 322 return initialize_failed_ || | 322 return initialize_failed_ || |
| 323 (command_buffer_ && IsCommandBufferContextLost()) || | 323 (command_buffer_ && IsCommandBufferContextLost()) || |
| (...skipping 21 matching lines...) Expand all Loading... |
| 345 // static | 345 // static |
| 346 WebGraphicsContext3DCommandBufferImpl* | 346 WebGraphicsContext3DCommandBufferImpl* |
| 347 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | 347 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( |
| 348 GpuChannelHost* host, | 348 GpuChannelHost* host, |
| 349 const WebGraphicsContext3D::Attributes& attributes, | 349 const WebGraphicsContext3D::Attributes& attributes, |
| 350 bool lose_context_when_out_of_memory, | 350 bool lose_context_when_out_of_memory, |
| 351 const GURL& active_url, | 351 const GURL& active_url, |
| 352 const SharedMemoryLimits& limits, | 352 const SharedMemoryLimits& limits, |
| 353 WebGraphicsContext3DCommandBufferImpl* share_context) { | 353 WebGraphicsContext3DCommandBufferImpl* share_context) { |
| 354 if (!host) | 354 if (!host) |
| 355 return NULL; | 355 return nullptr; |
| 356 | 356 |
| 357 if (share_context && share_context->IsCommandBufferContextLost()) | 357 if (share_context && share_context->IsCommandBufferContextLost()) |
| 358 return NULL; | 358 return nullptr; |
| 359 | 359 |
| 360 return new WebGraphicsContext3DCommandBufferImpl( | 360 return new WebGraphicsContext3DCommandBufferImpl( |
| 361 0, | 361 0, |
| 362 active_url, | 362 active_url, |
| 363 host, | 363 host, |
| 364 attributes, | 364 attributes, |
| 365 lose_context_when_out_of_memory, | 365 lose_context_when_out_of_memory, |
| 366 limits, | 366 limits, |
| 367 share_context); | 367 share_context); |
| 368 } | 368 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 395 share_group_->RemoveAllContexts(); | 395 share_group_->RemoveAllContexts(); |
| 396 | 396 |
| 397 DCHECK(host_.get()); | 397 DCHECK(host_.get()); |
| 398 { | 398 { |
| 399 base::AutoLock lock(g_default_share_groups_lock.Get()); | 399 base::AutoLock lock(g_default_share_groups_lock.Get()); |
| 400 g_default_share_groups.Get().erase(host_.get()); | 400 g_default_share_groups.Get().erase(host_.get()); |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 | 403 |
| 404 } // namespace content | 404 } // namespace content |
| OLD | NEW |