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

Side by Side Diff: cc/tile_priority.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: move all the math from picture_layer_tiling to tile_prority Created 8 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/tile_priority.h"
6
7 namespace {
8
9 const double kMaxTimeToVisibleInSeconds = 1000.0;
10
11 // TODO(qinmin): modify ui/range/Range.h to support template so that we
12 // don't need to define this.
13 struct Range {
14 Range(double start, double end) : start_(start), end_(end) {}
15 Range Intersects(const Range& other);
16 bool IsEmpty();
17 double start_;
18 double end_;
19 };
20
21 Range Range::Intersects(const Range& other) {
22 start_ = std::max(start_, other.start_);
23 end_ = std::min(end_, other.end_);
24 return Range(start_, end_);
25 }
26
27 bool Range::IsEmpty() {
28 return start_ >= end_;
29 }
30
31 // Calculate a time range that |value| will be larger than |threshold|
32 // given the velocity of its change.
33 Range TimeRangeValueLargerThanThreshold(
34 int value, int threshold, double velocity) {
35 double minimum_time = 0;
36 double maximum_time = kMaxTimeToVisibleInSeconds;
37
38 if (velocity > 0) {
39 if (value < threshold)
40 minimum_time = std::min(kMaxTimeToVisibleInSeconds,
41 (threshold - value) / velocity);
42 } else if (velocity <= 0) {
43 if (value < threshold)
44 minimum_time = kMaxTimeToVisibleInSeconds;
45 else if (velocity != 0)
46 maximum_time = std::min(maximum_time, (threshold - value) / velocity);
47 }
48
49 return Range(minimum_time, maximum_time);
50 }
51
52 } // namespace
53
54 namespace cc {
55
56 int TilePriority::manhattanDistance(const gfx::Rect& a, const gfx::Rect& b) {
57 gfx::Rect c = gfx::UnionRects(a, b);
58 int x = std::max(0, c.width() - a.width() - b.width() + 1);
59 int y = std::max(0, c.height() - a.height() - b.height() + 1);
60 return (x + y);
61 }
62
63 double TilePriority::TimeForBoundsToIntersect(gfx::Rect previous_bounds,
64 gfx::Rect current_bounds,
65 double time_delta,
66 gfx::Rect target_bounds) {
67 if (current_bounds.Intersects(target_bounds))
68 return 0;
69
70 if (previous_bounds.Intersects(target_bounds) || time_delta == 0)
71 return kMaxTimeToVisibleInSeconds;
72
73 // As we are trying to solve the case of both scaling and scrolling, using
74 // a single coordinate with velocity is not enough. The logic here is to
75 // calculate the velocity for each edge. Then we calculate the time range that
76 // each edge will stay on the same side of the target bounds. If there is an
77 // overlap between these time ranges, the bounds must have intersect with
78 // each other during that period of time.
79 double velocity =
80 (current_bounds.right() - previous_bounds.right()) / time_delta;
81 Range range = TimeRangeValueLargerThanThreshold(
82 current_bounds.right(), target_bounds.x(), velocity);
83
84 velocity = (current_bounds.x() - previous_bounds.x()) / time_delta;
85 range = range.Intersects(TimeRangeValueLargerThanThreshold(
86 -current_bounds.x(), -target_bounds.right(), -velocity));
87
88
89 velocity = (current_bounds.y() - previous_bounds.y()) / time_delta;
90 range = range.Intersects(TimeRangeValueLargerThanThreshold(
91 -current_bounds.y(), -target_bounds.bottom(), -velocity));
92
93 velocity = (current_bounds.bottom() - previous_bounds.bottom()) / time_delta;
94 range = range.Intersects(TimeRangeValueLargerThanThreshold(
95 current_bounds.bottom(), target_bounds.y(), velocity));
96
97 return range.IsEmpty() ? kMaxTimeToVisibleInSeconds : range.start_;
98 }
99
100 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698