diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index 126d7810f87..50af56133e1 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -15,6 +15,7 @@ #include "AnimationCommon.h" // For GetLayerAnimationInfo #include "FrameLayerBuilder.h" #include "GeckoProfiler.h" +#include "LayerAnimationInfo.h" // For LayerAnimationInfo::sRecords #include "nsStyleChangeList.h" #include "nsRuleProcessorData.h" #include "nsStyleUtil.h" @@ -2666,10 +2667,10 @@ ElementRestyler::AddLayerChangesForAnimation() RestyleManager::GetMaxAnimationGenerationForFrame(mFrame); nsChangeHint hint = nsChangeHint(0); - const auto& layerInfo = CommonAnimationManager::sLayerAnimationInfo; - for (size_t i = 0; i < ArrayLength(layerInfo); i++) { + for (const LayerAnimationInfo::Record& layerInfo : + LayerAnimationInfo::sRecords) { Layer* layer = - FrameLayerBuilder::GetDedicatedLayer(mFrame, layerInfo[i].mLayerType); + FrameLayerBuilder::GetDedicatedLayer(mFrame, layerInfo.mLayerType); if (layer && frameGeneration > layer->GetAnimationGeneration()) { // If we have a transform layer but don't have any transform style, we // probably just removed the transform but haven't destroyed the layer @@ -2678,11 +2679,11 @@ ElementRestyler::AddLayerChangesForAnimation() // so we can skip adding any change hint here. (If we *were* to add // nsChangeHint_UpdateTransformLayer, ApplyRenderingChangeToTree would // complain that we're updating a transform layer without a transform). - if (layerInfo[i].mLayerType == nsDisplayItem::TYPE_TRANSFORM && + if (layerInfo.mLayerType == nsDisplayItem::TYPE_TRANSFORM && !mFrame->StyleDisplay()->HasTransformStyle()) { continue; } - NS_UpdateHint(hint, layerInfo[i].mChangeHint); + NS_UpdateHint(hint, layerInfo.mChangeHint); } } if (hint) { diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp index dabedf9d210..6841040ccd9 100644 --- a/layout/build/nsLayoutStatics.cpp +++ b/layout/build/nsLayoutStatics.cpp @@ -68,6 +68,7 @@ #include "FrameLayerBuilder.h" #include "mozilla/dom/RequestSyncWifiService.h" #include "AnimationCommon.h" +#include "LayerAnimationInfo.h" #include "AudioChannelService.h" #include "mozilla/dom/DataStoreService.h" @@ -311,7 +312,7 @@ nsLayoutStatics::Initialize() #ifdef DEBUG nsStyleContext::Initialize(); - mozilla::CommonAnimationManager::Initialize(); + mozilla::LayerAnimationInfo::Initialize(); #endif MediaDecoder::InitStatics(); diff --git a/layout/style/AnimationCommon.cpp b/layout/style/AnimationCommon.cpp index 81693e71161..897cd7cd849 100644 --- a/layout/style/AnimationCommon.cpp +++ b/layout/style/AnimationCommon.cpp @@ -18,6 +18,7 @@ #include "nsIFrame.h" #include "nsLayoutUtils.h" #include "mozilla/LookAndFeel.h" +#include "LayerAnimationInfo.h" // For LayerAnimationInfo::sRecords #include "Layers.h" #include "FrameLayerBuilder.h" #include "nsDisplayList.h" @@ -406,30 +407,6 @@ CommonAnimationManager::GetAnimationRule(mozilla::dom::Element* aElement, return collection->mStyleRule; } -/* static */ const CommonAnimationManager::LayerAnimationRecord - CommonAnimationManager::sLayerAnimationInfo[] = - { { eCSSProperty_transform, - nsDisplayItem::TYPE_TRANSFORM, - nsChangeHint_UpdateTransformLayer }, - { eCSSProperty_opacity, - nsDisplayItem::TYPE_OPACITY, - nsChangeHint_UpdateOpacityLayer } }; - -/* static */ const CommonAnimationManager::LayerAnimationRecord* -CommonAnimationManager::LayerAnimationRecordFor(nsCSSProperty aProperty) -{ - MOZ_ASSERT(nsCSSProps::PropHasFlags(aProperty, - CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR), - "unexpected property"); - const auto& info = sLayerAnimationInfo; - for (size_t i = 0; i < ArrayLength(info); ++i) { - if (aProperty == info[i].mProperty) { - return &info[i]; - } - } - return nullptr; -} - /* virtual */ void CommonAnimationManager::WillRefresh(TimeStamp aTime) { @@ -455,42 +432,6 @@ CommonAnimationManager::WillRefresh(TimeStamp aTime) MaybeStartOrStopObservingRefreshDriver(); } -#ifdef DEBUG -/* static */ void -CommonAnimationManager::Initialize() -{ - const auto& info = CommonAnimationManager::sLayerAnimationInfo; - for (size_t i = 0; i < ArrayLength(info); i++) { - auto record = info[i]; - MOZ_ASSERT(nsCSSProps::PropHasFlags(record.mProperty, - CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR), - "CSS property with entry in sLayerAnimationInfo does not " - "have the CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR flag"); - } - - // Check that every property with the flag for animating on the - // compositor has an entry in sLayerAnimationInfo. - for (nsCSSProperty prop = nsCSSProperty(0); - prop < eCSSProperty_COUNT; - prop = nsCSSProperty(prop + 1)) { - if (nsCSSProps::PropHasFlags(prop, - CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR)) { - bool found = false; - for (size_t i = 0; i < ArrayLength(info); i++) { - auto record = info[i]; - if (record.mProperty == prop) { - found = true; - break; - } - } - MOZ_ASSERT(found, - "CSS property with the CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR " - "flag does not have an entry in sLayerAnimationInfo"); - } - } -} -#endif - NS_IMPL_ISUPPORTS(AnimValuesStyleRule, nsIStyleRule) /* virtual */ void @@ -901,9 +842,8 @@ AnimationCollection::CanThrottleAnimation(TimeStamp aTime) return false; } - const auto& info = CommonAnimationManager::sLayerAnimationInfo; - for (size_t i = 0; i < ArrayLength(info); i++) { - auto record = info[i]; + for (const LayerAnimationInfo::Record& record : + LayerAnimationInfo::sRecords) { // We only need to worry about *current* animations here. // - If we have a newly-finished animation, Animation::CanThrottle will // detect that and force an unthrottled sample. diff --git a/layout/style/AnimationCommon.h b/layout/style/AnimationCommon.h index b42bec58074..1ba0926f582 100644 --- a/layout/style/AnimationCommon.h +++ b/layout/style/AnimationCommon.h @@ -65,10 +65,6 @@ public: // nsARefreshObserver void WillRefresh(TimeStamp aTime) override; -#ifdef DEBUG - static void Initialize(); -#endif - // NOTE: This can return null after Disconnect(). nsPresContext* PresContext() const { return mPresContext; } @@ -120,18 +116,6 @@ public: nsChangeHint mChangeHint; }; -protected: - static const size_t kLayerRecords = 2; - -public: - static const LayerAnimationRecord sLayerAnimationInfo[kLayerRecords]; - - // Will return non-null for any property with the - // CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR flag; should only be called - // on such properties. - static const LayerAnimationRecord* - LayerAnimationRecordFor(nsCSSProperty aProperty); - protected: virtual ~CommonAnimationManager(); diff --git a/layout/style/LayerAnimationInfo.cpp b/layout/style/LayerAnimationInfo.cpp new file mode 100644 index 00000000000..bebdb7d3de6 --- /dev/null +++ b/layout/style/LayerAnimationInfo.cpp @@ -0,0 +1,53 @@ +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "LayerAnimationInfo.h" + +#include "nsCSSProps.h" // For nsCSSProps::PropHasFlags + +namespace mozilla { + +/* static */ const LayerAnimationInfo::Record LayerAnimationInfo::sRecords[] = + { { eCSSProperty_transform, + nsDisplayItem::TYPE_TRANSFORM, + nsChangeHint_UpdateTransformLayer }, + { eCSSProperty_opacity, + nsDisplayItem::TYPE_OPACITY, + nsChangeHint_UpdateOpacityLayer } }; + +#ifdef DEBUG +/* static */ void +LayerAnimationInfo::Initialize() +{ + for (const Record& record : sRecords) { + MOZ_ASSERT(nsCSSProps::PropHasFlags(record.mProperty, + CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR), + "CSS property with entry in LayerAnimation::sRecords does not " + "have the CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR flag"); + } + + // Check that every property with the flag for animating on the + // compositor has an entry in LayerAnimationInfo::sRecords. + for (nsCSSProperty prop = nsCSSProperty(0); + prop < eCSSProperty_COUNT; + prop = nsCSSProperty(prop + 1)) { + if (nsCSSProps::PropHasFlags(prop, + CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR)) { + bool found = false; + for (const Record& record : sRecords) { + if (record.mProperty == prop) { + found = true; + break; + } + } + MOZ_ASSERT(found, + "CSS property with the CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR " + "flag does not have an entry in LayerAnimationInfo::sRecords"); + } + } +} +#endif + +} // namespace mozilla diff --git a/layout/style/LayerAnimationInfo.h b/layout/style/LayerAnimationInfo.h new file mode 100644 index 00000000000..01a1ef42b39 --- /dev/null +++ b/layout/style/LayerAnimationInfo.h @@ -0,0 +1,33 @@ +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_LayerAnimationInfo_h +#define mozilla_LayerAnimationInfo_h + +#include "nsChangeHint.h" +#include "nsCSSProperty.h" +#include "nsDisplayList.h" // For nsDisplayItem::Type + +namespace mozilla { + +struct LayerAnimationInfo { +#ifdef DEBUG + static void Initialize(); +#endif + // For CSS properties that may be animated on a separate layer, represents + // a record of the corresponding layer type and change hint. + struct Record { + nsCSSProperty mProperty; + nsDisplayItem::Type mLayerType; + nsChangeHint mChangeHint; + }; + + static const size_t kRecords = 2; + static const Record sRecords[kRecords]; +}; + +} // namespace mozilla + +#endif /* !defined(mozilla_LayerAnimationInfo_h) */ diff --git a/layout/style/moz.build b/layout/style/moz.build index a0c968b1387..b3a31729347 100644 --- a/layout/style/moz.build +++ b/layout/style/moz.build @@ -85,6 +85,7 @@ EXPORTS.mozilla += [ 'CSSVariableResolver.h', 'CSSVariableValues.h', 'IncrementalClearCOMRuleArray.h', + 'LayerAnimationInfo.h', 'RuleNodeCacheConditions.h', 'RuleProcessorCache.h', 'StyleAnimationValue.h', @@ -130,6 +131,7 @@ UNIFIED_SOURCES += [ 'FontFaceSetIterator.cpp', 'ImageLoader.cpp', 'IncrementalClearCOMRuleArray.cpp', + 'LayerAnimationInfo.cpp', 'Loader.cpp', 'MediaQueryList.cpp', 'nsAnimationManager.cpp',