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

Side by Side Diff: cc/layer_tiling_data.cc

Issue 12471007: Part 8 of cc/ directory shuffles: resources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « cc/layer_tiling_data.h ('k') | cc/layer_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/layer_tiling_data.h"
6
7 #include "base/logging.h"
8
9 namespace cc {
10
11 scoped_ptr<LayerTilingData> LayerTilingData::Create(gfx::Size tile_size,
12 BorderTexelOption border) {
13 return make_scoped_ptr(new LayerTilingData(tile_size, border));
14 }
15
16 LayerTilingData::LayerTilingData(gfx::Size tile_size, BorderTexelOption border)
17 : tiling_data_(tile_size, gfx::Size(), border == HAS_BORDER_TEXELS) {
18 SetTileSize(tile_size);
19 }
20
21 LayerTilingData::~LayerTilingData() {}
22
23 void LayerTilingData::SetTileSize(gfx::Size size) {
24 if (tile_size() == size)
25 return;
26
27 reset();
28
29 tiling_data_.SetMaxTextureSize(size);
30 }
31
32 gfx::Size LayerTilingData::tile_size() const {
33 return tiling_data_.max_texture_size();
34 }
35
36 void LayerTilingData::SetBorderTexelOption(
37 BorderTexelOption border_texel_option) {
38 bool border_texels = border_texel_option == HAS_BORDER_TEXELS;
39 if (has_border_texels() == border_texels)
40 return;
41
42 reset();
43 tiling_data_.SetHasBorderTexels(border_texels);
44 }
45
46 const LayerTilingData& LayerTilingData::operator=
47 (const LayerTilingData & tiler) {
48 tiling_data_ = tiler.tiling_data_;
49
50 return *this;
51 }
52
53 void LayerTilingData::AddTile(scoped_ptr<Tile> tile, int i, int j) {
54 DCHECK(!TileAt(i, j));
55 tile->move_to(i, j);
56 tiles_.add(std::make_pair(i, j), tile.Pass());
57 }
58
59 scoped_ptr<LayerTilingData::Tile> LayerTilingData::TakeTile(int i, int j) {
60 return tiles_.take_and_erase(std::make_pair(i, j));
61 }
62
63 LayerTilingData::Tile* LayerTilingData::TileAt(int i, int j) const {
64 return tiles_.get(std::make_pair(i, j));
65 }
66
67 void LayerTilingData::ContentRectToTileIndices(gfx::Rect content_rect,
68 int* left,
69 int* top,
70 int* right,
71 int* bottom) const {
72 // An empty rect doesn't result in an empty set of tiles, so don't pass an
73 // empty rect.
74 // FIXME: Possibly we should fill a vector of tiles instead,
75 // since the normal use of this function is to enumerate some tiles.
76 DCHECK(!content_rect.IsEmpty());
77
78 *left = tiling_data_.TileXIndexFromSrcCoord(content_rect.x());
79 *top = tiling_data_.TileYIndexFromSrcCoord(content_rect.y());
80 *right = tiling_data_.TileXIndexFromSrcCoord(content_rect.right() - 1);
81 *bottom = tiling_data_.TileYIndexFromSrcCoord(content_rect.bottom() - 1);
82 }
83
84 gfx::Rect LayerTilingData::TileRect(const Tile* tile) const {
85 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(tile->i(), tile->j());
86 tile_rect.set_size(tile_size());
87 return tile_rect;
88 }
89
90 Region LayerTilingData::OpaqueRegionInContentRect(
91 gfx::Rect content_rect) const {
92 if (content_rect.IsEmpty())
93 return Region();
94
95 Region opaque_region;
96 int left, top, right, bottom;
97 ContentRectToTileIndices(content_rect, &left, &top, &right, &bottom);
98 for (int j = top; j <= bottom; ++j) {
99 for (int i = left; i <= right; ++i) {
100 Tile* tile = TileAt(i, j);
101 if (!tile)
102 continue;
103
104 gfx::Rect tile_opaque_rect =
105 gfx::IntersectRects(content_rect, tile->opaque_rect());
106 opaque_region.Union(tile_opaque_rect);
107 }
108 }
109 return opaque_region;
110 }
111
112 void LayerTilingData::SetBounds(gfx::Size size) {
113 tiling_data_.SetTotalSize(size);
114 if (size.IsEmpty()) {
115 tiles_.clear();
116 return;
117 }
118
119 // Any tiles completely outside our new bounds are invalid and should be
120 // dropped.
121 int left, top, right, bottom;
122 ContentRectToTileIndices(
123 gfx::Rect(gfx::Point(), size), &left, &top, &right, &bottom);
124 std::vector<TileMapKey> invalid_tile_keys;
125 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
126 if (it->first.first > right || it->first.second > bottom)
127 invalid_tile_keys.push_back(it->first);
128 }
129 for (size_t i = 0; i < invalid_tile_keys.size(); ++i)
130 tiles_.erase(invalid_tile_keys[i]);
131 }
132
133 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer_tiling_data.h ('k') | cc/layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698