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