This source file includes following definitions.
- HasAnimationThatInflatesBounds
- HasFilterAnimationThatInflatesBounds
- HasTransformAnimationThatInflatesBounds
- HasAncestorTransformAnimation
- HasAncestorFilterAnimation
- GetAnimationBounds
#include "cc/layers/layer_utils.h"
#include "cc/layers/layer_impl.h"
#include "cc/trees/layer_tree_host_common.h"
#include "ui/gfx/box_f.h"
namespace cc {
namespace {
bool HasAnimationThatInflatesBounds(const LayerImpl& layer) {
return layer.layer_animation_controller()->HasAnimationThatInflatesBounds();
}
bool HasFilterAnimationThatInflatesBounds(const LayerImpl& layer) {
return layer.layer_animation_controller()
->HasFilterAnimationThatInflatesBounds();
}
bool HasTransformAnimationThatInflatesBounds(const LayerImpl& layer) {
return layer.layer_animation_controller()
->HasTransformAnimationThatInflatesBounds();
}
inline bool HasAncestorTransformAnimation(const LayerImpl& layer) {
return layer.screen_space_transform_is_animating();
}
inline bool HasAncestorFilterAnimation(const LayerImpl& layer) {
for (const LayerImpl* current = &layer; current;
current = current->parent()) {
if (HasFilterAnimationThatInflatesBounds(*current))
return true;
}
return false;
}
}
bool LayerUtils::GetAnimationBounds(const LayerImpl& layer_in, gfx::BoxF* out) {
if (!layer_in.DrawsContent())
return false;
if (!HasAncestorTransformAnimation(layer_in) &&
!HasAncestorFilterAnimation(layer_in))
return false;
gfx::BoxF box(layer_in.bounds().width(), layer_in.bounds().height(), 0.f);
gfx::Transform coalesced_transform;
for (const LayerImpl* layer = &layer_in; layer; layer = layer->parent()) {
int anchor_x = layer->anchor_point().x() * layer->bounds().width();
int anchor_y = layer->anchor_point().y() * layer->bounds().height();
gfx::PointF position = layer->position();
if (layer->parent() && !HasAnimationThatInflatesBounds(*layer)) {
gfx::Transform composite_layer_transform;
composite_layer_transform.Translate3d(anchor_x + position.x(),
anchor_y + position.y(),
layer->anchor_point_z());
composite_layer_transform.PreconcatTransform(layer->transform());
composite_layer_transform.Translate3d(
-anchor_x, -anchor_y, -layer->anchor_point_z());
coalesced_transform.ConcatTransform(composite_layer_transform);
continue;
}
coalesced_transform.TransformBox(&box);
coalesced_transform.MakeIdentity();
box.set_origin(box.origin() + gfx::Vector3dF(-anchor_x,
-anchor_y,
-layer->anchor_point_z()));
if (HasFilterAnimationThatInflatesBounds(*layer)) {
gfx::BoxF inflated;
if (!layer->layer_animation_controller()->FilterAnimationBoundsForBox(
box, &inflated))
return false;
box = inflated;
}
if (HasTransformAnimationThatInflatesBounds(*layer)) {
gfx::BoxF inflated;
if (!layer->layer_animation_controller()->TransformAnimationBoundsForBox(
box, &inflated))
return false;
box = inflated;
}
box.set_origin(box.origin() + gfx::Vector3dF(anchor_x + position.x(),
anchor_y + position.y(),
layer->anchor_point_z()));
}
if (!coalesced_transform.IsIdentity())
coalesced_transform.TransformBox(&box);
*out = box;
return true;
}
}