| 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/trees/layer_tree_host_client.h" | 16 #include "cc/trees/layer_tree_host_client.h" |
| 17 #include "cc/trees/layer_tree_host_single_thread_client.h" | 17 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
| 19 #include "ui/base/compositor/begin_frame_manager.h" |
| 19 #include "ui/compositor/compositor_animation_observer.h" | 20 #include "ui/compositor/compositor_animation_observer.h" |
| 20 #include "ui/compositor/compositor_export.h" | 21 #include "ui/compositor/compositor_export.h" |
| 21 #include "ui/compositor/compositor_observer.h" | 22 #include "ui/compositor/compositor_observer.h" |
| 22 #include "ui/compositor/layer_animator_collection.h" | 23 #include "ui/compositor/layer_animator_collection.h" |
| 23 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
| 24 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
| 25 #include "ui/gfx/vector2d.h" | 26 #include "ui/gfx/vector2d.h" |
| 26 | 27 |
| 27 namespace base { | 28 namespace base { |
| 28 class MessageLoopProxy; | 29 class MessageLoopProxy; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 41 class Rect; | 42 class Rect; |
| 42 class Size; | 43 class Size; |
| 43 } | 44 } |
| 44 | 45 |
| 45 namespace gpu { | 46 namespace gpu { |
| 46 struct Mailbox; | 47 struct Mailbox; |
| 47 } | 48 } |
| 48 | 49 |
| 49 namespace ui { | 50 namespace ui { |
| 50 | 51 |
| 52 class BeginFrameManager; |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 DISALLOW_COPY_AND_ASSIGN(CompositorLock); | 121 DISALLOW_COPY_AND_ASSIGN(CompositorLock); |
| 121 }; | 122 }; |
| 122 | 123 |
| 123 // Compositor object to take care of GPU painting. | 124 // Compositor object to take care of GPU painting. |
| 124 // A Browser compositor object is responsible for generating the final | 125 // A Browser compositor object is responsible for generating the final |
| 125 // displayable form of pixels comprising a single widget's contents. It draws an | 126 // displayable form of pixels comprising a single widget's contents. It draws an |
| 126 // appropriately transformed texture for each transformed view in the widget's | 127 // appropriately transformed texture for each transformed view in the widget's |
| 127 // view hierarchy. | 128 // view hierarchy. |
| 128 class COMPOSITOR_EXPORT Compositor | 129 class COMPOSITOR_EXPORT Compositor |
| 129 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), | 130 : NON_EXPORTED_BASE(public cc::LayerTreeHostClient), |
| 130 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) { | 131 NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient), |
| 132 NON_EXPORTED_BASE(public ui::BeginFrameManager::Delegate) { |
| 131 public: | 133 public: |
| 132 Compositor(gfx::AcceleratedWidget widget, | 134 Compositor(gfx::AcceleratedWidget widget, |
| 133 ui::ContextFactory* context_factory, | 135 ui::ContextFactory* context_factory, |
| 134 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 136 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 135 virtual ~Compositor(); | 137 virtual ~Compositor(); |
| 136 | 138 |
| 137 ui::ContextFactory* context_factory() { return context_factory_; } | 139 ui::ContextFactory* context_factory() { return context_factory_; } |
| 138 | 140 |
| 139 // Schedules a redraw of the layer tree associated with this compositor. | 141 // Schedules a redraw of the layer tree associated with this compositor. |
| 140 void ScheduleDraw(); | 142 void ScheduleDraw(); |
| (...skipping 36 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. | 179 // Returns the size of the widget that is being drawn to in pixel coordinates. |
| 178 const gfx::Size& size() const { return size_; } | 180 const gfx::Size& size() const { return size_; } |
| 179 | 181 |
| 180 // Sets the background color used for areas that aren't covered by | 182 // Sets the background color used for areas that aren't covered by |
| 181 // the |root_layer|. | 183 // the |root_layer|. |
| 182 void SetBackgroundColor(SkColor color); | 184 void SetBackgroundColor(SkColor color); |
| 183 | 185 |
| 184 // Returns the widget for this compositor. | 186 // Returns the widget for this compositor. |
| 185 gfx::AcceleratedWidget widget() const { return widget_; } | 187 gfx::AcceleratedWidget widget() const { return widget_; } |
| 186 | 188 |
| 187 // Returns the vsync manager for this compositor. | 189 BeginFrameManager* begin_frame_manager() const { |
| 188 scoped_refptr<CompositorVSyncManager> vsync_manager() const; | 190 return begin_frame_manager_.get(); |
| 191 } |
| 189 | 192 |
| 190 // Compositor does not own observers. It is the responsibility of the | 193 // Compositor does not own observers. It is the responsibility of the |
| 191 // observer to remove itself when it is done observing. | 194 // observer to remove itself when it is done observing. |
| 192 void AddObserver(CompositorObserver* observer); | 195 void AddObserver(CompositorObserver* observer); |
| 193 void RemoveObserver(CompositorObserver* observer); | 196 void RemoveObserver(CompositorObserver* observer); |
| 194 bool HasObserver(CompositorObserver* observer); | 197 bool HasObserver(CompositorObserver* observer); |
| 195 | 198 |
| 196 void AddAnimationObserver(CompositorAnimationObserver* observer); | 199 void AddAnimationObserver(CompositorAnimationObserver* observer); |
| 197 void RemoveAnimationObserver(CompositorAnimationObserver* observer); | 200 void RemoveAnimationObserver(CompositorAnimationObserver* observer); |
| 198 bool HasAnimationObserver(CompositorAnimationObserver* observer); | 201 bool HasAnimationObserver(CompositorAnimationObserver* observer); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 220 virtual void Layout() OVERRIDE; | 223 virtual void Layout() OVERRIDE; |
| 221 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, | 224 virtual void ApplyScrollAndScale(const gfx::Vector2d& scroll_delta, |
| 222 float page_scale) OVERRIDE {} | 225 float page_scale) OVERRIDE {} |
| 223 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) | 226 virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(bool fallback) |
| 224 OVERRIDE; | 227 OVERRIDE; |
| 225 virtual void DidInitializeOutputSurface() OVERRIDE {} | 228 virtual void DidInitializeOutputSurface() OVERRIDE {} |
| 226 virtual void WillCommit() OVERRIDE {} | 229 virtual void WillCommit() OVERRIDE {} |
| 227 virtual void DidCommit() OVERRIDE; | 230 virtual void DidCommit() OVERRIDE; |
| 228 virtual void DidCommitAndDrawFrame() OVERRIDE; | 231 virtual void DidCommitAndDrawFrame() OVERRIDE; |
| 229 virtual void DidCompleteSwapBuffers() OVERRIDE; | 232 virtual void DidCompleteSwapBuffers() OVERRIDE; |
| 233 virtual void SendBeginFrame(const cc::BeginFrameArgs& args) OVERRIDE; |
| 230 | 234 |
| 231 // cc::LayerTreeHostSingleThreadClient implementation. | 235 // cc::LayerTreeHostSingleThreadClient implementation. |
| 232 virtual void DidPostSwapBuffers() OVERRIDE; | 236 virtual void DidPostSwapBuffers() OVERRIDE; |
| 233 virtual void DidAbortSwapBuffers() OVERRIDE; | 237 virtual void DidAbortSwapBuffers() OVERRIDE; |
| 234 | 238 |
| 239 // ui::BeginFrameManager::Delegate implementation. |
| 240 virtual void RequestBeginFrame() OVERRIDE; |
| 241 |
| 235 bool IsLocked() { return compositor_lock_ != NULL; } | 242 bool IsLocked() { return compositor_lock_ != NULL; } |
| 236 | 243 |
| 237 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; | 244 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; |
| 238 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); | 245 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); |
| 239 | 246 |
| 240 LayerAnimatorCollection* layer_animator_collection() { | 247 LayerAnimatorCollection* layer_animator_collection() { |
| 241 return &layer_animator_collection_; | 248 return &layer_animator_collection_; |
| 242 } | 249 } |
| 243 | 250 |
| 244 private: | 251 private: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 260 | 267 |
| 261 ObserverList<CompositorObserver> observer_list_; | 268 ObserverList<CompositorObserver> observer_list_; |
| 262 ObserverList<CompositorAnimationObserver> animation_observer_list_; | 269 ObserverList<CompositorAnimationObserver> animation_observer_list_; |
| 263 | 270 |
| 264 gfx::AcceleratedWidget widget_; | 271 gfx::AcceleratedWidget widget_; |
| 265 scoped_refptr<cc::Layer> root_web_layer_; | 272 scoped_refptr<cc::Layer> root_web_layer_; |
| 266 scoped_ptr<cc::LayerTreeHost> host_; | 273 scoped_ptr<cc::LayerTreeHost> host_; |
| 267 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_; | 274 scoped_refptr<base::MessageLoopProxy> compositor_thread_loop_; |
| 268 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 275 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 269 | 276 |
| 270 // The manager of vsync parameters for this compositor. | 277 // The manager of BeginFrame routing. |
| 271 scoped_refptr<CompositorVSyncManager> vsync_manager_; | 278 scoped_ptr<BeginFrameManager> begin_frame_manager_; |
| 272 | 279 |
| 273 // The device scale factor of the monitor that this compositor is compositing | 280 // The device scale factor of the monitor that this compositor is compositing |
| 274 // layers on. | 281 // layers on. |
| 275 float device_scale_factor_; | 282 float device_scale_factor_; |
| 276 | 283 |
| 277 int last_started_frame_; | 284 int last_started_frame_; |
| 278 int last_ended_frame_; | 285 int last_ended_frame_; |
| 279 | 286 |
| 280 bool disable_schedule_composite_; | 287 bool disable_schedule_composite_; |
| 281 | 288 |
| 282 CompositorLock* compositor_lock_; | 289 CompositorLock* compositor_lock_; |
| 283 | 290 |
| 284 LayerAnimatorCollection layer_animator_collection_; | 291 LayerAnimatorCollection layer_animator_collection_; |
| 285 | 292 |
| 286 DISALLOW_COPY_AND_ASSIGN(Compositor); | 293 DISALLOW_COPY_AND_ASSIGN(Compositor); |
| 287 }; | 294 }; |
| 288 | 295 |
| 289 } // namespace ui | 296 } // namespace ui |
| 290 | 297 |
| 291 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 298 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
| OLD | NEW |