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

Side by Side Diff: cc/output/context_cache_controller.cc

Issue 2278283003: Refactor client visibility handling (Closed)
Patch Set: fix compositor_unittests Created 4 years, 3 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
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/output/context_cache_controller.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h"
9 #include "gpu/command_buffer/client/context_support.h"
10 #include "third_party/skia/include/gpu/GrContext.h"
11
12 namespace cc {
13 ContextCacheController::ScopedVisibility::ScopedVisibility() = default;
14
15 ContextCacheController::ScopedVisibility::~ScopedVisibility() {
16 DCHECK(released_);
17 }
18
19 void ContextCacheController::ScopedVisibility::Release() {
20 DCHECK(!released_);
21 released_ = true;
22 }
23
24 ContextCacheController::ContextCacheController(
25 gpu::ContextSupport* context_support)
26 : context_support_(context_support) {}
27
28 void ContextCacheController::SetGrContext(GrContext* gr_context) {
29 gr_context_ = gr_context;
30 }
31
32 std::unique_ptr<ContextCacheController::ScopedVisibility>
33 ContextCacheController::ClientBecameVisible() {
34 bool became_visible = num_clients_visible_ == 0;
35 ++num_clients_visible_;
36
37 if (became_visible)
38 context_support_->SetAggressivelyFreeResources(false);
39
40 return base::WrapUnique(new ScopedVisibility());
41 }
42
43 void ContextCacheController::ClientBecameNotVisible(
44 std::unique_ptr<ScopedVisibility> scoped_visibility) {
45 DCHECK(scoped_visibility);
46 scoped_visibility->Release();
47
48 DCHECK_GT(num_clients_visible_, 0u);
49 --num_clients_visible_;
50
51 if (num_clients_visible_ == 0) {
52 if (gr_context_)
53 gr_context_->freeGpuResources();
54 context_support_->SetAggressivelyFreeResources(true);
55 }
56 }
57
58 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698