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

Side by Side Diff: cc/resources/pixel_ref_map.cc

Issue 1050103003: Revert of Revert of Implement DisplayList GatherPixelRefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « cc/resources/pixel_ref_map.h ('k') | cc/resources/recording_source_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "cc/resources/picture.h" 12 #include "cc/resources/picture.h"
12 #include "skia/ext/pixel_ref_utils.h" 13 #include "skia/ext/pixel_ref_utils.h"
13 14
14 namespace cc { 15 namespace cc {
15 16
16 PixelRefMap::PixelRefMap(const gfx::Size& cell_size) : cell_size_(cell_size) { 17 PixelRefMap::PixelRefMap(const gfx::Size& cell_size) : cell_size_(cell_size) {
17 DCHECK(!cell_size.IsEmpty()); 18 DCHECK(!cell_size.IsEmpty());
18 } 19 }
19 20
20 PixelRefMap::~PixelRefMap() { 21 PixelRefMap::~PixelRefMap() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 min_point_(-1, -1), 69 min_point_(-1, -1),
69 max_point_(-1, -1), 70 max_point_(-1, -1),
70 current_x_(0), 71 current_x_(0),
71 current_y_(0) { 72 current_y_(0) {
72 } 73 }
73 74
74 PixelRefMap::Iterator::Iterator(const gfx::Rect& rect, const Picture* picture) 75 PixelRefMap::Iterator::Iterator(const gfx::Rect& rect, const Picture* picture)
75 : target_pixel_ref_map_(&(picture->pixel_refs_)), 76 : target_pixel_ref_map_(&(picture->pixel_refs_)),
76 current_pixel_refs_(empty_pixel_refs_.Pointer()), 77 current_pixel_refs_(empty_pixel_refs_.Pointer()),
77 current_index_(0) { 78 current_index_(0) {
78 gfx::Rect layer_rect = picture->layer_rect_; 79 map_layer_rect_ = picture->layer_rect_;
79 gfx::Size cell_size = target_pixel_ref_map_->cell_size_; 80 DCHECK(!target_pixel_ref_map_->cell_size_.IsEmpty());
80 DCHECK(!cell_size.IsEmpty()); 81 PointToFirstPixelRef(rect);
81 gfx::Rect query_rect(rect); 82 }
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 }
90 83
91 // First, subtract the layer origin as cells are stored in layer space. 84 PixelRefMap::Iterator::Iterator(const gfx::Rect& rect,
92 query_rect.Offset(-layer_rect.OffsetFromOrigin()); 85 const DisplayItemList* display_list)
93 86 : target_pixel_ref_map_(display_list->pixel_refs_.get()),
94 // We have to find a cell_size aligned point that corresponds to 87 current_pixel_refs_(empty_pixel_refs_.Pointer()),
95 // query_rect. Point is a multiple of cell_size. 88 current_index_(0) {
96 min_point_ = gfx::Point(RoundDown(query_rect.x(), cell_size.width()), 89 map_layer_rect_ = display_list->layer_rect_;
97 RoundDown(query_rect.y(), cell_size.height())); 90 DCHECK(!target_pixel_ref_map_->cell_size_.IsEmpty());
98 max_point_ = 91 PointToFirstPixelRef(rect);
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);
116 } 92 }
117 93
118 PixelRefMap::Iterator::~Iterator() { 94 PixelRefMap::Iterator::~Iterator() {
119 } 95 }
120 96
121 PixelRefMap::Iterator& PixelRefMap::Iterator::operator++() { 97 PixelRefMap::Iterator& PixelRefMap::Iterator::operator++() {
122 ++current_index_; 98 ++current_index_;
123 // If we're not at the end of the list, then we have the next item. 99 // If we're not at the end of the list, then we have the next item.
124 if (current_index_ < current_pixel_refs_->size()) 100 if (current_index_ < current_pixel_refs_->size())
125 return *this; 101 return *this;
(...skipping 22 matching lines...) Expand all
148 continue; 124 continue;
149 125
150 // We found a non-empty list: store it and get the first pixel ref. 126 // We found a non-empty list: store it and get the first pixel ref.
151 current_pixel_refs_ = &iter->second; 127 current_pixel_refs_ = &iter->second;
152 current_index_ = 0; 128 current_index_ = 0;
153 break; 129 break;
154 } 130 }
155 return *this; 131 return *this;
156 } 132 }
157 133
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
158 } // namespace cc 173 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/pixel_ref_map.h ('k') | cc/resources/recording_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698