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 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 #include "cc/scheduler/delay_based_time_source.h" | 64 #include "cc/scheduler/delay_based_time_source.h" |
65 #include "cc/trees/damage_tracker.h" | 65 #include "cc/trees/damage_tracker.h" |
66 #include "cc/trees/layer_tree_host.h" | 66 #include "cc/trees/layer_tree_host.h" |
67 #include "cc/trees/layer_tree_host_common.h" | 67 #include "cc/trees/layer_tree_host_common.h" |
68 #include "cc/trees/layer_tree_impl.h" | 68 #include "cc/trees/layer_tree_impl.h" |
69 #include "cc/trees/occlusion_tracker.h" | 69 #include "cc/trees/occlusion_tracker.h" |
70 #include "cc/trees/single_thread_proxy.h" | 70 #include "cc/trees/single_thread_proxy.h" |
71 #include "cc/trees/tree_synchronizer.h" | 71 #include "cc/trees/tree_synchronizer.h" |
72 #include "gpu/command_buffer/client/gles2_interface.h" | 72 #include "gpu/command_buffer/client/gles2_interface.h" |
73 #include "gpu/GLES2/gl2extchromium.h" | 73 #include "gpu/GLES2/gl2extchromium.h" |
74 #include "ui/gfx/frame_time.h" | |
75 #include "ui/gfx/geometry/rect_conversions.h" | 74 #include "ui/gfx/geometry/rect_conversions.h" |
76 #include "ui/gfx/geometry/size_conversions.h" | 75 #include "ui/gfx/geometry/size_conversions.h" |
77 #include "ui/gfx/geometry/vector2d_conversions.h" | 76 #include "ui/gfx/geometry/vector2d_conversions.h" |
78 | 77 |
79 namespace cc { | 78 namespace cc { |
80 namespace { | 79 namespace { |
81 | 80 |
82 // Small helper class that saves the current viewport location as the user sees | 81 // Small helper class that saves the current viewport location as the user sees |
83 // it and resets to the same location. | 82 // it and resets to the same location. |
84 class ViewportAnchor { | 83 class ViewportAnchor { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 memory_history_(MemoryHistory::Create()), | 212 memory_history_(MemoryHistory::Create()), |
214 debug_rect_history_(DebugRectHistory::Create()), | 213 debug_rect_history_(DebugRectHistory::Create()), |
215 texture_mailbox_deleter_(new TextureMailboxDeleter( | 214 texture_mailbox_deleter_(new TextureMailboxDeleter( |
216 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | 215 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() |
217 : proxy_->MainThreadTaskRunner())), | 216 : proxy_->MainThreadTaskRunner())), |
218 max_memory_needed_bytes_(0), | 217 max_memory_needed_bytes_(0), |
219 zero_budget_(false), | 218 zero_budget_(false), |
220 device_scale_factor_(1.f), | 219 device_scale_factor_(1.f), |
221 overhang_ui_resource_id_(0), | 220 overhang_ui_resource_id_(0), |
222 resourceless_software_draw_(false), | 221 resourceless_software_draw_(false), |
223 begin_impl_frame_interval_(BeginFrameArgs::DefaultInterval()), | |
224 animation_registrar_(AnimationRegistrar::Create()), | 222 animation_registrar_(AnimationRegistrar::Create()), |
225 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 223 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
226 micro_benchmark_controller_(this), | 224 micro_benchmark_controller_(this), |
227 shared_bitmap_manager_(shared_bitmap_manager), | 225 shared_bitmap_manager_(shared_bitmap_manager), |
228 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 226 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
229 id_(id), | 227 id_(id), |
230 requires_high_res_to_draw_(false), | 228 requires_high_res_to_draw_(false), |
231 required_for_draw_tile_is_top_of_raster_queue_(false) { | 229 required_for_draw_tile_is_top_of_raster_queue_(false) { |
232 DCHECK(proxy_->IsImplThread()); | 230 DCHECK(proxy_->IsImplThread()); |
233 DidVisibilityChange(this, visible_); | 231 DidVisibilityChange(this, visible_); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 if (EvictedUIResourcesExist()) { | 365 if (EvictedUIResourcesExist()) { |
368 TRACE_EVENT_INSTANT0( | 366 TRACE_EVENT_INSTANT0( |
369 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", | 367 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", |
370 TRACE_EVENT_SCOPE_THREAD); | 368 TRACE_EVENT_SCOPE_THREAD); |
371 return false; | 369 return false; |
372 } | 370 } |
373 return true; | 371 return true; |
374 } | 372 } |
375 | 373 |
376 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { | 374 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { |
| 375 // DCHECK(!current_begin_frame_args_.HasFinished()); |
| 376 // DCHECK(monotonic_time == current_begin_frame_args_.Get().frame_time) |
| 377 // << "Called animate with unknown frame time!?"; |
377 if (input_handler_client_) | 378 if (input_handler_client_) |
378 input_handler_client_->Animate(monotonic_time); | 379 input_handler_client_->Animate(monotonic_time); |
379 AnimatePageScale(monotonic_time); | 380 AnimatePageScale(monotonic_time); |
380 AnimateLayers(monotonic_time); | 381 AnimateLayers(monotonic_time); |
381 AnimateScrollbars(monotonic_time); | 382 AnimateScrollbars(monotonic_time); |
382 AnimateTopControls(monotonic_time); | 383 AnimateTopControls(monotonic_time); |
383 } | 384 } |
384 | 385 |
385 void LayerTreeHostImpl::PrepareTiles() { | 386 void LayerTreeHostImpl::PrepareTiles() { |
386 if (!tile_manager_) | 387 if (!tile_manager_) |
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 "input", | 1627 "input", |
1627 "LatencyInfo.Flow", | 1628 "LatencyInfo.Flow", |
1628 TRACE_ID_DONT_MANGLE(metadata.latency_info[i].trace_id), | 1629 TRACE_ID_DONT_MANGLE(metadata.latency_info[i].trace_id), |
1629 "SwapBuffers"); | 1630 "SwapBuffers"); |
1630 } | 1631 } |
1631 renderer_->SwapBuffers(metadata); | 1632 renderer_->SwapBuffers(metadata); |
1632 return true; | 1633 return true; |
1633 } | 1634 } |
1634 | 1635 |
1635 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { | 1636 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { |
1636 // Sample the frame time now. This time will be used for updating animations | 1637 current_begin_frame_args_.Start(args); |
1637 // when we draw. | |
1638 UpdateCurrentBeginFrameArgs(args); | |
1639 // Cache the begin impl frame interval | |
1640 begin_impl_frame_interval_ = args.interval; | |
1641 | 1638 |
1642 if (required_for_draw_tile_is_top_of_raster_queue_) { | 1639 if (required_for_draw_tile_is_top_of_raster_queue_) { |
1643 // Optimistically schedule a draw, as a tile required for draw is at the top | 1640 // Optimistically schedule a draw, as a tile required for draw is at the top |
1644 // of the current raster queue. This will let us expect the tile to complete | 1641 // of the current raster queue. This will let us expect the tile to complete |
1645 // and draw it within the impl frame we are beginning now. | 1642 // and draw it within the impl frame we are beginning now. |
1646 SetNeedsRedraw(); | 1643 SetNeedsRedraw(); |
1647 } | 1644 } |
1648 } | 1645 } |
1649 | 1646 |
1650 void LayerTreeHostImpl::UpdateViewportContainerSizes() { | 1647 void LayerTreeHostImpl::UpdateViewportContainerSizes() { |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2403 ScrollOffsetAnimationCurve* curve = | 2400 ScrollOffsetAnimationCurve* curve = |
2404 animation->curve()->ToScrollOffsetAnimationCurve(); | 2401 animation->curve()->ToScrollOffsetAnimationCurve(); |
2405 | 2402 |
2406 gfx::ScrollOffset new_target = | 2403 gfx::ScrollOffset new_target = |
2407 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); | 2404 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); |
2408 new_target.SetToMax(gfx::ScrollOffset()); | 2405 new_target.SetToMax(gfx::ScrollOffset()); |
2409 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 2406 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
2410 | 2407 |
2411 curve->UpdateTarget( | 2408 curve->UpdateTarget( |
2412 animation->TrimTimeToCurrentIteration( | 2409 animation->TrimTimeToCurrentIteration( |
2413 CurrentBeginFrameArgs().frame_time).InSecondsF(), | 2410 current_begin_frame_args_.Get().frame_time).InSecondsF(), |
2414 new_target); | 2411 new_target); |
2415 | 2412 |
2416 return ScrollStarted; | 2413 return ScrollStarted; |
2417 } | 2414 } |
2418 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling | 2415 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling |
2419 // behavior as ScrollBy to determine which layer to animate, but we do not | 2416 // behavior as ScrollBy to determine which layer to animate, but we do not |
2420 // do the Android-specific things in ScrollBy like showing top controls. | 2417 // do the Android-specific things in ScrollBy like showing top controls. |
2421 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); | 2418 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel); |
2422 if (scroll_status == ScrollStarted) { | 2419 if (scroll_status == ScrollStarted) { |
2423 gfx::Vector2dF pending_delta = scroll_delta; | 2420 gfx::Vector2dF pending_delta = scroll_delta; |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3214 global_tile_state_.tree_priority = priority; | 3211 global_tile_state_.tree_priority = priority; |
3215 DidModifyTilePriorities(); | 3212 DidModifyTilePriorities(); |
3216 } | 3213 } |
3217 | 3214 |
3218 TreePriority LayerTreeHostImpl::GetTreePriority() const { | 3215 TreePriority LayerTreeHostImpl::GetTreePriority() const { |
3219 return global_tile_state_.tree_priority; | 3216 return global_tile_state_.tree_priority; |
3220 } | 3217 } |
3221 | 3218 |
3222 void LayerTreeHostImpl::UpdateCurrentBeginFrameArgs( | 3219 void LayerTreeHostImpl::UpdateCurrentBeginFrameArgs( |
3223 const BeginFrameArgs& args) { | 3220 const BeginFrameArgs& args) { |
3224 DCHECK(!current_begin_frame_args_.IsValid()); | 3221 current_begin_frame_args_.Start(args); |
3225 current_begin_frame_args_ = args; | |
3226 // TODO(skyostil): Stop overriding the frame time once the usage of frame | |
3227 // timing is unified. | |
3228 current_begin_frame_args_.frame_time = gfx::FrameTime::Now(); | |
3229 } | 3222 } |
3230 | 3223 |
3231 void LayerTreeHostImpl::ResetCurrentBeginFrameArgsForNextFrame() { | 3224 void LayerTreeHostImpl::ResetCurrentBeginFrameArgsForNextFrame() { |
3232 current_begin_frame_args_ = BeginFrameArgs(); | 3225 current_begin_frame_args_.Finish(); |
3233 } | 3226 } |
3234 | 3227 |
3235 BeginFrameArgs LayerTreeHostImpl::CurrentBeginFrameArgs() const { | 3228 BeginFrameArgs LayerTreeHostImpl::CurrentBeginFrameArgs() const { |
3236 // Try to use the current frame time to keep animations non-jittery. But if | 3229 // TODO(mithro): Remove this section once all calls to CurrentBeginFrameArgs |
3237 // we're not in a frame (because this is during an input event or a delayed | 3230 // which happens outside frame rendering are fixed. |
3238 // task), fall back to physical time. This should still be monotonic. | 3231 if (current_begin_frame_args_.HasFinished()) { |
3239 if (current_begin_frame_args_.IsValid()) | 3232 return current_begin_frame_args_.Last(); |
3240 return current_begin_frame_args_; | 3233 } |
3241 return BeginFrameArgs::Create( | 3234 return current_begin_frame_args_.Get(); |
3242 BEGINFRAME_FROM_HERE, gfx::FrameTime::Now(), base::TimeTicks(), | 3235 } |
3243 BeginFrameArgs::DefaultInterval(), BeginFrameArgs::NORMAL); | 3236 |
| 3237 base::TimeDelta LayerTreeHostImpl::CurrentBeginFrameInterval() const { |
| 3238 return current_begin_frame_args_.Interval(); |
3244 } | 3239 } |
3245 | 3240 |
3246 scoped_refptr<base::debug::ConvertableToTraceFormat> | 3241 scoped_refptr<base::debug::ConvertableToTraceFormat> |
3247 LayerTreeHostImpl::AsValue() const { | 3242 LayerTreeHostImpl::AsValue() const { |
3248 return AsValueWithFrame(NULL); | 3243 return AsValueWithFrame(NULL); |
3249 } | 3244 } |
3250 | 3245 |
3251 scoped_refptr<base::debug::ConvertableToTraceFormat> | 3246 scoped_refptr<base::debug::ConvertableToTraceFormat> |
3252 LayerTreeHostImpl::AsValueWithFrame(FrameData* frame) const { | 3247 LayerTreeHostImpl::AsValueWithFrame(FrameData* frame) const { |
3253 scoped_refptr<base::debug::TracedValue> state = | 3248 scoped_refptr<base::debug::TracedValue> state = |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3478 } | 3473 } |
3479 | 3474 |
3480 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3475 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3481 std::vector<PictureLayerImpl*>::iterator it = | 3476 std::vector<PictureLayerImpl*>::iterator it = |
3482 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3477 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3483 DCHECK(it != picture_layers_.end()); | 3478 DCHECK(it != picture_layers_.end()); |
3484 picture_layers_.erase(it); | 3479 picture_layers_.erase(it); |
3485 } | 3480 } |
3486 | 3481 |
3487 } // namespace cc | 3482 } // namespace cc |
OLD | NEW |