OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_COMPOSITOR_FRAME_SINK_H_ | 5 #ifndef CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_ |
6 #define CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_ | 6 #define CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 class Size; | 29 class Size; |
30 class Transform; | 30 class Transform; |
31 } | 31 } |
32 | 32 |
33 namespace cc { | 33 namespace cc { |
34 | 34 |
35 class CompositorFrame; | 35 class CompositorFrame; |
36 struct ManagedMemoryPolicy; | 36 struct ManagedMemoryPolicy; |
37 class CompositorFrameSinkClient; | 37 class CompositorFrameSinkClient; |
38 | 38 |
39 // Represents the output surface for a compositor. The compositor owns | 39 // An interface for submitting CompositorFrames to a display compositor |
40 // and manages its destruction. Its lifetime is: | 40 // which will compose frames from multiple CompositorFrameSinks to show |
41 // 1. Created on the main thread by the LayerTreeHost through its client. | 41 // on screen to the user. |
42 // 2. Passed to the compositor thread and bound to a client via BindToClient. | 42 // If a context_provider() is present, frames should be submitted with |
43 // From here on, it will only be used on the compositor thread. | 43 // OpenGL resources (created with the context_provider()). If not, then |
44 // 3. If the 3D context is lost, then the compositor will delete the output | 44 // SharedBitmap resources should be used. |
45 // surface (on the compositor thread) and go back to step 1. | |
46 class CC_EXPORT CompositorFrameSink { | 45 class CC_EXPORT CompositorFrameSink { |
47 public: | 46 public: |
48 struct Capabilities { | 47 struct Capabilities { |
49 Capabilities() = default; | 48 Capabilities() = default; |
50 | 49 |
51 // Whether ForceReclaimResources can be called to reclaim all resources | 50 // Whether ForceReclaimResources can be called to reclaim all resources |
52 // from the CompositorFrameSink. | 51 // from the CompositorFrameSink. |
53 bool can_force_reclaim_resources = false; | 52 bool can_force_reclaim_resources = false; |
54 // True if sync points for resources are needed when swapping delegated | 53 // True if sync points for resources are needed when swapping delegated |
55 // frames. | 54 // frames. |
56 bool delegated_sync_points_required = true; | 55 bool delegated_sync_points_required = true; |
57 }; | 56 }; |
58 | 57 |
59 // Constructor for GL-based and/or software compositing. | 58 // Constructor for GL-based and/or software resources. |
60 CompositorFrameSink(scoped_refptr<ContextProvider> context_provider, | 59 CompositorFrameSink(scoped_refptr<ContextProvider> context_provider, |
61 scoped_refptr<ContextProvider> worker_context_provider); | 60 scoped_refptr<ContextProvider> worker_context_provider); |
62 | 61 |
63 // Constructor for Vulkan-based compositing. | 62 // Constructor for Vulkan-based resources. |
64 explicit CompositorFrameSink( | 63 explicit CompositorFrameSink( |
65 scoped_refptr<VulkanContextProvider> vulkan_context_provider); | 64 scoped_refptr<VulkanContextProvider> vulkan_context_provider); |
66 | 65 |
67 virtual ~CompositorFrameSink(); | 66 virtual ~CompositorFrameSink(); |
68 | 67 |
69 // Called by the compositor on the compositor thread. This is a place where | 68 // Called by the compositor on the compositor thread. This is a place where |
70 // thread-specific data for the output surface can be initialized, since from | 69 // thread-specific data for the output surface can be initialized, since from |
71 // this point to when DetachFromClient() is called the output surface will | 70 // this point to when DetachFromClient() is called the output surface will |
72 // only be used on the compositor thread. | 71 // only be used on the compositor thread. |
73 // The caller should call DetachFromClient() on the same thread before | 72 // The caller should call DetachFromClient() on the same thread before |
74 // destroying the CompositorFrameSink, even if this fails. And BindToClient | 73 // destroying the CompositorFrameSink, even if this fails. And BindToClient |
75 // should not be called twice for a given CompositorFrameSink. | 74 // should not be called twice for a given CompositorFrameSink. |
76 virtual bool BindToClient(CompositorFrameSinkClient* client); | 75 virtual bool BindToClient(CompositorFrameSinkClient* client); |
77 | 76 |
78 // Called by the compositor on the compositor thread. This is a place where | 77 // Must be called from the thread where BindToClient was called if |
79 // thread-specific data for the output surface can be uninitialized. | 78 // BindToClient succeeded, after which the CompositorFrameSink may be |
| 79 // destroyed from any thread. This is a place where thread-specific data for |
| 80 // the object can be uninitialized. |
80 virtual void DetachFromClient(); | 81 virtual void DetachFromClient(); |
81 | 82 |
82 bool HasClient() { return !!client_; } | 83 bool HasClient() { return !!client_; } |
83 | 84 |
84 const Capabilities& capabilities() const { return capabilities_; } | 85 const Capabilities& capabilities() const { return capabilities_; } |
85 | 86 |
86 // Obtain the 3d context or the software device associated with this output | 87 // The ContextProviders may be null if frames should be submitted with |
87 // surface. Either of these may return a null pointer, but not both. | 88 // software SharedBitmap resources. |
88 // In the event of a lost context, the entire output surface should be | |
89 // recreated. | |
90 ContextProvider* context_provider() const { return context_provider_.get(); } | 89 ContextProvider* context_provider() const { return context_provider_.get(); } |
91 ContextProvider* worker_context_provider() const { | 90 ContextProvider* worker_context_provider() const { |
92 return worker_context_provider_.get(); | 91 return worker_context_provider_.get(); |
93 } | 92 } |
94 VulkanContextProvider* vulkan_context_provider() const { | 93 VulkanContextProvider* vulkan_context_provider() const { |
95 return vulkan_context_provider_.get(); | 94 return vulkan_context_provider_.get(); |
96 } | 95 } |
97 | 96 |
98 // If supported, this causes a ReclaimResources for all resources that are | 97 // If supported, this causes a ReclaimResources for all resources that are |
99 // currently in use. | 98 // currently in use. |
(...skipping 17 matching lines...) Expand all Loading... |
117 | 116 |
118 CompositorFrameSinkClient* client_ = nullptr; | 117 CompositorFrameSinkClient* client_ = nullptr; |
119 | 118 |
120 struct CompositorFrameSink::Capabilities capabilities_; | 119 struct CompositorFrameSink::Capabilities capabilities_; |
121 scoped_refptr<ContextProvider> context_provider_; | 120 scoped_refptr<ContextProvider> context_provider_; |
122 scoped_refptr<ContextProvider> worker_context_provider_; | 121 scoped_refptr<ContextProvider> worker_context_provider_; |
123 scoped_refptr<VulkanContextProvider> vulkan_context_provider_; | 122 scoped_refptr<VulkanContextProvider> vulkan_context_provider_; |
124 base::ThreadChecker client_thread_checker_; | 123 base::ThreadChecker client_thread_checker_; |
125 | 124 |
126 private: | 125 private: |
127 void DetachFromClientInternal(); | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSink); | 126 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSink); |
130 }; | 127 }; |
131 | 128 |
132 } // namespace cc | 129 } // namespace cc |
133 | 130 |
134 #endif // CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_ | 131 #endif // CC_OUTPUT_COMPOSITOR_FRAME_SINK_H_ |
OLD | NEW |