Chromium Code Reviews| 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 "cc/resources/gpu_rasterizer.h" | 5 #include "cc/resources/gpu_rasterizer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 } | 39 } |
| 40 | 40 |
| 41 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, | 41 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, |
| 42 ResourceProvider* resource_provider, | 42 ResourceProvider* resource_provider, |
| 43 bool use_distance_field_text, | 43 bool use_distance_field_text, |
| 44 bool threaded_gpu_rasterization_enabled, | 44 bool threaded_gpu_rasterization_enabled, |
| 45 int msaa_sample_count) | 45 int msaa_sample_count) |
| 46 : resource_provider_(resource_provider), | 46 : resource_provider_(resource_provider), |
| 47 use_distance_field_text_(use_distance_field_text), | 47 use_distance_field_text_(use_distance_field_text), |
| 48 threaded_gpu_rasterization_enabled_(threaded_gpu_rasterization_enabled), | 48 threaded_gpu_rasterization_enabled_(threaded_gpu_rasterization_enabled), |
| 49 msaa_sample_count_(msaa_sample_count) { | 49 msaa_sample_count_(msaa_sample_count), |
| 50 maxTextures_(0), | |
| 51 maxTextureBytes_(0), | |
| 52 cache_cleared_(false) { | |
| 50 } | 53 } |
| 51 | 54 |
| 52 GpuRasterizer::~GpuRasterizer() { | 55 GpuRasterizer::~GpuRasterizer() { |
| 53 } | 56 } |
| 54 | 57 |
| 55 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() { | 58 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() { |
| 56 return threaded_gpu_rasterization_enabled_ | 59 return threaded_gpu_rasterization_enabled_ |
| 57 ? PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES | 60 ? PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES |
| 58 : PrepareTilesMode::PREPARE_NONE; | 61 : PrepareTilesMode::PREPARE_NONE; |
| 59 } | 62 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 canvas->save(); | 187 canvas->save(); |
| 185 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), | 188 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), |
| 186 tile->contents_scale()); | 189 tile->contents_scale()); |
| 187 canvas->restore(); | 190 canvas->restore(); |
| 188 | 191 |
| 189 // Add the canvas and recorded picture to |multi_picture_draw_|. | 192 // Add the canvas and recorded picture to |multi_picture_draw_|. |
| 190 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 193 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
| 191 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); | 194 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); |
| 192 } | 195 } |
| 193 | 196 |
| 197 void GpuRasterizer::ClearCache() { | |
| 198 ContextProvider* context_provider = | |
| 199 resource_provider()->output_surface()->worker_context_provider(); | |
| 200 | |
| 201 // The context lock must be held while accessing the context on a | |
| 202 // worker thread. | |
| 203 base::AutoLock context_lock(*context_provider->GetLock()); | |
| 204 | |
| 205 // Allow context to bind to current thread. | |
| 206 context_provider->DetachFromThread(); | |
| 207 | |
| 208 // Save old limits and clear resource cache. | |
| 209 GrContext* gr_context = context_provider->GrContext(); | |
| 210 DCHECK(gr_context); | |
| 211 gr_context->getResourceCacheLimits(&maxTextures_, &maxTextureBytes_); | |
|
enne (OOO)
2015/03/31 18:43:05
Who sets these limits in the first place? It's wei
| |
| 212 gr_context->setResourceCacheLimits(0, 0); | |
| 213 | |
| 214 // Allow context to bind to other threads. | |
| 215 context_provider->DetachFromThread(); | |
| 216 cache_cleared_ = true; | |
| 217 } | |
| 218 | |
| 219 void GpuRasterizer::RestoreCacheLimits() { | |
| 220 if (!cache_cleared_) | |
| 221 return; | |
| 222 | |
| 223 ContextProvider* context_provider = | |
| 224 resource_provider()->output_surface()->worker_context_provider(); | |
| 225 | |
| 226 // The context lock must be held while accessing the context on a | |
| 227 // worker thread. | |
| 228 base::AutoLock context_lock(*context_provider->GetLock()); | |
| 229 | |
| 230 // Allow context to bind to current thread. | |
| 231 context_provider->DetachFromThread(); | |
| 232 | |
| 233 // Restore resource cache. | |
| 234 GrContext* gr_context = context_provider->GrContext(); | |
| 235 DCHECK(gr_context); | |
| 236 gr_context->setResourceCacheLimits(maxTextures_, maxTextureBytes_); | |
| 237 | |
| 238 // Allow context to bind to other threads. | |
| 239 context_provider->DetachFromThread(); | |
| 240 } | |
| 241 | |
| 194 } // namespace cc | 242 } // namespace cc |
| OLD | NEW |