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

Unified Diff: cc/picture_layer_tiling.cc

Issue 11414238: implement the logic to set tile priorities based on current matrix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/picture_layer_tiling.h ('k') | cc/picture_layer_tiling_set.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/picture_layer_tiling.cc
diff --git a/cc/picture_layer_tiling.cc b/cc/picture_layer_tiling.cc
index 7d3f975bda1c44eda663de9cac9dfd4290d850fd..4c792bf7865e2963812adb87d447739affbd8a2a 100644
--- a/cc/picture_layer_tiling.cc
+++ b/cc/picture_layer_tiling.cc
@@ -3,9 +3,17 @@
// 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;
+}
+
namespace cc {
scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create(
@@ -266,4 +274,118 @@ gfx::Size PictureLayerTiling::Iterator::texture_size() const {
return tiling_->tiling_data_.max_texture_size();
}
+void PictureLayerTiling::UpdateTilePriorities(
+ const gfx::Size& view_port,
+ 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_rect = gfx::ToEnclosingRect(
epennerAtGoogle 2012/11/29 22:52:55 Question for Enne. Is this scale correct in order
+ gfx::ScaleRect(content_rect, 1 / contents_scale_));
+ gfx::Rect screen_rect = MathUtil::mapClippedRect(
epennerAtGoogle 2012/11/29 22:07:50 I think this might bite us performance-wise if we
+ current_transform, layer_rect);
danakj 2012/11/29 22:57:30 What is current_transform? If it's the screen spac
epennerAtGoogle 2012/11/29 23:02:58 The trouble is there is multiple content scales, s
qinmin 2012/11/30 00:35:00 Ok, passing the content_scale from the layer to th
+ gfx::Rect previous_rect = MathUtil::mapClippedRect(
+ last_transform, layer_rect);
+
+ TilePriority priority;
+ priority.resolution = HIGH_RESOLUTION;
+ priority.time_to_visible_in_seconds = TimeForBoundsToIntersect(
+ previous_rect, screen_rect, time_delta, view_rect);
+
epennerAtGoogle 2012/11/29 22:07:50 I think for painting we are better off using manha
qinmin 2012/11/29 22:44:17 I like the idea of manhattan distance, it saves th
+ int x_offset = 0;
+ if (screen_rect.right() < view_rect.x())
+ x_offset = view_rect.x() - screen_rect.right();
+ else if (screen_rect.x() > view_rect.right())
+ x_offset = screen_rect.x() - view_rect.right();
+
+ int y_offset = 0;
+ if (screen_rect.bottom() < view_rect.y())
+ y_offset = view_rect.y() - screen_rect.bottom();
+ else if (screen_rect.y() > view_rect.bottom())
+ y_offset = screen_rect.y() - view_rect.bottom();
+
+ priority.distance_to_visible_in_pixels =
+ gfx::Vector2dF(x_offset, x_offset).Length();
+ // TODO(qinmin): pass the correct tree to this function.
+ TileAt(i, j)->set_priority(ACTIVE_TREE, priority);
+ }
+ }
+}
+
+double PictureLayerTiling::TimeForBoundsToIntersect(gfx::Rect previous_bounds,
epennerAtGoogle 2012/11/29 22:07:50 This is super clever.
+ 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
epennerAtGoogle 2012/11/29 22:07:50 I was initially confused by the comment but now I
+ // 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
« no previous file with comments | « cc/picture_layer_tiling.h ('k') | cc/picture_layer_tiling_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698