OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 UI_COMPOSITOR_COMPOSITOR_H_ | 5 #ifndef UI_COMPOSITOR_COMPOSITOR_H_ |
6 #define UI_COMPOSITOR_COMPOSITOR_H_ | 6 #define UI_COMPOSITOR_COMPOSITOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.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/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "cc/output/begin_frame_args.h" |
16 #include "cc/trees/layer_tree_host_client.h" | 17 #include "cc/trees/layer_tree_host_client.h" |
17 #include "cc/trees/layer_tree_host_single_thread_client.h" | 18 #include "cc/trees/layer_tree_host_single_thread_client.h" |
18 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "ui/base/compositor/compositor_begin_frame_observer.h" |
19 #include "ui/compositor/compositor_animation_observer.h" | 21 #include "ui/compositor/compositor_animation_observer.h" |
20 #include "ui/compositor/compositor_export.h" | 22 #include "ui/compositor/compositor_export.h" |
21 #include "ui/compositor/compositor_observer.h" | 23 #include "ui/compositor/compositor_observer.h" |
22 #include "ui/compositor/layer_animator_collection.h" | 24 #include "ui/compositor/layer_animator_collection.h" |
23 #include "ui/gfx/native_widget_types.h" | 25 #include "ui/gfx/native_widget_types.h" |
24 #include "ui/gfx/size.h" | 26 #include "ui/gfx/size.h" |
25 #include "ui/gfx/vector2d.h" | 27 #include "ui/gfx/vector2d.h" |
26 | 28 |
27 class SkBitmap; | 29 class SkBitmap; |
28 | 30 |
(...skipping 15 matching lines...) Expand all Loading... |
44 class Size; | 46 class Size; |
45 } | 47 } |
46 | 48 |
47 namespace gpu { | 49 namespace gpu { |
48 struct Mailbox; | 50 struct Mailbox; |
49 } | 51 } |
50 | 52 |
51 namespace ui { | 53 namespace ui { |
52 | 54 |
53 class Compositor; | 55 class Compositor; |
54 class CompositorVSyncManager; | |
55 class Layer; | 56 class Layer; |
56 class Reflector; | 57 class Reflector; |
57 class Texture; | 58 class Texture; |
58 struct LatencyInfo; | 59 struct LatencyInfo; |
59 | 60 |
60 // This class abstracts the creation of the 3D context for the compositor. It is | 61 // This class abstracts the creation of the 3D context for the compositor. It is |
61 // a global object. | 62 // a global object. |
62 class COMPOSITOR_EXPORT ContextFactory { | 63 class COMPOSITOR_EXPORT ContextFactory { |
63 public: | 64 public: |
64 virtual ~ContextFactory() {} | 65 virtual ~ContextFactory() {} |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // Sets the background color used for areas that aren't covered by | 186 // Sets the background color used for areas that aren't covered by |
186 // the |root_layer|. | 187 // the |root_layer|. |
187 void SetBackgroundColor(SkColor color); | 188 void SetBackgroundColor(SkColor color); |
188 | 189 |
189 // Set the visibility of the underlying compositor. | 190 // Set the visibility of the underlying compositor. |
190 void SetVisible(bool visible); | 191 void SetVisible(bool visible); |
191 | 192 |
192 // Returns the widget for this compositor. | 193 // Returns the widget for this compositor. |
193 gfx::AcceleratedWidget widget() const { return widget_; } | 194 gfx::AcceleratedWidget widget() const { return widget_; } |
194 | 195 |
195 // Returns the vsync manager for this compositor. | 196 // The "authoritative" vsync interval, if provided, will override interval |
196 scoped_refptr<CompositorVSyncManager> vsync_manager() const; | 197 // reported from 3D context. This is typically the value reported by a more |
| 198 // reliable source, e.g, the platform display configuration. |
| 199 // In the particular case of ChromeOS -- this is the value queried through |
| 200 // XRandR, which is more reliable than the value queried through the 3D |
| 201 // context. |
| 202 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) const; |
| 203 |
| 204 // Request BeginFrame scheduling to OutputSurface. |
| 205 void StartBeginFrame(const cc::BeginFrameArgs& args) const; |
197 | 206 |
198 // Returns the main thread task runner this compositor uses. Users of the | 207 // Returns the main thread task runner this compositor uses. Users of the |
199 // compositor generally shouldn't use this. | 208 // compositor generally shouldn't use this. |
200 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { | 209 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const { |
201 return task_runner_; | 210 return task_runner_; |
202 } | 211 } |
203 | 212 |
204 // Compositor does not own observers. It is the responsibility of the | 213 // Compositor does not own observers. It is the responsibility of the |
205 // observer to remove itself when it is done observing. | 214 // observer to remove itself when it is done observing. |
206 void AddObserver(CompositorObserver* observer); | 215 void AddObserver(CompositorObserver* observer); |
207 void RemoveObserver(CompositorObserver* observer); | 216 void RemoveObserver(CompositorObserver* observer); |
208 bool HasObserver(CompositorObserver* observer); | 217 bool HasObserver(CompositorObserver* observer); |
209 | 218 |
210 void AddAnimationObserver(CompositorAnimationObserver* observer); | 219 void AddAnimationObserver(CompositorAnimationObserver* observer); |
211 void RemoveAnimationObserver(CompositorAnimationObserver* observer); | 220 void RemoveAnimationObserver(CompositorAnimationObserver* observer); |
212 bool HasAnimationObserver(CompositorAnimationObserver* observer); | 221 bool HasAnimationObserver(CompositorAnimationObserver* observer); |
213 | 222 |
| 223 void AddBeginFrameObserver( |
| 224 CompositorBeginFrameObserver* observer, |
| 225 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer); |
| 226 void RemoveBeginFrameObserver(CompositorBeginFrameObserver* observer); |
| 227 |
214 // Creates a compositor lock. Returns NULL if it is not possible to lock at | 228 // Creates a compositor lock. Returns NULL if it is not possible to lock at |
215 // this time (i.e. we're waiting to complete a previous unlock). | 229 // this time (i.e. we're waiting to complete a previous unlock). |
216 scoped_refptr<CompositorLock> GetCompositorLock(); | 230 scoped_refptr<CompositorLock> GetCompositorLock(); |
217 | 231 |
218 // Internal functions, called back by command-buffer contexts on swap buffer | 232 // Internal functions, called back by command-buffer contexts on swap buffer |
219 // events. | 233 // events. |
220 | 234 |
221 // Signals swap has been posted. | 235 // Signals swap has been posted. |
222 void OnSwapBuffersPosted(); | 236 void OnSwapBuffersPosted(); |
223 | 237 |
224 // Signals swap has completed. | 238 // Signals swap has completed. |
225 void OnSwapBuffersComplete(); | 239 void OnSwapBuffersComplete(); |
226 | 240 |
227 // Signals swap has aborted (e.g. lost context). | 241 // Signals swap has aborted (e.g. lost context). |
228 void OnSwapBuffersAborted(); | 242 void OnSwapBuffersAborted(); |
229 | 243 |
230 // LayerTreeHostClient implementation. | 244 // LayerTreeHostClient implementation. |
231 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} | 245 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} |
232 virtual void DidBeginMainFrame() OVERRIDE {} | 246 virtual void DidBeginMainFrame() OVERRIDE {} |
233 virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE; | 247 virtual void BeginMainFrame(const cc::BeginFrameArgs& args) OVERRIDE; |
234 virtual void Layout() OVERRIDE; | 248 virtual void Layout() OVERRIDE; |
235 virtual void ApplyViewportDeltas( | 249 virtual void ApplyViewportDeltas( |
236 const gfx::Vector2d& scroll_delta, | 250 const gfx::Vector2d& scroll_delta, |
237 float page_scale, | 251 float page_scale, |
238 float top_controls_delta) OVERRIDE {} | 252 float top_controls_delta) OVERRIDE {} |
239 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) | 253 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) |
240 OVERRIDE; | 254 OVERRIDE; |
241 virtual void DidInitializeOutputSurface() OVERRIDE {} | 255 virtual void DidInitializeOutputSurface() OVERRIDE; |
| 256 virtual void DidLoseOutputSurface() OVERRIDE; |
242 virtual void WillCommit() OVERRIDE {} | 257 virtual void WillCommit() OVERRIDE {} |
243 virtual void DidCommit() OVERRIDE; | 258 virtual void DidCommit() OVERRIDE; |
244 virtual void DidCommitAndDrawFrame() OVERRIDE; | 259 virtual void DidCommitAndDrawFrame() OVERRIDE; |
245 virtual void DidCompleteSwapBuffers() OVERRIDE; | 260 virtual void DidCompleteSwapBuffers() OVERRIDE; |
| 261 virtual void SendBeginFrameToChildren( |
| 262 const cc::BeginFrameArgs& args) OVERRIDE; |
246 | 263 |
247 // cc::LayerTreeHostSingleThreadClient implementation. | 264 // cc::LayerTreeHostSingleThreadClient implementation. |
248 virtual void ScheduleComposite() OVERRIDE; | 265 virtual void ScheduleComposite() OVERRIDE; |
249 virtual void ScheduleAnimation() OVERRIDE; | 266 virtual void ScheduleAnimation() OVERRIDE; |
250 virtual void DidPostSwapBuffers() OVERRIDE; | 267 virtual void DidPostSwapBuffers() OVERRIDE; |
251 virtual void DidAbortSwapBuffers() OVERRIDE; | 268 virtual void DidAbortSwapBuffers() OVERRIDE; |
252 | 269 |
253 int last_started_frame() { return last_started_frame_; } | 270 int last_started_frame() { return last_started_frame_; } |
254 int last_ended_frame() { return last_ended_frame_; } | 271 int last_ended_frame() { return last_ended_frame_; } |
255 | 272 |
(...skipping 12 matching lines...) Expand all Loading... |
268 | 285 |
269 // Called by CompositorLock. | 286 // Called by CompositorLock. |
270 void UnlockCompositor(); | 287 void UnlockCompositor(); |
271 | 288 |
272 // Called to release any pending CompositorLock | 289 // Called to release any pending CompositorLock |
273 void CancelCompositorLock(); | 290 void CancelCompositorLock(); |
274 | 291 |
275 // Notifies the compositor that compositing is complete. | 292 // Notifies the compositor that compositing is complete. |
276 void NotifyEnd(); | 293 void NotifyEnd(); |
277 | 294 |
| 295 // Request scheduling of next BeginFrame to LayerTreeHost. |
| 296 void SetChildrenNeedBeginFrames(bool need_begin_frame); |
| 297 |
278 gfx::Size size_; | 298 gfx::Size size_; |
279 | 299 |
280 ui::ContextFactory* context_factory_; | 300 ui::ContextFactory* context_factory_; |
281 | 301 |
282 // The root of the Layer tree drawn by this compositor. | 302 // The root of the Layer tree drawn by this compositor. |
283 Layer* root_layer_; | 303 Layer* root_layer_; |
284 | 304 |
285 ObserverList<CompositorObserver> observer_list_; | 305 ObserverList<CompositorObserver> observer_list_; |
286 ObserverList<CompositorAnimationObserver> animation_observer_list_; | 306 ObserverList<CompositorAnimationObserver> animation_observer_list_; |
| 307 ObserverList<CompositorBeginFrameObserver> begin_frame_observer_list_; |
287 | 308 |
288 gfx::AcceleratedWidget widget_; | 309 gfx::AcceleratedWidget widget_; |
289 scoped_refptr<cc::Layer> root_web_layer_; | 310 scoped_refptr<cc::Layer> root_web_layer_; |
290 scoped_ptr<cc::LayerTreeHost> host_; | 311 scoped_ptr<cc::LayerTreeHost> host_; |
291 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_; | 312 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_; |
292 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 313 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
293 | 314 |
294 // The manager of vsync parameters for this compositor. | |
295 scoped_refptr<CompositorVSyncManager> vsync_manager_; | |
296 | |
297 // The device scale factor of the monitor that this compositor is compositing | 315 // The device scale factor of the monitor that this compositor is compositing |
298 // layers on. | 316 // layers on. |
299 float device_scale_factor_; | 317 float device_scale_factor_; |
300 | 318 |
301 int last_started_frame_; | 319 int last_started_frame_; |
302 int last_ended_frame_; | 320 int last_ended_frame_; |
303 | 321 |
304 bool disable_schedule_composite_; | 322 bool disable_schedule_composite_; |
305 | 323 |
306 CompositorLock* compositor_lock_; | 324 CompositorLock* compositor_lock_; |
307 | 325 |
308 // Prevent more than one draw from being scheduled. | 326 // Prevent more than one draw from being scheduled. |
309 bool defer_draw_scheduling_; | 327 bool defer_draw_scheduling_; |
310 | 328 |
311 // Used to prevent Draw()s while a composite is in progress. | 329 // Used to prevent Draw()s while a composite is in progress. |
312 bool waiting_on_compositing_end_; | 330 bool waiting_on_compositing_end_; |
313 bool draw_on_compositing_end_; | 331 bool draw_on_compositing_end_; |
314 enum SwapState { SWAP_NONE, SWAP_POSTED, SWAP_COMPLETED }; | 332 enum SwapState { SWAP_NONE, SWAP_POSTED, SWAP_COMPLETED }; |
315 SwapState swap_state_; | 333 SwapState swap_state_; |
316 | 334 |
317 LayerAnimatorCollection layer_animator_collection_; | 335 LayerAnimatorCollection layer_animator_collection_; |
318 | 336 |
319 base::WeakPtrFactory<Compositor> schedule_draw_factory_; | 337 base::WeakPtrFactory<Compositor> schedule_draw_factory_; |
320 | 338 |
| 339 // Used to send to any new BeginFrame observers immediately. |
| 340 cc::BeginFrameArgs last_begin_frame_args_; |
| 341 |
| 342 // Only used to post OutputSurface::BeginFrame to |task_runner_|. because |
| 343 // requesting a BeginFrame from compositor is only used on single threaded |
| 344 // mode. |
| 345 base::WeakPtr<cc::OutputSurface> output_surface_weak_ptr_; |
| 346 |
| 347 bool output_surface_lost_; |
| 348 |
321 DISALLOW_COPY_AND_ASSIGN(Compositor); | 349 DISALLOW_COPY_AND_ASSIGN(Compositor); |
322 }; | 350 }; |
323 | 351 |
324 } // namespace ui | 352 } // namespace ui |
325 | 353 |
326 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 354 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
OLD | NEW |