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

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

Issue 2188093002: cc: Complete swap promise for aborted commit after pending activation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: post rebase fix Created 4 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
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 #include "ui/gfx/geometry/vector2d_conversions.h" 94 #include "ui/gfx/geometry/vector2d_conversions.h"
95 95
96 namespace cc { 96 namespace cc {
97 namespace { 97 namespace {
98 98
99 // Small helper class that saves the current viewport location as the user sees 99 // Small helper class that saves the current viewport location as the user sees
100 // it and resets to the same location. 100 // it and resets to the same location.
101 class ViewportAnchor { 101 class ViewportAnchor {
102 public: 102 public:
103 ViewportAnchor(LayerImpl* inner_scroll, LayerImpl* outer_scroll) 103 ViewportAnchor(LayerImpl* inner_scroll, LayerImpl* outer_scroll)
104 : inner_(inner_scroll), 104 : inner_(inner_scroll), outer_(outer_scroll) {
105 outer_(outer_scroll) {
106 viewport_in_content_coordinates_ = inner_->CurrentScrollOffset(); 105 viewport_in_content_coordinates_ = inner_->CurrentScrollOffset();
107 106
108 if (outer_) 107 if (outer_)
109 viewport_in_content_coordinates_ += outer_->CurrentScrollOffset(); 108 viewport_in_content_coordinates_ += outer_->CurrentScrollOffset();
110 } 109 }
111 110
112 void ResetViewportToAnchoredPosition() { 111 void ResetViewportToAnchoredPosition() {
113 DCHECK(outer_); 112 DCHECK(outer_);
114 113
115 inner_->ClampScrollToMaxScrollOffset(); 114 inner_->ClampScrollToMaxScrollOffset();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 SetDebugState(settings.initial_debug_state); 254 SetDebugState(settings.initial_debug_state);
256 255
257 // LTHI always has an active tree. 256 // LTHI always has an active tree.
258 active_tree_ = base::MakeUnique<LayerTreeImpl>( 257 active_tree_ = base::MakeUnique<LayerTreeImpl>(
259 this, new SyncedProperty<ScaleGroup>, new SyncedTopControls, 258 this, new SyncedProperty<ScaleGroup>, new SyncedTopControls,
260 new SyncedElasticOverscroll); 259 new SyncedElasticOverscroll);
261 active_tree_->property_trees()->is_active = true; 260 active_tree_->property_trees()->is_active = true;
262 261
263 viewport_ = Viewport::Create(this); 262 viewport_ = Viewport::Create(this);
264 263
265 TRACE_EVENT_OBJECT_CREATED_WITH_ID( 264 TRACE_EVENT_OBJECT_CREATED_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
266 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); 265 "cc::LayerTreeHostImpl", id_);
267 266
268 top_controls_manager_ = 267 top_controls_manager_ =
269 TopControlsManager::Create(this, 268 TopControlsManager::Create(this, settings.top_controls_show_threshold,
270 settings.top_controls_show_threshold,
271 settings.top_controls_hide_threshold); 269 settings.top_controls_hide_threshold);
272 } 270 }
273 271
274 LayerTreeHostImpl::~LayerTreeHostImpl() { 272 LayerTreeHostImpl::~LayerTreeHostImpl() {
275 DCHECK(task_runner_provider_->IsImplThread()); 273 DCHECK(task_runner_provider_->IsImplThread());
276 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); 274 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()");
277 TRACE_EVENT_OBJECT_DELETED_WITH_ID( 275 TRACE_EVENT_OBJECT_DELETED_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
278 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); 276 "cc::LayerTreeHostImpl", id_);
279 277
280 // It is released before shutdown. 278 // It is released before shutdown.
281 DCHECK(!output_surface_); 279 DCHECK(!output_surface_);
282 280
283 DCHECK(!renderer_); 281 DCHECK(!renderer_);
284 DCHECK(!resource_provider_); 282 DCHECK(!resource_provider_);
285 DCHECK(!resource_pool_); 283 DCHECK(!resource_pool_);
286 DCHECK(!tile_task_manager_); 284 DCHECK(!tile_task_manager_);
287 DCHECK(!single_thread_synchronous_task_graph_runner_); 285 DCHECK(!single_thread_synchronous_task_graph_runner_);
288 DCHECK(!image_decode_controller_); 286 DCHECK(!image_decode_controller_);
(...skipping 14 matching lines...) Expand all
303 pending_tree_->Shutdown(); 301 pending_tree_->Shutdown();
304 active_tree_->Shutdown(); 302 active_tree_->Shutdown();
305 recycle_tree_ = nullptr; 303 recycle_tree_ = nullptr;
306 pending_tree_ = nullptr; 304 pending_tree_ = nullptr;
307 active_tree_ = nullptr; 305 active_tree_ = nullptr;
308 306
309 animation_host_->ClearTimelines(); 307 animation_host_->ClearTimelines();
310 animation_host_->SetMutatorHostClient(nullptr); 308 animation_host_->SetMutatorHostClient(nullptr);
311 } 309 }
312 310
313 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { 311 void LayerTreeHostImpl::BeginMainFrameAborted(
312 CommitEarlyOutReason reason,
313 std::vector<std::unique_ptr<SwapPromise>> swap_promises) {
314 // If the begin frame data was handled, then scroll and scale set was applied 314 // If the begin frame data was handled, then scroll and scale set was applied
315 // by the main thread, so the active tree needs to be updated as if these sent 315 // by the main thread, so the active tree needs to be updated as if these sent
316 // values were applied and committed. 316 // values were applied and committed.
317 if (CommitEarlyOutHandledCommit(reason)) 317 if (CommitEarlyOutHandledCommit(reason)) {
318 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); 318 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit();
319 if (pending_tree_) {
320 pending_tree_->AppendSwapPromises(std::move(swap_promises));
321 } else {
322 for (const auto& swap_promise : swap_promises)
323 swap_promise->DidNotSwap(SwapPromise::COMMIT_NO_UPDATE);
324 }
325 }
319 } 326 }
320 327
321 void LayerTreeHostImpl::BeginCommit() { 328 void LayerTreeHostImpl::BeginCommit() {
322 TRACE_EVENT0("cc", "LayerTreeHostImpl::BeginCommit"); 329 TRACE_EVENT0("cc", "LayerTreeHostImpl::BeginCommit");
323 330
324 // Ensure all textures are returned so partial texture updates can happen 331 // Ensure all textures are returned so partial texture updates can happen
325 // during the commit. 332 // during the commit.
326 // TODO(ericrk): We should not need to ForceReclaimResources when using 333 // TODO(ericrk): We should not need to ForceReclaimResources when using
327 // Impl-side-painting as it doesn't upload during commits. However, 334 // Impl-side-painting as it doesn't upload during commits. However,
328 // Display::Draw currently relies on resource being reclaimed to block drawing 335 // Display::Draw currently relies on resource being reclaimed to block drawing
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 gfx::SizeF(active_tree_->InnerViewportContainerLayer()->bounds()); 526 gfx::SizeF(active_tree_->InnerViewportContainerLayer()->bounds());
520 527
521 // TODO(miletus) : Pass in ScrollOffset. 528 // TODO(miletus) : Pass in ScrollOffset.
522 page_scale_animation_ = 529 page_scale_animation_ =
523 PageScaleAnimation::Create(ScrollOffsetToVector2dF(scroll_total), 530 PageScaleAnimation::Create(ScrollOffsetToVector2dF(scroll_total),
524 active_tree_->current_page_scale_factor(), 531 active_tree_->current_page_scale_factor(),
525 viewport_size, scaled_scrollable_size); 532 viewport_size, scaled_scrollable_size);
526 533
527 if (anchor_point) { 534 if (anchor_point) {
528 gfx::Vector2dF anchor(target_offset); 535 gfx::Vector2dF anchor(target_offset);
529 page_scale_animation_->ZoomWithAnchor(anchor, 536 page_scale_animation_->ZoomWithAnchor(anchor, page_scale,
530 page_scale,
531 duration.InSecondsF()); 537 duration.InSecondsF());
532 } else { 538 } else {
533 gfx::Vector2dF scaled_target_offset = target_offset; 539 gfx::Vector2dF scaled_target_offset = target_offset;
534 page_scale_animation_->ZoomTo(scaled_target_offset, 540 page_scale_animation_->ZoomTo(scaled_target_offset, page_scale,
535 page_scale,
536 duration.InSecondsF()); 541 duration.InSecondsF());
537 } 542 }
538 543
539 SetNeedsOneBeginImplFrame(); 544 SetNeedsOneBeginImplFrame();
540 client_->SetNeedsCommitOnImplThread(); 545 client_->SetNeedsCommitOnImplThread();
541 client_->RenewTreePriority(); 546 client_->RenewTreePriority();
542 } 547 }
543 548
544 void LayerTreeHostImpl::SetNeedsAnimateInput() { 549 void LayerTreeHostImpl::SetNeedsAnimateInput() {
545 DCHECK(!IsCurrentlyScrollingInnerViewport() || 550 DCHECK(!IsCurrentlyScrollingInnerViewport() ||
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 // Manually create the quad state for the gutter quads, as the root layer 744 // Manually create the quad state for the gutter quads, as the root layer
740 // doesn't have any bounds and so can't generate this itself. 745 // doesn't have any bounds and so can't generate this itself.
741 // TODO(danakj): Make the gutter quads generated by the solid color layer 746 // TODO(danakj): Make the gutter quads generated by the solid color layer
742 // (make it smarter about generating quads to fill unoccluded areas). 747 // (make it smarter about generating quads to fill unoccluded areas).
743 748
744 gfx::Rect root_target_rect = root_render_surface->content_rect(); 749 gfx::Rect root_target_rect = root_render_surface->content_rect();
745 float opacity = 1.f; 750 float opacity = 1.f;
746 int sorting_context_id = 0; 751 int sorting_context_id = 0;
747 SharedQuadState* shared_quad_state = 752 SharedQuadState* shared_quad_state =
748 target_render_pass->CreateAndAppendSharedQuadState(); 753 target_render_pass->CreateAndAppendSharedQuadState();
749 shared_quad_state->SetAll(gfx::Transform(), 754 shared_quad_state->SetAll(gfx::Transform(), root_target_rect.size(),
750 root_target_rect.size(), 755 root_target_rect, root_target_rect, false, opacity,
751 root_target_rect, 756 SkXfermode::kSrcOver_Mode, sorting_context_id);
752 root_target_rect,
753 false,
754 opacity,
755 SkXfermode::kSrcOver_Mode,
756 sorting_context_id);
757 757
758 for (Region::Iterator fill_rects(fill_region); fill_rects.has_rect(); 758 for (Region::Iterator fill_rects(fill_region); fill_rects.has_rect();
759 fill_rects.next()) { 759 fill_rects.next()) {
760 gfx::Rect screen_space_rect = fill_rects.rect(); 760 gfx::Rect screen_space_rect = fill_rects.rect();
761 gfx::Rect visible_screen_space_rect = screen_space_rect; 761 gfx::Rect visible_screen_space_rect = screen_space_rect;
762 // Skip the quad culler and just append the quads directly to avoid 762 // Skip the quad culler and just append the quads directly to avoid
763 // occlusion checks. 763 // occlusion checks.
764 SolidColorDrawQuad* quad = 764 SolidColorDrawQuad* quad =
765 target_render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); 765 target_render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
766 quad->SetNew(shared_quad_state, 766 quad->SetNew(shared_quad_state, screen_space_rect,
767 screen_space_rect, 767 visible_screen_space_rect, screen_background_color, false);
768 visible_screen_space_rect,
769 screen_background_color,
770 false);
771 } 768 }
772 } 769 }
773 770
774 static RenderPass* FindRenderPassById(const RenderPassList& list, 771 static RenderPass* FindRenderPassById(const RenderPassList& list,
775 RenderPassId id) { 772 RenderPassId id) {
776 auto it = std::find_if( 773 auto it = std::find_if(
777 list.begin(), list.end(), 774 list.begin(), list.end(),
778 [id](const std::unique_ptr<RenderPass>& p) { return p->id == id; }); 775 [id](const std::unique_ptr<RenderPass>& p) { return p->id == id; });
779 return it == list.end() ? nullptr : it->get(); 776 return it == list.end() ? nullptr : it->get();
780 } 777 }
781 778
782 DrawResult LayerTreeHostImpl::CalculateRenderPasses( 779 DrawResult LayerTreeHostImpl::CalculateRenderPasses(FrameData* frame) {
783 FrameData* frame) {
784 DCHECK(frame->render_passes.empty()); 780 DCHECK(frame->render_passes.empty());
785 DCHECK(CanDraw()); 781 DCHECK(CanDraw());
786 DCHECK(!active_tree_->LayerListIsEmpty()); 782 DCHECK(!active_tree_->LayerListIsEmpty());
787 783
788 TrackDamageForAllSurfaces(*frame->render_surface_layer_list); 784 TrackDamageForAllSurfaces(*frame->render_surface_layer_list);
789 785
790 // If the root render surface has no visible damage, then don't generate a 786 // If the root render surface has no visible damage, then don't generate a
791 // frame at all. 787 // frame at all.
792 RenderSurfaceImpl* root_surface = active_tree_->RootRenderSurface(); 788 RenderSurfaceImpl* root_surface = active_tree_->RootRenderSurface();
793 bool root_surface_has_no_visible_damage = 789 bool root_surface_has_no_visible_damage =
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 ->effect_tree.TakeCopyRequestsAndTransformToSurface( 892 ->effect_tree.TakeCopyRequestsAndTransformToSurface(
897 it->render_surface()->EffectTreeIndex(), 893 it->render_surface()->EffectTreeIndex(),
898 &target_render_pass->copy_requests); 894 &target_render_pass->copy_requests);
899 } 895 }
900 } else if (it.represents_contributing_render_surface() && 896 } else if (it.represents_contributing_render_surface() &&
901 it->render_surface()->contributes_to_drawn_surface()) { 897 it->render_surface()->contributes_to_drawn_surface()) {
902 RenderPassId contributing_render_pass_id = 898 RenderPassId contributing_render_pass_id =
903 it->render_surface()->GetRenderPassId(); 899 it->render_surface()->GetRenderPassId();
904 RenderPass* contributing_render_pass = 900 RenderPass* contributing_render_pass =
905 FindRenderPassById(frame->render_passes, contributing_render_pass_id); 901 FindRenderPassById(frame->render_passes, contributing_render_pass_id);
906 AppendQuadsForRenderSurfaceLayer(target_render_pass, 902 AppendQuadsForRenderSurfaceLayer(target_render_pass, *it,
907 *it,
908 contributing_render_pass, 903 contributing_render_pass,
909 &append_quads_data); 904 &append_quads_data);
910 } else if (it.represents_itself() && !it->visible_layer_rect().IsEmpty()) { 905 } else if (it.represents_itself() && !it->visible_layer_rect().IsEmpty()) {
911 bool occluded = 906 bool occluded =
912 it->draw_properties().occlusion_in_content_space.IsOccluded( 907 it->draw_properties().occlusion_in_content_space.IsOccluded(
913 it->visible_layer_rect()); 908 it->visible_layer_rect());
914 if (!occluded && it->WillDraw(draw_mode, resource_provider_.get())) { 909 if (!occluded && it->WillDraw(draw_mode, resource_provider_.get())) {
915 DCHECK_EQ(active_tree_.get(), it->layer_tree_impl()); 910 DCHECK_EQ(active_tree_.get(), it->layer_tree_impl());
916 911
917 frame->will_draw_layers.push_back(*it); 912 frame->will_draw_layers.push_back(*it);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 void LayerTreeHostImpl::DidAnimateScrollOffset() { 1054 void LayerTreeHostImpl::DidAnimateScrollOffset() {
1060 client_->SetNeedsCommitOnImplThread(); 1055 client_->SetNeedsCommitOnImplThread();
1061 client_->RenewTreePriority(); 1056 client_->RenewTreePriority();
1062 } 1057 }
1063 1058
1064 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { 1059 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) {
1065 viewport_damage_rect_.Union(damage_rect); 1060 viewport_damage_rect_.Union(damage_rect);
1066 } 1061 }
1067 1062
1068 DrawResult LayerTreeHostImpl::PrepareToDraw(FrameData* frame) { 1063 DrawResult LayerTreeHostImpl::PrepareToDraw(FrameData* frame) {
1069 TRACE_EVENT1("cc", 1064 TRACE_EVENT1("cc", "LayerTreeHostImpl::PrepareToDraw", "SourceFrameNumber",
1070 "LayerTreeHostImpl::PrepareToDraw",
1071 "SourceFrameNumber",
1072 active_tree_->source_frame_number()); 1065 active_tree_->source_frame_number());
1073 if (input_handler_client_) 1066 if (input_handler_client_)
1074 input_handler_client_->ReconcileElasticOverscrollAndRootScroll(); 1067 input_handler_client_->ReconcileElasticOverscrollAndRootScroll();
1075 1068
1076 if (const char* client_name = GetClientNameForMetrics()) { 1069 if (const char* client_name = GetClientNameForMetrics()) {
1077 size_t total_picture_memory = 0; 1070 size_t total_picture_memory = 0;
1078 for (const PictureLayerImpl* layer : active_tree()->picture_layers()) 1071 for (const PictureLayerImpl* layer : active_tree()->picture_layers())
1079 total_picture_memory += layer->GetRasterSource()->GetPictureMemoryUsage(); 1072 total_picture_memory += layer->GetRasterSource()->GetPictureMemoryUsage();
1080 if (total_picture_memory != 0) { 1073 if (total_picture_memory != 0) {
1081 // GetClientNameForMetrics only returns one non-null value over the 1074 // GetClientNameForMetrics only returns one non-null value over the
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 if (visible_ && policy.bytes_limit_when_visible > 0) { 1233 if (visible_ && policy.bytes_limit_when_visible > 0) {
1241 global_tile_state_.hard_memory_limit_in_bytes = 1234 global_tile_state_.hard_memory_limit_in_bytes =
1242 policy.bytes_limit_when_visible; 1235 policy.bytes_limit_when_visible;
1243 global_tile_state_.soft_memory_limit_in_bytes = 1236 global_tile_state_.soft_memory_limit_in_bytes =
1244 (static_cast<int64_t>(global_tile_state_.hard_memory_limit_in_bytes) * 1237 (static_cast<int64_t>(global_tile_state_.hard_memory_limit_in_bytes) *
1245 settings_.max_memory_for_prepaint_percentage) / 1238 settings_.max_memory_for_prepaint_percentage) /
1246 100; 1239 100;
1247 } 1240 }
1248 global_tile_state_.memory_limit_policy = 1241 global_tile_state_.memory_limit_policy =
1249 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( 1242 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy(
1250 visible_ ? 1243 visible_ ? policy.priority_cutoff_when_visible
1251 policy.priority_cutoff_when_visible : 1244 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING);
1252 gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING);
1253 global_tile_state_.num_resources_limit = policy.num_resources_limit; 1245 global_tile_state_.num_resources_limit = policy.num_resources_limit;
1254 1246
1255 if (global_tile_state_.hard_memory_limit_in_bytes > 0) { 1247 if (global_tile_state_.hard_memory_limit_in_bytes > 0) {
1256 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we 1248 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we
1257 // allow the worker context and image decode controller to retain allocated 1249 // allow the worker context and image decode controller to retain allocated
1258 // resources. Notify them here. If the memory policy has become zero, we'll 1250 // resources. Notify them here. If the memory policy has become zero, we'll
1259 // handle the notification in NotifyAllTileTasksCompleted, after 1251 // handle the notification in NotifyAllTileTasksCompleted, after
1260 // in-progress work finishes. 1252 // in-progress work finishes.
1261 if (output_surface_) { 1253 if (output_surface_) {
1262 output_surface_->SetWorkerContextShouldAggressivelyFreeResources( 1254 output_surface_->SetWorkerContextShouldAggressivelyFreeResources(
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 } 1596 }
1605 if (!InnerViewportScrollLayer()) 1597 if (!InnerViewportScrollLayer())
1606 return metadata; 1598 return metadata;
1607 1599
1608 metadata.root_overflow_x_hidden |= 1600 metadata.root_overflow_x_hidden |=
1609 !InnerViewportScrollLayer()->user_scrollable_horizontal(); 1601 !InnerViewportScrollLayer()->user_scrollable_horizontal();
1610 metadata.root_overflow_y_hidden |= 1602 metadata.root_overflow_y_hidden |=
1611 !InnerViewportScrollLayer()->user_scrollable_vertical(); 1603 !InnerViewportScrollLayer()->user_scrollable_vertical();
1612 1604
1613 // TODO(miletus) : Change the metadata to hold ScrollOffset. 1605 // TODO(miletus) : Change the metadata to hold ScrollOffset.
1614 metadata.root_scroll_offset = gfx::ScrollOffsetToVector2dF( 1606 metadata.root_scroll_offset =
1615 active_tree_->TotalScrollOffset()); 1607 gfx::ScrollOffsetToVector2dF(active_tree_->TotalScrollOffset());
1616 1608
1617 return metadata; 1609 return metadata;
1618 } 1610 }
1619 1611
1620 void LayerTreeHostImpl::DrawLayers(FrameData* frame) { 1612 void LayerTreeHostImpl::DrawLayers(FrameData* frame) {
1621 TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers"); 1613 TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers");
1622 1614
1623 base::TimeTicks frame_begin_time = CurrentBeginFrameArgs().frame_time; 1615 base::TimeTicks frame_begin_time = CurrentBeginFrameArgs().frame_time;
1624 DCHECK(CanDraw()); 1616 DCHECK(CanDraw());
1625 1617
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 active_tree_->device_scale_factor(), gfx::ColorSpace(), 1668 active_tree_->device_scale_factor(), gfx::ColorSpace(),
1677 DeviceViewport(), DeviceViewport()); 1669 DeviceViewport(), DeviceViewport());
1678 // The render passes should be consumed by the renderer. 1670 // The render passes should be consumed by the renderer.
1679 DCHECK(frame->render_passes.empty()); 1671 DCHECK(frame->render_passes.empty());
1680 1672
1681 // The next frame should start by assuming nothing has changed, and changes 1673 // The next frame should start by assuming nothing has changed, and changes
1682 // are noted as they occur. 1674 // are noted as they occur.
1683 // TODO(boliu): If we did a temporary software renderer frame, propogate the 1675 // TODO(boliu): If we did a temporary software renderer frame, propogate the
1684 // damage forward to the next frame. 1676 // damage forward to the next frame.
1685 for (size_t i = 0; i < frame->render_surface_layer_list->size(); i++) { 1677 for (size_t i = 0; i < frame->render_surface_layer_list->size(); i++) {
1686 (*frame->render_surface_layer_list)[i]->render_surface()->damage_tracker()-> 1678 (*frame->render_surface_layer_list)[i]
1687 DidDrawDamagedArea(); 1679 ->render_surface()
1680 ->damage_tracker()
1681 ->DidDrawDamagedArea();
1688 } 1682 }
1689 active_tree_->ResetAllChangeTracking(); 1683 active_tree_->ResetAllChangeTracking();
1690 1684
1691 active_tree_->set_has_ever_been_drawn(true); 1685 active_tree_->set_has_ever_been_drawn(true);
1692 devtools_instrumentation::DidDrawFrame(id_); 1686 devtools_instrumentation::DidDrawFrame(id_);
1693 benchmark_instrumentation::IssueImplThreadRenderingStatsEvent( 1687 benchmark_instrumentation::IssueImplThreadRenderingStatsEvent(
1694 rendering_stats_instrumentation_->impl_thread_rendering_stats()); 1688 rendering_stats_instrumentation_->impl_thread_rendering_stats());
1695 rendering_stats_instrumentation_->AccumulateAndClearImplThreadStats(); 1689 rendering_stats_instrumentation_->AccumulateAndClearImplThreadStats();
1696 } 1690 }
1697 1691
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 1795
1802 // We have released tilings for both active and pending tree. 1796 // We have released tilings for both active and pending tree.
1803 // We would not have any content to draw until the pending tree is activated. 1797 // We would not have any content to draw until the pending tree is activated.
1804 // Prevent the active tree from drawing until activation. 1798 // Prevent the active tree from drawing until activation.
1805 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. 1799 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw.
1806 SetRequiresHighResToDraw(); 1800 SetRequiresHighResToDraw();
1807 1801
1808 tree_resources_for_gpu_rasterization_dirty_ = false; 1802 tree_resources_for_gpu_rasterization_dirty_ = false;
1809 } 1803 }
1810 1804
1811 const RendererCapabilitiesImpl& 1805 const RendererCapabilitiesImpl& LayerTreeHostImpl::GetRendererCapabilities()
1812 LayerTreeHostImpl::GetRendererCapabilities() const { 1806 const {
1813 CHECK(renderer_); 1807 CHECK(renderer_);
1814 return renderer_->Capabilities(); 1808 return renderer_->Capabilities();
1815 } 1809 }
1816 1810
1817 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { 1811 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) {
1818 ResetRequiresHighResToDraw(); 1812 ResetRequiresHighResToDraw();
1819 if (frame.has_no_damage) { 1813 if (frame.has_no_damage) {
1820 active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS); 1814 active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS);
1821 return false; 1815 return false;
1822 } 1816 }
1823 CompositorFrameMetadata metadata = MakeCompositorFrameMetadata(); 1817 CompositorFrameMetadata metadata = MakeCompositorFrameMetadata();
1824 metadata.may_contain_video = frame.may_contain_video; 1818 metadata.may_contain_video = frame.may_contain_video;
1825 active_tree()->FinishSwapPromises(&metadata); 1819 active_tree()->FinishSwapPromises(&metadata);
1826 for (auto& latency : metadata.latency_info) { 1820 for (auto& latency : metadata.latency_info) {
1827 TRACE_EVENT_WITH_FLOW1("input,benchmark", 1821 TRACE_EVENT_WITH_FLOW1("input,benchmark", "LatencyInfo.Flow",
1828 "LatencyInfo.Flow",
1829 TRACE_ID_DONT_MANGLE(latency.trace_id()), 1822 TRACE_ID_DONT_MANGLE(latency.trace_id()),
1830 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, 1823 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
1831 "step", "SwapBuffers"); 1824 "step", "SwapBuffers");
1832 // Only add the latency component once for renderer swap, not the browser 1825 // Only add the latency component once for renderer swap, not the browser
1833 // swap. 1826 // swap.
1834 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, 1827 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, 0,
1835 0, nullptr)) { 1828 nullptr)) {
1836 latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, 1829 latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT,
1837 0, 0); 1830 0, 0);
1838 } 1831 }
1839 } 1832 }
1840 renderer_->SwapBuffers(std::move(metadata)); 1833 renderer_->SwapBuffers(std::move(metadata));
1841 return true; 1834 return true;
1842 } 1835 }
1843 1836
1844 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { 1837 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) {
1845 current_begin_frame_tracker_.Start(args); 1838 current_begin_frame_tracker_.Start(args);
(...skipping 15 matching lines...) Expand all
1861 current_begin_frame_tracker_.Finish(); 1854 current_begin_frame_tracker_.Finish();
1862 } 1855 }
1863 1856
1864 void LayerTreeHostImpl::UpdateViewportContainerSizes() { 1857 void LayerTreeHostImpl::UpdateViewportContainerSizes() {
1865 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer(); 1858 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer();
1866 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); 1859 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer();
1867 1860
1868 if (!inner_container) 1861 if (!inner_container)
1869 return; 1862 return;
1870 1863
1871 ViewportAnchor anchor(InnerViewportScrollLayer(), 1864 ViewportAnchor anchor(InnerViewportScrollLayer(), OuterViewportScrollLayer());
1872 OuterViewportScrollLayer());
1873 1865
1874 float top_controls_layout_height = 1866 float top_controls_layout_height =
1875 active_tree_->top_controls_shrink_blink_size() 1867 active_tree_->top_controls_shrink_blink_size()
1876 ? active_tree_->top_controls_height() 1868 ? active_tree_->top_controls_height()
1877 : 0.f; 1869 : 0.f;
1878 float delta_from_top_controls = 1870 float delta_from_top_controls =
1879 top_controls_layout_height - top_controls_manager_->ContentTopOffset(); 1871 top_controls_layout_height - top_controls_manager_->ContentTopOffset();
1880 1872
1881 // Adjust the viewport layers by shrinking/expanding the container to account 1873 // Adjust the viewport layers by shrinking/expanding the container to account
1882 // for changes in the size (e.g. top controls) since the last resize from 1874 // for changes in the size (e.g. top controls) since the last resize from
1883 // Blink. 1875 // Blink.
1884 gfx::Vector2dF amount_to_expand( 1876 gfx::Vector2dF amount_to_expand(0.f, delta_from_top_controls);
1885 0.f,
1886 delta_from_top_controls);
1887 inner_container->SetBoundsDelta(amount_to_expand); 1877 inner_container->SetBoundsDelta(amount_to_expand);
1888 1878
1889 if (outer_container && !outer_container->BoundsForScrolling().IsEmpty()) { 1879 if (outer_container && !outer_container->BoundsForScrolling().IsEmpty()) {
1890 // Adjust the outer viewport container as well, since adjusting only the 1880 // Adjust the outer viewport container as well, since adjusting only the
1891 // inner may cause its bounds to exceed those of the outer, causing scroll 1881 // inner may cause its bounds to exceed those of the outer, causing scroll
1892 // clamping. 1882 // clamping.
1893 gfx::Vector2dF amount_to_expand_scaled = gfx::ScaleVector2d( 1883 gfx::Vector2dF amount_to_expand_scaled = gfx::ScaleVector2d(
1894 amount_to_expand, 1.f / active_tree_->min_page_scale_factor()); 1884 amount_to_expand, 1.f / active_tree_->min_page_scale_factor());
1895 outer_container->SetBoundsDelta(amount_to_expand_scaled); 1885 outer_container->SetBoundsDelta(amount_to_expand_scaled);
1896 active_tree_->InnerViewportScrollLayer()->SetBoundsDelta( 1886 active_tree_->InnerViewportScrollLayer()->SetBoundsDelta(
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 DidModifyTilePriorities(); 2011 DidModifyTilePriorities();
2022 2012
2023 client_->OnCanDrawStateChanged(CanDraw()); 2013 client_->OnCanDrawStateChanged(CanDraw());
2024 client_->DidActivateSyncTree(); 2014 client_->DidActivateSyncTree();
2025 if (!tree_activation_callback_.is_null()) 2015 if (!tree_activation_callback_.is_null())
2026 tree_activation_callback_.Run(); 2016 tree_activation_callback_.Run();
2027 2017
2028 std::unique_ptr<PendingPageScaleAnimation> pending_page_scale_animation = 2018 std::unique_ptr<PendingPageScaleAnimation> pending_page_scale_animation =
2029 active_tree_->TakePendingPageScaleAnimation(); 2019 active_tree_->TakePendingPageScaleAnimation();
2030 if (pending_page_scale_animation) { 2020 if (pending_page_scale_animation) {
2031 StartPageScaleAnimation( 2021 StartPageScaleAnimation(pending_page_scale_animation->target_offset,
2032 pending_page_scale_animation->target_offset, 2022 pending_page_scale_animation->use_anchor,
2033 pending_page_scale_animation->use_anchor, 2023 pending_page_scale_animation->scale,
2034 pending_page_scale_animation->scale, 2024 pending_page_scale_animation->duration);
2035 pending_page_scale_animation->duration);
2036 } 2025 }
2037 // Activation can change the root scroll offset, so inform the synchronous 2026 // Activation can change the root scroll offset, so inform the synchronous
2038 // input handler. 2027 // input handler.
2039 UpdateRootLayerStateForSynchronousInputHandler(); 2028 UpdateRootLayerStateForSynchronousInputHandler();
2040 } 2029 }
2041 2030
2042 void LayerTreeHostImpl::SetVisible(bool visible) { 2031 void LayerTreeHostImpl::SetVisible(bool visible) {
2043 DCHECK(task_runner_provider_->IsImplThread()); 2032 DCHECK(task_runner_provider_->IsImplThread());
2044 2033
2045 if (visible_ == visible) 2034 if (visible_ == visible)
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 gfx::PointF screen_space_point = 2875 gfx::PointF screen_space_point =
2887 gfx::ScalePoint(viewport_point, scale_from_viewport_to_screen_space); 2876 gfx::ScalePoint(viewport_point, scale_from_viewport_to_screen_space);
2888 2877
2889 gfx::Vector2dF screen_space_delta = viewport_delta; 2878 gfx::Vector2dF screen_space_delta = viewport_delta;
2890 screen_space_delta.Scale(scale_from_viewport_to_screen_space); 2879 screen_space_delta.Scale(scale_from_viewport_to_screen_space);
2891 2880
2892 // First project the scroll start and end points to local layer space to find 2881 // First project the scroll start and end points to local layer space to find
2893 // the scroll delta in layer coordinates. 2882 // the scroll delta in layer coordinates.
2894 bool start_clipped, end_clipped; 2883 bool start_clipped, end_clipped;
2895 gfx::PointF screen_space_end_point = screen_space_point + screen_space_delta; 2884 gfx::PointF screen_space_end_point = screen_space_point + screen_space_delta;
2896 gfx::PointF local_start_point = 2885 gfx::PointF local_start_point = MathUtil::ProjectPoint(
2897 MathUtil::ProjectPoint(inverse_screen_space_transform, 2886 inverse_screen_space_transform, screen_space_point, &start_clipped);
2898 screen_space_point, 2887 gfx::PointF local_end_point = MathUtil::ProjectPoint(
2899 &start_clipped); 2888 inverse_screen_space_transform, screen_space_end_point, &end_clipped);
2900 gfx::PointF local_end_point =
2901 MathUtil::ProjectPoint(inverse_screen_space_transform,
2902 screen_space_end_point,
2903 &end_clipped);
2904 2889
2905 // In general scroll point coordinates should not get clipped. 2890 // In general scroll point coordinates should not get clipped.
2906 DCHECK(!start_clipped); 2891 DCHECK(!start_clipped);
2907 DCHECK(!end_clipped); 2892 DCHECK(!end_clipped);
2908 if (start_clipped || end_clipped) 2893 if (start_clipped || end_clipped)
2909 return gfx::Vector2dF(); 2894 return gfx::Vector2dF();
2910 2895
2911 // Apply the scroll delta. 2896 // Apply the scroll delta.
2912 gfx::ScrollOffset previous_offset = 2897 gfx::ScrollOffset previous_offset =
2913 scroll_tree->current_scroll_offset(scroll_node->owner_id); 2898 scroll_tree->current_scroll_offset(scroll_node->owner_id);
2914 scroll_tree->ScrollBy(scroll_node, local_end_point - local_start_point, 2899 scroll_tree->ScrollBy(scroll_node, local_end_point - local_start_point,
2915 active_tree()); 2900 active_tree());
2916 gfx::ScrollOffset scrolled = 2901 gfx::ScrollOffset scrolled =
2917 scroll_tree->current_scroll_offset(scroll_node->owner_id) - 2902 scroll_tree->current_scroll_offset(scroll_node->owner_id) -
2918 previous_offset; 2903 previous_offset;
2919 2904
2920 // Get the end point in the layer's content space so we can apply its 2905 // Get the end point in the layer's content space so we can apply its
2921 // ScreenSpaceTransform. 2906 // ScreenSpaceTransform.
2922 gfx::PointF actual_local_end_point = 2907 gfx::PointF actual_local_end_point =
2923 local_start_point + gfx::Vector2dF(scrolled.x(), scrolled.y()); 2908 local_start_point + gfx::Vector2dF(scrolled.x(), scrolled.y());
2924 2909
2925 // Calculate the applied scroll delta in viewport space coordinates. 2910 // Calculate the applied scroll delta in viewport space coordinates.
2926 gfx::PointF actual_screen_space_end_point = MathUtil::MapPoint( 2911 gfx::PointF actual_screen_space_end_point = MathUtil::MapPoint(
2927 screen_space_transform, actual_local_end_point, &end_clipped); 2912 screen_space_transform, actual_local_end_point, &end_clipped);
2928 DCHECK(!end_clipped); 2913 DCHECK(!end_clipped);
2929 if (end_clipped) 2914 if (end_clipped)
2930 return gfx::Vector2dF(); 2915 return gfx::Vector2dF();
2931 gfx::PointF actual_viewport_end_point = 2916 gfx::PointF actual_viewport_end_point = gfx::ScalePoint(
2932 gfx::ScalePoint(actual_screen_space_end_point, 2917 actual_screen_space_end_point, 1.f / scale_from_viewport_to_screen_space);
2933 1.f / scale_from_viewport_to_screen_space);
2934 return actual_viewport_end_point - viewport_point; 2918 return actual_viewport_end_point - viewport_point;
2935 } 2919 }
2936 2920
2937 static gfx::Vector2dF ScrollNodeWithLocalDelta( 2921 static gfx::Vector2dF ScrollNodeWithLocalDelta(
2938 ScrollNode* scroll_node, 2922 ScrollNode* scroll_node,
2939 const gfx::Vector2dF& local_delta, 2923 const gfx::Vector2dF& local_delta,
2940 float page_scale_factor, 2924 float page_scale_factor,
2941 LayerTreeImpl* layer_tree_impl) { 2925 LayerTreeImpl* layer_tree_impl) {
2942 ScrollTree& scroll_tree = layer_tree_impl->property_trees()->scroll_tree; 2926 ScrollTree& scroll_tree = layer_tree_impl->property_trees()->scroll_tree;
2943 gfx::ScrollOffset previous_offset = 2927 gfx::ScrollOffset previous_offset =
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
3715 ResourceId id = ResourceIdForUIResource(uid); 3699 ResourceId id = ResourceIdForUIResource(uid);
3716 if (id) { 3700 if (id) {
3717 resource_provider_->DeleteResource(id); 3701 resource_provider_->DeleteResource(id);
3718 ui_resource_map_.erase(uid); 3702 ui_resource_map_.erase(uid);
3719 } 3703 }
3720 MarkUIResourceNotEvicted(uid); 3704 MarkUIResourceNotEvicted(uid);
3721 } 3705 }
3722 3706
3723 void LayerTreeHostImpl::ClearUIResources() { 3707 void LayerTreeHostImpl::ClearUIResources() {
3724 for (UIResourceMap::const_iterator iter = ui_resource_map_.begin(); 3708 for (UIResourceMap::const_iterator iter = ui_resource_map_.begin();
3725 iter != ui_resource_map_.end(); 3709 iter != ui_resource_map_.end(); ++iter) {
3726 ++iter) {
3727 evicted_ui_resources_.insert(iter->first); 3710 evicted_ui_resources_.insert(iter->first);
3728 resource_provider_->DeleteResource(iter->second.resource_id); 3711 resource_provider_->DeleteResource(iter->second.resource_id);
3729 } 3712 }
3730 ui_resource_map_.clear(); 3713 ui_resource_map_.clear();
3731 } 3714 }
3732 3715
3733 void LayerTreeHostImpl::EvictAllUIResources() { 3716 void LayerTreeHostImpl::EvictAllUIResources() {
3734 if (ui_resource_map_.empty()) 3717 if (ui_resource_map_.empty())
3735 return; 3718 return;
3736 ClearUIResources(); 3719 ClearUIResources();
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
4043 return task_runner_provider_->HasImplThread(); 4026 return task_runner_provider_->HasImplThread();
4044 } 4027 }
4045 4028
4046 bool LayerTreeHostImpl::CommitToActiveTree() const { 4029 bool LayerTreeHostImpl::CommitToActiveTree() const {
4047 // In single threaded mode we skip the pending tree and commit directly to the 4030 // In single threaded mode we skip the pending tree and commit directly to the
4048 // active tree. 4031 // active tree.
4049 return !task_runner_provider_->HasImplThread(); 4032 return !task_runner_provider_->HasImplThread();
4050 } 4033 }
4051 4034
4052 } // namespace cc 4035 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698