2011-04-12 10:18:43 +04:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2013-10-23 00:55:14 +04:00
|
|
|
#include "AnimationCommon.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "nsTransitionManager.h"
|
|
|
|
#include "nsAnimationManager.h"
|
|
|
|
|
2014-06-20 07:39:25 +04:00
|
|
|
#include "ActiveLayerTracker.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "gfxPlatform.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsRuleData.h"
|
2014-06-20 07:39:24 +04:00
|
|
|
#include "nsCSSPropertySet.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsCSSValue.h"
|
2014-07-16 04:02:30 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsStyleContext.h"
|
2012-07-31 21:28:21 +04:00
|
|
|
#include "nsIFrame.h"
|
2012-07-31 21:28:22 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-12-12 01:12:43 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
|
|
|
#include "Layers.h"
|
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "nsDisplayList.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-08-20 02:55:18 +04:00
|
|
|
#include "RestyleManager.h"
|
2013-10-22 16:14:41 +04:00
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsStyleChangeList.h"
|
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
|
2014-04-03 09:57:28 +04:00
|
|
|
using mozilla::layers::Layer;
|
2014-08-10 11:06:44 +04:00
|
|
|
using mozilla::dom::AnimationPlayer;
|
2014-08-10 11:06:49 +04:00
|
|
|
using mozilla::dom::Animation;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
/* static */ bool
|
|
|
|
IsGeometricProperty(nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
switch (aProperty) {
|
|
|
|
case eCSSProperty_bottom:
|
|
|
|
case eCSSProperty_height:
|
|
|
|
case eCSSProperty_left:
|
|
|
|
case eCSSProperty_right:
|
|
|
|
case eCSSProperty_top:
|
|
|
|
case eCSSProperty_width:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 03:57:12 +04:00
|
|
|
namespace css {
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
CommonAnimationManager::CommonAnimationManager(nsPresContext *aPresContext)
|
|
|
|
: mPresContext(aPresContext)
|
|
|
|
{
|
2014-06-27 03:57:13 +04:00
|
|
|
PR_INIT_CLIST(&mElementCollections);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CommonAnimationManager::~CommonAnimationManager()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!mPresContext, "Disconnect should have been called");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CommonAnimationManager::Disconnect()
|
|
|
|
{
|
|
|
|
// Content nodes might outlive the transition or animation manager.
|
2014-06-27 03:57:13 +04:00
|
|
|
RemoveAllElementCollections();
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mPresContext = nullptr;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-27 03:57:13 +04:00
|
|
|
CommonAnimationManager::RemoveAllElementCollections()
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2014-06-27 03:57:13 +04:00
|
|
|
while (!PR_CLIST_IS_EMPTY(&mElementCollections)) {
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection* head =
|
|
|
|
static_cast<AnimationPlayerCollection*>(
|
2014-06-27 03:57:13 +04:00
|
|
|
PR_LIST_HEAD(&mElementCollections));
|
2011-04-12 10:18:43 +04:00
|
|
|
head->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection*
|
2014-06-20 07:39:25 +04:00
|
|
|
CommonAnimationManager::GetAnimationsForCompositor(nsIContent* aContent,
|
|
|
|
nsIAtom* aElementProperty,
|
|
|
|
nsCSSProperty aProperty)
|
|
|
|
{
|
|
|
|
if (!aContent->MayHaveAnimations())
|
|
|
|
return nullptr;
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection* collection =
|
|
|
|
static_cast<AnimationPlayerCollection*>(
|
2014-06-20 07:39:25 +04:00
|
|
|
aContent->GetProperty(aElementProperty));
|
2014-06-27 03:57:13 +04:00
|
|
|
if (!collection ||
|
|
|
|
!collection->HasAnimationOfProperty(aProperty) ||
|
|
|
|
!collection->CanPerformOnCompositorThread(
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::CanAnimate_AllowPartial)) {
|
2014-06-20 07:39:25 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-06-20 07:39:26 +04:00
|
|
|
|
|
|
|
// This animation can be done on the compositor.
|
|
|
|
// Mark the frame as active, in case we are able to throttle this animation.
|
2014-06-27 03:57:13 +04:00
|
|
|
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(collection->mElement);
|
2014-06-20 07:39:26 +04:00
|
|
|
if (frame) {
|
|
|
|
if (aProperty == eCSSProperty_opacity) {
|
|
|
|
ActiveLayerTracker::NotifyAnimated(frame, eCSSProperty_opacity);
|
|
|
|
} else if (aProperty == eCSSProperty_transform) {
|
|
|
|
ActiveLayerTracker::NotifyAnimated(frame, eCSSProperty_transform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 03:57:13 +04:00
|
|
|
return collection;
|
2014-06-20 07:39:25 +04:00
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
/*
|
|
|
|
* nsISupports implementation
|
|
|
|
*/
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(CommonAnimationManager, nsIStyleRuleProcessor)
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2013-11-28 10:46:39 +04:00
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-04-12 10:18:43 +04:00
|
|
|
CommonAnimationManager::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRestyleHint
|
|
|
|
CommonAnimationManager::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* virtual */ bool
|
2011-04-12 10:18:43 +04:00
|
|
|
CommonAnimationManager::MediumFeaturesChanged(nsPresContext* aPresContext)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
/* virtual */ size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
CommonAnimationManager::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-08-01 22:25:20 +04:00
|
|
|
{
|
2012-01-03 06:19:14 +04:00
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
2014-06-27 03:57:13 +04:00
|
|
|
// - mElementCollections
|
2012-01-03 06:19:14 +04:00
|
|
|
//
|
|
|
|
// The following members are not measured
|
|
|
|
// - mPresContext, because it's non-owning
|
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
CommonAnimationManager::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-12-09 09:01:52 +04:00
|
|
|
{
|
2012-01-25 12:52:51 +04:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-08-01 22:25:20 +04:00
|
|
|
}
|
|
|
|
|
2014-08-07 09:58:44 +04:00
|
|
|
void
|
|
|
|
CommonAnimationManager::AddStyleUpdatesTo(RestyleTracker& aTracker)
|
|
|
|
{
|
|
|
|
PRCList* next = PR_LIST_HEAD(&mElementCollections);
|
|
|
|
while (next != &mElementCollections) {
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection* collection =
|
|
|
|
static_cast<AnimationPlayerCollection*>(next);
|
2014-08-07 09:58:44 +04:00
|
|
|
next = PR_NEXT_LINK(next);
|
|
|
|
|
|
|
|
if (!collection->IsForElement()) {
|
|
|
|
// We don't support compositor-driven animation of :before/:after
|
|
|
|
// transitions or animations, so at least skip those.
|
|
|
|
// FIXME: We'll need to handle this before using this for the
|
|
|
|
// transitions redesign.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRestyleHint rshint = collection->IsForTransitions()
|
|
|
|
? eRestyle_CSSTransitions : eRestyle_CSSAnimations;
|
|
|
|
aTracker.AddPendingRestyle(collection->mElement, rshint, nsChangeHint(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2011-04-12 10:18:43 +04:00
|
|
|
CommonAnimationManager::ExtractComputedValueForTransition(
|
|
|
|
nsCSSProperty aProperty,
|
|
|
|
nsStyleContext* aStyleContext,
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue& aComputedValue)
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2014-06-24 10:29:54 +04:00
|
|
|
bool result = StyleAnimationValue::ExtractComputedValue(aProperty,
|
|
|
|
aStyleContext,
|
|
|
|
aComputedValue);
|
2011-04-12 10:18:43 +04:00
|
|
|
if (aProperty == eCSSProperty_visibility) {
|
|
|
|
NS_ABORT_IF_FALSE(aComputedValue.GetUnit() ==
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue::eUnit_Enumerated,
|
2011-04-12 10:18:43 +04:00
|
|
|
"unexpected unit");
|
|
|
|
aComputedValue.SetIntValue(aComputedValue.GetIntValue(),
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue::eUnit_Visibility);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(AnimValuesStyleRule, nsIStyleRule)
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
AnimValuesStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
nsStyleContext *contextParent = aRuleData->mStyleContext->GetParent();
|
|
|
|
if (contextParent && contextParent->HasPseudoElementData()) {
|
|
|
|
// Don't apply transitions or animations to things inside of
|
|
|
|
// pseudo-elements.
|
|
|
|
// FIXME (Bug 522599): Add tests for this.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
|
2011-04-12 10:18:43 +04:00
|
|
|
PropertyValuePair &cv = mPropertyValuePairs[i];
|
|
|
|
if (aRuleData->mSIDs & nsCachedStyleData::GetBitForSID(
|
|
|
|
nsCSSProps::kSIDTable[cv.mProperty]))
|
|
|
|
{
|
|
|
|
nsCSSValue *prop = aRuleData->ValueFor(cv.mProperty);
|
|
|
|
if (prop->GetUnit() == eCSSUnit_Null) {
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ok =
|
2011-04-12 10:18:43 +04:00
|
|
|
#endif
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue::UncomputeValue(cv.mProperty, cv.mValue, *prop);
|
2011-04-12 10:18:43 +04:00
|
|
|
NS_ABORT_IF_FALSE(ok, "could not store computed value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* virtual */ void
|
2012-08-22 19:56:38 +04:00
|
|
|
AnimValuesStyleRule::List(FILE* out, int32_t aIndent) const
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2012-11-20 23:55:14 +04:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
2012-11-21 01:22:35 +04:00
|
|
|
fputs("[anim values] { ", out);
|
2012-11-20 23:55:14 +04:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
|
|
|
|
const PropertyValuePair &pair = mPropertyValuePairs[i];
|
|
|
|
nsAutoString value;
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue::UncomputeValue(pair.mProperty, pair.mValue, value);
|
2012-11-21 01:22:35 +04:00
|
|
|
fprintf(out, "%s: %s; ", nsCSSProps::GetStringValue(pair.mProperty).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(value).get());
|
2012-11-20 23:55:14 +04:00
|
|
|
}
|
2012-11-21 01:22:35 +04:00
|
|
|
fputs("}\n", out);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-04-03 09:57:28 +04:00
|
|
|
} /* end sub-namespace css */
|
|
|
|
|
2012-07-31 21:28:21 +04:00
|
|
|
bool
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::CanAnimatePropertyOnCompositor(
|
2014-06-27 03:57:12 +04:00
|
|
|
const dom::Element *aElement,
|
2014-06-27 03:57:13 +04:00
|
|
|
nsCSSProperty aProperty,
|
|
|
|
CanAnimateFlags aFlags)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
2012-08-07 00:33:23 +04:00
|
|
|
bool shouldLog = nsLayoutUtils::IsAnimationLoggingEnabled();
|
2014-03-05 08:13:22 +04:00
|
|
|
if (!gfxPlatform::OffMainThreadCompositingEnabled()) {
|
|
|
|
if (shouldLog) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Compositor disabled");
|
|
|
|
LogAsyncAnimationFailure(message);
|
|
|
|
}
|
2012-08-26 05:27:28 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-25 09:32:10 +04:00
|
|
|
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(aElement);
|
2012-08-22 05:48:47 +04:00
|
|
|
if (IsGeometricProperty(aProperty)) {
|
|
|
|
if (shouldLog) {
|
2012-08-26 05:27:28 +04:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animation of geometric property '");
|
2012-12-12 01:12:47 +04:00
|
|
|
message.Append(nsCSSProps::GetStringValue(aProperty));
|
|
|
|
message.AppendLiteral("' is disabled");
|
2012-08-26 05:27:28 +04:00
|
|
|
LogAsyncAnimationFailure(message, aElement);
|
2012-08-22 05:48:47 +04:00
|
|
|
}
|
|
|
|
return false;
|
2012-08-05 21:03:43 +04:00
|
|
|
}
|
2012-08-03 10:32:13 +04:00
|
|
|
if (aProperty == eCSSProperty_transform) {
|
2012-08-22 05:48:47 +04:00
|
|
|
if (frame->Preserves3D() &&
|
2012-08-03 10:32:13 +04:00
|
|
|
frame->Preserves3DChildren()) {
|
2012-08-07 00:33:23 +04:00
|
|
|
if (shouldLog) {
|
2012-08-26 05:27:28 +04:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Gecko bug: Async animation of 'preserve-3d' transforms is not supported. See bug 779598");
|
|
|
|
LogAsyncAnimationFailure(message, aElement);
|
2012-08-03 10:32:13 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-22 05:48:47 +04:00
|
|
|
if (frame->IsSVGTransformed()) {
|
2012-08-07 00:33:23 +04:00
|
|
|
if (shouldLog) {
|
2012-08-26 05:27:28 +04:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Gecko bug: Async 'transform' animations of frames with SVG transforms is not supported. See bug 779599");
|
|
|
|
LogAsyncAnimationFailure(message, aElement);
|
2012-08-03 10:32:13 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-12-12 01:12:43 +04:00
|
|
|
if (aFlags & CanAnimate_HasGeometricProperty) {
|
2012-08-22 05:48:47 +04:00
|
|
|
if (shouldLog) {
|
2012-08-26 05:27:28 +04:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animation of 'transform' not possible due to presence of geometric properties");
|
|
|
|
LogAsyncAnimationFailure(message, aElement);
|
2012-08-22 05:48:47 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-03 10:32:13 +04:00
|
|
|
}
|
2013-05-23 11:09:26 +04:00
|
|
|
bool enabled = nsLayoutUtils::AreAsyncAnimationsEnabled();
|
|
|
|
if (!enabled && shouldLog) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animations are disabled");
|
|
|
|
LogAsyncAnimationFailure(message);
|
|
|
|
}
|
2013-06-18 12:03:20 +04:00
|
|
|
bool propertyAllowed = (aProperty == eCSSProperty_transform) ||
|
|
|
|
(aProperty == eCSSProperty_opacity) ||
|
|
|
|
(aFlags & CanAnimate_AllowPartial);
|
|
|
|
return enabled && propertyAllowed;
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
|
|
|
|
2013-10-22 14:30:45 +04:00
|
|
|
/* static */ bool
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::IsCompositorAnimationDisabledForFrame(
|
2014-06-27 03:57:12 +04:00
|
|
|
nsIFrame* aFrame)
|
2013-10-22 14:30:45 +04:00
|
|
|
{
|
|
|
|
void* prop = aFrame->Properties().Get(nsIFrame::RefusedAsyncAnimation());
|
|
|
|
return bool(reinterpret_cast<intptr_t>(prop));
|
|
|
|
}
|
|
|
|
|
2014-06-20 07:39:25 +04:00
|
|
|
bool
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::CanPerformOnCompositorThread(
|
2014-06-20 07:39:25 +04:00
|
|
|
CanAnimateFlags aFlags) const
|
|
|
|
{
|
|
|
|
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(mElement);
|
|
|
|
if (!frame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mElementProperty != nsGkAtoms::transitionsProperty &&
|
|
|
|
mElementProperty != nsGkAtoms::animationsProperty) {
|
|
|
|
if (nsLayoutUtils::IsAnimationLoggingEnabled()) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Gecko bug: Async animation of pseudoelements"
|
|
|
|
" not supported. See bug 771367 (");
|
|
|
|
message.Append(nsAtomCString(mElementProperty));
|
|
|
|
message.Append(")");
|
|
|
|
LogAsyncAnimationFailure(message, mElement);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t playerIdx = mPlayers.Length(); playerIdx-- != 0; ) {
|
|
|
|
const AnimationPlayer* player = mPlayers[playerIdx];
|
2014-08-10 11:06:49 +04:00
|
|
|
if (!player->IsRunning() || !player->GetSource()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const Animation* anim = player->GetSource();
|
|
|
|
for (size_t propIdx = 0, propEnd = anim->Properties().Length();
|
2014-06-20 07:39:25 +04:00
|
|
|
propIdx != propEnd; ++propIdx) {
|
2014-08-10 11:06:49 +04:00
|
|
|
if (IsGeometricProperty(anim->Properties()[propIdx].mProperty)) {
|
2014-06-20 07:39:25 +04:00
|
|
|
aFlags = CanAnimateFlags(aFlags | CanAnimate_HasGeometricProperty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool existsProperty = false;
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t playerIdx = mPlayers.Length(); playerIdx-- != 0; ) {
|
|
|
|
const AnimationPlayer* player = mPlayers[playerIdx];
|
2014-08-10 11:06:49 +04:00
|
|
|
if (!player->IsRunning() || !player->GetSource()) {
|
2014-06-20 07:39:25 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:49 +04:00
|
|
|
const Animation* anim = player->GetSource();
|
|
|
|
existsProperty = existsProperty || anim->Properties().Length() > 0;
|
2014-06-20 07:39:25 +04:00
|
|
|
|
2014-08-10 11:06:49 +04:00
|
|
|
for (size_t propIdx = 0, propEnd = anim->Properties().Length();
|
2014-06-20 07:39:25 +04:00
|
|
|
propIdx != propEnd; ++propIdx) {
|
2014-08-10 11:06:49 +04:00
|
|
|
const AnimationProperty& prop = anim->Properties()[propIdx];
|
2014-06-20 07:39:25 +04:00
|
|
|
if (!CanAnimatePropertyOnCompositor(mElement,
|
|
|
|
prop.mProperty,
|
|
|
|
aFlags) ||
|
|
|
|
IsCompositorAnimationDisabledForFrame(frame)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No properties to animate
|
|
|
|
if (!existsProperty) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-20 07:39:25 +04:00
|
|
|
bool
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::HasAnimationOfProperty(
|
2014-06-20 07:39:25 +04:00
|
|
|
nsCSSProperty aProperty) const
|
|
|
|
{
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t playerIdx = mPlayers.Length(); playerIdx-- != 0; ) {
|
|
|
|
const AnimationPlayer* player = mPlayers[playerIdx];
|
2014-08-10 11:06:49 +04:00
|
|
|
const Animation* anim = player->GetSource();
|
|
|
|
// FIXME: Drop the reference to the player once we move
|
|
|
|
// IsFinishedTransition to Animation
|
|
|
|
if (anim && anim->HasAnimationOfProperty(aProperty) &&
|
2014-08-10 11:06:48 +04:00
|
|
|
!player->IsFinishedTransition()) {
|
2014-06-20 07:39:25 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-26 05:27:28 +04:00
|
|
|
/* static */ void
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::LogAsyncAnimationFailure(nsCString& aMessage,
|
2012-08-26 05:27:28 +04:00
|
|
|
const nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent) {
|
|
|
|
aMessage.AppendLiteral(" [");
|
|
|
|
aMessage.Append(nsAtomCString(aContent->Tag()));
|
|
|
|
|
|
|
|
nsIAtom* id = aContent->GetID();
|
|
|
|
if (id) {
|
|
|
|
aMessage.AppendLiteral(" with id '");
|
|
|
|
aMessage.Append(nsAtomCString(aContent->GetID()));
|
2014-05-22 07:48:51 +04:00
|
|
|
aMessage.Append('\'');
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
2014-05-22 07:48:51 +04:00
|
|
|
aMessage.Append(']');
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
2014-05-22 07:48:51 +04:00
|
|
|
aMessage.Append('\n');
|
2012-08-26 05:27:28 +04:00
|
|
|
printf_stderr(aMessage.get());
|
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2014-06-24 10:29:53 +04:00
|
|
|
/*static*/ void
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::PropertyDtor(void *aObject, nsIAtom *aPropertyName,
|
2014-06-24 10:29:53 +04:00
|
|
|
void *aPropertyValue, void *aData)
|
|
|
|
{
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection* collection =
|
|
|
|
static_cast<AnimationPlayerCollection*>(aPropertyValue);
|
2014-06-24 10:29:53 +04:00
|
|
|
#ifdef DEBUG
|
2014-06-27 03:57:13 +04:00
|
|
|
NS_ABORT_IF_FALSE(!collection->mCalledPropertyDtor, "can't call dtor twice");
|
|
|
|
collection->mCalledPropertyDtor = true;
|
2014-06-24 10:29:53 +04:00
|
|
|
#endif
|
2014-06-27 03:57:13 +04:00
|
|
|
delete collection;
|
2014-06-24 10:29:53 +04:00
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:48 +04:00
|
|
|
void
|
|
|
|
AnimationPlayerCollection::Tick()
|
|
|
|
{
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t playerIdx = 0, playerEnd = mPlayers.Length();
|
|
|
|
playerIdx != playerEnd; playerIdx++) {
|
|
|
|
mPlayers[playerIdx]->Tick();
|
2014-08-10 11:06:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 07:39:24 +04:00
|
|
|
void
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::EnsureStyleRuleFor(TimeStamp aRefreshTime,
|
|
|
|
EnsureStyleRuleFlags aFlags)
|
2014-06-20 07:39:24 +04:00
|
|
|
{
|
|
|
|
if (!mNeedsRefreshes) {
|
|
|
|
mStyleRuleRefreshTime = aRefreshTime;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're performing animations on the compositor thread, then we can skip
|
|
|
|
// most of the work in this method. But even if we are throttled, then we
|
|
|
|
// have to do the work if an animation is ending in order to get correct end
|
|
|
|
// of animation behaviour (the styles of the animation disappear, or the fill
|
|
|
|
// mode behaviour). This loop checks for any finishing animations and forces
|
|
|
|
// the style recalculation if we find any.
|
2014-06-20 07:39:25 +04:00
|
|
|
if (aFlags == EnsureStyleRule_IsThrottled) {
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t playerIdx = mPlayers.Length(); playerIdx-- != 0; ) {
|
|
|
|
AnimationPlayer* player = mPlayers[playerIdx];
|
2014-06-20 07:39:24 +04:00
|
|
|
|
2014-08-10 11:06:49 +04:00
|
|
|
// Skip player with no source content, finished transitions, or animations
|
|
|
|
// whose @keyframes rule is empty.
|
|
|
|
if (!player->GetSource() ||
|
|
|
|
player->IsFinishedTransition() ||
|
|
|
|
player->GetSource()->Properties().IsEmpty()) {
|
2014-06-20 07:39:24 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:48 +04:00
|
|
|
// The GetComputedTiming() call here handles pausing. But:
|
2014-06-20 07:39:24 +04:00
|
|
|
// FIXME: avoid recalculating every time when paused.
|
2014-08-10 11:06:50 +04:00
|
|
|
ComputedTiming computedTiming = player->GetSource()->GetComputedTiming();
|
2014-06-20 07:39:24 +04:00
|
|
|
|
|
|
|
// XXX We shouldn't really be using mLastNotification as a general
|
|
|
|
// indicator that the animation has finished, it should be reserved for
|
|
|
|
// events. If we use it differently in the future this use might need
|
|
|
|
// changing.
|
2014-08-10 11:06:48 +04:00
|
|
|
if (!player->mIsRunningOnCompositor ||
|
2014-06-20 07:39:24 +04:00
|
|
|
(computedTiming.mPhase == ComputedTiming::AnimationPhase_After &&
|
2014-08-10 11:06:48 +04:00
|
|
|
player->mLastNotification != AnimationPlayer::LAST_NOTIFICATION_END))
|
2014-06-20 07:39:24 +04:00
|
|
|
{
|
2014-06-20 07:39:25 +04:00
|
|
|
aFlags = EnsureStyleRule_IsNotThrottled;
|
2014-06-20 07:39:24 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 07:39:25 +04:00
|
|
|
if (aFlags == EnsureStyleRule_IsThrottled) {
|
2014-06-20 07:39:24 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mStyleRule may be null and valid, if we have no style to apply.
|
|
|
|
if (mStyleRuleRefreshTime.IsNull() ||
|
|
|
|
mStyleRuleRefreshTime != aRefreshTime) {
|
|
|
|
mStyleRuleRefreshTime = aRefreshTime;
|
|
|
|
mStyleRule = nullptr;
|
|
|
|
// We'll set mNeedsRefreshes to true below in all cases where we need them.
|
|
|
|
mNeedsRefreshes = false;
|
|
|
|
|
|
|
|
// FIXME(spec): assume that properties in higher animations override
|
|
|
|
// those in lower ones.
|
|
|
|
// Therefore, we iterate from last animation to first.
|
|
|
|
nsCSSPropertySet properties;
|
|
|
|
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t playerIdx = mPlayers.Length(); playerIdx-- != 0; ) {
|
|
|
|
AnimationPlayer* player = mPlayers[playerIdx];
|
2014-06-20 07:39:24 +04:00
|
|
|
|
2014-08-10 11:06:50 +04:00
|
|
|
if (!player->GetSource() || player->IsFinishedTransition()) {
|
2014-06-20 07:39:24 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-10 11:06:48 +04:00
|
|
|
// The GetComputedTiming() call here handles pausing. But:
|
2014-06-20 07:39:24 +04:00
|
|
|
// FIXME: avoid recalculating every time when paused.
|
2014-08-10 11:06:50 +04:00
|
|
|
ComputedTiming computedTiming = player->GetSource()->GetComputedTiming();
|
2014-06-20 07:39:24 +04:00
|
|
|
|
|
|
|
if ((computedTiming.mPhase == ComputedTiming::AnimationPhase_Before ||
|
|
|
|
computedTiming.mPhase == ComputedTiming::AnimationPhase_Active) &&
|
2014-08-10 11:06:48 +04:00
|
|
|
!player->IsPaused()) {
|
2014-06-20 07:39:24 +04:00
|
|
|
mNeedsRefreshes = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the time fraction is null, we don't have fill data for the current
|
|
|
|
// time so we shouldn't animate.
|
2014-08-10 11:06:49 +04:00
|
|
|
// Likewise, if the player has no source content.
|
2014-08-10 11:06:50 +04:00
|
|
|
if (computedTiming.mTimeFraction == ComputedTiming::kNullTimeFraction) {
|
2014-06-20 07:39:24 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(0.0 <= computedTiming.mTimeFraction &&
|
|
|
|
computedTiming.mTimeFraction <= 1.0,
|
|
|
|
"timing fraction should be in [0-1]");
|
|
|
|
|
2014-08-10 11:06:49 +04:00
|
|
|
const Animation* anim = player->GetSource();
|
|
|
|
for (size_t propIdx = 0, propEnd = anim->Properties().Length();
|
2014-06-20 07:39:24 +04:00
|
|
|
propIdx != propEnd; ++propIdx)
|
|
|
|
{
|
2014-08-10 11:06:49 +04:00
|
|
|
const AnimationProperty& prop = anim->Properties()[propIdx];
|
2014-06-20 07:39:24 +04:00
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(prop.mSegments[0].mFromKey == 0.0,
|
|
|
|
"incorrect first from key");
|
|
|
|
NS_ABORT_IF_FALSE(prop.mSegments[prop.mSegments.Length() - 1].mToKey
|
|
|
|
== 1.0,
|
|
|
|
"incorrect last to key");
|
|
|
|
|
|
|
|
if (properties.HasProperty(prop.mProperty)) {
|
|
|
|
// A later animation already set this property.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
properties.AddProperty(prop.mProperty);
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(prop.mSegments.Length() > 0,
|
|
|
|
"property should not be in animations if it "
|
|
|
|
"has no segments");
|
|
|
|
|
|
|
|
// FIXME: Maybe cache the current segment?
|
|
|
|
const AnimationPropertySegment *segment = prop.mSegments.Elements(),
|
|
|
|
*segmentEnd = segment + prop.mSegments.Length();
|
|
|
|
while (segment->mToKey < computedTiming.mTimeFraction) {
|
|
|
|
NS_ABORT_IF_FALSE(segment->mFromKey < segment->mToKey,
|
|
|
|
"incorrect keys");
|
|
|
|
++segment;
|
|
|
|
if (segment == segmentEnd) {
|
|
|
|
NS_ABORT_IF_FALSE(false, "incorrect time fraction");
|
|
|
|
break; // in order to continue in outer loop (just below)
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(segment->mFromKey == (segment-1)->mToKey,
|
|
|
|
"incorrect keys");
|
|
|
|
}
|
|
|
|
if (segment == segmentEnd) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(segment->mFromKey < segment->mToKey,
|
|
|
|
"incorrect keys");
|
|
|
|
NS_ABORT_IF_FALSE(segment >= prop.mSegments.Elements() &&
|
|
|
|
size_t(segment - prop.mSegments.Elements()) <
|
|
|
|
prop.mSegments.Length(),
|
|
|
|
"out of array bounds");
|
|
|
|
|
|
|
|
if (!mStyleRule) {
|
|
|
|
// Allocate the style rule now that we know we have animation data.
|
|
|
|
mStyleRule = new css::AnimValuesStyleRule();
|
|
|
|
}
|
|
|
|
|
|
|
|
double positionInSegment =
|
|
|
|
(computedTiming.mTimeFraction - segment->mFromKey) /
|
|
|
|
(segment->mToKey - segment->mFromKey);
|
|
|
|
double valuePosition =
|
|
|
|
segment->mTimingFunction.GetValue(positionInSegment);
|
|
|
|
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue *val =
|
2014-06-20 07:39:24 +04:00
|
|
|
mStyleRule->AddEmptyValue(prop.mProperty);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool result =
|
|
|
|
#endif
|
2014-06-24 10:29:54 +04:00
|
|
|
StyleAnimationValue::Interpolate(prop.mProperty,
|
|
|
|
segment->mFromValue,
|
|
|
|
segment->mToValue,
|
|
|
|
valuePosition, *val);
|
2014-06-20 07:39:24 +04:00
|
|
|
NS_ABORT_IF_FALSE(result, "interpolate must succeed now");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-12 01:12:43 +04:00
|
|
|
bool
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::CanThrottleTransformChanges(TimeStamp aTime)
|
2012-12-12 01:12:43 +04:00
|
|
|
{
|
2013-05-22 14:31:03 +04:00
|
|
|
if (!nsLayoutUtils::AreAsyncAnimationsEnabled()) {
|
2012-12-12 01:12:43 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we know that the animation cannot cause overflow,
|
|
|
|
// we can just disable flushes for this animation.
|
|
|
|
|
|
|
|
// If we don't show scrollbars, we don't care about overflow.
|
|
|
|
if (LookAndFeel::GetInt(LookAndFeel::eIntID_ShowHideScrollbars) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this animation can cause overflow, we can throttle some of the ticks.
|
|
|
|
if ((aTime - mStyleRuleRefreshTime) < TimeDuration::FromMilliseconds(200)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the nearest scrollable ancestor has overflow:hidden,
|
|
|
|
// we don't care about overflow.
|
2013-06-25 09:32:10 +04:00
|
|
|
nsIScrollableFrame* scrollable = nsLayoutUtils::GetNearestScrollableFrame(
|
|
|
|
nsLayoutUtils::GetStyleFrame(mElement));
|
2012-12-12 01:12:43 +04:00
|
|
|
if (!scrollable) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-24 00:20:07 +04:00
|
|
|
ScrollbarStyles ss = scrollable->GetScrollbarStyles();
|
2012-12-12 01:12:43 +04:00
|
|
|
if (ss.mVertical == NS_STYLE_OVERFLOW_HIDDEN &&
|
|
|
|
ss.mHorizontal == NS_STYLE_OVERFLOW_HIDDEN &&
|
|
|
|
scrollable->GetLogicalScrollPosition() == nsPoint(0, 0)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::CanThrottleAnimation(TimeStamp aTime)
|
2012-12-12 01:12:43 +04:00
|
|
|
{
|
2013-06-25 09:32:10 +04:00
|
|
|
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(mElement);
|
2012-12-12 01:12:43 +04:00
|
|
|
if (!frame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasTransform = HasAnimationOfProperty(eCSSProperty_transform);
|
|
|
|
bool hasOpacity = HasAnimationOfProperty(eCSSProperty_opacity);
|
|
|
|
if (hasOpacity) {
|
|
|
|
Layer* layer = FrameLayerBuilder::GetDedicatedLayer(
|
|
|
|
frame, nsDisplayItem::TYPE_OPACITY);
|
|
|
|
if (!layer || mAnimationGeneration > layer->GetAnimationGeneration()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasTransform) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer* layer = FrameLayerBuilder::GetDedicatedLayer(
|
|
|
|
frame, nsDisplayItem::TYPE_TRANSFORM);
|
|
|
|
if (!layer || mAnimationGeneration > layer->GetAnimationGeneration()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CanThrottleTransformChanges(aTime);
|
|
|
|
}
|
|
|
|
|
2014-06-27 03:57:12 +04:00
|
|
|
void
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::UpdateAnimationGeneration(
|
2014-06-27 03:57:12 +04:00
|
|
|
nsPresContext* aPresContext)
|
2012-12-12 01:12:43 +04:00
|
|
|
{
|
|
|
|
mAnimationGeneration =
|
2013-07-20 23:14:25 +04:00
|
|
|
aPresContext->RestyleManager()->GetAnimationGeneration();
|
2012-12-12 01:12:43 +04:00
|
|
|
}
|
|
|
|
|
2014-06-16 22:43:04 +04:00
|
|
|
bool
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::HasCurrentAnimations()
|
2014-06-16 22:43:04 +04:00
|
|
|
{
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t playerIdx = mPlayers.Length(); playerIdx-- != 0; ) {
|
|
|
|
if (mPlayers[playerIdx]->IsCurrent()) {
|
2014-06-16 22:43:04 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|