Bug 1832173 - Remove HasArcFFI for AnimationValue. r=boris

See previous patches for context.

Differential Revision: https://phabricator.services.mozilla.com/D177622
This commit is contained in:
Emilio Cobos Álvarez 2023-05-11 08:25:36 +00:00
Родитель 266108bffa
Коммит 6f904444e8
28 изменённых файлов: 240 добавлений и 377 удалений

1
Cargo.lock сгенерированный
Просмотреть файл

@ -2035,6 +2035,7 @@ dependencies = [
"smallvec",
"style",
"style_traits",
"thin-vec",
"to_shmem",
]

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

@ -878,7 +878,7 @@ void Animation::CommitStyles(ErrorResult& aRv) {
bool changed = false;
nsCSSPropertyIDSet properties = keyframeEffect->GetPropertySet();
for (nsCSSPropertyID property : properties) {
RefPtr<RawServoAnimationValue> computedValue =
RefPtr<StyleAnimationValue> computedValue =
Servo_AnimationValueMap_GetValue(animationValues.get(), property)
.Consume();
if (computedValue) {

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

@ -32,7 +32,7 @@ namespace mozilla {
class ComputedStyle;
class EffectSet;
class RestyleTracker;
class StyleAnimationValue;
struct StyleAnimationValue;
struct StyleAnimationValueMap;
struct AnimationProperty;
struct NonOwningAnimationTarget;

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

@ -598,7 +598,7 @@ void KeyframeEffect::EnsureBaseStyle(
aBaseComputedStyle = aPresContext->StyleSet()->GetBaseContextForElement(
animatingElement, aComputedStyle);
}
RefPtr<RawServoAnimationValue> baseValue =
RefPtr<StyleAnimationValue> baseValue =
Servo_ComputedValues_ExtractAnimationValue(aBaseComputedStyle,
aProperty.mProperty)
.Consume();
@ -1322,10 +1322,7 @@ void KeyframeEffect::GetKeyframes(JSContext* aCx, nsTArray<JSObject*>& aResult,
propertyValue.mServoDeclarationBlock, propertyValue.mProperty,
&stringValue, computedStyle, customProperties, rawData);
} else {
RawServoAnimationValue* value =
mBaseValues.GetWeak(propertyValue.mProperty);
if (value) {
if (auto* value = mBaseValues.GetWeak(propertyValue.mProperty)) {
Servo_AnimationValue_Serialize(value, propertyValue.mProperty,
rawData, &stringValue);
}

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

@ -328,7 +328,7 @@ class KeyframeEffect : public AnimationEffect {
AnimationValue BaseStyle(nsCSSPropertyID aProperty) const {
AnimationValue result;
bool hasProperty = false;
// We cannot use getters_AddRefs on RawServoAnimationValue because it is
// We cannot use getters_AddRefs on StyleAnimationValue because it is
// an incomplete type, so Get() doesn't work. Instead, use GetWeak, and
// then assign the raw pointer to a RefPtr.
result.mServo = mBaseValues.GetWeak(aProperty, &hasProperty);
@ -464,7 +464,7 @@ class KeyframeEffect : public AnimationEffect {
// least one animation value that is composited with the underlying value
// (i.e. it uses the additive or accumulate composite mode).
using BaseValuesHashmap =
nsRefPtrHashtable<nsUint32HashKey, RawServoAnimationValue>;
nsRefPtrHashtable<nsUint32HashKey, StyleAnimationValue>;
BaseValuesHashmap mBaseValues;
private:

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

@ -3244,7 +3244,7 @@ nsDOMWindowUtils::GetUnanimatedComputedStyle(Element* aElement,
return NS_ERROR_FAILURE;
}
RefPtr<RawServoAnimationValue> value =
RefPtr<StyleAnimationValue> value =
Servo_ComputedValues_ExtractAnimationValue(computedStyle, propertyID)
.Consume();
if (!value) {

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

@ -34,8 +34,7 @@ using namespace mozilla::dom;
namespace mozilla {
using ServoAnimationValues =
CopyableAutoTArray<RefPtr<RawServoAnimationValue>, 1>;
using ServoAnimationValues = CopyableAutoTArray<RefPtr<StyleAnimationValue>, 1>;
/*static*/
SMILCSSValueType SMILCSSValueType::sSingleton;
@ -47,7 +46,7 @@ struct ValueWrapper {
mServoValues.AppendElement(aValue.mServo);
}
ValueWrapper(nsCSSPropertyID aPropID,
const RefPtr<RawServoAnimationValue>& aValue)
const RefPtr<StyleAnimationValue>& aValue)
: mPropID(aPropID), mServoValues{(aValue)} {}
ValueWrapper(nsCSSPropertyID aPropID, ServoAnimationValues&& aValues)
: mPropID(aPropID), mServoValues{std::move(aValues)} {}
@ -90,14 +89,14 @@ struct ValueWrapper {
// If both arguments are null, this method returns false.
//
// |aZeroValueStorage| should be a reference to a
// RefPtr<RawServoAnimationValue>. This is used where we may need to allocate a
// RefPtr<StyleAnimationValue>. This is used where we may need to allocate a
// new ServoAnimationValue to represent the appropriate zero value.
//
// Returns true on success, or otherwise.
static bool FinalizeServoAnimationValues(
const RefPtr<RawServoAnimationValue>*& aValue1,
const RefPtr<RawServoAnimationValue>*& aValue2,
RefPtr<RawServoAnimationValue>& aZeroValueStorage) {
const RefPtr<StyleAnimationValue>*& aValue1,
const RefPtr<StyleAnimationValue>*& aValue2,
RefPtr<StyleAnimationValue>& aZeroValueStorage) {
if (!aValue1 && !aValue2) {
return false;
}
@ -203,11 +202,11 @@ static bool AddOrAccumulateForServo(SMILValue& aDest,
"both of them exist");
for (size_t i = 0; i < len; i++) {
const RefPtr<RawServoAnimationValue>* valueToAdd =
const RefPtr<StyleAnimationValue>* valueToAdd =
aValueToAddWrapper ? &aValueToAddWrapper->mServoValues[i] : nullptr;
const RefPtr<RawServoAnimationValue>* destValue =
const RefPtr<StyleAnimationValue>* destValue =
aDestWrapper ? &aDestWrapper->mServoValues[i] : nullptr;
RefPtr<RawServoAnimationValue> zeroValueStorage;
RefPtr<StyleAnimationValue> zeroValueStorage;
if (!FinalizeServoAnimationValues(valueToAdd, destValue,
zeroValueStorage)) {
return false;
@ -223,7 +222,7 @@ static bool AddOrAccumulateForServo(SMILValue& aDest,
aDestWrapper->mServoValues.SetLength(len);
}
RefPtr<RawServoAnimationValue> result;
RefPtr<StyleAnimationValue> result;
if (aCompositeOp == CompositeOperation::Add) {
result = Servo_AnimationValues_Add(*destValue, *valueToAdd).Consume();
} else {
@ -307,10 +306,10 @@ static nsresult ComputeDistanceForServo(const ValueWrapper* aFromWrapper,
double squareDistance = 0;
for (size_t i = 0; i < len; i++) {
const RefPtr<RawServoAnimationValue>* fromValue =
const RefPtr<StyleAnimationValue>* fromValue =
aFromWrapper ? &aFromWrapper->mServoValues[0] : nullptr;
const RefPtr<RawServoAnimationValue>* toValue = &aToWrapper.mServoValues[0];
RefPtr<RawServoAnimationValue> zeroValueStorage;
const RefPtr<StyleAnimationValue>* toValue = &aToWrapper.mServoValues[0];
RefPtr<StyleAnimationValue> zeroValueStorage;
if (!FinalizeServoAnimationValues(fromValue, toValue, zeroValueStorage)) {
return NS_ERROR_FAILURE;
}
@ -370,16 +369,15 @@ static nsresult InterpolateForServo(const ValueWrapper* aStartWrapper,
"Start and end values length should be the same if "
"the start value exists");
for (size_t i = 0; i < len; i++) {
const RefPtr<RawServoAnimationValue>* startValue =
const RefPtr<StyleAnimationValue>* startValue =
aStartWrapper ? &aStartWrapper->mServoValues[i] : nullptr;
const RefPtr<RawServoAnimationValue>* endValue =
&aEndWrapper.mServoValues[i];
RefPtr<RawServoAnimationValue> zeroValueStorage;
const RefPtr<StyleAnimationValue>* endValue = &aEndWrapper.mServoValues[i];
RefPtr<StyleAnimationValue> zeroValueStorage;
if (!FinalizeServoAnimationValues(startValue, endValue, zeroValueStorage)) {
return NS_ERROR_FAILURE;
}
RefPtr<RawServoAnimationValue> result =
RefPtr<StyleAnimationValue> result =
Servo_AnimationValues_Interpolate(*startValue, *endValue, aUnitDistance)
.Consume();
if (!result) {
@ -558,8 +556,8 @@ void SMILCSSValueType::FinalizeValue(SMILValue& aValue,
ServoAnimationValues zeroValues;
zeroValues.SetCapacity(valueToMatchWrapper->mServoValues.Length());
for (auto& valueToMatch : valueToMatchWrapper->mServoValues) {
RefPtr<RawServoAnimationValue> zeroValue =
for (const auto& valueToMatch : valueToMatchWrapper->mServoValues) {
RefPtr<StyleAnimationValue> zeroValue =
Servo_AnimationValues_GetZeroValue(valueToMatch).Consume();
if (!zeroValue) {
return;

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

@ -157,7 +157,7 @@ static AnimationHelper::SampleResult SampleAnimationForProperty(
TimeStamp aCurrentFrameTime, const AnimatedValue* aPreviousValue,
CanSkipCompose aCanSkipCompose,
nsTArray<PropertyAnimation>& aPropertyAnimations,
RefPtr<RawServoAnimationValue>& aAnimationValue) {
RefPtr<StyleAnimationValue>& aAnimationValue) {
MOZ_ASSERT(!aPropertyAnimations.IsEmpty(), "Should have animations");
auto reason = AnimationHelper::SampleResult::Reason::None;
@ -318,17 +318,17 @@ AnimationHelper::SampleResult AnimationHelper::SampleAnimationForEachNode(
const MutexAutoLock& aProofOfMapLock, TimeStamp aPreviousFrameTime,
TimeStamp aCurrentFrameTime, const AnimatedValue* aPreviousValue,
nsTArray<PropertyAnimationGroup>& aPropertyAnimationGroups,
nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues /* out */) {
nsTArray<RefPtr<StyleAnimationValue>>& aAnimationValues /* out */) {
MOZ_ASSERT(!aPropertyAnimationGroups.IsEmpty(),
"Should be called with animation data");
MOZ_ASSERT(aAnimationValues.IsEmpty(),
"Should be called with empty aAnimationValues");
nsTArray<RefPtr<RawServoAnimationValue>> baseStyleOfDelayAnimations;
nsTArray<RefPtr<RawServoAnimationValue>> nonAnimatingValues;
nsTArray<RefPtr<StyleAnimationValue>> baseStyleOfDelayAnimations;
nsTArray<RefPtr<StyleAnimationValue>> nonAnimatingValues;
for (PropertyAnimationGroup& group : aPropertyAnimationGroups) {
// Initialize animation value with base style.
RefPtr<RawServoAnimationValue> currValue = group.mBaseStyle;
RefPtr<StyleAnimationValue> currValue = group.mBaseStyle;
CanSkipCompose canSkipCompose =
aPreviousValue && aPropertyAnimationGroups.Length() == 1 &&
@ -600,7 +600,7 @@ uint64_t AnimationHelper::GetNextCompositorAnimationsId() {
}
gfx::Matrix4x4 AnimationHelper::ServoAnimationValueToMatrix4x4(
const nsTArray<RefPtr<RawServoAnimationValue>>& aValues,
const nsTArray<RefPtr<StyleAnimationValue>>& aValues,
const TransformData& aTransformData, gfx::Path* aCachedMotionPath) {
using nsStyleTransformMatrix::TransformReferenceBox;

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

@ -87,9 +87,9 @@ class AnimationHelper {
* that it reduces each property group to a single output value:
*
* [
* { rotate, RawServoAnimationValue },
* { scale, RawServoAnimationValue },
* { transform, RawServoAnimationValue },
* { rotate, StyleAnimationValue },
* { scale, StyleAnimationValue },
* { transform, StyleAnimationValue },
* ]
*
* For transform animations, the caller (SampleAnimations) will combine the
@ -100,7 +100,7 @@ class AnimationHelper {
const MutexAutoLock& aProofOfMapLock, TimeStamp aPreviousFrameTime,
TimeStamp aCurrentFrameTime, const AnimatedValue* aPreviousValue,
nsTArray<PropertyAnimationGroup>& aPropertyAnimationGroups,
nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues);
nsTArray<RefPtr<StyleAnimationValue>>& aAnimationValues);
/**
* Extract organized animation data by property into an array of
@ -161,7 +161,7 @@ class AnimationHelper {
* (e.g. transform, translate etc.).
*/
static gfx::Matrix4x4 ServoAnimationValueToMatrix4x4(
const nsTArray<RefPtr<RawServoAnimationValue>>& aValue,
const nsTArray<RefPtr<StyleAnimationValue>>& aValue,
const TransformData& aTransformData, gfx::Path* aCachedMotionPath);
/**

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

@ -26,8 +26,8 @@ namespace layers {
struct PropertyAnimation {
struct SegmentData {
RefPtr<RawServoAnimationValue> mStartValue;
RefPtr<RawServoAnimationValue> mEndValue;
RefPtr<StyleAnimationValue> mStartValue;
RefPtr<StyleAnimationValue> mEndValue;
Maybe<mozilla::StyleComputedTimingFunction> mFunction;
float mStartPortion;
float mEndPortion;
@ -69,7 +69,7 @@ struct PropertyAnimationGroup {
nsCSSPropertyID mProperty;
nsTArray<PropertyAnimation> mAnimations;
RefPtr<RawServoAnimationValue> mBaseStyle;
RefPtr<StyleAnimationValue> mBaseStyle;
bool IsEmpty() const { return mAnimations.IsEmpty(); }
void Clear() {

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

@ -206,7 +206,7 @@ static ParentLayerRect GetClipRectForPartialPrerender(
void CompositorAnimationStorage::StoreAnimatedValue(
nsCSSPropertyID aProperty, uint64_t aId,
const std::unique_ptr<AnimationStorageData>& aAnimationStorageData,
const AutoTArray<RefPtr<RawServoAnimationValue>, 1>& aAnimationValues,
const AutoTArray<RefPtr<StyleAnimationValue>, 1>& aAnimationValues,
const MutexAutoLock& aProofOfMapLock, const RefPtr<APZSampler>& aApzSampler,
AnimatedValue* aAnimatedValueEntry,
JankedAnimationMap& aJankedAnimationMap) {
@ -310,7 +310,7 @@ bool CompositorAnimationStorage::SampleAnimations(
const nsCSSPropertyID lastPropertyAnimationGroupProperty =
animationStorageData->mAnimation.LastElement().mProperty;
isAnimating = true;
AutoTArray<RefPtr<RawServoAnimationValue>, 1> animationValues;
AutoTArray<RefPtr<StyleAnimationValue>, 1> animationValues;
AnimatedValue* previousValue = GetAnimatedValue(iter.first);
AnimationHelper::SampleResult sampleResult =
AnimationHelper::SampleAnimationForEachNode(

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

@ -193,7 +193,7 @@ class CompositorAnimationStorage final {
void StoreAnimatedValue(
nsCSSPropertyID aProperty, uint64_t aId,
const std::unique_ptr<AnimationStorageData>& aAnimationStorageData,
const AutoTArray<RefPtr<RawServoAnimationValue>, 1>& aAnimationValues,
const AutoTArray<RefPtr<StyleAnimationValue>, 1>& aAnimationValues,
const MutexAutoLock& aProofOfMapLock,
const RefPtr<APZSampler>& aApzSampler, AnimatedValue* aAnimatedValueEntry,
JankedAnimationMap& aJankedAnimationMap);

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

@ -680,7 +680,7 @@ nsCSSPropertyID Gecko_ElementTransitions_PropertyAt(const Element* aElement,
: nsCSSPropertyID::eCSSProperty_UNKNOWN;
}
const RawServoAnimationValue* Gecko_ElementTransitions_EndValueAt(
const StyleAnimationValue* Gecko_ElementTransitions_EndValueAt(
const Element* aElement, size_t aIndex) {
CSSTransition* transition = GetCurrentTransitionAt(aElement, aIndex);
return transition ? transition->ToValue().mServo.get() : nullptr;
@ -705,10 +705,10 @@ double Gecko_GetPositionInSegment(const AnimationPropertySegment* aSegment,
aSegment->mTimingFunction, positionInSegment, aBeforeFlag);
}
const RawServoAnimationValue* Gecko_AnimationGetBaseStyle(
const StyleAnimationValue* Gecko_AnimationGetBaseStyle(
const RawServoAnimationValueTable* aBaseStyles, nsCSSPropertyID aProperty) {
auto base = reinterpret_cast<
const nsRefPtrHashtable<nsUint32HashKey, RawServoAnimationValue>*>(
const nsRefPtrHashtable<nsUint32HashKey, StyleAnimationValue>*>(
aBaseStyles);
return base->GetWeak(aProperty);
}

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

@ -253,7 +253,7 @@ size_t Gecko_ElementTransitions_Length(
nsCSSPropertyID Gecko_ElementTransitions_PropertyAt(
const mozilla::dom::Element* aElementOrPseudo, size_t aIndex);
const RawServoAnimationValue* Gecko_ElementTransitions_EndValueAt(
const mozilla::StyleAnimationValue* Gecko_ElementTransitions_EndValueAt(
const mozilla::dom::Element* aElementOrPseudo, size_t aIndex);
double Gecko_GetProgressFromComputedTiming(const mozilla::ComputedTiming*);
@ -263,10 +263,10 @@ double Gecko_GetPositionInSegment(const mozilla::AnimationPropertySegment*,
// Get servo's AnimationValue for |aProperty| from the cached base style
// |aBaseStyles|.
// |aBaseStyles| is nsRefPtrHashtable<nsUint32HashKey, RawServoAnimationValue>.
// |aBaseStyles| is nsRefPtrHashtable<nsUint32HashKey, StyleAnimationValue>.
// We use RawServoAnimationValueTableBorrowed to avoid exposing
// nsRefPtrHashtable in FFI.
const RawServoAnimationValue* Gecko_AnimationGetBaseStyle(
const mozilla::StyleAnimationValue* Gecko_AnimationGetBaseStyle(
const RawServoAnimationValueTable* aBaseStyles, nsCSSPropertyID aProperty);
void Gecko_StyleTransition_SetUnsupportedProperty(

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

@ -26,7 +26,6 @@ SERVO_ARC_TYPE(CssRules, ServoCssRules)
SERVO_ARC_TYPE(DeclarationBlock, RawServoDeclarationBlock)
SERVO_ARC_TYPE(StyleRule, RawServoStyleRule)
SERVO_ARC_TYPE(ImportRule, RawServoImportRule)
SERVO_ARC_TYPE(AnimationValue, RawServoAnimationValue)
SERVO_ARC_TYPE(Keyframe, RawServoKeyframe)
SERVO_ARC_TYPE(KeyframesRule, RawServoKeyframesRule)
SERVO_ARC_TYPE(LayerBlockRule, RawServoLayerBlockRule)

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

@ -128,6 +128,7 @@ struct PropertyStyleAnimationValuePair;
struct PropertyValuePair;
struct StyleAnimation;
struct StyleCssUrlData;
struct StyleAnimationValue;
struct StyleStylesheetContents;
struct URLExtraData;
using ComputedKeyframeValues = nsTArray<PropertyStyleAnimationValuePair>;
@ -154,6 +155,7 @@ class Element;
}; \
}
#include "mozilla/ServoArcTypeList.h"
SERVO_ARC_TYPE(AnimationValue, mozilla::StyleAnimationValue)
SERVO_ARC_TYPE(ComputedStyle, mozilla::ComputedStyle)
SERVO_ARC_TYPE(CssUrlData, mozilla::StyleCssUrlData)
SERVO_ARC_TYPE(StyleSheetContents, mozilla::StyleStylesheetContents)

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

@ -414,7 +414,6 @@ opaque-types = [
"mozilla::dom::TreeOrderedArray", # AutoTArray<>
"gfxSize", # <- union { struct { T width; T height; }; T components[2] };
"gfxSize_Super", # Ditto.
"mozilla::StyleAnimationValue",
"StyleAnimationValue", # pulls in a whole bunch of stuff we don't need in the bindings
"mozilla::dom::.*Callback", # Pulls in ErrorResult and other things that
# don't align properly on Linux 32-bit
@ -650,6 +649,7 @@ cbindgen-types = [
{ gecko = "StyleAuthorStyles", servo = "crate::gecko::data::AuthorStyles" },
{ gecko = "StyleUseCounters", servo = "crate::use_counters::UseCounters" },
{ gecko = "StyleStylesheetContents", servo = "crate::stylesheets::StylesheetContents" },
{ gecko = "StyleAnimationValue", servo = "crate::properties::animated_properties::AnimationValue" },
]
mapped-generic-types = [

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

@ -32,7 +32,7 @@ namespace mozilla {
// this automatically from cbindgen.
template struct StyleStrong<ComputedStyle>;
template struct StyleStrong<ServoCssRules>;
template struct StyleStrong<RawServoAnimationValue>;
template struct StyleStrong<StyleAnimationValue>;
template struct StyleStrong<RawServoDeclarationBlock>;
template struct StyleStrong<StyleStylesheetContents>;
template struct StyleStrong<RawServoKeyframe>;

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

@ -1090,7 +1090,7 @@ nsTArray<ComputedKeyframeValues> ServoStyleSet::GetComputedKeyframeValuesFor(
void ServoStyleSet::GetAnimationValues(
RawServoDeclarationBlock* aDeclarations, Element* aElement,
const ComputedStyle* aComputedStyle,
nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues) {
nsTArray<RefPtr<StyleAnimationValue>>& aAnimationValues) {
// Servo_GetAnimationValues below won't handle ignoring existing element
// data for bfcached documents. (See comment in ResolveStyleLazily
// about these bfcache issues.)
@ -1108,13 +1108,13 @@ already_AddRefed<ComputedStyle> ServoStyleSet::GetBaseContextForElement(
already_AddRefed<ComputedStyle>
ServoStyleSet::ResolveServoStyleByAddingAnimation(
Element* aElement, const ComputedStyle* aStyle,
RawServoAnimationValue* aAnimationValue) {
StyleAnimationValue* aAnimationValue) {
return Servo_StyleSet_GetComputedValuesByAddingAnimation(
mRawData.get(), aElement, aStyle, &Snapshots(), aAnimationValue)
.Consume();
}
already_AddRefed<RawServoAnimationValue> ServoStyleSet::ComputeAnimationValue(
already_AddRefed<StyleAnimationValue> ServoStyleSet::ComputeAnimationValue(
Element* aElement, RawServoDeclarationBlock* aDeclarations,
const ComputedStyle* aStyle) {
return Servo_AnimationValue_Compute(aElement, aDeclarations, aStyle,

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

@ -389,7 +389,7 @@ class ServoStyleSet {
void GetAnimationValues(
RawServoDeclarationBlock* aDeclarations, dom::Element* aElement,
const mozilla::ComputedStyle* aStyle,
nsTArray<RefPtr<RawServoAnimationValue>>& aAnimationValues);
nsTArray<RefPtr<StyleAnimationValue>>& aAnimationValues);
void AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
@ -418,7 +418,7 @@ class ServoStyleSet {
// Note: |aElement| should be the generated element if it is pseudo.
already_AddRefed<ComputedStyle> ResolveServoStyleByAddingAnimation(
dom::Element* aElement, const ComputedStyle* aStyle,
RawServoAnimationValue* aAnimationValue);
StyleAnimationValue* aAnimationValue);
/**
* Resolve style for a given declaration block with/without the parent style.
* If the parent style is not specified, the document default computed values
@ -428,7 +428,7 @@ class ServoStyleSet {
const ComputedStyle* aParentOrNull,
const RawServoDeclarationBlock* aDeclarations);
already_AddRefed<RawServoAnimationValue> ComputeAnimationValue(
already_AddRefed<StyleAnimationValue> ComputeAnimationValue(
dom::Element* aElement, RawServoDeclarationBlock* aDeclaration,
const mozilla::ComputedStyle* aStyle);

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

@ -213,7 +213,7 @@ AnimationValue AnimationValue::FromString(nsCSSPropertyID aProperty,
}
/* static */
already_AddRefed<RawServoAnimationValue> AnimationValue::FromAnimatable(
already_AddRefed<StyleAnimationValue> AnimationValue::FromAnimatable(
nsCSSPropertyID aProperty, const layers::Animatable& aAnimatable) {
switch (aAnimatable.type()) {
case layers::Animatable::Tnull_t:

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

@ -45,7 +45,7 @@ enum class PseudoStyleType : uint8_t;
struct PropertyStyleAnimationValuePair;
struct AnimationValue {
explicit AnimationValue(const RefPtr<RawServoAnimationValue>& aValue)
explicit AnimationValue(const RefPtr<StyleAnimationValue>& aValue)
: mServo(aValue) {}
AnimationValue() = default;
@ -105,15 +105,15 @@ struct AnimationValue {
const nsACString& aValue,
dom::Element* aElement);
// Create an already_AddRefed<RawServoAnimationValue> from a
// Create an already_AddRefed<StyleAnimationValue> from a
// layers::Animatable. Basically, this function should return AnimationValue,
// but it seems the caller, AnimationHelper, only needs
// RawServoAnimationValue, so we return its already_AddRefed<> to avoid
// StyleAnimationValue, so we return its already_AddRefed<> to avoid
// adding/removing a redundant ref-count.
static already_AddRefed<RawServoAnimationValue> FromAnimatable(
static already_AddRefed<StyleAnimationValue> FromAnimatable(
nsCSSPropertyID aProperty, const layers::Animatable& aAnimatable);
RefPtr<RawServoAnimationValue> mServo;
RefPtr<StyleAnimationValue> mServo;
};
inline std::ostream& operator<<(std::ostream& aOut,

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

@ -10,12 +10,12 @@
use crate::gecko::url::CssUrlData;
use crate::gecko_bindings::structs::{
RawServoAnimationValue, RawServoContainerRule, RawServoCounterStyleRule,
RawServoDeclarationBlock, RawServoFontFaceRule, RawServoFontFeatureValuesRule,
RawServoFontPaletteValuesRule, RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule,
RawServoLayerBlockRule, RawServoLayerStatementRule, RawServoMediaList, RawServoMediaRule,
RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule,
RawServoSupportsRule, ServoCssRules,
RawServoContainerRule, RawServoCounterStyleRule, RawServoDeclarationBlock,
RawServoFontFaceRule, RawServoFontFeatureValuesRule, RawServoFontPaletteValuesRule,
RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule, RawServoLayerBlockRule,
RawServoLayerStatementRule, RawServoMediaList, RawServoMediaRule, RawServoMozDocumentRule,
RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule, RawServoSupportsRule,
ServoCssRules,
};
use crate::gecko_bindings::sugar::ownership::HasArcFFI;
use crate::media_queries::MediaList;
@ -60,9 +60,6 @@ impl_arc_ffi!(Locked<StyleRule> => RawServoStyleRule
impl_arc_ffi!(Locked<ImportRule> => RawServoImportRule
[Servo_ImportRule_AddRef, Servo_ImportRule_Release]);
impl_arc_ffi!(AnimationValue => RawServoAnimationValue
[Servo_AnimationValue_AddRef, Servo_AnimationValue_Release]);
impl_arc_ffi!(Locked<Keyframe> => RawServoKeyframe
[Servo_Keyframe_AddRef, Servo_Keyframe_Release]);
@ -137,3 +134,8 @@ impl_simple_arc_ffi!(
Servo_ComputedStyle_AddRef,
Servo_ComputedStyle_Release
);
impl_simple_arc_ffi!(
AnimationValue,
Servo_AnimationValue_AddRef,
Servo_AnimationValue_Release
);

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

@ -825,14 +825,12 @@ impl<'le> GeckoElement<'le> {
let mut map = FxHashMap::with_capacity_and_hasher(collection_length, Default::default());
for i in 0..collection_length {
let raw_end_value = unsafe { Gecko_ElementTransitions_EndValueAt(self.0, i).as_ref() };
let end_value = AnimationValue::arc_from_borrowed(&raw_end_value)
.expect("AnimationValue not found in ElementTransitions");
let end_value = unsafe {
Arc::from_raw_addrefed(Gecko_ElementTransitions_EndValueAt(self.0, i))
};
let property = end_value.id();
debug_assert!(!property.is_logical());
map.insert(property, end_value.clone_arc());
map.insert(property, end_value);
}
map
}

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

@ -9,7 +9,7 @@ use crate::gecko_bindings::{bindings, structs};
use crate::Atom;
use servo_arc::Arc;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::ops::Deref;
use std::{fmt, mem, ptr};
use std::fmt::Write;
@ -40,18 +40,6 @@ impl<T: RefCounted> fmt::Debug for RefPtr<T> {
}
}
/// A RefPtr that we know is uniquely owned.
///
/// This is basically Box<T>, with the additional guarantee that the box can be
/// safely interpreted as a RefPtr<T> (with refcount 1)
///
/// This is useful when you wish to create a refptr and mutate it temporarily,
/// while it is still uniquely owned.
pub struct UniqueRefPtr<T: RefCounted>(RefPtr<T>);
// There is no safe conversion from &T to RefPtr<T> (like Gecko has)
// because this lets you break UniqueRefPtr's guarantee
impl<T: RefCounted> RefPtr<T> {
/// Create a new RefPtr from an already addrefed pointer obtained from FFI.
///
@ -59,7 +47,7 @@ impl<T: RefCounted> RefPtr<T> {
pub unsafe fn from_addrefed(ptr: *mut T) -> Self {
debug_assert!(!ptr.is_null());
RefPtr {
ptr: ptr,
ptr,
_marker: PhantomData,
}
}
@ -125,23 +113,6 @@ impl<T: RefCounted> RefPtr<T> {
}
}
impl<T: RefCounted> UniqueRefPtr<T> {
/// Create a unique refptr from an already addrefed pointer obtained from
/// FFI.
///
/// The refcount must be one.
///
/// The pointer must be valid and non null
pub unsafe fn from_addrefed(ptr: *mut T) -> Self {
UniqueRefPtr(RefPtr::from_addrefed(ptr))
}
/// Convert to a RefPtr so that it can be used.
pub fn get(self) -> RefPtr<T> {
self.0
}
}
impl<T: RefCounted> Deref for RefPtr<T> {
type Target = T;
fn deref(&self) -> &T {
@ -150,19 +121,6 @@ impl<T: RefCounted> Deref for RefPtr<T> {
}
}
impl<T: RefCounted> Deref for UniqueRefPtr<T> {
type Target = T;
fn deref(&self) -> &T {
unsafe { &*self.0.ptr }
}
}
impl<T: RefCounted> DerefMut for UniqueRefPtr<T> {
fn deref_mut(&mut self) -> &mut T {
unsafe { &mut *self.0.ptr }
}
}
impl<T: RefCounted> structs::RefPtr<T> {
/// Produces a Rust-side RefPtr from an FFI RefPtr, bumping the refcount.
///
@ -226,24 +184,51 @@ impl<T: RefCounted> structs::RefPtr<T> {
}
impl<T> structs::RefPtr<T> {
/// Sets the contents to an `Arc<T>`, releasing the old value in `self` if
/// necessary.
pub fn set_arc<U>(&mut self, other: Arc<U>)
/// Returns a new, null refptr.
pub fn null() -> Self {
Self {
mRawPtr: ptr::null_mut(),
_phantom_0: PhantomData,
}
}
/// Create a new RefPtr from an arc.
pub fn from_arc(s: Arc<T>) -> Self {
Self {
mRawPtr: Arc::into_raw(s) as *mut _,
_phantom_0: PhantomData,
}
}
/// Create a new RefPtr from an arc.
pub fn from_arc_ffi<U>(s: Arc<U>) -> Self
where
U: HasArcFFI<FFIType = T>,
{
Self {
mRawPtr: unsafe { mem::transmute(Arc::into_raw_offset(s)) },
_phantom_0: PhantomData,
}
}
/// Sets the contents to an Arc<T>.
pub fn set_arc(&mut self, other: Arc<T>) {
unsafe {
if !self.mRawPtr.is_null() {
let _ = Arc::from_raw(self.mRawPtr);
}
self.mRawPtr = Arc::into_raw(other) as *mut _;
}
}
/// Sets the contents to an Arc<U>.
pub fn set_arc_ffi<U>(&mut self, other: Arc<U>)
where
U: HasArcFFI<FFIType = T>,
{
unsafe {
U::release_opt(self.mRawPtr.as_ref());
}
self.set_arc_leaky(other);
}
/// Sets the contents to an Arc<T>
/// will leak existing contents
pub fn set_arc_leaky<U>(&mut self, other: Arc<U>)
where
U: HasArcFFI<FFIType = T>,
{
*self = unsafe { mem::transmute(Arc::into_raw_offset(other)) };
}
}

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

@ -29,4 +29,5 @@ servo_arc = {path = "../../components/servo_arc"}
smallvec = "1.0"
style = {path = "../../components/style", features = ["gecko"]}
style_traits = {path = "../../components/style_traits"}
thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
to_shmem = {path = "../../components/to_shmem"}

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

@ -11,7 +11,7 @@ use dom::{DocumentState, ElementState};
use malloc_size_of::MallocSizeOfOps;
use nsstring::{nsCString, nsString};
use selectors::NthIndexCache;
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
use servo_arc::{Arc, ArcBorrow};
use smallvec::SmallVec;
use std::collections::BTreeSet;
use std::fmt::Write;
@ -83,12 +83,11 @@ use style::gecko_bindings::structs::StyleSheet as DomStyleSheet;
use style::gecko_bindings::structs::URLExtraData;
use style::gecko_bindings::structs::{nsINode as RawGeckoNode, Element as RawGeckoElement};
use style::gecko_bindings::structs::{
RawServoAnimationValue, RawServoContainerRule, RawServoCounterStyleRule,
RawServoDeclarationBlock, RawServoFontFaceRule, RawServoFontFeatureValuesRule,
RawServoFontPaletteValuesRule, RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule,
RawServoLayerBlockRule, RawServoLayerStatementRule, RawServoMediaList, RawServoMediaRule,
RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule,
RawServoSupportsRule, ServoCssRules,
RawServoContainerRule, RawServoCounterStyleRule, RawServoDeclarationBlock,
RawServoFontFaceRule, RawServoFontFeatureValuesRule, RawServoFontPaletteValuesRule,
RawServoImportRule, RawServoKeyframe, RawServoKeyframesRule, RawServoLayerBlockRule,
RawServoLayerStatementRule, RawServoMediaList, RawServoMediaRule, RawServoMozDocumentRule,
RawServoNamespaceRule, RawServoPageRule, RawServoSupportsRule, ServoCssRules,
};
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, Strong};
use style::gecko_bindings::sugar::refptr::RefPtr;
@ -144,6 +143,7 @@ use style::values::specified::source_size_list::SourceSizeList;
use style::values::specified::{AbsoluteLength, NoCalcLength};
use style::values::{specified, AtomIdent, CustomIdent, KeyframesName};
use style_traits::{CssWriter, ParseError, ParsingMode, ToCss};
use thin_vec::ThinVec;
use to_shmem::SharedMemoryBuilder;
trait ClosureHelper {
@ -378,14 +378,12 @@ pub extern "C" fn Servo_MaybeGCRuleTree(raw_data: &PerDocumentStyleData) {
#[no_mangle]
pub extern "C" fn Servo_AnimationValues_Interpolate(
from: &RawServoAnimationValue,
to: &RawServoAnimationValue,
from: &AnimationValue,
to: &AnimationValue,
progress: f64,
) -> Strong<RawServoAnimationValue> {
let from_value = AnimationValue::as_arc(&from);
let to_value = AnimationValue::as_arc(&to);
if let Ok(value) = from_value.animate(to_value, Procedure::Interpolate { progress }) {
Arc::new(value).into_strong()
) -> Strong<AnimationValue> {
if let Ok(value) = from.animate(to, Procedure::Interpolate { progress }) {
Arc::new(value).into()
} else {
Strong::null()
}
@ -393,25 +391,16 @@ pub extern "C" fn Servo_AnimationValues_Interpolate(
#[no_mangle]
pub extern "C" fn Servo_AnimationValues_IsInterpolable(
from: &RawServoAnimationValue,
to: &RawServoAnimationValue,
from: &AnimationValue,
to: &AnimationValue,
) -> bool {
let from_value = AnimationValue::as_arc(&from);
let to_value = AnimationValue::as_arc(&to);
from_value
.animate(to_value, Procedure::Interpolate { progress: 0.5 })
.is_ok()
from.animate(to, Procedure::Interpolate { progress: 0.5 }).is_ok()
}
#[no_mangle]
pub extern "C" fn Servo_AnimationValues_Add(
a: &RawServoAnimationValue,
b: &RawServoAnimationValue,
) -> Strong<RawServoAnimationValue> {
let a_value = AnimationValue::as_arc(&a);
let b_value = AnimationValue::as_arc(&b);
if let Ok(value) = a_value.animate(b_value, Procedure::Add) {
Arc::new(value).into_strong()
pub extern "C" fn Servo_AnimationValues_Add(a: &AnimationValue, b: &AnimationValue) -> Strong<AnimationValue> {
if let Ok(value) = a.animate(b, Procedure::Add) {
Arc::new(value).into()
} else {
Strong::null()
}
@ -419,14 +408,12 @@ pub extern "C" fn Servo_AnimationValues_Add(
#[no_mangle]
pub extern "C" fn Servo_AnimationValues_Accumulate(
a: &RawServoAnimationValue,
b: &RawServoAnimationValue,
a: &AnimationValue,
b: &AnimationValue,
count: u64,
) -> Strong<RawServoAnimationValue> {
let a_value = AnimationValue::as_arc(&a);
let b_value = AnimationValue::as_arc(&b);
if let Ok(value) = a_value.animate(b_value, Procedure::Accumulate { count }) {
Arc::new(value).into_strong()
) -> Strong<AnimationValue> {
if let Ok(value) = a.animate(b, Procedure::Accumulate { count }) {
Arc::new(value).into()
} else {
Strong::null()
}
@ -434,11 +421,10 @@ pub extern "C" fn Servo_AnimationValues_Accumulate(
#[no_mangle]
pub extern "C" fn Servo_AnimationValues_GetZeroValue(
value_to_match: &RawServoAnimationValue,
) -> Strong<RawServoAnimationValue> {
let value_to_match = AnimationValue::as_arc(&value_to_match);
value_to_match: &AnimationValue,
) -> Strong<AnimationValue> {
if let Ok(zero_value) = value_to_match.to_animated_zero() {
Arc::new(zero_value).into_strong()
Arc::new(zero_value).into()
} else {
Strong::null()
}
@ -446,17 +432,12 @@ pub extern "C" fn Servo_AnimationValues_GetZeroValue(
#[no_mangle]
pub extern "C" fn Servo_AnimationValues_ComputeDistance(
from: &RawServoAnimationValue,
to: &RawServoAnimationValue,
from: &AnimationValue,
to: &AnimationValue,
) -> f64 {
let from_value = AnimationValue::as_arc(&from);
let to_value = AnimationValue::as_arc(&to);
// If compute_squared_distance() failed, this function will return negative value
// in order to check whether we support the specified paced animation values.
from_value
.compute_squared_distance(to_value)
.map(|d| d.sqrt())
.unwrap_or(-1.0)
from.compute_squared_distance(to).map_or(-1.0, |d| d.sqrt())
}
/// Compute one of the endpoints for the interpolation interval, compositing it with the
@ -465,7 +446,7 @@ pub extern "C" fn Servo_AnimationValues_ComputeDistance(
/// It is the responsibility of the caller to ensure that |underlying_value| is provided
/// when it will be used.
fn composite_endpoint(
endpoint_value: Option<&RawOffsetArc<AnimationValue>>,
endpoint_value: Option<&AnimationValue>,
composite: CompositeOperation,
underlying_value: Option<&AnimationValue>,
) -> Option<AnimationValue> {
@ -488,7 +469,7 @@ fn composite_endpoint(
/// Accumulate one of the endpoints of the animation interval.
/// A returned value of None means, "Just use endpoint_value as-is."
fn accumulate_endpoint(
endpoint_value: Option<&RawOffsetArc<AnimationValue>>,
endpoint_value: Option<&AnimationValue>,
composited_value: Option<AnimationValue>,
last_value: &AnimationValue,
current_iteration: u64,
@ -524,22 +505,8 @@ fn compose_animation_segment(
segment_progress: f64,
) -> AnimationValue {
// Extract keyframe values.
let raw_from_value;
let keyframe_from_value = if !segment.mFromValue.mServo.mRawPtr.is_null() {
raw_from_value = unsafe { &*segment.mFromValue.mServo.mRawPtr };
Some(AnimationValue::as_arc(&raw_from_value))
} else {
None
};
let raw_to_value;
let keyframe_to_value = if !segment.mToValue.mServo.mRawPtr.is_null() {
raw_to_value = unsafe { &*segment.mToValue.mServo.mRawPtr };
Some(AnimationValue::as_arc(&raw_to_value))
} else {
None
};
let keyframe_from_value = unsafe {segment.mFromValue.mServo.mRawPtr.as_ref() };
let keyframe_to_value = unsafe { segment.mToValue.mServo.mRawPtr.as_ref() };
let mut composited_from_value = composite_endpoint(
keyframe_from_value,
segment.mFromComposite,
@ -612,14 +579,12 @@ fn compose_animation_segment(
#[no_mangle]
pub extern "C" fn Servo_ComposeAnimationSegment(
segment: &structs::AnimationPropertySegment,
underlying_value: Option<&RawServoAnimationValue>,
last_value: Option<&RawServoAnimationValue>,
underlying_value: Option<&AnimationValue>,
last_value: Option<&AnimationValue>,
iteration_composite: IterationCompositeOperation,
progress: f64,
current_iteration: u64,
) -> Strong<RawServoAnimationValue> {
let underlying_value = AnimationValue::arc_from_borrowed(&underlying_value).map(|v| &**v);
let last_value = AnimationValue::arc_from_borrowed(&last_value).map(|v| &**v);
) -> Strong<AnimationValue> {
let result = compose_animation_segment(
segment,
underlying_value,
@ -629,7 +594,7 @@ pub extern "C" fn Servo_ComposeAnimationSegment(
progress,
progress,
);
Arc::new(result).into_strong()
Arc::new(result).into()
}
#[no_mangle]
@ -667,13 +632,9 @@ pub extern "C" fn Servo_AnimationCompose(
// effect), or, if there is no current value, look up the cached base value
// for this property.
let underlying_value = if need_underlying_value {
let previous_composed_value = value_map.get(&property).cloned();
let previous_composed_value = value_map.get(&property).map(|v| &*v);
previous_composed_value.or_else(|| {
let raw_base_style =
unsafe { Gecko_AnimationGetBaseStyle(base_values, css_property).as_ref() };
AnimationValue::arc_from_borrowed(&raw_base_style)
.map(|v| &**v)
.cloned()
unsafe { Gecko_AnimationGetBaseStyle(base_values, css_property).as_ref() }
})
} else {
None
@ -684,14 +645,7 @@ pub extern "C" fn Servo_AnimationCompose(
return;
}
let raw_last_value;
let last_value = if !last_segment.mToValue.mServo.mRawPtr.is_null() {
raw_last_value = unsafe { &*last_segment.mToValue.mServo.mRawPtr };
Some(&**AnimationValue::as_arc(&raw_last_value))
} else {
None
};
let last_value = unsafe { last_segment.mToValue.mServo.mRawPtr.as_ref() };
let progress = unsafe { Gecko_GetProgressFromComputedTiming(computed_timing) };
let position = if segment.mToKey == segment.mFromKey {
// Note: compose_animation_segment doesn't use this value
@ -703,7 +657,7 @@ pub extern "C" fn Servo_AnimationCompose(
let result = compose_animation_segment(
segment,
underlying_value.as_ref(),
underlying_value,
last_value,
iteration_composite,
computed_timing.mCurrentIteration,
@ -726,12 +680,12 @@ macro_rules! get_property_id_from_nscsspropertyid {
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_Serialize(
value: &RawServoAnimationValue,
value: &AnimationValue,
property: nsCSSPropertyID,
raw_data: &PerDocumentStyleData,
buffer: &mut nsACString,
) {
let uncomputed_value = AnimationValue::as_arc(&value).uncompute();
let uncomputed_value = value.uncompute();
let data = raw_data.borrow();
let rv = PropertyDeclarationBlock::with_one(uncomputed_value, Importance::Normal)
.single_value_to_css(
@ -746,26 +700,20 @@ pub extern "C" fn Servo_AnimationValue_Serialize(
/// Debug: MOZ_DBG for AnimationValue.
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_Dump(
value: &RawServoAnimationValue,
result: &mut nsACString,
) {
let value = AnimationValue::as_arc(&value);
pub extern "C" fn Servo_AnimationValue_Dump(value: &AnimationValue, result: &mut nsACString) {
write!(result, "{:?}", value).unwrap();
}
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_GetColor(
value: &RawServoAnimationValue,
value: &AnimationValue,
foreground_color: structs::nscolor,
) -> structs::nscolor {
use style::gecko::values::{
convert_absolute_color_to_nscolor, convert_nscolor_to_absolute_color,
};
use style::values::computed::color::Color as ComputedColor;
let value = AnimationValue::as_arc(&value);
match **value {
match *value {
AnimationValue::BackgroundColor(ref color) => {
let computed: ComputedColor = color.clone();
let foreground_color = convert_nscolor_to_absolute_color(foreground_color);
@ -776,9 +724,8 @@ pub extern "C" fn Servo_AnimationValue_GetColor(
}
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_IsCurrentColor(value: &RawServoAnimationValue) -> bool {
let value = AnimationValue::as_arc(&value);
match **value {
pub extern "C" fn Servo_AnimationValue_IsCurrentColor(value: &AnimationValue) -> bool {
match *value {
AnimationValue::BackgroundColor(ref color) => color.is_currentcolor(),
_ => {
debug_assert!(false, "Other color properties are not supported yet");
@ -788,9 +735,8 @@ pub extern "C" fn Servo_AnimationValue_IsCurrentColor(value: &RawServoAnimationV
}
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_GetOpacity(value: &RawServoAnimationValue) -> f32 {
let value = AnimationValue::as_arc(&value);
if let AnimationValue::Opacity(opacity) = **value {
pub extern "C" fn Servo_AnimationValue_GetOpacity(value: &AnimationValue) -> f32 {
if let AnimationValue::Opacity(opacity) = *value {
opacity
} else {
panic!("The AnimationValue should be Opacity");
@ -798,15 +744,15 @@ pub extern "C" fn Servo_AnimationValue_GetOpacity(value: &RawServoAnimationValue
}
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_Opacity(opacity: f32) -> Strong<RawServoAnimationValue> {
Arc::new(AnimationValue::Opacity(opacity)).into_strong()
pub extern "C" fn Servo_AnimationValue_Opacity(opacity: f32) -> Strong<AnimationValue> {
Arc::new(AnimationValue::Opacity(opacity)).into()
}
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_Color(
color_property: nsCSSPropertyID,
color: structs::nscolor,
) -> Strong<RawServoAnimationValue> {
) -> Strong<AnimationValue> {
use style::gecko::values::convert_nscolor_to_absolute_color;
use style::values::animated::color::Color;
@ -817,171 +763,123 @@ pub extern "C" fn Servo_AnimationValue_Color(
match property {
LonghandId::BackgroundColor => {
Arc::new(AnimationValue::BackgroundColor(Color::Absolute(animated))).into_strong()
Arc::new(AnimationValue::BackgroundColor(Color::Absolute(animated))).into()
},
_ => panic!("Should be background-color property"),
}
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_GetScale(
value: &RawServoAnimationValue,
) -> *const computed::Scale {
let value = AnimationValue::as_arc(&value);
match **value {
pub unsafe extern "C" fn Servo_AnimationValue_GetScale(value: &AnimationValue) -> *const computed::Scale {
match *value {
AnimationValue::Scale(ref value) => value,
_ => unreachable!("Expected scale"),
}
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_GetTranslate(
value: &RawServoAnimationValue,
) -> *const computed::Translate {
let value = AnimationValue::as_arc(&value);
match **value {
pub unsafe extern "C" fn Servo_AnimationValue_GetTranslate(value: &AnimationValue) -> *const computed::Translate {
match *value {
AnimationValue::Translate(ref value) => value,
_ => unreachable!("Expected translate"),
}
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_GetRotate(
value: &RawServoAnimationValue,
) -> *const computed::Rotate {
let value = AnimationValue::as_arc(&value);
match **value {
pub unsafe extern "C" fn Servo_AnimationValue_GetRotate(value: &AnimationValue) -> *const computed::Rotate {
match *value {
AnimationValue::Rotate(ref value) => value,
_ => unreachable!("Expected rotate"),
}
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_GetTransform(
value: &RawServoAnimationValue,
) -> *const computed::Transform {
let value = AnimationValue::as_arc(&value);
match **value {
pub unsafe extern "C" fn Servo_AnimationValue_GetTransform(value: &AnimationValue) -> *const computed::Transform {
match *value {
AnimationValue::Transform(ref value) => value,
_ => unreachable!("Unsupported transform animation value"),
}
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetPath(
value: &RawServoAnimationValue,
) -> *const computed::motion::OffsetPath {
let value = AnimationValue::as_arc(&value);
match **value {
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetPath(value: &AnimationValue) -> *const computed::motion::OffsetPath {
match *value {
AnimationValue::OffsetPath(ref value) => value,
_ => unreachable!("Expected offset-path"),
}
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetDistance(
value: &RawServoAnimationValue,
) -> *const computed::LengthPercentage {
let value = AnimationValue::as_arc(&value);
match **value {
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetDistance(value: &AnimationValue) -> *const computed::LengthPercentage {
match *value {
AnimationValue::OffsetDistance(ref value) => value,
_ => unreachable!("Expected offset-distance"),
}
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetRotate(
value: &RawServoAnimationValue,
) -> *const computed::motion::OffsetRotate {
let value = AnimationValue::as_arc(&value);
match **value {
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetRotate(value: &AnimationValue) -> *const computed::motion::OffsetRotate {
match *value {
AnimationValue::OffsetRotate(ref value) => value,
_ => unreachable!("Expected offset-rotate"),
}
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetAnchor(
value: &RawServoAnimationValue,
) -> *const computed::position::PositionOrAuto {
let value = AnimationValue::as_arc(&value);
match **value {
pub unsafe extern "C" fn Servo_AnimationValue_GetOffsetAnchor(value: &AnimationValue) -> *const computed::position::PositionOrAuto {
match *value {
AnimationValue::OffsetAnchor(ref value) => value,
_ => unreachable!("Expected offset-anchor"),
}
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_Rotate(
r: &computed::Rotate,
) -> Strong<RawServoAnimationValue> {
Arc::new(AnimationValue::Rotate(r.clone())).into_strong()
pub unsafe extern "C" fn Servo_AnimationValue_Rotate(r: &computed::Rotate) -> Strong<AnimationValue> {
Arc::new(AnimationValue::Rotate(r.clone())).into()
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_Translate(
t: &computed::Translate,
) -> Strong<RawServoAnimationValue> {
Arc::new(AnimationValue::Translate(t.clone())).into_strong()
pub unsafe extern "C" fn Servo_AnimationValue_Translate(t: &computed::Translate) -> Strong<AnimationValue> {
Arc::new(AnimationValue::Translate(t.clone())).into()
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_Scale(
s: &computed::Scale,
) -> Strong<RawServoAnimationValue> {
Arc::new(AnimationValue::Scale(s.clone())).into_strong()
pub unsafe extern "C" fn Servo_AnimationValue_Scale(s: &computed::Scale) -> Strong<AnimationValue> {
Arc::new(AnimationValue::Scale(s.clone())).into()
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_Transform(
transform: &computed::Transform,
) -> Strong<RawServoAnimationValue> {
Arc::new(AnimationValue::Transform(transform.clone())).into_strong()
pub unsafe extern "C" fn Servo_AnimationValue_Transform(transform: &computed::Transform) -> Strong<AnimationValue> {
Arc::new(AnimationValue::Transform(transform.clone())).into()
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_OffsetPath(
p: &computed::motion::OffsetPath,
) -> Strong<RawServoAnimationValue> {
Arc::new(AnimationValue::OffsetPath(p.clone())).into_strong()
pub unsafe extern "C" fn Servo_AnimationValue_OffsetPath(p: &computed::motion::OffsetPath) -> Strong<AnimationValue> {
Arc::new(AnimationValue::OffsetPath(p.clone())).into()
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_OffsetDistance(
d: &computed::length::LengthPercentage,
) -> Strong<RawServoAnimationValue> {
Arc::new(AnimationValue::OffsetDistance(d.clone())).into_strong()
pub unsafe extern "C" fn Servo_AnimationValue_OffsetDistance(d: &computed::LengthPercentage) -> Strong<AnimationValue> {
Arc::new(AnimationValue::OffsetDistance(d.clone())).into()
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_OffsetRotate(
r: &computed::motion::OffsetRotate,
) -> Strong<RawServoAnimationValue> {
Arc::new(AnimationValue::OffsetRotate(*r)).into_strong()
pub unsafe extern "C" fn Servo_AnimationValue_OffsetRotate(r: &computed::motion::OffsetRotate) -> Strong<AnimationValue> {
Arc::new(AnimationValue::OffsetRotate(*r)).into()
}
#[no_mangle]
pub unsafe extern "C" fn Servo_AnimationValue_OffsetAnchor(
p: &computed::position::PositionOrAuto,
) -> Strong<RawServoAnimationValue> {
Arc::new(AnimationValue::OffsetAnchor(p.clone())).into_strong()
pub unsafe extern "C" fn Servo_AnimationValue_OffsetAnchor(p: &computed::position::PositionOrAuto) -> Strong<AnimationValue> {
Arc::new(AnimationValue::OffsetAnchor(p.clone())).into()
}
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_DeepEqual(
this: &RawServoAnimationValue,
other: &RawServoAnimationValue,
) -> bool {
let this_value = AnimationValue::as_arc(&this);
let other_value = AnimationValue::as_arc(&other);
this_value == other_value
pub extern "C" fn Servo_AnimationValue_DeepEqual(this: &AnimationValue, other: &AnimationValue) -> bool {
this == other
}
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_Uncompute(
value: &RawServoAnimationValue,
) -> Strong<RawServoDeclarationBlock> {
let value = AnimationValue::as_arc(&value);
pub extern "C" fn Servo_AnimationValue_Uncompute(value: &AnimationValue) -> Strong<RawServoDeclarationBlock> {
let global_style_data = &*GLOBAL_STYLE_DATA;
Arc::new(
global_style_data
@ -1145,13 +1043,13 @@ pub unsafe extern "C" fn Servo_AnimationValueMap_Drop(value_map: *mut AnimationV
pub extern "C" fn Servo_AnimationValueMap_GetValue(
value_map: &AnimationValueMap,
property_id: nsCSSPropertyID,
) -> Strong<RawServoAnimationValue> {
) -> Strong<AnimationValue> {
let property = match LonghandId::from_nscsspropertyid(property_id) {
Ok(longhand) => longhand,
Err(()) => return Strong::null(),
};
value_map.get(&property).map_or(Strong::null(), |value| {
Arc::new(value.clone()).into_strong()
Arc::new(value.clone()).into()
})
}
@ -1208,7 +1106,7 @@ pub extern "C" fn Servo_StyleSet_GetComputedValuesByAddingAnimation(
element: &RawGeckoElement,
computed_values: &ComputedValues,
snapshots: *const ServoElementSnapshotTable,
animation_value: &RawServoAnimationValue,
animation_value: &AnimationValue,
) -> Strong<ComputedValues> {
debug_assert!(!snapshots.is_null());
let rules = match computed_values.rules {
@ -1218,7 +1116,7 @@ pub extern "C" fn Servo_StyleSet_GetComputedValuesByAddingAnimation(
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();
let uncomputed_value = AnimationValue::as_arc(&animation_value).uncompute();
let uncomputed_value = animation_value.uncompute();
let doc_data = raw_style_set.borrow();
let with_animations_rules = {
@ -1263,13 +1161,13 @@ pub extern "C" fn Servo_StyleSet_GetComputedValuesByAddingAnimation(
pub extern "C" fn Servo_ComputedValues_ExtractAnimationValue(
computed_values: &ComputedValues,
property_id: nsCSSPropertyID,
) -> Strong<RawServoAnimationValue> {
) -> Strong<AnimationValue> {
let property = match LonghandId::from_nscsspropertyid(property_id) {
Ok(longhand) => longhand,
Err(()) => return Strong::null(),
};
match AnimationValue::from_computed_values(property, &computed_values) {
Some(v) => Arc::new(v).into_strong(),
Some(v) => Arc::new(v).into(),
None => Strong::null(),
}
}
@ -4924,10 +4822,9 @@ pub unsafe extern "C" fn Servo_DeclarationBlock_SetProperty(
#[no_mangle]
pub unsafe extern "C" fn Servo_DeclarationBlock_SetPropertyToAnimationValue(
declarations: &RawServoDeclarationBlock,
animation_value: &RawServoAnimationValue,
animation_value: &AnimationValue,
before_change_closure: DeclarationBlockMutationClosure,
) -> bool {
let animation_value = AnimationValue::as_arc(&animation_value);
let non_custom_property_id = animation_value.id().into();
let mut source_declarations = SourcePropertyDeclaration::with_one(animation_value.uncompute());
@ -6187,19 +6084,14 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(
seen.insert(property);
// This is safe since we immediately write to the uninitialized values.
unsafe { animation_values.set_len((property_index + 1) as u32) };
animation_values[property_index].mProperty = property.to_nscsspropertyid();
match value {
Some(v) => {
animation_values[property_index]
.mValue
.mServo
.set_arc_leaky(Arc::new(v));
},
None => {
animation_values[property_index].mValue.mServo.mRawPtr =
ptr::null_mut();
},
unsafe {
animation_values.set_len((property_index + 1) as u32);
ptr::write(&mut animation_values[property_index], structs::PropertyStyleAnimationValuePair {
mProperty: property.to_nscsspropertyid(),
mValue: structs::AnimationValue {
mServo: value.map_or(structs::RefPtr::null(), |v| structs::RefPtr::from_arc(Arc::new(v))),
},
});
}
property_index += 1;
};
@ -6235,7 +6127,7 @@ pub extern "C" fn Servo_GetAnimationValues(
element: &RawGeckoElement,
style: &ComputedValues,
raw_data: &PerDocumentStyleData,
animation_values: &mut nsTArray<structs::RefPtr<structs::RawServoAnimationValue>>,
animation_values: &mut ThinVec<structs::RefPtr<AnimationValue>>,
) {
let data = raw_data.borrow();
let element = GeckoElement(element);
@ -6268,17 +6160,11 @@ pub extern "C" fn Servo_GetAnimationValues(
&default_values,
None, // SMIL has no extra custom properties.
);
for (index, anim) in iter.enumerate() {
unsafe { animation_values.set_len((index + 1) as u32) };
animation_values[index].set_arc_leaky(Arc::new(anim));
}
animation_values.extend(iter.map(|v| structs::RefPtr::from_arc(Arc::new(v))));
}
#[no_mangle]
pub extern "C" fn Servo_AnimationValue_GetPropertyId(
value: &RawServoAnimationValue,
) -> nsCSSPropertyID {
let value = AnimationValue::as_arc(&value);
pub extern "C" fn Servo_AnimationValue_GetPropertyId(value: &AnimationValue) -> nsCSSPropertyID {
value.id().to_nscsspropertyid()
}
@ -6288,7 +6174,7 @@ pub extern "C" fn Servo_AnimationValue_Compute(
declarations: &RawServoDeclarationBlock,
style: &ComputedValues,
raw_data: &PerDocumentStyleData,
) -> Strong<RawServoAnimationValue> {
) -> Strong<AnimationValue> {
let data = raw_data.borrow();
let element = GeckoElement(element);
@ -6327,7 +6213,7 @@ pub extern "C" fn Servo_AnimationValue_Compute(
None, // No extra custom properties for devtools.
default_values,
);
animation.map_or(Strong::null(), |value| Arc::new(value).into_strong())
animation.map_or(Strong::null(), |value| Arc::new(value).into())
},
_ => Strong::null(),
}
@ -6548,7 +6434,7 @@ pub unsafe extern "C" fn Servo_StyleSet_GetKeyframesForName(
id.to_nscsspropertyid(),
);
(*pair).mServoDeclarationBlock.set_arc_leaky(Arc::new(
(*pair).mServoDeclarationBlock.set_arc_ffi(Arc::new(
global_style_data
.shared_lock
.wrap(PropertyDeclarationBlock::with_one(
@ -6571,7 +6457,7 @@ pub unsafe extern "C" fn Servo_StyleSet_GetKeyframesForName(
nsCSSPropertyID::eCSSPropertyExtra_variable,
);
(*pair).mServoDeclarationBlock.set_arc_leaky(Arc::new(
(*pair).mServoDeclarationBlock.set_arc_ffi(Arc::new(
global_style_data.shared_lock.wrap(custom_properties),
));
}
@ -6609,17 +6495,11 @@ pub unsafe extern "C" fn Servo_StyleSet_GetKeyframesForName(
#[no_mangle]
pub extern "C" fn Servo_StyleSet_GetFontFaceRules(
raw_data: &PerDocumentStyleData,
rules: &mut nsTArray<structs::nsFontFaceRuleContainer>,
rules: &mut ThinVec<structs::nsFontFaceRuleContainer>,
) {
let data = raw_data.borrow();
debug_assert_eq!(rules.len(), 0);
let len: u32 = data
.stylist
.iter_extra_data_origins()
.map(|(d, _)| d.font_faces.len() as u32)
.sum();
// Reversed iterator because Gecko expects rules to appear sorted
// UserAgent first, Author last.
let font_face_iter = data
@ -6627,11 +6507,10 @@ pub extern "C" fn Servo_StyleSet_GetFontFaceRules(
.iter_extra_data_origins_rev()
.flat_map(|(d, o)| d.font_faces.iter().zip(iter::repeat(o)));
unsafe { rules.set_len(len) };
for ((&(ref rule, _), origin), dest) in font_face_iter.zip(rules.iter_mut()) {
dest.mRule.set_arc_leaky(rule.clone());
dest.mOrigin = origin;
}
rules.extend(font_face_iter.map(|(&(ref rule, _layer_id), origin)| structs::nsFontFaceRuleContainer {
mRule: structs::RefPtr::from_arc_ffi(rule.clone()),
mOrigin: origin,
}))
}
// XXX Ideally this should return a Option<&RawServoCounterStyleRule>,

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

@ -21,6 +21,7 @@ extern crate smallvec;
#[macro_use]
extern crate style;
extern crate style_traits;
extern crate thin_vec;
extern crate to_shmem;
mod error_reporter;