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 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 rendering_stats_instrumentation)); | 164 rendering_stats_instrumentation)); |
165 } | 165 } |
166 | 166 |
167 LayerTreeHostImpl::LayerTreeHostImpl( | 167 LayerTreeHostImpl::LayerTreeHostImpl( |
168 const LayerTreeSettings& settings, | 168 const LayerTreeSettings& settings, |
169 LayerTreeHostImplClient* client, | 169 LayerTreeHostImplClient* client, |
170 Proxy* proxy, | 170 Proxy* proxy, |
171 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 171 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
172 : client_(client), | 172 : client_(client), |
173 proxy_(proxy), | 173 proxy_(proxy), |
| 174 output_surface_lost_(true), |
174 input_handler_client_(NULL), | 175 input_handler_client_(NULL), |
175 did_lock_scrolling_layer_(false), | 176 did_lock_scrolling_layer_(false), |
176 should_bubble_scrolls_(false), | 177 should_bubble_scrolls_(false), |
177 wheel_scrolling_(false), | 178 wheel_scrolling_(false), |
178 manage_tiles_needed_(false), | 179 manage_tiles_needed_(false), |
179 root_layer_scroll_offset_delegate_(NULL), | 180 root_layer_scroll_offset_delegate_(NULL), |
180 settings_(settings), | 181 settings_(settings), |
181 visible_(true), | 182 visible_(true), |
182 cached_managed_memory_policy_( | 183 cached_managed_memory_policy_( |
183 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), | 184 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 void LayerTreeHostImpl::CommitComplete() { | 247 void LayerTreeHostImpl::CommitComplete() { |
247 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); | 248 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); |
248 | 249 |
249 // Impl-side painting needs an update immediately post-commit to have the | 250 // Impl-side painting needs an update immediately post-commit to have the |
250 // opportunity to create tilings. Other paths can call UpdateDrawProperties | 251 // opportunity to create tilings. Other paths can call UpdateDrawProperties |
251 // more lazily when needed prior to drawing. | 252 // more lazily when needed prior to drawing. |
252 if (settings_.impl_side_painting) { | 253 if (settings_.impl_side_painting) { |
253 pending_tree_->set_needs_update_draw_properties(); | 254 pending_tree_->set_needs_update_draw_properties(); |
254 pending_tree_->UpdateDrawProperties(); | 255 pending_tree_->UpdateDrawProperties(); |
255 // Start working on newly created tiles immediately if needed. | 256 // Start working on newly created tiles immediately if needed. |
256 ManageTiles(); | 257 if (!manage_tiles_needed_) |
| 258 client_->NotifyReadyToActivate(); |
| 259 else |
| 260 ManageTiles(); |
| 261 |
257 } else { | 262 } else { |
258 active_tree_->set_needs_update_draw_properties(); | 263 active_tree_->set_needs_update_draw_properties(); |
259 } | 264 } |
260 | 265 |
261 client_->SendManagedMemoryStats(); | 266 client_->SendManagedMemoryStats(); |
262 } | 267 } |
263 | 268 |
264 bool LayerTreeHostImpl::CanDraw() const { | 269 bool LayerTreeHostImpl::CanDraw() const { |
265 // Note: If you are changing this function or any other function that might | 270 // Note: If you are changing this function or any other function that might |
266 // affect the result of CanDraw, make sure to call | 271 // affect the result of CanDraw, make sure to call |
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 | 1082 |
1078 void LayerTreeHostImpl::DidInitializeVisibleTile() { | 1083 void LayerTreeHostImpl::DidInitializeVisibleTile() { |
1079 // TODO(reveman): Determine tiles that changed and only damage | 1084 // TODO(reveman): Determine tiles that changed and only damage |
1080 // what's necessary. | 1085 // what's necessary. |
1081 SetFullRootLayerDamage(); | 1086 SetFullRootLayerDamage(); |
1082 if (client_) | 1087 if (client_) |
1083 client_->DidInitializeVisibleTileOnImplThread(); | 1088 client_->DidInitializeVisibleTileOnImplThread(); |
1084 } | 1089 } |
1085 | 1090 |
1086 void LayerTreeHostImpl::NotifyReadyToActivate() { | 1091 void LayerTreeHostImpl::NotifyReadyToActivate() { |
1087 if (pending_tree_) { | 1092 client_->NotifyReadyToActivate(); |
1088 need_to_update_visible_tiles_before_draw_ = true; | |
1089 ActivatePendingTree(); | |
1090 } | |
1091 } | 1093 } |
1092 | 1094 |
1093 bool LayerTreeHostImpl::ShouldClearRootRenderPass() const { | 1095 bool LayerTreeHostImpl::ShouldClearRootRenderPass() const { |
1094 return settings_.should_clear_root_render_pass; | 1096 return settings_.should_clear_root_render_pass; |
1095 } | 1097 } |
1096 | 1098 |
1097 void LayerTreeHostImpl::SetMemoryPolicy(const ManagedMemoryPolicy& policy) { | 1099 void LayerTreeHostImpl::SetMemoryPolicy(const ManagedMemoryPolicy& policy) { |
1098 SetManagedMemoryPolicy(policy, zero_budget_); | 1100 SetManagedMemoryPolicy(policy, zero_budget_); |
1099 } | 1101 } |
1100 | 1102 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 bool LayerTreeHostImpl::IsContextLost() { | 1333 bool LayerTreeHostImpl::IsContextLost() { |
1332 DCHECK(proxy_->IsImplThread()); | 1334 DCHECK(proxy_->IsImplThread()); |
1333 return renderer_ && renderer_->IsContextLost(); | 1335 return renderer_ && renderer_->IsContextLost(); |
1334 } | 1336 } |
1335 | 1337 |
1336 const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const { | 1338 const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const { |
1337 return renderer_->Capabilities(); | 1339 return renderer_->Capabilities(); |
1338 } | 1340 } |
1339 | 1341 |
1340 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { | 1342 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { |
1341 if (frame.has_no_damage) | 1343 if (frame.has_no_damage || output_surface_lost_) |
1342 return false; | 1344 return false; |
1343 renderer_->SwapBuffers(); | 1345 renderer_->SwapBuffers(); |
1344 active_tree_->ClearLatencyInfo(); | 1346 active_tree_->ClearLatencyInfo(); |
1345 return true; | 1347 return true; |
1346 } | 1348 } |
1347 | 1349 |
1348 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { | 1350 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { |
1349 if (output_surface_) | 1351 if (output_surface_) |
1350 output_surface_->SetNeedsBeginFrame(enable); | 1352 output_surface_->SetNeedsBeginFrame(enable); |
1351 } | 1353 } |
(...skipping 22 matching lines...) Expand all Loading... |
1374 } | 1376 } |
1375 | 1377 |
1376 const LayerTreeSettings& LayerTreeHostImpl::Settings() const { | 1378 const LayerTreeSettings& LayerTreeHostImpl::Settings() const { |
1377 return settings(); | 1379 return settings(); |
1378 } | 1380 } |
1379 | 1381 |
1380 void LayerTreeHostImpl::DidLoseOutputSurface() { | 1382 void LayerTreeHostImpl::DidLoseOutputSurface() { |
1381 // TODO(jamesr): The renderer_ check is needed to make some of the | 1383 // TODO(jamesr): The renderer_ check is needed to make some of the |
1382 // LayerTreeHostContextTest tests pass, but shouldn't be necessary (or | 1384 // LayerTreeHostContextTest tests pass, but shouldn't be necessary (or |
1383 // important) in production. We should adjust the test to not need this. | 1385 // important) in production. We should adjust the test to not need this. |
| 1386 output_surface_lost_ = true; |
1384 if (renderer_) | 1387 if (renderer_) |
1385 client_->DidLoseOutputSurfaceOnImplThread(); | 1388 client_->DidLoseOutputSurfaceOnImplThread(); |
1386 } | 1389 } |
1387 | 1390 |
1388 void LayerTreeHostImpl::Readback(void* pixels, | 1391 void LayerTreeHostImpl::Readback(void* pixels, |
1389 gfx::Rect rect_in_device_viewport) { | 1392 gfx::Rect rect_in_device_viewport) { |
1390 DCHECK(renderer_); | 1393 DCHECK(renderer_); |
1391 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); | 1394 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); |
1392 } | 1395 } |
1393 | 1396 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 TRACE_EVENT_ASYNC_STEP1( | 1471 TRACE_EVENT_ASYNC_STEP1( |
1469 "cc", | 1472 "cc", |
1470 "PendingTree", pending_tree_.get(), "activate", | 1473 "PendingTree", pending_tree_.get(), "activate", |
1471 "state", TracedValue::FromValue(ActivationStateAsValue().release())); | 1474 "state", TracedValue::FromValue(ActivationStateAsValue().release())); |
1472 } | 1475 } |
1473 | 1476 |
1474 void LayerTreeHostImpl::ActivatePendingTree() { | 1477 void LayerTreeHostImpl::ActivatePendingTree() { |
1475 CHECK(pending_tree_); | 1478 CHECK(pending_tree_); |
1476 TRACE_EVENT_ASYNC_END0("cc", "PendingTree", pending_tree_.get()); | 1479 TRACE_EVENT_ASYNC_END0("cc", "PendingTree", pending_tree_.get()); |
1477 | 1480 |
| 1481 need_to_update_visible_tiles_before_draw_ = true; |
| 1482 |
1478 active_tree_->SetRootLayerScrollOffsetDelegate(NULL); | 1483 active_tree_->SetRootLayerScrollOffsetDelegate(NULL); |
1479 active_tree_->PushPersistedState(pending_tree_.get()); | 1484 active_tree_->PushPersistedState(pending_tree_.get()); |
1480 if (pending_tree_->needs_full_tree_sync()) { | 1485 if (pending_tree_->needs_full_tree_sync()) { |
1481 active_tree_->SetRootLayer( | 1486 active_tree_->SetRootLayer( |
1482 TreeSynchronizer::SynchronizeTrees(pending_tree_->root_layer(), | 1487 TreeSynchronizer::SynchronizeTrees(pending_tree_->root_layer(), |
1483 active_tree_->DetachLayerTree(), | 1488 active_tree_->DetachLayerTree(), |
1484 active_tree_.get())); | 1489 active_tree_.get())); |
1485 } | 1490 } |
1486 TreeSynchronizer::PushProperties(pending_tree_->root_layer(), | 1491 TreeSynchronizer::PushProperties(pending_tree_->root_layer(), |
1487 active_tree_->root_layer()); | 1492 active_tree_->root_layer()); |
1488 DCHECK(!recycle_tree_); | 1493 DCHECK(!recycle_tree_); |
1489 | 1494 |
1490 // Process any requests in the UI resource queue. The request queue is given | 1495 // Process any requests in the UI resource queue. The request queue is given |
1491 // in LayerTreeHost::FinishCommitOnImplThread. This must take place before | 1496 // in LayerTreeHost::FinishCommitOnImplThread. This must take place before |
1492 // the swap. | 1497 // the swap. |
1493 pending_tree_->ProcessUIResourceRequestQueue(); | 1498 pending_tree_->ProcessUIResourceRequestQueue(); |
1494 | 1499 |
1495 pending_tree_->PushPropertiesTo(active_tree_.get()); | 1500 pending_tree_->PushPropertiesTo(active_tree_.get()); |
1496 | 1501 |
1497 // Now that we've synced everything from the pending tree to the active | 1502 // Now that we've synced everything from the pending tree to the active |
1498 // tree, rename the pending tree the recycle tree so we can reuse it on the | 1503 // tree, rename the pending tree the recycle tree so we can reuse it on the |
1499 // next sync. | 1504 // next sync. |
1500 pending_tree_.swap(recycle_tree_); | 1505 pending_tree_.swap(recycle_tree_); |
1501 | 1506 |
1502 active_tree_->SetRootLayerScrollOffsetDelegate( | 1507 active_tree_->SetRootLayerScrollOffsetDelegate( |
1503 root_layer_scroll_offset_delegate_); | 1508 root_layer_scroll_offset_delegate_); |
1504 active_tree_->DidBecomeActive(); | 1509 active_tree_->DidBecomeActive(); |
1505 | 1510 |
| 1511 client_->DidActivatePendingTree(); |
| 1512 if (!tree_activation_callback_.is_null()) |
| 1513 tree_activation_callback_.Run(); |
| 1514 |
1506 // Reduce wasted memory now that unlinked resources are guaranteed not | 1515 // Reduce wasted memory now that unlinked resources are guaranteed not |
1507 // to be used. | 1516 // to be used. |
1508 client_->ReduceWastedContentsTextureMemoryOnImplThread(); | 1517 client_->ReduceWastedContentsTextureMemoryOnImplThread(); |
1509 | 1518 |
1510 client_->OnCanDrawStateChanged(CanDraw()); | 1519 client_->OnCanDrawStateChanged(CanDraw()); |
1511 client_->OnHasPendingTreeStateChanged(pending_tree_); | 1520 client_->OnHasPendingTreeStateChanged(pending_tree_); |
1512 client_->SetNeedsRedrawOnImplThread(); | 1521 client_->SetNeedsRedrawOnImplThread(); |
1513 client_->RenewTreePriority(); | 1522 client_->RenewTreePriority(); |
1514 | 1523 |
1515 if (debug_state_.continuous_painting) { | 1524 if (debug_state_.continuous_painting) { |
1516 const RenderingStats& stats = | 1525 const RenderingStats& stats = |
1517 rendering_stats_instrumentation_->GetRenderingStats(); | 1526 rendering_stats_instrumentation_->GetRenderingStats(); |
1518 paint_time_counter_->SavePaintTime( | 1527 paint_time_counter_->SavePaintTime( |
1519 stats.main_stats.paint_time + stats.main_stats.record_time + | 1528 stats.main_stats.paint_time + stats.main_stats.record_time + |
1520 stats.impl_stats.rasterize_time_for_now_bins_on_pending_tree); | 1529 stats.impl_stats.rasterize_time_for_now_bins_on_pending_tree); |
1521 } | 1530 } |
1522 | |
1523 client_->DidActivatePendingTree(); | |
1524 if (!tree_activation_callback_.is_null()) | |
1525 tree_activation_callback_.Run(); | |
1526 } | 1531 } |
1527 | 1532 |
1528 void LayerTreeHostImpl::SetVisible(bool visible) { | 1533 void LayerTreeHostImpl::SetVisible(bool visible) { |
1529 DCHECK(proxy_->IsImplThread()); | 1534 DCHECK(proxy_->IsImplThread()); |
1530 | 1535 |
1531 if (visible_ == visible) | 1536 if (visible_ == visible) |
1532 return; | 1537 return; |
1533 visible_ = visible; | 1538 visible_ = visible; |
1534 DidVisibilityChange(this, visible_); | 1539 DidVisibilityChange(this, visible_); |
1535 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); | 1540 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 // before we destroy the old resource provider. | 1628 // before we destroy the old resource provider. |
1624 ReleaseTreeResources(); | 1629 ReleaseTreeResources(); |
1625 if (resource_provider_) | 1630 if (resource_provider_) |
1626 resource_provider_->DidLoseOutputSurface(); | 1631 resource_provider_->DidLoseOutputSurface(); |
1627 | 1632 |
1628 // Note: order is important here. | 1633 // Note: order is important here. |
1629 renderer_.reset(); | 1634 renderer_.reset(); |
1630 tile_manager_.reset(); | 1635 tile_manager_.reset(); |
1631 resource_provider_.reset(); | 1636 resource_provider_.reset(); |
1632 output_surface_.reset(); | 1637 output_surface_.reset(); |
| 1638 output_surface_lost_ = true; |
1633 | 1639 |
1634 if (!output_surface->BindToClient(this)) | 1640 if (!output_surface->BindToClient(this)) |
1635 return false; | 1641 return false; |
1636 | 1642 |
1637 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( | 1643 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( |
1638 output_surface.get(), settings_.highp_threshold_min); | 1644 output_surface.get(), settings_.highp_threshold_min); |
1639 if (!resource_provider) | 1645 if (!resource_provider) |
1640 return false; | 1646 return false; |
1641 | 1647 |
1642 if (output_surface->capabilities().deferred_gl_initialization) | 1648 if (output_surface->capabilities().deferred_gl_initialization) |
(...skipping 25 matching lines...) Expand all Loading... |
1668 } | 1674 } |
1669 | 1675 |
1670 int max_frames_pending = | 1676 int max_frames_pending = |
1671 output_surface->capabilities().max_frames_pending; | 1677 output_surface->capabilities().max_frames_pending; |
1672 if (max_frames_pending <= 0) | 1678 if (max_frames_pending <= 0) |
1673 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; | 1679 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; |
1674 output_surface->SetMaxFramesPending(max_frames_pending); | 1680 output_surface->SetMaxFramesPending(max_frames_pending); |
1675 | 1681 |
1676 resource_provider_ = resource_provider.Pass(); | 1682 resource_provider_ = resource_provider.Pass(); |
1677 output_surface_ = output_surface.Pass(); | 1683 output_surface_ = output_surface.Pass(); |
| 1684 output_surface_lost_ = false; |
1678 | 1685 |
1679 client_->OnCanDrawStateChanged(CanDraw()); | 1686 client_->OnCanDrawStateChanged(CanDraw()); |
1680 | 1687 |
1681 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs | 1688 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs |
1682 // to be initialized to get max texture size. | 1689 // to be initialized to get max texture size. |
1683 active_tree_->set_needs_update_draw_properties(); | 1690 active_tree_->set_needs_update_draw_properties(); |
1684 if (pending_tree_) | 1691 if (pending_tree_) |
1685 pending_tree_->set_needs_update_draw_properties(); | 1692 pending_tree_->set_needs_update_draw_properties(); |
1686 | 1693 |
1687 return true; | 1694 return true; |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 if (!page_scale_animation_ || !RootScrollLayer()) | 2245 if (!page_scale_animation_ || !RootScrollLayer()) |
2239 return; | 2246 return; |
2240 | 2247 |
2241 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); | 2248 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); |
2242 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() + | 2249 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() + |
2243 RootScrollLayer()->ScrollDelta(); | 2250 RootScrollLayer()->ScrollDelta(); |
2244 | 2251 |
2245 active_tree_->SetPageScaleDelta( | 2252 active_tree_->SetPageScaleDelta( |
2246 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / | 2253 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / |
2247 active_tree_->page_scale_factor()); | 2254 active_tree_->page_scale_factor()); |
| 2255 |
2248 gfx::Vector2dF next_scroll = | 2256 gfx::Vector2dF next_scroll = |
2249 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); | 2257 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); |
2250 | 2258 |
2251 RootScrollLayer()->ScrollBy(next_scroll - scroll_total); | 2259 RootScrollLayer()->ScrollBy(next_scroll - scroll_total); |
2252 client_->SetNeedsRedrawOnImplThread(); | 2260 client_->SetNeedsRedrawOnImplThread(); |
2253 | 2261 |
2254 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { | 2262 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { |
2255 page_scale_animation_.reset(); | 2263 page_scale_animation_.reset(); |
2256 client_->SetNeedsCommitOnImplThread(); | 2264 client_->SetNeedsCommitOnImplThread(); |
2257 client_->RenewTreePriority(); | 2265 client_->RenewTreePriority(); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2529 | 2537 |
2530 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource( | 2538 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource( |
2531 UIResourceId uid) const { | 2539 UIResourceId uid) const { |
2532 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid); | 2540 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid); |
2533 if (iter != ui_resource_map_.end()) | 2541 if (iter != ui_resource_map_.end()) |
2534 return iter->second; | 2542 return iter->second; |
2535 return 0; | 2543 return 0; |
2536 } | 2544 } |
2537 | 2545 |
2538 } // namespace cc | 2546 } // namespace cc |
OLD | NEW |