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 // Note: DidSwapBuffers and OnSwapBuffersComplete should not be called on | |
danakj
2014/04/11 15:42:22
In browser process land we've avoided doing things
brianderson
2014/04/11 20:21:28
The id check works for making sure that an Ack for
danakj
2014/04/14 18:19:27
What if we reset the acks in flight and stuff when
brianderson
2014/04/16 21:51:31
Going to go with that solution and avoid being ove
| |
146 // the client when the OutputSurface is lost to avoid race conditions where | |
147 // DidSwapBuffersComplete gets registered for an incorrect OutputSurface. | |
148 OutputSurfaceClient* client_; | |
149 bool is_lost_; | |
150 | |
148 // Synchronously initialize context3d and enter hardware mode. | 151 // Synchronously initialize context3d and enter hardware mode. |
149 // This can only supported in threaded compositing mode. | 152 // This can only supported in threaded compositing mode. |
150 // |offscreen_context_provider| should match what is returned by | 153 // |offscreen_context_provider| should match what is returned by |
151 // LayerTreeClient::OffscreenContextProvider(). | 154 // LayerTreeClient::OffscreenContextProvider(). |
152 bool InitializeAndSetContext3d( | 155 bool InitializeAndSetContext3d( |
153 scoped_refptr<ContextProvider> context_provider, | 156 scoped_refptr<ContextProvider> context_provider, |
154 scoped_refptr<ContextProvider> offscreen_context_provider); | 157 scoped_refptr<ContextProvider> offscreen_context_provider); |
155 void ReleaseGL(); | 158 void ReleaseGL(); |
156 | 159 |
157 void PostSwapBuffersComplete(); | 160 void PostSwapBuffersComplete(); |
158 | 161 |
159 struct OutputSurface::Capabilities capabilities_; | 162 struct OutputSurface::Capabilities capabilities_; |
160 scoped_refptr<ContextProvider> context_provider_; | 163 scoped_refptr<ContextProvider> context_provider_; |
161 scoped_ptr<SoftwareOutputDevice> software_device_; | 164 scoped_ptr<SoftwareOutputDevice> software_device_; |
162 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_; | 165 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_; |
163 gfx::Size surface_size_; | 166 gfx::Size surface_size_; |
164 float device_scale_factor_; | 167 float device_scale_factor_; |
165 base::TimeDelta begin_frame_interval_; | |
166 | 168 |
167 // The FrameRateController is deprecated. | |
168 // Platforms should move to native BeginFrames instead. | |
169 void CommitVSyncParameters(base::TimeTicks timebase, | 169 void CommitVSyncParameters(base::TimeTicks timebase, |
170 base::TimeDelta interval); | 170 base::TimeDelta interval); |
171 virtual void FrameRateControllerTick(const BeginFrameArgs& args) OVERRIDE; | |
172 scoped_ptr<FrameRateController> frame_rate_controller_; | |
173 | 171 |
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); | 172 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); | 173 void ReclaimResources(const CompositorFrameAck* ack); |
189 void DidLoseOutputSurface(); | 174 void DidLoseOutputSurface(); |
190 void SetExternalStencilTest(bool enabled); | 175 void SetExternalStencilTest(bool enabled); |
191 void SetExternalDrawConstraints(const gfx::Transform& transform, | 176 void SetExternalDrawConstraints(const gfx::Transform& transform, |
192 const gfx::Rect& viewport, | 177 const gfx::Rect& viewport, |
193 const gfx::Rect& clip, | 178 const gfx::Rect& clip, |
194 bool valid_for_tile_management); | 179 bool valid_for_tile_management); |
195 | 180 |
196 // virtual for testing. | |
197 virtual base::TimeTicks RetroactiveBeginFrameDeadline(); | |
198 virtual void PostCheckForRetroactiveBeginFrame(); | |
199 void CheckForRetroactiveBeginFrame(); | |
200 | |
201 private: | 181 private: |
202 OutputSurfaceClient* client_; | |
203 | |
204 void SetUpContext3d(); | 182 void SetUpContext3d(); |
205 void ResetContext3d(); | 183 void ResetContext3d(); |
206 void SetMemoryPolicy(const ManagedMemoryPolicy& policy); | 184 void SetMemoryPolicy(const ManagedMemoryPolicy& policy); |
207 void UpdateAndMeasureGpuLatency(); | 185 void UpdateAndMeasureGpuLatency(); |
208 | 186 void OnSwapBuffersComplete(); |
209 bool is_lost_; | |
210 | |
211 // check_for_retroactive_begin_frame_pending_ is used to avoid posting | |
212 // redundant checks for a retroactive BeginFrame. | |
213 bool check_for_retroactive_begin_frame_pending_; | |
214 | 187 |
215 bool external_stencil_test_enabled_; | 188 bool external_stencil_test_enabled_; |
216 | 189 |
217 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | 190 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; |
218 | 191 |
219 std::deque<unsigned> available_gpu_latency_query_ids_; | 192 std::deque<unsigned> available_gpu_latency_query_ids_; |
220 std::deque<unsigned> pending_gpu_latency_query_ids_; | 193 std::deque<unsigned> pending_gpu_latency_query_ids_; |
221 RollingTimeDeltaHistory gpu_latency_history_; | 194 RollingTimeDeltaHistory gpu_latency_history_; |
222 | 195 |
223 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | 196 DISALLOW_COPY_AND_ASSIGN(OutputSurface); |
224 }; | 197 }; |
225 | 198 |
226 } // namespace cc | 199 } // namespace cc |
227 | 200 |
228 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | 201 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ |
OLD | NEW |