| 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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // construct a DebugScopedSetImplThread object. There is no need to do | 99 // construct a DebugScopedSetImplThread object. There is no need to do |
| 100 // this in multi-threaded mode since the real thread id's will be | 100 // this in multi-threaded mode since the real thread id's will be |
| 101 // correct. In fact, setting fake thread id's interferes with the real | 101 // correct. In fact, setting fake thread id's interferes with the real |
| 102 // thread id's and causes breakage. | 102 // thread id's and causes breakage. |
| 103 scoped_ptr<DebugScopedSetImplThread> set_impl_thread; | 103 scoped_ptr<DebugScopedSetImplThread> set_impl_thread; |
| 104 if (!layer_tree_host_impl_->proxy()->HasImplThread()) { | 104 if (!layer_tree_host_impl_->proxy()->HasImplThread()) { |
| 105 set_impl_thread.reset( | 105 set_impl_thread.reset( |
| 106 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); | 106 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // TODO(enne): This should probably happen post-animate. | |
| 110 if (layer_tree_host_impl_->pending_tree()) { | 109 if (layer_tree_host_impl_->pending_tree()) { |
| 111 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); | 110 layer_tree_host_impl_->ActivatePendingTreeIfNeeded(); |
| 112 | 111 |
| 113 if (layer_tree_host_impl_->pending_tree()) { | 112 if (layer_tree_host_impl_->pending_tree()) { |
| 114 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); | 113 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); |
| 115 layer_tree_host_impl_->ManageTiles(); | 114 layer_tree_host_impl_->ManageTiles(); |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 | 117 |
| 119 layer_tree_host_impl_->Animate( | 118 layer_tree_host_impl_->Animate( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 rendering_stats_instrumentation)); | 161 rendering_stats_instrumentation)); |
| 163 } | 162 } |
| 164 | 163 |
| 165 LayerTreeHostImpl::LayerTreeHostImpl( | 164 LayerTreeHostImpl::LayerTreeHostImpl( |
| 166 const LayerTreeSettings& settings, | 165 const LayerTreeSettings& settings, |
| 167 LayerTreeHostImplClient* client, | 166 LayerTreeHostImplClient* client, |
| 168 Proxy* proxy, | 167 Proxy* proxy, |
| 169 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 168 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 170 : client_(client), | 169 : client_(client), |
| 171 proxy_(proxy), | 170 proxy_(proxy), |
| 171 output_surface_lost_(true), |
| 172 input_handler_client_(NULL), | 172 input_handler_client_(NULL), |
| 173 did_lock_scrolling_layer_(false), | 173 did_lock_scrolling_layer_(false), |
| 174 should_bubble_scrolls_(false), | 174 should_bubble_scrolls_(false), |
| 175 wheel_scrolling_(false), | 175 wheel_scrolling_(false), |
| 176 manage_tiles_needed_(false), | 176 manage_tiles_needed_(false), |
| 177 root_layer_scroll_offset_delegate_(NULL), | 177 root_layer_scroll_offset_delegate_(NULL), |
| 178 settings_(settings), | 178 settings_(settings), |
| 179 visible_(true), | 179 visible_(true), |
| 180 managed_memory_policy_( | 180 managed_memory_policy_( |
| 181 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), | 181 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 bool LayerTreeHostImpl::IsContextLost() { | 1264 bool LayerTreeHostImpl::IsContextLost() { |
| 1265 DCHECK(proxy_->IsImplThread()); | 1265 DCHECK(proxy_->IsImplThread()); |
| 1266 return renderer_ && renderer_->IsContextLost(); | 1266 return renderer_ && renderer_->IsContextLost(); |
| 1267 } | 1267 } |
| 1268 | 1268 |
| 1269 const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const { | 1269 const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const { |
| 1270 return renderer_->Capabilities(); | 1270 return renderer_->Capabilities(); |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1273 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { | 1273 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { |
| 1274 if (frame.has_no_damage) | 1274 if (frame.has_no_damage || output_surface_lost_) |
| 1275 return false; | 1275 return false; |
| 1276 renderer_->SwapBuffers(); | 1276 renderer_->SwapBuffers(); |
| 1277 active_tree_->ClearLatencyInfo(); | 1277 active_tree_->ClearLatencyInfo(); |
| 1278 return true; | 1278 return true; |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { | 1281 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { |
| 1282 if (output_surface_) | 1282 if (output_surface_) |
| 1283 output_surface_->SetNeedsBeginFrame(enable); | 1283 output_surface_->SetNeedsBeginFrame(enable); |
| 1284 } | 1284 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 const LayerTreeSettings& LayerTreeHostImpl::Settings() const { | 1300 const LayerTreeSettings& LayerTreeHostImpl::Settings() const { |
| 1301 return settings(); | 1301 return settings(); |
| 1302 } | 1302 } |
| 1303 | 1303 |
| 1304 void LayerTreeHostImpl::DidLoseOutputSurface() { | 1304 void LayerTreeHostImpl::DidLoseOutputSurface() { |
| 1305 // TODO(jamesr): The renderer_ check is needed to make some of the | 1305 // TODO(jamesr): The renderer_ check is needed to make some of the |
| 1306 // LayerTreeHostContextTest tests pass, but shouldn't be necessary (or | 1306 // LayerTreeHostContextTest tests pass, but shouldn't be necessary (or |
| 1307 // important) in production. We should adjust the test to not need this. | 1307 // important) in production. We should adjust the test to not need this. |
| 1308 output_surface_lost_ = true; |
| 1308 if (renderer_) | 1309 if (renderer_) |
| 1309 client_->DidLoseOutputSurfaceOnImplThread(); | 1310 client_->DidLoseOutputSurfaceOnImplThread(); |
| 1310 } | 1311 } |
| 1311 | 1312 |
| 1312 void LayerTreeHostImpl::Readback(void* pixels, | 1313 void LayerTreeHostImpl::Readback(void* pixels, |
| 1313 gfx::Rect rect_in_device_viewport) { | 1314 gfx::Rect rect_in_device_viewport) { |
| 1314 DCHECK(renderer_); | 1315 DCHECK(renderer_); |
| 1315 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); | 1316 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); |
| 1316 } | 1317 } |
| 1317 | 1318 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1415 | 1416 |
| 1416 // Now that we've synced everything from the pending tree to the active | 1417 // Now that we've synced everything from the pending tree to the active |
| 1417 // tree, rename the pending tree the recycle tree so we can reuse it on the | 1418 // tree, rename the pending tree the recycle tree so we can reuse it on the |
| 1418 // next sync. | 1419 // next sync. |
| 1419 pending_tree_.swap(recycle_tree_); | 1420 pending_tree_.swap(recycle_tree_); |
| 1420 | 1421 |
| 1421 active_tree_->SetRootLayerScrollOffsetDelegate( | 1422 active_tree_->SetRootLayerScrollOffsetDelegate( |
| 1422 root_layer_scroll_offset_delegate_); | 1423 root_layer_scroll_offset_delegate_); |
| 1423 active_tree_->DidBecomeActive(); | 1424 active_tree_->DidBecomeActive(); |
| 1424 | 1425 |
| 1426 client_->DidActivatePendingTree(); |
| 1427 |
| 1425 // Reduce wasted memory now that unlinked resources are guaranteed not | 1428 // Reduce wasted memory now that unlinked resources are guaranteed not |
| 1426 // to be used. | 1429 // to be used. |
| 1427 client_->ReduceWastedContentsTextureMemoryOnImplThread(); | 1430 client_->ReduceWastedContentsTextureMemoryOnImplThread(); |
| 1428 | 1431 |
| 1429 client_->OnCanDrawStateChanged(CanDraw()); | 1432 client_->OnCanDrawStateChanged(CanDraw()); |
| 1430 client_->OnHasPendingTreeStateChanged(pending_tree_); | 1433 client_->OnHasPendingTreeStateChanged(pending_tree_); |
| 1431 client_->SetNeedsRedrawOnImplThread(); | 1434 client_->SetNeedsRedrawOnImplThread(); |
| 1432 client_->RenewTreePriority(); | 1435 client_->RenewTreePriority(); |
| 1433 | 1436 |
| 1434 if (debug_state_.continuous_painting) { | 1437 if (debug_state_.continuous_painting) { |
| 1435 const RenderingStats& stats = | 1438 const RenderingStats& stats = |
| 1436 rendering_stats_instrumentation_->GetRenderingStats(); | 1439 rendering_stats_instrumentation_->GetRenderingStats(); |
| 1437 paint_time_counter_->SavePaintTime( | 1440 paint_time_counter_->SavePaintTime( |
| 1438 stats.total_paint_time + stats.total_record_time + | 1441 stats.total_paint_time + stats.total_record_time + |
| 1439 stats.total_rasterize_time_for_now_bins_on_pending_tree); | 1442 stats.total_rasterize_time_for_now_bins_on_pending_tree); |
| 1440 } | 1443 } |
| 1441 | |
| 1442 client_->DidActivatePendingTree(); | |
| 1443 } | 1444 } |
| 1444 | 1445 |
| 1445 void LayerTreeHostImpl::SetVisible(bool visible) { | 1446 void LayerTreeHostImpl::SetVisible(bool visible) { |
| 1446 DCHECK(proxy_->IsImplThread()); | 1447 DCHECK(proxy_->IsImplThread()); |
| 1447 | 1448 |
| 1448 if (visible_ == visible) | 1449 if (visible_ == visible) |
| 1449 return; | 1450 return; |
| 1450 visible_ = visible; | 1451 visible_ = visible; |
| 1451 DidVisibilityChange(this, visible_); | 1452 DidVisibilityChange(this, visible_); |
| 1452 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); | 1453 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 // before we destroy the old resource provider. | 1541 // before we destroy the old resource provider. |
| 1541 ReleaseTreeResources(); | 1542 ReleaseTreeResources(); |
| 1542 if (resource_provider_) | 1543 if (resource_provider_) |
| 1543 resource_provider_->DidLoseOutputSurface(); | 1544 resource_provider_->DidLoseOutputSurface(); |
| 1544 | 1545 |
| 1545 // Note: order is important here. | 1546 // Note: order is important here. |
| 1546 renderer_.reset(); | 1547 renderer_.reset(); |
| 1547 tile_manager_.reset(); | 1548 tile_manager_.reset(); |
| 1548 resource_provider_.reset(); | 1549 resource_provider_.reset(); |
| 1549 output_surface_.reset(); | 1550 output_surface_.reset(); |
| 1551 output_surface_lost_ = true; |
| 1550 | 1552 |
| 1551 if (!output_surface->BindToClient(this)) | 1553 if (!output_surface->BindToClient(this)) |
| 1552 return false; | 1554 return false; |
| 1553 | 1555 |
| 1554 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( | 1556 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( |
| 1555 output_surface.get(), settings_.highp_threshold_min); | 1557 output_surface.get(), settings_.highp_threshold_min); |
| 1556 if (!resource_provider) | 1558 if (!resource_provider) |
| 1557 return false; | 1559 return false; |
| 1558 | 1560 |
| 1559 if (output_surface->capabilities().deferred_gl_initialization) | 1561 if (output_surface->capabilities().deferred_gl_initialization) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1585 } | 1587 } |
| 1586 | 1588 |
| 1587 int max_frames_pending = | 1589 int max_frames_pending = |
| 1588 output_surface->capabilities().max_frames_pending; | 1590 output_surface->capabilities().max_frames_pending; |
| 1589 if (max_frames_pending <= 0) | 1591 if (max_frames_pending <= 0) |
| 1590 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; | 1592 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; |
| 1591 output_surface->SetMaxFramesPending(max_frames_pending); | 1593 output_surface->SetMaxFramesPending(max_frames_pending); |
| 1592 | 1594 |
| 1593 resource_provider_ = resource_provider.Pass(); | 1595 resource_provider_ = resource_provider.Pass(); |
| 1594 output_surface_ = output_surface.Pass(); | 1596 output_surface_ = output_surface.Pass(); |
| 1597 output_surface_lost_ = false; |
| 1595 | 1598 |
| 1596 client_->OnCanDrawStateChanged(CanDraw()); | 1599 client_->OnCanDrawStateChanged(CanDraw()); |
| 1597 | 1600 |
| 1598 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs | 1601 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs |
| 1599 // to be initialized to get max texture size. | 1602 // to be initialized to get max texture size. |
| 1600 active_tree_->set_needs_update_draw_properties(); | 1603 active_tree_->set_needs_update_draw_properties(); |
| 1601 if (pending_tree_) | 1604 if (pending_tree_) |
| 1602 pending_tree_->set_needs_update_draw_properties(); | 1605 pending_tree_->set_needs_update_draw_properties(); |
| 1603 | 1606 |
| 1604 return true; | 1607 return true; |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2387 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) | 2390 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) |
| 2388 return; | 2391 return; |
| 2389 if (debug_state_.continuous_painting != new_debug_state.continuous_painting) | 2392 if (debug_state_.continuous_painting != new_debug_state.continuous_painting) |
| 2390 paint_time_counter_->ClearHistory(); | 2393 paint_time_counter_->ClearHistory(); |
| 2391 | 2394 |
| 2392 debug_state_ = new_debug_state; | 2395 debug_state_ = new_debug_state; |
| 2393 SetFullRootLayerDamage(); | 2396 SetFullRootLayerDamage(); |
| 2394 } | 2397 } |
| 2395 | 2398 |
| 2396 } // namespace cc | 2399 } // namespace cc |
| OLD | NEW |