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

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

Issue 2278283003: Refactor client visibility handling (Closed)
Patch Set: more fixes 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
« no previous file with comments | « cc/output/context_cache_controller.h ('k') | cc/output/context_cache_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ContextCacheController::~ContextCacheController() = default;
29
30 void ContextCacheController::SetGrContext(GrContext* gr_context) {
31 gr_context_ = gr_context;
32 }
33
34 std::unique_ptr<ContextCacheController::ScopedVisibility>
35 ContextCacheController::ClientBecameVisible() {
36 bool became_visible = num_clients_visible_ == 0;
37 ++num_clients_visible_;
38
39 if (became_visible)
40 context_support_->SetAggressivelyFreeResources(false);
41
42 return base::WrapUnique(new ScopedVisibility());
43 }
44
45 void ContextCacheController::ClientBecameNotVisible(
46 std::unique_ptr<ScopedVisibility> scoped_visibility) {
47 DCHECK(scoped_visibility);
48 scoped_visibility->Release();
49
50 DCHECK_GT(num_clients_visible_, 0u);
51 --num_clients_visible_;
52
53 if (num_clients_visible_ == 0) {
54 if (gr_context_)
55 gr_context_->freeGpuResources();
56 context_support_->SetAggressivelyFreeResources(true);
57 }
58 }
59
60 std::unique_ptr<ContextCacheController::ScopedVisibility>
61 ContextCacheController::CreateScopedVisibilityForTesting() const {
62 return base::WrapUnique(new ScopedVisibility());
63 }
64
65 void ContextCacheController::ReleaseScopedVisibilityForTesting(
66 std::unique_ptr<ScopedVisibility> scoped_visibility) const {
67 scoped_visibility->Release();
68 }
69
70 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/context_cache_controller.h ('k') | cc/output/context_cache_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698