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.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <stack> | 8 #include <stack> |
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/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "cc/animation/animation_registrar.h" | 17 #include "cc/animation/animation_registrar.h" |
18 #include "cc/animation/layer_animation_controller.h" | 18 #include "cc/animation/layer_animation_controller.h" |
19 #include "cc/base/math_util.h" | 19 #include "cc/base/math_util.h" |
20 #include "cc/base/thread.h" | |
21 #include "cc/debug/overdraw_metrics.h" | 20 #include "cc/debug/overdraw_metrics.h" |
22 #include "cc/debug/rendering_stats_instrumentation.h" | 21 #include "cc/debug/rendering_stats_instrumentation.h" |
23 #include "cc/input/top_controls_manager.h" | 22 #include "cc/input/top_controls_manager.h" |
24 #include "cc/layers/heads_up_display_layer.h" | 23 #include "cc/layers/heads_up_display_layer.h" |
25 #include "cc/layers/heads_up_display_layer_impl.h" | 24 #include "cc/layers/heads_up_display_layer_impl.h" |
26 #include "cc/layers/layer.h" | 25 #include "cc/layers/layer.h" |
27 #include "cc/layers/layer_iterator.h" | 26 #include "cc/layers/layer_iterator.h" |
28 #include "cc/layers/render_surface.h" | 27 #include "cc/layers/render_surface.h" |
29 #include "cc/layers/scrollbar_layer.h" | 28 #include "cc/layers/scrollbar_layer.h" |
30 #include "cc/resources/prioritized_resource_manager.h" | 29 #include "cc/resources/prioritized_resource_manager.h" |
(...skipping 27 matching lines...) Expand all Loading... |
58 | 57 |
59 RendererCapabilities::~RendererCapabilities() {} | 58 RendererCapabilities::~RendererCapabilities() {} |
60 | 59 |
61 bool LayerTreeHost::AnyLayerTreeHostInstanceExists() { | 60 bool LayerTreeHost::AnyLayerTreeHostInstanceExists() { |
62 return s_num_layer_tree_instances > 0; | 61 return s_num_layer_tree_instances > 0; |
63 } | 62 } |
64 | 63 |
65 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( | 64 scoped_ptr<LayerTreeHost> LayerTreeHost::Create( |
66 LayerTreeHostClient* client, | 65 LayerTreeHostClient* client, |
67 const LayerTreeSettings& settings, | 66 const LayerTreeSettings& settings, |
68 scoped_ptr<Thread> impl_thread) { | 67 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
69 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(client, | 68 scoped_ptr<LayerTreeHost> layer_tree_host(new LayerTreeHost(client, |
70 settings)); | 69 settings)); |
71 if (!layer_tree_host->Initialize(impl_thread.Pass())) | 70 if (!layer_tree_host->Initialize(impl_task_runner)) |
72 return scoped_ptr<LayerTreeHost>(); | 71 return scoped_ptr<LayerTreeHost>(); |
73 return layer_tree_host.Pass(); | 72 return layer_tree_host.Pass(); |
74 } | 73 } |
75 | 74 |
76 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, | 75 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, |
77 const LayerTreeSettings& settings) | 76 const LayerTreeSettings& settings) |
78 : animating_(false), | 77 : animating_(false), |
79 needs_full_tree_sync_(true), | 78 needs_full_tree_sync_(true), |
80 needs_filter_context_(false), | 79 needs_filter_context_(false), |
81 client_(client), | 80 client_(client), |
(...skipping 17 matching lines...) Expand all Loading... |
99 in_paint_layer_contents_(false), | 98 in_paint_layer_contents_(false), |
100 total_frames_used_for_lcd_text_metrics_(0) { | 99 total_frames_used_for_lcd_text_metrics_(0) { |
101 if (settings_.accelerated_animation_enabled) | 100 if (settings_.accelerated_animation_enabled) |
102 animation_registrar_ = AnimationRegistrar::Create(); | 101 animation_registrar_ = AnimationRegistrar::Create(); |
103 s_num_layer_tree_instances++; | 102 s_num_layer_tree_instances++; |
104 | 103 |
105 rendering_stats_instrumentation_->set_record_rendering_stats( | 104 rendering_stats_instrumentation_->set_record_rendering_stats( |
106 debug_state_.RecordRenderingStats()); | 105 debug_state_.RecordRenderingStats()); |
107 } | 106 } |
108 | 107 |
109 bool LayerTreeHost::Initialize(scoped_ptr<Thread> impl_thread) { | 108 bool LayerTreeHost::Initialize( |
110 if (impl_thread) | 109 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
111 return InitializeProxy(ThreadProxy::Create(this, impl_thread.Pass())); | 110 if (impl_task_runner) |
| 111 return InitializeProxy(ThreadProxy::Create(this, impl_task_runner)); |
112 else | 112 else |
113 return InitializeProxy(SingleThreadProxy::Create(this)); | 113 return InitializeProxy(SingleThreadProxy::Create(this)); |
114 } | 114 } |
115 | 115 |
116 bool LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) { | 116 bool LayerTreeHost::InitializeForTesting(scoped_ptr<Proxy> proxy_for_testing) { |
117 return InitializeProxy(proxy_for_testing.Pass()); | 117 return InitializeProxy(proxy_for_testing.Pass()); |
118 } | 118 } |
119 | 119 |
120 bool LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) { | 120 bool LayerTreeHost::InitializeProxy(scoped_ptr<Proxy> proxy) { |
121 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); | 121 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 needs_full_tree_sync_ = true; | 478 needs_full_tree_sync_ = true; |
479 SetNeedsCommit(); | 479 SetNeedsCommit(); |
480 } | 480 } |
481 | 481 |
482 void LayerTreeHost::SetNeedsRedraw() { | 482 void LayerTreeHost::SetNeedsRedraw() { |
483 SetNeedsRedrawRect(gfx::Rect(device_viewport_size_)); | 483 SetNeedsRedrawRect(gfx::Rect(device_viewport_size_)); |
484 } | 484 } |
485 | 485 |
486 void LayerTreeHost::SetNeedsRedrawRect(gfx::Rect damage_rect) { | 486 void LayerTreeHost::SetNeedsRedrawRect(gfx::Rect damage_rect) { |
487 proxy_->SetNeedsRedraw(damage_rect); | 487 proxy_->SetNeedsRedraw(damage_rect); |
488 if (!proxy_->ImplThread()) | 488 if (!proxy_->HasImplThread()) |
489 client_->ScheduleComposite(); | 489 client_->ScheduleComposite(); |
490 } | 490 } |
491 | 491 |
492 bool LayerTreeHost::CommitRequested() const { | 492 bool LayerTreeHost::CommitRequested() const { |
493 return proxy_->CommitRequested(); | 493 return proxy_->CommitRequested(); |
494 } | 494 } |
495 | 495 |
496 void LayerTreeHost::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events, | 496 void LayerTreeHost::SetAnimationEvents(scoped_ptr<AnimationEventsVector> events, |
497 base::Time wall_clock_time) { | 497 base::Time wall_clock_time) { |
498 DCHECK(proxy_->IsMainThread()); | 498 DCHECK(proxy_->IsMainThread()); |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 void LayerTreeHost::StartRateLimiter(WebKit::WebGraphicsContext3D* context3d) { | 990 void LayerTreeHost::StartRateLimiter(WebKit::WebGraphicsContext3D* context3d) { |
991 if (animating_) | 991 if (animating_) |
992 return; | 992 return; |
993 | 993 |
994 DCHECK(context3d); | 994 DCHECK(context3d); |
995 RateLimiterMap::iterator it = rate_limiters_.find(context3d); | 995 RateLimiterMap::iterator it = rate_limiters_.find(context3d); |
996 if (it != rate_limiters_.end()) { | 996 if (it != rate_limiters_.end()) { |
997 it->second->Start(); | 997 it->second->Start(); |
998 } else { | 998 } else { |
999 scoped_refptr<RateLimiter> rate_limiter = | 999 scoped_refptr<RateLimiter> rate_limiter = |
1000 RateLimiter::Create(context3d, this, proxy_->MainThread()); | 1000 RateLimiter::Create(context3d, this, proxy_->MainThreadTaskRunner()); |
1001 rate_limiters_[context3d] = rate_limiter; | 1001 rate_limiters_[context3d] = rate_limiter; |
1002 rate_limiter->Start(); | 1002 rate_limiter->Start(); |
1003 } | 1003 } |
1004 } | 1004 } |
1005 | 1005 |
1006 void LayerTreeHost::StopRateLimiter(WebKit::WebGraphicsContext3D* context3d) { | 1006 void LayerTreeHost::StopRateLimiter(WebKit::WebGraphicsContext3D* context3d) { |
1007 RateLimiterMap::iterator it = rate_limiters_.find(context3d); | 1007 RateLimiterMap::iterator it = rate_limiters_.find(context3d); |
1008 if (it != rate_limiters_.end()) { | 1008 if (it != rate_limiters_.end()) { |
1009 it->second->Stop(); | 1009 it->second->Stop(); |
1010 rate_limiters_.erase(it); | 1010 rate_limiters_.erase(it); |
(...skipping 23 matching lines...) Expand all Loading... |
1034 SetNeedsCommit(); | 1034 SetNeedsCommit(); |
1035 } | 1035 } |
1036 | 1036 |
1037 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, | 1037 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, |
1038 TopControlsState current, | 1038 TopControlsState current, |
1039 bool animate) { | 1039 bool animate) { |
1040 if (!settings_.calculate_top_controls_position) | 1040 if (!settings_.calculate_top_controls_position) |
1041 return; | 1041 return; |
1042 | 1042 |
1043 // Top controls are only used in threaded mode. | 1043 // Top controls are only used in threaded mode. |
1044 proxy_->ImplThread()->PostTask( | 1044 proxy_->ImplThreadTaskRunner()->PostTask( |
| 1045 FROM_HERE, |
1045 base::Bind(&TopControlsManager::UpdateTopControlsState, | 1046 base::Bind(&TopControlsManager::UpdateTopControlsState, |
1046 top_controls_manager_weak_ptr_, | 1047 top_controls_manager_weak_ptr_, |
1047 constraints, | 1048 constraints, |
1048 current, | 1049 current, |
1049 animate)); | 1050 animate)); |
1050 } | 1051 } |
1051 | 1052 |
1052 bool LayerTreeHost::BlocksPendingCommit() const { | 1053 bool LayerTreeHost::BlocksPendingCommit() const { |
1053 if (!root_layer_.get()) | 1054 if (!root_layer_.get()) |
1054 return false; | 1055 return false; |
(...skipping 25 matching lines...) Expand all Loading... |
1080 bool start_ready_animations = true; | 1081 bool start_ready_animations = true; |
1081 (*iter).second->UpdateState(start_ready_animations, NULL); | 1082 (*iter).second->UpdateState(start_ready_animations, NULL); |
1082 } | 1083 } |
1083 } | 1084 } |
1084 | 1085 |
1085 skia::RefPtr<SkPicture> LayerTreeHost::CapturePicture() { | 1086 skia::RefPtr<SkPicture> LayerTreeHost::CapturePicture() { |
1086 return proxy_->CapturePicture(); | 1087 return proxy_->CapturePicture(); |
1087 } | 1088 } |
1088 | 1089 |
1089 } // namespace cc | 1090 } // namespace cc |
OLD | NEW |