| 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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "cc/output/managed_memory_policy.h" | 8 #include "cc/output/managed_memory_policy.h" |
| 9 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" | 9 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" |
| 10 #include "webkit/common/gpu/managed_memory_policy_convert.h" | 10 #include "webkit/common/gpu/managed_memory_policy_convert.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 virtual void onMemoryAllocationChanged( | 69 virtual void onMemoryAllocationChanged( |
| 70 WebKit::WebGraphicsMemoryAllocation allocation) { | 70 WebKit::WebGraphicsMemoryAllocation allocation) { |
| 71 provider_->OnMemoryAllocationChanged(allocation); | 71 provider_->OnMemoryAllocationChanged(allocation); |
| 72 } | 72 } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 ContextProviderCommandBuffer* provider_; | 75 ContextProviderCommandBuffer* provider_; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 scoped_refptr<ContextProviderCommandBuffer> | 78 scoped_refptr<ContextProviderCommandBuffer> |
| 79 ContextProviderCommandBuffer::Create(const CreateCallback& create_callback) { | 79 ContextProviderCommandBuffer::Create( |
| 80 scoped_refptr<ContextProviderCommandBuffer> provider = | 80 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d) { |
| 81 new ContextProviderCommandBuffer; | 81 if (!context3d) |
| 82 if (!provider->InitializeOnMainThread(create_callback)) | |
| 83 return NULL; | 82 return NULL; |
| 84 return provider; | 83 |
| 84 return new ContextProviderCommandBuffer(context3d.Pass()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 ContextProviderCommandBuffer::ContextProviderCommandBuffer() | 87 ContextProviderCommandBuffer::ContextProviderCommandBuffer( |
| 88 : leak_on_destroy_(false), | 88 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d) |
| 89 : context3d_(context3d.Pass()), |
| 90 leak_on_destroy_(false), |
| 89 destroyed_(false) { | 91 destroyed_(false) { |
| 90 DCHECK(main_thread_checker_.CalledOnValidThread()); | 92 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 93 DCHECK(context3d_); |
| 91 context_thread_checker_.DetachFromThread(); | 94 context_thread_checker_.DetachFromThread(); |
| 92 } | 95 } |
| 93 | 96 |
| 94 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { | 97 ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { |
| 95 DCHECK(main_thread_checker_.CalledOnValidThread() || | 98 DCHECK(main_thread_checker_.CalledOnValidThread() || |
| 96 context_thread_checker_.CalledOnValidThread()); | 99 context_thread_checker_.CalledOnValidThread()); |
| 97 | 100 |
| 98 base::AutoLock lock(main_thread_lock_); | 101 base::AutoLock lock(main_thread_lock_); |
| 99 if (leak_on_destroy_) { | 102 if (leak_on_destroy_) { |
| 100 WebGraphicsContext3DCommandBufferImpl* context3d ALLOW_UNUSED = | 103 WebGraphicsContext3DCommandBufferImpl* context3d ALLOW_UNUSED = |
| 101 context3d_.release(); | 104 context3d_.release(); |
| 102 webkit::gpu::GrContextForWebGraphicsContext3D* gr_context ALLOW_UNUSED = | 105 webkit::gpu::GrContextForWebGraphicsContext3D* gr_context ALLOW_UNUSED = |
| 103 gr_context_.release(); | 106 gr_context_.release(); |
| 104 } | 107 } |
| 105 } | 108 } |
| 106 | 109 |
| 107 bool ContextProviderCommandBuffer::InitializeOnMainThread( | |
| 108 const CreateCallback& create_callback) { | |
| 109 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
| 110 | |
| 111 DCHECK(!context3d_); | |
| 112 DCHECK(!create_callback.is_null()); | |
| 113 context3d_ = create_callback.Run(); | |
| 114 return !!context3d_; | |
| 115 } | |
| 116 | |
| 117 bool ContextProviderCommandBuffer::BindToCurrentThread() { | 110 bool ContextProviderCommandBuffer::BindToCurrentThread() { |
| 118 DCHECK(context3d_); | 111 DCHECK(context3d_); |
| 119 | 112 |
| 120 // This is called on the thread the context will be used. | 113 // This is called on the thread the context will be used. |
| 121 DCHECK(context_thread_checker_.CalledOnValidThread()); | 114 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 122 | 115 |
| 123 if (lost_context_callback_proxy_) | 116 if (lost_context_callback_proxy_) |
| 124 return true; | 117 return true; |
| 125 | 118 |
| 126 if (!context3d_->makeContextCurrent()) | 119 if (!context3d_->makeContextCurrent()) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 223 |
| 231 void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback( | 224 void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback( |
| 232 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { | 225 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { |
| 233 DCHECK(context_thread_checker_.CalledOnValidThread()); | 226 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 234 DCHECK(memory_policy_changed_callback_.is_null() || | 227 DCHECK(memory_policy_changed_callback_.is_null() || |
| 235 memory_policy_changed_callback.is_null()); | 228 memory_policy_changed_callback.is_null()); |
| 236 memory_policy_changed_callback_ = memory_policy_changed_callback; | 229 memory_policy_changed_callback_ = memory_policy_changed_callback; |
| 237 } | 230 } |
| 238 | 231 |
| 239 } // namespace content | 232 } // namespace content |
| OLD | NEW |