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 #include "cc/base/region.h" | 10 #include "cc/base/region.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 *right = tiling_data_.TileXIndexFromSrcCoord(content_rect.right() - 1); | 85 *right = tiling_data_.TileXIndexFromSrcCoord(content_rect.right() - 1); |
86 *bottom = tiling_data_.TileYIndexFromSrcCoord(content_rect.bottom() - 1); | 86 *bottom = tiling_data_.TileYIndexFromSrcCoord(content_rect.bottom() - 1); |
87 } | 87 } |
88 | 88 |
89 gfx::Rect LayerTilingData::TileRect(const Tile* tile) const { | 89 gfx::Rect LayerTilingData::TileRect(const Tile* tile) const { |
90 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(tile->i(), tile->j()); | 90 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(tile->i(), tile->j()); |
91 tile_rect.set_size(tile_size()); | 91 tile_rect.set_size(tile_size()); |
92 return tile_rect; | 92 return tile_rect; |
93 } | 93 } |
94 | 94 |
95 SimpleEnclosedRegion LayerTilingData::OpaqueRegionInContentRect( | |
96 const gfx::Rect& content_rect) const { | |
97 if (content_rect.IsEmpty()) | |
98 return SimpleEnclosedRegion(); | |
99 | |
100 Region opaque_region; | |
101 int left, top, right, bottom; | |
102 ContentRectToTileIndices(content_rect, &left, &top, &right, &bottom); | |
103 for (int j = top; j <= bottom; ++j) { | |
104 for (int i = left; i <= right; ++i) { | |
105 Tile* tile = TileAt(i, j); | |
106 if (!tile) | |
107 continue; | |
108 | |
109 gfx::Rect tile_opaque_rect = | |
110 gfx::IntersectRects(content_rect, tile->opaque_rect()); | |
111 opaque_region.Union(tile_opaque_rect); | |
112 } | |
113 } | |
114 return SimpleEnclosedRegion(opaque_region); | |
115 } | |
116 | |
117 void LayerTilingData::SetTilingSize(const gfx::Size& tiling_size) { | 95 void LayerTilingData::SetTilingSize(const gfx::Size& tiling_size) { |
118 tiling_data_.SetTilingSize(tiling_size); | 96 tiling_data_.SetTilingSize(tiling_size); |
119 if (tiling_size.IsEmpty()) { | 97 if (tiling_size.IsEmpty()) { |
120 tiles_.clear(); | 98 tiles_.clear(); |
121 return; | 99 return; |
122 } | 100 } |
123 | 101 |
124 // Any tiles completely outside our new bounds are invalid and should be | 102 // Any tiles completely outside our new bounds are invalid and should be |
125 // dropped. | 103 // dropped. |
126 int left, top, right, bottom; | 104 int left, top, right, bottom; |
127 ContentRectToTileIndices( | 105 ContentRectToTileIndices( |
128 gfx::Rect(tiling_size), &left, &top, &right, &bottom); | 106 gfx::Rect(tiling_size), &left, &top, &right, &bottom); |
129 std::vector<TileMapKey> invalid_tile_keys; | 107 std::vector<TileMapKey> invalid_tile_keys; |
130 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 108 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
131 if (it->first.first > right || it->first.second > bottom) | 109 if (it->first.first > right || it->first.second > bottom) |
132 invalid_tile_keys.push_back(it->first); | 110 invalid_tile_keys.push_back(it->first); |
133 } | 111 } |
134 for (size_t i = 0; i < invalid_tile_keys.size(); ++i) | 112 for (size_t i = 0; i < invalid_tile_keys.size(); ++i) |
135 tiles_.erase(invalid_tile_keys[i]); | 113 tiles_.erase(invalid_tile_keys[i]); |
136 } | 114 } |
137 | 115 |
138 } // namespace cc | 116 } // namespace cc |
OLD | NEW |