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/layers/tiled_layer.h" | 5 #include "cc/layers/tiled_layer.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "cc/debug/overdraw_metrics.h" | 10 #include "cc/debug/overdraw_metrics.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 139 } |
140 | 140 |
141 void TiledLayer::UpdateBounds() { | 141 void TiledLayer::UpdateBounds() { |
142 gfx::Size old_bounds = tiler_->bounds(); | 142 gfx::Size old_bounds = tiler_->bounds(); |
143 gfx::Size new_bounds = content_bounds(); | 143 gfx::Size new_bounds = content_bounds(); |
144 if (old_bounds == new_bounds) | 144 if (old_bounds == new_bounds) |
145 return; | 145 return; |
146 tiler_->SetBounds(new_bounds); | 146 tiler_->SetBounds(new_bounds); |
147 | 147 |
148 // Invalidate any areas that the new bounds exposes. | 148 // Invalidate any areas that the new bounds exposes. |
149 Region old_region = gfx::Rect(gfx::Point(), old_bounds); | 149 Region old_region = gfx::Rect(old_bounds); |
150 Region new_region = gfx::Rect(gfx::Point(), new_bounds); | 150 Region new_region = gfx::Rect(new_bounds); |
151 new_region.Subtract(old_region); | 151 new_region.Subtract(old_region); |
152 for (Region::Iterator new_rects(new_region); | 152 for (Region::Iterator new_rects(new_region); |
153 new_rects.has_rect(); | 153 new_rects.has_rect(); |
154 new_rects.next()) | 154 new_rects.next()) |
155 InvalidateContentRect(new_rects.rect()); | 155 InvalidateContentRect(new_rects.rect()); |
156 } | 156 } |
157 | 157 |
158 void TiledLayer::SetTileSize(gfx::Size size) { tiler_->SetTileSize(size); } | 158 void TiledLayer::SetTileSize(gfx::Size size) { tiler_->SetTileSize(size); } |
159 | 159 |
160 void TiledLayer::SetBorderTexelOption( | 160 void TiledLayer::SetBorderTexelOption( |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 // This picks a small animated layer to be anything less than one viewport. This | 562 // This picks a small animated layer to be anything less than one viewport. This |
563 // is specifically for page transitions which are viewport-sized layers. The | 563 // is specifically for page transitions which are viewport-sized layers. The |
564 // extra tile of padding is due to these layers being slightly larger than the | 564 // extra tile of padding is due to these layers being slightly larger than the |
565 // viewport in some cases. | 565 // viewport in some cases. |
566 bool TiledLayer::IsSmallAnimatedLayer() const { | 566 bool TiledLayer::IsSmallAnimatedLayer() const { |
567 if (!draw_transform_is_animating() && !screen_space_transform_is_animating()) | 567 if (!draw_transform_is_animating() && !screen_space_transform_is_animating()) |
568 return false; | 568 return false; |
569 gfx::Size viewport_size = | 569 gfx::Size viewport_size = |
570 layer_tree_host() ? layer_tree_host()->device_viewport_size() | 570 layer_tree_host() ? layer_tree_host()->device_viewport_size() |
571 : gfx::Size(); | 571 : gfx::Size(); |
572 gfx::Rect content_rect(gfx::Point(), content_bounds()); | 572 gfx::Rect content_rect(content_bounds()); |
573 return content_rect.width() <= | 573 return content_rect.width() <= |
574 viewport_size.width() + tiler_->tile_size().width() && | 574 viewport_size.width() + tiler_->tile_size().width() && |
575 content_rect.height() <= | 575 content_rect.height() <= |
576 viewport_size.height() + tiler_->tile_size().height(); | 576 viewport_size.height() + tiler_->tile_size().height(); |
577 } | 577 } |
578 | 578 |
579 namespace { | 579 namespace { |
580 // FIXME: Remove this and make this based on distance once distance can be | 580 // FIXME: Remove this and make this based on distance once distance can be |
581 // calculated for offscreen layers. For now, prioritize all small animated | 581 // calculated for offscreen layers. For now, prioritize all small animated |
582 // layers after 512 pixels of pre-painting. | 582 // layers after 512 pixels of pre-painting. |
(...skipping 25 matching lines...) Expand all Loading... |
608 | 608 |
609 if (tiler_->has_empty_bounds()) | 609 if (tiler_->has_empty_bounds()) |
610 return; | 610 return; |
611 | 611 |
612 bool draws_to_root = !render_target()->parent(); | 612 bool draws_to_root = !render_target()->parent(); |
613 bool small_animated_layer = IsSmallAnimatedLayer(); | 613 bool small_animated_layer = IsSmallAnimatedLayer(); |
614 | 614 |
615 // Minimally create the tiles in the desired pre-paint rect. | 615 // Minimally create the tiles in the desired pre-paint rect. |
616 gfx::Rect create_tiles_rect = IdlePaintRect(); | 616 gfx::Rect create_tiles_rect = IdlePaintRect(); |
617 if (small_animated_layer) | 617 if (small_animated_layer) |
618 create_tiles_rect = gfx::Rect(gfx::Point(), content_bounds()); | 618 create_tiles_rect = gfx::Rect(content_bounds()); |
619 if (!create_tiles_rect.IsEmpty()) { | 619 if (!create_tiles_rect.IsEmpty()) { |
620 int left, top, right, bottom; | 620 int left, top, right, bottom; |
621 tiler_->ContentRectToTileIndices( | 621 tiler_->ContentRectToTileIndices( |
622 create_tiles_rect, &left, &top, &right, &bottom); | 622 create_tiles_rect, &left, &top, &right, &bottom); |
623 for (int j = top; j <= bottom; ++j) { | 623 for (int j = top; j <= bottom; ++j) { |
624 for (int i = left; i <= right; ++i) { | 624 for (int i = left; i <= right; ++i) { |
625 if (!TileAt(i, j)) | 625 if (!TileAt(i, j)) |
626 CreateTile(i, j); | 626 CreateTile(i, j); |
627 } | 627 } |
628 } | 628 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 gfx::Vector2d(delta.x(), 0) : | 702 gfx::Vector2d(delta.x(), 0) : |
703 gfx::Vector2d(0, delta.y()); | 703 gfx::Vector2d(0, delta.y()); |
704 predicted_visible_rect_ = | 704 predicted_visible_rect_ = |
705 ExpandRectByDelta(visible_content_rect(), major_scroll_delta); | 705 ExpandRectByDelta(visible_content_rect(), major_scroll_delta); |
706 | 706 |
707 // Bound the prediction to prevent unbounded paints, and clamp to content | 707 // Bound the prediction to prevent unbounded paints, and clamp to content |
708 // bounds. | 708 // bounds. |
709 gfx::Rect bound = visible_content_rect(); | 709 gfx::Rect bound = visible_content_rect(); |
710 bound.Inset(-tiler_->tile_size().width() * kMaxPredictiveTilesCount, | 710 bound.Inset(-tiler_->tile_size().width() * kMaxPredictiveTilesCount, |
711 -tiler_->tile_size().height() * kMaxPredictiveTilesCount); | 711 -tiler_->tile_size().height() * kMaxPredictiveTilesCount); |
712 bound.Intersect(gfx::Rect(gfx::Point(), content_bounds())); | 712 bound.Intersect(gfx::Rect(content_bounds())); |
713 predicted_visible_rect_.Intersect(bound); | 713 predicted_visible_rect_.Intersect(bound); |
714 } | 714 } |
715 previous_content_bounds_ = content_bounds(); | 715 previous_content_bounds_ = content_bounds(); |
716 previous_visible_rect_ = visible_content_rect(); | 716 previous_visible_rect_ = visible_content_rect(); |
717 } | 717 } |
718 | 718 |
719 void TiledLayer::Update(ResourceUpdateQueue* queue, | 719 void TiledLayer::Update(ResourceUpdateQueue* queue, |
720 const OcclusionTracker* occlusion, | 720 const OcclusionTracker* occlusion, |
721 RenderingStats* stats) { | 721 RenderingStats* stats) { |
722 DCHECK(!skips_draw_ && !failed_update_); // Did ResetUpdateState get skipped? | 722 DCHECK(!skips_draw_ && !failed_update_); // Did ResetUpdateState get skipped? |
723 { | 723 { |
724 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 724 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
725 true); | 725 true); |
726 | 726 |
727 ContentsScalingLayer::Update(queue, occlusion, stats); | 727 ContentsScalingLayer::Update(queue, occlusion, stats); |
728 UpdateBounds(); | 728 UpdateBounds(); |
729 } | 729 } |
730 | 730 |
731 if (tiler_->has_empty_bounds() || !DrawsContent()) | 731 if (tiler_->has_empty_bounds() || !DrawsContent()) |
732 return; | 732 return; |
733 | 733 |
734 bool did_paint = false; | 734 bool did_paint = false; |
735 | 735 |
736 // Animation pre-paint. If the layer is small, try to paint it all | 736 // Animation pre-paint. If the layer is small, try to paint it all |
737 // immediately whether or not it is occluded, to avoid paint/upload | 737 // immediately whether or not it is occluded, to avoid paint/upload |
738 // hiccups while it is animating. | 738 // hiccups while it is animating. |
739 if (IsSmallAnimatedLayer()) { | 739 if (IsSmallAnimatedLayer()) { |
740 int left, top, right, bottom; | 740 int left, top, right, bottom; |
741 tiler_->ContentRectToTileIndices(gfx::Rect(gfx::Point(), content_bounds()), | 741 tiler_->ContentRectToTileIndices(gfx::Rect(content_bounds()), |
742 &left, | 742 &left, |
743 &top, | 743 &top, |
744 &right, | 744 &right, |
745 &bottom); | 745 &bottom); |
746 UpdateTiles(left, top, right, bottom, queue, NULL, stats, &did_paint); | 746 UpdateTiles(left, top, right, bottom, queue, NULL, stats, &did_paint); |
747 if (did_paint) | 747 if (did_paint) |
748 return; | 748 return; |
749 // This was an attempt to paint the entire layer so if we fail it's okay, | 749 // This was an attempt to paint the entire layer so if we fail it's okay, |
750 // just fallback on painting visible etc. below. | 750 // just fallback on painting visible etc. below. |
751 failed_update_ = false; | 751 failed_update_ = false; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 gfx::Rect prepaint_rect = visible_content_rect(); | 880 gfx::Rect prepaint_rect = visible_content_rect(); |
881 prepaint_rect.Inset(-tiler_->tile_size().width() * kPrepaintColumns, | 881 prepaint_rect.Inset(-tiler_->tile_size().width() * kPrepaintColumns, |
882 -tiler_->tile_size().height() * kPrepaintRows); | 882 -tiler_->tile_size().height() * kPrepaintRows); |
883 gfx::Rect content_rect(content_bounds()); | 883 gfx::Rect content_rect(content_bounds()); |
884 prepaint_rect.Intersect(content_rect); | 884 prepaint_rect.Intersect(content_rect); |
885 | 885 |
886 return prepaint_rect; | 886 return prepaint_rect; |
887 } | 887 } |
888 | 888 |
889 } // namespace cc | 889 } // namespace cc |
OLD | NEW |