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

Unified Diff: cc/output/context_cache_controller.cc

Issue 2278283003: Refactor client visibility handling (Closed)
Patch Set: fix compositor_unittests Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: cc/output/context_cache_controller.cc
diff --git a/cc/output/context_cache_controller.cc b/cc/output/context_cache_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2b5e0a89497534b559c3ec7230c14504c884a270
--- /dev/null
+++ b/cc/output/context_cache_controller.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/output/context_cache_controller.h"
+
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "gpu/command_buffer/client/context_support.h"
+#include "third_party/skia/include/gpu/GrContext.h"
+
+namespace cc {
+ContextCacheController::ScopedVisibility::ScopedVisibility() = default;
+
+ContextCacheController::ScopedVisibility::~ScopedVisibility() {
+ DCHECK(released_);
+}
+
+void ContextCacheController::ScopedVisibility::Release() {
+ DCHECK(!released_);
+ released_ = true;
+}
+
+ContextCacheController::ContextCacheController(
+ gpu::ContextSupport* context_support)
+ : context_support_(context_support) {}
+
+void ContextCacheController::SetGrContext(GrContext* gr_context) {
+ gr_context_ = gr_context;
+}
+
+std::unique_ptr<ContextCacheController::ScopedVisibility>
+ContextCacheController::ClientBecameVisible() {
+ bool became_visible = num_clients_visible_ == 0;
+ ++num_clients_visible_;
+
+ if (became_visible)
+ context_support_->SetAggressivelyFreeResources(false);
+
+ return base::WrapUnique(new ScopedVisibility());
+}
+
+void ContextCacheController::ClientBecameNotVisible(
+ std::unique_ptr<ScopedVisibility> scoped_visibility) {
+ DCHECK(scoped_visibility);
+ scoped_visibility->Release();
+
+ DCHECK_GT(num_clients_visible_, 0u);
+ --num_clients_visible_;
+
+ if (num_clients_visible_ == 0) {
+ if (gr_context_)
+ gr_context_->freeGpuResources();
+ context_support_->SetAggressivelyFreeResources(true);
+ }
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698