| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "blimp/client/feature/compositor/blimp_context_provider.h" | 5 #include "blimp/client/feature/compositor/blimp_context_provider.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 "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "gpu/command_buffer/client/gl_in_process_context.h" | 10 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 11 #include "gpu/command_buffer/client/gles2_implementation.h" | 11 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 12 #include "gpu/command_buffer/client/gles2_lib.h" | 12 #include "gpu/command_buffer/client/gles2_lib.h" |
| 13 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 13 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h" |
| 14 #include "third_party/skia/include/gpu/GrContext.h" | 14 #include "third_party/skia/include/gpu/GrContext.h" |
| 15 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 15 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 16 | 16 |
| 17 namespace blimp { | 17 namespace blimp { |
| 18 namespace client { | 18 namespace client { |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 scoped_refptr<BlimpContextProvider> BlimpContextProvider::Create( | 21 scoped_refptr<BlimpContextProvider> BlimpContextProvider::Create( |
| 22 gfx::AcceleratedWidget widget, | 22 gfx::AcceleratedWidget widget, |
| 23 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { | 23 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 45 widget, gfx::Size(1, 1), nullptr /* share_context */, attribs_for_gles2, | 45 widget, gfx::Size(1, 1), nullptr /* share_context */, attribs_for_gles2, |
| 46 gfx::PreferDiscreteGpu, gpu::GLInProcessContextSharedMemoryLimits(), | 46 gfx::PreferDiscreteGpu, gpu::GLInProcessContextSharedMemoryLimits(), |
| 47 gpu_memory_buffer_manager, nullptr /* memory_limits */)); | 47 gpu_memory_buffer_manager, nullptr /* memory_limits */)); |
| 48 context_->GetImplementation()->SetLostContextCallback( | 48 context_->GetImplementation()->SetLostContextCallback( |
| 49 base::Bind(&BlimpContextProvider::OnLostContext, base::Unretained(this))); | 49 base::Bind(&BlimpContextProvider::OnLostContext, base::Unretained(this))); |
| 50 } | 50 } |
| 51 | 51 |
| 52 BlimpContextProvider::~BlimpContextProvider() { | 52 BlimpContextProvider::~BlimpContextProvider() { |
| 53 DCHECK(main_thread_checker_.CalledOnValidThread() || | 53 DCHECK(main_thread_checker_.CalledOnValidThread() || |
| 54 context_thread_checker_.CalledOnValidThread()); | 54 context_thread_checker_.CalledOnValidThread()); |
| 55 if (gr_context_) | |
| 56 gr_context_->releaseResourcesAndAbandonContext(); | |
| 57 } | 55 } |
| 58 | 56 |
| 59 bool BlimpContextProvider::BindToCurrentThread() { | 57 bool BlimpContextProvider::BindToCurrentThread() { |
| 60 DCHECK(context_thread_checker_.CalledOnValidThread()); | 58 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 61 capabilities_.gpu = context_->GetImplementation()->capabilities(); | 59 capabilities_.gpu = context_->GetImplementation()->capabilities(); |
| 62 capabilities_.gpu.image = true; | 60 capabilities_.gpu.image = true; |
| 63 return true; | 61 return true; |
| 64 } | 62 } |
| 65 | 63 |
| 66 void BlimpContextProvider::DetachFromThread() { | 64 void BlimpContextProvider::DetachFromThread() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 79 | 77 |
| 80 gpu::ContextSupport* BlimpContextProvider::ContextSupport() { | 78 gpu::ContextSupport* BlimpContextProvider::ContextSupport() { |
| 81 DCHECK(context_thread_checker_.CalledOnValidThread()); | 79 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 82 return context_->GetImplementation(); | 80 return context_->GetImplementation(); |
| 83 } | 81 } |
| 84 | 82 |
| 85 class GrContext* BlimpContextProvider::GrContext() { | 83 class GrContext* BlimpContextProvider::GrContext() { |
| 86 DCHECK(context_thread_checker_.CalledOnValidThread()); | 84 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 87 | 85 |
| 88 if (gr_context_) | 86 if (gr_context_) |
| 89 return gr_context_.get(); | 87 return gr_context_->get(); |
| 90 | 88 |
| 91 sk_sp<GrGLInterface> interface( | 89 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL())); |
| 92 skia_bindings::CreateGLES2InterfaceBindings(ContextGL())); | |
| 93 | 90 |
| 94 gr_context_ = skia::AdoptRef(GrContext::Create( | 91 return gr_context_->get(); |
| 95 // GrContext takes ownership of |interface|. | |
| 96 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); | |
| 97 return gr_context_.get(); | |
| 98 } | 92 } |
| 99 | 93 |
| 100 void BlimpContextProvider::InvalidateGrContext(uint32_t state) { | 94 void BlimpContextProvider::InvalidateGrContext(uint32_t state) { |
| 101 DCHECK(context_thread_checker_.CalledOnValidThread()); | 95 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 102 | 96 |
| 103 if (gr_context_) | 97 if (gr_context_) |
| 104 gr_context_->resetContext(state); | 98 gr_context_->ResetContext(state); |
| 105 } | 99 } |
| 106 | 100 |
| 107 void BlimpContextProvider::SetupLock() { | 101 void BlimpContextProvider::SetupLock() { |
| 108 context_->SetLock(&context_lock_); | 102 context_->SetLock(&context_lock_); |
| 109 } | 103 } |
| 110 | 104 |
| 111 base::Lock* BlimpContextProvider::GetLock() { | 105 base::Lock* BlimpContextProvider::GetLock() { |
| 112 return &context_lock_; | 106 return &context_lock_; |
| 113 } | 107 } |
| 114 | 108 |
| 115 void BlimpContextProvider::DeleteCachedResources() { | 109 void BlimpContextProvider::DeleteCachedResources() { |
| 116 DCHECK(context_thread_checker_.CalledOnValidThread()); | 110 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 117 | 111 |
| 118 if (gr_context_) | 112 if (gr_context_) |
| 119 gr_context_->freeGpuResources(); | 113 gr_context_->FreeGpuResources(); |
| 120 } | 114 } |
| 121 | 115 |
| 122 void BlimpContextProvider::SetLostContextCallback( | 116 void BlimpContextProvider::SetLostContextCallback( |
| 123 const LostContextCallback& lost_context_callback) { | 117 const LostContextCallback& lost_context_callback) { |
| 124 DCHECK(context_thread_checker_.CalledOnValidThread()); | 118 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 125 lost_context_callback_ = lost_context_callback; | 119 lost_context_callback_ = lost_context_callback; |
| 126 } | 120 } |
| 127 | 121 |
| 128 void BlimpContextProvider::OnLostContext() { | 122 void BlimpContextProvider::OnLostContext() { |
| 129 DCHECK(context_thread_checker_.CalledOnValidThread()); | 123 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 130 if (!lost_context_callback_.is_null()) | 124 if (!lost_context_callback_.is_null()) |
| 131 lost_context_callback_.Run(); | 125 lost_context_callback_.Run(); |
| 132 if (gr_context_) | 126 if (gr_context_) |
| 133 gr_context_->abandonContext(); | 127 gr_context_->OnLostContext(); |
| 134 } | 128 } |
| 135 | 129 |
| 136 } // namespace client | 130 } // namespace client |
| 137 } // namespace blimp | 131 } // namespace blimp |
| OLD | NEW |