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