| 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/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 21 #include "cc/base/latency_info_swap_promise.h" | 21 #include "cc/base/latency_info_swap_promise.h" |
| 22 #include "cc/base/switches.h" | 22 #include "cc/base/switches.h" |
| 23 #include "cc/input/input_handler.h" | 23 #include "cc/input/input_handler.h" |
| 24 #include "cc/layers/layer.h" | 24 #include "cc/layers/layer.h" |
| 25 #include "cc/output/context_provider.h" | 25 #include "cc/output/context_provider.h" |
| 26 #include "cc/trees/layer_tree_host.h" | 26 #include "cc/trees/layer_tree_host.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
| 28 #include "ui/compositor/compositor_observer.h" | 28 #include "ui/compositor/compositor_observer.h" |
| 29 #include "ui/compositor/compositor_switches.h" | 29 #include "ui/compositor/compositor_switches.h" |
| 30 #include "ui/compositor/compositor_vsync_manager.h" |
| 30 #include "ui/compositor/dip_util.h" | 31 #include "ui/compositor/dip_util.h" |
| 31 #include "ui/compositor/layer.h" | 32 #include "ui/compositor/layer.h" |
| 32 #include "ui/gfx/frame_time.h" | 33 #include "ui/gfx/frame_time.h" |
| 33 #include "ui/gl/gl_context.h" | 34 #include "ui/gl/gl_context.h" |
| 34 #include "ui/gl/gl_switches.h" | 35 #include "ui/gl/gl_switches.h" |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 const double kDefaultRefreshRate = 60.0; | 39 const double kDefaultRefreshRate = 60.0; |
| 39 const double kTestRefreshRate = 200.0; | 40 const double kTestRefreshRate = 200.0; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 posted_swaps_->pending_swap_ = NULL; | 177 posted_swaps_->pending_swap_ = NULL; |
| 177 } | 178 } |
| 178 | 179 |
| 179 } // namespace | 180 } // namespace |
| 180 | 181 |
| 181 namespace ui { | 182 namespace ui { |
| 182 | 183 |
| 183 Compositor::Compositor(gfx::AcceleratedWidget widget) | 184 Compositor::Compositor(gfx::AcceleratedWidget widget) |
| 184 : root_layer_(NULL), | 185 : root_layer_(NULL), |
| 185 widget_(widget), | 186 widget_(widget), |
| 187 vsync_manager_(new CompositorVSyncManager()), |
| 186 posted_swaps_(new PostedSwapQueue()), | 188 posted_swaps_(new PostedSwapQueue()), |
| 187 device_scale_factor_(0.0f), | 189 device_scale_factor_(0.0f), |
| 188 last_started_frame_(0), | 190 last_started_frame_(0), |
| 189 last_ended_frame_(0), | 191 last_ended_frame_(0), |
| 190 next_draw_is_resize_(false), | 192 next_draw_is_resize_(false), |
| 191 disable_schedule_composite_(false), | 193 disable_schedule_composite_(false), |
| 192 compositor_lock_(NULL), | 194 compositor_lock_(NULL), |
| 193 defer_draw_scheduling_(false), | 195 defer_draw_scheduling_(false), |
| 194 waiting_on_compositing_end_(false), | 196 waiting_on_compositing_end_(false), |
| 195 draw_on_compositing_end_(false), | 197 draw_on_compositing_end_(false), |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 if (root_layer_) | 415 if (root_layer_) |
| 414 root_layer_->OnDeviceScaleFactorChanged(scale); | 416 root_layer_->OnDeviceScaleFactorChanged(scale); |
| 415 } | 417 } |
| 416 } | 418 } |
| 417 | 419 |
| 418 void Compositor::SetBackgroundColor(SkColor color) { | 420 void Compositor::SetBackgroundColor(SkColor color) { |
| 419 host_->set_background_color(color); | 421 host_->set_background_color(color); |
| 420 ScheduleDraw(); | 422 ScheduleDraw(); |
| 421 } | 423 } |
| 422 | 424 |
| 425 scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const { |
| 426 return vsync_manager_; |
| 427 } |
| 428 |
| 423 void Compositor::AddObserver(CompositorObserver* observer) { | 429 void Compositor::AddObserver(CompositorObserver* observer) { |
| 424 observer_list_.AddObserver(observer); | 430 observer_list_.AddObserver(observer); |
| 425 } | 431 } |
| 426 | 432 |
| 427 void Compositor::RemoveObserver(CompositorObserver* observer) { | 433 void Compositor::RemoveObserver(CompositorObserver* observer) { |
| 428 observer_list_.RemoveObserver(observer); | 434 observer_list_.RemoveObserver(observer); |
| 429 } | 435 } |
| 430 | 436 |
| 431 bool Compositor::HasObserver(CompositorObserver* observer) { | 437 bool Compositor::HasObserver(CompositorObserver* observer) { |
| 432 return observer_list_.HasObserver(observer); | 438 return observer_list_.HasObserver(observer); |
| 433 } | 439 } |
| 434 | 440 |
| 435 void Compositor::OnUpdateVSyncParameters(base::TimeTicks timebase, | |
| 436 base::TimeDelta interval) { | |
| 437 FOR_EACH_OBSERVER(CompositorObserver, | |
| 438 observer_list_, | |
| 439 OnUpdateVSyncParameters(this, timebase, interval)); | |
| 440 } | |
| 441 | |
| 442 void Compositor::Layout() { | 441 void Compositor::Layout() { |
| 443 // We're sending damage that will be addressed during this composite | 442 // We're sending damage that will be addressed during this composite |
| 444 // cycle, so we don't need to schedule another composite to address it. | 443 // cycle, so we don't need to schedule another composite to address it. |
| 445 disable_schedule_composite_ = true; | 444 disable_schedule_composite_ = true; |
| 446 if (root_layer_) | 445 if (root_layer_) |
| 447 root_layer_->SendDamagedRects(); | 446 root_layer_->SendDamagedRects(); |
| 448 disable_schedule_composite_ = false; | 447 disable_schedule_composite_ = false; |
| 449 } | 448 } |
| 450 | 449 |
| 451 scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) { | 450 scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // CompositorObservers to be notified before starting another | 559 // CompositorObservers to be notified before starting another |
| 561 // draw cycle. | 560 // draw cycle. |
| 562 ScheduleDraw(); | 561 ScheduleDraw(); |
| 563 } | 562 } |
| 564 FOR_EACH_OBSERVER(CompositorObserver, | 563 FOR_EACH_OBSERVER(CompositorObserver, |
| 565 observer_list_, | 564 observer_list_, |
| 566 OnCompositingEnded(this)); | 565 OnCompositingEnded(this)); |
| 567 } | 566 } |
| 568 | 567 |
| 569 } // namespace ui | 568 } // namespace ui |
| OLD | NEW |