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_OUTPUT_SURFACE_H_ | 5 #ifndef CC_OUTPUT_OUTPUT_SURFACE_H_ |
6 #define CC_OUTPUT_OUTPUT_SURFACE_H_ | 6 #define CC_OUTPUT_OUTPUT_SURFACE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "cc/base/cc_export.h" | 14 #include "cc/base/cc_export.h" |
15 #include "cc/base/rolling_time_delta_history.h" | 15 #include "cc/base/rolling_time_delta_history.h" |
| 16 #include "cc/output/begin_frame_args.h" |
16 #include "cc/output/context_provider.h" | 17 #include "cc/output/context_provider.h" |
17 #include "cc/output/overlay_candidate_validator.h" | 18 #include "cc/output/overlay_candidate_validator.h" |
18 #include "cc/output/software_output_device.h" | 19 #include "cc/output/software_output_device.h" |
19 #include "cc/scheduler/frame_rate_controller.h" | |
20 | 20 |
21 namespace base { class SingleThreadTaskRunner; } | 21 namespace base { class SingleThreadTaskRunner; } |
22 | 22 |
23 namespace ui { struct LatencyInfo; } | 23 namespace ui { struct LatencyInfo; } |
24 | 24 |
25 namespace gfx { | 25 namespace gfx { |
26 class Rect; | 26 class Rect; |
27 class Size; | 27 class Size; |
28 class Transform; | 28 class Transform; |
29 } | 29 } |
30 | 30 |
31 namespace cc { | 31 namespace cc { |
32 | 32 |
33 class CompositorFrame; | 33 class CompositorFrame; |
34 class CompositorFrameAck; | 34 class CompositorFrameAck; |
35 struct ManagedMemoryPolicy; | 35 struct ManagedMemoryPolicy; |
36 class OutputSurfaceClient; | 36 class OutputSurfaceClient; |
37 | 37 |
38 // Represents the output surface for a compositor. The compositor owns | 38 // Represents the output surface for a compositor. The compositor owns |
39 // and manages its destruction. Its lifetime is: | 39 // and manages its destruction. Its lifetime is: |
40 // 1. Created on the main thread by the LayerTreeHost through its client. | 40 // 1. Created on the main thread by the LayerTreeHost through its client. |
41 // 2. Passed to the compositor thread and bound to a client via BindToClient. | 41 // 2. Passed to the compositor thread and bound to a client via BindToClient. |
42 // From here on, it will only be used on the compositor thread. | 42 // From here on, it will only be used on the compositor thread. |
43 // 3. If the 3D context is lost, then the compositor will delete the output | 43 // 3. If the 3D context is lost, then the compositor will delete the output |
44 // surface (on the compositor thread) and go back to step 1. | 44 // surface (on the compositor thread) and go back to step 1. |
45 class CC_EXPORT OutputSurface : public FrameRateControllerClient { | 45 class CC_EXPORT OutputSurface { |
46 public: | 46 public: |
47 enum { | 47 enum { |
48 DEFAULT_MAX_FRAMES_PENDING = 2 | 48 DEFAULT_MAX_FRAMES_PENDING = 2 |
49 }; | 49 }; |
50 | 50 |
51 explicit OutputSurface(scoped_refptr<ContextProvider> context_provider); | 51 explicit OutputSurface(scoped_refptr<ContextProvider> context_provider); |
52 | 52 |
53 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device); | 53 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device); |
54 | 54 |
55 OutputSurface(scoped_refptr<ContextProvider> context_provider, | 55 OutputSurface(scoped_refptr<ContextProvider> context_provider, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 // Called by the compositor on the compositor thread. This is a place where | 102 // Called by the compositor on the compositor thread. This is a place where |
103 // thread-specific data for the output surface can be initialized, since from | 103 // thread-specific data for the output surface can be initialized, since from |
104 // this point on the output surface will only be used on the compositor | 104 // this point on the output surface will only be used on the compositor |
105 // thread. | 105 // thread. |
106 virtual bool BindToClient(OutputSurfaceClient* client); | 106 virtual bool BindToClient(OutputSurfaceClient* client); |
107 | 107 |
108 // Enable or disable vsync. | 108 // Enable or disable vsync. |
109 void SetThrottleFrameProduction(bool enable); | 109 void SetThrottleFrameProduction(bool enable); |
110 | 110 |
111 void InitializeBeginFrameEmulation(base::SingleThreadTaskRunner* task_runner, | |
112 base::TimeDelta interval); | |
113 | |
114 virtual void EnsureBackbuffer(); | 111 virtual void EnsureBackbuffer(); |
115 virtual void DiscardBackbuffer(); | 112 virtual void DiscardBackbuffer(); |
116 | 113 |
117 virtual void Reshape(const gfx::Size& size, float scale_factor); | 114 virtual void Reshape(const gfx::Size& size, float scale_factor); |
118 virtual gfx::Size SurfaceSize() const; | 115 virtual gfx::Size SurfaceSize() const; |
119 | 116 |
120 virtual void BindFramebuffer(); | 117 virtual void BindFramebuffer(); |
121 | 118 |
122 // The implementation may destroy or steal the contents of the CompositorFrame | 119 // The implementation may destroy or steal the contents of the CompositorFrame |
123 // passed in (though it will not take ownership of the CompositorFrame | 120 // passed in (though it will not take ownership of the CompositorFrame |
124 // itself). | 121 // itself). |
125 virtual void SwapBuffers(CompositorFrame* frame); | 122 virtual void SwapBuffers(CompositorFrame* frame); |
126 | 123 |
127 // Notifies frame-rate smoothness preference. If true, all non-critical | 124 // Notifies frame-rate smoothness preference. If true, all non-critical |
128 // processing should be stopped, or lowered in priority. | 125 // processing should be stopped, or lowered in priority. |
129 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} | 126 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} |
130 | 127 |
131 // Requests a BeginFrame notification from the output surface. The | 128 // Requests a BeginFrame notification from the output surface. The |
132 // notification will be delivered by calling | 129 // notification will be delivered by calling |
133 // OutputSurfaceClient::BeginFrame until the callback is disabled. | 130 // OutputSurfaceClient::BeginFrame until the callback is disabled. |
134 virtual void SetNeedsBeginFrame(bool enable); | 131 virtual void SetNeedsBeginFrame(bool enable) {} |
135 | 132 |
136 bool HasClient() { return !!client_; } | 133 bool HasClient() { return !!client_; } |
137 | 134 |
138 // Returns an estimate of the current GPU latency. When only a software | 135 // Returns an estimate of the current GPU latency. When only a software |
139 // device is present, returns 0. | 136 // device is present, returns 0. |
140 base::TimeDelta GpuLatencyEstimate(); | 137 base::TimeDelta GpuLatencyEstimate(); |
141 | 138 |
142 // Get the class capable of informing cc of hardware overlay capability. | 139 // Get the class capable of informing cc of hardware overlay capability. |
143 OverlayCandidateValidator* overlay_candidate_validator() const { | 140 OverlayCandidateValidator* overlay_candidate_validator() const { |
144 return overlay_candidate_validator_.get(); | 141 return overlay_candidate_validator_.get(); |
145 } | 142 } |
146 | 143 |
147 protected: | 144 protected: |
| 145 OutputSurfaceClient* client_; |
| 146 |
148 // Synchronously initialize context3d and enter hardware mode. | 147 // Synchronously initialize context3d and enter hardware mode. |
149 // This can only supported in threaded compositing mode. | 148 // This can only supported in threaded compositing mode. |
150 // |offscreen_context_provider| should match what is returned by | 149 // |offscreen_context_provider| should match what is returned by |
151 // LayerTreeClient::OffscreenContextProvider(). | 150 // LayerTreeClient::OffscreenContextProvider(). |
152 bool InitializeAndSetContext3d( | 151 bool InitializeAndSetContext3d( |
153 scoped_refptr<ContextProvider> context_provider, | 152 scoped_refptr<ContextProvider> context_provider, |
154 scoped_refptr<ContextProvider> offscreen_context_provider); | 153 scoped_refptr<ContextProvider> offscreen_context_provider); |
155 void ReleaseGL(); | 154 void ReleaseGL(); |
156 | 155 |
157 void PostSwapBuffersComplete(); | 156 void PostSwapBuffersComplete(); |
158 | 157 |
159 struct OutputSurface::Capabilities capabilities_; | 158 struct OutputSurface::Capabilities capabilities_; |
160 scoped_refptr<ContextProvider> context_provider_; | 159 scoped_refptr<ContextProvider> context_provider_; |
161 scoped_ptr<SoftwareOutputDevice> software_device_; | 160 scoped_ptr<SoftwareOutputDevice> software_device_; |
162 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_; | 161 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_; |
163 gfx::Size surface_size_; | 162 gfx::Size surface_size_; |
164 float device_scale_factor_; | 163 float device_scale_factor_; |
165 base::TimeDelta begin_frame_interval_; | |
166 | 164 |
167 // The FrameRateController is deprecated. | |
168 // Platforms should move to native BeginFrames instead. | |
169 void CommitVSyncParameters(base::TimeTicks timebase, | 165 void CommitVSyncParameters(base::TimeTicks timebase, |
170 base::TimeDelta interval); | 166 base::TimeDelta interval); |
171 virtual void FrameRateControllerTick(const BeginFrameArgs& args) OVERRIDE; | |
172 scoped_ptr<FrameRateController> frame_rate_controller_; | |
173 | 167 |
174 bool throttle_frame_production_; | |
175 bool needs_begin_frame_; | |
176 bool client_ready_for_begin_frame_; | |
177 | |
178 // This stores a BeginFrame that we couldn't process immediately, | |
179 // but might process retroactively in the near future. | |
180 BeginFrameArgs skipped_begin_frame_args_; | |
181 | |
182 // Forwarded to OutputSurfaceClient but threaded through OutputSurface | |
183 // first so OutputSurface has a chance to update the FrameRateController | |
184 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); | 168 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); |
185 void BeginFrame(const BeginFrameArgs& args); | |
186 void DidSwapBuffers(); | |
187 void OnSwapBuffersComplete(); | |
188 void ReclaimResources(const CompositorFrameAck* ack); | 169 void ReclaimResources(const CompositorFrameAck* ack); |
189 void DidLoseOutputSurface(); | 170 void DidLoseOutputSurface(); |
190 void SetExternalStencilTest(bool enabled); | 171 void SetExternalStencilTest(bool enabled); |
191 void SetExternalDrawConstraints(const gfx::Transform& transform, | 172 void SetExternalDrawConstraints(const gfx::Transform& transform, |
192 const gfx::Rect& viewport, | 173 const gfx::Rect& viewport, |
193 const gfx::Rect& clip, | 174 const gfx::Rect& clip, |
194 bool valid_for_tile_management); | 175 bool valid_for_tile_management); |
195 | 176 |
196 // virtual for testing. | |
197 virtual base::TimeTicks RetroactiveBeginFrameDeadline(); | |
198 virtual void PostCheckForRetroactiveBeginFrame(); | |
199 void CheckForRetroactiveBeginFrame(); | |
200 | |
201 private: | 177 private: |
202 OutputSurfaceClient* client_; | |
203 | |
204 void SetUpContext3d(); | 178 void SetUpContext3d(); |
205 void ResetContext3d(); | 179 void ResetContext3d(); |
206 void SetMemoryPolicy(const ManagedMemoryPolicy& policy); | 180 void SetMemoryPolicy(const ManagedMemoryPolicy& policy); |
207 void UpdateAndMeasureGpuLatency(); | 181 void UpdateAndMeasureGpuLatency(); |
208 | 182 |
209 // check_for_retroactive_begin_frame_pending_ is used to avoid posting | 183 void OnSwapBuffersComplete(); |
210 // redundant checks for a retroactive BeginFrame. | |
211 bool check_for_retroactive_begin_frame_pending_; | |
212 | 184 |
213 bool external_stencil_test_enabled_; | 185 bool external_stencil_test_enabled_; |
214 | 186 |
215 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | 187 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; |
216 | 188 |
217 std::deque<unsigned> available_gpu_latency_query_ids_; | 189 std::deque<unsigned> available_gpu_latency_query_ids_; |
218 std::deque<unsigned> pending_gpu_latency_query_ids_; | 190 std::deque<unsigned> pending_gpu_latency_query_ids_; |
219 RollingTimeDeltaHistory gpu_latency_history_; | 191 RollingTimeDeltaHistory gpu_latency_history_; |
220 | 192 |
221 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | 193 DISALLOW_COPY_AND_ASSIGN(OutputSurface); |
222 }; | 194 }; |
223 | 195 |
224 } // namespace cc | 196 } // namespace cc |
225 | 197 |
226 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | 198 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ |
OLD | NEW |