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