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

Unified Diff: cc/resources/picture_layer_tiling.cc

Issue 13582006: Prioritize tiles near the viewport in out-of-viewport layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use ToString() Created 7 years, 8 months 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 | « no previous file | cc/resources/picture_layer_tiling_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/picture_layer_tiling.cc
diff --git a/cc/resources/picture_layer_tiling.cc b/cc/resources/picture_layer_tiling.cc
index e406417dcec8c22046079f6a7b9ea821a83b2e70..3035033bdc20e85fecf2b77ccfb4fbcdb1202447 100644
--- a/cc/resources/picture_layer_tiling.cc
+++ b/cc/resources/picture_layer_tiling.cc
@@ -527,6 +527,8 @@ scoped_ptr<base::Value> PictureLayerTiling::AsValue() const {
return state.PassAs<base::Value>();
}
+namespace {
+
// This struct represents an event at which the expending rect intersects
// one of its boundaries. 4 intersection events will occur during expansion.
struct EdgeEvent {
@@ -535,6 +537,24 @@ struct EdgeEvent {
int distance;
};
+// Compute the delta to expand from edges to cover target_area.
+int ComputeExpansionDelta(int num_x_edges, int num_y_edges,
+ int width, int height,
+ int64 target_area) {
+ // Compute coefficients for the quadratic equation:
+ // a*x^2 + b*x + c = 0
+ int a = num_y_edges * num_x_edges;
+ int b = num_y_edges * width + num_x_edges * height;
+ int64 c = static_cast<int64>(width) * height - target_area;
+
+ // Compute the delta for our edges using the quadratic equation.
+ return a == 0 ? -c / b :
+ (-b + static_cast<int>(
+ std::sqrt(static_cast<int64>(b) * b - 4.0 * a * c))) / (2 * a);
+}
+
+} // namespace
+
gfx::Rect PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
gfx::Rect starting_rect,
int64 target_area,
@@ -545,9 +565,23 @@ gfx::Rect PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
DCHECK(!bounding_rect.IsEmpty());
DCHECK_GT(target_area, 0);
- gfx::Rect rect = IntersectRects(starting_rect, bounding_rect);
- if (rect.IsEmpty())
+ // Expand the starting rect to cover target_area.
+ int delta = ComputeExpansionDelta(
+ 2, 2, starting_rect.width(), starting_rect.height(), target_area);
+ gfx::Rect expanded_starting_rect = starting_rect;
+ expanded_starting_rect.Inset(-delta, -delta);
+
+ gfx::Rect rect = IntersectRects(expanded_starting_rect, bounding_rect);
+ if (rect.IsEmpty()) {
+ // The starting_rect and bounding_rect are far away.
return rect;
+ }
+ if (rect == expanded_starting_rect) {
+ // The expanded starting rect already covers target_area on bounding_rect.
+ return rect;
+ }
+
+ // Continue to expand rect to let it cover target_area.
// These values will be updated by the loop and uses as the output.
int origin_x = rect.x();
@@ -584,14 +618,8 @@ gfx::Rect PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
continue;
}
- // Compute coefficients for the quadraic equation.
- int a = num_y_edges * num_x_edges;
- int b = num_y_edges * width + num_x_edges * height;
- int c = width * height - target_area;
-
- // Compute the delta for our edges using the quadratic equation.
- int delta = a == 0 ? -c / b :
- (-b + static_cast<int>(std::sqrt(b * b - 4.0 * a * c))) / (2 * a);
+ int delta = ComputeExpansionDelta(
+ num_x_edges, num_y_edges, width, height, target_area);
// Clamp delta to our event distance.
if (delta > event.distance)
« no previous file with comments | « no previous file | cc/resources/picture_layer_tiling_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698