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

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

Issue 2353033003: Idle cleanup for worker context (Closed)
Patch Set: fix windows build Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_PROVIDER_H_ 5 #ifndef CC_OUTPUT_CONTEXT_PROVIDER_H_
6 #define CC_OUTPUT_CONTEXT_PROVIDER_H_ 6 #define CC_OUTPUT_CONTEXT_PROVIDER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "cc/base/cc_export.h" 14 #include "cc/base/cc_export.h"
15 #include "cc/output/context_cache_controller.h"
15 #include "gpu/command_buffer/common/capabilities.h" 16 #include "gpu/command_buffer/common/capabilities.h"
16 17
17 class GrContext; 18 class GrContext;
18 19
19 namespace base { 20 namespace base {
20 class Lock; 21 class Lock;
21 } 22 }
22 23
23 namespace gpu { 24 namespace gpu {
24 class ContextSupport; 25 class ContextSupport;
25 namespace gles2 { class GLES2Interface; } 26 namespace gles2 { class GLES2Interface; }
26 } 27 }
27 28
28 namespace cc { 29 namespace cc {
29 class ContextCacheController;
30 struct ManagedMemoryPolicy; 30 struct ManagedMemoryPolicy;
31 31
32 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { 32 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
33 public: 33 public:
34 // Hold an instance of this lock while using a context across multiple 34 // Hold an instance of this lock while using a context across multiple
35 // threads. This only works for ContextProviders that will return a valid 35 // threads. This only works for ContextProviders that will return a valid
36 // lock from GetLock(), so is not always supported. Most use of 36 // lock from GetLock(), so is not always supported. Most use of
37 // ContextProvider should be single-thread only on the thread that 37 // ContextProvider should be single-thread only on the thread that
38 // BindToCurrentThread is run on. 38 // BindToCurrentThread is run on.
39 class ScopedContextLock { 39 class CC_EXPORT ScopedContextLock {
40 public: 40 public:
41 explicit ScopedContextLock(ContextProvider* context_provider) 41 explicit ScopedContextLock(ContextProvider* context_provider);
42 : context_provider_(context_provider), 42 ~ScopedContextLock();
43 context_lock_(*context_provider_->GetLock()) {
44 // Allow current thread to use |context_provider_|.
45 context_provider_->DetachFromThread();
46 }
47 ~ScopedContextLock() {
48 // Allow usage by thread for which |context_provider_| is bound to.
49 context_provider_->DetachFromThread();
50 }
51 43
52 gpu::gles2::GLES2Interface* ContextGL() { 44 gpu::gles2::GLES2Interface* ContextGL() {
53 return context_provider_->ContextGL(); 45 return context_provider_->ContextGL();
54 } 46 }
55 47
56 private: 48 private:
57 ContextProvider* const context_provider_; 49 ContextProvider* const context_provider_;
58 base::AutoLock context_lock_; 50 base::AutoLock context_lock_;
51 std::unique_ptr<ContextCacheController::ScopedBusy> busy_;
59 }; 52 };
60 53
61 // Bind the 3d context to the current thread. This should be called before 54 // Bind the 3d context to the current thread. This should be called before
62 // accessing the contexts. Calling it more than once should have no effect. 55 // accessing the contexts. Calling it more than once should have no effect.
63 // Once this function has been called, the class should only be accessed 56 // Once this function has been called, the class should only be accessed
64 // from the same thread unless the function has some explicitly specified 57 // from the same thread unless the function has some explicitly specified
65 // rules for access on a different thread. See SetupLockOnMainThread(), which 58 // rules for access on a different thread. See SetupLockOnMainThread(), which
66 // can be used to provide access from multiple threads. 59 // can be used to provide access from multiple threads.
67 virtual bool BindToCurrentThread() = 0; 60 virtual bool BindToCurrentThread() = 0;
68 61
(...skipping 27 matching lines...) Expand all
96 virtual base::Lock* GetLock() = 0; 89 virtual base::Lock* GetLock() = 0;
97 90
98 protected: 91 protected:
99 friend class base::RefCountedThreadSafe<ContextProvider>; 92 friend class base::RefCountedThreadSafe<ContextProvider>;
100 virtual ~ContextProvider() {} 93 virtual ~ContextProvider() {}
101 }; 94 };
102 95
103 } // namespace cc 96 } // namespace cc
104 97
105 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ 98 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698