OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/paint_aggregator.h" | 5 #include "content/renderer/paint_aggregator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 if (dy > 0) { | 70 if (dy > 0) { |
71 damaged_rect.set_y(scroll_rect.y()); | 71 damaged_rect.set_y(scroll_rect.y()); |
72 damaged_rect.set_height(dy); | 72 damaged_rect.set_height(dy); |
73 } else { | 73 } else { |
74 damaged_rect.set_y(scroll_rect.bottom() + dy); | 74 damaged_rect.set_y(scroll_rect.bottom() + dy); |
75 damaged_rect.set_height(-dy); | 75 damaged_rect.set_height(-dy); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 // In case the scroll offset exceeds the width/height of the scroll rect | 79 // In case the scroll offset exceeds the width/height of the scroll rect |
80 damaged_rect.Intersect(scroll_rect); | 80 return gfx::IntersectRects(scroll_rect, damaged_rect); |
81 return damaged_rect; | |
82 } | 81 } |
83 | 82 |
84 gfx::Rect PaintAggregator::PendingUpdate::GetPaintBounds() const { | 83 gfx::Rect PaintAggregator::PendingUpdate::GetPaintBounds() const { |
85 gfx::Rect bounds; | 84 gfx::Rect bounds; |
86 for (size_t i = 0; i < paint_rects.size(); ++i) | 85 for (size_t i = 0; i < paint_rects.size(); ++i) |
87 bounds.Union(paint_rects[i]); | 86 bounds.Union(paint_rects[i]); |
88 return bounds; | 87 return bounds; |
89 } | 88 } |
90 | 89 |
91 bool PaintAggregator::HasPendingUpdate() const { | 90 bool PaintAggregator::HasPendingUpdate() const { |
(...skipping 24 matching lines...) Expand all Loading... |
116 } | 115 } |
117 | 116 |
118 void PaintAggregator::InvalidateRect(const gfx::Rect& rect) { | 117 void PaintAggregator::InvalidateRect(const gfx::Rect& rect) { |
119 // Combine overlapping paints using smallest bounding box. | 118 // Combine overlapping paints using smallest bounding box. |
120 for (size_t i = 0; i < update_.paint_rects.size(); ++i) { | 119 for (size_t i = 0; i < update_.paint_rects.size(); ++i) { |
121 const gfx::Rect& existing_rect = update_.paint_rects[i]; | 120 const gfx::Rect& existing_rect = update_.paint_rects[i]; |
122 if (existing_rect.Contains(rect)) // Optimize out redundancy. | 121 if (existing_rect.Contains(rect)) // Optimize out redundancy. |
123 return; | 122 return; |
124 if (rect.Intersects(existing_rect) || rect.SharesEdgeWith(existing_rect)) { | 123 if (rect.Intersects(existing_rect) || rect.SharesEdgeWith(existing_rect)) { |
125 // Re-invalidate in case the union intersects other paint rects. | 124 // Re-invalidate in case the union intersects other paint rects. |
126 gfx::Rect combined_rect = existing_rect; | 125 gfx::Rect combined_rect = gfx::UnionRects(existing_rect, rect); |
127 combined_rect.Union(rect); | |
128 update_.paint_rects.erase(update_.paint_rects.begin() + i); | 126 update_.paint_rects.erase(update_.paint_rects.begin() + i); |
129 InvalidateRect(combined_rect); | 127 InvalidateRect(combined_rect); |
130 return; | 128 return; |
131 } | 129 } |
132 } | 130 } |
133 | 131 |
134 // Add a non-overlapping paint. | 132 // Add a non-overlapping paint. |
135 update_.paint_rects.push_back(rect); | 133 update_.paint_rects.push_back(rect); |
136 | 134 |
137 // If the new paint overlaps with a scroll, then it forces an invalidation of | 135 // If the new paint overlaps with a scroll, then it forces an invalidation of |
138 // the scroll. If the new paint is contained by a scroll, then trim off the | 136 // the scroll. If the new paint is contained by a scroll, then trim off the |
139 // scroll damage to avoid redundant painting. | 137 // scroll damage to avoid redundant painting. |
140 if (!update_.scroll_rect.IsEmpty()) { | 138 if (!update_.scroll_rect.IsEmpty()) { |
141 if (ShouldInvalidateScrollRect(rect)) { | 139 if (ShouldInvalidateScrollRect(rect)) { |
142 InvalidateScrollRect(); | 140 InvalidateScrollRect(); |
143 } else if (update_.scroll_rect.Contains(rect)) { | 141 } else if (update_.scroll_rect.Contains(rect)) { |
144 gfx::Rect paint_rect = rect; | 142 update_.paint_rects[update_.paint_rects.size() - 1] = |
145 paint_rect.Subtract(update_.GetScrollDamage()); | 143 gfx::SubtractRects(rect, update_.GetScrollDamage()); |
146 update_.paint_rects[update_.paint_rects.size() - 1] = paint_rect; | |
147 if (update_.paint_rects[update_.paint_rects.size() - 1].IsEmpty()) | 144 if (update_.paint_rects[update_.paint_rects.size() - 1].IsEmpty()) |
148 update_.paint_rects.erase(update_.paint_rects.end() - 1); | 145 update_.paint_rects.erase(update_.paint_rects.end() - 1); |
149 } | 146 } |
150 } | 147 } |
151 | 148 |
152 if (update_.paint_rects.size() > kMaxPaintRects) | 149 if (update_.paint_rects.size() > kMaxPaintRects) |
153 CombinePaintRects(); | 150 CombinePaintRects(); |
154 | 151 |
155 // Track how large the paint_rects vector grows during an invalidation | 152 // Track how large the paint_rects vector grows during an invalidation |
156 // sequence. Note: A subsequent invalidation may end up being combined | 153 // sequence. Note: A subsequent invalidation may end up being combined |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 outer.Union(existing_rect); | 279 outer.Union(existing_rect); |
283 } | 280 } |
284 } | 281 } |
285 update_.paint_rects.clear(); | 282 update_.paint_rects.clear(); |
286 update_.paint_rects.push_back(inner); | 283 update_.paint_rects.push_back(inner); |
287 update_.paint_rects.push_back(outer); | 284 update_.paint_rects.push_back(outer); |
288 } | 285 } |
289 } | 286 } |
290 | 287 |
291 } // namespace content | 288 } // namespace content |
OLD | NEW |