OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "cc/playback/pixel_ref_map.h" | 5 #include "cc/playback/pixel_ref_map.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 int min_x = std::numeric_limits<int>::max(); | 27 int min_x = std::numeric_limits<int>::max(); |
28 int min_y = std::numeric_limits<int>::max(); | 28 int min_y = std::numeric_limits<int>::max(); |
29 int max_x = 0; | 29 int max_x = 0; |
30 int max_y = 0; | 30 int max_y = 0; |
31 | 31 |
32 skia::DiscardablePixelRefList pixel_refs; | 32 skia::DiscardablePixelRefList pixel_refs; |
33 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture, &pixel_refs); | 33 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture, &pixel_refs); |
34 for (skia::DiscardablePixelRefList::const_iterator it = pixel_refs.begin(); | 34 for (skia::DiscardablePixelRefList::const_iterator it = pixel_refs.begin(); |
35 it != pixel_refs.end(); ++it) { | 35 it != pixel_refs.end(); ++it) { |
36 gfx::Point min(MathUtil::RoundDown(static_cast<int>(it->pixel_ref_rect.x()), | 36 gfx::Point min( |
37 cell_size_.width()), | 37 MathUtil::UncheckedRoundDown(static_cast<int>(it->pixel_ref_rect.x()), |
38 MathUtil::RoundDown(static_cast<int>(it->pixel_ref_rect.y()), | 38 cell_size_.width()), |
39 cell_size_.height())); | 39 MathUtil::UncheckedRoundDown(static_cast<int>(it->pixel_ref_rect.y()), |
40 gfx::Point max(MathUtil::RoundDown( | 40 cell_size_.height())); |
| 41 gfx::Point max(MathUtil::UncheckedRoundDown( |
41 static_cast<int>(std::ceil(it->pixel_ref_rect.right())), | 42 static_cast<int>(std::ceil(it->pixel_ref_rect.right())), |
42 cell_size_.width()), | 43 cell_size_.width()), |
43 MathUtil::RoundDown( | 44 MathUtil::UncheckedRoundDown( |
44 static_cast<int>(std::ceil(it->pixel_ref_rect.bottom())), | 45 static_cast<int>(std::ceil(it->pixel_ref_rect.bottom())), |
45 cell_size_.height())); | 46 cell_size_.height())); |
46 | 47 |
47 for (int y = min.y(); y <= max.y(); y += cell_size_.height()) { | 48 for (int y = min.y(); y <= max.y(); y += cell_size_.height()) { |
48 for (int x = min.x(); x <= max.x(); x += cell_size_.width()) { | 49 for (int x = min.x(); x <= max.x(); x += cell_size_.width()) { |
49 PixelRefMapKey key(x, y); | 50 PixelRefMapKey key(x, y); |
50 data_hash_map_[key].push_back(it->pixel_ref); | 51 data_hash_map_[key].push_back(it->pixel_ref); |
51 } | 52 } |
52 } | 53 } |
53 | 54 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 return; | 142 return; |
142 } | 143 } |
143 | 144 |
144 // First, subtract the layer origin as cells are stored in layer space. | 145 // First, subtract the layer origin as cells are stored in layer space. |
145 query_rect.Offset(-map_layer_rect_.OffsetFromOrigin()); | 146 query_rect.Offset(-map_layer_rect_.OffsetFromOrigin()); |
146 | 147 |
147 DCHECK(!target_pixel_ref_map_->cell_size_.IsEmpty()); | 148 DCHECK(!target_pixel_ref_map_->cell_size_.IsEmpty()); |
148 gfx::Size cell_size(target_pixel_ref_map_->cell_size_); | 149 gfx::Size cell_size(target_pixel_ref_map_->cell_size_); |
149 // We have to find a cell_size aligned point that corresponds to | 150 // We have to find a cell_size aligned point that corresponds to |
150 // query_rect. Point is a multiple of cell_size. | 151 // query_rect. Point is a multiple of cell_size. |
151 min_point_ = | 152 min_point_ = gfx::Point( |
152 gfx::Point(MathUtil::RoundDown(query_rect.x(), cell_size.width()), | 153 MathUtil::UncheckedRoundDown(query_rect.x(), cell_size.width()), |
153 MathUtil::RoundDown(query_rect.y(), cell_size.height())); | 154 MathUtil::UncheckedRoundDown(query_rect.y(), cell_size.height())); |
154 max_point_ = gfx::Point( | 155 max_point_ = gfx::Point( |
155 MathUtil::RoundDown(query_rect.right() - 1, cell_size.width()), | 156 MathUtil::UncheckedRoundDown(query_rect.right() - 1, cell_size.width()), |
156 MathUtil::RoundDown(query_rect.bottom() - 1, cell_size.height())); | 157 MathUtil::UncheckedRoundDown(query_rect.bottom() - 1, |
| 158 cell_size.height())); |
157 | 159 |
158 // Limit the points to known pixel ref boundaries. | 160 // Limit the points to known pixel ref boundaries. |
159 min_point_ = gfx::Point( | 161 min_point_ = gfx::Point( |
160 std::max(min_point_.x(), target_pixel_ref_map_->min_pixel_cell_.x()), | 162 std::max(min_point_.x(), target_pixel_ref_map_->min_pixel_cell_.x()), |
161 std::max(min_point_.y(), target_pixel_ref_map_->min_pixel_cell_.y())); | 163 std::max(min_point_.y(), target_pixel_ref_map_->min_pixel_cell_.y())); |
162 max_point_ = gfx::Point( | 164 max_point_ = gfx::Point( |
163 std::min(max_point_.x(), target_pixel_ref_map_->max_pixel_cell_.x()), | 165 std::min(max_point_.x(), target_pixel_ref_map_->max_pixel_cell_.x()), |
164 std::min(max_point_.y(), target_pixel_ref_map_->max_pixel_cell_.y())); | 166 std::min(max_point_.y(), target_pixel_ref_map_->max_pixel_cell_.y())); |
165 | 167 |
166 // Make the current x be cell_size.width() less than min point, so that | 168 // Make the current x be cell_size.width() less than min point, so that |
167 // the first increment will point at min_point_. | 169 // the first increment will point at min_point_. |
168 current_x_ = min_point_.x() - cell_size.width(); | 170 current_x_ = min_point_.x() - cell_size.width(); |
169 current_y_ = min_point_.y(); | 171 current_y_ = min_point_.y(); |
170 if (current_y_ <= max_point_.y()) | 172 if (current_y_ <= max_point_.y()) |
171 ++(*this); | 173 ++(*this); |
172 } | 174 } |
173 | 175 |
174 } // namespace cc | 176 } // namespace cc |
OLD | NEW |