OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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/picture_layer_impl.h" | 5 #include "cc/picture_layer_impl.h" |
6 | 6 |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "cc/append_quads_data.h" | 8 #include "cc/append_quads_data.h" |
9 #include "cc/checkerboard_draw_quad.h" | 9 #include "cc/checkerboard_draw_quad.h" |
10 #include "cc/debug_border_draw_quad.h" | 10 #include "cc/debug_border_draw_quad.h" |
11 #include "cc/debug_colors.h" | 11 #include "cc/debug_colors.h" |
12 #include "cc/layer_tree_impl.h" | 12 #include "cc/layer_tree_impl.h" |
13 #include "cc/math_util.h" | 13 #include "cc/math_util.h" |
14 #include "cc/quad_sink.h" | 14 #include "cc/quad_sink.h" |
15 #include "cc/solid_color_draw_quad.h" | 15 #include "cc/solid_color_draw_quad.h" |
16 #include "cc/tile_draw_quad.h" | 16 #include "cc/tile_draw_quad.h" |
17 #include "ui/gfx/quad_f.h" | 17 #include "ui/gfx/quad_f.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
21 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* treeImpl, int id) | 21 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* treeImpl, int id) |
22 : LayerImpl(treeImpl, id), | 22 : LayerImpl(treeImpl, id), |
23 tilings_(this), | 23 tilings_(this), |
24 pile_(PicturePileImpl::Create()), | 24 pile_(PicturePileImpl::Create()), |
25 last_update_time_(0) { | 25 last_update_time_(0), |
| 26 is_mask_(false) { |
26 } | 27 } |
27 | 28 |
28 PictureLayerImpl::~PictureLayerImpl() { | 29 PictureLayerImpl::~PictureLayerImpl() { |
29 } | 30 } |
30 | 31 |
31 const char* PictureLayerImpl::layerTypeAsString() const { | 32 const char* PictureLayerImpl::layerTypeAsString() const { |
32 return "PictureLayer"; | 33 return "PictureLayer"; |
33 } | 34 } |
34 | 35 |
35 void PictureLayerImpl::appendQuads(QuadSink& quadSink, | 36 void PictureLayerImpl::appendQuads(QuadSink& quadSink, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 126 |
126 void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const { | 127 void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const { |
127 // TODO(enne): implement me | 128 // TODO(enne): implement me |
128 } | 129 } |
129 | 130 |
130 void PictureLayerImpl::didUpdateTransforms() { | 131 void PictureLayerImpl::didUpdateTransforms() { |
131 if (drawsContent()) { | 132 if (drawsContent()) { |
132 // TODO(enne): Add tilings during pinch zoom | 133 // TODO(enne): Add tilings during pinch zoom |
133 // TODO(enne): Consider culling old tilings after pinch finishes. | 134 // TODO(enne): Consider culling old tilings after pinch finishes. |
134 if (!tilings_.num_tilings()) { | 135 if (!tilings_.num_tilings()) { |
135 gfx::Size tile_size = layerTreeImpl()->settings().defaultTileSize; | 136 AddTiling(contentsScaleX(), TileSize()); |
136 AddTiling(contentsScaleX(), tile_size); | |
137 // TODO(enne): Add a low-res tiling as well. | 137 // TODO(enne): Add a low-res tiling as well. |
138 } | 138 } |
139 } else { | 139 } else { |
140 // TODO(enne): This should be unnecessary once there are two trees. | 140 // TODO(enne): This should be unnecessary once there are two trees. |
141 tilings_.Reset(); | 141 tilings_.Reset(); |
142 } | 142 } |
143 | 143 |
144 gfx::Transform current_screen_space_transform = screenSpaceTransform(); | 144 gfx::Transform current_screen_space_transform = |
| 145 screenSpaceTransform(); |
145 double current_time = | 146 double current_time = |
146 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); | 147 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
147 double time_delta = 0; | 148 double time_delta = 0; |
148 if (last_update_time_ != 0 && last_bounds_ == bounds() && | 149 if (last_update_time_ != 0 && last_bounds_ == bounds() && |
149 last_content_bounds_ == contentBounds() && | 150 last_content_bounds_ == contentBounds() && |
150 last_content_scale_x_ == contentsScaleX() && | 151 last_content_scale_x_ == contentsScaleX() && |
151 last_content_scale_y_ == contentsScaleY()) { | 152 last_content_scale_y_ == contentsScaleY()) { |
152 time_delta = current_time - last_update_time_; | 153 time_delta = current_time - last_update_time_; |
153 } | 154 } |
154 WhichTree tree = layerTreeImpl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; | 155 WhichTree tree = layerTreeImpl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; |
155 tilings_.UpdateTilePriorities( | 156 tilings_.UpdateTilePriorities( |
156 tree, | 157 tree, |
157 layerTreeImpl()->device_viewport_size(), | 158 layerTreeImpl()->device_viewport_size(), |
158 contentsScaleX(), | 159 contentsScaleX(), |
159 contentsScaleY(), | 160 contentsScaleY(), |
160 last_screen_space_transform_, | 161 last_screen_space_transform_, |
161 current_screen_space_transform, | 162 current_screen_space_transform, |
162 time_delta); | 163 time_delta); |
163 | 164 |
164 last_screen_space_transform_ = current_screen_space_transform; | 165 last_screen_space_transform_ = current_screen_space_transform; |
165 last_update_time_ = current_time; | 166 last_update_time_ = current_time; |
166 last_bounds_ = bounds(); | 167 last_bounds_ = bounds(); |
167 last_content_bounds_ = contentBounds(); | 168 last_content_bounds_ = contentBounds(); |
168 last_content_scale_x_ = contentsScaleX(); | 169 last_content_scale_x_ = contentsScaleX(); |
169 last_content_scale_y_ = contentsScaleY(); | 170 last_content_scale_y_ = contentsScaleY(); |
170 } | 171 } |
171 | 172 |
172 void PictureLayerImpl::didUpdateBounds() { | 173 void PictureLayerImpl::didUpdateBounds() { |
| 174 if (is_mask_) |
| 175 tilings_.Reset(); |
173 tilings_.SetLayerBounds(bounds()); | 176 tilings_.SetLayerBounds(bounds()); |
174 } | 177 } |
175 | 178 |
176 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, | 179 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, |
177 gfx::Rect rect) { | 180 gfx::Rect rect) { |
178 TileManager* tile_manager = layerTreeImpl()->tile_manager(); | 181 TileManager* tile_manager = layerTreeImpl()->tile_manager(); |
179 | 182 |
180 return make_scoped_refptr(new Tile( | 183 return make_scoped_refptr(new Tile( |
181 tile_manager, | 184 tile_manager, |
182 pile_.get(), | 185 pile_.get(), |
(...skipping 20 matching lines...) Expand all Loading... |
203 | 206 |
204 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { | 207 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { |
205 tilings_.CloneAll(other->tilings_, invalidation_); | 208 tilings_.CloneAll(other->tilings_, invalidation_); |
206 } | 209 } |
207 | 210 |
208 void PictureLayerImpl::SyncTiling( | 211 void PictureLayerImpl::SyncTiling( |
209 const PictureLayerTiling* tiling) { | 212 const PictureLayerTiling* tiling) { |
210 tilings_.Clone(tiling, invalidation_); | 213 tilings_.Clone(tiling, invalidation_); |
211 } | 214 } |
212 | 215 |
| 216 void PictureLayerImpl::SetIsMask(bool is_mask) { |
| 217 if (is_mask_ == is_mask) |
| 218 return; |
| 219 is_mask_ = is_mask; |
| 220 tilings_.Reset(); |
| 221 } |
| 222 |
| 223 ResourceProvider::ResourceId PictureLayerImpl::contentsResourceId() const { |
| 224 gfx::Rect content_rect(gfx::Point(), contentBounds()); |
| 225 float scale = contentsScaleX(); |
| 226 for (PictureLayerTilingSet::Iterator iter(&tilings_, scale, content_rect); |
| 227 iter; |
| 228 ++iter) { |
| 229 // Mask resource not ready yet. |
| 230 if (!*iter || !iter->GetResourceId()) |
| 231 return 0; |
| 232 // Masks only supported if they fit on exactly one tile. |
| 233 if (iter.geometry_rect() != content_rect) |
| 234 return 0; |
| 235 return iter->GetResourceId(); |
| 236 } |
| 237 return 0; |
| 238 } |
| 239 |
213 void PictureLayerImpl::AddTiling(float contents_scale, gfx::Size tile_size) { | 240 void PictureLayerImpl::AddTiling(float contents_scale, gfx::Size tile_size) { |
214 const PictureLayerTiling* tiling = tilings_.AddTiling( | 241 const PictureLayerTiling* tiling = tilings_.AddTiling( |
215 contents_scale, | 242 contents_scale, |
216 tile_size); | 243 tile_size); |
217 | 244 |
218 // If a new tiling is created on the active tree, sync it to the pending tree | 245 // If a new tiling is created on the active tree, sync it to the pending tree |
219 // so that it can share the same tiles. | 246 // so that it can share the same tiles. |
220 if (layerTreeImpl()->IsPendingTree()) | 247 if (layerTreeImpl()->IsPendingTree()) |
221 return; | 248 return; |
222 | 249 |
223 PictureLayerImpl* pending_twin = static_cast<PictureLayerImpl*>( | 250 PictureLayerImpl* pending_twin = static_cast<PictureLayerImpl*>( |
224 layerTreeImpl()->FindPendingTreeLayerById(id())); | 251 layerTreeImpl()->FindPendingTreeLayerById(id())); |
225 if (!pending_twin) | 252 if (!pending_twin) |
226 return; | 253 return; |
227 DCHECK_EQ(id(), pending_twin->id()); | 254 DCHECK_EQ(id(), pending_twin->id()); |
228 pending_twin->SyncTiling(tiling); | 255 pending_twin->SyncTiling(tiling); |
229 } | 256 } |
230 | 257 |
| 258 gfx::Size PictureLayerImpl::TileSize() const { |
| 259 if (is_mask_) { |
| 260 int max_size = layerTreeImpl()->MaxTextureSize(); |
| 261 return gfx::Size( |
| 262 std::min(max_size, contentBounds().width()), |
| 263 std::min(max_size, contentBounds().height())); |
| 264 } |
| 265 |
| 266 return layerTreeImpl()->settings().defaultTileSize; |
| 267 } |
| 268 |
231 } // namespace cc | 269 } // namespace cc |
OLD | NEW |