Commit 60b33bf2 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Split out additive behavior handling from AnimateAdditiveNumber

This removes the need of passing an out-parameter to the function. For
calling code this means it's easy to separate the mutation of the object
itself (the addition) from the rest of the computation.

Move variable definitions around to move closer to their actual use.

Bug: 1017723
Change-Id: Icca4d0cd3c0e421c8ba2c9867cdd60eabeac4c11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2395716Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#805258}
parent aea5524b
......@@ -16,15 +16,15 @@ struct SMILAnimationEffectParameters {
bool is_cumulative = false;
};
// Compute the animated number value based on effect parameters and timing data.
inline void AnimateAdditiveNumber(
// Compute the animated number value, excluding additive behavior, based on
// effect parameters and timing data.
inline float ComputeAnimatedNumber(
const SMILAnimationEffectParameters& parameters,
float percentage,
unsigned repeat_count,
float from_number,
float to_number,
float to_at_end_of_duration_number,
float& animated_number) {
float to_at_end_of_duration_number) {
float number;
if (parameters.is_discrete)
number = percentage < 0.5 ? from_number : to_number;
......@@ -32,9 +32,7 @@ inline void AnimateAdditiveNumber(
number = (to_number - from_number) * percentage + from_number;
if (repeat_count && parameters.is_cumulative)
number += to_at_end_of_duration_number * repeat_count;
if (parameters.is_additive)
number += animated_number;
animated_number = number;
return number;
}
} // namespace blink
......
......@@ -378,13 +378,14 @@ void SVGAngle::CalculateAnimatedValue(
return;
}
float animated_value = Value();
AnimateAdditiveNumber(parameters, percentage, repeat_count,
from_angle->Value(), to_angle->Value(),
To<SVGAngle>(to_at_end_of_duration)->Value(),
animated_value);
float result = ComputeAnimatedNumber(
parameters, percentage, repeat_count, from_angle->Value(),
to_angle->Value(), To<SVGAngle>(to_at_end_of_duration)->Value());
if (parameters.is_additive)
result += Value();
OrientType()->SetEnumValue(kSVGMarkerOrientAngle);
SetValue(animated_value);
SetValue(result);
}
float SVGAngle::CalculateDistance(const SVGPropertyBase* other,
......
......@@ -217,16 +217,12 @@ void SVGAnimateMotionElement::CalculateAnimatedValue(float percentage,
transform->MakeIdentity();
if (GetAnimationMode() != kPathAnimation) {
float animated_x = 0;
AnimateAdditiveNumber(parameters, percentage, repeat_count, from_point_.X(),
to_point_.X(), to_point_at_end_of_duration_.X(),
animated_x);
float animated_y = 0;
AnimateAdditiveNumber(parameters, percentage, repeat_count, from_point_.Y(),
to_point_.Y(), to_point_at_end_of_duration_.Y(),
animated_y);
float animated_x = ComputeAnimatedNumber(
parameters, percentage, repeat_count, from_point_.X(), to_point_.X(),
to_point_at_end_of_duration_.X());
float animated_y = ComputeAnimatedNumber(
parameters, percentage, repeat_count, from_point_.Y(), to_point_.Y(),
to_point_at_end_of_duration_.Y());
transform->Translate(animated_x, animated_y);
return;
}
......
......@@ -97,27 +97,27 @@ void SVGColorProperty::CalculateAnimatedValue(
Color to_color = to_style_color.Resolve(fallback_color, color_scheme);
Color to_at_end_of_duration_color =
to_at_end_of_duration_style_color.Resolve(fallback_color, color_scheme);
Color animated_color = style_color_.Resolve(fallback_color, color_scheme);
float animated_red = animated_color.Red();
AnimateAdditiveNumber(parameters, percentage, repeat_count, from_color.Red(),
to_color.Red(), to_at_end_of_duration_color.Red(),
animated_red);
float animated_green = animated_color.Green();
AnimateAdditiveNumber(parameters, percentage, repeat_count,
from_color.Green(), to_color.Green(),
to_at_end_of_duration_color.Green(), animated_green);
float animated_blue = animated_color.Blue();
AnimateAdditiveNumber(parameters, percentage, repeat_count, from_color.Blue(),
to_color.Blue(), to_at_end_of_duration_color.Blue(),
animated_blue);
float animated_alpha = animated_color.Alpha();
AnimateAdditiveNumber(parameters, percentage, repeat_count,
from_color.Alpha(), to_color.Alpha(),
to_at_end_of_duration_color.Alpha(), animated_alpha);
float animated_red = ComputeAnimatedNumber(
parameters, percentage, repeat_count, from_color.Red(), to_color.Red(),
to_at_end_of_duration_color.Red());
float animated_green = ComputeAnimatedNumber(
parameters, percentage, repeat_count, from_color.Green(),
to_color.Green(), to_at_end_of_duration_color.Green());
float animated_blue = ComputeAnimatedNumber(
parameters, percentage, repeat_count, from_color.Blue(), to_color.Blue(),
to_at_end_of_duration_color.Blue());
float animated_alpha = ComputeAnimatedNumber(
parameters, percentage, repeat_count, from_color.Alpha(),
to_color.Alpha(), to_at_end_of_duration_color.Alpha());
if (parameters.is_additive) {
Color animated_color = style_color_.Resolve(fallback_color, color_scheme);
animated_red += animated_color.Red();
animated_green += animated_color.Green();
animated_blue += animated_color.Blue();
animated_alpha += animated_color.Alpha();
}
style_color_ =
StyleColor(MakeRGBA(roundf(animated_red), roundf(animated_green),
......
......@@ -74,11 +74,13 @@ void SVGInteger::CalculateAnimatedValue(
auto* to_integer = To<SVGInteger>(to);
auto* to_at_end_of_duration_integer = To<SVGInteger>(to_at_end_of_duration);
float animated_float = value_;
AnimateAdditiveNumber(parameters, percentage, repeat_count,
from_integer->Value(), to_integer->Value(),
to_at_end_of_duration_integer->Value(), animated_float);
value_ = clampTo<int>(roundf(animated_float));
float result = ComputeAnimatedNumber(
parameters, percentage, repeat_count, from_integer->Value(),
to_integer->Value(), to_at_end_of_duration_integer->Value());
if (parameters.is_additive)
result += value_;
value_ = clampTo<int>(roundf(result));
}
float SVGInteger::CalculateDistance(const SVGPropertyBase* other,
......
......@@ -333,28 +333,31 @@ void SVGLength::CalculateAnimatedValue(
To<SVGLength>(to_at_end_of_duration_value);
SVGLengthContext length_context(context_element);
float animated_number = Value(length_context);
AnimateAdditiveNumber(
float result = ComputeAnimatedNumber(
parameters, percentage, repeat_count, from_length->Value(length_context),
to_length->Value(length_context),
to_at_end_of_duration_length->Value(length_context), animated_number);
to_at_end_of_duration_length->Value(length_context));
// TODO(shanmuga.m): Construct a calc() expression if the units fall in
// different categories.
CSSPrimitiveValue::UnitType new_unit =
CSSPrimitiveValue::UnitType result_unit =
CSSPrimitiveValue::UnitType::kUserUnits;
if (percentage < 0.5) {
if (!from_length->IsCalculated()) {
new_unit = from_length->NumericLiteralType();
result_unit = from_length->NumericLiteralType();
}
} else {
if (!to_length->IsCalculated()) {
new_unit = to_length->NumericLiteralType();
result_unit = to_length->NumericLiteralType();
}
}
animated_number = length_context.ConvertValueFromUserUnits(
animated_number, UnitMode(), new_unit);
value_ = CSSNumericLiteralValue::Create(animated_number, new_unit);
if (parameters.is_additive)
result += Value(length_context);
value_ = CSSNumericLiteralValue::Create(
length_context.ConvertValueFromUserUnits(result, UnitMode(), result_unit),
result_unit);
}
float SVGLength::CalculateDistance(const SVGPropertyBase* to_value,
......
......@@ -86,9 +86,13 @@ void SVGNumber::CalculateAnimatedValue(
auto* to_number = To<SVGNumber>(to);
auto* to_at_end_of_duration_number = To<SVGNumber>(to_at_end_of_duration);
AnimateAdditiveNumber(parameters, percentage, repeat_count,
from_number->Value(), to_number->Value(),
to_at_end_of_duration_number->Value(), value_);
float result = ComputeAnimatedNumber(parameters, percentage, repeat_count,
from_number->Value(), to_number->Value(),
to_at_end_of_duration_number->Value());
if (parameters.is_additive)
result += value_;
value_ = result;
}
float SVGNumber::CalculateDistance(const SVGPropertyBase* other,
......
......@@ -94,6 +94,10 @@ void SVGPointList::CalculateAnimatedValue(
const SVGElement* context_element) {
auto* from_list = To<SVGPointList>(from_value);
auto* to_list = To<SVGPointList>(to_value);
if (!AdjustFromToListValues(from_list, to_list, percentage))
return;
auto* to_at_end_of_duration_list =
To<SVGPointList>(to_at_end_of_duration_value);
......@@ -102,13 +106,7 @@ void SVGPointList::CalculateAnimatedValue(
uint32_t to_at_end_of_duration_list_size =
to_at_end_of_duration_list->length();
if (!AdjustFromToListValues(from_list, to_list, percentage))
return;
for (uint32_t i = 0; i < to_point_list_size; ++i) {
float animated_x = at(i)->X();
float animated_y = at(i)->Y();
FloatPoint effective_from;
if (from_point_list_size)
effective_from = from_list->at(i)->Value();
......@@ -117,13 +115,17 @@ void SVGPointList::CalculateAnimatedValue(
if (i < to_at_end_of_duration_list_size)
effective_to_at_end = to_at_end_of_duration_list->at(i)->Value();
AnimateAdditiveNumber(parameters, percentage, repeat_count,
effective_from.X(), effective_to.X(),
effective_to_at_end.X(), animated_x);
AnimateAdditiveNumber(parameters, percentage, repeat_count,
effective_from.Y(), effective_to.Y(),
effective_to_at_end.Y(), animated_y);
at(i)->SetValue(FloatPoint(animated_x, animated_y));
FloatPoint result(
ComputeAnimatedNumber(parameters, percentage, repeat_count,
effective_from.X(), effective_to.X(),
effective_to_at_end.X()),
ComputeAnimatedNumber(parameters, percentage, repeat_count,
effective_from.Y(), effective_to.Y(),
effective_to_at_end.Y()));
if (parameters.is_additive)
result += at(i)->Value();
at(i)->SetValue(result);
}
}
......
......@@ -102,24 +102,22 @@ void SVGRect::CalculateAnimatedValue(
auto* to_rect = To<SVGRect>(to_value);
auto* to_at_end_of_duration_rect = To<SVGRect>(to_at_end_of_duration_value);
float animated_x = X();
float animated_y = Y();
float animated_width = Width();
float animated_height = Height();
AnimateAdditiveNumber(parameters, percentage, repeat_count, from_rect->X(),
to_rect->X(), to_at_end_of_duration_rect->X(),
animated_x);
AnimateAdditiveNumber(parameters, percentage, repeat_count, from_rect->Y(),
to_rect->Y(), to_at_end_of_duration_rect->Y(),
animated_y);
AnimateAdditiveNumber(parameters, percentage, repeat_count,
from_rect->Width(), to_rect->Width(),
to_at_end_of_duration_rect->Width(), animated_width);
AnimateAdditiveNumber(parameters, percentage, repeat_count,
from_rect->Height(), to_rect->Height(),
to_at_end_of_duration_rect->Height(), animated_height);
value_ = FloatRect(animated_x, animated_y, animated_width, animated_height);
FloatRect result(ComputeAnimatedNumber(parameters, percentage, repeat_count,
from_rect->X(), to_rect->X(),
to_at_end_of_duration_rect->X()),
ComputeAnimatedNumber(parameters, percentage, repeat_count,
from_rect->Y(), to_rect->Y(),
to_at_end_of_duration_rect->Y()),
ComputeAnimatedNumber(parameters, percentage, repeat_count,
from_rect->Width(), to_rect->Width(),
to_at_end_of_duration_rect->Width()),
ComputeAnimatedNumber(parameters, percentage, repeat_count,
from_rect->Height(), to_rect->Height(),
to_at_end_of_duration_rect->Height()));
if (parameters.is_additive)
result += value_;
value_ = result;
}
float SVGRect::CalculateDistance(const SVGPropertyBase* to,
......
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