| Index: cc/output/context_cache_controller.h
|
| diff --git a/cc/output/context_cache_controller.h b/cc/output/context_cache_controller.h
|
| index 03f7e2cd74f9117e11cb95ac6db4a747199301f7..1e45e2593ab0d4398ea2c34fc60133de74efcbc0 100644
|
| --- a/cc/output/context_cache_controller.h
|
| +++ b/cc/output/context_cache_controller.h
|
| @@ -10,11 +10,13 @@
|
|
|
| #include "base/macros.h"
|
| #include "base/memory/ref_counted.h"
|
| +#include "base/memory/weak_ptr.h"
|
| #include "cc/base/cc_export.h"
|
|
|
| class GrContext;
|
|
|
| namespace base {
|
| +class Lock;
|
| class SingleThreadTaskRunner;
|
| }
|
|
|
| @@ -25,26 +27,26 @@ 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.
|
| +// appropriate. Currently, cache clearing is triggered when the Context
|
| +// provider transitions from Visible to Not Visible, or from Busy to Idle. As a
|
| +// ContextProvider may have multiple clients, ContextCacheController tracks
|
| +// visibility and idle status across all clients and only cleans up when
|
| +// appropriate.
|
| class CC_EXPORT ContextCacheController {
|
| public:
|
| - class CC_EXPORT ScopedVisibility {
|
| + class CC_EXPORT ScopedToken {
|
| public:
|
| - ~ScopedVisibility();
|
| + ~ScopedToken();
|
|
|
| private:
|
| friend class ContextCacheController;
|
| - ScopedVisibility();
|
| + ScopedToken();
|
| void Release();
|
|
|
| bool released_ = false;
|
| };
|
| + using ScopedVisibility = ScopedToken;
|
| + using ScopedBusy = ScopedToken;
|
|
|
| ContextCacheController(
|
| gpu::ContextSupport* context_support,
|
| @@ -52,6 +54,7 @@ class CC_EXPORT ContextCacheController {
|
| virtual ~ContextCacheController();
|
|
|
| void SetGrContext(GrContext* gr_context);
|
| + void SetLock(base::Lock* lock);
|
|
|
| // Clients of the owning ContextProvider should call this function when they
|
| // become visible. The returned ScopedVisibility pointer must be passed back
|
| @@ -64,17 +67,35 @@ class CC_EXPORT ContextCacheController {
|
| virtual void ClientBecameNotVisible(
|
| std::unique_ptr<ScopedVisibility> scoped_visibility);
|
|
|
| - protected:
|
| - std::unique_ptr<ScopedVisibility> CreateScopedVisibilityForTesting() const;
|
| - void ReleaseScopedVisibilityForTesting(
|
| - std::unique_ptr<ScopedVisibility> scoped_visibility) const;
|
| + // Clients of the owning ContextProvider may call this function when they
|
| + // become busy. The returned ScopedBusy pointer must be passed back
|
| + // to ClientBecameNotBusy or it will DCHECK in its destructor.
|
| + std::unique_ptr<ScopedBusy> ClientBecameBusy();
|
| +
|
| + // When a client becomes not busy, it must pass back any ScopedBusy
|
| + // pointers it owns via this function.
|
| + void ClientBecameNotBusy(std::unique_ptr<ScopedBusy> scoped_busy);
|
|
|
| private:
|
| + void OnIdle(uint32_t idle_generation);
|
| +
|
| gpu::ContextSupport* context_support_;
|
| scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
| GrContext* gr_context_ = nullptr;
|
|
|
| uint32_t num_clients_visible_ = 0;
|
| + uint32_t num_clients_busy_ = 0;
|
| +
|
| + // If set, |context_lock_| is used to ensure we safely access our data when
|
| + // in an idle callback.
|
| + base::Lock* context_lock_ = nullptr;
|
| +
|
| + // Used to invalidate idle callbacks. We can't just cancel |idle_callback_|,
|
| + // as we must be able to invalidate from multiple threads, and idle_callback_
|
| + // is not threadsafe.
|
| + uint32_t current_idle_generation_ = 0;
|
| +
|
| + base::WeakPtrFactory<ContextCacheController> weak_factory_;
|
| };
|
|
|
| } // namespace cc
|
|
|