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

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

Issue 2366033002: Revert of Idle cleanup for worker context (Closed)
Patch Set: Created 4 years, 2 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/BUILD.gn ('k') | cc/output/context_cache_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_ 5 #ifndef CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_
6 #define CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_ 6 #define CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_
7 7
8 #include <cstdint> 8 #include <cstdint>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "cc/base/cc_export.h" 13 #include "cc/base/cc_export.h"
15 14
16 class GrContext; 15 class GrContext;
17 16
18 namespace base { 17 namespace base {
19 class Lock;
20 class SingleThreadTaskRunner; 18 class SingleThreadTaskRunner;
21 } 19 }
22 20
23 namespace gpu { 21 namespace gpu {
24 class ContextSupport; 22 class ContextSupport;
25 } 23 }
26 24
27 namespace cc { 25 namespace cc {
28 26
29 // ContextCacheController manages clearing cached data on ContextProvider when 27 // ContextCacheController manages clearing cached data on ContextProvider when
30 // appropriate. Currently, cache clearing is triggered when the Context 28 // appropriate. Currently, cache clearing happens when the ContextProvider
31 // provider transitions from Visible to Not Visible, or from Busy to Idle. As a 29 // transitions from visible to not visible. As a ContextProvider may have
32 // ContextProvider may have multiple clients, ContextCacheController tracks 30 // multiple clients, ContextCacheController tracks visibility across all
33 // visibility and idle status across all clients and only cleans up when 31 // clients and only cleans up when appropriate.
34 // appropriate. 32 //
33 // Note: Virtuals on this function are for testing only. This function is not
34 // designed to have multiple implementations.
35 class CC_EXPORT ContextCacheController { 35 class CC_EXPORT ContextCacheController {
36 public: 36 public:
37 class CC_EXPORT ScopedToken { 37 class CC_EXPORT ScopedVisibility {
38 public: 38 public:
39 ~ScopedToken(); 39 ~ScopedVisibility();
40 40
41 private: 41 private:
42 friend class ContextCacheController; 42 friend class ContextCacheController;
43 ScopedToken(); 43 ScopedVisibility();
44 void Release(); 44 void Release();
45 45
46 bool released_ = false; 46 bool released_ = false;
47 }; 47 };
48 using ScopedVisibility = ScopedToken;
49 using ScopedBusy = ScopedToken;
50 48
51 ContextCacheController( 49 ContextCacheController(
52 gpu::ContextSupport* context_support, 50 gpu::ContextSupport* context_support,
53 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 51 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
54 virtual ~ContextCacheController(); 52 virtual ~ContextCacheController();
55 53
56 void SetGrContext(GrContext* gr_context); 54 void SetGrContext(GrContext* gr_context);
57 void SetLock(base::Lock* lock);
58 55
59 // Clients of the owning ContextProvider should call this function when they 56 // Clients of the owning ContextProvider should call this function when they
60 // become visible. The returned ScopedVisibility pointer must be passed back 57 // become visible. The returned ScopedVisibility pointer must be passed back
61 // to ClientBecameNotVisible or it will DCHECK in its destructor. 58 // to ClientBecameNotVisible or it will DCHECK in its destructor.
62 virtual std::unique_ptr<ScopedVisibility> ClientBecameVisible(); 59 virtual std::unique_ptr<ScopedVisibility> ClientBecameVisible();
63 60
64 // When a client becomes not visible (either due to a visibility change or 61 // When a client becomes not visible (either due to a visibility change or
65 // because it is being deleted), it must pass back any ScopedVisibility 62 // because it is being deleted), it must pass back any ScopedVisibility
66 // pointers it owns via this function. 63 // pointers it owns via this function.
67 virtual void ClientBecameNotVisible( 64 virtual void ClientBecameNotVisible(
68 std::unique_ptr<ScopedVisibility> scoped_visibility); 65 std::unique_ptr<ScopedVisibility> scoped_visibility);
69 66
70 // Clients of the owning ContextProvider may call this function when they 67 protected:
71 // become busy. The returned ScopedBusy pointer must be passed back 68 std::unique_ptr<ScopedVisibility> CreateScopedVisibilityForTesting() const;
72 // to ClientBecameNotBusy or it will DCHECK in its destructor. 69 void ReleaseScopedVisibilityForTesting(
73 std::unique_ptr<ScopedBusy> ClientBecameBusy(); 70 std::unique_ptr<ScopedVisibility> scoped_visibility) const;
74
75 // When a client becomes not busy, it must pass back any ScopedBusy
76 // pointers it owns via this function.
77 void ClientBecameNotBusy(std::unique_ptr<ScopedBusy> scoped_busy);
78 71
79 private: 72 private:
80 void OnIdle(uint32_t idle_generation);
81 void PostIdleCallback(uint32_t current_idle_generation) const;
82 void InvalidatePendingIdleCallbacks();
83
84 gpu::ContextSupport* context_support_; 73 gpu::ContextSupport* context_support_;
85 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 74 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
86 GrContext* gr_context_ = nullptr; 75 GrContext* gr_context_ = nullptr;
87 76
88 // If set, |context_lock_| must be held before accessing any member within
89 // the idle callback. Exceptions to this are |current_idle_generation_|,
90 // which has its own lock, and weak_ptr_ and task_runner_, which may be
91 // accessed from multiple threads without locking.
92 base::Lock* context_lock_ = nullptr;
93
94 uint32_t num_clients_visible_ = 0; 77 uint32_t num_clients_visible_ = 0;
95 uint32_t num_clients_busy_ = 0;
96 bool callback_pending_ = false;
97
98 // |current_idle_generation_lock_| must be held when accessing
99 // |current_idle_generation_|. |current_idle_generation_lock_| must never be
100 // held while acquiring |context_lock_|.
101 base::Lock current_idle_generation_lock_;
102 uint32_t current_idle_generation_ = 0;
103
104 base::WeakPtr<ContextCacheController> weak_ptr_;
105 base::WeakPtrFactory<ContextCacheController> weak_factory_;
106 }; 78 };
107 79
108 } // namespace cc 80 } // namespace cc
109 81
110 #endif // CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_ 82 #endif // CC_OUTPUT_CONTEXT_CACHE_CONTROLLER_H_
OLDNEW
« no previous file with comments | « cc/BUILD.gn ('k') | cc/output/context_cache_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698