| 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/surfaces/surface_sequence.h" | 16 #include "cc/surfaces/surface_sequence.h" |
| 17 #include "cc/trees/layer_tree_host_client.h" | 17 #include "cc/trees/layer_tree_host_client.h" |
| 18 #include "cc/trees/layer_tree_host_single_thread_client.h" | 18 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 19 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "ui/compositor/compositor_animation_observer.h" | 20 #include "ui/compositor/compositor_animation_observer.h" |
| 21 #include "ui/compositor/compositor_export.h" | 21 #include "ui/compositor/compositor_export.h" |
| 22 #include "ui/compositor/compositor_observer.h" | 22 #include "ui/compositor/compositor_observer.h" |
| 23 #include "ui/compositor/layer_animator_collection.h" | 23 #include "ui/compositor/layer_animator_collection.h" |
| 24 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
| 25 #include "ui/gfx/geometry/vector2d.h" | 25 #include "ui/gfx/geometry/vector2d.h" |
| 26 #include "ui/gfx/native_widget_types.h" | 26 #include "ui/gfx/native_widget_types.h" |
| 27 | 27 |
| 28 class SkBitmap; | |
| 29 | |
| 30 namespace base { | 28 namespace base { |
| 31 class MessageLoopProxy; | 29 class MessageLoopProxy; |
| 32 class RunLoop; | 30 class RunLoop; |
| 33 } | 31 } |
| 34 | 32 |
| 35 namespace cc { | 33 namespace cc { |
| 36 class ContextProvider; | 34 class ContextProvider; |
| 37 class Layer; | 35 class Layer; |
| 38 class LayerTreeDebugState; | 36 class LayerTreeDebugState; |
| 39 class LayerTreeHost; | 37 class LayerTreeHost; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 166 |
| 169 // Called when we need the compositor to preserve the alpha channel in the | 167 // Called when we need the compositor to preserve the alpha channel in the |
| 170 // output for situations when we want to render transparently atop something | 168 // output for situations when we want to render transparently atop something |
| 171 // else, e.g. Aero glass. | 169 // else, e.g. Aero glass. |
| 172 void SetHostHasTransparentBackground(bool host_has_transparent_background); | 170 void SetHostHasTransparentBackground(bool host_has_transparent_background); |
| 173 | 171 |
| 174 // The scale factor of the device that this compositor is | 172 // The scale factor of the device that this compositor is |
| 175 // compositing layers on. | 173 // compositing layers on. |
| 176 float device_scale_factor() const { return device_scale_factor_; } | 174 float device_scale_factor() const { return device_scale_factor_; } |
| 177 | 175 |
| 178 // Draws the scene created by the layer tree and any visual effects. | |
| 179 void Draw(); | |
| 180 | |
| 181 // Where possible, draws are scissored to a damage region calculated from | 176 // Where possible, draws are scissored to a damage region calculated from |
| 182 // changes to layer properties. This bypasses that and indicates that | 177 // changes to layer properties. This bypasses that and indicates that |
| 183 // the whole frame needs to be drawn. | 178 // the whole frame needs to be drawn. |
| 184 void ScheduleFullRedraw(); | 179 void ScheduleFullRedraw(); |
| 185 | 180 |
| 186 // Schedule redraw and append damage_rect to the damage region calculated | 181 // Schedule redraw and append damage_rect to the damage region calculated |
| 187 // from changes to layer properties. | 182 // from changes to layer properties. |
| 188 void ScheduleRedrawRect(const gfx::Rect& damage_rect); | 183 void ScheduleRedrawRect(const gfx::Rect& damage_rect); |
| 189 | 184 |
| 190 // Finishes all outstanding rendering and disables swapping on this surface | 185 // Finishes all outstanding rendering and disables swapping on this surface |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 void RequestNewOutputSurface() override; | 255 void RequestNewOutputSurface() override; |
| 261 void DidInitializeOutputSurface() override; | 256 void DidInitializeOutputSurface() override; |
| 262 void DidFailToInitializeOutputSurface() override; | 257 void DidFailToInitializeOutputSurface() override; |
| 263 void WillCommit() override {} | 258 void WillCommit() override {} |
| 264 void DidCommit() override; | 259 void DidCommit() override; |
| 265 void DidCommitAndDrawFrame() override; | 260 void DidCommitAndDrawFrame() override; |
| 266 void DidCompleteSwapBuffers() override; | 261 void DidCompleteSwapBuffers() override; |
| 267 void DidCompletePageScaleAnimation() override {} | 262 void DidCompletePageScaleAnimation() override {} |
| 268 | 263 |
| 269 // cc::LayerTreeHostSingleThreadClient implementation. | 264 // cc::LayerTreeHostSingleThreadClient implementation. |
| 270 void ScheduleComposite() override; | |
| 271 void ScheduleAnimation() override; | |
| 272 void DidPostSwapBuffers() override; | 265 void DidPostSwapBuffers() override; |
| 273 void DidAbortSwapBuffers() override; | 266 void DidAbortSwapBuffers() override; |
| 274 | 267 |
| 275 int last_started_frame() { return last_started_frame_; } | |
| 276 int last_ended_frame() { return last_ended_frame_; } | |
| 277 | |
| 278 bool IsLocked() { return compositor_lock_ != NULL; } | 268 bool IsLocked() { return compositor_lock_ != NULL; } |
| 279 | 269 |
| 280 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; | 270 const cc::LayerTreeDebugState& GetLayerTreeDebugState() const; |
| 281 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); | 271 void SetLayerTreeDebugState(const cc::LayerTreeDebugState& debug_state); |
| 282 const cc::RendererSettings& GetRendererSettings() const; | 272 const cc::RendererSettings& GetRendererSettings() const; |
| 283 | 273 |
| 284 LayerAnimatorCollection* layer_animator_collection() { | 274 LayerAnimatorCollection* layer_animator_collection() { |
| 285 return &layer_animator_collection_; | 275 return &layer_animator_collection_; |
| 286 } | 276 } |
| 287 | 277 |
| 288 cc::SurfaceIdAllocator* surface_id_allocator() { | 278 cc::SurfaceIdAllocator* surface_id_allocator() { |
| 289 return surface_id_allocator_.get(); | 279 return surface_id_allocator_.get(); |
| 290 } | 280 } |
| 291 | 281 |
| 292 private: | 282 private: |
| 293 friend class base::RefCounted<Compositor>; | 283 friend class base::RefCounted<Compositor>; |
| 294 friend class CompositorLock; | 284 friend class CompositorLock; |
| 295 | 285 |
| 296 enum { | 286 enum { |
| 297 OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4, | 287 OUTPUT_SURFACE_RETRIES_BEFORE_FALLBACK = 4, |
| 298 MAX_OUTPUT_SURFACE_RETRIES = 5, | 288 MAX_OUTPUT_SURFACE_RETRIES = 5, |
| 299 }; | 289 }; |
| 300 | 290 |
| 301 // Called by CompositorLock. | 291 // Called by CompositorLock. |
| 302 void UnlockCompositor(); | 292 void UnlockCompositor(); |
| 303 | 293 |
| 304 // Called to release any pending CompositorLock | 294 // Called to release any pending CompositorLock |
| 305 void CancelCompositorLock(); | 295 void CancelCompositorLock(); |
| 306 | 296 |
| 307 // Notifies the compositor that compositing is complete. | |
| 308 void NotifyEnd(); | |
| 309 | |
| 310 gfx::Size size_; | 297 gfx::Size size_; |
| 311 | 298 |
| 312 ui::ContextFactory* context_factory_; | 299 ui::ContextFactory* context_factory_; |
| 313 | 300 |
| 314 // The root of the Layer tree drawn by this compositor. | 301 // The root of the Layer tree drawn by this compositor. |
| 315 Layer* root_layer_; | 302 Layer* root_layer_; |
| 316 | 303 |
| 317 ObserverList<CompositorObserver, true> observer_list_; | 304 ObserverList<CompositorObserver, true> observer_list_; |
| 318 ObserverList<CompositorAnimationObserver> animation_observer_list_; | 305 ObserverList<CompositorAnimationObserver> animation_observer_list_; |
| 319 | 306 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 333 | 320 |
| 334 int last_started_frame_; | 321 int last_started_frame_; |
| 335 int last_ended_frame_; | 322 int last_ended_frame_; |
| 336 | 323 |
| 337 int num_failed_recreate_attempts_; | 324 int num_failed_recreate_attempts_; |
| 338 | 325 |
| 339 bool disable_schedule_composite_; | 326 bool disable_schedule_composite_; |
| 340 | 327 |
| 341 CompositorLock* compositor_lock_; | 328 CompositorLock* compositor_lock_; |
| 342 | 329 |
| 343 // Prevent more than one draw from being scheduled. | |
| 344 bool defer_draw_scheduling_; | |
| 345 | |
| 346 // Used to prevent Draw()s while a composite is in progress. | |
| 347 bool waiting_on_compositing_end_; | |
| 348 bool draw_on_compositing_end_; | |
| 349 enum SwapState { SWAP_NONE, SWAP_POSTED, SWAP_COMPLETED }; | |
| 350 SwapState swap_state_; | |
| 351 | |
| 352 LayerAnimatorCollection layer_animator_collection_; | 330 LayerAnimatorCollection layer_animator_collection_; |
| 353 | 331 |
| 354 base::WeakPtrFactory<Compositor> weak_ptr_factory_; | 332 base::WeakPtrFactory<Compositor> weak_ptr_factory_; |
| 355 | 333 |
| 356 DISALLOW_COPY_AND_ASSIGN(Compositor); | 334 DISALLOW_COPY_AND_ASSIGN(Compositor); |
| 357 }; | 335 }; |
| 358 | 336 |
| 359 } // namespace ui | 337 } // namespace ui |
| 360 | 338 |
| 361 #endif // UI_COMPOSITOR_COMPOSITOR_H_ | 339 #endif // UI_COMPOSITOR_COMPOSITOR_H_ |
| OLD | NEW |