From fd98de719ce5686f5afbd2ac4176ad895ac62a07 Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Fri, 4 Dec 2015 08:32:53 +0900 Subject: [PATCH] Bug 1226118 part 5 - Move LogAsyncAnimationFailure to AnimationUtils; r=dholbert This patch also moves AnimationUtils out of the dom namespace since it seems unnecessary. We typically only put actual DOM interfaces in the dom namespace. --- dom/animation/AnimationUtils.cpp | 36 ++++++++++++++++++++++++++++++++ dom/animation/AnimationUtils.h | 20 +++++++++++------- dom/animation/KeyframeEffect.cpp | 12 +++++------ dom/animation/moz.build | 1 + layout/base/nsDisplayList.cpp | 10 ++++----- layout/style/AnimationCommon.cpp | 23 ++------------------ layout/style/AnimationCommon.h | 3 --- 7 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 dom/animation/AnimationUtils.cpp diff --git a/dom/animation/AnimationUtils.cpp b/dom/animation/AnimationUtils.cpp new file mode 100644 index 000000000000..7ef553089407 --- /dev/null +++ b/dom/animation/AnimationUtils.cpp @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 "AnimationUtils.h" + +#include "nsDebug.h" +#include "nsIAtom.h" +#include "nsIContent.h" +#include "nsString.h" + +namespace mozilla { + +/* static */ void +AnimationUtils::LogAsyncAnimationFailure(nsCString& aMessage, + const nsIContent* aContent) +{ + if (aContent) { + aMessage.AppendLiteral(" ["); + aMessage.Append(nsAtomCString(aContent->NodeInfo()->NameAtom())); + + nsIAtom* id = aContent->GetID(); + if (id) { + aMessage.AppendLiteral(" with id '"); + aMessage.Append(nsAtomCString(aContent->GetID())); + aMessage.Append('\''); + } + aMessage.Append(']'); + } + aMessage.Append('\n'); + printf_stderr("%s", aMessage.get()); +} + +} // namespace mozilla diff --git a/dom/animation/AnimationUtils.h b/dom/animation/AnimationUtils.h index be3e621e2f26..23e8e33b5b0f 100644 --- a/dom/animation/AnimationUtils.h +++ b/dom/animation/AnimationUtils.h @@ -9,17 +9,19 @@ #include "mozilla/TimeStamp.h" #include "mozilla/dom/Nullable.h" +#include "nsStringFwd.h" + +class nsIContent; namespace mozilla { -namespace dom { class AnimationUtils { public: - static Nullable - TimeDurationToDouble(const Nullable& aTime) + static dom::Nullable + TimeDurationToDouble(const dom::Nullable& aTime) { - Nullable result; + dom::Nullable result; if (!aTime.IsNull()) { result.SetValue(aTime.Value().ToMilliseconds()); @@ -28,10 +30,10 @@ public: return result; } - static Nullable - DoubleToTimeDuration(const Nullable& aTime) + static dom::Nullable + DoubleToTimeDuration(const dom::Nullable& aTime) { - Nullable result; + dom::Nullable result; if (!aTime.IsNull()) { result.SetValue(TimeDuration::FromMilliseconds(aTime.Value())); @@ -39,9 +41,11 @@ public: return result; } + + static void LogAsyncAnimationFailure(nsCString& aMessage, + const nsIContent* aContent = nullptr); }; -} // namespace dom } // namespace mozilla #endif diff --git a/dom/animation/KeyframeEffect.cpp b/dom/animation/KeyframeEffect.cpp index c50e824bf97a..76fe4c54a05e 100644 --- a/dom/animation/KeyframeEffect.cpp +++ b/dom/animation/KeyframeEffect.cpp @@ -9,6 +9,7 @@ #include "mozilla/dom/AnimationEffectReadOnlyBinding.h" #include "mozilla/dom/KeyframeEffectBinding.h" #include "mozilla/dom/PropertyIndexedKeyframesBinding.h" +#include "mozilla/AnimationUtils.h" #include "mozilla/FloatingPoint.h" #include "mozilla/LookAndFeel.h" // For LookAndFeel::GetInt #include "mozilla/StyleAnimationValue.h" @@ -55,7 +56,7 @@ GetComputedTimingDictionary(const ComputedTiming& aComputedTiming, aRetVal.mActiveDuration = aComputedTiming.mActiveDuration.ToMilliseconds(); aRetVal.mEndTime = std::max(aRetVal.mDelay + aRetVal.mActiveDuration + aRetVal.mEndDelay, 0.0); - aRetVal.mLocalTime = dom::AnimationUtils::TimeDurationToDouble(aLocalTime); + aRetVal.mLocalTime = AnimationUtils::TimeDurationToDouble(aLocalTime); aRetVal.mProgress = aComputedTiming.mProgress; if (!aRetVal.mProgress.IsNull()) { // Convert the returned currentIteration into Infinity if we set @@ -1990,7 +1991,7 @@ KeyframeEffectReadOnly::CanAnimateTransformOnCompositor( nsCString message; message.AppendLiteral("Gecko bug: Async animation of 'preserve-3d' " "transforms is not supported. See bug 779598"); - AnimationCollection::LogAsyncAnimationFailure(message, aContent); + AnimationUtils::LogAsyncAnimationFailure(message, aContent); } return false; } @@ -2004,7 +2005,7 @@ KeyframeEffectReadOnly::CanAnimateTransformOnCompositor( message.AppendLiteral("Gecko bug: Async animation of " "'backface-visibility: hidden' transforms is not supported." " See bug 1186204."); - AnimationCollection::LogAsyncAnimationFailure(message, aContent); + AnimationUtils::LogAsyncAnimationFailure(message, aContent); } return false; } @@ -2013,7 +2014,7 @@ KeyframeEffectReadOnly::CanAnimateTransformOnCompositor( nsCString message; message.AppendLiteral("Gecko bug: Async 'transform' animations of " "aFrames with SVG transforms is not supported. See bug 779599"); - AnimationCollection::LogAsyncAnimationFailure(message, aContent); + AnimationUtils::LogAsyncAnimationFailure(message, aContent); } return false; } @@ -2034,8 +2035,7 @@ KeyframeEffectReadOnly::CanAnimatePropertyOnCompositor( message.AppendLiteral("Performance warning: Async animation of " "'transform' or 'opacity' not possible due to animation of geometric" "properties on the same element"); - AnimationCollection::LogAsyncAnimationFailure(message, - aFrame->GetContent()); + AnimationUtils::LogAsyncAnimationFailure(message, aFrame->GetContent()); } return false; } diff --git a/dom/animation/moz.build b/dom/animation/moz.build index 60767fcf0733..327b0bdbf4c8 100644 --- a/dom/animation/moz.build +++ b/dom/animation/moz.build @@ -27,6 +27,7 @@ UNIFIED_SOURCES += [ 'Animation.cpp', 'AnimationEffectReadOnly.cpp', 'AnimationTimeline.cpp', + 'AnimationUtils.cpp', 'ComputedTimingFunction.cpp', 'DocumentTimeline.cpp', 'EffectSet.cpp', diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 71fa4a74b5e8..bc3a39406e47 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -54,6 +54,7 @@ #include "ImageContainer.h" #include "nsCanvasFrame.h" #include "StickyScrollContainer.h" +#include "mozilla/AnimationUtils.h" #include "mozilla/EventStates.h" #include "mozilla/LookAndFeel.h" #include "mozilla/PendingAnimationTracker.h" @@ -5398,8 +5399,7 @@ nsDisplayOpacity::CanUseAsyncAnimations(nsDisplayListBuilder* aBuilder) if (nsLayoutUtils::IsAnimationLoggingEnabled()) { nsCString message; message.AppendLiteral("Performance warning: Async animation disabled because frame was not marked active for opacity animation"); - AnimationCollection::LogAsyncAnimationFailure(message, - Frame()->GetContent()); + AnimationUtils::LogAsyncAnimationFailure(message, Frame()->GetContent()); } return false; } @@ -5450,8 +5450,7 @@ nsDisplayTransform::ShouldPrerenderTransformedContent(nsDisplayListBuilder* aBui if (aLogAnimations) { nsCString message; message.AppendLiteral("Performance warning: Async animation disabled because frame was not marked active for transform animation"); - AnimationCollection::LogAsyncAnimationFailure(message, - aFrame->GetContent()); + AnimationUtils::LogAsyncAnimationFailure(message, aFrame->GetContent()); } return false; } @@ -5490,8 +5489,7 @@ nsDisplayTransform::ShouldPrerenderTransformedContent(nsDisplayListBuilder* aBui message.AppendLiteral(") is larger than the max allowable value ("); message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(maxInAppUnits)); message.Append(')'); - AnimationCollection::LogAsyncAnimationFailure(message, - aFrame->GetContent()); + AnimationUtils::LogAsyncAnimationFailure(message, aFrame->GetContent()); } return false; } diff --git a/layout/style/AnimationCommon.cpp b/layout/style/AnimationCommon.cpp index 5c0d500ba8bc..db30ce61f993 100644 --- a/layout/style/AnimationCommon.cpp +++ b/layout/style/AnimationCommon.cpp @@ -20,6 +20,7 @@ #include "LayerAnimationInfo.h" // For LayerAnimationInfo::sRecords #include "FrameLayerBuilder.h" #include "nsDisplayList.h" +#include "mozilla/AnimationUtils.h" #include "mozilla/EffectSet.h" #include "mozilla/MemoryReporting.h" #include "mozilla/dom/KeyframeEffect.h" @@ -438,7 +439,7 @@ AnimationCollection::CanPerformOnCompositorThread(const nsIFrame* aFrame) const if (nsLayoutUtils::IsAnimationLoggingEnabled()) { nsCString message; message.AppendLiteral("Performance warning: Async animations are disabled"); - LogAsyncAnimationFailure(message); + AnimationUtils::LogAsyncAnimationFailure(message); } return false; } @@ -524,26 +525,6 @@ AnimationCollection::GetElementToRestyle() const return pseudoFrame->GetContent()->AsElement(); } -/* static */ void -AnimationCollection::LogAsyncAnimationFailure(nsCString& aMessage, - const nsIContent* aContent) -{ - if (aContent) { - aMessage.AppendLiteral(" ["); - aMessage.Append(nsAtomCString(aContent->NodeInfo()->NameAtom())); - - nsIAtom* id = aContent->GetID(); - if (id) { - aMessage.AppendLiteral(" with id '"); - aMessage.Append(nsAtomCString(aContent->GetID())); - aMessage.Append('\''); - } - aMessage.Append(']'); - } - aMessage.Append('\n'); - printf_stderr("%s", aMessage.get()); -} - /*static*/ void AnimationCollection::PropertyDtor(void *aObject, nsIAtom *aPropertyName, void *aPropertyValue, void *aData) diff --git a/layout/style/AnimationCommon.h b/layout/style/AnimationCommon.h index d0384ddb575e..dc6c38f9dee2 100644 --- a/layout/style/AnimationCommon.h +++ b/layout/style/AnimationCommon.h @@ -335,9 +335,6 @@ public: } } - static void LogAsyncAnimationFailure(nsCString& aMessage, - const nsIContent* aContent = nullptr); - dom::Element *mElement; // the atom we use in mElement's prop table (must be a static atom,