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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 if (context_provider->ContextCapabilities().gpu.texture_rectangle) | 120 if (context_provider->ContextCapabilities().gpu.texture_rectangle) |
121 return GL_TEXTURE_RECTANGLE_ARB; | 121 return GL_TEXTURE_RECTANGLE_ARB; |
122 | 122 |
123 return GL_TEXTURE_2D; | 123 return GL_TEXTURE_2D; |
124 } | 124 } |
125 | 125 |
126 } // namespace | 126 } // namespace |
127 | 127 |
128 namespace cc { | 128 namespace cc { |
129 | 129 |
130 class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { | |
131 public: | |
132 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create( | |
133 LayerTreeHostImpl* layer_tree_host_impl, | |
134 scoped_refptr<DelayBasedTimeSource> time_source) { | |
135 return make_scoped_ptr( | |
136 new LayerTreeHostImplTimeSourceAdapter(layer_tree_host_impl, | |
137 time_source)); | |
138 } | |
139 virtual ~LayerTreeHostImplTimeSourceAdapter() { | |
140 time_source_->SetClient(NULL); | |
141 time_source_->SetActive(false); | |
142 } | |
143 | |
144 virtual void OnTimerTick() OVERRIDE { | |
145 // In single threaded mode we attempt to simulate changing the current | |
146 // thread by maintaining a fake thread id. When we switch from one | |
147 // thread to another, we construct DebugScopedSetXXXThread objects that | |
148 // update the thread id. This lets DCHECKS that ensure we're on the | |
149 // right thread to work correctly in single threaded mode. The problem | |
150 // here is that the timer tasks are run via the message loop, and when | |
151 // they run, we've had no chance to construct a DebugScopedSetXXXThread | |
152 // object. The result is that we report that we're running on the main | |
153 // thread. In multi-threaded mode, this timer is run on the compositor | |
154 // thread, so to keep this consistent in single-threaded mode, we'll | |
155 // construct a DebugScopedSetImplThread object. There is no need to do | |
156 // this in multi-threaded mode since the real thread id's will be | |
157 // correct. In fact, setting fake thread id's interferes with the real | |
158 // thread id's and causes breakage. | |
159 scoped_ptr<DebugScopedSetImplThread> set_impl_thread; | |
160 if (!layer_tree_host_impl_->proxy()->HasImplThread()) { | |
161 set_impl_thread.reset( | |
162 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); | |
163 } | |
164 | |
165 // TODO(enne): This should probably happen post-animate. | |
166 if (layer_tree_host_impl_->pending_tree()) { | |
167 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); | |
168 layer_tree_host_impl_->ManageTiles(); | |
169 } | |
170 | |
171 layer_tree_host_impl_->Animate( | |
172 layer_tree_host_impl_->CurrentFrameTimeTicks()); | |
173 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); | |
174 bool start_ready_animations = true; | |
175 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | |
176 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
177 } | |
178 | |
179 void SetActive(bool active) { | |
180 if (active != time_source_->Active()) | |
181 time_source_->SetActive(active); | |
182 } | |
183 | |
184 bool Active() const { return time_source_->Active(); } | |
185 | |
186 private: | |
187 LayerTreeHostImplTimeSourceAdapter( | |
188 LayerTreeHostImpl* layer_tree_host_impl, | |
189 scoped_refptr<DelayBasedTimeSource> time_source) | |
190 : layer_tree_host_impl_(layer_tree_host_impl), | |
191 time_source_(time_source) { | |
192 time_source_->SetClient(this); | |
193 } | |
194 | |
195 LayerTreeHostImpl* layer_tree_host_impl_; | |
196 scoped_refptr<DelayBasedTimeSource> time_source_; | |
197 | |
198 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter); | |
199 }; | |
200 | |
201 LayerTreeHostImpl::FrameData::FrameData() | 130 LayerTreeHostImpl::FrameData::FrameData() |
202 : contains_incomplete_tile(false), has_no_damage(false) {} | 131 : contains_incomplete_tile(false), has_no_damage(false) {} |
203 | 132 |
204 LayerTreeHostImpl::FrameData::~FrameData() {} | 133 LayerTreeHostImpl::FrameData::~FrameData() {} |
205 | 134 |
206 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( | 135 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( |
207 const LayerTreeSettings& settings, | 136 const LayerTreeSettings& settings, |
208 LayerTreeHostImplClient* client, | 137 LayerTreeHostImplClient* client, |
209 Proxy* proxy, | 138 Proxy* proxy, |
210 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 139 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
211 SharedBitmapManager* manager, | 140 SharedBitmapManager* manager, |
212 int id) { | 141 int id) { |
213 return make_scoped_ptr(new LayerTreeHostImpl( | 142 return make_scoped_ptr(new LayerTreeHostImpl( |
214 settings, client, proxy, rendering_stats_instrumentation, manager, id)); | 143 settings, client, proxy, rendering_stats_instrumentation, manager, id)); |
215 } | 144 } |
216 | 145 |
217 LayerTreeHostImpl::LayerTreeHostImpl( | 146 LayerTreeHostImpl::LayerTreeHostImpl( |
218 const LayerTreeSettings& settings, | 147 const LayerTreeSettings& settings, |
219 LayerTreeHostImplClient* client, | 148 LayerTreeHostImplClient* client, |
220 Proxy* proxy, | 149 Proxy* proxy, |
221 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 150 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
222 SharedBitmapManager* manager, | 151 SharedBitmapManager* manager, |
223 int id) | 152 int id) |
224 : client_(client), | 153 : BaseFrameSource(0), |
154 client_(client), | |
225 proxy_(proxy), | 155 proxy_(proxy), |
226 input_handler_client_(NULL), | 156 input_handler_client_(NULL), |
227 did_lock_scrolling_layer_(false), | 157 did_lock_scrolling_layer_(false), |
228 should_bubble_scrolls_(false), | 158 should_bubble_scrolls_(false), |
229 wheel_scrolling_(false), | 159 wheel_scrolling_(false), |
230 scroll_affects_scroll_handler_(false), | 160 scroll_affects_scroll_handler_(false), |
231 scroll_layer_id_when_mouse_over_scrollbar_(0), | 161 scroll_layer_id_when_mouse_over_scrollbar_(0), |
232 tile_priorities_dirty_(false), | 162 tile_priorities_dirty_(false), |
233 root_layer_scroll_offset_delegate_(NULL), | 163 root_layer_scroll_offset_delegate_(NULL), |
234 settings_(settings), | 164 settings_(settings), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 pending_tree()->ApplyScrollDeltasSinceBeginMainFrame(); | 267 pending_tree()->ApplyScrollDeltasSinceBeginMainFrame(); |
338 pending_tree_->set_needs_update_draw_properties(); | 268 pending_tree_->set_needs_update_draw_properties(); |
339 pending_tree_->UpdateDrawProperties(); | 269 pending_tree_->UpdateDrawProperties(); |
340 // Start working on newly created tiles immediately if needed. | 270 // Start working on newly created tiles immediately if needed. |
341 if (!tile_manager_ || !tile_priorities_dirty_) | 271 if (!tile_manager_ || !tile_priorities_dirty_) |
342 NotifyReadyToActivate(); | 272 NotifyReadyToActivate(); |
343 else | 273 else |
344 ManageTiles(); | 274 ManageTiles(); |
345 } else { | 275 } else { |
346 active_tree_->set_needs_update_draw_properties(); | 276 active_tree_->set_needs_update_draw_properties(); |
347 if (time_source_client_adapter_ && time_source_client_adapter_->Active()) | |
348 DCHECK(active_tree_->root_layer()); | |
349 } | 277 } |
350 | 278 |
351 client_->SendManagedMemoryStats(); | 279 client_->SendManagedMemoryStats(); |
352 | 280 |
353 micro_benchmark_controller_.DidCompleteCommit(); | 281 micro_benchmark_controller_.DidCompleteCommit(); |
354 } | 282 } |
355 | 283 |
356 bool LayerTreeHostImpl::CanDraw() const { | 284 bool LayerTreeHostImpl::CanDraw() const { |
357 // Note: If you are changing this function or any other function that might | 285 // Note: If you are changing this function or any other function that might |
358 // affect the result of CanDraw, make sure to call | 286 // affect the result of CanDraw, make sure to call |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
953 DCHECK_EQ(1u, frame->render_passes.size()); | 881 DCHECK_EQ(1u, frame->render_passes.size()); |
954 | 882 |
955 return draw_result; | 883 return draw_result; |
956 } | 884 } |
957 | 885 |
958 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { | 886 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { |
959 if (input_handler_client_) | 887 if (input_handler_client_) |
960 input_handler_client_->MainThreadHasStoppedFlinging(); | 888 input_handler_client_->MainThreadHasStoppedFlinging(); |
961 } | 889 } |
962 | 890 |
963 void LayerTreeHostImpl::UpdateBackgroundAnimateTicking( | |
964 bool should_background_tick) { | |
965 DCHECK(proxy_->IsImplThread()); | |
966 if (should_background_tick) | |
967 DCHECK(active_tree_->root_layer()); | |
968 | |
969 bool enabled = should_background_tick && needs_animate_layers(); | |
brianderson
2014/05/07 18:09:59
Do we need to communicate the needs_animate_layer(
mithro-old
2014/05/07 22:02:32
The needs_animate_layer is part of the question if
brianderson
2014/05/08 00:55:58
Yes.
| |
970 | |
971 // Lazily create the time_source adapter so that we can vary the interval for | |
972 // testing. | |
973 if (!time_source_client_adapter_) { | |
974 time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create( | |
975 this, | |
976 DelayBasedTimeSource::Create( | |
977 LowFrequencyAnimationInterval(), | |
978 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | |
979 : proxy_->MainThreadTaskRunner())); | |
980 } | |
981 | |
982 time_source_client_adapter_->SetActive(enabled); | |
983 } | |
984 | |
985 void LayerTreeHostImpl::DidAnimateScrollOffset() { | 891 void LayerTreeHostImpl::DidAnimateScrollOffset() { |
986 client_->SetNeedsCommitOnImplThread(); | 892 client_->SetNeedsCommitOnImplThread(); |
987 client_->RenewTreePriority(); | 893 client_->RenewTreePriority(); |
988 } | 894 } |
989 | 895 |
990 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { | 896 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { |
991 viewport_damage_rect_.Union(damage_rect); | 897 viewport_damage_rect_.Union(damage_rect); |
992 } | 898 } |
993 | 899 |
994 static inline RenderPass* FindRenderPassById( | 900 static inline RenderPass* FindRenderPassById( |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1334 } | 1240 } |
1335 | 1241 |
1336 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { | 1242 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { |
1337 if (damage_rect.IsEmpty()) | 1243 if (damage_rect.IsEmpty()) |
1338 return; | 1244 return; |
1339 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 1245 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
1340 client_->SetNeedsRedrawRectOnImplThread(damage_rect); | 1246 client_->SetNeedsRedrawRectOnImplThread(damage_rect); |
1341 } | 1247 } |
1342 | 1248 |
1343 void LayerTreeHostImpl::BeginFrame(const BeginFrameArgs& args) { | 1249 void LayerTreeHostImpl::BeginFrame(const BeginFrameArgs& args) { |
1344 client_->BeginFrame(args); | 1250 SendBeginFrame(args); |
1345 } | 1251 } |
1346 | 1252 |
1347 void LayerTreeHostImpl::DidSwapBuffers() { | 1253 void LayerTreeHostImpl::DidSwapBuffers() { |
1348 client_->DidSwapBuffersOnImplThread(); | 1254 client_->DidSwapBuffersOnImplThread(); |
1349 } | 1255 } |
1350 | 1256 |
1351 void LayerTreeHostImpl::DidSwapBuffersComplete() { | 1257 void LayerTreeHostImpl::DidSwapBuffersComplete() { |
1352 client_->DidSwapBuffersCompleteOnImplThread(); | 1258 client_->DidSwapBuffersCompleteOnImplThread(); |
1353 } | 1259 } |
1354 | 1260 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1547 TRACE_EVENT_FLOW_STEP0( | 1453 TRACE_EVENT_FLOW_STEP0( |
1548 "input", | 1454 "input", |
1549 "LatencyInfo.Flow", | 1455 "LatencyInfo.Flow", |
1550 TRACE_ID_DONT_MANGLE(metadata.latency_info[i].trace_id), | 1456 TRACE_ID_DONT_MANGLE(metadata.latency_info[i].trace_id), |
1551 "SwapBuffers"); | 1457 "SwapBuffers"); |
1552 } | 1458 } |
1553 renderer_->SwapBuffers(metadata); | 1459 renderer_->SwapBuffers(metadata); |
1554 return true; | 1460 return true; |
1555 } | 1461 } |
1556 | 1462 |
1557 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { | 1463 void LayerTreeHostImpl::SetNeedsBeginFrame(bool needs_begin_frame) { |
1558 if (output_surface_) | 1464 if (output_surface_) |
1559 output_surface_->SetNeedsBeginFrame(enable); | 1465 output_surface_->SetNeedsBeginFrame(needs_begin_frame); |
1560 else | 1466 else |
1561 DCHECK(!enable); | 1467 DCHECK(!needs_begin_frame); |
1468 } | |
1469 | |
1470 void LayerTreeHostImpl::SetSink(FrameSink* sink) { | |
brianderson
2014/05/07 18:09:59
Missing?
mithro-old
2014/05/07 23:42:28
Done.
| |
1471 } | |
1472 void LayerTreeHostImpl::SetTimeBaseAndInterval(base::TimeTicks timebase, | |
1473 base::TimeDelta interval) { | |
1474 } | |
1475 | |
1476 scoped_ptr<base::Value> LayerTreeHostImpl::FrameSourceAsValue() const { | |
1477 scoped_ptr<base::DictionaryValue> state = | |
1478 BaseFrameSource::BaseFrameSourceAsValue(); | |
1479 state->SetString("type", "LayerTreeHostImpl"); | |
1480 state->SetInteger("this", reinterpret_cast<size_t>(this)); | |
1481 state->SetInteger("output_surface", | |
1482 reinterpret_cast<size_t>(output_surface_.get())); | |
1483 return state.PassAs<base::Value>(); | |
1484 } | |
1485 std::string LayerTreeHostImpl::FrameSourceType() const { | |
1486 return "LayerTreeHostImpl"; | |
1562 } | 1487 } |
1563 | 1488 |
1564 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { | 1489 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { |
1565 // Sample the frame time now. This time will be used for updating animations | 1490 // Sample the frame time now. This time will be used for updating animations |
1566 // when we draw. | 1491 // when we draw. |
1567 UpdateCurrentFrameTime(); | 1492 UpdateCurrentFrameTime(); |
1568 } | 1493 } |
1569 | 1494 |
1570 gfx::SizeF LayerTreeHostImpl::ComputeInnerViewportContainerSize() const { | 1495 gfx::SizeF LayerTreeHostImpl::ComputeInnerViewportContainerSize() const { |
1571 gfx::SizeF dip_size = | 1496 gfx::SizeF dip_size = |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1735 paint_time_counter_->SavePaintTime(stats.main_stats.paint_time + | 1660 paint_time_counter_->SavePaintTime(stats.main_stats.paint_time + |
1736 stats.main_stats.record_time + | 1661 stats.main_stats.record_time + |
1737 stats.impl_stats.rasterize_time); | 1662 stats.impl_stats.rasterize_time); |
1738 } | 1663 } |
1739 | 1664 |
1740 UpdateInnerViewportContainerSize(); | 1665 UpdateInnerViewportContainerSize(); |
1741 client_->DidActivatePendingTree(); | 1666 client_->DidActivatePendingTree(); |
1742 if (!tree_activation_callback_.is_null()) | 1667 if (!tree_activation_callback_.is_null()) |
1743 tree_activation_callback_.Run(); | 1668 tree_activation_callback_.Run(); |
1744 | 1669 |
1745 if (time_source_client_adapter_ && time_source_client_adapter_->Active()) | |
1746 DCHECK(active_tree_->root_layer()); | |
1747 devtools_instrumentation::DidActivateLayerTree( | 1670 devtools_instrumentation::DidActivateLayerTree( |
1748 id_, active_tree_->source_frame_number()); | 1671 id_, active_tree_->source_frame_number()); |
1749 } | 1672 } |
1750 | 1673 |
1751 void LayerTreeHostImpl::SetVisible(bool visible) { | 1674 void LayerTreeHostImpl::SetVisible(bool visible) { |
1752 DCHECK(proxy_->IsImplThread()); | 1675 DCHECK(proxy_->IsImplThread()); |
1753 | 1676 |
1754 if (visible_ == visible) | 1677 if (visible_ == visible) |
1755 return; | 1678 return; |
1756 visible_ = visible; | 1679 visible_ = visible; |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2007 resource_provider_ = resource_provider.Pass(); | 1930 resource_provider_ = resource_provider.Pass(); |
2008 output_surface_ = output_surface.Pass(); | 1931 output_surface_ = output_surface.Pass(); |
2009 | 1932 |
2010 client_->OnCanDrawStateChanged(CanDraw()); | 1933 client_->OnCanDrawStateChanged(CanDraw()); |
2011 | 1934 |
2012 return true; | 1935 return true; |
2013 } | 1936 } |
2014 | 1937 |
2015 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase, | 1938 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase, |
2016 base::TimeDelta interval) { | 1939 base::TimeDelta interval) { |
2017 client_->CommitVSyncParameters(timebase, interval); | 1940 // fsink_->UpdateTimebaseAndInterval(timebase, interval); |
2018 } | 1941 } |
2019 | 1942 |
2020 void LayerTreeHostImpl::DeferredInitialize() { | 1943 void LayerTreeHostImpl::DeferredInitialize() { |
2021 DCHECK(output_surface_->capabilities().deferred_gl_initialization); | 1944 DCHECK(output_surface_->capabilities().deferred_gl_initialization); |
2022 DCHECK(settings_.impl_side_painting); | 1945 DCHECK(settings_.impl_side_painting); |
2023 DCHECK(output_surface_->context_provider()); | 1946 DCHECK(output_surface_->context_provider()); |
2024 | 1947 |
2025 ReleaseTreeResources(); | 1948 ReleaseTreeResources(); |
2026 renderer_.reset(); | 1949 renderer_.reset(); |
2027 | 1950 |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3151 swap_promise_monitor_.erase(monitor); | 3074 swap_promise_monitor_.erase(monitor); |
3152 } | 3075 } |
3153 | 3076 |
3154 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 3077 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
3155 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3078 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
3156 for (; it != swap_promise_monitor_.end(); it++) | 3079 for (; it != swap_promise_monitor_.end(); it++) |
3157 (*it)->OnSetNeedsRedrawOnImpl(); | 3080 (*it)->OnSetNeedsRedrawOnImpl(); |
3158 } | 3081 } |
3159 | 3082 |
3160 } // namespace cc | 3083 } // namespace cc |
OLD | NEW |