Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 16871016: cc: Use BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@bfargs2
Patch Set: Improve main thread perf by pushing out deadline if no Impl updates. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 rendering_stats_instrumentation)); 163 rendering_stats_instrumentation));
164 } 164 }
165 165
166 LayerTreeHostImpl::LayerTreeHostImpl( 166 LayerTreeHostImpl::LayerTreeHostImpl(
167 const LayerTreeSettings& settings, 167 const LayerTreeSettings& settings,
168 LayerTreeHostImplClient* client, 168 LayerTreeHostImplClient* client,
169 Proxy* proxy, 169 Proxy* proxy,
170 RenderingStatsInstrumentation* rendering_stats_instrumentation) 170 RenderingStatsInstrumentation* rendering_stats_instrumentation)
171 : client_(client), 171 : client_(client),
172 proxy_(proxy), 172 proxy_(proxy),
173 output_surface_lost_(true),
173 input_handler_client_(NULL), 174 input_handler_client_(NULL),
174 did_lock_scrolling_layer_(false), 175 did_lock_scrolling_layer_(false),
175 should_bubble_scrolls_(false), 176 should_bubble_scrolls_(false),
176 wheel_scrolling_(false), 177 wheel_scrolling_(false),
177 manage_tiles_needed_(false), 178 manage_tiles_needed_(false),
178 root_layer_scroll_offset_delegate_(NULL), 179 root_layer_scroll_offset_delegate_(NULL),
179 settings_(settings), 180 settings_(settings),
180 visible_(true), 181 visible_(true),
181 cached_managed_memory_policy_( 182 cached_managed_memory_policy_(
182 PrioritizedResourceManager::DefaultMemoryAllocationLimit(), 183 PrioritizedResourceManager::DefaultMemoryAllocationLimit(),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 void LayerTreeHostImpl::CommitComplete() { 246 void LayerTreeHostImpl::CommitComplete() {
246 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete"); 247 TRACE_EVENT0("cc", "LayerTreeHostImpl::CommitComplete");
247 248
248 // Impl-side painting needs an update immediately post-commit to have the 249 // Impl-side painting needs an update immediately post-commit to have the
249 // opportunity to create tilings. Other paths can call UpdateDrawProperties 250 // opportunity to create tilings. Other paths can call UpdateDrawProperties
250 // more lazily when needed prior to drawing. 251 // more lazily when needed prior to drawing.
251 if (settings_.impl_side_painting) { 252 if (settings_.impl_side_painting) {
252 pending_tree_->set_needs_update_draw_properties(); 253 pending_tree_->set_needs_update_draw_properties();
253 pending_tree_->UpdateDrawProperties(); 254 pending_tree_->UpdateDrawProperties();
254 // Start working on newly created tiles immediately if needed. 255 // Start working on newly created tiles immediately if needed.
255 ManageTiles(); 256 if (!manage_tiles_needed_)
257 client_->NotifyReadyToActivate();
258 else
259 ManageTiles();
260
256 } else { 261 } else {
257 active_tree_->set_needs_update_draw_properties(); 262 active_tree_->set_needs_update_draw_properties();
258 } 263 }
259 264
260 client_->SendManagedMemoryStats(); 265 client_->SendManagedMemoryStats();
261 } 266 }
262 267
263 bool LayerTreeHostImpl::CanDraw() const { 268 bool LayerTreeHostImpl::CanDraw() const {
264 // Note: If you are changing this function or any other function that might 269 // Note: If you are changing this function or any other function that might
265 // affect the result of CanDraw, make sure to call 270 // affect the result of CanDraw, make sure to call
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 1060
1056 void LayerTreeHostImpl::DidInitializeVisibleTile() { 1061 void LayerTreeHostImpl::DidInitializeVisibleTile() {
1057 // TODO(reveman): Determine tiles that changed and only damage 1062 // TODO(reveman): Determine tiles that changed and only damage
1058 // what's necessary. 1063 // what's necessary.
1059 SetFullRootLayerDamage(); 1064 SetFullRootLayerDamage();
1060 if (client_) 1065 if (client_)
1061 client_->DidInitializeVisibleTileOnImplThread(); 1066 client_->DidInitializeVisibleTileOnImplThread();
1062 } 1067 }
1063 1068
1064 void LayerTreeHostImpl::NotifyReadyToActivate() { 1069 void LayerTreeHostImpl::NotifyReadyToActivate() {
1065 if (pending_tree_) { 1070 client_->NotifyReadyToActivate();
1066 need_to_update_visible_tiles_before_draw_ = true;
1067 ActivatePendingTree();
1068 }
1069 } 1071 }
1070 1072
1071 bool LayerTreeHostImpl::ShouldClearRootRenderPass() const { 1073 bool LayerTreeHostImpl::ShouldClearRootRenderPass() const {
1072 return settings_.should_clear_root_render_pass; 1074 return settings_.should_clear_root_render_pass;
1073 } 1075 }
1074 1076
1075 void LayerTreeHostImpl::SetMemoryPolicy(const ManagedMemoryPolicy& policy) { 1077 void LayerTreeHostImpl::SetMemoryPolicy(const ManagedMemoryPolicy& policy) {
1076 SetManagedMemoryPolicy(policy, zero_budget_); 1078 SetManagedMemoryPolicy(policy, zero_budget_);
1077 } 1079 }
1078 1080
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 bool LayerTreeHostImpl::IsContextLost() { 1305 bool LayerTreeHostImpl::IsContextLost() {
1304 DCHECK(proxy_->IsImplThread()); 1306 DCHECK(proxy_->IsImplThread());
1305 return renderer_ && renderer_->IsContextLost(); 1307 return renderer_ && renderer_->IsContextLost();
1306 } 1308 }
1307 1309
1308 const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const { 1310 const RendererCapabilities& LayerTreeHostImpl::GetRendererCapabilities() const {
1309 return renderer_->Capabilities(); 1311 return renderer_->Capabilities();
1310 } 1312 }
1311 1313
1312 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { 1314 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) {
1313 if (frame.has_no_damage) 1315 if (frame.has_no_damage || output_surface_lost_)
1314 return false; 1316 return false;
1315 renderer_->SwapBuffers(); 1317 renderer_->SwapBuffers();
1316 active_tree_->ClearLatencyInfo(); 1318 active_tree_->ClearLatencyInfo();
1317 return true; 1319 return true;
1318 } 1320 }
1319 1321
1320 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) { 1322 void LayerTreeHostImpl::SetNeedsBeginFrame(bool enable) {
1321 if (output_surface_) 1323 if (output_surface_)
1322 output_surface_->SetNeedsBeginFrame(enable); 1324 output_surface_->SetNeedsBeginFrame(enable);
1323 } 1325 }
(...skipping 22 matching lines...) Expand all
1346 } 1348 }
1347 1349
1348 const LayerTreeSettings& LayerTreeHostImpl::Settings() const { 1350 const LayerTreeSettings& LayerTreeHostImpl::Settings() const {
1349 return settings(); 1351 return settings();
1350 } 1352 }
1351 1353
1352 void LayerTreeHostImpl::DidLoseOutputSurface() { 1354 void LayerTreeHostImpl::DidLoseOutputSurface() {
1353 // TODO(jamesr): The renderer_ check is needed to make some of the 1355 // TODO(jamesr): The renderer_ check is needed to make some of the
1354 // LayerTreeHostContextTest tests pass, but shouldn't be necessary (or 1356 // LayerTreeHostContextTest tests pass, but shouldn't be necessary (or
1355 // important) in production. We should adjust the test to not need this. 1357 // important) in production. We should adjust the test to not need this.
1358 output_surface_lost_ = true;
1356 if (renderer_) 1359 if (renderer_)
1357 client_->DidLoseOutputSurfaceOnImplThread(); 1360 client_->DidLoseOutputSurfaceOnImplThread();
1358 } 1361 }
1359 1362
1360 void LayerTreeHostImpl::Readback(void* pixels, 1363 void LayerTreeHostImpl::Readback(void* pixels,
1361 gfx::Rect rect_in_device_viewport) { 1364 gfx::Rect rect_in_device_viewport) {
1362 DCHECK(renderer_); 1365 DCHECK(renderer_);
1363 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport); 1366 renderer_->GetFramebufferPixels(pixels, rect_in_device_viewport);
1364 } 1367 }
1365 1368
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 TRACE_EVENT_ASYNC_STEP1( 1443 TRACE_EVENT_ASYNC_STEP1(
1441 "cc", 1444 "cc",
1442 "PendingTree", pending_tree_.get(), "activate", 1445 "PendingTree", pending_tree_.get(), "activate",
1443 "state", TracedValue::FromValue(ActivationStateAsValue().release())); 1446 "state", TracedValue::FromValue(ActivationStateAsValue().release()));
1444 } 1447 }
1445 1448
1446 void LayerTreeHostImpl::ActivatePendingTree() { 1449 void LayerTreeHostImpl::ActivatePendingTree() {
1447 CHECK(pending_tree_); 1450 CHECK(pending_tree_);
1448 TRACE_EVENT_ASYNC_END0("cc", "PendingTree", pending_tree_.get()); 1451 TRACE_EVENT_ASYNC_END0("cc", "PendingTree", pending_tree_.get());
1449 1452
1453 need_to_update_visible_tiles_before_draw_ = true;
1454
1450 active_tree_->SetRootLayerScrollOffsetDelegate(NULL); 1455 active_tree_->SetRootLayerScrollOffsetDelegate(NULL);
1451 active_tree_->PushPersistedState(pending_tree_.get()); 1456 active_tree_->PushPersistedState(pending_tree_.get());
1452 if (pending_tree_->needs_full_tree_sync()) { 1457 if (pending_tree_->needs_full_tree_sync()) {
1453 active_tree_->SetRootLayer( 1458 active_tree_->SetRootLayer(
1454 TreeSynchronizer::SynchronizeTrees(pending_tree_->root_layer(), 1459 TreeSynchronizer::SynchronizeTrees(pending_tree_->root_layer(),
1455 active_tree_->DetachLayerTree(), 1460 active_tree_->DetachLayerTree(),
1456 active_tree_.get())); 1461 active_tree_.get()));
1457 } 1462 }
1458 TreeSynchronizer::PushProperties(pending_tree_->root_layer(), 1463 TreeSynchronizer::PushProperties(pending_tree_->root_layer(),
1459 active_tree_->root_layer()); 1464 active_tree_->root_layer());
1460 DCHECK(!recycle_tree_); 1465 DCHECK(!recycle_tree_);
1461 1466
1462 // Process any requests in the UI resource queue. The request queue is given 1467 // Process any requests in the UI resource queue. The request queue is given
1463 // in LayerTreeHost::FinishCommitOnImplThread. This must take place before 1468 // in LayerTreeHost::FinishCommitOnImplThread. This must take place before
1464 // the swap. 1469 // the swap.
1465 pending_tree_->ProcessUIResourceRequestQueue(); 1470 pending_tree_->ProcessUIResourceRequestQueue();
1466 1471
1467 pending_tree_->PushPropertiesTo(active_tree_.get()); 1472 pending_tree_->PushPropertiesTo(active_tree_.get());
1468 1473
1469 // Now that we've synced everything from the pending tree to the active 1474 // Now that we've synced everything from the pending tree to the active
1470 // tree, rename the pending tree the recycle tree so we can reuse it on the 1475 // tree, rename the pending tree the recycle tree so we can reuse it on the
1471 // next sync. 1476 // next sync.
1472 pending_tree_.swap(recycle_tree_); 1477 pending_tree_.swap(recycle_tree_);
1473 1478
1474 active_tree_->SetRootLayerScrollOffsetDelegate( 1479 active_tree_->SetRootLayerScrollOffsetDelegate(
1475 root_layer_scroll_offset_delegate_); 1480 root_layer_scroll_offset_delegate_);
1476 active_tree_->DidBecomeActive(); 1481 active_tree_->DidBecomeActive();
1477 1482
1483 client_->DidActivatePendingTree();
1484 if (!tree_activation_callback_.is_null())
1485 tree_activation_callback_.Run();
1486
1478 // Reduce wasted memory now that unlinked resources are guaranteed not 1487 // Reduce wasted memory now that unlinked resources are guaranteed not
1479 // to be used. 1488 // to be used.
1480 client_->ReduceWastedContentsTextureMemoryOnImplThread(); 1489 client_->ReduceWastedContentsTextureMemoryOnImplThread();
1481 1490
1482 client_->OnCanDrawStateChanged(CanDraw()); 1491 client_->OnCanDrawStateChanged(CanDraw());
1483 client_->OnHasPendingTreeStateChanged(pending_tree_); 1492 client_->OnHasPendingTreeStateChanged(pending_tree_);
1484 client_->SetNeedsRedrawOnImplThread(); 1493 client_->SetNeedsRedrawOnImplThread();
1485 client_->RenewTreePriority(); 1494 client_->RenewTreePriority();
1486 1495
1487 if (debug_state_.continuous_painting) { 1496 if (debug_state_.continuous_painting) {
1488 const RenderingStats& stats = 1497 const RenderingStats& stats =
1489 rendering_stats_instrumentation_->GetRenderingStats(); 1498 rendering_stats_instrumentation_->GetRenderingStats();
1490 paint_time_counter_->SavePaintTime( 1499 paint_time_counter_->SavePaintTime(
1491 stats.total_paint_time + stats.total_record_time + 1500 stats.total_paint_time + stats.total_record_time +
1492 stats.total_rasterize_time_for_now_bins_on_pending_tree); 1501 stats.total_rasterize_time_for_now_bins_on_pending_tree);
1493 } 1502 }
1494
1495 client_->DidActivatePendingTree();
1496 if (!tree_activation_callback_.is_null())
1497 tree_activation_callback_.Run();
1498 } 1503 }
1499 1504
1500 void LayerTreeHostImpl::SetVisible(bool visible) { 1505 void LayerTreeHostImpl::SetVisible(bool visible) {
1501 DCHECK(proxy_->IsImplThread()); 1506 DCHECK(proxy_->IsImplThread());
1502 1507
1503 if (visible_ == visible) 1508 if (visible_ == visible)
1504 return; 1509 return;
1505 visible_ = visible; 1510 visible_ = visible;
1506 DidVisibilityChange(this, visible_); 1511 DidVisibilityChange(this, visible_);
1507 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); 1512 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 // before we destroy the old resource provider. 1600 // before we destroy the old resource provider.
1596 ReleaseTreeResources(); 1601 ReleaseTreeResources();
1597 if (resource_provider_) 1602 if (resource_provider_)
1598 resource_provider_->DidLoseOutputSurface(); 1603 resource_provider_->DidLoseOutputSurface();
1599 1604
1600 // Note: order is important here. 1605 // Note: order is important here.
1601 renderer_.reset(); 1606 renderer_.reset();
1602 tile_manager_.reset(); 1607 tile_manager_.reset();
1603 resource_provider_.reset(); 1608 resource_provider_.reset();
1604 output_surface_.reset(); 1609 output_surface_.reset();
1610 output_surface_lost_ = true;
1605 1611
1606 if (!output_surface->BindToClient(this)) 1612 if (!output_surface->BindToClient(this))
1607 return false; 1613 return false;
1608 1614
1609 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create( 1615 scoped_ptr<ResourceProvider> resource_provider = ResourceProvider::Create(
1610 output_surface.get(), settings_.highp_threshold_min); 1616 output_surface.get(), settings_.highp_threshold_min);
1611 if (!resource_provider) 1617 if (!resource_provider)
1612 return false; 1618 return false;
1613 1619
1614 if (output_surface->capabilities().deferred_gl_initialization) 1620 if (output_surface->capabilities().deferred_gl_initialization)
(...skipping 25 matching lines...) Expand all
1640 } 1646 }
1641 1647
1642 int max_frames_pending = 1648 int max_frames_pending =
1643 output_surface->capabilities().max_frames_pending; 1649 output_surface->capabilities().max_frames_pending;
1644 if (max_frames_pending <= 0) 1650 if (max_frames_pending <= 0)
1645 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; 1651 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING;
1646 output_surface->SetMaxFramesPending(max_frames_pending); 1652 output_surface->SetMaxFramesPending(max_frames_pending);
1647 1653
1648 resource_provider_ = resource_provider.Pass(); 1654 resource_provider_ = resource_provider.Pass();
1649 output_surface_ = output_surface.Pass(); 1655 output_surface_ = output_surface.Pass();
1656 output_surface_lost_ = false;
1650 1657
1651 client_->OnCanDrawStateChanged(CanDraw()); 1658 client_->OnCanDrawStateChanged(CanDraw());
1652 1659
1653 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs 1660 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs
1654 // to be initialized to get max texture size. 1661 // to be initialized to get max texture size.
1655 active_tree_->set_needs_update_draw_properties(); 1662 active_tree_->set_needs_update_draw_properties();
1656 if (pending_tree_) 1663 if (pending_tree_)
1657 pending_tree_->set_needs_update_draw_properties(); 1664 pending_tree_->set_needs_update_draw_properties();
1658 1665
1659 return true; 1666 return true;
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 if (!page_scale_animation_ || !RootScrollLayer()) 2216 if (!page_scale_animation_ || !RootScrollLayer())
2210 return; 2217 return;
2211 2218
2212 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); 2219 double monotonic_time = (time - base::TimeTicks()).InSecondsF();
2213 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() + 2220 gfx::Vector2dF scroll_total = RootScrollLayer()->scroll_offset() +
2214 RootScrollLayer()->ScrollDelta(); 2221 RootScrollLayer()->ScrollDelta();
2215 2222
2216 active_tree_->SetPageScaleDelta( 2223 active_tree_->SetPageScaleDelta(
2217 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / 2224 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) /
2218 active_tree_->page_scale_factor()); 2225 active_tree_->page_scale_factor());
2226
2219 gfx::Vector2dF next_scroll = 2227 gfx::Vector2dF next_scroll =
2220 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); 2228 page_scale_animation_->ScrollOffsetAtTime(monotonic_time);
2221 2229
2222 RootScrollLayer()->ScrollBy(next_scroll - scroll_total); 2230 RootScrollLayer()->ScrollBy(next_scroll - scroll_total);
2223 client_->SetNeedsRedrawOnImplThread(); 2231 client_->SetNeedsRedrawOnImplThread();
2224 2232
2225 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { 2233 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) {
2226 page_scale_animation_.reset(); 2234 page_scale_animation_.reset();
2227 client_->SetNeedsCommitOnImplThread(); 2235 client_->SetNeedsCommitOnImplThread();
2228 client_->RenewTreePriority(); 2236 client_->RenewTreePriority();
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 2503
2496 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource( 2504 ResourceProvider::ResourceId LayerTreeHostImpl::ResourceIdForUIResource(
2497 UIResourceId uid) const { 2505 UIResourceId uid) const {
2498 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid); 2506 UIResourceMap::const_iterator iter = ui_resource_map_.find(uid);
2499 if (iter != ui_resource_map_.end()) 2507 if (iter != ui_resource_map_.end())
2500 return iter->second; 2508 return iter->second;
2501 return 0; 2509 return 0;
2502 } 2510 }
2503 2511
2504 } // namespace cc 2512 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698