| 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 namespace base { | 29 namespace base { |
| 28 class MessageLoopProxy; | 30 class MessageLoopProxy; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 42 class Size; | 44 class Size; |
| 43 } | 45 } |
| 44 | 46 |
| 45 namespace gpu { | 47 namespace gpu { |
| 46 struct Mailbox; | 48 struct Mailbox; |
| 47 } | 49 } |
| 48 | 50 |
| 49 namespace ui { | 51 namespace ui { |
| 50 | 52 |
| 51 class Compositor; | 53 class Compositor; |
| 52 class CompositorVSyncManager; | |
| 53 class Layer; | 54 class Layer; |
| 54 class Reflector; | 55 class Reflector; |
| 55 class Texture; | 56 class Texture; |
| 56 struct LatencyInfo; | 57 struct LatencyInfo; |
| 57 | 58 |
| 58 // This class abstracts the creation of the 3D context for the compositor. It is | 59 // This class abstracts the creation of the 3D context for the compositor. It is |
| 59 // a global object. | 60 // a global object. |
| 60 class COMPOSITOR_EXPORT ContextFactory { | 61 class COMPOSITOR_EXPORT ContextFactory { |
| 61 public: | 62 public: |
| 62 virtual ~ContextFactory() {} | 63 virtual ~ContextFactory() {} |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // Returns the size of the widget that is being drawn to in pixel coordinates. | 178 // Returns the size of the widget that is being drawn to in pixel coordinates. |
| 178 const gfx::Size& size() const { return size_; } | 179 const gfx::Size& size() const { return size_; } |
| 179 | 180 |
| 180 // Sets the background color used for areas that aren't covered by | 181 // Sets the background color used for areas that aren't covered by |
| 181 // the |root_layer|. | 182 // the |root_layer|. |
| 182 void SetBackgroundColor(SkColor color); | 183 void SetBackgroundColor(SkColor color); |
| 183 | 184 |
| 184 // Returns the widget for this compositor. | 185 // Returns the widget for this compositor. |
| 185 gfx::AcceleratedWidget widget() const { return widget_; } | 186 gfx::AcceleratedWidget widget() const { return widget_; } |
| 186 | 187 |
| 187 // Returns the vsync manager for this compositor. | 188 // The "authoritative" vsync interval, if provided, will override interval |
| 188 scoped_refptr<CompositorVSyncManager> vsync_manager() const; | 189 // reported from 3D context. This is typically the value reported by a more |
| 190 // reliable source, e.g, the platform display configuration. |
| 191 // In the particular case of ChromeOS -- this is the value queried through |
| 192 // XRandR, which is more reliable than the value queried through the 3D |
| 193 // context. |
| 194 void SetAuthoritativeVSyncInterval(base::TimeDelta interval) const; |
| 195 |
| 196 // Request BeginFrame scheduling to OutputSurface. |
| 197 void StartBeginFrame(const cc::BeginFrameArgs& args) const; |
| 189 | 198 |
| 190 // Compositor does not own observers. It is the responsibility of the | 199 // Compositor does not own observers. It is the responsibility of the |
| 191 // observer to remove itself when it is done observing. | 200 // observer to remove itself when it is done observing. |
| 192 void AddObserver(CompositorObserver* observer); | 201 void AddObserver(CompositorObserver* observer); |
| 193 void RemoveObserver(CompositorObserver* observer); | 202 void RemoveObserver(CompositorObserver* observer); |
| 194 bool HasObserver(CompositorObserver* observer); | 203 bool HasObserver(CompositorObserver* observer); |
| 195 | 204 |
| 196 void AddAnimationObserver(CompositorAnimationObserver* observer); | 205 void AddAnimationObserver(CompositorAnimationObserver* observer); |
| 197 void RemoveAnimationObserver(CompositorAnimationObserver* observer); | 206 void RemoveAnimationObserver(CompositorAnimationObserver* observer); |
| 198 bool HasAnimationObserver(CompositorAnimationObserver* observer); | 207 bool HasAnimationObserver(CompositorAnimationObserver* observer); |
| 199 | 208 |
| 209 void AddBeginFrameObserver( |
| 210 CompositorBeginFrameObserver* observer, |
| 211 const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer); |
| 212 void RemoveBeginFrameObserver(CompositorBeginFrameObserver* observer); |
| 213 |
| 200 // Creates a compositor lock. Returns NULL if it is not possible to lock at | 214 // Creates a compositor lock. Returns NULL if it is not possible to lock at |
| 201 // this time (i.e. we're waiting to complete a previous unlock). | 215 // this time (i.e. we're waiting to complete a previous unlock). |
| 202 scoped_refptr<CompositorLock> GetCompositorLock(); | 216 scoped_refptr<CompositorLock> GetCompositorLock(); |
| 203 | 217 |
| 204 // Internal functions, called back by command-buffer contexts on swap buffer | 218 // Internal functions, called back by command-buffer contexts on swap buffer |
| 205 // events. | 219 // events. |
| 206 | 220 |
| 207 // Signals swap has been posted. | 221 // Signals swap has been posted. |
| 208 void OnSwapBuffersPosted(); | 222 void OnSwapBuffersPosted(); |
| 209 | 223 |
| 210 // Signals swap has completed. | 224 // Signals swap has completed. |
| 211 void OnSwapBuffersComplete(); | 225 void OnSwapBuffersComplete(); |
| 212 | 226 |
| 213 // Signals swap has aborted (e.g. lost context). | 227 // Signals swap has aborted (e.g. lost context). |
| 214 void OnSwapBuffersAborted(); | 228 void OnSwapBuffersAborted(); |
| 215 | 229 |
| 216 // LayerTreeHostClient implementation. | 230 // LayerTreeHostClient implementation. |
| 217 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} | 231 virtual void WillBeginMainFrame(int frame_id) OVERRIDE {} |
| 218 virtual void DidBeginMainFrame() OVERRIDE {} | 232 virtual void DidBeginMainFrame() OVERRIDE {} |
| 219 virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE; | 233 virtual void Animate(base::TimeTicks frame_begin_time) OVERRIDE; |
| 220 virtual void Layout() OVERRIDE; | 234 virtual void Layout() OVERRIDE; |
| 221 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, | 235 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, |
| 222 float page_scale) OVERRIDE {} | 236 float page_scale) OVERRIDE {} |
| 223 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) | 237 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) |
| 224 OVERRIDE; | 238 OVERRIDE; |
| 225 virtual void DidInitializeOutputSurface() OVERRIDE {} | 239 virtual void DidInitializeOutputSurface() OVERRIDE; |
| 240 virtual void DidLoseOutputSurface() OVERRIDE; |
| 226 virtual void WillCommit() OVERRIDE {} | 241 virtual void WillCommit() OVERRIDE {} |
| 227 virtual void DidCommit() OVERRIDE; | 242 virtual void DidCommit() OVERRIDE; |
| 228 virtual void DidCommitAndDrawFrame() OVERRIDE; | 243 virtual void DidCommitAndDrawFrame() OVERRIDE; |
| 229 virtual void DidCompleteSwapBuffers() OVERRIDE; | 244 virtual void DidCompleteSwapBuffers() OVERRIDE; |
| 245 virtual void SendBeginFrameToChildren( |
| 246 const cc::BeginFrameArgs& args) OVERRIDE; |
| 230 | 247 |
| 231 // cc::LayerTreeHostSingleThreadClient implementation. | 248 // cc::LayerTreeHostSingleThreadClient implementation. |
| 232 virtual void DidPostSwapBuffers() OVERRIDE; | 249 virtual void DidPostSwapBuffers() OVERRIDE; |
| 233 virtual void DidAbortSwapBuffers() OVERRIDE; | 250 virtual void DidAbortSwapBuffers() OVERRIDE; |
| 234 | 251 |
| 235 bool IsLocked() { return compositor_lock_ != NULL; } | 252 bool IsLocked() { return compositor_lock_ != NULL; } |
| 236 | 253 |
| 237 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; | 254 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; |
| 238 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); | 255 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); |
| 239 | 256 |
| 240 LayerAnimatorCollection* layer_animator_collection() { | 257 LayerAnimatorCollection* layer_animator_collection() { |
| 241 return &layer_animator_collection_; | 258 return &layer_animator_collection_; |
| 242 } | 259 } |
| 243 | 260 |
| 244 private: | 261 private: |
| 245 friend class base::RefCounted<Compositor>; | 262 friend class base::RefCounted<Compositor>; |
| 246 friend class CompositorLock; | 263 friend class CompositorLock; |
| 247 | 264 |
| 248 // Called by CompositorLock. | 265 // Called by CompositorLock. |
| 249 void UnlockCompositor(); | 266 void UnlockCompositor(); |
| 250 | 267 |
| 251 // Called to release any pending CompositorLock | 268 // Called to release any pending CompositorLock |
| 252 void CancelCompositorLock(); | 269 void CancelCompositorLock(); |
| 253 | 270 |
| 271 // Request scheduling of next BeginFrame to LayerTreeHost. |
| 272 void SetChildrenNeedBeginFrames(bool need_begin_frame); |
| 273 |
| 254 gfx::Size size_; | 274 gfx::Size size_; |
| 255 | 275 |
| 256 ui::ContextFactory* context_factory_; | 276 ui::ContextFactory* context_factory_; |
| 257 | 277 |
| 258 // The root of the Layer tree drawn by this compositor. | 278 // The root of the Layer tree drawn by this compositor. |
| 259 Layer* root_layer_; | 279 Layer* root_layer_; |
| 260 | 280 |
| 261 ObserverList<CompositorObserver> observer_list_; | 281 ObserverList<CompositorObserver> observer_list_; |
| 262 ObserverList<CompositorAnimationObserver> animation_observer_list_; | 282 ObserverList<CompositorAnimationObserver> animation_observer_list_; |
| 283 ObserverList<CompositorBeginFrameObserver> begin_frame_observer_list_; |
| 263 | 284 |
| 264 gfx::AcceleratedWidget widget_; | 285 gfx::AcceleratedWidget widget_; |
| 265 scoped_refptr<cc::Layer> root_web_layer_; | 286 scoped_refptr<cc::Layer> root_web_layer_; |
| 266 scoped_ptr<cc::LayerTreeHost> host_; | 287 scoped_ptr<cc::LayerTreeHost> host_; |
| 267 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_; | 288 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_; |
| 268 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 289 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 269 | 290 |
| 270 // The manager of vsync parameters for this compositor. | |
| 271 scoped_refptr<CompositorVSyncManager> vsync_manager_; | |
| 272 | |
| 273 // The device scale factor of the monitor that this compositor is compositing | 291 // The device scale factor of the monitor that this compositor is compositing |
| 274 // layers on. | 292 // layers on. |
| 275 float device_scale_factor_; | 293 float device_scale_factor_; |
| 276 | 294 |
| 277 int last_started_frame_; | 295 int last_started_frame_; |
| 278 int last_ended_frame_; | 296 int last_ended_frame_; |
| 279 | 297 |
| 280 bool disable_schedule_composite_; | 298 bool disable_schedule_composite_; |
| 281 | 299 |
| 282 CompositorLock* compositor_lock_; | 300 CompositorLock* compositor_lock_; |
| 283 | 301 |
| 284 LayerAnimatorCollection layer_animator_collection_; | 302 LayerAnimatorCollection layer_animator_collection_; |
| 285 | 303 |
| 304 // Used to send to any new BeginFrame observers immediately. |
| 305 cc::BeginFrameArgs last_begin_frame_args_; |
| 306 |
| 307 // Only used to post OutputSurface::BeginFrame to |task_runner_|. because |
| 308 // requesting a BeginFrame from compositor is only used on single threaded |
| 309 // mode. |
| 310 base::WeakPtr<cc::OutputSurface> output_surface_weak_ptr_; |
| 311 |
| 312 bool output_surface_lost_; |
| 313 |
| 286 DISALLOW_COPY_AND_ASSIGN(Compositor); | 314 DISALLOW_COPY_AND_ASSIGN(Compositor); |
| 287 }; | 315 }; |
| 288 | 316 |
| 289 } // namespace ui | 317 } // namespace ui |
| 290 | 318 |
| 291 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 319 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
| OLD | NEW |