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

Side by Side Diff: cc/picture_layer_impl.cc

Issue 11704002: cc: Generate tilings at other scales for impl-side painting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, sort() Created 7 years, 11 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/picture_layer_impl.h ('k') | cc/picture_layer_tiling.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/gfx/size_conversions.h"
19 19
20 namespace {
21 const float kMaxScaleRatioDuringPinch = 2.0f;
22 }
23
20 namespace cc { 24 namespace cc {
21 25
22 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* treeImpl, int id) 26 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* treeImpl, int id)
23 : LayerImpl(treeImpl, id), 27 : LayerImpl(treeImpl, id),
24 tilings_(this), 28 tilings_(this),
25 pile_(PicturePileImpl::Create()), 29 pile_(PicturePileImpl::Create()),
26 last_update_time_(0), 30 last_update_time_(0),
31 last_content_scale_(0),
32 ideal_contents_scale_(0),
27 is_mask_(false) { 33 is_mask_(false) {
28 } 34 }
29 35
30 PictureLayerImpl::~PictureLayerImpl() { 36 PictureLayerImpl::~PictureLayerImpl() {
31 } 37 }
32 38
33 const char* PictureLayerImpl::layerTypeAsString() const { 39 const char* PictureLayerImpl::layerTypeAsString() const {
34 return "PictureLayer"; 40 return "PictureLayer";
35 } 41 }
36 42
37 void PictureLayerImpl::appendQuads(QuadSink& quadSink, 43 void PictureLayerImpl::appendQuads(QuadSink& quadSink,
38 AppendQuadsData& appendQuadsData) { 44 AppendQuadsData& appendQuadsData) {
39 45
40 const gfx::Rect& rect = visibleContentRect(); 46 const gfx::Rect& rect = visibleContentRect();
41 gfx::Rect content_rect(gfx::Point(), contentBounds()); 47 gfx::Rect content_rect(gfx::Point(), contentBounds());
42 48
43 SharedQuadState* sharedQuadState = 49 SharedQuadState* sharedQuadState =
44 quadSink.useSharedQuadState(createSharedQuadState()); 50 quadSink.useSharedQuadState(createSharedQuadState());
45 bool clipped = false; 51 bool clipped = false;
46 gfx::QuadF target_quad = MathUtil::mapQuad( 52 gfx::QuadF target_quad = MathUtil::mapQuad(
47 drawTransform(), 53 drawTransform(),
48 gfx::QuadF(rect), 54 gfx::QuadF(rect),
49 clipped); 55 clipped);
50 bool isAxisAlignedInTarget = !clipped && target_quad.IsRectilinear(); 56 bool isAxisAlignedInTarget = !clipped && target_quad.IsRectilinear();
51 bool useAA = !isAxisAlignedInTarget; 57 bool useAA = !isAxisAlignedInTarget;
52 58
53 if (showDebugBorders()) { 59 if (showDebugBorders()) {
54 for (PictureLayerTilingSet::Iterator iter(&tilings_, 60 for (PictureLayerTilingSet::Iterator iter(&tilings_,
55 contentsScaleX(), 61 contentsScaleX(),
56 rect); 62 rect,
63 ideal_contents_scale_);
57 iter; 64 iter;
58 ++iter) { 65 ++iter) {
59 SkColor color; 66 SkColor color;
60 float width; 67 float width;
61 if (*iter && iter->GetResourceId()) { 68 if (*iter && iter->GetResourceId()) {
62 color = DebugColors::TileBorderColor(); 69 color = DebugColors::TileBorderColor();
63 width = DebugColors::TileBorderWidth(layerTreeImpl()); 70 width = DebugColors::TileBorderWidth(layerTreeImpl());
64 } else { 71 } else {
65 color = DebugColors::MissingTileBorderColor(); 72 color = DebugColors::MissingTileBorderColor();
66 width = DebugColors::MissingTileBorderWidth(layerTreeImpl()); 73 width = DebugColors::MissingTileBorderWidth(layerTreeImpl());
67 } 74 }
68 75
69 scoped_ptr<DebugBorderDrawQuad> debugBorderQuad = 76 scoped_ptr<DebugBorderDrawQuad> debugBorderQuad =
70 DebugBorderDrawQuad::Create(); 77 DebugBorderDrawQuad::Create();
71 gfx::Rect geometry_rect = iter.geometry_rect(); 78 gfx::Rect geometry_rect = iter.geometry_rect();
72 debugBorderQuad->SetNew(sharedQuadState, geometry_rect, color, width); 79 debugBorderQuad->SetNew(sharedQuadState, geometry_rect, color, width);
73 quadSink.append(debugBorderQuad.PassAs<DrawQuad>(), appendQuadsData); 80 quadSink.append(debugBorderQuad.PassAs<DrawQuad>(), appendQuadsData);
74 } 81 }
75 } 82 }
76 83
77 for (PictureLayerTilingSet::Iterator iter(&tilings_, contentsScaleX(), rect); 84 // Keep track of the tilings that were used so that tilings that are
85 // unused can be considered for removal.
86 std::vector<PictureLayerTiling*> seen_tilings;
87
88 for (PictureLayerTilingSet::Iterator iter(&tilings_,
89 contentsScaleX(),
90 rect,
91 ideal_contents_scale_);
78 iter; 92 iter;
79 ++iter) { 93 ++iter) {
80 ResourceProvider::ResourceId resource = 0; 94 ResourceProvider::ResourceId resource = 0;
81 if (*iter) 95 if (*iter)
82 resource = iter->GetResourceId(); 96 resource = iter->GetResourceId();
83 97
84 gfx::Rect geometry_rect = iter.geometry_rect(); 98 gfx::Rect geometry_rect = iter.geometry_rect();
85 99
86 if (!resource) { 100 if (!resource) {
87 if (drawCheckerboardForMissingTiles()) { 101 if (drawCheckerboardForMissingTiles()) {
(...skipping 27 matching lines...) Expand all
115 opaque_rect, 129 opaque_rect,
116 resource, 130 resource,
117 texture_rect, 131 texture_rect,
118 iter.texture_size(), 132 iter.texture_size(),
119 iter->contents_swizzled(), 133 iter->contents_swizzled(),
120 outside_left_edge && useAA, 134 outside_left_edge && useAA,
121 outside_top_edge && useAA, 135 outside_top_edge && useAA,
122 outside_right_edge && useAA, 136 outside_right_edge && useAA,
123 outside_bottom_edge && useAA); 137 outside_bottom_edge && useAA);
124 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); 138 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
139
140 if (!seen_tilings.size() || seen_tilings.back() != iter.CurrentTiling())
141 seen_tilings.push_back(iter.CurrentTiling());
125 } 142 }
143
144 // During a pinch, a user could zoom in and out, so throwing away a tiling may
145 // be premature.
146 if (!layerTreeImpl()->PinchGestureActive())
147 CleanUpUnusedTilings(seen_tilings);
126 } 148 }
127 149
128 void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const { 150 void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const {
129 // TODO(enne): implement me 151 // TODO(enne): implement me
130 } 152 }
131 153
132 void PictureLayerImpl::didUpdateTransforms() { 154 void PictureLayerImpl::didUpdateTransforms() {
133 gfx::Transform current_screen_space_transform = 155 gfx::Transform current_screen_space_transform =
134 screenSpaceTransform(); 156 screenSpaceTransform();
135 double current_time = 157 double current_time =
136 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 158 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
137 double time_delta = 0; 159 double time_delta = 0;
138 if (last_update_time_ != 0 && last_bounds_ == bounds() && 160 if (last_update_time_ != 0 && last_bounds_ == bounds() &&
139 last_content_bounds_ == contentBounds() && 161 last_content_bounds_ == contentBounds() &&
140 last_content_scale_x_ == contentsScaleX() && 162 last_content_scale_ == contentsScaleX()) {
141 last_content_scale_y_ == contentsScaleY()) {
142 time_delta = current_time - last_update_time_; 163 time_delta = current_time - last_update_time_;
143 } 164 }
144 WhichTree tree = layerTreeImpl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; 165 WhichTree tree = layerTreeImpl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
145 tilings_.UpdateTilePriorities( 166 tilings_.UpdateTilePriorities(
146 tree, 167 tree,
147 layerTreeImpl()->device_viewport_size(), 168 layerTreeImpl()->device_viewport_size(),
169 last_content_scale_,
148 contentsScaleX(), 170 contentsScaleX(),
149 contentsScaleY(),
150 last_screen_space_transform_, 171 last_screen_space_transform_,
151 current_screen_space_transform, 172 current_screen_space_transform,
152 time_delta); 173 time_delta);
153 174
154 last_screen_space_transform_ = current_screen_space_transform; 175 last_screen_space_transform_ = current_screen_space_transform;
155 last_update_time_ = current_time; 176 last_update_time_ = current_time;
156 last_bounds_ = bounds(); 177 last_bounds_ = bounds();
157 last_content_bounds_ = contentBounds(); 178 last_content_bounds_ = contentBounds();
158 last_content_scale_x_ = contentsScaleX(); 179 last_content_scale_ = contentsScaleX();
159 last_content_scale_y_ = contentsScaleY();
160 } 180 }
161 181
162 void PictureLayerImpl::calculateContentsScale( 182 void PictureLayerImpl::calculateContentsScale(
163 float ideal_contents_scale, 183 float ideal_contents_scale,
164 float* contents_scale_x, 184 float* contents_scale_x,
165 float* contents_scale_y, 185 float* contents_scale_y,
166 gfx::Size* content_bounds) { 186 gfx::Size* content_bounds) {
167 if (!drawsContent()) { 187 if (!drawsContent()) {
168 DCHECK(!tilings_.num_tilings()); 188 DCHECK(!tilings_.num_tilings());
169 return; 189 return;
170 } 190 }
171 191
172 float min_contents_scale = layerTreeImpl()->settings().minimumContentsScale; 192 float min_contents_scale = layerTreeImpl()->settings().minimumContentsScale;
173 ideal_contents_scale = std::max(ideal_contents_scale, min_contents_scale); 193 ideal_contents_scale_ = std::max(ideal_contents_scale, min_contents_scale);
174 194
175 ManageTilings(ideal_contents_scale); 195 ManageTilings(ideal_contents_scale_);
176 196
177 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious. 197 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious.
178 // There are (usually) several tilings at different scales. However, the 198 // There are (usually) several tilings at different scales. However, the
179 // content bounds is the (integer!) space in which quads are generated. 199 // content bounds is the (integer!) space in which quads are generated.
180 // In order to guarantee that we can fill this integer space with any set of 200 // In order to guarantee that we can fill this integer space with any set of
181 // tilings (and then map back to floating point texture coordinates), the 201 // tilings (and then map back to floating point texture coordinates), the
182 // contents scale must be at least as large as the largest of the tilings. 202 // contents scale must be at least as large as the largest of the tilings.
183 float max_contents_scale = min_contents_scale; 203 float max_contents_scale = min_contents_scale;
184 for (size_t i = 0; i < tilings_.num_tilings(); ++i) { 204 for (size_t i = 0; i < tilings_.num_tilings(); ++i) {
185 const PictureLayerTiling* tiling = tilings_.tiling_at(i); 205 const PictureLayerTiling* tiling = tilings_.tiling_at(i);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 250
231 void PictureLayerImpl::SyncTiling( 251 void PictureLayerImpl::SyncTiling(
232 const PictureLayerTiling* tiling) { 252 const PictureLayerTiling* tiling) {
233 tilings_.Clone(tiling, invalidation_); 253 tilings_.Clone(tiling, invalidation_);
234 } 254 }
235 255
236 void PictureLayerImpl::SetIsMask(bool is_mask) { 256 void PictureLayerImpl::SetIsMask(bool is_mask) {
237 if (is_mask_ == is_mask) 257 if (is_mask_ == is_mask)
238 return; 258 return;
239 is_mask_ = is_mask; 259 is_mask_ = is_mask;
240 tilings_.Reset(); 260 tilings_.RemoveAllTiles();
241 } 261 }
242 262
243 ResourceProvider::ResourceId PictureLayerImpl::contentsResourceId() const { 263 ResourceProvider::ResourceId PictureLayerImpl::contentsResourceId() const {
244 gfx::Rect content_rect(gfx::Point(), contentBounds()); 264 gfx::Rect content_rect(gfx::Point(), contentBounds());
245 float scale = contentsScaleX(); 265 float scale = contentsScaleX();
246 for (PictureLayerTilingSet::Iterator iter(&tilings_, scale, content_rect); 266 for (PictureLayerTilingSet::Iterator iter(&tilings_,
267 scale,
268 content_rect,
269 ideal_contents_scale_);
247 iter; 270 iter;
248 ++iter) { 271 ++iter) {
249 // Mask resource not ready yet. 272 // Mask resource not ready yet.
250 if (!*iter || !iter->GetResourceId()) 273 if (!*iter || !iter->GetResourceId())
251 return 0; 274 return 0;
252 // Masks only supported if they fit on exactly one tile. 275 // Masks only supported if they fit on exactly one tile.
253 if (iter.geometry_rect() != content_rect) 276 if (iter.geometry_rect() != content_rect)
254 return 0; 277 return 0;
255 return iter->GetResourceId(); 278 return iter->GetResourceId();
256 } 279 }
257 return 0; 280 return 0;
258 } 281 }
259 282
260 void PictureLayerImpl::AddTiling(float contents_scale, gfx::Size tile_size) { 283 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
261 if (contents_scale < layerTreeImpl()->settings().minimumContentsScale) 284 if (contents_scale < layerTreeImpl()->settings().minimumContentsScale)
262 return; 285 return NULL;
263 286
264 const PictureLayerTiling* tiling = tilings_.AddTiling( 287 PictureLayerTiling* tiling = tilings_.AddTiling(
265 contents_scale, 288 contents_scale,
266 tile_size); 289 TileSize());
267 290
268 // If a new tiling is created on the active tree, sync it to the pending tree 291 // If a new tiling is created on the active tree, sync it to the pending tree
269 // so that it can share the same tiles. 292 // so that it can share the same tiles.
270 if (layerTreeImpl()->IsPendingTree()) 293 if (layerTreeImpl()->IsPendingTree())
271 return; 294 return tiling;
272 295
273 PictureLayerImpl* pending_twin = static_cast<PictureLayerImpl*>( 296 PictureLayerImpl* pending_twin = static_cast<PictureLayerImpl*>(
274 layerTreeImpl()->FindPendingTreeLayerById(id())); 297 layerTreeImpl()->FindPendingTreeLayerById(id()));
275 if (!pending_twin) 298 if (!pending_twin)
276 return; 299 return tiling;
277 DCHECK_EQ(id(), pending_twin->id()); 300 DCHECK_EQ(id(), pending_twin->id());
278 pending_twin->SyncTiling(tiling); 301 pending_twin->SyncTiling(tiling);
302 return tiling;
279 } 303 }
280 304
281 gfx::Size PictureLayerImpl::TileSize() const { 305 gfx::Size PictureLayerImpl::TileSize() const {
282 if (is_mask_) { 306 if (is_mask_) {
283 int max_size = layerTreeImpl()->MaxTextureSize(); 307 int max_size = layerTreeImpl()->MaxTextureSize();
284 return gfx::Size( 308 return gfx::Size(
285 std::min(max_size, contentBounds().width()), 309 std::min(max_size, contentBounds().width()),
286 std::min(max_size, contentBounds().height())); 310 std::min(max_size, contentBounds().height()));
287 } 311 }
288 312
289 return layerTreeImpl()->settings().defaultTileSize; 313 return layerTreeImpl()->settings().defaultTileSize;
290 } 314 }
291 315
316 namespace {
317
318 inline float PositiveRatio(float float1, float float2) {
319 DCHECK(float1 > 0);
320 DCHECK(float2 > 0);
321 return float1 > float2 ? float1 / float2 : float2 / float1;
322 }
323
324 inline bool IsCloserToThan(
325 PictureLayerTiling* layer1,
326 PictureLayerTiling* layer2,
327 float contents_scale) {
328 // Absolute value for ratios.
329 float ratio1 = PositiveRatio(layer1->contents_scale(), contents_scale);
330 float ratio2 = PositiveRatio(layer2->contents_scale(), contents_scale);
331 return ratio1 < ratio2;
332 }
333
334 } // namespace
335
292 void PictureLayerImpl::ManageTilings(float ideal_contents_scale) { 336 void PictureLayerImpl::ManageTilings(float ideal_contents_scale) {
293 if (drawsContent()) { 337 DCHECK(ideal_contents_scale);
294 // TODO(enne): Add tilings during pinch zoom 338 float low_res_factor = layerTreeImpl()->settings().lowResContentsScaleFactor;
295 // TODO(enne): Consider culling old tilings after pinch finishes. 339 float low_res_contents_scale = ideal_contents_scale * low_res_factor;
296 if (!tilings_.num_tilings()) { 340
297 AddTiling(ideal_contents_scale, TileSize()); 341 // Remove any tilings from the pending tree that don't exactly match the
298 // TODO(enne): Add a low-res tiling as well. 342 // contents scale. The pending tree should always come in crisp. However,
343 // don't do this during a pinch, to avoid throwing away a tiling that should
344 // have been kept.
345 if (layerTreeImpl()->IsPendingTree() &&
346 !layerTreeImpl()->PinchGestureActive()) {
347 std::vector<PictureLayerTiling*> remove_list;
348 for (size_t i = 0; i < tilings_.num_tilings(); ++i) {
349 PictureLayerTiling* tiling = tilings_.tiling_at(i);
350 if (tiling->contents_scale() == ideal_contents_scale)
351 continue;
352 if (tiling->contents_scale() == low_res_contents_scale)
353 continue;
354 remove_list.push_back(tiling);
299 } 355 }
300 } else { 356
301 // TODO(enne): This should be unnecessary once there are two trees. 357 for (size_t i = 0; i < remove_list.size(); ++i)
302 tilings_.Reset(); 358 tilings_.Remove(remove_list[i]);
303 } 359 }
360
361 // Find existing tilings closest to ideal high / low res.
362 PictureLayerTiling* high_res = NULL;
363 PictureLayerTiling* low_res = NULL;
364 for (size_t i = 0; i < tilings_.num_tilings(); ++i) {
365 PictureLayerTiling* tiling = tilings_.tiling_at(i);
366 if (!high_res || IsCloserToThan(tiling, high_res, ideal_contents_scale))
367 high_res = tiling;
368 if (!low_res || IsCloserToThan(tiling, low_res, low_res_contents_scale))
369 low_res = tiling;
370
371 // Reset all tilings to non-ideal until the end of this function.
372 tiling->set_resolution(NON_IDEAL_RESOLUTION);
373 }
374
375 // The active tree always has calcDrawProperties called on it first, and
376 // any tilings added to the active tree will be synced to the pending tree.
377 // Therefore, only add tilings to the active tree.
378 if (layerTreeImpl()->IsActiveTree()) {
379 if (layerTreeImpl()->PinchGestureActive() && high_res) {
380 // If zooming out, if only available high-res tiling is very high
381 // resolution, create additional tilings closer to the ideal.
382 // When zooming in, add some additional tilings so that content
383 // "crisps up" prior to releasing pinch.
384 float ratio = PositiveRatio(
385 high_res->contents_scale(),
386 ideal_contents_scale);
387 if (ratio >= kMaxScaleRatioDuringPinch)
388 high_res = AddTiling(ideal_contents_scale);
389 } else {
390 // When not pinching or if no tilings, add exact contents scales.
391 if (!high_res || high_res->contents_scale() != ideal_contents_scale)
392 high_res = AddTiling(ideal_contents_scale);
393 if (!low_res || low_res->contents_scale() != low_res_contents_scale)
394 low_res = AddTiling(low_res_contents_scale);
395 }
396 }
397
398 if (high_res)
399 high_res->set_resolution(HIGH_RESOLUTION);
400 if (low_res && low_res != high_res)
401 low_res->set_resolution(LOW_RESOLUTION);
402 }
403
404 void PictureLayerImpl::CleanUpUnusedTilings(
405 std::vector<PictureLayerTiling*> used_tilings) {
406 std::vector<PictureLayerTiling*> to_remove;
407
408 for (size_t i = 0; i < tilings_.num_tilings(); ++i) {
409 PictureLayerTiling* tiling = tilings_.tiling_at(i);
410 // Don't remove the current high or low res tilinig.
411 if (tiling->resolution() != NON_IDEAL_RESOLUTION)
412 continue;
413 if (std::find(used_tilings.begin(), used_tilings.end(), tiling) ==
414 used_tilings.end())
415 to_remove.push_back(tiling);
416 }
417
418 for (size_t i = 0; i < to_remove.size(); ++i)
419 tilings_.Remove(to_remove[i]);
304 } 420 }
305 421
306 } // namespace cc 422 } // namespace cc
OLDNEW
« no previous file with comments | « cc/picture_layer_impl.h ('k') | cc/picture_layer_tiling.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698