| 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 "gpu/command_buffer/client/gl_in_process_context.h" | 5 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 private: | 72 private: |
| 73 void Destroy(); | 73 void Destroy(); |
| 74 void OnContextLost(); | 74 void OnContextLost(); |
| 75 void OnSignalSyncPoint(const base::Closure& callback); | 75 void OnSignalSyncPoint(const base::Closure& callback); |
| 76 | 76 |
| 77 scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_; | 77 scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_; |
| 78 scoped_ptr<TransferBuffer> transfer_buffer_; | 78 scoped_ptr<TransferBuffer> transfer_buffer_; |
| 79 scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; | 79 scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; |
| 80 scoped_ptr<InProcessCommandBuffer> command_buffer_; | 80 scoped_ptr<InProcessCommandBuffer> command_buffer_; |
| 81 | 81 |
| 82 unsigned int share_group_id_; | |
| 83 bool context_lost_; | 82 bool context_lost_; |
| 84 base::Closure context_lost_callback_; | 83 base::Closure context_lost_callback_; |
| 85 | 84 |
| 86 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl); | 85 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl); |
| 87 }; | 86 }; |
| 88 | 87 |
| 89 base::LazyInstance<base::Lock> g_all_shared_contexts_lock = | 88 base::LazyInstance<base::Lock> g_all_shared_contexts_lock = |
| 90 LAZY_INSTANCE_INITIALIZER; | 89 LAZY_INSTANCE_INITIALIZER; |
| 91 base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts = | 90 base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts = |
| 92 LAZY_INSTANCE_INITIALIZER; | 91 LAZY_INSTANCE_INITIALIZER; |
| 93 | 92 |
| 94 GLInProcessContextImpl::GLInProcessContextImpl() | 93 GLInProcessContextImpl::GLInProcessContextImpl() |
| 95 : share_group_id_(0), context_lost_(false) {} | 94 : context_lost_(false) {} |
| 96 | 95 |
| 97 GLInProcessContextImpl::~GLInProcessContextImpl() { | 96 GLInProcessContextImpl::~GLInProcessContextImpl() { |
| 98 { | 97 { |
| 99 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 98 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 100 g_all_shared_contexts.Get().erase(this); | 99 g_all_shared_contexts.Get().erase(this); |
| 101 } | 100 } |
| 102 Destroy(); | 101 Destroy(); |
| 103 } | 102 } |
| 104 | 103 |
| 105 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { | 104 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 attrib_vector.push_back(attribs.fail_if_major_perf_caveat); | 181 attrib_vector.push_back(attribs.fail_if_major_perf_caveat); |
| 183 } | 182 } |
| 184 attrib_vector.push_back(NONE); | 183 attrib_vector.push_back(NONE); |
| 185 | 184 |
| 186 base::Closure wrapped_callback = | 185 base::Closure wrapped_callback = |
| 187 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr()); | 186 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr()); |
| 188 command_buffer_.reset(new InProcessCommandBuffer()); | 187 command_buffer_.reset(new InProcessCommandBuffer()); |
| 189 | 188 |
| 190 scoped_ptr<base::AutoLock> scoped_shared_context_lock; | 189 scoped_ptr<base::AutoLock> scoped_shared_context_lock; |
| 191 scoped_refptr<gles2::ShareGroup> share_group; | 190 scoped_refptr<gles2::ShareGroup> share_group; |
| 191 InProcessCommandBuffer* share_command_buffer = NULL; |
| 192 if (share_resources) { | 192 if (share_resources) { |
| 193 scoped_shared_context_lock.reset( | 193 scoped_shared_context_lock.reset( |
| 194 new base::AutoLock(g_all_shared_contexts_lock.Get())); | 194 new base::AutoLock(g_all_shared_contexts_lock.Get())); |
| 195 for (std::set<GLInProcessContextImpl*>::const_iterator it = | 195 for (std::set<GLInProcessContextImpl*>::const_iterator it = |
| 196 g_all_shared_contexts.Get().begin(); | 196 g_all_shared_contexts.Get().begin(); |
| 197 it != g_all_shared_contexts.Get().end(); | 197 it != g_all_shared_contexts.Get().end(); |
| 198 it++) { | 198 it++) { |
| 199 const GLInProcessContextImpl* context = *it; | 199 const GLInProcessContextImpl* context = *it; |
| 200 if (!context->context_lost_) { | 200 if (!context->context_lost_) { |
| 201 share_group = context->gles2_implementation_->share_group(); | 201 share_group = context->gles2_implementation_->share_group(); |
| 202 share_command_buffer = context->command_buffer_.get(); |
| 202 DCHECK(share_group); | 203 DCHECK(share_group); |
| 203 share_group_id_ = context->share_group_id_; | 204 DCHECK(share_command_buffer); |
| 204 break; | 205 break; |
| 205 } | 206 } |
| 206 share_group_id_ = std::max(share_group_id_, context->share_group_id_); | |
| 207 } | 207 } |
| 208 if (!share_group && !++share_group_id_) | |
| 209 ++share_group_id_; | |
| 210 } | 208 } |
| 211 if (!command_buffer_->Initialize(surface, | 209 if (!command_buffer_->Initialize(surface, |
| 212 is_offscreen, | 210 is_offscreen, |
| 213 share_resources, | |
| 214 window, | 211 window, |
| 215 size, | 212 size, |
| 216 attrib_vector, | 213 attrib_vector, |
| 217 gpu_preference, | 214 gpu_preference, |
| 218 wrapped_callback, | 215 wrapped_callback, |
| 219 share_group_id_)) { | 216 share_command_buffer)) { |
| 220 LOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; | 217 LOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; |
| 221 return false; | 218 return false; |
| 222 } | 219 } |
| 223 | 220 |
| 224 // Create the GLES2 helper, which writes the command buffer protocol. | 221 // Create the GLES2 helper, which writes the command buffer protocol. |
| 225 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); | 222 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); |
| 226 if (!gles2_helper_->Initialize(kCommandBufferSize)) { | 223 if (!gles2_helper_->Initialize(kCommandBufferSize)) { |
| 227 LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; | 224 LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; |
| 228 Destroy(); | 225 Destroy(); |
| 229 return false; | 226 return false; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 gfx::kNullAcceleratedWidget, | 331 gfx::kNullAcceleratedWidget, |
| 335 surface->GetSize(), | 332 surface->GetSize(), |
| 336 attribs, | 333 attribs, |
| 337 gpu_preference)) | 334 gpu_preference)) |
| 338 return NULL; | 335 return NULL; |
| 339 | 336 |
| 340 return context.release(); | 337 return context.release(); |
| 341 } | 338 } |
| 342 | 339 |
| 343 } // namespace gpu | 340 } // namespace gpu |
| OLD | NEW |