Chromium Code Reviews| 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" |
| 11 #include "cc/playback/display_item_list.h" | 11 #include "cc/playback/display_item_list.h" |
| 12 #include "cc/playback/picture.h" | 12 #include "cc/playback/picture.h" |
| 13 #include "skia/ext/pixel_ref_utils.h" | 13 #include "skia/ext/pixel_ref_utils.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 PixelRefMap::PixelRefMap(const gfx::Size& cell_size) : cell_size_(cell_size) { | 17 PixelRefMap::PixelRefMap(const gfx::Size& cell_size) : cell_size_(cell_size) { |
| 18 DCHECK(!cell_size.IsEmpty()); | 18 DCHECK(!cell_size.IsEmpty()); |
| 19 } | 19 } |
| 20 | 20 |
| 21 PixelRefMap::~PixelRefMap() { | 21 PixelRefMap::~PixelRefMap() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 void PixelRefMap::GatherPixelRefsFromPicture(SkPicture* picture) { | 24 void PixelRefMap::GatherPixelRefsFromPicture(SkPicture* picture, |
| 25 const gfx::Rect& layer_rect) { | |
| 25 DCHECK(picture); | 26 DCHECK(picture); |
| 26 | 27 |
| 27 int min_x = std::numeric_limits<int>::max(); | 28 int min_x = std::numeric_limits<int>::max(); |
| 28 int min_y = std::numeric_limits<int>::max(); | 29 int min_y = std::numeric_limits<int>::max(); |
| 29 int max_x = 0; | 30 int max_x = 0; |
| 30 int max_y = 0; | 31 int max_y = 0; |
| 31 | 32 |
| 32 skia::DiscardablePixelRefList pixel_refs; | 33 skia::DiscardablePixelRefList pixel_refs; |
| 33 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture, &pixel_refs); | 34 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture, &pixel_refs); |
| 34 for (skia::DiscardablePixelRefList::const_iterator it = pixel_refs.begin(); | 35 for (skia::DiscardablePixelRefList::const_iterator it = pixel_refs.begin(); |
| 35 it != pixel_refs.end(); ++it) { | 36 it != pixel_refs.end(); ++it) { |
| 36 gfx::Point min( | 37 gfx::Point min( |
| 37 MathUtil::UncheckedRoundDown(static_cast<int>(it->pixel_ref_rect.x()), | 38 MathUtil::UncheckedRoundDown(static_cast<int>(it->pixel_ref_rect.x()), |
| 38 cell_size_.width()), | 39 cell_size_.width()), |
| 39 MathUtil::UncheckedRoundDown(static_cast<int>(it->pixel_ref_rect.y()), | 40 MathUtil::UncheckedRoundDown(static_cast<int>(it->pixel_ref_rect.y()), |
| 40 cell_size_.height())); | 41 cell_size_.height())); |
| 41 gfx::Point max(MathUtil::UncheckedRoundDown( | 42 gfx::Point max(MathUtil::UncheckedRoundDown( |
| 42 static_cast<int>(std::ceil(it->pixel_ref_rect.right())), | 43 static_cast<int>(std::ceil(it->pixel_ref_rect.right())), |
| 43 cell_size_.width()), | 44 cell_size_.width()), |
| 44 MathUtil::UncheckedRoundDown( | 45 MathUtil::UncheckedRoundDown( |
| 45 static_cast<int>(std::ceil(it->pixel_ref_rect.bottom())), | 46 static_cast<int>(std::ceil(it->pixel_ref_rect.bottom())), |
| 46 cell_size_.height())); | 47 cell_size_.height())); |
| 47 | 48 |
| 49 // We recorded the picture as if it was at (0, 0) by translating by layer | |
|
weiliangc
2015/08/07 22:56:00
Do you mean in skia::PixelRefUtils::GatherDiscarda
vmpstr
2015/08/10 17:36:05
No I mean here at record time when we record the p
| |
| 50 // rect origin. However, now the matrix stores this offset, and the rect is | |
| 51 // also offset. Add the rect origin back here. It really doesn't make much | |
| 52 // of a difference, since the query for pixel refs doesn't use this | |
| 53 // information. However, since picture pile / display list also returns this | |
| 54 // information, it would be nice to express it relative to the layer, not | |
| 55 // relative to the particular implementation of the raster source. | |
| 56 skia::PositionPixelRef position_pixel_ref = *it; | |
| 57 position_pixel_ref.pixel_ref_rect.setXYWH( | |
| 58 position_pixel_ref.pixel_ref_rect.x() + layer_rect.x(), | |
| 59 position_pixel_ref.pixel_ref_rect.y() + layer_rect.y(), | |
| 60 position_pixel_ref.pixel_ref_rect.width(), | |
| 61 position_pixel_ref.pixel_ref_rect.height()); | |
| 62 | |
| 63 // The pixel refs are relative to the picture origin, but we want to store | |
| 64 // positions here | |
|
ericrk
2015/08/07 00:33:56
nit: This second comment is a bit hard to follow.
vmpstr
2015/08/10 17:36:05
Ya sorry this was an unfinished comment that evolv
| |
| 48 for (int y = min.y(); y <= max.y(); y += cell_size_.height()) { | 65 for (int y = min.y(); y <= max.y(); y += cell_size_.height()) { |
| 49 for (int x = min.x(); x <= max.x(); x += cell_size_.width()) { | 66 for (int x = min.x(); x <= max.x(); x += cell_size_.width()) { |
| 50 PixelRefMapKey key(x, y); | 67 PixelRefMapKey key(x, y); |
| 51 data_hash_map_[key].push_back(it->pixel_ref); | 68 data_hash_map_[key].push_back(position_pixel_ref); |
| 52 } | 69 } |
| 53 } | 70 } |
| 54 | 71 |
| 55 min_x = std::min(min_x, min.x()); | 72 min_x = std::min(min_x, min.x()); |
| 56 min_y = std::min(min_y, min.y()); | 73 min_y = std::min(min_y, min.y()); |
| 57 max_x = std::max(max_x, max.x()); | 74 max_x = std::max(max_x, max.x()); |
| 58 max_y = std::max(max_y, max.y()); | 75 max_y = std::max(max_y, max.y()); |
| 59 } | 76 } |
| 60 | 77 |
| 61 min_pixel_cell_ = gfx::Point(min_x, min_y); | 78 min_pixel_cell_ = gfx::Point(min_x, min_y); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 | 184 |
| 168 // Make the current x be cell_size.width() less than min point, so that | 185 // Make the current x be cell_size.width() less than min point, so that |
| 169 // the first increment will point at min_point_. | 186 // the first increment will point at min_point_. |
| 170 current_x_ = min_point_.x() - cell_size.width(); | 187 current_x_ = min_point_.x() - cell_size.width(); |
| 171 current_y_ = min_point_.y(); | 188 current_y_ = min_point_.y(); |
| 172 if (current_y_ <= max_point_.y()) | 189 if (current_y_ <= max_point_.y()) |
| 173 ++(*this); | 190 ++(*this); |
| 174 } | 191 } |
| 175 | 192 |
| 176 } // namespace cc | 193 } // namespace cc |
| OLD | NEW |