| 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 #include "ui/compositor/compositor.h" | 5 #include "ui/compositor/compositor.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 17 #include "cc/base/latency_info_swap_promise.h" | 17 #include "cc/base/latency_info_swap_promise.h" |
| 18 #include "cc/base/switches.h" | 18 #include "cc/base/switches.h" |
| 19 #include "cc/input/input_handler.h" | 19 #include "cc/input/input_handler.h" |
| 20 #include "cc/layers/layer.h" | 20 #include "cc/layers/layer.h" |
| 21 #include "cc/output/context_provider.h" | 21 #include "cc/output/context_provider.h" |
| 22 #include "cc/trees/layer_tree_host.h" | 22 #include "cc/trees/layer_tree_host.h" |
| 23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #include "ui/compositor/compositor_observer.h" | 24 #include "ui/compositor/compositor_observer.h" |
| 25 #include "ui/compositor/compositor_switches.h" | 25 #include "ui/compositor/compositor_switches.h" |
| 26 #include "ui/compositor/compositor_vsync_manager.h" | |
| 27 #include "ui/compositor/dip_util.h" | 26 #include "ui/compositor/dip_util.h" |
| 28 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
| 29 #include "ui/compositor/layer_animator_collection.h" | 28 #include "ui/compositor/layer_animator_collection.h" |
| 30 #include "ui/gfx/frame_time.h" | 29 #include "ui/gfx/frame_time.h" |
| 31 #include "ui/gl/gl_context.h" | 30 #include "ui/gl/gl_context.h" |
| 32 #include "ui/gl/gl_switches.h" | 31 #include "ui/gl/gl_switches.h" |
| 33 | 32 |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 const double kDefaultRefreshRate = 60.0; | 35 const double kDefaultRefreshRate = 60.0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 62 } | 61 } |
| 63 | 62 |
| 64 Compositor::Compositor(gfx::AcceleratedWidget widget, | 63 Compositor::Compositor(gfx::AcceleratedWidget widget, |
| 65 ui::ContextFactory* context_factory, | 64 ui::ContextFactory* context_factory, |
| 66 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 65 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 67 : context_factory_(context_factory), | 66 : context_factory_(context_factory), |
| 68 root_layer_(NULL), | 67 root_layer_(NULL), |
| 69 widget_(widget), | 68 widget_(widget), |
| 70 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), | 69 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), |
| 71 task_runner_(task_runner), | 70 task_runner_(task_runner), |
| 72 vsync_manager_(new CompositorVSyncManager()), | 71 begin_frame_manager_(new BeginFrameManager(this)), |
| 73 device_scale_factor_(0.0f), | 72 device_scale_factor_(0.0f), |
| 74 disable_schedule_composite_(false), | 73 disable_schedule_composite_(false), |
| 75 compositor_lock_(NULL), | 74 compositor_lock_(NULL), |
| 76 layer_animator_collection_(this) { | 75 layer_animator_collection_(this) { |
| 77 root_web_layer_ = cc::Layer::Create(); | 76 root_web_layer_ = cc::Layer::Create(); |
| 78 | 77 |
| 79 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 78 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 80 | 79 |
| 81 cc::LayerTreeSettings settings; | 80 cc::LayerTreeSettings settings; |
| 82 settings.refresh_rate = | 81 settings.refresh_rate = |
| 83 context_factory_->DoesCreateTestContexts() | 82 context_factory_->DoesCreateTestContexts() |
| 84 ? kTestRefreshRate | 83 ? kTestRefreshRate |
| 85 : kDefaultRefreshRate; | 84 : kDefaultRefreshRate; |
| 86 settings.main_frame_before_draw_enabled = false; | 85 settings.main_frame_before_draw_enabled = false; |
| 87 settings.main_frame_before_activation_enabled = false; | 86 settings.main_frame_before_activation_enabled = false; |
| 88 settings.throttle_frame_production = | 87 settings.throttle_frame_production = |
| 89 !command_line->HasSwitch(switches::kDisableGpuVsync); | 88 !command_line->HasSwitch(switches::kDisableGpuVsync); |
| 90 #if !defined(OS_MACOSX) | 89 #if !defined(OS_MACOSX) |
| 91 settings.partial_swap_enabled = | 90 settings.partial_swap_enabled = |
| 92 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); | 91 !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); |
| 92 settings.begin_frame_publisher = |
| 93 command_line->HasSwitch(cc::switches::kEnableBeginFrameScheduling); |
| 93 #endif | 94 #endif |
| 94 #if defined(OS_CHROMEOS) | 95 #if defined(OS_CHROMEOS) |
| 95 settings.per_tile_painting_enabled = true; | 96 settings.per_tile_painting_enabled = true; |
| 96 #endif | 97 #endif |
| 97 | 98 |
| 98 // These flags should be mirrored by renderer versions in content/renderer/. | 99 // These flags should be mirrored by renderer versions in content/renderer/. |
| 99 settings.initial_debug_state.show_debug_borders = | 100 settings.initial_debug_state.show_debug_borders = |
| 100 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders); | 101 command_line->HasSwitch(cc::switches::kUIShowCompositedLayerBorders); |
| 101 settings.initial_debug_state.show_fps_counter = | 102 settings.initial_debug_state.show_fps_counter = |
| 102 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); | 103 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (root_layer_) | 222 if (root_layer_) |
| 222 root_layer_->OnDeviceScaleFactorChanged(scale); | 223 root_layer_->OnDeviceScaleFactorChanged(scale); |
| 223 } | 224 } |
| 224 } | 225 } |
| 225 | 226 |
| 226 void Compositor::SetBackgroundColor(SkColor color) { | 227 void Compositor::SetBackgroundColor(SkColor color) { |
| 227 host_->set_background_color(color); | 228 host_->set_background_color(color); |
| 228 ScheduleDraw(); | 229 ScheduleDraw(); |
| 229 } | 230 } |
| 230 | 231 |
| 231 scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const { | |
| 232 return vsync_manager_; | |
| 233 } | |
| 234 | |
| 235 void Compositor::AddObserver(CompositorObserver* observer) { | 232 void Compositor::AddObserver(CompositorObserver* observer) { |
| 236 observer_list_.AddObserver(observer); | 233 observer_list_.AddObserver(observer); |
| 237 } | 234 } |
| 238 | 235 |
| 239 void Compositor::RemoveObserver(CompositorObserver* observer) { | 236 void Compositor::RemoveObserver(CompositorObserver* observer) { |
| 240 observer_list_.RemoveObserver(observer); | 237 observer_list_.RemoveObserver(observer); |
| 241 } | 238 } |
| 242 | 239 |
| 243 bool Compositor::HasObserver(CompositorObserver* observer) { | 240 bool Compositor::HasObserver(CompositorObserver* observer) { |
| 244 return observer_list_.HasObserver(observer); | 241 return observer_list_.HasObserver(observer); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 if (compositor_thread_loop_) { | 293 if (compositor_thread_loop_) { |
| 297 base::TimeTicks start_time = gfx::FrameTime::Now(); | 294 base::TimeTicks start_time = gfx::FrameTime::Now(); |
| 298 FOR_EACH_OBSERVER(CompositorObserver, | 295 FOR_EACH_OBSERVER(CompositorObserver, |
| 299 observer_list_, | 296 observer_list_, |
| 300 OnCompositingStarted(this, start_time)); | 297 OnCompositingStarted(this, start_time)); |
| 301 } | 298 } |
| 302 FOR_EACH_OBSERVER( | 299 FOR_EACH_OBSERVER( |
| 303 CompositorObserver, observer_list_, OnCompositingEnded(this)); | 300 CompositorObserver, observer_list_, OnCompositingEnded(this)); |
| 304 } | 301 } |
| 305 | 302 |
| 303 void Compositor::SendBeginFrame(const cc::BeginFrameArgs& args) { |
| 304 begin_frame_manager_->SendBeginFrame(args); |
| 305 } |
| 306 |
| 306 void Compositor::DidPostSwapBuffers() { | 307 void Compositor::DidPostSwapBuffers() { |
| 307 base::TimeTicks start_time = gfx::FrameTime::Now(); | 308 base::TimeTicks start_time = gfx::FrameTime::Now(); |
| 308 FOR_EACH_OBSERVER(CompositorObserver, | 309 FOR_EACH_OBSERVER(CompositorObserver, |
| 309 observer_list_, | 310 observer_list_, |
| 310 OnCompositingStarted(this, start_time)); | 311 OnCompositingStarted(this, start_time)); |
| 311 } | 312 } |
| 312 | 313 |
| 313 void Compositor::DidAbortSwapBuffers() { | 314 void Compositor::DidAbortSwapBuffers() { |
| 314 FOR_EACH_OBSERVER(CompositorObserver, | 315 FOR_EACH_OBSERVER(CompositorObserver, |
| 315 observer_list_, | 316 observer_list_, |
| 316 OnCompositingAborted(this)); | 317 OnCompositingAborted(this)); |
| 317 } | 318 } |
| 318 | 319 |
| 320 void Compositor::RequestBeginFrame() { |
| 321 host_->RequestBeginFrame(); |
| 322 } |
| 323 |
| 319 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { | 324 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { |
| 320 return host_->debug_state(); | 325 return host_->debug_state(); |
| 321 } | 326 } |
| 322 | 327 |
| 323 void Compositor::SetLayerTreeDebugState( | 328 void Compositor::SetLayerTreeDebugState( |
| 324 const cc::LayerTreeDebugState& debug_state) { | 329 const cc::LayerTreeDebugState& debug_state) { |
| 325 host_->SetDebugState(debug_state); | 330 host_->SetDebugState(debug_state); |
| 326 } | 331 } |
| 327 | 332 |
| 328 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { | 333 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 344 observer_list_, | 349 observer_list_, |
| 345 OnCompositingLockStateChanged(this)); | 350 OnCompositingLockStateChanged(this)); |
| 346 } | 351 } |
| 347 | 352 |
| 348 void Compositor::CancelCompositorLock() { | 353 void Compositor::CancelCompositorLock() { |
| 349 if (compositor_lock_) | 354 if (compositor_lock_) |
| 350 compositor_lock_->CancelLock(); | 355 compositor_lock_->CancelLock(); |
| 351 } | 356 } |
| 352 | 357 |
| 353 } // namespace ui | 358 } // namespace ui |
| OLD | NEW |