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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 302 } |
303 | 303 |
304 // The layer trees must be destroyed before the layer tree host. We've | 304 // The layer trees must be destroyed before the layer tree host. We've |
305 // made a contract with our animation controllers that the registrar | 305 // made a contract with our animation controllers that the registrar |
306 // will outlive them, and we must make good. | 306 // will outlive them, and we must make good. |
307 if (recycle_tree_) | 307 if (recycle_tree_) |
308 recycle_tree_->Shutdown(); | 308 recycle_tree_->Shutdown(); |
309 if (pending_tree_) | 309 if (pending_tree_) |
310 pending_tree_->Shutdown(); | 310 pending_tree_->Shutdown(); |
311 active_tree_->Shutdown(); | 311 active_tree_->Shutdown(); |
312 recycle_tree_.reset(); | 312 recycle_tree_ = nullptr; |
313 pending_tree_.reset(); | 313 pending_tree_ = nullptr; |
314 active_tree_.reset(); | 314 active_tree_ = nullptr; |
315 DestroyTileManager(); | 315 DestroyTileManager(); |
316 } | 316 } |
317 | 317 |
318 void LayerTreeHostImpl::BeginMainFrameAborted(bool did_handle) { | 318 void LayerTreeHostImpl::BeginMainFrameAborted(bool did_handle) { |
319 // If the begin frame data was handled, then scroll and scale set was applied | 319 // If the begin frame data was handled, then scroll and scale set was applied |
320 // by the main thread, so the active tree needs to be updated as if these sent | 320 // by the main thread, so the active tree needs to be updated as if these sent |
321 // values were applied and committed. | 321 // values were applied and committed. |
322 if (did_handle) { | 322 if (did_handle) { |
323 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); | 323 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); |
324 active_tree_->ResetContentsTexturesPurged(); | 324 active_tree_->ResetContentsTexturesPurged(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 if (!InnerViewportScrollLayer()) | 439 if (!InnerViewportScrollLayer()) |
440 return; | 440 return; |
441 | 441 |
442 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); | 442 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); |
443 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); | 443 gfx::SizeF scaled_scrollable_size = active_tree_->ScrollableSize(); |
444 gfx::SizeF viewport_size = | 444 gfx::SizeF viewport_size = |
445 active_tree_->InnerViewportContainerLayer()->bounds(); | 445 active_tree_->InnerViewportContainerLayer()->bounds(); |
446 | 446 |
447 // Easing constants experimentally determined. | 447 // Easing constants experimentally determined. |
448 scoped_ptr<TimingFunction> timing_function = | 448 scoped_ptr<TimingFunction> timing_function = |
449 CubicBezierTimingFunction::Create(.8, 0, .3, .9).PassAs<TimingFunction>(); | 449 CubicBezierTimingFunction::Create(.8, 0, .3, .9); |
450 | 450 |
451 page_scale_animation_ = | 451 page_scale_animation_ = |
452 PageScaleAnimation::Create(scroll_total, | 452 PageScaleAnimation::Create(scroll_total, |
453 active_tree_->total_page_scale_factor(), | 453 active_tree_->total_page_scale_factor(), |
454 viewport_size, | 454 viewport_size, |
455 scaled_scrollable_size, | 455 scaled_scrollable_size, |
456 timing_function.Pass()); | 456 timing_function.Pass()); |
457 | 457 |
458 if (anchor_point) { | 458 if (anchor_point) { |
459 gfx::Vector2dF anchor(target_offset); | 459 gfx::Vector2dF anchor(target_offset); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 LayerImpl* layer_impl = | 499 LayerImpl* layer_impl = |
500 active_tree_->FindLayerThatIsHitByPointInTouchHandlerRegion( | 500 active_tree_->FindLayerThatIsHitByPointInTouchHandlerRegion( |
501 device_viewport_point); | 501 device_viewport_point); |
502 | 502 |
503 return layer_impl != NULL; | 503 return layer_impl != NULL; |
504 } | 504 } |
505 | 505 |
506 scoped_ptr<SwapPromiseMonitor> | 506 scoped_ptr<SwapPromiseMonitor> |
507 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor( | 507 LayerTreeHostImpl::CreateLatencyInfoSwapPromiseMonitor( |
508 ui::LatencyInfo* latency) { | 508 ui::LatencyInfo* latency) { |
509 return scoped_ptr<SwapPromiseMonitor>( | 509 return make_scoped_ptr( |
510 new LatencyInfoSwapPromiseMonitor(latency, NULL, this)); | 510 new LatencyInfoSwapPromiseMonitor(latency, NULL, this)); |
511 } | 511 } |
512 | 512 |
513 void LayerTreeHostImpl::QueueSwapPromiseForMainThreadScrollUpdate( | 513 void LayerTreeHostImpl::QueueSwapPromiseForMainThreadScrollUpdate( |
514 scoped_ptr<SwapPromise> swap_promise) { | 514 scoped_ptr<SwapPromise> swap_promise) { |
515 swap_promises_for_main_thread_scroll_update_.push_back(swap_promise.Pass()); | 515 swap_promises_for_main_thread_scroll_update_.push_back(swap_promise.Pass()); |
516 } | 516 } |
517 | 517 |
518 void LayerTreeHostImpl::TrackDamageForAllSurfaces( | 518 void LayerTreeHostImpl::TrackDamageForAllSurfaces( |
519 LayerImpl* root_draw_layer, | 519 LayerImpl* root_draw_layer, |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 SetFullRootLayerDamage(); | 1164 SetFullRootLayerDamage(); |
1165 DidInitializeVisibleTile(); | 1165 DidInitializeVisibleTile(); |
1166 } | 1166 } |
1167 | 1167 |
1168 void LayerTreeHostImpl::ResetTreesForTesting() { | 1168 void LayerTreeHostImpl::ResetTreesForTesting() { |
1169 if (active_tree_) | 1169 if (active_tree_) |
1170 active_tree_->DetachLayerTree(); | 1170 active_tree_->DetachLayerTree(); |
1171 active_tree_ = LayerTreeImpl::create(this); | 1171 active_tree_ = LayerTreeImpl::create(this); |
1172 if (pending_tree_) | 1172 if (pending_tree_) |
1173 pending_tree_->DetachLayerTree(); | 1173 pending_tree_->DetachLayerTree(); |
1174 pending_tree_.reset(); | 1174 pending_tree_ = nullptr; |
1175 if (recycle_tree_) | 1175 if (recycle_tree_) |
1176 recycle_tree_->DetachLayerTree(); | 1176 recycle_tree_->DetachLayerTree(); |
1177 recycle_tree_.reset(); | 1177 recycle_tree_ = nullptr; |
1178 } | 1178 } |
1179 | 1179 |
1180 void LayerTreeHostImpl::ResetRecycleTreeForTesting() { | 1180 void LayerTreeHostImpl::ResetRecycleTreeForTesting() { |
1181 if (recycle_tree_) | 1181 if (recycle_tree_) |
1182 recycle_tree_->DetachLayerTree(); | 1182 recycle_tree_->DetachLayerTree(); |
1183 recycle_tree_.reset(); | 1183 recycle_tree_ = nullptr; |
1184 } | 1184 } |
1185 | 1185 |
1186 void LayerTreeHostImpl::EnforceManagedMemoryPolicy( | 1186 void LayerTreeHostImpl::EnforceManagedMemoryPolicy( |
1187 const ManagedMemoryPolicy& policy) { | 1187 const ManagedMemoryPolicy& policy) { |
1188 | 1188 |
1189 bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread( | 1189 bool evicted_resources = client_->ReduceContentsTextureMemoryOnImplThread( |
1190 visible_ ? policy.bytes_limit_when_visible : 0, | 1190 visible_ ? policy.bytes_limit_when_visible : 0, |
1191 ManagedMemoryPolicy::PriorityCutoffToValue( | 1191 ManagedMemoryPolicy::PriorityCutoffToValue( |
1192 visible_ ? policy.priority_cutoff_when_visible | 1192 visible_ ? policy.priority_cutoff_when_visible |
1193 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING)); | 1193 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING)); |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2034 proxy_->ImplThreadTaskRunner(), | 2034 proxy_->ImplThreadTaskRunner(), |
2035 resource_pool_.get(), | 2035 resource_pool_.get(), |
2036 raster_worker_pool_->AsRasterizer(), | 2036 raster_worker_pool_->AsRasterizer(), |
2037 rendering_stats_instrumentation_); | 2037 rendering_stats_instrumentation_); |
2038 | 2038 |
2039 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); | 2039 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
2040 need_to_update_visible_tiles_before_draw_ = false; | 2040 need_to_update_visible_tiles_before_draw_ = false; |
2041 } | 2041 } |
2042 | 2042 |
2043 void LayerTreeHostImpl::DestroyTileManager() { | 2043 void LayerTreeHostImpl::DestroyTileManager() { |
2044 tile_manager_.reset(); | 2044 tile_manager_ = nullptr; |
2045 resource_pool_.reset(); | 2045 resource_pool_ = nullptr; |
2046 staging_resource_pool_.reset(); | 2046 staging_resource_pool_ = nullptr; |
2047 raster_worker_pool_.reset(); | 2047 raster_worker_pool_ = nullptr; |
2048 } | 2048 } |
2049 | 2049 |
2050 bool LayerTreeHostImpl::UsePendingTreeForSync() const { | 2050 bool LayerTreeHostImpl::UsePendingTreeForSync() const { |
2051 // In impl-side painting, synchronize to the pending tree so that it has | 2051 // In impl-side painting, synchronize to the pending tree so that it has |
2052 // time to raster before being displayed. | 2052 // time to raster before being displayed. |
2053 return settings_.impl_side_painting; | 2053 return settings_.impl_side_painting; |
2054 } | 2054 } |
2055 | 2055 |
2056 bool LayerTreeHostImpl::UseZeroCopyRasterizer() const { | 2056 bool LayerTreeHostImpl::UseZeroCopyRasterizer() const { |
2057 return settings_.use_zero_copy && GetRendererCapabilities().using_map_image; | 2057 return settings_.use_zero_copy && GetRendererCapabilities().using_map_image; |
(...skipping 12 matching lines...) Expand all Loading... |
2070 bool LayerTreeHostImpl::InitializeRenderer( | 2070 bool LayerTreeHostImpl::InitializeRenderer( |
2071 scoped_ptr<OutputSurface> output_surface) { | 2071 scoped_ptr<OutputSurface> output_surface) { |
2072 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); | 2072 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); |
2073 | 2073 |
2074 // Since we will create a new resource provider, we cannot continue to use | 2074 // Since we will create a new resource provider, we cannot continue to use |
2075 // the old resources (i.e. render_surfaces and texture IDs). Clear them | 2075 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
2076 // before we destroy the old resource provider. | 2076 // before we destroy the old resource provider. |
2077 ReleaseTreeResources(); | 2077 ReleaseTreeResources(); |
2078 | 2078 |
2079 // Note: order is important here. | 2079 // Note: order is important here. |
2080 renderer_.reset(); | 2080 renderer_ = nullptr; |
2081 DestroyTileManager(); | 2081 DestroyTileManager(); |
2082 resource_provider_.reset(); | 2082 resource_provider_ = nullptr; |
2083 output_surface_.reset(); | 2083 output_surface_ = nullptr; |
2084 | 2084 |
2085 if (!output_surface->BindToClient(this)) | 2085 if (!output_surface->BindToClient(this)) |
2086 return false; | 2086 return false; |
2087 | 2087 |
2088 output_surface_ = output_surface.Pass(); | 2088 output_surface_ = output_surface.Pass(); |
2089 resource_provider_ = | 2089 resource_provider_ = |
2090 ResourceProvider::Create(output_surface_.get(), | 2090 ResourceProvider::Create(output_surface_.get(), |
2091 shared_bitmap_manager_, | 2091 shared_bitmap_manager_, |
2092 proxy_->blocking_main_thread_task_runner(), | 2092 proxy_->blocking_main_thread_task_runner(), |
2093 settings_.highp_threshold_min, | 2093 settings_.highp_threshold_min, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 base::TimeDelta interval) { | 2135 base::TimeDelta interval) { |
2136 client_->CommitVSyncParameters(timebase, interval); | 2136 client_->CommitVSyncParameters(timebase, interval); |
2137 } | 2137 } |
2138 | 2138 |
2139 void LayerTreeHostImpl::DeferredInitialize() { | 2139 void LayerTreeHostImpl::DeferredInitialize() { |
2140 DCHECK(output_surface_->capabilities().deferred_gl_initialization); | 2140 DCHECK(output_surface_->capabilities().deferred_gl_initialization); |
2141 DCHECK(settings_.impl_side_painting); | 2141 DCHECK(settings_.impl_side_painting); |
2142 DCHECK(output_surface_->context_provider()); | 2142 DCHECK(output_surface_->context_provider()); |
2143 | 2143 |
2144 ReleaseTreeResources(); | 2144 ReleaseTreeResources(); |
2145 renderer_.reset(); | 2145 renderer_ = nullptr; |
2146 DestroyTileManager(); | 2146 DestroyTileManager(); |
2147 | 2147 |
2148 resource_provider_->InitializeGL(); | 2148 resource_provider_->InitializeGL(); |
2149 | 2149 |
2150 CreateAndSetRenderer(); | 2150 CreateAndSetRenderer(); |
2151 EnforceZeroBudget(false); | 2151 EnforceZeroBudget(false); |
2152 CreateAndSetTileManager(); | 2152 CreateAndSetTileManager(); |
2153 | 2153 |
2154 client_->SetNeedsCommitOnImplThread(); | 2154 client_->SetNeedsCommitOnImplThread(); |
2155 } | 2155 } |
2156 | 2156 |
2157 void LayerTreeHostImpl::ReleaseGL() { | 2157 void LayerTreeHostImpl::ReleaseGL() { |
2158 DCHECK(output_surface_->capabilities().deferred_gl_initialization); | 2158 DCHECK(output_surface_->capabilities().deferred_gl_initialization); |
2159 DCHECK(settings_.impl_side_painting); | 2159 DCHECK(settings_.impl_side_painting); |
2160 DCHECK(output_surface_->context_provider()); | 2160 DCHECK(output_surface_->context_provider()); |
2161 | 2161 |
2162 ReleaseTreeResources(); | 2162 ReleaseTreeResources(); |
2163 renderer_.reset(); | 2163 renderer_ = nullptr; |
2164 DestroyTileManager(); | 2164 DestroyTileManager(); |
2165 | 2165 |
2166 resource_provider_->InitializeSoftware(); | 2166 resource_provider_->InitializeSoftware(); |
2167 output_surface_->ReleaseContextProvider(); | 2167 output_surface_->ReleaseContextProvider(); |
2168 | 2168 |
2169 CreateAndSetRenderer(); | 2169 CreateAndSetRenderer(); |
2170 EnforceZeroBudget(true); | 2170 EnforceZeroBudget(true); |
2171 CreateAndSetTileManager(); | 2171 CreateAndSetTileManager(); |
2172 | 2172 |
2173 client_->SetNeedsCommitOnImplThread(); | 2173 client_->SetNeedsCommitOnImplThread(); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 } | 2421 } |
2422 | 2422 |
2423 active_tree_->SetCurrentlyScrollingLayer(layer_impl); | 2423 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
2424 | 2424 |
2425 scoped_ptr<ScrollOffsetAnimationCurve> curve = | 2425 scoped_ptr<ScrollOffsetAnimationCurve> curve = |
2426 ScrollOffsetAnimationCurve::Create(target_offset, | 2426 ScrollOffsetAnimationCurve::Create(target_offset, |
2427 EaseInOutTimingFunction::Create()); | 2427 EaseInOutTimingFunction::Create()); |
2428 curve->SetInitialValue(current_offset); | 2428 curve->SetInitialValue(current_offset); |
2429 | 2429 |
2430 scoped_ptr<Animation> animation = | 2430 scoped_ptr<Animation> animation = |
2431 Animation::Create(curve.PassAs<AnimationCurve>(), | 2431 Animation::Create(curve.Pass(), |
2432 AnimationIdProvider::NextAnimationId(), | 2432 AnimationIdProvider::NextAnimationId(), |
2433 AnimationIdProvider::NextGroupId(), | 2433 AnimationIdProvider::NextGroupId(), |
2434 Animation::ScrollOffset); | 2434 Animation::ScrollOffset); |
2435 animation->set_is_impl_only(true); | 2435 animation->set_is_impl_only(true); |
2436 | 2436 |
2437 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass()); | 2437 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass()); |
2438 | 2438 |
2439 SetNeedsAnimate(); | 2439 SetNeedsAnimate(); |
2440 return ScrollStarted; | 2440 return ScrollStarted; |
2441 } | 2441 } |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2985 active_tree_->SetPageScaleDelta( | 2985 active_tree_->SetPageScaleDelta( |
2986 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / | 2986 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / |
2987 active_tree_->page_scale_factor()); | 2987 active_tree_->page_scale_factor()); |
2988 gfx::Vector2dF next_scroll = | 2988 gfx::Vector2dF next_scroll = |
2989 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); | 2989 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); |
2990 | 2990 |
2991 ScrollViewportBy(next_scroll - scroll_total); | 2991 ScrollViewportBy(next_scroll - scroll_total); |
2992 SetNeedsRedraw(); | 2992 SetNeedsRedraw(); |
2993 | 2993 |
2994 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { | 2994 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { |
2995 page_scale_animation_.reset(); | 2995 page_scale_animation_ = nullptr; |
2996 client_->SetNeedsCommitOnImplThread(); | 2996 client_->SetNeedsCommitOnImplThread(); |
2997 client_->RenewTreePriority(); | 2997 client_->RenewTreePriority(); |
2998 } else { | 2998 } else { |
2999 SetNeedsAnimate(); | 2999 SetNeedsAnimate(); |
3000 } | 3000 } |
3001 } | 3001 } |
3002 | 3002 |
3003 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { | 3003 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { |
3004 if (!top_controls_manager_ || !top_controls_manager_->animation()) | 3004 if (!top_controls_manager_ || !top_controls_manager_->animation()) |
3005 return; | 3005 return; |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3391 } | 3391 } |
3392 | 3392 |
3393 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3393 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3394 std::vector<PictureLayerImpl*>::iterator it = | 3394 std::vector<PictureLayerImpl*>::iterator it = |
3395 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3395 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3396 DCHECK(it != picture_layers_.end()); | 3396 DCHECK(it != picture_layers_.end()); |
3397 picture_layers_.erase(it); | 3397 picture_layers_.erase(it); |
3398 } | 3398 } |
3399 | 3399 |
3400 } // namespace cc | 3400 } // namespace cc |
OLD | NEW |