Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/context_provider_command_buffer.h" | 5 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 | 102 |
| 103 std::string unique_context_name = | 103 std::string unique_context_name = |
| 104 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get()); | 104 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get()); |
| 105 context3d_->traceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str()); | 105 context3d_->traceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str()); |
| 106 | 106 |
| 107 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); | 107 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); |
| 108 return true; | 108 return true; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void ContextProviderCommandBuffer::DetachFromThread() { | 111 void ContextProviderCommandBuffer::DetachFromThread() { |
| 112 DCHECK(context3d_); | |
| 113 // Invalidate any weak pointers used by the context3d_ to ensure that it's | |
| 114 // safe to use and destroy it on a different thread. There's no guarantee | |
| 115 // that callbacks such as ContextLost will be delivered after this has been | |
|
danakj
2015/09/03 18:09:58
Can you add this to the ContextProvider::DetachFro
| |
| 116 // called. | |
| 117 context3d_->InvalidateWeakPtrsOnCurrentThread(); | |
| 112 context_thread_checker_.DetachFromThread(); | 118 context_thread_checker_.DetachFromThread(); |
| 113 } | 119 } |
| 114 | 120 |
| 115 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() { | 121 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() { |
| 116 DCHECK(context3d_); | 122 DCHECK(context3d_); |
| 117 DCHECK(lost_context_callback_proxy_); // Is bound to thread. | 123 DCHECK(lost_context_callback_proxy_); // Is bound to thread. |
| 118 DCHECK(context_thread_checker_.CalledOnValidThread()); | 124 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 119 | 125 |
| 120 return context3d_->GetImplementation(); | 126 return context3d_->GetImplementation(); |
| 121 } | 127 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 } | 181 } |
| 176 | 182 |
| 177 void ContextProviderCommandBuffer::DeleteCachedResources() { | 183 void ContextProviderCommandBuffer::DeleteCachedResources() { |
| 178 DCHECK(context_thread_checker_.CalledOnValidThread()); | 184 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 179 | 185 |
| 180 if (gr_context_) | 186 if (gr_context_) |
| 181 gr_context_->FreeGpuResources(); | 187 gr_context_->FreeGpuResources(); |
| 182 } | 188 } |
| 183 | 189 |
| 184 void ContextProviderCommandBuffer::OnLostContext() { | 190 void ContextProviderCommandBuffer::OnLostContext() { |
| 185 DCHECK(context_thread_checker_.CalledOnValidThread()); | 191 // Note: no thread check here as this should not change the thread for which |
| 192 // this context is currently bound. e.g. a worker context might be unbound | |
| 193 // and this should not result in it being bound to the current thread. | |
| 186 { | 194 { |
| 187 base::AutoLock lock(main_thread_lock_); | 195 base::AutoLock lock(main_thread_lock_); |
| 188 if (destroyed_) | 196 if (destroyed_) |
| 189 return; | 197 return; |
| 190 destroyed_ = true; | 198 destroyed_ = true; |
| 191 } | 199 } |
| 192 if (!lost_context_callback_.is_null()) | 200 if (!lost_context_callback_.is_null()) |
| 193 base::ResetAndReturn(&lost_context_callback_).Run(); | 201 base::ResetAndReturn(&lost_context_callback_).Run(); |
| 194 if (gr_context_) | 202 if (gr_context_) |
| 195 gr_context_->OnLostContext(); | 203 gr_context_->OnLostContext(); |
| 196 } | 204 } |
| 197 | 205 |
| 198 void ContextProviderCommandBuffer::OnMemoryAllocationChanged( | 206 void ContextProviderCommandBuffer::OnMemoryAllocationChanged( |
| 199 const gpu::MemoryAllocation& allocation) { | 207 const gpu::MemoryAllocation& allocation) { |
| 200 DCHECK(context_thread_checker_.CalledOnValidThread()); | 208 // Note: no thread check here as this should not change the thread for which |
| 201 | 209 // this context is currently bound. e.g. a worker context might be unbound |
| 210 // and this should not result in it being bound to the current thread. | |
| 202 if (memory_policy_changed_callback_.is_null()) | 211 if (memory_policy_changed_callback_.is_null()) |
| 203 return; | 212 return; |
| 204 | 213 |
| 205 memory_policy_changed_callback_.Run(cc::ManagedMemoryPolicy(allocation)); | 214 memory_policy_changed_callback_.Run(cc::ManagedMemoryPolicy(allocation)); |
| 206 } | 215 } |
| 207 | 216 |
| 208 void ContextProviderCommandBuffer::InitializeCapabilities() { | 217 void ContextProviderCommandBuffer::InitializeCapabilities() { |
| 209 Capabilities caps; | 218 Capabilities caps; |
| 210 caps.gpu = context3d_->GetImplementation()->capabilities(); | 219 caps.gpu = context3d_->GetImplementation()->capabilities(); |
| 211 | 220 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 241 | 250 |
| 242 if (!memory_policy_changed_callback_.is_null()) { | 251 if (!memory_policy_changed_callback_.is_null()) { |
| 243 DCHECK(context3d_->GetCommandBufferProxy()); | 252 DCHECK(context3d_->GetCommandBufferProxy()); |
| 244 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( | 253 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( |
| 245 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, | 254 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, |
| 246 base::Unretained(this))); | 255 base::Unretained(this))); |
| 247 } | 256 } |
| 248 } | 257 } |
| 249 | 258 |
| 250 } // namespace content | 259 } // namespace content |
| OLD | NEW |