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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // relatively unused. | 59 // relatively unused. |
60 limits.start_transfer_buffer_size = 64 * 1024; | 60 limits.start_transfer_buffer_size = 64 * 1024; |
61 limits.min_transfer_buffer_size = 64 * 1024; | 61 limits.min_transfer_buffer_size = 64 * 1024; |
62 | 62 |
63 context_.reset(gpu::GLInProcessContext::Create( | 63 context_.reset(gpu::GLInProcessContext::Create( |
64 service, surface, surface->IsOffscreen(), gfx::kNullAcceleratedWidget, | 64 service, surface, surface->IsOffscreen(), gfx::kNullAcceleratedWidget, |
65 nullptr /* share_context */, attributes, limits, nullptr, nullptr)); | 65 nullptr /* share_context */, attributes, limits, nullptr, nullptr)); |
66 | 66 |
67 context_->GetImplementation()->SetLostContextCallback(base::Bind( | 67 context_->GetImplementation()->SetLostContextCallback(base::Bind( |
68 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); | 68 &AwRenderThreadContextProvider::OnLostContext, base::Unretained(this))); |
| 69 |
| 70 cache_controller_.reset( |
| 71 new cc::ContextCacheController(context_->GetImplementation())); |
69 } | 72 } |
70 | 73 |
71 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { | 74 AwRenderThreadContextProvider::~AwRenderThreadContextProvider() { |
72 DCHECK(main_thread_checker_.CalledOnValidThread()); | 75 DCHECK(main_thread_checker_.CalledOnValidThread()); |
73 if (gr_context_) | 76 if (gr_context_) |
74 gr_context_->releaseResourcesAndAbandonContext(); | 77 gr_context_->releaseResourcesAndAbandonContext(); |
75 } | 78 } |
76 | 79 |
77 uint32_t AwRenderThreadContextProvider::GetCopyTextureInternalFormat() { | 80 uint32_t AwRenderThreadContextProvider::GetCopyTextureInternalFormat() { |
78 // The attributes used in the constructor included an alpha channel. | 81 // The attributes used in the constructor included an alpha channel. |
(...skipping 28 matching lines...) Expand all Loading... |
107 DCHECK(main_thread_checker_.CalledOnValidThread()); | 110 DCHECK(main_thread_checker_.CalledOnValidThread()); |
108 | 111 |
109 if (gr_context_) | 112 if (gr_context_) |
110 return gr_context_.get(); | 113 return gr_context_.get(); |
111 | 114 |
112 sk_sp<GrGLInterface> interface( | 115 sk_sp<GrGLInterface> interface( |
113 skia_bindings::CreateGLES2InterfaceBindings(ContextGL())); | 116 skia_bindings::CreateGLES2InterfaceBindings(ContextGL())); |
114 gr_context_ = sk_sp<::GrContext>(GrContext::Create( | 117 gr_context_ = sk_sp<::GrContext>(GrContext::Create( |
115 // GrContext takes ownership of |interface|. | 118 // GrContext takes ownership of |interface|. |
116 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); | 119 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); |
| 120 cache_controller_->SetGrContext(gr_context_.get()); |
117 return gr_context_.get(); | 121 return gr_context_.get(); |
118 } | 122 } |
119 | 123 |
| 124 gpu::ContextSupport* AwRenderThreadContextProvider::CacheController() { |
| 125 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 126 return cache_controller_.get(); |
| 127 } |
| 128 |
120 void AwRenderThreadContextProvider::InvalidateGrContext(uint32_t state) { | 129 void AwRenderThreadContextProvider::InvalidateGrContext(uint32_t state) { |
121 DCHECK(main_thread_checker_.CalledOnValidThread()); | 130 DCHECK(main_thread_checker_.CalledOnValidThread()); |
122 | 131 |
123 if (gr_context_) | 132 if (gr_context_) |
124 gr_context_->resetContext(state); | 133 gr_context_->resetContext(state); |
125 } | 134 } |
126 | 135 |
127 base::Lock* AwRenderThreadContextProvider::GetLock() { | 136 base::Lock* AwRenderThreadContextProvider::GetLock() { |
128 // This context provider is not used on multiple threads. | 137 // This context provider is not used on multiple threads. |
129 NOTREACHED(); | 138 NOTREACHED(); |
130 return nullptr; | 139 return nullptr; |
131 } | 140 } |
132 | 141 |
133 void AwRenderThreadContextProvider::DeleteCachedResources() { | |
134 DCHECK(main_thread_checker_.CalledOnValidThread()); | |
135 | |
136 if (gr_context_) { | |
137 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", | |
138 TRACE_EVENT_SCOPE_THREAD); | |
139 gr_context_->freeGpuResources(); | |
140 } | |
141 } | |
142 | |
143 void AwRenderThreadContextProvider::SetLostContextCallback( | 142 void AwRenderThreadContextProvider::SetLostContextCallback( |
144 const LostContextCallback& lost_context_callback) { | 143 const LostContextCallback& lost_context_callback) { |
145 lost_context_callback_ = lost_context_callback; | 144 lost_context_callback_ = lost_context_callback; |
146 } | 145 } |
147 | 146 |
148 void AwRenderThreadContextProvider::OnLostContext() { | 147 void AwRenderThreadContextProvider::OnLostContext() { |
149 DCHECK(main_thread_checker_.CalledOnValidThread()); | 148 DCHECK(main_thread_checker_.CalledOnValidThread()); |
150 | 149 |
151 if (!lost_context_callback_.is_null()) | 150 if (!lost_context_callback_.is_null()) |
152 lost_context_callback_.Run(); | 151 lost_context_callback_.Run(); |
153 if (gr_context_) | 152 if (gr_context_) |
154 gr_context_->abandonContext(); | 153 gr_context_->abandonContext(); |
155 } | 154 } |
156 | 155 |
157 } // namespace android_webview | 156 } // namespace android_webview |
OLD | NEW |