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

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

Issue 2257533006: Free worker context resources on idle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-cleanup2
Patch Set: rebase Created 4 years, 4 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/test/test_context_support.h » ('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) 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 "gpu/command_buffer/client/context_support.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 struct ManagedMemoryPolicy; 30 struct ManagedMemoryPolicy;
30 31
31 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { 32 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
32 public: 33 public:
33 // 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
34 // threads. This only works for ContextProviders that will return a valid 35 // threads. This only works for ContextProviders that will return a valid
35 // lock from GetLock(), so is not always supported. Most use of 36 // lock from GetLock(), so is not always supported. Most use of
36 // ContextProvider should be single-thread only on the thread that 37 // ContextProvider should be single-thread only on the thread that
37 // BindToCurrentThread is run on. 38 // BindToCurrentThread is run on.
38 class ScopedContextLock { 39 class CC_EXPORT ScopedContextLock {
39 public: 40 public:
40 explicit ScopedContextLock(ContextProvider* context_provider) 41 explicit ScopedContextLock(ContextProvider* context_provider);
41 : context_provider_(context_provider), 42 ~ScopedContextLock();
42 context_lock_(*context_provider_->GetLock()) {
43 // Allow current thread to use |context_provider_|.
44 context_provider_->DetachFromThread();
45 }
46 ~ScopedContextLock() {
47 // Allow usage by thread for which |context_provider_| is bound to.
48 context_provider_->DetachFromThread();
49 }
50 43
51 gpu::gles2::GLES2Interface* ContextGL() { 44 gpu::gles2::GLES2Interface* ContextGL() {
52 return context_provider_->ContextGL(); 45 return context_provider_->ContextGL();
53 } 46 }
54 47
55 private: 48 private:
56 ContextProvider* const context_provider_; 49 ContextProvider* const context_provider_;
57 base::AutoLock context_lock_; 50 base::AutoLock context_lock_;
51 std::unique_ptr<gpu::ContextSupport::ScopedBusy> busy_;
58 }; 52 };
59 53
60 // 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
61 // 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.
62 // 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
63 // from the same thread unless the function has some explicitly specified 57 // from the same thread unless the function has some explicitly specified
64 // rules for access on a different thread. See SetupLockOnMainThread(), which 58 // rules for access on a different thread. See SetupLockOnMainThread(), which
65 // can be used to provide access from multiple threads. 59 // can be used to provide access from multiple threads.
66 virtual bool BindToCurrentThread() = 0; 60 virtual bool BindToCurrentThread() = 0;
67 61
(...skipping 29 matching lines...) Expand all
97 virtual base::Lock* GetLock() = 0; 91 virtual base::Lock* GetLock() = 0;
98 92
99 protected: 93 protected:
100 friend class base::RefCountedThreadSafe<ContextProvider>; 94 friend class base::RefCountedThreadSafe<ContextProvider>;
101 virtual ~ContextProvider() {} 95 virtual ~ContextProvider() {}
102 }; 96 };
103 97
104 } // namespace cc 98 } // namespace cc
105 99
106 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ 100 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_
OLDNEW
« no previous file with comments | « cc/BUILD.gn ('k') | cc/test/test_context_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698