OLD | NEW |
(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 #ifndef CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_ |
| 6 #define CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_ |
| 7 |
| 8 #include <cstdint> |
| 9 #include <memory> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "cc/base/cc_export.h" |
| 13 |
| 14 class GrContext; |
| 15 |
| 16 namespace gpu { |
| 17 class ContextSupport; |
| 18 } |
| 19 |
| 20 namespace cc { |
| 21 |
| 22 // ContextCacheController manages clearing cached data on ContextProvider when |
| 23 // appropriate. Currently, cache clearing happens when the ContextProvider |
| 24 // transitions from visible to not visible. As a ContextProvider may have |
| 25 // multiple clients, ContextCacheController tracks visibility across all |
| 26 // clients and only cleans up when appropriate. |
| 27 // |
| 28 // Note: Virtuals on this function are for testing only. This function is not |
| 29 // designed to have multiple implementations. |
| 30 class CC_EXPORT ContextCacheController { |
| 31 public: |
| 32 class CC_EXPORT ScopedVisibility { |
| 33 public: |
| 34 ~ScopedVisibility(); |
| 35 |
| 36 private: |
| 37 friend class ContextCacheController; |
| 38 ScopedVisibility(); |
| 39 void Release(); |
| 40 |
| 41 bool released_ = false; |
| 42 }; |
| 43 |
| 44 explicit ContextCacheController(gpu::ContextSupport* context_support); |
| 45 virtual ~ContextCacheController(); |
| 46 |
| 47 void SetGrContext(GrContext* gr_context); |
| 48 |
| 49 // Clients of the owning ContextProvider should call this function when they |
| 50 // become visible. The returned ScopedVisibility pointer must be passed back |
| 51 // to ClientBecameNotVisible or it will DCHECK in its destructor. |
| 52 virtual std::unique_ptr<ScopedVisibility> ClientBecameVisible(); |
| 53 |
| 54 // When a client becomes not visible (either due to a visibility change or |
| 55 // because it is being deleted), it must pass back any ScopedVisibility |
| 56 // pointers it owns via this function. |
| 57 virtual void ClientBecameNotVisible( |
| 58 std::unique_ptr<ScopedVisibility> scoped_visibility); |
| 59 |
| 60 protected: |
| 61 std::unique_ptr<ScopedVisibility> CreateScopedVisibilityForTesting() const; |
| 62 void ReleaseScopedVisibilityForTesting( |
| 63 std::unique_ptr<ScopedVisibility> scoped_visibility) const; |
| 64 |
| 65 private: |
| 66 gpu::ContextSupport* context_support_; |
| 67 GrContext* gr_context_ = nullptr; |
| 68 |
| 69 uint32_t num_clients_visible_ = 0; |
| 70 }; |
| 71 |
| 72 } // namespace cc |
| 73 |
| 74 #endif // CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_ |
OLD | NEW |