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

Side by Side Diff: cc/picture_layer_tiling.cc

Issue 11377176: cc: Add PictureLayerTiling for impl-side painting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win builder /o\ Created 8 years, 1 month 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/picture_layer_tiling.h ('k') | cc/tile.h » ('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 2012 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/picture_layer_tiling.h"
6
7 namespace cc {
8
9 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create(
10 gfx::Size tile_size) {
11 return make_scoped_ptr(new PictureLayerTiling(tile_size));
12 }
13
14 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Clone() const {
15 return make_scoped_ptr(new PictureLayerTiling(*this));
16 }
17
18 PictureLayerTiling::PictureLayerTiling(gfx::Size tile_size)
19 : client_(NULL),
20 tiling_data_(tile_size, gfx::Size(), true) {
21 }
22
23 PictureLayerTiling::~PictureLayerTiling() {
24 }
25
26 const PictureLayerTiling& PictureLayerTiling::operator=(
27 const PictureLayerTiling& tiler) {
28 tiling_data_ = tiler.tiling_data_;
29 tiles_ = tiler.tiles_;
30 return *this;
31 }
32
33 void PictureLayerTiling::create_tiles(gfx::Rect rect) {
34 for (Iterator iter(this, rect); iter; ++iter) {
35 if (*iter)
36 continue;
37 tiles_[std::make_pair(iter.tile_i_, iter.tile_j_)] =
38 client_->CreateTile(this, iter.full_tile_rect());
39 }
40 }
41
42 void PictureLayerTiling::set_client(PictureLayerTilingClient* client) {
43 client_ = client;
44 }
45
46 Tile* PictureLayerTiling::TileAt(int i, int j) const {
47 TileMap::const_iterator iter = tiles_.find(std::make_pair(i, j));
48 if (iter == tiles_.end())
49 return NULL;
50 return iter->second.get();
51 }
52
53 Region PictureLayerTiling::OpaqueRegionInContentRect(
54 const gfx::Rect& content_rect) const {
55 Region opaque_region;
56 // TODO(enne): implement me
57 return opaque_region;
58 }
59
60 void PictureLayerTiling::SetBounds(gfx::Size size) {
61 tiling_data_.SetTotalSize(size);
62 if (size.IsEmpty()) {
63 tiles_.clear();
64 return;
65 }
66
67 // Any tiles outside our new bounds are invalid and should be dropped.
68 int right = tiling_data_.TileXIndexFromSrcCoord(size.width() - 1);
69 int bottom = tiling_data_.TileYIndexFromSrcCoord(size.height() - 1);
70 std::vector<TileMapKey> invalid_tile_keys;
71 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
72 if (it->first.first > right || it->first.second > bottom)
73 invalid_tile_keys.push_back(it->first);
74 }
75 for (size_t i = 0; i < invalid_tile_keys.size(); ++i)
76 tiles_.erase(invalid_tile_keys[i]);
77 }
78
79 PictureLayerTiling::Iterator::Iterator(PictureLayerTiling* tiling,
80 gfx::Rect content_rect)
81 : tiling_(tiling),
82 content_rect_(content_rect),
83 current_tile_(NULL),
84 tile_i_(0),
85 tile_j_(0),
86 left_(0),
87 top_(0),
88 right_(0),
89 bottom_(0) {
90 DCHECK(tiling_);
91 if (content_rect_.IsEmpty())
92 return;
93
94 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x());
95 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y());
96 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(
97 content_rect.right() - 1);
98 bottom_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(
99 content_rect.bottom() - 1);
100
101 tile_i_ = left_;
102 tile_j_ = top_;
103 current_tile_ = tiling_->TileAt(tile_i_, tile_j_);
104 }
105
106 PictureLayerTiling::Iterator::~Iterator() {
107 }
108
109 PictureLayerTiling::Iterator& PictureLayerTiling::Iterator::operator++() {
110 if (!current_tile_)
111 return *this;
112
113 do {
114 tile_i_++;
115 if (tile_i_ > right_) {
116 tile_i_ = left_;
117 tile_j_++;
118 if (tile_j_ > top_)
119 current_tile_ = NULL;
120 return *this;
121 }
122 } while (!geometry_rect().IsEmpty());
123
124 current_tile_ = tiling_->TileAt(tile_i_, tile_j_);
125 return *this;
126 }
127
128 gfx::Rect PictureLayerTiling::Iterator::geometry_rect() const {
129 gfx::Rect geometry_rect = tiling_->tiling_data_.TileBounds(tile_i_, tile_j_);
130 geometry_rect.Intersect(content_rect_);
131 return geometry_rect;
132 }
133
134 gfx::Rect PictureLayerTiling::Iterator::full_tile_rect() const {
135 gfx::Rect tile_rect =
136 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_);
137 tile_rect.set_size(texture_size());
138 return tile_rect;
139 }
140
141 gfx::Rect PictureLayerTiling::Iterator::texture_rect() const {
142 gfx::Rect full_bounds = tiling_->tiling_data_.TileBounds(tile_i_, tile_j_);
143 gfx::Rect visible = geometry_rect();
144 gfx::Vector2d display_offset = visible.origin() - full_bounds.origin();
145 gfx::Vector2d offset = visible.origin() - full_bounds.origin();
146 offset += tiling_->tiling_data_.TextureOffset(tile_i_, tile_j_);
147
148 return gfx::Rect(gfx::PointAtOffsetFromOrigin(offset), visible.size());
149 }
150
151 gfx::Rect PictureLayerTiling::Iterator::opaque_rect() const {
152 gfx::Rect opaque_rect;
153 opaque_rect = current_tile_->opaque_rect();
154 opaque_rect.Intersect(content_rect_);
155 return opaque_rect;
156 }
157
158 gfx::Size PictureLayerTiling::Iterator::texture_size() const {
159 return tiling_->tiling_data_.max_texture_size();
160 }
161
162 bool PictureLayerTiling::Iterator::operator==(const Iterator& other) const {
163 return tiling_ == other.tiling_ && current_tile_ == other.current_tile_;
164 }
165
166 bool PictureLayerTiling::Iterator::operator!=(const Iterator& other) const {
167 return !(*this == other);
168 }
169
170 } // namespace cc
OLDNEW
« no previous file with comments | « cc/picture_layer_tiling.h ('k') | cc/tile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698