OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 2133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 return context_provider ? context_provider->ContextGL() : NULL; | 2144 return context_provider ? context_provider->ContextGL() : NULL; |
2145 } | 2145 } |
2146 | 2146 |
2147 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 2147 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
2148 ContextProvider* context_provider = | 2148 ContextProvider* context_provider = |
2149 worker_context ? output_surface_->worker_context_provider() | 2149 worker_context ? output_surface_->worker_context_provider() |
2150 : output_surface_->context_provider(); | 2150 : output_surface_->context_provider(); |
2151 return context_provider ? context_provider->GrContext() : NULL; | 2151 return context_provider ? context_provider->GrContext() : NULL; |
2152 } | 2152 } |
2153 | 2153 |
| 2154 void ResourceProvider::FreeGrResources() { |
| 2155 if (!output_surface_) |
| 2156 return; |
| 2157 |
| 2158 ContextProvider* context_provider = |
| 2159 output_surface_->worker_context_provider(); |
| 2160 if (!context_provider) |
| 2161 return; |
| 2162 |
| 2163 // The context lock must be held while accessing the context on a |
| 2164 // worker thread. |
| 2165 base::AutoLock context_lock(*context_provider->GetLock()); |
| 2166 |
| 2167 // Allow context to bind to current thread. |
| 2168 context_provider->DetachFromThread(); |
| 2169 |
| 2170 class GrContext* gr_context = context_provider->GrContext(); |
| 2171 DCHECK(gr_context); |
| 2172 gr_context->freeGpuResources(); |
| 2173 |
| 2174 // Allow context to bind to other threads. |
| 2175 context_provider->DetachFromThread(); |
| 2176 } |
| 2177 |
2154 } // namespace cc | 2178 } // namespace cc |
OLD | NEW |