Index: cc/picture_layer_tiling.cc |
diff --git a/cc/picture_layer_tiling.cc b/cc/picture_layer_tiling.cc |
index 7d3f975bda1c44eda663de9cac9dfd4290d850fd..ba41776142ca63bdfbe1041e62151256d47dbd26 100644 |
--- a/cc/picture_layer_tiling.cc |
+++ b/cc/picture_layer_tiling.cc |
@@ -3,9 +3,27 @@ |
// found in the LICENSE file. |
#include "cc/picture_layer_tiling.h" |
+ |
+#include "cc/math_util.h" |
#include "ui/gfx/rect_conversions.h" |
#include "ui/gfx/size_conversions.h" |
+#include <algorithm> |
+ |
+namespace { |
+ |
+const double kMaxTimeToVisibleInSeconds = 1000.0; |
+ |
+int manhattanDistance(const gfx::Rect& a, const gfx::Rect& b) |
+{ |
+ gfx::Rect c = gfx::UnionRects(a, b); |
+ int x = std::max(0, c.width() - a.width() - b.width() + 1); |
+ int y = std::max(0, c.height() - a.height() - b.height() + 1); |
+ return (x + y); |
+} |
+ |
+} |
+ |
namespace cc { |
scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( |
@@ -266,4 +284,107 @@ gfx::Size PictureLayerTiling::Iterator::texture_size() const { |
return tiling_->tiling_data_.max_texture_size(); |
} |
+void PictureLayerTiling::UpdateTilePriorities( |
+ const gfx::Size& view_port, |
+ float layer_content_scale, |
+ const gfx::Transform& last_transform, |
+ const gfx::Transform& current_transform, |
+ double time_delta) { |
+ gfx::Rect countent_rect = ContentRect(); |
+ if (countent_rect.IsEmpty()) |
+ return; |
+ |
+ gfx::Rect view_rect(gfx::Point(), view_port); |
+ int right = tiling_data_.TileXIndexFromSrcCoord(countent_rect.width() - 1); |
+ int bottom = tiling_data_.TileYIndexFromSrcCoord(countent_rect.height() - 1); |
+ for (int j = 0; j <= bottom; ++j) { |
+ for (int i = 0; i <= right; ++i) { |
+ gfx::Rect content_rect = tiling_data_.TileBounds(i, j); |
+ gfx::Rect layer_content_rect = gfx::ToEnclosingRect( |
+ gfx::ScaleRect(content_rect, layer_content_scale / contents_scale_)); |
+ gfx::Rect screen_rect = MathUtil::mapClippedRect( |
+ current_transform, layer_content_rect); |
+ gfx::Rect previous_rect = MathUtil::mapClippedRect( |
+ last_transform, layer_content_rect); |
+ |
+ TilePriority priority; |
epenner
2012/11/30 19:29:31
Sorry if this is annoying, but after looking at th
qinmin
2012/11/30 20:32:35
Done, the math thingy are moved to TilePriority. A
|
+ priority.resolution = HIGH_RESOLUTION; |
+ priority.time_to_visible_in_seconds = TimeForBoundsToIntersect( |
+ previous_rect, screen_rect, time_delta, view_rect); |
+ |
+ priority.distance_to_visible_in_pixels = manhattanDistance(screen_rect, |
+ view_rect); |
+ // TODO(qinmin): pass the correct tree to this function. |
+ TileAt(i, j)->set_priority(ACTIVE_TREE, priority); |
+ } |
+ } |
+} |
+ |
+double PictureLayerTiling::TimeForBoundsToIntersect(gfx::Rect previous_bounds, |
+ gfx::Rect current_bounds, |
+ double time_delta, |
+ gfx::Rect target_bounds) { |
+ if (current_bounds.Intersects(target_bounds)) |
+ return 0; |
+ |
+ if (previous_bounds.Intersects(target_bounds) || time_delta == 0) |
+ return kMaxTimeToVisibleInSeconds; |
+ |
+ // As we are trying to solve the case of both scaling and scrolling, using |
+ // a single coordinate with velocity is not enough. The logic here is to |
+ // calculate the velocity for each edge. Then we calculate the time range that |
+ // each edge will stay on the same side of the target bounds. If there is an |
+ // overlap between these time ranges, the bounds must have intersect with |
+ // each other during that period of time. |
+ double velocity = |
+ (current_bounds.right() - previous_bounds.right()) / time_delta; |
+ PictureLayerTiling::Range range = TimeRangeValueLargerThanThreshold( |
+ current_bounds.right(), target_bounds.x(), velocity); |
+ |
+ velocity = (current_bounds.x() - previous_bounds.x()) / time_delta; |
+ range = range.Intersects(TimeRangeValueLargerThanThreshold( |
+ -current_bounds.x(), -target_bounds.right(), -velocity)); |
+ |
+ |
+ velocity = (current_bounds.y() - previous_bounds.y()) / time_delta; |
+ range = range.Intersects(TimeRangeValueLargerThanThreshold( |
+ -current_bounds.y(), -target_bounds.bottom(), -velocity)); |
+ |
+ velocity = (current_bounds.bottom() - previous_bounds.bottom()) / time_delta; |
+ range = range.Intersects(TimeRangeValueLargerThanThreshold( |
+ current_bounds.bottom(), target_bounds.y(), velocity)); |
+ |
+ return range.IsEmpty() ? kMaxTimeToVisibleInSeconds : range.start_; |
+} |
+ |
+PictureLayerTiling::Range PictureLayerTiling::TimeRangeValueLargerThanThreshold( |
+ int value, int threshold, double velocity) { |
+ double minimum_time = 0; |
+ double maximum_time = kMaxTimeToVisibleInSeconds; |
+ |
+ if (velocity > 0) { |
+ if (value < threshold) |
+ minimum_time = std::min(kMaxTimeToVisibleInSeconds, |
+ (threshold - value) / velocity); |
+ } else if (velocity <= 0) { |
+ if (value < threshold) |
+ minimum_time = kMaxTimeToVisibleInSeconds; |
+ else if (velocity != 0) |
+ maximum_time = std::min(maximum_time, (threshold - value) / velocity); |
+ } |
+ |
+ return PictureLayerTiling::Range(minimum_time, maximum_time); |
+} |
+ |
+PictureLayerTiling::Range PictureLayerTiling::Range::Intersects( |
+ const PictureLayerTiling::Range& other) { |
+ start_ = std::max(start_, other.start_); |
+ end_ = std::min(end_, other.end_); |
+ return PictureLayerTiling::Range(start_, end_); |
+} |
+ |
+bool PictureLayerTiling::Range::IsEmpty() { |
+ return start_ >= end_; |
+} |
+ |
} // namespace cc |