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

Side by Side Diff: cc/layers/layer_impl.cc

Issue 783543003: Update from https://crrev.com/306901 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « cc/layers/heads_up_display_layer_impl.cc ('k') | cc/layers/nine_patch_layer_impl.cc » ('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/layers/layer_impl.h" 5 #include "cc/layers/layer_impl.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/debug/trace_event_argument.h" 8 #include "base/debug/trace_event_argument.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 stacking_order_changed_ = false; 614 stacking_order_changed_ = false;
615 update_rect_ = gfx::Rect(); 615 update_rect_ = gfx::Rect();
616 needs_push_properties_ = false; 616 needs_push_properties_ = false;
617 num_dependents_need_push_properties_ = 0; 617 num_dependents_need_push_properties_ = 0;
618 } 618 }
619 619
620 gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const { 620 gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const {
621 if (!scroll_clip_layer_) 621 if (!scroll_clip_layer_)
622 return gfx::Vector2dF(); 622 return gfx::Vector2dF();
623 623
624 float scale_delta = layer_tree_impl()->page_scale_delta();
625 float scale = layer_tree_impl()->page_scale_factor();
626
627 gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta(); 624 gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta();
628 625
629 // In virtual-viewport mode, we don't need to compensate for pinch zoom or 626 // In virtual-viewport mode, we don't need to compensate for pinch zoom or
630 // scale since the fixed container is the outer viewport, which sits below 627 // scale since the fixed container is the outer viewport, which sits below
631 // the page scale. 628 // the page scale.
632 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) 629 if (layer_tree_impl()->settings().use_pinch_virtual_viewport)
633 return delta_from_scroll; 630 return delta_from_scroll;
634 631
632 float scale_delta = layer_tree_impl()->page_scale_delta();
633 float scale = layer_tree_impl()->current_page_scale_factor() /
634 layer_tree_impl()->page_scale_delta();
635
635 delta_from_scroll.Scale(1.f / scale); 636 delta_from_scroll.Scale(1.f / scale);
636 637
637 // The delta-from-pinch component requires some explanation: A viewport of 638 // The delta-from-pinch component requires some explanation: A viewport of
638 // size (w,h) will appear to be size (w/s,h/s) under scale s in the content 639 // size (w,h) will appear to be size (w/s,h/s) under scale s in the content
639 // space. If s -> s' on the impl thread, where s' = s * ds, then the apparent 640 // space. If s -> s' on the impl thread, where s' = s * ds, then the apparent
640 // viewport size change in the content space due to ds is: 641 // viewport size change in the content space due to ds is:
641 // 642 //
642 // (w/s',h/s') - (w/s,h/s) = (w,h)(1/s' - 1/s) = (w,h)(1 - ds)/(s ds) 643 // (w/s',h/s') - (w/s,h/s) = (w,h)(1/s' - 1/s) = (w,h)(1 - ds)/(s ds)
643 // 644 //
644 gfx::Vector2dF delta_from_pinch = 645 gfx::Vector2dF delta_from_pinch =
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 float scale_factor = 1.f; 1207 float scale_factor = 1.f;
1207 for (LayerImpl const* current_layer = this; 1208 for (LayerImpl const* current_layer = this;
1208 current_layer != scroll_clip_layer_; 1209 current_layer != scroll_clip_layer_;
1209 current_layer = current_layer->parent()) { 1210 current_layer = current_layer->parent()) {
1210 DCHECK(current_layer); 1211 DCHECK(current_layer);
1211 float current_layer_scale = 1.f; 1212 float current_layer_scale = 1.f;
1212 1213
1213 const gfx::Transform& layer_transform = current_layer->transform(); 1214 const gfx::Transform& layer_transform = current_layer->transform();
1214 if (current_layer == page_scale_layer) { 1215 if (current_layer == page_scale_layer) {
1215 DCHECK(layer_transform.IsIdentity()); 1216 DCHECK(layer_transform.IsIdentity());
1216 current_layer_scale = layer_tree_impl()->total_page_scale_factor(); 1217 current_layer_scale = layer_tree_impl()->current_page_scale_factor();
1217 } else { 1218 } else {
1218 // TODO(wjmaclean) Should we allow for translation too? 1219 // TODO(wjmaclean) Should we allow for translation too?
1219 DCHECK(layer_transform.IsScale2d()); 1220 DCHECK(layer_transform.IsScale2d());
1220 gfx::Vector2dF layer_scale = layer_transform.Scale2d(); 1221 gfx::Vector2dF layer_scale = layer_transform.Scale2d();
1221 // TODO(wjmaclean) Allow for non-isotropic scales. 1222 // TODO(wjmaclean) Allow for non-isotropic scales.
1222 DCHECK(layer_scale.x() == layer_scale.y()); 1223 DCHECK(layer_scale.x() == layer_scale.y());
1223 current_layer_scale = layer_scale.x(); 1224 current_layer_scale = layer_scale.x();
1224 } 1225 }
1225 1226
1226 scale_factor *= current_layer_scale; 1227 scale_factor *= current_layer_scale;
1227 } 1228 }
1228 // TODO(wjmaclean) Once we move to a model where the two-viewport model is 1229 // TODO(wjmaclean) Once we move to a model where the two-viewport model is
1229 // turned on in all builds, remove the next two lines. For now however, the 1230 // turned on in all builds, remove the next two lines. For now however, the
1230 // page scale layer may coincide with the clip layer, and so this is 1231 // page scale layer may coincide with the clip layer, and so this is
1231 // necessary. 1232 // necessary.
1232 if (page_scale_layer == scroll_clip_layer_) 1233 if (page_scale_layer == scroll_clip_layer_)
1233 scale_factor *= layer_tree_impl()->total_page_scale_factor(); 1234 scale_factor *= layer_tree_impl()->current_page_scale_factor();
1234 1235
1235 scaled_scroll_bounds.SetSize(scale_factor * scaled_scroll_bounds.width(), 1236 scaled_scroll_bounds.SetSize(scale_factor * scaled_scroll_bounds.width(),
1236 scale_factor * scaled_scroll_bounds.height()); 1237 scale_factor * scaled_scroll_bounds.height());
1237 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds); 1238 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds);
1238 1239
1239 gfx::ScrollOffset max_offset( 1240 gfx::ScrollOffset max_offset(
1240 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), 1241 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(),
1241 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); 1242 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height());
1242 // We need the final scroll offset to be in CSS coords. 1243 // We need the final scroll offset to be in CSS coords.
1243 max_offset.Scale(1 / scale_factor); 1244 max_offset.Scale(1 / scale_factor);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 // TODO(wjmaclean) This computation is nearly identical to the one in 1283 // TODO(wjmaclean) This computation is nearly identical to the one in
1283 // MaxScrollOffset. Find some way to combine these. 1284 // MaxScrollOffset. Find some way to combine these.
1284 gfx::ScrollOffset current_offset; 1285 gfx::ScrollOffset current_offset;
1285 for (LayerImpl const* current_layer = this; 1286 for (LayerImpl const* current_layer = this;
1286 current_layer != scrollbar_clip_layer; 1287 current_layer != scrollbar_clip_layer;
1287 current_layer = current_layer->parent()) { 1288 current_layer = current_layer->parent()) {
1288 DCHECK(current_layer); 1289 DCHECK(current_layer);
1289 const gfx::Transform& layer_transform = current_layer->transform(); 1290 const gfx::Transform& layer_transform = current_layer->transform();
1290 if (current_layer == page_scale_layer) { 1291 if (current_layer == page_scale_layer) {
1291 DCHECK(layer_transform.IsIdentity()); 1292 DCHECK(layer_transform.IsIdentity());
1292 float scale_factor = layer_tree_impl()->total_page_scale_factor(); 1293 float scale_factor = layer_tree_impl()->current_page_scale_factor();
1293 current_offset.Scale(scale_factor); 1294 current_offset.Scale(scale_factor);
1294 scroll_rect.Scale(scale_factor); 1295 scroll_rect.Scale(scale_factor);
1295 } else { 1296 } else {
1296 DCHECK(layer_transform.IsScale2d()); 1297 DCHECK(layer_transform.IsScale2d());
1297 gfx::Vector2dF layer_scale = layer_transform.Scale2d(); 1298 gfx::Vector2dF layer_scale = layer_transform.Scale2d();
1298 DCHECK(layer_scale.x() == layer_scale.y()); 1299 DCHECK(layer_scale.x() == layer_scale.y());
1299 gfx::ScrollOffset new_offset = ScrollOffsetWithDelta( 1300 gfx::ScrollOffset new_offset = ScrollOffsetWithDelta(
1300 current_layer->scroll_offset(), current_layer->ScrollDelta()); 1301 current_layer->scroll_offset(), current_layer->ScrollDelta());
1301 new_offset.Scale(layer_scale.x(), layer_scale.y()); 1302 new_offset.Scale(layer_scale.x(), layer_scale.y());
1302 current_offset += new_offset; 1303 current_offset += new_offset;
1303 } 1304 }
1304 } 1305 }
1305 // TODO(wjmaclean) Once we move to a model where the two-viewport model is 1306 // TODO(wjmaclean) Once we move to a model where the two-viewport model is
1306 // turned on in all builds, remove the next two lines. For now however, the 1307 // turned on in all builds, remove the next two lines. For now however, the
1307 // page scale layer may coincide with the clip layer, and so this is 1308 // page scale layer may coincide with the clip layer, and so this is
1308 // necessary. 1309 // necessary.
1309 if (page_scale_layer == scrollbar_clip_layer) { 1310 if (page_scale_layer == scrollbar_clip_layer) {
1310 scroll_rect.Scale(layer_tree_impl()->total_page_scale_factor()); 1311 scroll_rect.Scale(layer_tree_impl()->current_page_scale_factor());
1311 current_offset.Scale(layer_tree_impl()->total_page_scale_factor()); 1312 current_offset.Scale(layer_tree_impl()->current_page_scale_factor());
1312 } 1313 }
1313 1314
1314 bool scrollbar_needs_animation = false; 1315 bool scrollbar_needs_animation = false;
1315 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust( 1316 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust(
1316 scrollbar_clip_layer->bounds_delta().y()); 1317 scrollbar_clip_layer->bounds_delta().y());
1317 if (scrollbar_layer->orientation() == HORIZONTAL) { 1318 if (scrollbar_layer->orientation() == HORIZONTAL) {
1318 float visible_ratio = clip_rect.width() / scroll_rect.width(); 1319 float visible_ratio = clip_rect.width() / scroll_rect.width();
1319 scrollbar_needs_animation |= 1320 scrollbar_needs_animation |=
1320 scrollbar_layer->SetCurrentPos(current_offset.x()); 1321 scrollbar_layer->SetCurrentPos(current_offset.x());
1321 scrollbar_needs_animation |= 1322 scrollbar_needs_animation |=
(...skipping 14 matching lines...) Expand all
1336 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars 1337 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1337 // should activate for every scroll on the main frame, not just the 1338 // should activate for every scroll on the main frame, not just the
1338 // scrolls that move the pinch virtual viewport (i.e. trigger from 1339 // scrolls that move the pinch virtual viewport (i.e. trigger from
1339 // either inner or outer viewport). 1340 // either inner or outer viewport).
1340 if (scrollbar_animation_controller_) { 1341 if (scrollbar_animation_controller_) {
1341 // When both non-overlay and overlay scrollbars are both present, don't 1342 // When both non-overlay and overlay scrollbars are both present, don't
1342 // animate the overlay scrollbars when page scale factor is at the min. 1343 // animate the overlay scrollbars when page scale factor is at the min.
1343 // Non-overlay scrollbars also shouldn't trigger animations. 1344 // Non-overlay scrollbars also shouldn't trigger animations.
1344 bool is_animatable_scrollbar = 1345 bool is_animatable_scrollbar =
1345 scrollbar_layer->is_overlay_scrollbar() && 1346 scrollbar_layer->is_overlay_scrollbar() &&
1346 ((layer_tree_impl()->total_page_scale_factor() > 1347 ((layer_tree_impl()->current_page_scale_factor() >
1347 layer_tree_impl()->min_page_scale_factor()) || 1348 layer_tree_impl()->min_page_scale_factor()) ||
1348 !layer_tree_impl()->settings().use_pinch_zoom_scrollbars); 1349 !layer_tree_impl()->settings().use_pinch_zoom_scrollbars);
1349 if (is_animatable_scrollbar) 1350 if (is_animatable_scrollbar)
1350 scrollbar_animation_controller_->DidScrollUpdate(on_resize); 1351 scrollbar_animation_controller_->DidScrollUpdate(on_resize);
1351 } 1352 }
1352 } 1353 }
1353 } 1354 }
1354 1355
1355 void LayerImpl::DidBecomeActive() { 1356 void LayerImpl::DidBecomeActive() {
1356 if (layer_tree_impl_->settings().scrollbar_animator == 1357 if (layer_tree_impl_->settings().scrollbar_animator ==
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 1590
1590 void LayerImpl::NotifyAnimationFinished( 1591 void LayerImpl::NotifyAnimationFinished(
1591 base::TimeTicks monotonic_time, 1592 base::TimeTicks monotonic_time,
1592 Animation::TargetProperty target_property, 1593 Animation::TargetProperty target_property,
1593 int group) { 1594 int group) {
1594 if (target_property == Animation::ScrollOffset) 1595 if (target_property == Animation::ScrollOffset)
1595 layer_tree_impl_->InputScrollAnimationFinished(); 1596 layer_tree_impl_->InputScrollAnimationFinished();
1596 } 1597 }
1597 1598
1598 } // namespace cc 1599 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/heads_up_display_layer_impl.cc ('k') | cc/layers/nine_patch_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698