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 #include "ui/gfx/size_conversions.h" |
18 | 19 |
19 namespace cc { | 20 namespace cc { |
20 | 21 |
21 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* treeImpl, int id) | 22 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* treeImpl, int id) |
22 : LayerImpl(treeImpl, id), | 23 : LayerImpl(treeImpl, id), |
23 tilings_(this), | 24 tilings_(this), |
24 pile_(PicturePileImpl::Create()), | 25 pile_(PicturePileImpl::Create()), |
25 last_update_time_(0), | 26 last_update_time_(0), |
26 is_mask_(false) { | 27 is_mask_(false) { |
27 } | 28 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 outside_bottom_edge && useAA); | 123 outside_bottom_edge && useAA); |
123 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); | 124 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); |
124 } | 125 } |
125 } | 126 } |
126 | 127 |
127 void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const { | 128 void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const { |
128 // TODO(enne): implement me | 129 // TODO(enne): implement me |
129 } | 130 } |
130 | 131 |
131 void PictureLayerImpl::didUpdateTransforms() { | 132 void PictureLayerImpl::didUpdateTransforms() { |
132 if (drawsContent()) { | |
133 // TODO(enne): Add tilings during pinch zoom | |
134 // TODO(enne): Consider culling old tilings after pinch finishes. | |
135 if (!tilings_.num_tilings()) { | |
136 AddTiling(contentsScaleX(), TileSize()); | |
137 // TODO(enne): Add a low-res tiling as well. | |
138 } | |
139 } else { | |
140 // TODO(enne): This should be unnecessary once there are two trees. | |
141 tilings_.Reset(); | |
142 } | |
143 | |
144 gfx::Transform current_screen_space_transform = | 133 gfx::Transform current_screen_space_transform = |
145 screenSpaceTransform(); | 134 screenSpaceTransform(); |
146 double current_time = | 135 double current_time = |
147 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); | 136 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
148 double time_delta = 0; | 137 double time_delta = 0; |
149 if (last_update_time_ != 0 && last_bounds_ == bounds() && | 138 if (last_update_time_ != 0 && last_bounds_ == bounds() && |
150 last_content_bounds_ == contentBounds() && | 139 last_content_bounds_ == contentBounds() && |
151 last_content_scale_x_ == contentsScaleX() && | 140 last_content_scale_x_ == contentsScaleX() && |
152 last_content_scale_y_ == contentsScaleY()) { | 141 last_content_scale_y_ == contentsScaleY()) { |
153 time_delta = current_time - last_update_time_; | 142 time_delta = current_time - last_update_time_; |
154 } | 143 } |
155 WhichTree tree = layerTreeImpl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; | 144 WhichTree tree = layerTreeImpl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; |
156 tilings_.UpdateTilePriorities( | 145 tilings_.UpdateTilePriorities( |
157 tree, | 146 tree, |
158 layerTreeImpl()->device_viewport_size(), | 147 layerTreeImpl()->device_viewport_size(), |
159 contentsScaleX(), | 148 contentsScaleX(), |
160 contentsScaleY(), | 149 contentsScaleY(), |
161 last_screen_space_transform_, | 150 last_screen_space_transform_, |
162 current_screen_space_transform, | 151 current_screen_space_transform, |
163 time_delta); | 152 time_delta); |
164 | 153 |
165 last_screen_space_transform_ = current_screen_space_transform; | 154 last_screen_space_transform_ = current_screen_space_transform; |
166 last_update_time_ = current_time; | 155 last_update_time_ = current_time; |
167 last_bounds_ = bounds(); | 156 last_bounds_ = bounds(); |
168 last_content_bounds_ = contentBounds(); | 157 last_content_bounds_ = contentBounds(); |
169 last_content_scale_x_ = contentsScaleX(); | 158 last_content_scale_x_ = contentsScaleX(); |
170 last_content_scale_y_ = contentsScaleY(); | 159 last_content_scale_y_ = contentsScaleY(); |
171 } | 160 } |
172 | 161 |
| 162 void PictureLayerImpl::calculateContentsScale( |
| 163 float ideal_contents_scale, |
| 164 float* contents_scale_x, |
| 165 float* contents_scale_y, |
| 166 gfx::Size* content_bounds) { |
| 167 if (!drawsContent()) { |
| 168 DCHECK(!tilings_.num_tilings()); |
| 169 return; |
| 170 } |
| 171 |
| 172 ManageTilings(ideal_contents_scale); |
| 173 |
| 174 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious. |
| 175 // There are (usually) several tilings at different scales. However, the |
| 176 // content bounds is the (integer!) space in which quads are generated. |
| 177 // In order to guarantee that we can fill this integer space with any set of |
| 178 // tilings (and then map back to floating point texture coordinates), the |
| 179 // contents scale must be at least as large as the largest of the tilings. |
| 180 float max_contents_scale = 1.f; |
| 181 for (size_t i = 0; i < tilings_.num_tilings(); ++i) { |
| 182 const PictureLayerTiling* tiling = tilings_.tiling_at(i); |
| 183 max_contents_scale = std::max(max_contents_scale, tiling->contents_scale()); |
| 184 } |
| 185 |
| 186 *contents_scale_x = max_contents_scale; |
| 187 *contents_scale_y = max_contents_scale; |
| 188 *content_bounds = gfx::ToCeiledSize( |
| 189 gfx::ScaleSize(bounds(), max_contents_scale, max_contents_scale)); |
| 190 } |
| 191 |
173 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, | 192 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, |
174 gfx::Rect rect) { | 193 gfx::Rect rect) { |
175 TileManager* tile_manager = layerTreeImpl()->tile_manager(); | 194 TileManager* tile_manager = layerTreeImpl()->tile_manager(); |
176 | 195 |
177 return make_scoped_refptr(new Tile( | 196 return make_scoped_refptr(new Tile( |
178 tile_manager, | 197 tile_manager, |
179 pile_.get(), | 198 pile_.get(), |
180 rect.size(), | 199 rect.size(), |
181 GL_RGBA, | 200 GL_RGBA, |
182 rect, | 201 rect, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 if (is_mask_) { | 272 if (is_mask_) { |
254 int max_size = layerTreeImpl()->MaxTextureSize(); | 273 int max_size = layerTreeImpl()->MaxTextureSize(); |
255 return gfx::Size( | 274 return gfx::Size( |
256 std::min(max_size, contentBounds().width()), | 275 std::min(max_size, contentBounds().width()), |
257 std::min(max_size, contentBounds().height())); | 276 std::min(max_size, contentBounds().height())); |
258 } | 277 } |
259 | 278 |
260 return layerTreeImpl()->settings().defaultTileSize; | 279 return layerTreeImpl()->settings().defaultTileSize; |
261 } | 280 } |
262 | 281 |
| 282 void PictureLayerImpl::ManageTilings(float ideal_contents_scale) { |
| 283 if (drawsContent()) { |
| 284 // TODO(enne): Add tilings during pinch zoom |
| 285 // TODO(enne): Consider culling old tilings after pinch finishes. |
| 286 if (!tilings_.num_tilings()) { |
| 287 AddTiling(ideal_contents_scale, TileSize()); |
| 288 // TODO(enne): Add a low-res tiling as well. |
| 289 } |
| 290 } else { |
| 291 // TODO(enne): This should be unnecessary once there are two trees. |
| 292 tilings_.Reset(); |
| 293 } |
| 294 } |
| 295 |
263 } // namespace cc | 296 } // namespace cc |
OLD | NEW |