Commit f05a79d8 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Chromium LUCI CQ

Fix too small scale during animation without scale but with ancestor scale

Previously during a translation animation, as the animation didn't have
scale, we would fallback to use the native scale. In cases that the
animating element had a big accumulated scale from ancestors, the scale
would be too small compared to the ideal scale.

Another failure case was that when a big animation scale would cause the
rasterized layer to be larger than the viewport, we would also fallback
to use the native scale, which might be also too small if the layer had
a big accumulated scale from ancestors.

Now don't adjust scale for transform animation if the animation doesn't
animate scale. And don't fallback to native scale when the scale is too
big, but calculate a scale that just makes the rasterized layer not
larger than the viewport.

Bug: 1153428
Change-Id: I4a4f3133b01099752629f6710c8375a7b715ab0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566053Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832491}
parent 01a6c3bb
...@@ -1442,73 +1442,8 @@ void PictureLayerImpl::RecalculateRasterScales() { ...@@ -1442,73 +1442,8 @@ void PictureLayerImpl::RecalculateRasterScales() {
raster_contents_scale_ / raster_device_scale_ / raster_source_scale_; raster_contents_scale_ / raster_device_scale_ / raster_source_scale_;
} }
// We rasterize at the maximum scale that will occur during the animation, if if (draw_properties().screen_space_transform_is_animating)
// the maximum scale is known. However we want to avoid excessive memory use. AdjustRasterScaleForTransformAnimation(preserved_raster_contents_scale);
// If the scale is smaller than what we would choose otherwise, then it's
// always better off for us memory-wise. But otherwise, we don't choose a
// scale at which this layer's rastered content would become larger than the
// viewport.
if (draw_properties().screen_space_transform_is_animating) {
bool can_raster_at_maximum_scale = false;
bool should_raster_at_starting_scale = false;
CombinedAnimationScale animation_scales =
layer_tree_impl()->property_trees()->GetAnimationScales(
transform_tree_index(), layer_tree_impl());
float maximum_scale = animation_scales.maximum_animation_scale;
float starting_scale = animation_scales.starting_animation_scale;
if (maximum_scale != kNotScaled) {
gfx::Size bounds_at_maximum_scale =
gfx::ScaleToCeiledSize(raster_source_->GetSize(), maximum_scale);
int64_t maximum_area =
static_cast<int64_t>(bounds_at_maximum_scale.width()) *
static_cast<int64_t>(bounds_at_maximum_scale.height());
gfx::Size viewport = layer_tree_impl()->GetDeviceViewport().size();
// Use the square of the maximum viewport dimension direction, to
// compensate for viewports with different aspect ratios.
int64_t max_viewport_dimension =
std::max(static_cast<int64_t>(viewport.width()),
static_cast<int64_t>(viewport.height()));
int64_t squared_viewport_area =
max_viewport_dimension * max_viewport_dimension;
if (maximum_area <= squared_viewport_area)
can_raster_at_maximum_scale = true;
}
if (starting_scale != kNotScaled && starting_scale > maximum_scale) {
gfx::Size bounds_at_starting_scale =
gfx::ScaleToCeiledSize(raster_source_->GetSize(), starting_scale);
int64_t start_area =
static_cast<int64_t>(bounds_at_starting_scale.width()) *
static_cast<int64_t>(bounds_at_starting_scale.height());
gfx::Size viewport = layer_tree_impl()->GetDeviceViewport().size();
int64_t viewport_area = static_cast<int64_t>(viewport.width()) *
static_cast<int64_t>(viewport.height());
if (start_area <= viewport_area)
should_raster_at_starting_scale = true;
}
// Use the computed scales for the raster scale directly, do not try to use
// the ideal scale here. The current ideal scale may be way too large in the
// case of an animation with scale, and will be constantly changing.
float animation_desired_scale;
if (should_raster_at_starting_scale)
animation_desired_scale = starting_scale;
else if (can_raster_at_maximum_scale)
animation_desired_scale = maximum_scale;
else
animation_desired_scale = 1.f * ideal_page_scale_ * ideal_device_scale_;
if (HasWillChangeTransformHint()) {
// If we have a will-change: transform hint, do not shrink the content
// raster scale, otherwise we will end up throwing away larger tiles we
// may need again.
raster_contents_scale_ =
std::max(preserved_raster_contents_scale, animation_desired_scale);
} else {
raster_contents_scale_ = animation_desired_scale;
}
}
if (HasWillChangeTransformHint()) { if (HasWillChangeTransformHint()) {
raster_contents_scale_ = raster_contents_scale_ =
...@@ -1544,6 +1479,46 @@ void PictureLayerImpl::RecalculateRasterScales() { ...@@ -1544,6 +1479,46 @@ void PictureLayerImpl::RecalculateRasterScales() {
DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale()); DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale());
} }
void PictureLayerImpl::AdjustRasterScaleForTransformAnimation(
float preserved_raster_contents_scale) {
DCHECK(draw_properties().screen_space_transform_is_animating);
CombinedAnimationScale animation_scales =
layer_tree_impl()->property_trees()->GetAnimationScales(
transform_tree_index(), layer_tree_impl());
float maximum_scale = animation_scales.maximum_animation_scale;
float starting_scale = animation_scales.starting_animation_scale;
// Adjust raster scale only if the animation scale is known.
if (maximum_scale == kNotScaled && starting_scale == kNotScaled)
return;
// We rasterize at the maximum scale that will occur during the animation.
raster_contents_scale_ = std::max(maximum_scale, starting_scale);
DCHECK_NE(raster_contents_scale_, kNotScaled);
// However we want to avoid excessive memory use. Choose a scale at which this
// layer's rastered content is not larger than the viewport.
gfx::Size viewport = layer_tree_impl()->GetDeviceViewport().size();
float max_viewport_dimension = std::max(viewport.width(), viewport.height());
DCHECK(max_viewport_dimension);
// Use square to compensate for viewports with different aspect ratios.
float squared_viewport_area = max_viewport_dimension * max_viewport_dimension;
gfx::Size bounds_at_maximum_scale =
gfx::ScaleToCeiledSize(raster_source_->GetSize(), raster_contents_scale_);
float maximum_area = static_cast<float>(bounds_at_maximum_scale.width()) *
bounds_at_maximum_scale.height();
// Clamp the scale to make the rastered content not larger than the viewport.
if (UNLIKELY(maximum_area > squared_viewport_area))
raster_contents_scale_ /= std::sqrt(maximum_area / squared_viewport_area);
if (HasWillChangeTransformHint()) {
// If we have a will-change: transform hint, do not shrink the content
// raster scale, otherwise we will end up throwing away larger tiles we
// may need again.
raster_contents_scale_ =
std::max(preserved_raster_contents_scale, raster_contents_scale_);
}
}
void PictureLayerImpl::CleanUpTilingsOnActiveLayer( void PictureLayerImpl::CleanUpTilingsOnActiveLayer(
const std::vector<PictureLayerTiling*>& used_tilings) { const std::vector<PictureLayerTiling*>& used_tilings) {
DCHECK(layer_tree_impl()->IsActiveTree()); DCHECK(layer_tree_impl()->IsActiveTree());
......
...@@ -177,6 +177,8 @@ class CC_EXPORT PictureLayerImpl ...@@ -177,6 +177,8 @@ class CC_EXPORT PictureLayerImpl
void AddLowResolutionTilingIfNeeded(); void AddLowResolutionTilingIfNeeded();
bool ShouldAdjustRasterScale() const; bool ShouldAdjustRasterScale() const;
void RecalculateRasterScales(); void RecalculateRasterScales();
void AdjustRasterScaleForTransformAnimation(
float preserved_raster_contents_scale);
float MinimumRasterContentsScaleForWillChangeTransform() const; float MinimumRasterContentsScaleForWillChangeTransform() const;
// Returns false if raster translation is not applicable. // Returns false if raster translation is not applicable.
bool CalculateRasterTranslation(gfx::Vector2dF& raster_translation) const; bool CalculateRasterTranslation(gfx::Vector2dF& raster_translation) const;
......
This diff is collapsed.
...@@ -217,11 +217,11 @@ crbug.com/1093466 virtual/portals/http/tests/portals/* [ Pass ] ...@@ -217,11 +217,11 @@ crbug.com/1093466 virtual/portals/http/tests/portals/* [ Pass ]
crbug.com/1093466 virtual/portals/wpt_internal/portals/* [ Pass ] crbug.com/1093466 virtual/portals/wpt_internal/portals/* [ Pass ]
# Subpixel differences # Subpixel differences
crbug.com/771643 external/wpt/css/css-backgrounds/background-attachment-local/attachment-local-clipping-color-5.html [ Failure ] crbug.com/997202 external/wpt/css/css-backgrounds/background-attachment-local/attachment-local-clipping-color-5.html [ Failure ]
crbug.com/771643 external/wpt/css/css-backgrounds/background-attachment-local/attachment-local-clipping-image-5.html [ Failure ] crbug.com/997202 external/wpt/css/css-backgrounds/background-attachment-local/attachment-local-clipping-image-5.html [ Failure ]
crbug.com/997202 external/wpt/css/css-backgrounds/border-radius-clip-001.html [ Failure ] crbug.com/997202 external/wpt/css/css-backgrounds/border-radius-clip-001.html [ Failure ]
crbug.com/997202 external/wpt/css/css-backgrounds/border-radius-clip-002.htm [ Failure ] crbug.com/997202 external/wpt/css/css-backgrounds/border-radius-clip-002.htm [ Failure ]
crbug.com/986110 external/wpt/css/css-transforms/perspective-transforms-equivalence.html [ Failure ] crbug.com/997202 external/wpt/css/css-transforms/perspective-transforms-equivalence.html [ Failure ]
crbug.com/807395 fast/multicol/mixed-opacity-test.html [ Failure ] crbug.com/807395 fast/multicol/mixed-opacity-test.html [ Failure ]
...@@ -263,9 +263,9 @@ crbug.com/974720 [ Mac10.13 ] virtual/text-antialias/firstline/capitalize-transf ...@@ -263,9 +263,9 @@ crbug.com/974720 [ Mac10.13 ] virtual/text-antialias/firstline/capitalize-transf
crbug.com/974720 [ Mac10.13 ] virtual/text-antialias/firstline/capitalize-transform.html [ Pass Crash ] crbug.com/974720 [ Mac10.13 ] virtual/text-antialias/firstline/capitalize-transform.html [ Pass Crash ]
# Subpixel differences due to compositing on Mac10.14+. # Subpixel differences due to compositing on Mac10.14+.
crbug.com/1079418 [ Mac10.14 ] external/wpt/svg/extensibility/foreignObject/foreign-object-scale-scroll.html [ Failure ] crbug.com/997202 [ Mac10.14 ] external/wpt/svg/extensibility/foreignObject/foreign-object-scale-scroll.html [ Failure ]
crbug.com/1079418 [ Mac10.15 ] external/wpt/svg/extensibility/foreignObject/foreign-object-scale-scroll.html [ Failure ] crbug.com/997202 [ Mac10.15 ] external/wpt/svg/extensibility/foreignObject/foreign-object-scale-scroll.html [ Failure ]
crbug.com/1079418 [ Mac11.0 ] external/wpt/svg/extensibility/foreignObject/foreign-object-scale-scroll.html [ Failure ] crbug.com/997202 [ Mac11.0 ] external/wpt/svg/extensibility/foreignObject/foreign-object-scale-scroll.html [ Failure ]
# This test depends on synchronous focus() which does not exist (anymore?). # This test depends on synchronous focus() which does not exist (anymore?).
crbug.com/1074482 external/wpt/html/interaction/focus/the-autofocus-attribute/update-the-rendering.html [ Failure ] crbug.com/1074482 external/wpt/html/interaction/focus/the-autofocus-attribute/update-the-rendering.html [ Failure ]
...@@ -347,9 +347,9 @@ crbug.com/898394 virtual/android/url-bar/bottom-and-top-fixed-sticks-to-top.html ...@@ -347,9 +347,9 @@ crbug.com/898394 virtual/android/url-bar/bottom-and-top-fixed-sticks-to-top.html
crbug.com/1024151 http/tests/devtools/tracing/timeline-style/timeline-style-recalc-all-invalidator-types.js [ Failure Pass ] crbug.com/1024151 http/tests/devtools/tracing/timeline-style/timeline-style-recalc-all-invalidator-types.js [ Failure Pass ]
# Subpixel rounding differences that are incorrect. # Subpixel rounding differences that are incorrect.
crbug.com/836886 compositing/overflow/scaled-overflow.html [ Failure ] crbug.com/997202 compositing/overflow/scaled-overflow.html [ Failure ]
# Flaky subpixel AA difference (not necessarily incorrect, but flaky) # Flaky subpixel AA difference (not necessarily incorrect, but flaky)
crbug.com/921105 virtual/threaded-no-composited-antialiasing/animations/skew-notsequential-compositor.html [ Failure Pass ] crbug.com/997202 virtual/threaded-no-composited-antialiasing/animations/skew-notsequential-compositor.html [ Failure Pass ]
crbug.com/954591 external/wpt/css/css-transforms/composited-under-rotateY-180deg.html [ Failure ] crbug.com/954591 external/wpt/css/css-transforms/composited-under-rotateY-180deg.html [ Failure ]
crbug.com/954591 external/wpt/css/css-transforms/composited-under-rotateY-180deg-clip.html [ Failure ] crbug.com/954591 external/wpt/css/css-transforms/composited-under-rotateY-180deg-clip.html [ Failure ]
...@@ -1787,7 +1787,7 @@ crbug.com/528062 [ Win ] http/tests/security/contentSecurityPolicy/cached-frame- ...@@ -1787,7 +1787,7 @@ crbug.com/528062 [ Win ] http/tests/security/contentSecurityPolicy/cached-frame-
# In this configuration, the pixel smoothed glyphs will be created from subpixel smoothed glyphs. # In this configuration, the pixel smoothed glyphs will be created from subpixel smoothed glyphs.
# This means that CoreGraphics may draw outside the reported glyph bounds, and in this case does. # This means that CoreGraphics may draw outside the reported glyph bounds, and in this case does.
# By about a quarter or less of a pixel. # By about a quarter or less of a pixel.
crbug.com/421412 [ Mac ] virtual/text-antialias/international/bdo-bidi-width.html [ Failure ] crbug.com/997202 [ Mac ] virtual/text-antialias/international/bdo-bidi-width.html [ Failure ]
crbug.com/574283 [ Mac ] fast/scroll-behavior/smooth-scroll/ongoing-smooth-scroll-anchors.html [ Skip ] crbug.com/574283 [ Mac ] fast/scroll-behavior/smooth-scroll/ongoing-smooth-scroll-anchors.html [ Skip ]
crbug.com/574283 [ Mac ] virtual/threaded-prefer-compositing/fast/scroll-behavior/smooth-scroll/fixed-background-in-iframe.html [ Skip ] crbug.com/574283 [ Mac ] virtual/threaded-prefer-compositing/fast/scroll-behavior/smooth-scroll/fixed-background-in-iframe.html [ Skip ]
...@@ -5938,10 +5938,7 @@ crbug.com/1145019 [ Win7 ] fast/events/updateLayoutForHitTest.html [ Failure ] ...@@ -5938,10 +5938,7 @@ crbug.com/1145019 [ Win7 ] fast/events/updateLayoutForHitTest.html [ Failure ]
# Lack of support for reftest fuzzy matching # Lack of support for reftest fuzzy matching
# Reftests have minor pixel differences due to antialiasing. # Reftests have minor pixel differences due to antialiasing.
crbug.com/997202 [ Mac ] external/wpt/css/css-transforms/animation/transform-interpolation-rotate-slerp.html [ Failure ] crbug.com/997202 external/wpt/css/css-transforms/animation/transform-interpolation-rotate-slerp.html [ Failure ]
crbug.com/997202 [ Mac ] virtual/composite-relative-keyframes/external/wpt/css/css-transforms/animation/transform-interpolation-rotate-slerp.html [ Failure ]
crbug.com/997202 [ Mac ] virtual/threaded/external/wpt/css/css-transforms/animation/transform-interpolation-rotate-slerp.html [ Failure ]
crbug.com/997202 [ Mac ] virtual/transform-interop/external/wpt/css/css-transforms/animation/transform-interpolation-rotate-slerp.html [ Failure ]
# Sheriff 2020-11-04 # Sheriff 2020-11-04
crbug.com/1144273 http/tests/devtools/sources/debugger-ui/continue-to-location-markers-in-top-level-function.js [ Pass Failure Timeout ] crbug.com/1144273 http/tests/devtools/sources/debugger-ui/continue-to-location-markers-in-top-level-function.js [ Pass Failure Timeout ]
......
<!DOCTYPE html>
<div style="width: 200px; height: 100px; background: blue"></div>
<div style="width: 200px; height: 100px; background: green"></div>
<!DOCTYPE html>
<title>Transform animation under large scale</title>
<link rel="author" title="Xianzhu Wang" href="mailto:wangxianzhu@chromium.org">
<link rel="help" href="https://crbug.com/1153428">
<link rel="match" href="transform-animation-under-large-scale-ref.html">
<style>
@keyframes move {
0% {transform: translateX(-1px);}
100% {transform: translateX(0);}
}
</style>
<div style="width: 2px; height: 2px; transform: scale(100); transform-origin: 0 0; overflow: hidden">
<div style="animation: move 1s infinite alternate">
<div style="width: 4px; height: 1px; background: blue"></div>
<div style="width: 4px; height: 1px; background: green"></div>
</div>
</div>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment