OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layer_tiling_data.h" | 5 #include "cc/resources/layer_tiling_data.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } | 59 } |
60 | 60 |
61 scoped_ptr<LayerTilingData::Tile> LayerTilingData::TakeTile(int i, int j) { | 61 scoped_ptr<LayerTilingData::Tile> LayerTilingData::TakeTile(int i, int j) { |
62 return tiles_.take_and_erase(std::make_pair(i, j)); | 62 return tiles_.take_and_erase(std::make_pair(i, j)); |
63 } | 63 } |
64 | 64 |
65 LayerTilingData::Tile* LayerTilingData::TileAt(int i, int j) const { | 65 LayerTilingData::Tile* LayerTilingData::TileAt(int i, int j) const { |
66 return tiles_.get(std::make_pair(i, j)); | 66 return tiles_.get(std::make_pair(i, j)); |
67 } | 67 } |
68 | 68 |
69 void LayerTilingData::ContentRectToTileIndices(gfx::Rect content_rect, | 69 void LayerTilingData::ContentRectToTileIndices(const gfx::Rect& content_rect, |
70 int* left, | 70 int* left, |
71 int* top, | 71 int* top, |
72 int* right, | 72 int* right, |
73 int* bottom) const { | 73 int* bottom) const { |
74 // An empty rect doesn't result in an empty set of tiles, so don't pass an | 74 // An empty rect doesn't result in an empty set of tiles, so don't pass an |
75 // empty rect. | 75 // empty rect. |
76 // TODO(enne): Possibly we should fill a vector of tiles instead, since the | 76 // TODO(enne): Possibly we should fill a vector of tiles instead, since the |
77 // normal use of this function is to enumerate some tiles. | 77 // normal use of this function is to enumerate some tiles. |
78 DCHECK(!content_rect.IsEmpty()); | 78 DCHECK(!content_rect.IsEmpty()); |
79 | 79 |
80 *left = tiling_data_.TileXIndexFromSrcCoord(content_rect.x()); | 80 *left = tiling_data_.TileXIndexFromSrcCoord(content_rect.x()); |
81 *top = tiling_data_.TileYIndexFromSrcCoord(content_rect.y()); | 81 *top = tiling_data_.TileYIndexFromSrcCoord(content_rect.y()); |
82 *right = tiling_data_.TileXIndexFromSrcCoord(content_rect.right() - 1); | 82 *right = tiling_data_.TileXIndexFromSrcCoord(content_rect.right() - 1); |
83 *bottom = tiling_data_.TileYIndexFromSrcCoord(content_rect.bottom() - 1); | 83 *bottom = tiling_data_.TileYIndexFromSrcCoord(content_rect.bottom() - 1); |
84 } | 84 } |
85 | 85 |
86 gfx::Rect LayerTilingData::TileRect(const Tile* tile) const { | 86 gfx::Rect LayerTilingData::TileRect(const Tile* tile) const { |
87 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(tile->i(), tile->j()); | 87 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(tile->i(), tile->j()); |
88 tile_rect.set_size(tile_size()); | 88 tile_rect.set_size(tile_size()); |
89 return tile_rect; | 89 return tile_rect; |
90 } | 90 } |
91 | 91 |
92 Region LayerTilingData::OpaqueRegionInContentRect( | 92 Region LayerTilingData::OpaqueRegionInContentRect( |
93 gfx::Rect content_rect) const { | 93 const gfx::Rect& content_rect) const { |
94 if (content_rect.IsEmpty()) | 94 if (content_rect.IsEmpty()) |
95 return Region(); | 95 return Region(); |
96 | 96 |
97 Region opaque_region; | 97 Region opaque_region; |
98 int left, top, right, bottom; | 98 int left, top, right, bottom; |
99 ContentRectToTileIndices(content_rect, &left, &top, &right, &bottom); | 99 ContentRectToTileIndices(content_rect, &left, &top, &right, &bottom); |
100 for (int j = top; j <= bottom; ++j) { | 100 for (int j = top; j <= bottom; ++j) { |
101 for (int i = left; i <= right; ++i) { | 101 for (int i = left; i <= right; ++i) { |
102 Tile* tile = TileAt(i, j); | 102 Tile* tile = TileAt(i, j); |
103 if (!tile) | 103 if (!tile) |
(...skipping 22 matching lines...) Expand all Loading... |
126 std::vector<TileMapKey> invalid_tile_keys; | 126 std::vector<TileMapKey> invalid_tile_keys; |
127 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 127 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
128 if (it->first.first > right || it->first.second > bottom) | 128 if (it->first.first > right || it->first.second > bottom) |
129 invalid_tile_keys.push_back(it->first); | 129 invalid_tile_keys.push_back(it->first); |
130 } | 130 } |
131 for (size_t i = 0; i < invalid_tile_keys.size(); ++i) | 131 for (size_t i = 0; i < invalid_tile_keys.size(); ++i) |
132 tiles_.erase(invalid_tile_keys[i]); | 132 tiles_.erase(invalid_tile_keys[i]); |
133 } | 133 } |
134 | 134 |
135 } // namespace cc | 135 } // namespace cc |
OLD | NEW |