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

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

Issue 221833009: cc: Move scheduling logic out of OutputSurface (Closed) Base URL: http://git.chromium.org/chromium/src.git@swapAck2Sched11
Patch Set: rebase; add comment about race Created 6 years, 8 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/cc_tests.gyp ('k') | cc/output/output_surface.cc » ('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 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
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 bool InitializeAndSetContext3d( 149 bool InitializeAndSetContext3d(
151 scoped_refptr<ContextProvider> context_provider); 150 scoped_refptr<ContextProvider> context_provider);
152 void ReleaseGL(); 151 void ReleaseGL();
153 152
154 void PostSwapBuffersComplete(); 153 void PostSwapBuffersComplete();
155 154
156 struct OutputSurface::Capabilities capabilities_; 155 struct OutputSurface::Capabilities capabilities_;
157 scoped_refptr<ContextProvider> context_provider_; 156 scoped_refptr<ContextProvider> context_provider_;
158 scoped_ptr<SoftwareOutputDevice> software_device_; 157 scoped_ptr<SoftwareOutputDevice> software_device_;
159 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_; 158 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_;
160 gfx::Size surface_size_; 159 gfx::Size surface_size_;
161 float device_scale_factor_; 160 float device_scale_factor_;
162 base::TimeDelta begin_frame_interval_;
163 161
164 // The FrameRateController is deprecated.
165 // Platforms should move to native BeginFrames instead.
166 void CommitVSyncParameters(base::TimeTicks timebase, 162 void CommitVSyncParameters(base::TimeTicks timebase,
167 base::TimeDelta interval); 163 base::TimeDelta interval);
168 virtual void FrameRateControllerTick(const BeginFrameArgs& args) OVERRIDE;
169 scoped_ptr<FrameRateController> frame_rate_controller_;
170 164
171 bool throttle_frame_production_;
172 bool needs_begin_frame_;
173 bool client_ready_for_begin_frame_;
174
175 // This stores a BeginFrame that we couldn't process immediately,
176 // but might process retroactively in the near future.
177 BeginFrameArgs skipped_begin_frame_args_;
178
179 // Forwarded to OutputSurfaceClient but threaded through OutputSurface
180 // first so OutputSurface has a chance to update the FrameRateController
181 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); 165 void SetNeedsRedrawRect(const gfx::Rect& damage_rect);
182 void BeginFrame(const BeginFrameArgs& args);
183 void DidSwapBuffers();
184 void OnSwapBuffersComplete();
185 void ReclaimResources(const CompositorFrameAck* ack); 166 void ReclaimResources(const CompositorFrameAck* ack);
186 void DidLoseOutputSurface(); 167 void DidLoseOutputSurface();
187 void SetExternalStencilTest(bool enabled); 168 void SetExternalStencilTest(bool enabled);
188 void SetExternalDrawConstraints(const gfx::Transform& transform, 169 void SetExternalDrawConstraints(const gfx::Transform& transform,
189 const gfx::Rect& viewport, 170 const gfx::Rect& viewport,
190 const gfx::Rect& clip, 171 const gfx::Rect& clip,
191 bool valid_for_tile_management); 172 bool valid_for_tile_management);
192 173
193 // virtual for testing.
194 virtual base::TimeTicks RetroactiveBeginFrameDeadline();
195 virtual void PostCheckForRetroactiveBeginFrame();
196 void CheckForRetroactiveBeginFrame();
197
198 private: 174 private:
199 OutputSurfaceClient* client_;
200
201 void SetUpContext3d(); 175 void SetUpContext3d();
202 void ResetContext3d(); 176 void ResetContext3d();
203 void SetMemoryPolicy(const ManagedMemoryPolicy& policy); 177 void SetMemoryPolicy(const ManagedMemoryPolicy& policy);
204 void UpdateAndMeasureGpuLatency(); 178 void UpdateAndMeasureGpuLatency();
205 179
206 // check_for_retroactive_begin_frame_pending_ is used to avoid posting 180 void OnSwapBuffersComplete();
207 // redundant checks for a retroactive BeginFrame.
208 bool check_for_retroactive_begin_frame_pending_;
209 181
210 bool external_stencil_test_enabled_; 182 bool external_stencil_test_enabled_;
211 183
212 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; 184 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_;
213 185
214 std::deque<unsigned> available_gpu_latency_query_ids_; 186 std::deque<unsigned> available_gpu_latency_query_ids_;
215 std::deque<unsigned> pending_gpu_latency_query_ids_; 187 std::deque<unsigned> pending_gpu_latency_query_ids_;
216 RollingTimeDeltaHistory gpu_latency_history_; 188 RollingTimeDeltaHistory gpu_latency_history_;
217 189
218 DISALLOW_COPY_AND_ASSIGN(OutputSurface); 190 DISALLOW_COPY_AND_ASSIGN(OutputSurface);
219 }; 191 };
220 192
221 } // namespace cc 193 } // namespace cc
222 194
223 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ 195 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_
OLDNEW
« no previous file with comments | « cc/cc_tests.gyp ('k') | cc/output/output_surface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698