Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Side by Side Diff: cc/resources/gpu_rasterizer.cc

Issue 1016733002: cc: Free gpu resources when we are invisible or TM is oom. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments addressed. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
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 maxTextures_(kMaxGaneshResourceCacheCount),
62 maxTextureBytes_(kMaxGaneshResourceCacheBytes),
63 cache_cleared_(false) {
64 ContextProvider* worker_context_provider =
vmiura 2015/04/02 19:12:34 As this is in three places, please refactor the co
sohanjg 2015/04/08 09:00:31 Done.
65 resource_provider_->output_surface()->worker_context_provider();
66
67 // The context lock must be held while accessing the context on a
68 // worker thread.
69 base::AutoLock context_lock(*worker_context_provider->GetLock());
70
71 // Allow context to bind to current thread.
72 worker_context_provider->DetachFromThread();
73
74 GrContext* gr_context = worker_context_provider->GrContext();
75 if (gr_context)
76 gr_context->setResourceCacheLimits(maxTextures_, maxTextureBytes_);
77
78 // Allow context to bind to other threads.
79 worker_context_provider->DetachFromThread();
50 } 80 }
51 81
52 GpuRasterizer::~GpuRasterizer() { 82 GpuRasterizer::~GpuRasterizer() {
53 } 83 }
54 84
55 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() { 85 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() {
56 return threaded_gpu_rasterization_enabled_ 86 return threaded_gpu_rasterization_enabled_
57 ? PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES 87 ? PrepareTilesMode::RASTERIZE_PRIORITIZED_TILES
58 : PrepareTilesMode::PREPARE_NONE; 88 : PrepareTilesMode::PREPARE_NONE;
59 } 89 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 canvas->save(); 224 canvas->save();
195 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), 225 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(),
196 tile->contents_scale()); 226 tile->contents_scale());
197 canvas->restore(); 227 canvas->restore();
198 228
199 // Add the canvas and recorded picture to |multi_picture_draw_|. 229 // Add the canvas and recorded picture to |multi_picture_draw_|.
200 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); 230 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording());
201 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); 231 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get());
202 } 232 }
203 233
234 void GpuRasterizer::SetZeroMemoryLimit() {
235 ContextProvider* context_provider =
236 resource_provider()->output_surface()->worker_context_provider();
237
238 // The context lock must be held while accessing the context on a
239 // worker thread.
240 base::AutoLock context_lock(*context_provider->GetLock());
241
242 // Allow context to bind to current thread.
243 context_provider->DetachFromThread();
244
245 // Clear resource cache.
246 GrContext* gr_context = context_provider->GrContext();
247 DCHECK(gr_context);
248 gr_context->setResourceCacheLimits(0, 0);
249
250 // Allow context to bind to other threads.
251 context_provider->DetachFromThread();
252 cache_cleared_ = true;
253 }
254
255 void GpuRasterizer::SetDefaultMemoryLimit() {
256 if (!cache_cleared_)
257 return;
258
259 ContextProvider* context_provider =
260 resource_provider()->output_surface()->worker_context_provider();
261
262 // The context lock must be held while accessing the context on a
263 // worker thread.
264 base::AutoLock context_lock(*context_provider->GetLock());
265
266 // Allow context to bind to current thread.
267 context_provider->DetachFromThread();
268
269 // Restore resource cache.
270 GrContext* gr_context = context_provider->GrContext();
271 DCHECK(gr_context);
272 gr_context->setResourceCacheLimits(maxTextures_, maxTextureBytes_);
273
274 // Allow context to bind to other threads.
275 context_provider->DetachFromThread();
276 }
277
204 } // namespace cc 278 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698