| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 if (context_provider->ContextCapabilities().gpu.texture_rectangle) | 112 if (context_provider->ContextCapabilities().gpu.texture_rectangle) |
| 113 return GL_TEXTURE_RECTANGLE_ARB; | 113 return GL_TEXTURE_RECTANGLE_ARB; |
| 114 | 114 |
| 115 return GL_TEXTURE_2D; | 115 return GL_TEXTURE_2D; |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace | 118 } // namespace |
| 119 | 119 |
| 120 namespace cc { | 120 namespace cc { |
| 121 | 121 |
| 122 class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { | |
| 123 public: | |
| 124 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> Create( | |
| 125 LayerTreeHostImpl* layer_tree_host_impl, | |
| 126 scoped_refptr<DelayBasedTimeSource> time_source) { | |
| 127 return make_scoped_ptr( | |
| 128 new LayerTreeHostImplTimeSourceAdapter(layer_tree_host_impl, | |
| 129 time_source)); | |
| 130 } | |
| 131 virtual ~LayerTreeHostImplTimeSourceAdapter() { | |
| 132 time_source_->SetClient(NULL); | |
| 133 time_source_->SetActive(false); | |
| 134 } | |
| 135 | |
| 136 virtual void OnTimerTick() OVERRIDE { | |
| 137 // In single threaded mode we attempt to simulate changing the current | |
| 138 // thread by maintaining a fake thread id. When we switch from one | |
| 139 // thread to another, we construct DebugScopedSetXXXThread objects that | |
| 140 // update the thread id. This lets DCHECKS that ensure we're on the | |
| 141 // right thread to work correctly in single threaded mode. The problem | |
| 142 // here is that the timer tasks are run via the message loop, and when | |
| 143 // they run, we've had no chance to construct a DebugScopedSetXXXThread | |
| 144 // object. The result is that we report that we're running on the main | |
| 145 // thread. In multi-threaded mode, this timer is run on the compositor | |
| 146 // thread, so to keep this consistent in single-threaded mode, we'll | |
| 147 // construct a DebugScopedSetImplThread object. There is no need to do | |
| 148 // this in multi-threaded mode since the real thread id's will be | |
| 149 // correct. In fact, setting fake thread id's interferes with the real | |
| 150 // thread id's and causes breakage. | |
| 151 scoped_ptr<DebugScopedSetImplThread> set_impl_thread; | |
| 152 if (!layer_tree_host_impl_->proxy()->HasImplThread()) { | |
| 153 set_impl_thread.reset( | |
| 154 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); | |
| 155 } | |
| 156 | |
| 157 // TODO(enne): This should probably happen post-animate. | |
| 158 if (layer_tree_host_impl_->pending_tree()) { | |
| 159 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); | |
| 160 layer_tree_host_impl_->ManageTiles(); | |
| 161 } | |
| 162 | |
| 163 layer_tree_host_impl_->Animate( | |
| 164 layer_tree_host_impl_->CurrentFrameTimeTicks()); | |
| 165 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); | |
| 166 bool start_ready_animations = true; | |
| 167 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | |
| 168 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | |
| 169 } | |
| 170 | |
| 171 void SetActive(bool active) { | |
| 172 if (active != time_source_->Active()) | |
| 173 time_source_->SetActive(active); | |
| 174 } | |
| 175 | |
| 176 bool Active() const { return time_source_->Active(); } | |
| 177 | |
| 178 private: | |
| 179 LayerTreeHostImplTimeSourceAdapter( | |
| 180 LayerTreeHostImpl* layer_tree_host_impl, | |
| 181 scoped_refptr<DelayBasedTimeSource> time_source) | |
| 182 : layer_tree_host_impl_(layer_tree_host_impl), | |
| 183 time_source_(time_source) { | |
| 184 time_source_->SetClient(this); | |
| 185 } | |
| 186 | |
| 187 LayerTreeHostImpl* layer_tree_host_impl_; | |
| 188 scoped_refptr<DelayBasedTimeSource> time_source_; | |
| 189 | |
| 190 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImplTimeSourceAdapter); | |
| 191 }; | |
| 192 | |
| 193 LayerTreeHostImpl::FrameData::FrameData() | 122 LayerTreeHostImpl::FrameData::FrameData() |
| 194 : contains_incomplete_tile(false), has_no_damage(false) {} | 123 : contains_incomplete_tile(false), has_no_damage(false) {} |
| 195 | 124 |
| 196 LayerTreeHostImpl::FrameData::~FrameData() {} | 125 LayerTreeHostImpl::FrameData::~FrameData() {} |
| 197 | 126 |
| 198 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( | 127 scoped_ptr<LayerTreeHostImpl> LayerTreeHostImpl::Create( |
| 199 const LayerTreeSettings& settings, | 128 const LayerTreeSettings& settings, |
| 200 LayerTreeHostImplClient* client, | 129 LayerTreeHostImplClient* client, |
| 201 Proxy* proxy, | 130 Proxy* proxy, |
| 202 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 131 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 203 SharedBitmapManager* manager, | 132 SharedBitmapManager* manager, |
| 204 int id) { | 133 int id) { |
| 205 return make_scoped_ptr(new LayerTreeHostImpl( | 134 return make_scoped_ptr(new LayerTreeHostImpl( |
| 206 settings, client, proxy, rendering_stats_instrumentation, manager, id)); | 135 settings, client, proxy, rendering_stats_instrumentation, manager, id)); |
| 207 } | 136 } |
| 208 | 137 |
| 209 LayerTreeHostImpl::LayerTreeHostImpl( | 138 LayerTreeHostImpl::LayerTreeHostImpl( |
| 210 const LayerTreeSettings& settings, | 139 const LayerTreeSettings& settings, |
| 211 LayerTreeHostImplClient* client, | 140 LayerTreeHostImplClient* client, |
| 212 Proxy* proxy, | 141 Proxy* proxy, |
| 213 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 142 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 214 SharedBitmapManager* manager, | 143 SharedBitmapManager* manager, |
| 215 int id) | 144 int id) |
| 216 : client_(client), | 145 : BaseBeginFrameSource(0), |
| 146 client_(client), |
| 217 proxy_(proxy), | 147 proxy_(proxy), |
| 218 use_gpu_rasterization_(false), | 148 use_gpu_rasterization_(false), |
| 219 input_handler_client_(NULL), | 149 input_handler_client_(NULL), |
| 220 did_lock_scrolling_layer_(false), | 150 did_lock_scrolling_layer_(false), |
| 221 should_bubble_scrolls_(false), | 151 should_bubble_scrolls_(false), |
| 222 wheel_scrolling_(false), | 152 wheel_scrolling_(false), |
| 223 scroll_affects_scroll_handler_(false), | 153 scroll_affects_scroll_handler_(false), |
| 224 scroll_layer_id_when_mouse_over_scrollbar_(0), | 154 scroll_layer_id_when_mouse_over_scrollbar_(0), |
| 225 tile_priorities_dirty_(false), | 155 tile_priorities_dirty_(false), |
| 226 root_layer_scroll_offset_delegate_(NULL), | 156 root_layer_scroll_offset_delegate_(NULL), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 pending_tree()->ApplyScrollDeltasSinceBeginMainFrame(); | 257 pending_tree()->ApplyScrollDeltasSinceBeginMainFrame(); |
| 328 pending_tree_->set_needs_update_draw_properties(); | 258 pending_tree_->set_needs_update_draw_properties(); |
| 329 pending_tree_->UpdateDrawProperties(); | 259 pending_tree_->UpdateDrawProperties(); |
| 330 // Start working on newly created tiles immediately if needed. | 260 // Start working on newly created tiles immediately if needed. |
| 331 if (!tile_manager_ || !tile_priorities_dirty_) | 261 if (!tile_manager_ || !tile_priorities_dirty_) |
| 332 NotifyReadyToActivate(); | 262 NotifyReadyToActivate(); |
| 333 else | 263 else |
| 334 ManageTiles(); | 264 ManageTiles(); |
| 335 } else { | 265 } else { |
| 336 active_tree_->set_needs_update_draw_properties(); | 266 active_tree_->set_needs_update_draw_properties(); |
| 337 if (time_source_client_adapter_ && time_source_client_adapter_->Active()) | |
| 338 DCHECK(active_tree_->root_layer()); | |
| 339 } | 267 } |
| 340 | 268 |
| 341 client_->SendManagedMemoryStats(); | 269 client_->SendManagedMemoryStats(); |
| 342 | 270 |
| 343 micro_benchmark_controller_.DidCompleteCommit(); | 271 micro_benchmark_controller_.DidCompleteCommit(); |
| 344 } | 272 } |
| 345 | 273 |
| 346 bool LayerTreeHostImpl::CanDraw() const { | 274 bool LayerTreeHostImpl::CanDraw() const { |
| 347 // Note: If you are changing this function or any other function that might | 275 // Note: If you are changing this function or any other function that might |
| 348 // affect the result of CanDraw, make sure to call | 276 // affect the result of CanDraw, make sure to call |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 DCHECK_EQ(1u, frame->render_passes.size()); | 860 DCHECK_EQ(1u, frame->render_passes.size()); |
| 933 | 861 |
| 934 return draw_result; | 862 return draw_result; |
| 935 } | 863 } |
| 936 | 864 |
| 937 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { | 865 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { |
| 938 if (input_handler_client_) | 866 if (input_handler_client_) |
| 939 input_handler_client_->MainThreadHasStoppedFlinging(); | 867 input_handler_client_->MainThreadHasStoppedFlinging(); |
| 940 } | 868 } |
| 941 | 869 |
| 942 void LayerTreeHostImpl::UpdateBackgroundAnimateTicking( | |
| 943 bool should_background_tick) { | |
| 944 DCHECK(proxy_->IsImplThread()); | |
| 945 if (should_background_tick) | |
| 946 DCHECK(active_tree_->root_layer()); | |
| 947 | |
| 948 bool enabled = should_background_tick && needs_animate_layers(); | |
| 949 | |
| 950 // Lazily create the time_source adapter so that we can vary the interval for | |
| 951 // testing. | |
| 952 if (!time_source_client_adapter_) { | |
| 953 time_source_client_adapter_ = LayerTreeHostImplTimeSourceAdapter::Create( | |
| 954 this, | |
| 955 DelayBasedTimeSource::Create( | |
| 956 LowFrequencyAnimationInterval(), | |
| 957 proxy_->HasImplThread() ? proxy_->ImplThreadTaskRunner() | |
| 958 : proxy_->MainThreadTaskRunner())); | |
| 959 } | |
| 960 | |
| 961 time_source_client_adapter_->SetActive(enabled); | |
| 962 } | |
| 963 | |
| 964 void LayerTreeHostImpl::DidAnimateScrollOffset() { | 870 void LayerTreeHostImpl::DidAnimateScrollOffset() { |
| 965 client_->SetNeedsCommitOnImplThread(); | 871 client_->SetNeedsCommitOnImplThread(); |
| 966 client_->RenewTreePriority(); | 872 client_->RenewTreePriority(); |
| 967 } | 873 } |
| 968 | 874 |
| 969 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { | 875 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { |
| 970 viewport_damage_rect_.Union(damage_rect); | 876 viewport_damage_rect_.Union(damage_rect); |
| 971 } | 877 } |
| 972 | 878 |
| 973 static inline RenderPass* FindRenderPassById( | 879 static inline RenderPass* FindRenderPassById( |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 } | 1228 } |
| 1323 | 1229 |
| 1324 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { | 1230 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { |
| 1325 if (damage_rect.IsEmpty()) | 1231 if (damage_rect.IsEmpty()) |
| 1326 return; | 1232 return; |
| 1327 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 1233 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
| 1328 client_->SetNeedsRedrawRectOnImplThread(damage_rect); | 1234 client_->SetNeedsRedrawRectOnImplThread(damage_rect); |
| 1329 } | 1235 } |
| 1330 | 1236 |
| 1331 void LayerTreeHostImpl::BeginFrame(const BeginFrameArgs& args) { | 1237 void LayerTreeHostImpl::BeginFrame(const BeginFrameArgs& args) { |
| 1332 client_->BeginFrame(args); | 1238 frame_sink_->BeginFrame(args); |
| 1333 } | 1239 } |
| 1334 | 1240 |
| 1335 void LayerTreeHostImpl::DidSwapBuffers() { | 1241 void LayerTreeHostImpl::DidSwapBuffers() { |
| 1336 client_->DidSwapBuffersOnImplThread(); | 1242 client_->DidSwapBuffersOnImplThread(); |
| 1337 } | 1243 } |
| 1338 | 1244 |
| 1339 void LayerTreeHostImpl::DidSwapBuffersComplete() { | 1245 void LayerTreeHostImpl::DidSwapBuffersComplete() { |
| 1340 client_->DidSwapBuffersCompleteOnImplThread(); | 1246 client_->DidSwapBuffersCompleteOnImplThread(); |
| 1341 } | 1247 } |
| 1342 | 1248 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 TRACE_EVENT_FLOW_STEP0( | 1463 TRACE_EVENT_FLOW_STEP0( |
| 1558 "input", | 1464 "input", |
| 1559 "LatencyInfo.Flow", | 1465 "LatencyInfo.Flow", |
| 1560 TRACE_ID_DONT_MANGLE(metadata.latency_info[i].trace_id), | 1466 TRACE_ID_DONT_MANGLE(metadata.latency_info[i].trace_id), |
| 1561 "SwapBuffers"); | 1467 "SwapBuffers"); |
| 1562 } | 1468 } |
| 1563 renderer_->SwapBuffers(metadata); | 1469 renderer_->SwapBuffers(metadata); |
| 1564 return true; | 1470 return true; |
| 1565 } | 1471 } |
| 1566 | 1472 |
| 1567 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { | 1473 void LayerTreeHostImpl::OnGenerateChange(bool generate_frames) { |
| 1568 if (output_surface_) | 1474 if (output_surface_) |
| 1569 output_surface_->SetNeedsBeginFrame(enable); | 1475 output_surface_->SetNeedsBeginFrame(generate_frames); |
| 1570 else | 1476 else |
| 1571 DCHECK(!enable); | 1477 DCHECK(!generate_frames); |
| 1478 } |
| 1479 |
| 1480 std::string LayerTreeHostImpl::TypeString() const { |
| 1481 return "LayerTreeHostImpl"; |
| 1572 } | 1482 } |
| 1573 | 1483 |
| 1574 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { | 1484 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 1575 // Sample the frame time now. This time will be used for updating animations | 1485 // Sample the frame time now. This time will be used for updating animations |
| 1576 // when we draw. | 1486 // when we draw. |
| 1577 UpdateCurrentFrameTime(); | 1487 UpdateCurrentFrameTime(); |
| 1578 // Cache the begin impl frame interval | 1488 // Cache the begin impl frame interval |
| 1579 begin_impl_frame_interval_ = args.interval; | 1489 begin_impl_frame_interval_ = args.interval; |
| 1580 } | 1490 } |
| 1581 | 1491 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1741 paint_time_counter_->SavePaintTime(stats.main_stats.paint_time + | 1651 paint_time_counter_->SavePaintTime(stats.main_stats.paint_time + |
| 1742 stats.main_stats.record_time + | 1652 stats.main_stats.record_time + |
| 1743 stats.impl_stats.rasterize_time); | 1653 stats.impl_stats.rasterize_time); |
| 1744 } | 1654 } |
| 1745 | 1655 |
| 1746 UpdateInnerViewportContainerSize(); | 1656 UpdateInnerViewportContainerSize(); |
| 1747 client_->DidActivatePendingTree(); | 1657 client_->DidActivatePendingTree(); |
| 1748 if (!tree_activation_callback_.is_null()) | 1658 if (!tree_activation_callback_.is_null()) |
| 1749 tree_activation_callback_.Run(); | 1659 tree_activation_callback_.Run(); |
| 1750 | 1660 |
| 1751 if (time_source_client_adapter_ && time_source_client_adapter_->Active()) | |
| 1752 DCHECK(active_tree_->root_layer()); | |
| 1753 devtools_instrumentation::DidActivateLayerTree( | 1661 devtools_instrumentation::DidActivateLayerTree( |
| 1754 id_, active_tree_->source_frame_number()); | 1662 id_, active_tree_->source_frame_number()); |
| 1755 } | 1663 } |
| 1756 | 1664 |
| 1757 void LayerTreeHostImpl::SetVisible(bool visible) { | 1665 void LayerTreeHostImpl::SetVisible(bool visible) { |
| 1758 DCHECK(proxy_->IsImplThread()); | 1666 DCHECK(proxy_->IsImplThread()); |
| 1759 | 1667 |
| 1760 if (visible_ == visible) | 1668 if (visible_ == visible) |
| 1761 return; | 1669 return; |
| 1762 visible_ = visible; | 1670 visible_ = visible; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2013 if (max_frames_pending <= 0) | 1921 if (max_frames_pending <= 0) |
| 2014 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; | 1922 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; |
| 2015 client_->SetMaxSwapsPendingOnImplThread(max_frames_pending); | 1923 client_->SetMaxSwapsPendingOnImplThread(max_frames_pending); |
| 2016 client_->OnCanDrawStateChanged(CanDraw()); | 1924 client_->OnCanDrawStateChanged(CanDraw()); |
| 2017 | 1925 |
| 2018 return true; | 1926 return true; |
| 2019 } | 1927 } |
| 2020 | 1928 |
| 2021 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase, | 1929 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase, |
| 2022 base::TimeDelta interval) { | 1930 base::TimeDelta interval) { |
| 2023 client_->CommitVSyncParameters(timebase, interval); | 1931 // fsink_->UpdateTimebaseAndInterval(timebase, interval); |
| 2024 } | 1932 } |
| 2025 | 1933 |
| 2026 void LayerTreeHostImpl::DeferredInitialize() { | 1934 void LayerTreeHostImpl::DeferredInitialize() { |
| 2027 DCHECK(output_surface_->capabilities().deferred_gl_initialization); | 1935 DCHECK(output_surface_->capabilities().deferred_gl_initialization); |
| 2028 DCHECK(settings_.impl_side_painting); | 1936 DCHECK(settings_.impl_side_painting); |
| 2029 DCHECK(output_surface_->context_provider()); | 1937 DCHECK(output_surface_->context_provider()); |
| 2030 | 1938 |
| 2031 ReleaseTreeResources(); | 1939 ReleaseTreeResources(); |
| 2032 renderer_.reset(); | 1940 renderer_.reset(); |
| 2033 | 1941 |
| (...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3128 swap_promise_monitor_.erase(monitor); | 3036 swap_promise_monitor_.erase(monitor); |
| 3129 } | 3037 } |
| 3130 | 3038 |
| 3131 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 3039 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
| 3132 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3040 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
| 3133 for (; it != swap_promise_monitor_.end(); it++) | 3041 for (; it != swap_promise_monitor_.end(); it++) |
| 3134 (*it)->OnSetNeedsRedrawOnImpl(); | 3042 (*it)->OnSetNeedsRedrawOnImpl(); |
| 3135 } | 3043 } |
| 3136 | 3044 |
| 3137 } // namespace cc | 3045 } // namespace cc |
| OLD | NEW |