| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 const LayerTreeSettings& settings, | 182 const LayerTreeSettings& settings, |
| 183 LayerTreeHostImplClient* client, | 183 LayerTreeHostImplClient* client, |
| 184 Proxy* proxy, | 184 Proxy* proxy, |
| 185 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 185 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 186 SharedBitmapManager* shared_bitmap_manager, | 186 SharedBitmapManager* shared_bitmap_manager, |
| 187 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 187 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 188 TaskGraphRunner* task_graph_runner, | 188 TaskGraphRunner* task_graph_runner, |
| 189 int id) | 189 int id) |
| 190 : client_(client), | 190 : client_(client), |
| 191 proxy_(proxy), | 191 proxy_(proxy), |
| 192 current_begin_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), |
| 192 content_is_suitable_for_gpu_rasterization_(true), | 193 content_is_suitable_for_gpu_rasterization_(true), |
| 193 has_gpu_rasterization_trigger_(false), | 194 has_gpu_rasterization_trigger_(false), |
| 194 use_gpu_rasterization_(false), | 195 use_gpu_rasterization_(false), |
| 195 use_msaa_(false), | 196 use_msaa_(false), |
| 196 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE), | 197 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE), |
| 197 tree_resources_for_gpu_rasterization_dirty_(false), | 198 tree_resources_for_gpu_rasterization_dirty_(false), |
| 198 input_handler_client_(NULL), | 199 input_handler_client_(NULL), |
| 199 did_lock_scrolling_layer_(false), | 200 did_lock_scrolling_layer_(false), |
| 200 should_bubble_scrolls_(false), | 201 should_bubble_scrolls_(false), |
| 201 wheel_scrolling_(false), | 202 wheel_scrolling_(false), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 214 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), | 215 fps_counter_(FrameRateCounter::Create(proxy_->HasImplThread())), |
| 215 paint_time_counter_(PaintTimeCounter::Create()), | 216 paint_time_counter_(PaintTimeCounter::Create()), |
| 216 memory_history_(MemoryHistory::Create()), | 217 memory_history_(MemoryHistory::Create()), |
| 217 debug_rect_history_(DebugRectHistory::Create()), | 218 debug_rect_history_(DebugRectHistory::Create()), |
| 218 texture_mailbox_deleter_(new TextureMailboxDeleter( | 219 texture_mailbox_deleter_(new TextureMailboxDeleter( |
| 219 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | 220 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() |
| 220 : proxy_->MainThreadTaskRunner())), | 221 : proxy_->MainThreadTaskRunner())), |
| 221 max_memory_needed_bytes_(0), | 222 max_memory_needed_bytes_(0), |
| 222 device_scale_factor_(1.f), | 223 device_scale_factor_(1.f), |
| 223 resourceless_software_draw_(false), | 224 resourceless_software_draw_(false), |
| 224 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()), | |
| 225 animation_registrar_(AnimationRegistrar::Create()), | 225 animation_registrar_(AnimationRegistrar::Create()), |
| 226 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 226 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
| 227 micro_benchmark_controller_(this), | 227 micro_benchmark_controller_(this), |
| 228 shared_bitmap_manager_(shared_bitmap_manager), | 228 shared_bitmap_manager_(shared_bitmap_manager), |
| 229 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 229 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 230 task_graph_runner_(task_graph_runner), | 230 task_graph_runner_(task_graph_runner), |
| 231 id_(id), | 231 id_(id), |
| 232 requires_high_res_to_draw_(false), | 232 requires_high_res_to_draw_(false), |
| 233 is_likely_to_require_a_draw_(false), | 233 is_likely_to_require_a_draw_(false), |
| 234 frame_timing_tracker_(FrameTimingTracker::Create()) { | 234 frame_timing_tracker_(FrameTimingTracker::Create()) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 if (EvictedUIResourcesExist()) { | 392 if (EvictedUIResourcesExist()) { |
| 393 TRACE_EVENT_INSTANT0( | 393 TRACE_EVENT_INSTANT0( |
| 394 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", | 394 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", |
| 395 TRACE_EVENT_SCOPE_THREAD); | 395 TRACE_EVENT_SCOPE_THREAD); |
| 396 return false; | 396 return false; |
| 397 } | 397 } |
| 398 return true; | 398 return true; |
| 399 } | 399 } |
| 400 | 400 |
| 401 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { | 401 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { |
| 402 // mithro(TODO): Enable these checks. |
| 403 // DCHECK(!current_begin_frame_tracker_.HasFinished()); |
| 404 // DCHECK(monotonic_time == current_begin_frame_tracker_.Current().frame_time) |
| 405 // << "Called animate with unknown frame time!?"; |
| 402 if (input_handler_client_) | 406 if (input_handler_client_) |
| 403 input_handler_client_->Animate(monotonic_time); | 407 input_handler_client_->Animate(monotonic_time); |
| 404 AnimatePageScale(monotonic_time); | 408 AnimatePageScale(monotonic_time); |
| 405 AnimateLayers(monotonic_time); | 409 AnimateLayers(monotonic_time); |
| 406 AnimateScrollbars(monotonic_time); | 410 AnimateScrollbars(monotonic_time); |
| 407 AnimateTopControls(monotonic_time); | 411 AnimateTopControls(monotonic_time); |
| 408 } | 412 } |
| 409 | 413 |
| 410 void LayerTreeHostImpl::PrepareTiles() { | 414 void LayerTreeHostImpl::PrepareTiles() { |
| 411 if (!tile_manager_) | 415 if (!tile_manager_) |
| (...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1701 0, nullptr)) { | 1705 0, nullptr)) { |
| 1702 latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, | 1706 latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, |
| 1703 0, 0); | 1707 0, 0); |
| 1704 } | 1708 } |
| 1705 } | 1709 } |
| 1706 renderer_->SwapBuffers(metadata); | 1710 renderer_->SwapBuffers(metadata); |
| 1707 return true; | 1711 return true; |
| 1708 } | 1712 } |
| 1709 | 1713 |
| 1710 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { | 1714 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 1711 // Sample the frame time now. This time will be used for updating animations | 1715 current_begin_frame_tracker_.Start(args); |
| 1712 // when we draw. | |
| 1713 DCHECK(!current_begin_frame_args_.IsValid()); | |
| 1714 current_begin_frame_args_ = args; | |
| 1715 // TODO(mithro): Stop overriding the frame time once the usage of frame | |
| 1716 // timing is unified. | |
| 1717 current_begin_frame_args_.frame_time = base::TimeTicks::Now(); | |
| 1718 | |
| 1719 // Cache the begin impl frame interval | |
| 1720 begin_impl_frame_interval_ = args.interval; | |
| 1721 | 1716 |
| 1722 if (is_likely_to_require_a_draw_) { | 1717 if (is_likely_to_require_a_draw_) { |
| 1723 // Optimistically schedule a draw. This will let us expect the tile manager | 1718 // Optimistically schedule a draw. This will let us expect the tile manager |
| 1724 // to complete its work so that we can draw new tiles within the impl frame | 1719 // to complete its work so that we can draw new tiles within the impl frame |
| 1725 // we are beginning now. | 1720 // we are beginning now. |
| 1726 SetNeedsRedraw(); | 1721 SetNeedsRedraw(); |
| 1727 } | 1722 } |
| 1728 | 1723 |
| 1729 for (auto& it : video_frame_controllers_) | 1724 for (auto& it : video_frame_controllers_) |
| 1730 it->OnBeginFrame(args); | 1725 it->OnBeginFrame(args); |
| 1731 } | 1726 } |
| 1732 | 1727 |
| 1733 void LayerTreeHostImpl::DidFinishImplFrame() { | 1728 void LayerTreeHostImpl::DidFinishImplFrame() { |
| 1734 DCHECK(current_begin_frame_args_.IsValid()); | 1729 current_begin_frame_tracker_.Finish(); |
| 1735 current_begin_frame_args_ = BeginFrameArgs(); | |
| 1736 } | 1730 } |
| 1737 | 1731 |
| 1738 void LayerTreeHostImpl::UpdateViewportContainerSizes() { | 1732 void LayerTreeHostImpl::UpdateViewportContainerSizes() { |
| 1739 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer(); | 1733 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer(); |
| 1740 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); | 1734 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); |
| 1741 | 1735 |
| 1742 if (!inner_container) | 1736 if (!inner_container) |
| 1743 return; | 1737 return; |
| 1744 | 1738 |
| 1745 // TODO(bokan): This code is currently specific to top controls. It should be | 1739 // TODO(bokan): This code is currently specific to top controls. It should be |
| (...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3160 } | 3154 } |
| 3161 | 3155 |
| 3162 void LayerTreeHostImpl::SetNeedsRedrawForScrollbarAnimation() { | 3156 void LayerTreeHostImpl::SetNeedsRedrawForScrollbarAnimation() { |
| 3163 SetNeedsRedraw(); | 3157 SetNeedsRedraw(); |
| 3164 } | 3158 } |
| 3165 | 3159 |
| 3166 void LayerTreeHostImpl::AddVideoFrameController( | 3160 void LayerTreeHostImpl::AddVideoFrameController( |
| 3167 VideoFrameController* controller) { | 3161 VideoFrameController* controller) { |
| 3168 bool was_empty = video_frame_controllers_.empty(); | 3162 bool was_empty = video_frame_controllers_.empty(); |
| 3169 video_frame_controllers_.insert(controller); | 3163 video_frame_controllers_.insert(controller); |
| 3170 if (current_begin_frame_args_.IsValid()) | 3164 if (current_begin_frame_tracker_.DangerousMethodHasStarted() && |
| 3171 controller->OnBeginFrame(current_begin_frame_args_); | 3165 !current_begin_frame_tracker_.DangerousMethodHasFinished()) |
| 3166 controller->OnBeginFrame(current_begin_frame_tracker_.Current()); |
| 3172 if (was_empty) | 3167 if (was_empty) |
| 3173 client_->SetVideoNeedsBeginFrames(true); | 3168 client_->SetVideoNeedsBeginFrames(true); |
| 3174 } | 3169 } |
| 3175 | 3170 |
| 3176 void LayerTreeHostImpl::RemoveVideoFrameController( | 3171 void LayerTreeHostImpl::RemoveVideoFrameController( |
| 3177 VideoFrameController* controller) { | 3172 VideoFrameController* controller) { |
| 3178 video_frame_controllers_.erase(controller); | 3173 video_frame_controllers_.erase(controller); |
| 3179 if (video_frame_controllers_.empty()) | 3174 if (video_frame_controllers_.empty()) |
| 3180 client_->SetVideoNeedsBeginFrames(false); | 3175 client_->SetVideoNeedsBeginFrames(false); |
| 3181 } | 3176 } |
| 3182 | 3177 |
| 3183 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { | 3178 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { |
| 3184 if (!tile_manager_) | 3179 if (!tile_manager_) |
| 3185 return; | 3180 return; |
| 3186 | 3181 |
| 3187 if (global_tile_state_.tree_priority == priority) | 3182 if (global_tile_state_.tree_priority == priority) |
| 3188 return; | 3183 return; |
| 3189 global_tile_state_.tree_priority = priority; | 3184 global_tile_state_.tree_priority = priority; |
| 3190 DidModifyTilePriorities(); | 3185 DidModifyTilePriorities(); |
| 3191 } | 3186 } |
| 3192 | 3187 |
| 3193 TreePriority LayerTreeHostImpl::GetTreePriority() const { | 3188 TreePriority LayerTreeHostImpl::GetTreePriority() const { |
| 3194 return global_tile_state_.tree_priority; | 3189 return global_tile_state_.tree_priority; |
| 3195 } | 3190 } |
| 3196 | 3191 |
| 3197 BeginFrameArgs LayerTreeHostImpl::CurrentBeginFrameArgs() const { | 3192 BeginFrameArgs LayerTreeHostImpl::CurrentBeginFrameArgs() const { |
| 3198 // Try to use the current frame time to keep animations non-jittery. But if | 3193 // TODO(mithro): Replace call with current_begin_frame_tracker_.Current() |
| 3199 // we're not in a frame (because this is during an input event or a delayed | 3194 // once all calls which happens outside impl frames are fixed. |
| 3200 // task), fall back to physical time. This should still be monotonic. | 3195 return current_begin_frame_tracker_.DangerousMethodCurrentOrLast(); |
| 3201 if (current_begin_frame_args_.IsValid()) | 3196 } |
| 3202 return current_begin_frame_args_; | 3197 |
| 3203 return BeginFrameArgs::Create( | 3198 base::TimeDelta LayerTreeHostImpl::CurrentBeginFrameInterval() const { |
| 3204 BEGINFRAME_FROM_HERE, base::TimeTicks::Now(), base::TimeTicks(), | 3199 return current_begin_frame_tracker_.Interval(); |
| 3205 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL); | |
| 3206 } | 3200 } |
| 3207 | 3201 |
| 3208 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 3202 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 3209 LayerTreeHostImpl::AsValueWithFrame(FrameData* frame) const { | 3203 LayerTreeHostImpl::AsValueWithFrame(FrameData* frame) const { |
| 3210 scoped_refptr<base::trace_event::TracedValue> state = | 3204 scoped_refptr<base::trace_event::TracedValue> state = |
| 3211 new base::trace_event::TracedValue(); | 3205 new base::trace_event::TracedValue(); |
| 3212 AsValueWithFrameInto(frame, state.get()); | 3206 AsValueWithFrameInto(frame, state.get()); |
| 3213 return state; | 3207 return state; |
| 3214 } | 3208 } |
| 3215 | 3209 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3442 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 3436 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
| 3443 | 3437 |
| 3444 curve->UpdateTarget( | 3438 curve->UpdateTarget( |
| 3445 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) | 3439 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) |
| 3446 .InSecondsF(), | 3440 .InSecondsF(), |
| 3447 new_target); | 3441 new_target); |
| 3448 | 3442 |
| 3449 return true; | 3443 return true; |
| 3450 } | 3444 } |
| 3451 } // namespace cc | 3445 } // namespace cc |
| OLD | NEW |