| 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 "android_webview/browser/aw_render_thread_context_provider.h" | 5 #include "android_webview/browser/aw_render_thread_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 "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 attributes.alpha_size = 8; | 45 attributes.alpha_size = 8; |
| 46 attributes.stencil_size = 8; | 46 attributes.stencil_size = 8; |
| 47 // The depth buffer may exist due to having a stencil buffer, but we don't | 47 // The depth buffer may exist due to having a stencil buffer, but we don't |
| 48 // need one, so use -1 for it. | 48 // need one, so use -1 for it. |
| 49 attributes.depth_size = -1; | 49 attributes.depth_size = -1; |
| 50 attributes.samples = 0; | 50 attributes.samples = 0; |
| 51 attributes.sample_buffers = 0; | 51 attributes.sample_buffers = 0; |
| 52 attributes.bind_generates_resource = false; | 52 attributes.bind_generates_resource = false; |
| 53 context_.reset(gpu::GLInProcessContext::Create( | 53 context_.reset(gpu::GLInProcessContext::Create( |
| 54 service, surface, surface->IsOffscreen(), gfx::kNullAcceleratedWidget, | 54 service, surface, surface->IsOffscreen(), gfx::kNullAcceleratedWidget, |
| 55 surface->GetSize(), nullptr /* share_context */, | 55 surface->GetSize(), nullptr /* share_context */, attributes, |
| 56 false /* share_resources */, attributes, gfx::PreferDiscreteGpu, | 56 gfx::PreferDiscreteGpu, gpu::GLInProcessContextSharedMemoryLimits(), |
| 57 gpu::GLInProcessContextSharedMemoryLimits(), nullptr, nullptr)); | 57 nullptr, nullptr)); |
| 58 | 58 |
| 59 context_->SetContextLostCallback(base::Bind( | 59 context_->SetContextLostCallback(base::Bind( |
| 60 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); | 60 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); |
| 61 | 61 |
| 62 capabilities_.gpu = context_->GetImplementation()->capabilities(); | 62 capabilities_.gpu = context_->GetImplementation()->capabilities(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { | 65 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { |
| 66 DCHECK(main_thread_checker_.CalledOnValidThread()); | 66 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 67 if (gr_context_) | 67 if (gr_context_) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 109 } |
| 110 | 110 |
| 111 void AwRenderThreadContextProvider::InvalidateGrContext(uint32_t state) { | 111 void AwRenderThreadContextProvider::InvalidateGrContext(uint32_t state) { |
| 112 DCHECK(main_thread_checker_.CalledOnValidThread()); | 112 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 113 | 113 |
| 114 if (gr_context_) | 114 if (gr_context_) |
| 115 gr_context_->resetContext(state); | 115 gr_context_->resetContext(state); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void AwRenderThreadContextProvider::SetupLock() { | 118 void AwRenderThreadContextProvider::SetupLock() { |
| 119 context_->SetLock(&context_lock_); | 119 // This context provider is not used on multiple threads. |
| 120 NOTREACHED(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 base::Lock* AwRenderThreadContextProvider::GetLock() { | 123 base::Lock* AwRenderThreadContextProvider::GetLock() { |
| 123 return &context_lock_; | 124 // This context provider is not used on multiple threads. |
| 125 NOTREACHED(); |
| 126 return nullptr; |
| 124 } | 127 } |
| 125 | 128 |
| 126 void AwRenderThreadContextProvider::DeleteCachedResources() { | 129 void AwRenderThreadContextProvider::DeleteCachedResources() { |
| 127 DCHECK(main_thread_checker_.CalledOnValidThread()); | 130 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 128 | 131 |
| 129 if (gr_context_) { | 132 if (gr_context_) { |
| 130 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", | 133 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", |
| 131 TRACE_EVENT_SCOPE_THREAD); | 134 TRACE_EVENT_SCOPE_THREAD); |
| 132 gr_context_->freeGpuResources(); | 135 gr_context_->freeGpuResources(); |
| 133 } | 136 } |
| 134 } | 137 } |
| 135 | 138 |
| 136 void AwRenderThreadContextProvider::SetLostContextCallback( | 139 void AwRenderThreadContextProvider::SetLostContextCallback( |
| 137 const LostContextCallback& lost_context_callback) { | 140 const LostContextCallback& lost_context_callback) { |
| 138 lost_context_callback_ = lost_context_callback; | 141 lost_context_callback_ = lost_context_callback; |
| 139 } | 142 } |
| 140 | 143 |
| 141 void AwRenderThreadContextProvider::OnLostContext() { | 144 void AwRenderThreadContextProvider::OnLostContext() { |
| 142 DCHECK(main_thread_checker_.CalledOnValidThread()); | 145 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 143 | 146 |
| 144 if (!lost_context_callback_.is_null()) | 147 if (!lost_context_callback_.is_null()) |
| 145 base::ResetAndReturn(&lost_context_callback_).Run(); | 148 base::ResetAndReturn(&lost_context_callback_).Run(); |
| 146 if (gr_context_) | 149 if (gr_context_) |
| 147 gr_context_->abandonContext(); | 150 gr_context_->abandonContext(); |
| 148 } | 151 } |
| 149 | 152 |
| 150 } // namespace android_webview | 153 } // namespace android_webview |
| OLD | NEW |