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

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

Issue 1336733002: Re-land: cc: Implement shared worker contexts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix LayerTreeHostClientTakeAwayOutputSurface test. Content provider is always destroyed on the clie… Created 5 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
« no previous file with comments | « cc/layers/ui_resource_layer_impl_unittest.cc ('k') | cc/output/output_surface.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 "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 14 matching lines...) Expand all
25 namespace cc { 25 namespace cc {
26 struct ManagedMemoryPolicy; 26 struct ManagedMemoryPolicy;
27 27
28 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { 28 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
29 public: 29 public:
30 class ScopedContextLock { 30 class ScopedContextLock {
31 public: 31 public:
32 explicit ScopedContextLock(ContextProvider* context_provider) 32 explicit ScopedContextLock(ContextProvider* context_provider)
33 : context_provider_(context_provider), 33 : context_provider_(context_provider),
34 context_lock_(*context_provider_->GetLock()) { 34 context_lock_(*context_provider_->GetLock()) {
35 // Allow current thread to bind to |context_provider|. 35 // Allow current thread to use |context_provider_|.
36 context_provider_->DetachFromThread(); 36 context_provider_->DetachFromThread();
37 } 37 }
38 ~ScopedContextLock() { 38 ~ScopedContextLock() {
39 // Allow a different thread to bind to |context_provider|. 39 // Allow usage by thread for which |context_provider_| is bound to.
40 context_provider_->DetachFromThread(); 40 context_provider_->DetachFromThread();
41 } 41 }
42 42
43 gpu::gles2::GLES2Interface* ContextGL() { 43 gpu::gles2::GLES2Interface* ContextGL() {
44 return context_provider_->ContextGL(); 44 return context_provider_->ContextGL();
45 } 45 }
46 46
47 private: 47 private:
48 ContextProvider* const context_provider_; 48 ContextProvider* const context_provider_;
49 base::AutoLock context_lock_; 49 base::AutoLock context_lock_;
50 }; 50 };
51 // Bind the 3d context to the current thread. This should be called before 51 // Bind the 3d context to the current thread. This should be called before
52 // accessing the contexts. Calling it more than once should have no effect. 52 // accessing the contexts. Calling it more than once should have no effect.
53 // Once this function has been called, the class should only be accessed 53 // Once this function has been called, the class should only be accessed
54 // from the same thread. 54 // from the same thread unless the function has some explicitly specified
55 // rules for access on a different thread. See SetupLockOnMainThread(), which
56 // can be used to provide access from multiple threads.
55 virtual bool BindToCurrentThread() = 0; 57 virtual bool BindToCurrentThread() = 0;
56 virtual void DetachFromThread() {} 58 virtual void DetachFromThread() {}
57 59
58 virtual gpu::gles2::GLES2Interface* ContextGL() = 0; 60 virtual gpu::gles2::GLES2Interface* ContextGL() = 0;
59 virtual gpu::ContextSupport* ContextSupport() = 0; 61 virtual gpu::ContextSupport* ContextSupport() = 0;
60 virtual class GrContext* GrContext() = 0; 62 virtual class GrContext* GrContext() = 0;
61 63
62 struct Capabilities { 64 struct Capabilities {
63 gpu::Capabilities gpu; 65 gpu::Capabilities gpu;
64 size_t max_transfer_buffer_usage_bytes; 66 size_t max_transfer_buffer_usage_bytes;
65 67
66 CC_EXPORT Capabilities(); 68 CC_EXPORT Capabilities();
67 }; 69 };
68 70
69 // Invalidates the cached OpenGL state in GrContext. 71 // Invalidates the cached OpenGL state in GrContext.
70 // See skia GrContext::resetContext for details. 72 // See skia GrContext::resetContext for details.
71 virtual void InvalidateGrContext(uint32_t state) = 0; 73 virtual void InvalidateGrContext(uint32_t state) = 0;
72 74
73 // Sets up a lock so this context can be used from multiple threads. 75 // Sets up a lock so this context can be used from multiple threads. After
76 // calling this, all functions without explicit thread usage constraints can
77 // be used on any thread while the lock returned by GetLock() is acquired.
74 virtual void SetupLock() = 0; 78 virtual void SetupLock() = 0;
75 79
76 // Returns the lock that should be held if using this context from multiple 80 // Returns the lock that should be held if using this context from multiple
77 // threads. 81 // threads. This can be called on any thread.
78 virtual base::Lock* GetLock() = 0; 82 virtual base::Lock* GetLock() = 0;
79 83
80 // Returns the capabilities of the currently bound 3d context. 84 // Returns the capabilities of the currently bound 3d context.
81 virtual Capabilities ContextCapabilities() = 0; 85 virtual Capabilities ContextCapabilities() = 0;
82 86
83 // Ask the provider to check if the contexts are valid or lost. If they are, 87 // Ask the provider to check if the contexts are valid or lost. If they are,
84 // this should invalidate the provider so that it can be replaced with a new 88 // this should invalidate the provider so that it can be replaced with a new
85 // one. 89 // one.
86 virtual void VerifyContexts() = 0; 90 virtual void VerifyContexts() = 0;
87 91
(...skipping 20 matching lines...) Expand all
108 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0; 112 const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
109 113
110 protected: 114 protected:
111 friend class base::RefCountedThreadSafe<ContextProvider>; 115 friend class base::RefCountedThreadSafe<ContextProvider>;
112 virtual ~ContextProvider() {} 116 virtual ~ContextProvider() {}
113 }; 117 };
114 118
115 } // namespace cc 119 } // namespace cc
116 120
117 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_ 121 #endif // CC_OUTPUT_CONTEXT_PROVIDER_H_
OLDNEW
« no previous file with comments | « cc/layers/ui_resource_layer_impl_unittest.cc ('k') | cc/output/output_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698