Bug 1151694 - Part 1 - Move CommonAnimationManager::sLayerAnimationInfo into LayerAnimationInfo.(cpp|h). r=bbirtles

This commit is contained in:
Hiroyuki Ikezoe 2015-09-03 22:59:00 +02:00
parent 4f5c0f0757
commit e92ce11cd1
7 changed files with 99 additions and 85 deletions

View File

@ -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) {

View File

@ -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();

View File

@ -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.

View File

@ -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();

View File

@ -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

View File

@ -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) */

View File

@ -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',