Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(750)

Side by Side Diff: content/common/gpu/client/context_provider_command_buffer.cc

Issue 889063002: (not for commit) Create 2nd ContextProvider for Ganesh rasterization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 73
74 CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() { 74 CommandBufferProxyImpl* ContextProviderCommandBuffer::GetCommandBufferProxy() {
75 return context3d_->GetCommandBufferProxy(); 75 return context3d_->GetCommandBufferProxy();
76 } 76 }
77 77
78 WebGraphicsContext3DCommandBufferImpl* 78 WebGraphicsContext3DCommandBufferImpl*
79 ContextProviderCommandBuffer::WebContext3D() { 79 ContextProviderCommandBuffer::WebContext3D() {
80 DCHECK(context3d_); 80 DCHECK(context3d_);
81 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 81 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
82 DCHECK(context_thread_checker_.CalledOnValidThread()); 82 CHECK(context_thread_checker_.CalledOnValidThread());
83 83
84 return context3d_.get(); 84 return context3d_.get();
85 } 85 }
86 86
87 bool ContextProviderCommandBuffer::BindToCurrentThread() { 87 bool ContextProviderCommandBuffer::BindToCurrentThread() {
88 // This is called on the thread the context will be used. 88 // This is called on the thread the context will be used.
89 DCHECK(context_thread_checker_.CalledOnValidThread()); 89 CHECK(context_thread_checker_.CalledOnValidThread());
90 90
91 if (lost_context_callback_proxy_) 91 if (lost_context_callback_proxy_)
92 return true; 92 return true;
93 93
94 if (!context3d_->InitializeOnCurrentThread()) 94 if (!context3d_->InitializeOnCurrentThread())
95 return false; 95 return false;
96 96
97 InitializeCapabilities(); 97 InitializeCapabilities();
98 98
99 std::string unique_context_name = 99 std::string unique_context_name =
100 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get()); 100 base::StringPrintf("%s-%p", debug_name_.c_str(), context3d_.get());
101 context3d_->traceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str()); 101 context3d_->traceBeginCHROMIUM("gpu_toplevel", unique_context_name.c_str());
102 102
103 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); 103 lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
104 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( 104 context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback(
105 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, 105 base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged,
106 base::Unretained(this))); 106 base::Unretained(this)));
107 return true; 107 return true;
108 } 108 }
109 109
110 void ContextProviderCommandBuffer::RebindToCurrentThread() {
111 context_thread_checker_.DetachFromThread();
112 context_thread_checker_.CalledOnValidThread();
113 }
114
110 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() { 115 gpu::gles2::GLES2Interface* ContextProviderCommandBuffer::ContextGL() {
111 DCHECK(context3d_); 116 DCHECK(context3d_);
112 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 117 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
113 DCHECK(context_thread_checker_.CalledOnValidThread()); 118 // CHECK(context_thread_checker_.CalledOnValidThread());
114 119
115 return context3d_->GetImplementation(); 120 return context3d_->GetImplementation();
116 } 121 }
117 122
118 gpu::ContextSupport* ContextProviderCommandBuffer::ContextSupport() { 123 gpu::ContextSupport* ContextProviderCommandBuffer::ContextSupport() {
119 return context3d_->GetContextSupport(); 124 return context3d_->GetContextSupport();
120 } 125 }
121 126
122 class GrContext* ContextProviderCommandBuffer::GrContext() { 127 class GrContext* ContextProviderCommandBuffer::GrContext() {
123 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 128 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
124 DCHECK(context_thread_checker_.CalledOnValidThread()); 129 CHECK(context_thread_checker_.CalledOnValidThread());
125 130
126 if (gr_context_) 131 if (gr_context_)
127 return gr_context_->get(); 132 return gr_context_->get();
128 133
129 gr_context_.reset( 134 gr_context_.reset(
130 new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get())); 135 new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get()));
131 return gr_context_->get(); 136 return gr_context_->get();
132 } 137 }
133 138
134 cc::ContextProvider::Capabilities 139 cc::ContextProvider::Capabilities
135 ContextProviderCommandBuffer::ContextCapabilities() { 140 ContextProviderCommandBuffer::ContextCapabilities() {
136 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 141 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
137 DCHECK(context_thread_checker_.CalledOnValidThread()); 142 CHECK(context_thread_checker_.CalledOnValidThread());
138 143
139 return capabilities_; 144 return capabilities_;
140 } 145 }
141 146
142 bool ContextProviderCommandBuffer::IsContextLost() { 147 bool ContextProviderCommandBuffer::IsContextLost() {
143 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 148 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
144 DCHECK(context_thread_checker_.CalledOnValidThread()); 149 CHECK(context_thread_checker_.CalledOnValidThread());
145 150
146 return context3d_->isContextLost(); 151 return context3d_->isContextLost();
147 } 152 }
148 153
149 void ContextProviderCommandBuffer::VerifyContexts() { 154 void ContextProviderCommandBuffer::VerifyContexts() {
150 DCHECK(lost_context_callback_proxy_); // Is bound to thread. 155 DCHECK(lost_context_callback_proxy_); // Is bound to thread.
151 DCHECK(context_thread_checker_.CalledOnValidThread()); 156 CHECK(context_thread_checker_.CalledOnValidThread());
152 157
153 if (context3d_->isContextLost()) 158 if (context3d_->isContextLost())
154 OnLostContext(); 159 OnLostContext();
155 } 160 }
156 161
157 void ContextProviderCommandBuffer::DeleteCachedResources() { 162 void ContextProviderCommandBuffer::DeleteCachedResources() {
158 DCHECK(context_thread_checker_.CalledOnValidThread()); 163 CHECK(context_thread_checker_.CalledOnValidThread());
159 164
160 if (gr_context_) 165 if (gr_context_)
161 gr_context_->FreeGpuResources(); 166 gr_context_->FreeGpuResources();
162 } 167 }
163 168
164 void ContextProviderCommandBuffer::OnLostContext() { 169 void ContextProviderCommandBuffer::OnLostContext() {
165 DCHECK(context_thread_checker_.CalledOnValidThread()); 170 CHECK(context_thread_checker_.CalledOnValidThread());
166 { 171 {
167 base::AutoLock lock(main_thread_lock_); 172 base::AutoLock lock(main_thread_lock_);
168 if (destroyed_) 173 if (destroyed_)
169 return; 174 return;
170 destroyed_ = true; 175 destroyed_ = true;
171 } 176 }
172 if (!lost_context_callback_.is_null()) 177 if (!lost_context_callback_.is_null())
173 base::ResetAndReturn(&lost_context_callback_).Run(); 178 base::ResetAndReturn(&lost_context_callback_).Run();
174 if (gr_context_) 179 if (gr_context_)
175 gr_context_->OnLostContext(); 180 gr_context_->OnLostContext();
176 } 181 }
177 182
178 void ContextProviderCommandBuffer::OnMemoryAllocationChanged( 183 void ContextProviderCommandBuffer::OnMemoryAllocationChanged(
179 const gpu::MemoryAllocation& allocation) { 184 const gpu::MemoryAllocation& allocation) {
180 DCHECK(context_thread_checker_.CalledOnValidThread()); 185 CHECK(context_thread_checker_.CalledOnValidThread());
181 186
182 if (memory_policy_changed_callback_.is_null()) 187 if (memory_policy_changed_callback_.is_null())
183 return; 188 return;
184 189
185 memory_policy_changed_callback_.Run(cc::ManagedMemoryPolicy(allocation)); 190 memory_policy_changed_callback_.Run(cc::ManagedMemoryPolicy(allocation));
186 } 191 }
187 192
188 void ContextProviderCommandBuffer::InitializeCapabilities() { 193 void ContextProviderCommandBuffer::InitializeCapabilities() {
189 Capabilities caps; 194 Capabilities caps;
190 caps.gpu = context3d_->GetImplementation()->capabilities(); 195 caps.gpu = context3d_->GetImplementation()->capabilities();
191 196
192 size_t mapped_memory_limit = context3d_->GetMappedMemoryLimit(); 197 size_t mapped_memory_limit = context3d_->GetMappedMemoryLimit();
193 caps.max_transfer_buffer_usage_bytes = 198 caps.max_transfer_buffer_usage_bytes =
194 mapped_memory_limit == WebGraphicsContext3DCommandBufferImpl::kNoLimit 199 mapped_memory_limit == WebGraphicsContext3DCommandBufferImpl::kNoLimit
195 ? std::numeric_limits<size_t>::max() : mapped_memory_limit; 200 ? std::numeric_limits<size_t>::max() : mapped_memory_limit;
196 201
197 capabilities_ = caps; 202 capabilities_ = caps;
198 } 203 }
199 204
200 bool ContextProviderCommandBuffer::DestroyedOnMainThread() { 205 bool ContextProviderCommandBuffer::DestroyedOnMainThread() {
201 DCHECK(main_thread_checker_.CalledOnValidThread()); 206 DCHECK(main_thread_checker_.CalledOnValidThread());
202 207
203 base::AutoLock lock(main_thread_lock_); 208 base::AutoLock lock(main_thread_lock_);
204 return destroyed_; 209 return destroyed_;
205 } 210 }
206 211
207 void ContextProviderCommandBuffer::SetLostContextCallback( 212 void ContextProviderCommandBuffer::SetLostContextCallback(
208 const LostContextCallback& lost_context_callback) { 213 const LostContextCallback& lost_context_callback) {
209 DCHECK(context_thread_checker_.CalledOnValidThread()); 214 CHECK(context_thread_checker_.CalledOnValidThread());
210 DCHECK(lost_context_callback_.is_null() || 215 DCHECK(lost_context_callback_.is_null() ||
211 lost_context_callback.is_null()); 216 lost_context_callback.is_null());
212 lost_context_callback_ = lost_context_callback; 217 lost_context_callback_ = lost_context_callback;
213 } 218 }
214 219
215 void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback( 220 void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback(
216 const MemoryPolicyChangedCallback& memory_policy_changed_callback) { 221 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
217 DCHECK(context_thread_checker_.CalledOnValidThread()); 222 CHECK(context_thread_checker_.CalledOnValidThread());
218 DCHECK(memory_policy_changed_callback_.is_null() || 223 DCHECK(memory_policy_changed_callback_.is_null() ||
219 memory_policy_changed_callback.is_null()); 224 memory_policy_changed_callback.is_null());
220 memory_policy_changed_callback_ = memory_policy_changed_callback; 225 memory_policy_changed_callback_ = memory_policy_changed_callback;
221 } 226 }
222 227
223 } // namespace content 228 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/client/context_provider_command_buffer.h ('k') | content/renderer/gpu/compositor_output_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698