| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "blimp/client/support/compositor/blimp_context_provider.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback_helpers.h" | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/threading/thread_task_runner_handle.h" | |
| 11 #include "cc/output/context_cache_controller.h" | |
| 12 #include "gpu/command_buffer/client/gles2_implementation.h" | |
| 13 #include "gpu/command_buffer/client/gles2_lib.h" | |
| 14 #include "gpu/command_buffer/client/shared_memory_limits.h" | |
| 15 #include "gpu/ipc/gl_in_process_context.h" | |
| 16 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h" | |
| 17 #include "third_party/skia/include/gpu/GrContext.h" | |
| 18 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | |
| 19 | |
| 20 namespace blimp { | |
| 21 namespace client { | |
| 22 | |
| 23 // static | |
| 24 scoped_refptr<BlimpContextProvider> BlimpContextProvider::Create( | |
| 25 gpu::SurfaceHandle widget, | |
| 26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { | |
| 27 return new BlimpContextProvider(widget, gpu_memory_buffer_manager); | |
| 28 } | |
| 29 | |
| 30 BlimpContextProvider::BlimpContextProvider( | |
| 31 gpu::SurfaceHandle widget, | |
| 32 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { | |
| 33 context_thread_checker_.DetachFromThread(); | |
| 34 | |
| 35 gpu::gles2::ContextCreationAttribHelper attribs_for_gles2; | |
| 36 attribs_for_gles2.alpha_size = 8; | |
| 37 attribs_for_gles2.depth_size = 0; | |
| 38 attribs_for_gles2.stencil_size = 0; | |
| 39 attribs_for_gles2.samples = 0; | |
| 40 attribs_for_gles2.sample_buffers = 0; | |
| 41 attribs_for_gles2.fail_if_major_perf_caveat = false; | |
| 42 attribs_for_gles2.bind_generates_resource = false; | |
| 43 attribs_for_gles2.context_type = gpu::gles2::CONTEXT_TYPE_OPENGLES2; | |
| 44 attribs_for_gles2.lose_context_when_out_of_memory = true; | |
| 45 | |
| 46 context_.reset(gpu::GLInProcessContext::Create( | |
| 47 nullptr /* service */, nullptr /* surface */, | |
| 48 widget == gpu::kNullSurfaceHandle /* is_offscreen */, widget, | |
| 49 nullptr /* share_context */, attribs_for_gles2, gpu::SharedMemoryLimits(), | |
| 50 gpu_memory_buffer_manager, nullptr /* memory_limits */, | |
| 51 base::ThreadTaskRunnerHandle::Get())); | |
| 52 context_->GetImplementation()->SetLostContextCallback( | |
| 53 base::Bind(&BlimpContextProvider::OnLostContext, base::Unretained(this))); | |
| 54 cache_controller_.reset(new cc::ContextCacheController( | |
| 55 context_->GetImplementation(), base::ThreadTaskRunnerHandle::Get())); | |
| 56 } | |
| 57 | |
| 58 BlimpContextProvider::~BlimpContextProvider() { | |
| 59 DCHECK(main_thread_checker_.CalledOnValidThread() || | |
| 60 context_thread_checker_.CalledOnValidThread()); | |
| 61 } | |
| 62 | |
| 63 bool BlimpContextProvider::BindToCurrentThread() { | |
| 64 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 void BlimpContextProvider::DetachFromThread() { | |
| 69 context_thread_checker_.DetachFromThread(); | |
| 70 } | |
| 71 | |
| 72 gpu::Capabilities BlimpContextProvider::ContextCapabilities() { | |
| 73 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 74 return context_->GetImplementation()->capabilities(); | |
| 75 } | |
| 76 | |
| 77 gpu::gles2::GLES2Interface* BlimpContextProvider::ContextGL() { | |
| 78 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 79 return context_->GetImplementation(); | |
| 80 } | |
| 81 | |
| 82 gpu::ContextSupport* BlimpContextProvider::ContextSupport() { | |
| 83 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 84 return context_->GetImplementation(); | |
| 85 } | |
| 86 | |
| 87 class GrContext* BlimpContextProvider::GrContext() { | |
| 88 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 89 | |
| 90 if (gr_context_) | |
| 91 return gr_context_->get(); | |
| 92 | |
| 93 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL())); | |
| 94 cache_controller_->SetGrContext(gr_context_->get()); | |
| 95 return gr_context_->get(); | |
| 96 } | |
| 97 | |
| 98 cc::ContextCacheController* BlimpContextProvider::CacheController() { | |
| 99 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 100 return cache_controller_.get(); | |
| 101 } | |
| 102 | |
| 103 void BlimpContextProvider::InvalidateGrContext(uint32_t state) { | |
| 104 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 105 | |
| 106 if (gr_context_) | |
| 107 gr_context_->ResetContext(state); | |
| 108 } | |
| 109 | |
| 110 base::Lock* BlimpContextProvider::GetLock() { | |
| 111 return &context_lock_; | |
| 112 } | |
| 113 | |
| 114 void BlimpContextProvider::SetLostContextCallback( | |
| 115 const LostContextCallback& lost_context_callback) { | |
| 116 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 117 lost_context_callback_ = lost_context_callback; | |
| 118 } | |
| 119 | |
| 120 void BlimpContextProvider::OnLostContext() { | |
| 121 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 122 if (!lost_context_callback_.is_null()) | |
| 123 lost_context_callback_.Run(); | |
| 124 if (gr_context_) | |
| 125 gr_context_->OnLostContext(); | |
| 126 } | |
| 127 | |
| 128 } // namespace client | |
| 129 } // namespace blimp | |
| OLD | NEW |