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" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "cc/debug/devtools_instrumentation.h" | 12 #include "cc/debug/devtools_instrumentation.h" |
| 13 #include "cc/debug/frame_viewer_instrumentation.h" | 13 #include "cc/debug/frame_viewer_instrumentation.h" |
| 14 #include "cc/output/context_provider.h" | 14 #include "cc/output/context_provider.h" |
| 15 #include "cc/resources/raster_buffer.h" | 15 #include "cc/resources/raster_buffer.h" |
| 16 #include "cc/resources/raster_source.h" | 16 #include "cc/resources/raster_source.h" |
| 17 #include "cc/resources/resource.h" | 17 #include "cc/resources/resource.h" |
| 18 #include "cc/resources/resource_provider.h" | 18 #include "cc/resources/resource_provider.h" |
| 19 #include "cc/resources/scoped_gpu_raster.h" | 19 #include "cc/resources/scoped_gpu_raster.h" |
| 20 #include "cc/resources/tile_manager.h" | 20 #include "cc/resources/tile_manager.h" |
| 21 #include "gpu/command_buffer/client/gles2_interface.h" | 21 #include "gpu/command_buffer/client/gles2_interface.h" |
| 22 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | 22 #include "third_party/skia/include/core/SkMultiPictureDraw.h" |
| 23 #include "third_party/skia/include/core/SkPictureRecorder.h" | 23 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 24 #include "third_party/skia/include/core/SkSurface.h" | 24 #include "third_party/skia/include/core/SkSurface.h" |
| 25 #include "third_party/skia/include/gpu/GrContext.h" | 25 #include "third_party/skia/include/gpu/GrContext.h" |
| 26 | 26 |
| 27 namespace { | |
| 28 // The limit of the number of GPU resources we hold in the GrContext's | |
| 29 // GPU cache. | |
| 30 const int kMaxGaneshResourceCacheCount = 2048; | |
|
enne (OOO)
2015/04/08 17:19:34
Maybe you could make these LayerTreeSettings, and
sohanjg
2015/04/09 09:20:44
OK, but the memory limit we are maintaining in the
hendrikw
2015/04/09 15:43:45
I agree with enne (I think they meant LayerTreeHos
| |
| 31 | |
| 32 // The limit of the bytes allocated toward GPU resources in the GrContext's | |
| 33 // GPU cache. | |
| 34 const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 27 namespace cc { | 38 namespace cc { |
| 28 | 39 |
| 29 // static | 40 // static |
| 30 scoped_ptr<GpuRasterizer> GpuRasterizer::Create( | 41 scoped_ptr<GpuRasterizer> GpuRasterizer::Create( |
| 31 ContextProvider* context_provider, | 42 ContextProvider* context_provider, |
| 32 ResourceProvider* resource_provider, | 43 ResourceProvider* resource_provider, |
| 33 bool use_distance_field_text, | 44 bool use_distance_field_text, |
| 34 bool threaded_gpu_rasterization_enabled, | 45 bool threaded_gpu_rasterization_enabled, |
| 35 int msaa_sample_count) { | 46 int msaa_sample_count) { |
| 36 return make_scoped_ptr<GpuRasterizer>(new GpuRasterizer( | 47 return make_scoped_ptr<GpuRasterizer>(new GpuRasterizer( |
| 37 context_provider, resource_provider, use_distance_field_text, | 48 context_provider, resource_provider, use_distance_field_text, |
| 38 threaded_gpu_rasterization_enabled, msaa_sample_count)); | 49 threaded_gpu_rasterization_enabled, msaa_sample_count)); |
| 39 } | 50 } |
| 40 | 51 |
| 41 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, | 52 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, |
| 42 ResourceProvider* resource_provider, | 53 ResourceProvider* resource_provider, |
| 43 bool use_distance_field_text, | 54 bool use_distance_field_text, |
| 44 bool threaded_gpu_rasterization_enabled, | 55 bool threaded_gpu_rasterization_enabled, |
| 45 int msaa_sample_count) | 56 int msaa_sample_count) |
| 46 : resource_provider_(resource_provider), | 57 : resource_provider_(resource_provider), |
| 47 use_distance_field_text_(use_distance_field_text), | 58 use_distance_field_text_(use_distance_field_text), |
| 48 threaded_gpu_rasterization_enabled_(threaded_gpu_rasterization_enabled), | 59 threaded_gpu_rasterization_enabled_(threaded_gpu_rasterization_enabled), |
| 49 msaa_sample_count_(msaa_sample_count) { | 60 msaa_sample_count_(msaa_sample_count), |
| 61 max_textures_(kMaxGaneshResourceCacheCount), | |
| 62 max_texture_bytes_(kMaxGaneshResourceCacheBytes), | |
| 63 default_memory_limit_set_(true) { | |
| 64 SetGrCacheLimits(max_textures_, max_texture_bytes_); | |
| 50 } | 65 } |
| 51 | 66 |
| 52 GpuRasterizer::~GpuRasterizer() { | 67 GpuRasterizer::~GpuRasterizer() { |
| 53 } | 68 } |
| 54 | 69 |
| 55 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() { | 70 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() { |
| 56 return threaded_gpu_rasterization_enabled_ | 71 return threaded_gpu_rasterization_enabled_ |
| 57 ? PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES | 72 ? PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES |
| 58 : PrepareTilesMode::PREPARE_NONE; | 73 : PrepareTilesMode::PREPARE_NONE; |
| 59 } | 74 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 canvas->save(); | 209 canvas->save(); |
| 195 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), | 210 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), |
| 196 tile->contents_scale()); | 211 tile->contents_scale()); |
| 197 canvas->restore(); | 212 canvas->restore(); |
| 198 | 213 |
| 199 // Add the canvas and recorded picture to |multi_picture_draw_|. | 214 // Add the canvas and recorded picture to |multi_picture_draw_|. |
| 200 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 215 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
| 201 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); | 216 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); |
| 202 } | 217 } |
| 203 | 218 |
| 219 void GpuRasterizer::SetMemoryLimits(bool visible, size_t memory_limit_bytes) { | |
|
hendrikw
2015/04/09 15:43:45
Wouldn't it make sense to call freeGpuResources()
| |
| 220 if (!visible || memory_limit_bytes == 0) { | |
| 221 SetGrCacheLimits(0, 0); | |
| 222 default_memory_limit_set_ = false; | |
| 223 } else if (!default_memory_limit_set_) { | |
| 224 SetGrCacheLimits(max_textures_, max_texture_bytes_); | |
| 225 } | |
| 226 } | |
| 227 | |
| 228 void GpuRasterizer::SetGrCacheLimits(int textures, int texture_bytes) { | |
| 229 ContextProvider* context_provider = | |
| 230 resource_provider()->output_surface()->worker_context_provider(); | |
| 231 | |
| 232 // The context lock must be held while accessing the context on a | |
| 233 // worker thread. | |
| 234 base::AutoLock context_lock(*context_provider->GetLock()); | |
| 235 | |
| 236 // Allow context to bind to current thread. | |
| 237 context_provider->DetachFromThread(); | |
| 238 | |
| 239 GrContext* gr_context = context_provider->GrContext(); | |
| 240 DCHECK(gr_context); | |
| 241 gr_context->setResourceCacheLimits(textures, texture_bytes); | |
| 242 | |
| 243 // Allow context to bind to other threads. | |
| 244 context_provider->DetachFromThread(); | |
| 245 } | |
| 246 | |
| 204 } // namespace cc | 247 } // namespace cc |
| OLD | NEW |