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/resources/pixel_ref_map.h" | 5 #include "cc/resources/pixel_ref_map.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "cc/base/util.h" | 10 #include "cc/base/util.h" |
11 #include "cc/resources/display_item_list.h" | |
12 #include "cc/resources/picture.h" | 11 #include "cc/resources/picture.h" |
13 #include "skia/ext/pixel_ref_utils.h" | 12 #include "skia/ext/pixel_ref_utils.h" |
14 | 13 |
15 namespace cc { | 14 namespace cc { |
16 | 15 |
17 PixelRefMap::PixelRefMap(const gfx::Size& cell_size) : cell_size_(cell_size) { | 16 PixelRefMap::PixelRefMap(const gfx::Size& cell_size) : cell_size_(cell_size) { |
18 DCHECK(!cell_size.IsEmpty()); | 17 DCHECK(!cell_size.IsEmpty()); |
19 } | 18 } |
20 | 19 |
21 PixelRefMap::~PixelRefMap() { | 20 PixelRefMap::~PixelRefMap() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 min_point_(-1, -1), | 68 min_point_(-1, -1), |
70 max_point_(-1, -1), | 69 max_point_(-1, -1), |
71 current_x_(0), | 70 current_x_(0), |
72 current_y_(0) { | 71 current_y_(0) { |
73 } | 72 } |
74 | 73 |
75 PixelRefMap::Iterator::Iterator(const gfx::Rect& rect, const Picture* picture) | 74 PixelRefMap::Iterator::Iterator(const gfx::Rect& rect, const Picture* picture) |
76 : target_pixel_ref_map_(&(picture->pixel_refs_)), | 75 : target_pixel_ref_map_(&(picture->pixel_refs_)), |
77 current_pixel_refs_(empty_pixel_refs_.Pointer()), | 76 current_pixel_refs_(empty_pixel_refs_.Pointer()), |
78 current_index_(0) { | 77 current_index_(0) { |
79 map_layer_rect_ = picture->layer_rect_; | 78 gfx::Rect layer_rect = picture->layer_rect_; |
80 DCHECK(!target_pixel_ref_map_->cell_size_.IsEmpty()); | 79 gfx::Size cell_size = target_pixel_ref_map_->cell_size_; |
81 PointToFirstPixelRef(rect); | 80 DCHECK(!cell_size.IsEmpty()); |
82 } | 81 gfx::Rect query_rect(rect); |
| 82 // Early out if the query rect doesn't intersect this picture. |
| 83 if (!query_rect.Intersects(layer_rect)) { |
| 84 min_point_ = gfx::Point(0, 0); |
| 85 max_point_ = gfx::Point(0, 0); |
| 86 current_x_ = 1; |
| 87 current_y_ = 1; |
| 88 return; |
| 89 } |
83 | 90 |
84 PixelRefMap::Iterator::Iterator(const gfx::Rect& rect, | 91 // First, subtract the layer origin as cells are stored in layer space. |
85 const DisplayItemList* display_list) | 92 query_rect.Offset(-layer_rect.OffsetFromOrigin()); |
86 : target_pixel_ref_map_(display_list->pixel_refs_.get()), | 93 |
87 current_pixel_refs_(empty_pixel_refs_.Pointer()), | 94 // We have to find a cell_size aligned point that corresponds to |
88 current_index_(0) { | 95 // query_rect. Point is a multiple of cell_size. |
89 map_layer_rect_ = display_list->layer_rect_; | 96 min_point_ = gfx::Point(RoundDown(query_rect.x(), cell_size.width()), |
90 DCHECK(!target_pixel_ref_map_->cell_size_.IsEmpty()); | 97 RoundDown(query_rect.y(), cell_size.height())); |
91 PointToFirstPixelRef(rect); | 98 max_point_ = |
| 99 gfx::Point(RoundDown(query_rect.right() - 1, cell_size.width()), |
| 100 RoundDown(query_rect.bottom() - 1, cell_size.height())); |
| 101 |
| 102 // Limit the points to known pixel ref boundaries. |
| 103 min_point_ = gfx::Point( |
| 104 std::max(min_point_.x(), target_pixel_ref_map_->min_pixel_cell_.x()), |
| 105 std::max(min_point_.y(), target_pixel_ref_map_->min_pixel_cell_.y())); |
| 106 max_point_ = gfx::Point( |
| 107 std::min(max_point_.x(), target_pixel_ref_map_->max_pixel_cell_.x()), |
| 108 std::min(max_point_.y(), target_pixel_ref_map_->max_pixel_cell_.y())); |
| 109 |
| 110 // Make the current x be cell_size.width() less than min point, so that |
| 111 // the first increment will point at min_point_. |
| 112 current_x_ = min_point_.x() - cell_size.width(); |
| 113 current_y_ = min_point_.y(); |
| 114 if (current_y_ <= max_point_.y()) |
| 115 ++(*this); |
92 } | 116 } |
93 | 117 |
94 PixelRefMap::Iterator::~Iterator() { | 118 PixelRefMap::Iterator::~Iterator() { |
95 } | 119 } |
96 | 120 |
97 PixelRefMap::Iterator& PixelRefMap::Iterator::operator++() { | 121 PixelRefMap::Iterator& PixelRefMap::Iterator::operator++() { |
98 ++current_index_; | 122 ++current_index_; |
99 // If we're not at the end of the list, then we have the next item. | 123 // If we're not at the end of the list, then we have the next item. |
100 if (current_index_ < current_pixel_refs_->size()) | 124 if (current_index_ < current_pixel_refs_->size()) |
101 return *this; | 125 return *this; |
(...skipping 22 matching lines...) Expand all Loading... |
124 continue; | 148 continue; |
125 | 149 |
126 // We found a non-empty list: store it and get the first pixel ref. | 150 // We found a non-empty list: store it and get the first pixel ref. |
127 current_pixel_refs_ = &iter->second; | 151 current_pixel_refs_ = &iter->second; |
128 current_index_ = 0; | 152 current_index_ = 0; |
129 break; | 153 break; |
130 } | 154 } |
131 return *this; | 155 return *this; |
132 } | 156 } |
133 | 157 |
134 void PixelRefMap::Iterator::PointToFirstPixelRef(const gfx::Rect& rect) { | |
135 gfx::Rect query_rect(rect); | |
136 // Early out if the query rect doesn't intersect this picture. | |
137 if (!query_rect.Intersects(map_layer_rect_)) { | |
138 min_point_ = gfx::Point(0, 0); | |
139 max_point_ = gfx::Point(0, 0); | |
140 current_x_ = 1; | |
141 current_y_ = 1; | |
142 return; | |
143 } | |
144 | |
145 // First, subtract the layer origin as cells are stored in layer space. | |
146 query_rect.Offset(-map_layer_rect_.OffsetFromOrigin()); | |
147 | |
148 gfx::Size cell_size(target_pixel_ref_map_->cell_size_); | |
149 // We have to find a cell_size aligned point that corresponds to | |
150 // query_rect. Point is a multiple of cell_size. | |
151 min_point_ = gfx::Point(RoundDown(query_rect.x(), cell_size.width()), | |
152 RoundDown(query_rect.y(), cell_size.height())); | |
153 max_point_ = | |
154 gfx::Point(RoundDown(query_rect.right() - 1, cell_size.width()), | |
155 RoundDown(query_rect.bottom() - 1, cell_size.height())); | |
156 | |
157 // Limit the points to known pixel ref boundaries. | |
158 min_point_ = gfx::Point( | |
159 std::max(min_point_.x(), target_pixel_ref_map_->min_pixel_cell_.x()), | |
160 std::max(min_point_.y(), target_pixel_ref_map_->min_pixel_cell_.y())); | |
161 max_point_ = gfx::Point( | |
162 std::min(max_point_.x(), target_pixel_ref_map_->max_pixel_cell_.x()), | |
163 std::min(max_point_.y(), target_pixel_ref_map_->max_pixel_cell_.y())); | |
164 | |
165 // Make the current x be cell_size.width() less than min point, so that | |
166 // the first increment will point at min_point_. | |
167 current_x_ = min_point_.x() - cell_size.width(); | |
168 current_y_ = min_point_.y(); | |
169 if (current_y_ <= max_point_.y()) | |
170 ++(*this); | |
171 } | |
172 | |
173 } // namespace cc | 158 } // namespace cc |
OLD | NEW |