Index: cc/output/context_cache_controller.h |
diff --git a/cc/output/context_cache_controller.h b/cc/output/context_cache_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d7ccd9755a3d407e1d29cb470b62f51cead8384c |
--- /dev/null |
+++ b/cc/output/context_cache_controller.h |
@@ -0,0 +1,74 @@ |
+// 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. |
+ |
+#ifndef CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_ |
+#define CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_ |
+ |
+#include <cstdint> |
+#include <memory> |
+ |
+#include "base/macros.h" |
+#include "cc/base/cc_export.h" |
+ |
+class GrContext; |
+ |
+namespace gpu { |
+class ContextSupport; |
+} |
+ |
+namespace cc { |
+ |
+// ContextCacheController manages clearing cached data on ContextProvider when |
+// appropriate. Currently, cache clearing happens when the ContextProvider |
+// transitions from visible to not visible. As a ContextProvider may have |
+// multiple clients, ContextCacheController tracks visibility across all |
+// clients and only cleans up when appropriate. |
+// |
+// Note: Virtuals on this function are for testing only. This function is not |
+// designed to have multiple implementations. |
+class CC_EXPORT ContextCacheController { |
+ public: |
+ class ScopedVisibility { |
+ public: |
+ ~ScopedVisibility(); |
+ |
+ private: |
+ friend class ContextCacheController; |
+ ScopedVisibility(); |
+ void Release(); |
+ |
+ bool released_ = false; |
+ }; |
+ |
+ explicit ContextCacheController(gpu::ContextSupport* context_support); |
+ virtual ~ContextCacheController(); |
+ |
+ void SetGrContext(GrContext* gr_context); |
+ |
+ // Clients of the owning ContextProvider should call this function when they |
+ // become visible. The returned ScopedVisibility pointer must be passed back |
+ // to ClientBecameNotVisible or it will DCHECK in its destructor. |
+ virtual std::unique_ptr<ScopedVisibility> ClientBecameVisible(); |
danakj
2016/08/29 23:56:20
If you are going to make these virtual I think the
ericrk
2016/08/30 18:18:58
Made these un-virtual - seemed to be adding too mu
|
+ |
+ // When a client becomes not visible (either due to a visibility change or |
+ // because it is being deleted), it must pass back any ScopedVisibility |
+ // pointers it owns via this function. |
+ virtual void ClientBecameNotVisible( |
+ std::unique_ptr<ScopedVisibility> scoped_visibility); |
+ |
+ protected: |
+ std::unique_ptr<ScopedVisibility> CreateScopedVisibilityForTesting() const; |
danakj
2016/08/29 23:56:20
Can you TODO to remove these when c++11 gmock supp
ericrk
2016/08/30 18:18:58
made un-virtual
|
+ void ReleaseScopedVisibilityForTesting( |
+ std::unique_ptr<ScopedVisibility> scoped_visibility) const; |
+ |
+ private: |
+ gpu::ContextSupport* context_support_; |
+ GrContext* gr_context_ = nullptr; |
+ |
+ uint32_t num_clients_visible_ = 0; |
+}; |
+ |
+} // namespace cc |
+ |
+#endif // CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_ |