| 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 | |
| 59 context_->SetContextLostCallback(base::Bind( | |
| 60 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); | |
| 61 | 58 |
| 62 capabilities_.gpu = context_->GetImplementation()->capabilities(); | 59 capabilities_.gpu = context_->GetImplementation()->capabilities(); |
| 63 } | 60 } |
| 64 | 61 |
| 65 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { | 62 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { |
| 66 DCHECK(main_thread_checker_.CalledOnValidThread()); | 63 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 67 if (gr_context_) | 64 if (gr_context_) |
| 68 gr_context_->releaseResourcesAndAbandonContext(); | 65 gr_context_->releaseResourcesAndAbandonContext(); |
| 69 } | 66 } |
| 70 | 67 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 106 } |
| 110 | 107 |
| 111 void AwRenderThreadContextProvider::InvalidateGrContext(uint32_t state) { | 108 void AwRenderThreadContextProvider::InvalidateGrContext(uint32_t state) { |
| 112 DCHECK(main_thread_checker_.CalledOnValidThread()); | 109 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 113 | 110 |
| 114 if (gr_context_) | 111 if (gr_context_) |
| 115 gr_context_->resetContext(state); | 112 gr_context_->resetContext(state); |
| 116 } | 113 } |
| 117 | 114 |
| 118 void AwRenderThreadContextProvider::SetupLock() { | 115 void AwRenderThreadContextProvider::SetupLock() { |
| 119 context_->SetLock(&context_lock_); | 116 // This context provider is not used on multiple threads. |
| 117 NOTREACHED(); |
| 120 } | 118 } |
| 121 | 119 |
| 122 base::Lock* AwRenderThreadContextProvider::GetLock() { | 120 base::Lock* AwRenderThreadContextProvider::GetLock() { |
| 123 return &context_lock_; | 121 // This context provider is not used on multiple threads. |
| 122 NOTREACHED(); |
| 123 return nullptr; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void AwRenderThreadContextProvider::DeleteCachedResources() { | 126 void AwRenderThreadContextProvider::DeleteCachedResources() { |
| 127 DCHECK(main_thread_checker_.CalledOnValidThread()); | 127 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 128 | 128 |
| 129 if (gr_context_) { | 129 if (gr_context_) { |
| 130 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", | 130 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", |
| 131 TRACE_EVENT_SCOPE_THREAD); | 131 TRACE_EVENT_SCOPE_THREAD); |
| 132 gr_context_->freeGpuResources(); | 132 gr_context_->freeGpuResources(); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 void AwRenderThreadContextProvider::SetLostContextCallback( | 136 void AwRenderThreadContextProvider::SetLostContextCallback( |
| 137 const LostContextCallback& lost_context_callback) { | 137 const LostContextCallback& lost_context_callback) { |
| 138 lost_context_callback_ = lost_context_callback; | 138 // No support for lost context callbacks with in-process GL. |
| 139 } | 139 NOTREACHED(); |
| 140 | |
| 141 void AwRenderThreadContextProvider::OnLostContext() { | |
| 142 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
| 143 | |
| 144 if (!lost_context_callback_.is_null()) | |
| 145 base::ResetAndReturn(&lost_context_callback_).Run(); | |
| 146 if (gr_context_) | |
| 147 gr_context_->abandonContext(); | |
| 148 } | 140 } |
| 149 | 141 |
| 150 } // namespace android_webview | 142 } // namespace android_webview |
| OLD | NEW |