OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "cc/scheduler/delay_based_time_source.h" | 69 #include "cc/scheduler/delay_based_time_source.h" |
70 #include "cc/trees/damage_tracker.h" | 70 #include "cc/trees/damage_tracker.h" |
71 #include "cc/trees/latency_info_swap_promise_monitor.h" | 71 #include "cc/trees/latency_info_swap_promise_monitor.h" |
72 #include "cc/trees/layer_tree_host.h" | 72 #include "cc/trees/layer_tree_host.h" |
73 #include "cc/trees/layer_tree_host_common.h" | 73 #include "cc/trees/layer_tree_host_common.h" |
74 #include "cc/trees/layer_tree_impl.h" | 74 #include "cc/trees/layer_tree_impl.h" |
75 #include "cc/trees/single_thread_proxy.h" | 75 #include "cc/trees/single_thread_proxy.h" |
76 #include "cc/trees/tree_synchronizer.h" | 76 #include "cc/trees/tree_synchronizer.h" |
77 #include "gpu/GLES2/gl2extchromium.h" | 77 #include "gpu/GLES2/gl2extchromium.h" |
78 #include "gpu/command_buffer/client/gles2_interface.h" | 78 #include "gpu/command_buffer/client/gles2_interface.h" |
| 79 #include "ui/gfx/frame_time.h" |
79 #include "ui/gfx/geometry/rect_conversions.h" | 80 #include "ui/gfx/geometry/rect_conversions.h" |
80 #include "ui/gfx/geometry/scroll_offset.h" | 81 #include "ui/gfx/geometry/scroll_offset.h" |
81 #include "ui/gfx/geometry/size_conversions.h" | 82 #include "ui/gfx/geometry/size_conversions.h" |
82 #include "ui/gfx/geometry/vector2d_conversions.h" | 83 #include "ui/gfx/geometry/vector2d_conversions.h" |
83 | 84 |
84 namespace cc { | 85 namespace cc { |
85 namespace { | 86 namespace { |
86 | 87 |
87 // Small helper class that saves the current viewport location as the user sees | 88 // Small helper class that saves the current viewport location as the user sees |
88 // it and resets to the same location. | 89 // it and resets to the same location. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 const LayerTreeSettings& settings, | 183 const LayerTreeSettings& settings, |
183 LayerTreeHostImplClient* client, | 184 LayerTreeHostImplClient* client, |
184 Proxy* proxy, | 185 Proxy* proxy, |
185 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 186 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
186 SharedBitmapManager* shared_bitmap_manager, | 187 SharedBitmapManager* shared_bitmap_manager, |
187 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 188 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
188 TaskGraphRunner* task_graph_runner, | 189 TaskGraphRunner* task_graph_runner, |
189 int id) | 190 int id) |
190 : client_(client), | 191 : client_(client), |
191 proxy_(proxy), | 192 proxy_(proxy), |
192 current_begin_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), | |
193 content_is_suitable_for_gpu_rasterization_(true), | 193 content_is_suitable_for_gpu_rasterization_(true), |
194 has_gpu_rasterization_trigger_(false), | 194 has_gpu_rasterization_trigger_(false), |
195 use_gpu_rasterization_(false), | 195 use_gpu_rasterization_(false), |
196 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE), | 196 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE), |
197 input_handler_client_(NULL), | 197 input_handler_client_(NULL), |
198 did_lock_scrolling_layer_(false), | 198 did_lock_scrolling_layer_(false), |
199 should_bubble_scrolls_(false), | 199 should_bubble_scrolls_(false), |
200 wheel_scrolling_(false), | 200 wheel_scrolling_(false), |
201 scroll_affects_scroll_handler_(false), | 201 scroll_affects_scroll_handler_(false), |
202 scroll_layer_id_when_mouse_over_scrollbar_(0), | 202 scroll_layer_id_when_mouse_over_scrollbar_(0), |
(...skipping 10 matching lines...) Expand all Loading... |
213 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), | 213 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), |
214 paint_time_counter_(PaintTimeCounter::Create()), | 214 paint_time_counter_(PaintTimeCounter::Create()), |
215 memory_history_(MemoryHistory::Create()), | 215 memory_history_(MemoryHistory::Create()), |
216 debug_rect_history_(DebugRectHistory::Create()), | 216 debug_rect_history_(DebugRectHistory::Create()), |
217 texture_mailbox_deleter_(new TextureMailboxDeleter( | 217 texture_mailbox_deleter_(new TextureMailboxDeleter( |
218 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | 218 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() |
219 : proxy_->MainThreadTaskRunner())), | 219 : proxy_->MainThreadTaskRunner())), |
220 max_memory_needed_bytes_(0), | 220 max_memory_needed_bytes_(0), |
221 device_scale_factor_(1.f), | 221 device_scale_factor_(1.f), |
222 resourceless_software_draw_(false), | 222 resourceless_software_draw_(false), |
| 223 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()), |
223 animation_registrar_(AnimationRegistrar::Create()), | 224 animation_registrar_(AnimationRegistrar::Create()), |
224 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 225 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
225 micro_benchmark_controller_(this), | 226 micro_benchmark_controller_(this), |
226 shared_bitmap_manager_(shared_bitmap_manager), | 227 shared_bitmap_manager_(shared_bitmap_manager), |
227 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 228 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
228 task_graph_runner_(task_graph_runner), | 229 task_graph_runner_(task_graph_runner), |
229 id_(id), | 230 id_(id), |
230 requires_high_res_to_draw_(false), | 231 requires_high_res_to_draw_(false), |
231 is_likely_to_require_a_draw_(false), | 232 is_likely_to_require_a_draw_(false), |
232 frame_timing_tracker_(FrameTimingTracker::Create()) { | 233 frame_timing_tracker_(FrameTimingTracker::Create()) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 if (EvictedUIResourcesExist()) { | 386 if (EvictedUIResourcesExist()) { |
386 TRACE_EVENT_INSTANT0( | 387 TRACE_EVENT_INSTANT0( |
387 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", | 388 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", |
388 TRACE_EVENT_SCOPE_THREAD); | 389 TRACE_EVENT_SCOPE_THREAD); |
389 return false; | 390 return false; |
390 } | 391 } |
391 return true; | 392 return true; |
392 } | 393 } |
393 | 394 |
394 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { | 395 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { |
395 // mithro(TODO): Enable these checks. | |
396 // DCHECK(!current_begin_frame_tracker_.HasFinished()); | |
397 // DCHECK(monotonic_time == current_begin_frame_tracker_.Current().frame_time) | |
398 // << "Called animate with unknown frame time!?"; | |
399 if (input_handler_client_) | 396 if (input_handler_client_) |
400 input_handler_client_->Animate(monotonic_time); | 397 input_handler_client_->Animate(monotonic_time); |
401 AnimatePageScale(monotonic_time); | 398 AnimatePageScale(monotonic_time); |
402 AnimateLayers(monotonic_time); | 399 AnimateLayers(monotonic_time); |
403 AnimateScrollbars(monotonic_time); | 400 AnimateScrollbars(monotonic_time); |
404 AnimateTopControls(monotonic_time); | 401 AnimateTopControls(monotonic_time); |
405 } | 402 } |
406 | 403 |
407 void LayerTreeHostImpl::PrepareTiles() { | 404 void LayerTreeHostImpl::PrepareTiles() { |
408 if (!tile_manager_) | 405 if (!tile_manager_) |
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 0, nullptr)) { | 1662 0, nullptr)) { |
1666 latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, | 1663 latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, |
1667 0, 0); | 1664 0, 0); |
1668 } | 1665 } |
1669 } | 1666 } |
1670 renderer_->SwapBuffers(metadata); | 1667 renderer_->SwapBuffers(metadata); |
1671 return true; | 1668 return true; |
1672 } | 1669 } |
1673 | 1670 |
1674 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { | 1671 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { |
1675 current_begin_frame_tracker_.Start(args); | 1672 // Sample the frame time now. This time will be used for updating animations |
| 1673 // when we draw. |
| 1674 DCHECK(!current_begin_frame_args_.IsValid()); |
| 1675 current_begin_frame_args_ = args; |
| 1676 // TODO(mithro): Stop overriding the frame time once the usage of frame |
| 1677 // timing is unified. |
| 1678 current_begin_frame_args_.frame_time = gfx::FrameTime::Now(); |
| 1679 |
| 1680 // Cache the begin impl frame interval |
| 1681 begin_impl_frame_interval_ = args.interval; |
1676 | 1682 |
1677 if (is_likely_to_require_a_draw_) { | 1683 if (is_likely_to_require_a_draw_) { |
1678 // Optimistically schedule a draw. This will let us expect the tile manager | 1684 // Optimistically schedule a draw. This will let us expect the tile manager |
1679 // to complete its work so that we can draw new tiles within the impl frame | 1685 // to complete its work so that we can draw new tiles within the impl frame |
1680 // we are beginning now. | 1686 // we are beginning now. |
1681 SetNeedsRedraw(); | 1687 SetNeedsRedraw(); |
1682 } | 1688 } |
1683 | 1689 |
1684 for (auto& it : video_frame_controllers_) | 1690 for (auto& it : video_frame_controllers_) |
1685 it->OnBeginFrame(args); | 1691 it->OnBeginFrame(args); |
1686 } | 1692 } |
1687 | 1693 |
1688 void LayerTreeHostImpl::DidFinishImplFrame() { | 1694 void LayerTreeHostImpl::DidFinishImplFrame() { |
1689 current_begin_frame_tracker_.Finish(); | 1695 DCHECK(current_begin_frame_args_.IsValid()); |
| 1696 current_begin_frame_args_ = BeginFrameArgs(); |
1690 } | 1697 } |
1691 | 1698 |
1692 void LayerTreeHostImpl::UpdateViewportContainerSizes() { | 1699 void LayerTreeHostImpl::UpdateViewportContainerSizes() { |
1693 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer(); | 1700 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer(); |
1694 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); | 1701 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); |
1695 | 1702 |
1696 if (!inner_container) | 1703 if (!inner_container) |
1697 return; | 1704 return; |
1698 | 1705 |
1699 // TODO(bokan): This code is currently specific to top controls. It should be | 1706 // TODO(bokan): This code is currently specific to top controls. It should be |
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3102 } | 3109 } |
3103 | 3110 |
3104 void LayerTreeHostImpl::SetNeedsRedrawForScrollbarAnimation() { | 3111 void LayerTreeHostImpl::SetNeedsRedrawForScrollbarAnimation() { |
3105 SetNeedsRedraw(); | 3112 SetNeedsRedraw(); |
3106 } | 3113 } |
3107 | 3114 |
3108 void LayerTreeHostImpl::AddVideoFrameController( | 3115 void LayerTreeHostImpl::AddVideoFrameController( |
3109 VideoFrameController* controller) { | 3116 VideoFrameController* controller) { |
3110 bool was_empty = video_frame_controllers_.empty(); | 3117 bool was_empty = video_frame_controllers_.empty(); |
3111 video_frame_controllers_.insert(controller); | 3118 video_frame_controllers_.insert(controller); |
3112 if (current_begin_frame_tracker_.DangerousMethodHasStarted() && | 3119 if (current_begin_frame_args_.IsValid()) |
3113 !current_begin_frame_tracker_.DangerousMethodHasFinished()) | 3120 controller->OnBeginFrame(current_begin_frame_args_); |
3114 controller->OnBeginFrame(current_begin_frame_tracker_.Current()); | |
3115 if (was_empty) | 3121 if (was_empty) |
3116 client_->SetVideoNeedsBeginFrames(true); | 3122 client_->SetVideoNeedsBeginFrames(true); |
3117 } | 3123 } |
3118 | 3124 |
3119 void LayerTreeHostImpl::RemoveVideoFrameController( | 3125 void LayerTreeHostImpl::RemoveVideoFrameController( |
3120 VideoFrameController* controller) { | 3126 VideoFrameController* controller) { |
3121 video_frame_controllers_.erase(controller); | 3127 video_frame_controllers_.erase(controller); |
3122 if (video_frame_controllers_.empty()) | 3128 if (video_frame_controllers_.empty()) |
3123 client_->SetVideoNeedsBeginFrames(false); | 3129 client_->SetVideoNeedsBeginFrames(false); |
3124 } | 3130 } |
3125 | 3131 |
3126 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { | 3132 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { |
3127 if (!tile_manager_) | 3133 if (!tile_manager_) |
3128 return; | 3134 return; |
3129 | 3135 |
3130 if (global_tile_state_.tree_priority == priority) | 3136 if (global_tile_state_.tree_priority == priority) |
3131 return; | 3137 return; |
3132 global_tile_state_.tree_priority = priority; | 3138 global_tile_state_.tree_priority = priority; |
3133 DidModifyTilePriorities(); | 3139 DidModifyTilePriorities(); |
3134 } | 3140 } |
3135 | 3141 |
3136 TreePriority LayerTreeHostImpl::GetTreePriority() const { | 3142 TreePriority LayerTreeHostImpl::GetTreePriority() const { |
3137 return global_tile_state_.tree_priority; | 3143 return global_tile_state_.tree_priority; |
3138 } | 3144 } |
3139 | 3145 |
3140 BeginFrameArgs LayerTreeHostImpl::CurrentBeginFrameArgs() const { | 3146 BeginFrameArgs LayerTreeHostImpl::CurrentBeginFrameArgs() const { |
3141 // TODO(mithro): Replace call with current_begin_frame_tracker_.Current() | 3147 // Try to use the current frame time to keep animations non-jittery. But if |
3142 // once all calls which happens outside impl frames are fixed. | 3148 // we're not in a frame (because this is during an input event or a delayed |
3143 return current_begin_frame_tracker_.DangerousMethodCurrentOrLast(); | 3149 // task), fall back to physical time. This should still be monotonic. |
3144 } | 3150 if (current_begin_frame_args_.IsValid()) |
3145 | 3151 return current_begin_frame_args_; |
3146 base::TimeDelta LayerTreeHostImpl::CurrentBeginFrameInterval() const { | 3152 return BeginFrameArgs::Create( |
3147 return current_begin_frame_tracker_.Interval(); | 3153 BEGINFRAME_FROM_HERE, gfx::FrameTime::Now(), base::TimeTicks(), |
| 3154 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL); |
3148 } | 3155 } |
3149 | 3156 |
3150 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 3157 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
3151 LayerTreeHostImpl::AsValueWithFrame(FrameData* frame) const { | 3158 LayerTreeHostImpl::AsValueWithFrame(FrameData* frame) const { |
3152 scoped_refptr<base::trace_event::TracedValue> state = | 3159 scoped_refptr<base::trace_event::TracedValue> state = |
3153 new base::trace_event::TracedValue(); | 3160 new base::trace_event::TracedValue(); |
3154 AsValueWithFrameInto(frame, state.get()); | 3161 AsValueWithFrameInto(frame, state.get()); |
3155 return state; | 3162 return state; |
3156 } | 3163 } |
3157 | 3164 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3388 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 3395 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
3389 | 3396 |
3390 curve->UpdateTarget( | 3397 curve->UpdateTarget( |
3391 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) | 3398 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) |
3392 .InSecondsF(), | 3399 .InSecondsF(), |
3393 new_target); | 3400 new_target); |
3394 | 3401 |
3395 return true; | 3402 return true; |
3396 } | 3403 } |
3397 } // namespace cc | 3404 } // namespace cc |
OLD | NEW |