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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "cc/output/context_cache_controller.h" |
18 #include "cc/output/managed_memory_policy.h" | 19 #include "cc/output/managed_memory_policy.h" |
19 #include "content/common/gpu/client/command_buffer_metrics.h" | 20 #include "content/common/gpu/client/command_buffer_metrics.h" |
20 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 21 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
21 #include "gpu/command_buffer/client/gles2_implementation.h" | 22 #include "gpu/command_buffer/client/gles2_implementation.h" |
22 #include "gpu/command_buffer/client/gles2_trace_implementation.h" | 23 #include "gpu/command_buffer/client/gles2_trace_implementation.h" |
23 #include "gpu/command_buffer/client/gpu_switches.h" | 24 #include "gpu/command_buffer/client/gpu_switches.h" |
24 #include "gpu/command_buffer/client/transfer_buffer.h" | 25 #include "gpu/command_buffer/client/transfer_buffer.h" |
25 #include "gpu/command_buffer/common/constants.h" | 26 #include "gpu/command_buffer/common/constants.h" |
26 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 27 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
27 #include "gpu/ipc/client/gpu_channel_host.h" | 28 #include "gpu/ipc/client/gpu_channel_host.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 219 } |
219 set_bind_failed.Reset(); | 220 set_bind_failed.Reset(); |
220 bind_succeeded_ = true; | 221 bind_succeeded_ = true; |
221 | 222 |
222 gles2_impl_->SetLostContextCallback( | 223 gles2_impl_->SetLostContextCallback( |
223 base::Bind(&ContextProviderCommandBuffer::OnLostContext, | 224 base::Bind(&ContextProviderCommandBuffer::OnLostContext, |
224 // |this| owns the GLES2Implementation which holds the | 225 // |this| owns the GLES2Implementation which holds the |
225 // callback. | 226 // callback. |
226 base::Unretained(this))); | 227 base::Unretained(this))); |
227 | 228 |
| 229 cache_controller_.reset(new cc::ContextCacheController(gles2_impl_.get())); |
| 230 |
228 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 231 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
229 switches::kEnableGpuClientTracing)) { | 232 switches::kEnableGpuClientTracing)) { |
230 // This wraps the real GLES2Implementation and we should always use this | 233 // This wraps the real GLES2Implementation and we should always use this |
231 // instead when it's present. | 234 // instead when it's present. |
232 trace_impl_.reset( | 235 trace_impl_.reset( |
233 new gpu::gles2::GLES2TraceImplementation(gles2_impl_.get())); | 236 new gpu::gles2::GLES2TraceImplementation(gles2_impl_.get())); |
234 } | 237 } |
235 | 238 |
236 // Do this last once the context is set up. | 239 // Do this last once the context is set up. |
237 std::string type_name = | 240 std::string type_name = |
(...skipping 29 matching lines...) Expand all Loading... |
267 } | 270 } |
268 | 271 |
269 class GrContext* ContextProviderCommandBuffer::GrContext() { | 272 class GrContext* ContextProviderCommandBuffer::GrContext() { |
270 DCHECK(bind_succeeded_); | 273 DCHECK(bind_succeeded_); |
271 DCHECK(context_thread_checker_.CalledOnValidThread()); | 274 DCHECK(context_thread_checker_.CalledOnValidThread()); |
272 | 275 |
273 if (gr_context_) | 276 if (gr_context_) |
274 return gr_context_->get(); | 277 return gr_context_->get(); |
275 | 278 |
276 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL())); | 279 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL())); |
| 280 cache_controller_->SetGrContext(gr_context_->get()); |
277 | 281 |
278 // If GlContext is already lost, also abandon the new GrContext. | 282 // If GlContext is already lost, also abandon the new GrContext. |
279 if (gr_context_->get() && | 283 if (gr_context_->get() && |
280 ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR) | 284 ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR) |
281 gr_context_->get()->abandonContext(); | 285 gr_context_->get()->abandonContext(); |
282 | 286 |
283 return gr_context_->get(); | 287 return gr_context_->get(); |
284 } | 288 } |
285 | 289 |
| 290 cc::ContextCacheController* ContextProviderCommandBuffer::CacheController() { |
| 291 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 292 return cache_controller_.get(); |
| 293 } |
| 294 |
286 void ContextProviderCommandBuffer::InvalidateGrContext(uint32_t state) { | 295 void ContextProviderCommandBuffer::InvalidateGrContext(uint32_t state) { |
287 if (gr_context_) { | 296 if (gr_context_) { |
288 DCHECK(bind_succeeded_); | 297 DCHECK(bind_succeeded_); |
289 DCHECK(context_thread_checker_.CalledOnValidThread()); | 298 DCHECK(context_thread_checker_.CalledOnValidThread()); |
290 gr_context_->ResetContext(state); | 299 gr_context_->ResetContext(state); |
291 } | 300 } |
292 } | 301 } |
293 | 302 |
294 void ContextProviderCommandBuffer::SetDefaultTaskRunner( | 303 void ContextProviderCommandBuffer::SetDefaultTaskRunner( |
295 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner) { | 304 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner) { |
296 DCHECK(!bind_succeeded_); | 305 DCHECK(!bind_succeeded_); |
297 default_task_runner_ = std::move(default_task_runner); | 306 default_task_runner_ = std::move(default_task_runner); |
298 } | 307 } |
299 | 308 |
300 base::Lock* ContextProviderCommandBuffer::GetLock() { | 309 base::Lock* ContextProviderCommandBuffer::GetLock() { |
301 DCHECK(support_locking_); | 310 DCHECK(support_locking_); |
302 return &context_lock_; | 311 return &context_lock_; |
303 } | 312 } |
304 | 313 |
305 gpu::Capabilities ContextProviderCommandBuffer::ContextCapabilities() { | 314 gpu::Capabilities ContextProviderCommandBuffer::ContextCapabilities() { |
306 DCHECK(bind_succeeded_); | 315 DCHECK(bind_succeeded_); |
307 DCHECK(context_thread_checker_.CalledOnValidThread()); | 316 DCHECK(context_thread_checker_.CalledOnValidThread()); |
308 // Skips past the trace_impl_ as it doesn't have capabilities. | 317 // Skips past the trace_impl_ as it doesn't have capabilities. |
309 return gles2_impl_->capabilities(); | 318 return gles2_impl_->capabilities(); |
310 } | 319 } |
311 | 320 |
312 void ContextProviderCommandBuffer::DeleteCachedResources() { | |
313 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
314 | |
315 if (gr_context_) | |
316 gr_context_->FreeGpuResources(); | |
317 } | |
318 | |
319 void ContextProviderCommandBuffer::OnLostContext() { | 321 void ContextProviderCommandBuffer::OnLostContext() { |
320 DCHECK(context_thread_checker_.CalledOnValidThread()); | 322 DCHECK(context_thread_checker_.CalledOnValidThread()); |
321 | 323 |
322 if (!lost_context_callback_.is_null()) | 324 if (!lost_context_callback_.is_null()) |
323 lost_context_callback_.Run(); | 325 lost_context_callback_.Run(); |
324 if (gr_context_) | 326 if (gr_context_) |
325 gr_context_->OnLostContext(); | 327 gr_context_->OnLostContext(); |
326 | 328 |
327 gpu::CommandBuffer::State state = GetCommandBufferProxy()->GetLastState(); | 329 gpu::CommandBuffer::State state = GetCommandBufferProxy()->GetLastState(); |
328 command_buffer_metrics::UmaRecordContextLost(context_type_, state.error, | 330 command_buffer_metrics::UmaRecordContextLost(context_type_, state.error, |
329 state.context_lost_reason); | 331 state.context_lost_reason); |
330 } | 332 } |
331 | 333 |
332 void ContextProviderCommandBuffer::SetLostContextCallback( | 334 void ContextProviderCommandBuffer::SetLostContextCallback( |
333 const LostContextCallback& lost_context_callback) { | 335 const LostContextCallback& lost_context_callback) { |
334 DCHECK(context_thread_checker_.CalledOnValidThread()); | 336 DCHECK(context_thread_checker_.CalledOnValidThread()); |
335 DCHECK(lost_context_callback_.is_null() || | 337 DCHECK(lost_context_callback_.is_null() || |
336 lost_context_callback.is_null()); | 338 lost_context_callback.is_null()); |
337 lost_context_callback_ = lost_context_callback; | 339 lost_context_callback_ = lost_context_callback; |
338 } | 340 } |
339 | 341 |
340 } // namespace content | 342 } // namespace content |
OLD | NEW |