Index: cc/tiles/picture_layer_tiling.cc |
diff --git a/cc/tiles/picture_layer_tiling.cc b/cc/tiles/picture_layer_tiling.cc |
index 01beed6937045970d700af0c0b34e1f2203844bd..401dd78e81b3be9eb37f5affdbbe50d7920ed64a 100644 |
--- a/cc/tiles/picture_layer_tiling.cc |
+++ b/cc/tiles/picture_layer_tiling.cc |
@@ -29,40 +29,13 @@ |
#include "ui/gfx/geometry/size_conversions.h" |
namespace cc { |
-namespace { |
- |
-const float kSoonBorderDistanceViewportPercentage = 0.15f; |
-const float kMaxSoonBorderDistanceInScreenPixels = 312.f; |
- |
-} // namespace |
- |
-std::unique_ptr<PictureLayerTiling> PictureLayerTiling::Create( |
- WhichTree tree, |
- float contents_scale, |
- scoped_refptr<RasterSource> raster_source, |
- PictureLayerTilingClient* client, |
- size_t tiling_interest_area_padding, |
- float skewport_target_time_in_seconds, |
- int skewport_extrapolation_limit_in_content_pixels) { |
- return base::WrapUnique(new PictureLayerTiling( |
- tree, contents_scale, raster_source, client, tiling_interest_area_padding, |
- skewport_target_time_in_seconds, |
- skewport_extrapolation_limit_in_content_pixels)); |
-} |
PictureLayerTiling::PictureLayerTiling( |
WhichTree tree, |
float contents_scale, |
scoped_refptr<RasterSource> raster_source, |
- PictureLayerTilingClient* client, |
- size_t tiling_interest_area_padding, |
- float skewport_target_time_in_seconds, |
- int skewport_extrapolation_limit_in_content_pixels) |
- : tiling_interest_area_padding_(tiling_interest_area_padding), |
- skewport_target_time_in_seconds_(skewport_target_time_in_seconds), |
- skewport_extrapolation_limit_in_content_pixels_( |
- skewport_extrapolation_limit_in_content_pixels), |
- contents_scale_(contents_scale), |
+ PictureLayerTilingClient* client) |
+ : contents_scale_(contents_scale), |
client_(client), |
tree_(tree), |
raster_source_(raster_source), |
@@ -75,8 +48,7 @@ PictureLayerTiling::PictureLayerTiling( |
has_skewport_rect_tiles_(false), |
has_soon_border_rect_tiles_(false), |
has_eventually_rect_tiles_(false), |
- all_tiles_done_(true), |
- invalidated_since_last_compute_priority_rects_(false) { |
+ all_tiles_done_(true) { |
DCHECK(!raster_source->IsSolidColor()); |
gfx::Size content_bounds = |
gfx::ScaleToCeiledSize(raster_source_->GetSize(), contents_scale); |
@@ -95,17 +67,6 @@ PictureLayerTiling::PictureLayerTiling( |
PictureLayerTiling::~PictureLayerTiling() { |
} |
-// static |
-float PictureLayerTiling::CalculateSoonBorderDistance( |
- const gfx::Rect& visible_rect_in_content_space, |
- float content_to_screen_scale) { |
- float max_dimension = std::max(visible_rect_in_content_space.width(), |
- visible_rect_in_content_space.height()); |
- return std::min( |
- kMaxSoonBorderDistanceInScreenPixels / content_to_screen_scale, |
- max_dimension * kSoonBorderDistanceViewportPercentage); |
-} |
- |
Tile* PictureLayerTiling::CreateTile(const Tile::CreateInfo& info) { |
const int i = info.tiling_i_index; |
const int j = info.tiling_j_index; |
@@ -289,7 +250,6 @@ void PictureLayerTiling::SetRasterSourceAndResize( |
void PictureLayerTiling::Invalidate(const Region& layer_invalidation) { |
DCHECK(tree_ != ACTIVE_TREE || !client_->GetPendingOrActiveTwinTiling(this)); |
- invalidated_since_last_compute_priority_rects_ = true; |
RemoveTilesInRegion(layer_invalidation, true /* recreate tiles */); |
} |
@@ -575,69 +535,12 @@ void PictureLayerTiling::Reset() { |
all_tiles_done_ = true; |
} |
-gfx::Rect PictureLayerTiling::ComputeSkewport( |
- double current_frame_time_in_seconds, |
- const gfx::Rect& visible_rect_in_content_space) const { |
- gfx::Rect skewport = visible_rect_in_content_space; |
- if (skewport.IsEmpty()) |
- return skewport; |
- |
- if (visible_rect_history_[1].frame_time_in_seconds == 0.0) |
- return skewport; |
- |
- double time_delta = current_frame_time_in_seconds - |
- visible_rect_history_[1].frame_time_in_seconds; |
- if (time_delta == 0.0) |
- return skewport; |
- |
- double extrapolation_multiplier = |
- skewport_target_time_in_seconds_ / time_delta; |
- |
- int old_x = visible_rect_history_[1].visible_rect_in_content_space.x(); |
- int old_y = visible_rect_history_[1].visible_rect_in_content_space.y(); |
- int old_right = |
- visible_rect_history_[1].visible_rect_in_content_space.right(); |
- int old_bottom = |
- visible_rect_history_[1].visible_rect_in_content_space.bottom(); |
- |
- int new_x = visible_rect_in_content_space.x(); |
- int new_y = visible_rect_in_content_space.y(); |
- int new_right = visible_rect_in_content_space.right(); |
- int new_bottom = visible_rect_in_content_space.bottom(); |
- |
- // Compute the maximum skewport based on |
- // |skewport_extrapolation_limit_in_content_pixels_|. |
- gfx::Rect max_skewport = skewport; |
- max_skewport.Inset(-skewport_extrapolation_limit_in_content_pixels_, |
- -skewport_extrapolation_limit_in_content_pixels_); |
- |
- // Inset the skewport by the needed adjustment. |
- skewport.Inset(extrapolation_multiplier * (new_x - old_x), |
- extrapolation_multiplier * (new_y - old_y), |
- extrapolation_multiplier * (old_right - new_right), |
- extrapolation_multiplier * (old_bottom - new_bottom)); |
- |
- // Ensure that visible rect is contained in the skewport. |
- skewport.Union(visible_rect_in_content_space); |
- |
- // Clip the skewport to |max_skewport|. This needs to happen after the |
- // union in case intersecting would have left the empty rect. |
- skewport.Intersect(max_skewport); |
- |
- // Due to limits in int's representation, it is possible that the two |
- // operations above (union and intersect) result in an empty skewport. To |
- // avoid any unpleasant situations like that, union the visible rect again to |
- // ensure that skewport.Contains(visible_rect_in_content_space) is always |
- // true. |
- skewport.Union(visible_rect_in_content_space); |
- |
- return skewport; |
-} |
- |
-bool PictureLayerTiling::ComputeTilePriorityRects( |
- const gfx::Rect& viewport_in_layer_space, |
+void PictureLayerTiling::ComputeTilePriorityRects( |
+ const gfx::Rect& visible_rect_in_layer_space, |
+ const gfx::Rect& skewport_in_layer_space, |
+ const gfx::Rect& soon_border_rect_in_layer_space, |
+ const gfx::Rect& eventually_rect_in_layer_space, |
float ideal_contents_scale, |
- double current_frame_time_in_seconds, |
const Occlusion& occlusion_in_layer_space) { |
// If we have, or had occlusions, mark the tiles as 'not done' to ensure that |
// we reiterate the tiles for rasterization. |
@@ -646,87 +549,24 @@ bool PictureLayerTiling::ComputeTilePriorityRects( |
set_all_tiles_done(false); |
} |
- bool invalidated = invalidated_since_last_compute_priority_rects_; |
- invalidated_since_last_compute_priority_rects_ = false; |
- if (!NeedsUpdateForFrameAtTimeAndViewport(current_frame_time_in_seconds, |
- viewport_in_layer_space)) { |
- // This should never be zero for the purposes of has_ever_been_updated(). |
- DCHECK_NE(current_frame_time_in_seconds, 0.0); |
- return invalidated; |
- } |
- |
const float content_to_screen_scale = ideal_contents_scale / contents_scale_; |
- // We want to compute the visible rect and eventually rect from it in the |
- // space of the tiling. But the visible rect (viewport) can be arbitrarily |
- // positioned, so be careful when scaling it since we can exceed integer |
- // bounds. |
- gfx::Rect eventually_rect; |
- gfx::Rect visible_rect_in_content_space; |
- |
- // We keep things as floats in here. |
- { |
- gfx::RectF visible_rectf_in_content_space = |
- gfx::ScaleRect(gfx::RectF(viewport_in_layer_space), contents_scale_); |
- |
- // Determine if the eventually rect will even touch the tiling, if it's too |
- // far away just treat it as empty so we don't exceed integer bounds. |
- const float pad_in_content_space = |
- tiling_interest_area_padding_ / content_to_screen_scale; |
- gfx::RectF eventually_rectf = visible_rectf_in_content_space; |
- // If the visible rect is empty, keep the eventually rect as empty. |
- if (!eventually_rectf.IsEmpty()) { |
- eventually_rectf.Inset(-pad_in_content_space, -pad_in_content_space); |
- |
- // If the eventually rect will touch the tiling, then we convert back to |
- // integers and set the visible and eventually rects. |
- auto bounds = gfx::RectF(gfx::SizeF(tiling_size())); |
- if (eventually_rectf.Intersects(bounds)) { |
- visible_rect_in_content_space = |
- gfx::ToEnclosingRect(visible_rectf_in_content_space); |
- eventually_rect = gfx::ToEnclosingRect(eventually_rectf); |
- } |
- } |
+ const gfx::Rect* input_rects[] = { |
+ &visible_rect_in_layer_space, &skewport_in_layer_space, |
+ &soon_border_rect_in_layer_space, &eventually_rect_in_layer_space}; |
+ gfx::Rect output_rects[4]; |
+ for (size_t i = 0; i < arraysize(input_rects); ++i) { |
+ output_rects[i] = gfx::ToEnclosingRect( |
+ gfx::ScaleRect(gfx::RectF(*input_rects[i]), contents_scale_)); |
} |
- DCHECK_EQ(visible_rect_in_content_space.IsEmpty(), eventually_rect.IsEmpty()); |
- |
- // Now we have an empty visible/eventually rect if it's not useful and a |
- // non-empty one if it is. We can compute the final eventually rect. |
- eventually_rect = |
- tiling_data_.ExpandRectIgnoringBordersToTileBounds(eventually_rect); |
+ // Make sure the eventually rect is aligned to tile bounds. |
+ output_rects[3] = |
+ tiling_data_.ExpandRectIgnoringBordersToTileBounds(output_rects[3]); |
- DCHECK(eventually_rect.IsEmpty() || |
- gfx::Rect(tiling_size()).Contains(eventually_rect)) |
- << "tiling_size: " << tiling_size().ToString() |
- << " eventually_rect: " << eventually_rect.ToString(); |
- |
- if (tiling_size().IsEmpty()) { |
- UpdateVisibleRectHistory(current_frame_time_in_seconds, |
- visible_rect_in_content_space); |
- last_viewport_in_layer_space_ = viewport_in_layer_space; |
- return false; |
- } |
- |
- // Calculate the skewport. |
- gfx::Rect skewport = ComputeSkewport(current_frame_time_in_seconds, |
- visible_rect_in_content_space); |
- DCHECK(skewport.Contains(visible_rect_in_content_space)); |
- |
- // Calculate the soon border rect. |
- gfx::Rect soon_border_rect = visible_rect_in_content_space; |
- float border = CalculateSoonBorderDistance(visible_rect_in_content_space, |
- content_to_screen_scale); |
- soon_border_rect.Inset(-border, -border, -border, -border); |
- |
- UpdateVisibleRectHistory(current_frame_time_in_seconds, |
- visible_rect_in_content_space); |
- last_viewport_in_layer_space_ = viewport_in_layer_space; |
- |
- SetTilePriorityRects(content_to_screen_scale, visible_rect_in_content_space, |
- skewport, soon_border_rect, eventually_rect, |
+ SetTilePriorityRects(content_to_screen_scale, output_rects[0], |
+ output_rects[1], output_rects[2], output_rects[3], |
occlusion_in_layer_space); |
- SetLiveTilesRect(eventually_rect); |
- return true; |
+ SetLiveTilesRect(output_rects[3]); |
} |
void PictureLayerTiling::SetTilePriorityRects( |