Bug 1592822 - Use Serde for OffsetRotate and PositionOrAuto. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D60088

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Chiou 2020-01-22 20:18:38 +00:00
Родитель 14387265a7
Коммит ffa1ebad7b
9 изменённых файлов: 47 добавлений и 73 удалений

Просмотреть файл

@ -874,6 +874,8 @@ inline mozilla::StyleVecU8 ConvertToStyleVecU8(mozilla::ipc::ByteBuf&& aOther) {
IMPL_PARAMTRAITS_BY_SERDE(LengthPercentage)
IMPL_PARAMTRAITS_BY_SERDE(StyleOffsetPath)
IMPL_PARAMTRAITS_BY_SERDE(StyleOffsetRotate)
IMPL_PARAMTRAITS_BY_SERDE(StylePositionOrAuto)
IMPL_PARAMTRAITS_BY_SERDE(StyleRotate)
IMPL_PARAMTRAITS_BY_SERDE(StyleScale)
IMPL_PARAMTRAITS_BY_SERDE(StyleTranslate)

Просмотреть файл

@ -61,6 +61,8 @@ using mozilla::VsyncId from "mozilla/VsyncDispatcher.h";
using mozilla::LengthPercentage from "mozilla/ServoStyleConsts.h";
using mozilla::RayReferenceData from "mozilla/MotionPathUtils.h";
using mozilla::StyleOffsetPath from "mozilla/ServoStyleConsts.h";
using mozilla::StyleOffsetRotate from "mozilla/ServoStyleConsts.h";
using mozilla::StylePositionOrAuto from "mozilla/ServoStyleConsts.h";
using mozilla::StyleRotate from "mozilla/ServoStyleConsts.h";
using mozilla::StyleScale from "mozilla/ServoStyleConsts.h";
using mozilla::StyleTranslate from "mozilla/ServoStyleConsts.h";
@ -117,31 +119,8 @@ union TimingFunction {
StepFunction;
};
// Send the angle with units rather than sending all angles in radians
// to avoid having floating point error introduced by unit switching.
struct CSSAngle {
float value;
int unit; // an nsCSSUnit that is valid for angles
};
struct LayerColor { Color value; };
struct OffsetRotate {
CSSAngle angle;
bool isAuto;
};
struct AnchorPosition {
LengthPercentage horizontal;
LengthPercentage vertical;
};
union OffsetAnchor {
// null_t represents auto
null_t;
AnchorPosition;
};
union Animatable {
null_t;
float;
@ -152,8 +131,8 @@ union Animatable {
StyleTransform;
StyleOffsetPath;
LengthPercentage;
OffsetRotate;
OffsetAnchor;
StyleOffsetRotate;
StylePositionOrAuto;
};
struct AnimationSegment {

Просмотреть файл

@ -203,10 +203,6 @@ nsCString ActiveScrolledRoot::ToString(
return std::move(str);
}
static inline CSSAngle MakeCSSAngle(const StyleAngle& aValue) {
return CSSAngle(aValue.ToDegrees(), eCSSUnit_Degree);
}
static StyleTransformOperation ResolveTranslate(
TransformReferenceBox& aRefBox, const LengthPercentage& aX,
const LengthPercentage& aY = LengthPercentage::Zero(),
@ -387,21 +383,12 @@ static void SetAnimatable(nsCSSPropertyID aProperty,
case eCSSProperty_offset_distance:
aAnimatable = aAnimationValue.GetOffsetDistanceProperty();
break;
case eCSSProperty_offset_rotate: {
const StyleOffsetRotate& r = aAnimationValue.GetOffsetRotateProperty();
aAnimatable = OffsetRotate(MakeCSSAngle(r.angle), r.auto_);
case eCSSProperty_offset_rotate:
aAnimatable = aAnimationValue.GetOffsetRotateProperty();
break;
}
case eCSSProperty_offset_anchor: {
const StylePositionOrAuto& p = aAnimationValue.GetOffsetAnchorProperty();
if (p.IsAuto()) {
aAnimatable = OffsetAnchor(null_t());
break;
}
aAnimatable = OffsetAnchor(
AnchorPosition(p.AsPosition().horizontal, p.AsPosition().vertical));
case eCSSProperty_offset_anchor:
aAnimatable = aAnimationValue.GetOffsetAnchorProperty();
break;
}
default:
MOZ_ASSERT_UNREACHABLE("Unsupported property");
}
@ -780,16 +767,12 @@ static void AddNonAnimatingTransformLikePropertiesStyles(
case eCSSProperty_offset_rotate:
if (hasMotion && (!display->mOffsetRotate.auto_ ||
display->mOffsetRotate.angle.ToDegrees() != 0.0)) {
const StyleOffsetRotate& rotate = display->mOffsetRotate;
appendFakeAnimation(
id, OffsetRotate(MakeCSSAngle(rotate.angle), rotate.auto_));
appendFakeAnimation(id, display->mOffsetRotate);
}
break;
case eCSSProperty_offset_anchor:
if (hasMotion && !display->mOffsetAnchor.IsAuto()) {
const StylePosition& position = display->mOffsetAnchor.AsPosition();
appendFakeAnimation(id, OffsetAnchor(AnchorPosition(
position.horizontal, position.vertical)));
appendFakeAnimation(id, display->mOffsetAnchor);
}
break;
default:

Просмотреть файл

@ -70,6 +70,8 @@ BASIC_SERDE_FUNCS(StyleScale)
BASIC_SERDE_FUNCS(StyleTranslate)
BASIC_SERDE_FUNCS(StyleTransform)
BASIC_SERDE_FUNCS(StyleOffsetPath)
BASIC_SERDE_FUNCS(StyleOffsetRotate)
BASIC_SERDE_FUNCS(StylePositionOrAuto)
#undef BASIC_SERDE_FUNCS

Просмотреть файл

@ -42,17 +42,6 @@ using nsStyleTransformMatrix::Decompose2DMatrix;
using nsStyleTransformMatrix::Decompose3DMatrix;
using nsStyleTransformMatrix::ShearType;
// TODO(emilio): Remove angle unit in a followup, should always be degrees.
static inline StyleAngle GetCSSAngle(const layers::CSSAngle& aAngle) {
if (aAngle.unit() != eCSSUnit_Degree) {
NS_ERROR("Bogus animation from IPC");
return StyleAngle{0.0};
}
return StyleAngle{aAngle.value()};
}
// AnimationValue Implementation
bool AnimationValue::operator==(const AnimationValue& aOther) const {
if (mServo && aOther.mServo) {
return Servo_AnimationValue_DeepEqual(mServo, aOther.mServo);
@ -271,20 +260,14 @@ already_AddRefed<RawServoAnimationValue> AnimationValue::FromAnimatable(
return Servo_AnimationValue_OffsetDistance(
&aAnimatable.get_LengthPercentage())
.Consume();
case layers::Animatable::TOffsetRotate: {
const layers::OffsetRotate& r = aAnimatable.get_OffsetRotate();
auto rotate = StyleOffsetRotate{r.isAuto(), GetCSSAngle(r.angle())};
return Servo_AnimationValue_OffsetRotate(&rotate).Consume();
}
case layers::Animatable::TOffsetAnchor: {
const layers::OffsetAnchor& a = aAnimatable.get_OffsetAnchor();
auto anchor = a.type() == layers::OffsetAnchor::Type::Tnull_t
? StylePositionOrAuto::Auto()
: StylePositionOrAuto::Position(
StylePosition{a.get_AnchorPosition().horizontal(),
a.get_AnchorPosition().vertical()});
return Servo_AnimationValue_OffsetAnchor(&anchor).Consume();
}
case layers::Animatable::TStyleOffsetRotate:
return Servo_AnimationValue_OffsetRotate(
&aAnimatable.get_StyleOffsetRotate())
.Consume();
case layers::Animatable::TStylePositionOrAuto:
return Servo_AnimationValue_OffsetAnchor(
&aAnimatable.get_StylePositionOrAuto())
.Consume();
default:
MOZ_ASSERT_UNREACHABLE("Unsupported type");
}

Просмотреть файл

@ -23,8 +23,10 @@ fn is_auto_zero_angle(auto: &bool, angle: &Angle) -> bool {
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
ToAnimatedZero,
ToCss,
ToResolvedValue,

Просмотреть файл

@ -12,8 +12,10 @@
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
@ -44,15 +46,18 @@ impl<H, V> Position<H, V> {
/// A generic type for representing an `Auto | <position>`.
/// This is used by <offset-anchor> for now.
/// https://drafts.fxtf.org/motion-1/#offset-anchor-property
/// cbindgen:private-default-tagged-enum-constructor=false
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
Parse,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedZero,
ToComputedValue,

Просмотреть файл

@ -721,3 +721,9 @@ public:
// The implementation of IPC LayersMessages needs this to be public.
StyleGenericOffsetPath(): tag(Tag::None) {}
"""
"GenericPositionOrAuto" = """
public:
// The implementation of IPC LayersMessages needs this to be public.
StyleGenericPositionOrAuto(): tag(Tag::Auto) {}
"""

Просмотреть файл

@ -1073,6 +1073,18 @@ impl_basic_serde_funcs!(
computed::motion::OffsetPath
);
impl_basic_serde_funcs!(
Servo_StyleOffsetRotate_Serialize,
Servo_StyleOffsetRotate_Deserialize,
computed::motion::OffsetRotate
);
impl_basic_serde_funcs!(
Servo_StylePositionOrAuto_Serialize,
Servo_StylePositionOrAuto_Deserialize,
computed::position::PositionOrAuto
);
#[no_mangle]
pub extern "C" fn Servo_SVGPathData_Normalize(
input: &specified::SVGPathData,