| 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 "webkit/common/gpu/context_provider_in_process.h" | 5 #include "webkit/common/gpu/context_provider_in_process.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "cc/output/managed_memory_policy.h" | 9 #include "cc/output/managed_memory_policy.h" |
| 10 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" | 10 #include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 WebKit::WebGraphicsMemoryAllocation allocation) { | 71 WebKit::WebGraphicsMemoryAllocation allocation) { |
| 72 provider_->OnMemoryAllocationChanged(allocation); | 72 provider_->OnMemoryAllocationChanged(allocation); |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 ContextProviderInProcess* provider_; | 76 ContextProviderInProcess* provider_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // static | 79 // static |
| 80 scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create( | 80 scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create( |
| 81 const CreateCallback& create_callback) { | 81 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d) { |
| 82 scoped_refptr<ContextProviderInProcess> provider = | 82 if (!context3d) |
| 83 new ContextProviderInProcess; | |
| 84 if (!provider->InitializeOnMainThread(create_callback)) | |
| 85 return NULL; | 83 return NULL; |
| 86 return provider; | 84 return new ContextProviderInProcess(context3d.Pass()); |
| 87 } | 85 } |
| 88 | 86 |
| 89 static scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> | 87 // static |
| 90 CreateOffscreenContext() { | 88 scoped_refptr<ContextProviderInProcess> |
| 89 ContextProviderInProcess::CreateOffscreen() { |
| 91 WebKit::WebGraphicsContext3D::Attributes attributes; | 90 WebKit::WebGraphicsContext3D::Attributes attributes; |
| 92 attributes.depth = false; | 91 attributes.depth = false; |
| 93 attributes.stencil = true; | 92 attributes.stencil = true; |
| 94 attributes.antialias = false; | 93 attributes.antialias = false; |
| 95 attributes.shareResources = true; | 94 attributes.shareResources = true; |
| 96 attributes.noAutomaticFlushes = true; | 95 attributes.noAutomaticFlushes = true; |
| 97 | 96 |
| 98 return WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( | 97 return Create( |
| 99 attributes).Pass(); | 98 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( |
| 99 attributes)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // static | 102 ContextProviderInProcess::ContextProviderInProcess( |
| 103 scoped_refptr<ContextProviderInProcess> | 103 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d) |
| 104 ContextProviderInProcess::CreateOffscreen() { | 104 : context3d_(context3d.Pass()), |
| 105 return Create(base::Bind(&CreateOffscreenContext)); | 105 destroyed_(false) { |
| 106 } | |
| 107 | |
| 108 ContextProviderInProcess::ContextProviderInProcess() | |
| 109 : destroyed_(false) { | |
| 110 DCHECK(main_thread_checker_.CalledOnValidThread()); | 106 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 107 DCHECK(context3d_); |
| 111 context_thread_checker_.DetachFromThread(); | 108 context_thread_checker_.DetachFromThread(); |
| 112 } | 109 } |
| 113 | 110 |
| 114 ContextProviderInProcess::~ContextProviderInProcess() { | 111 ContextProviderInProcess::~ContextProviderInProcess() { |
| 115 DCHECK(main_thread_checker_.CalledOnValidThread() || | 112 DCHECK(main_thread_checker_.CalledOnValidThread() || |
| 116 context_thread_checker_.CalledOnValidThread()); | 113 context_thread_checker_.CalledOnValidThread()); |
| 117 } | 114 } |
| 118 | 115 |
| 119 bool ContextProviderInProcess::InitializeOnMainThread( | |
| 120 const CreateCallback& create_callback) { | |
| 121 DCHECK(!context3d_); | |
| 122 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
| 123 DCHECK(!create_callback.is_null()); | |
| 124 | |
| 125 context3d_ = create_callback.Run(); | |
| 126 return context3d_; | |
| 127 } | |
| 128 | |
| 129 bool ContextProviderInProcess::BindToCurrentThread() { | 116 bool ContextProviderInProcess::BindToCurrentThread() { |
| 130 DCHECK(context3d_); | 117 DCHECK(context3d_); |
| 131 | 118 |
| 132 // This is called on the thread the context will be used. | 119 // This is called on the thread the context will be used. |
| 133 DCHECK(context_thread_checker_.CalledOnValidThread()); | 120 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 134 | 121 |
| 135 if (lost_context_callback_proxy_) | 122 if (lost_context_callback_proxy_) |
| 136 return true; | 123 return true; |
| 137 | 124 |
| 138 if (!context3d_->makeContextCurrent()) | 125 if (!context3d_->makeContextCurrent()) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 void ContextProviderInProcess::SetMemoryPolicyChangedCallback( | 229 void ContextProviderInProcess::SetMemoryPolicyChangedCallback( |
| 243 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { | 230 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { |
| 244 DCHECK(context_thread_checker_.CalledOnValidThread()); | 231 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 245 DCHECK(memory_policy_changed_callback_.is_null() || | 232 DCHECK(memory_policy_changed_callback_.is_null() || |
| 246 memory_policy_changed_callback.is_null()); | 233 memory_policy_changed_callback.is_null()); |
| 247 memory_policy_changed_callback_ = memory_policy_changed_callback; | 234 memory_policy_changed_callback_ = memory_policy_changed_callback; |
| 248 } | 235 } |
| 249 | 236 |
| 250 } // namespace gpu | 237 } // namespace gpu |
| 251 } // namespace webkit | 238 } // namespace webkit |
| OLD | NEW |