From a0f05d7d7e8bca4c19dd4d33e5c1ce59b0d40016 Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Wed, 13 Jan 2016 07:54:53 +0900 Subject: [PATCH] Bug 1232577 part 2 - Add a hashmap to ElementCompositor to track which (pseudo-) elements need to have their animation style rule updated; r=heycam We will eventually use this in place of the various state flags stored on AnimationCollection (e.g. mStyleRuleRefreshTime, mStyleChanging, mHasPendingAnimationRestyle) as well as to do a more targetted update in FlushAnimations and AddStyleUpdatesTo. --- dom/animation/EffectCompositor.cpp | 18 +++++++- dom/animation/EffectCompositor.h | 12 ++++++ dom/animation/PseudoElementHashEntry.h | 60 ++++++++++++++++++++++++++ dom/animation/moz.build | 1 + 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 dom/animation/PseudoElementHashEntry.h diff --git a/dom/animation/EffectCompositor.cpp b/dom/animation/EffectCompositor.cpp index c7300cd596fc..1f4dc41d16c8 100644 --- a/dom/animation/EffectCompositor.cpp +++ b/dom/animation/EffectCompositor.cpp @@ -29,7 +29,23 @@ using mozilla::dom::KeyframeEffectReadOnly; namespace mozilla { -NS_IMPL_CYCLE_COLLECTION_0(EffectCompositor) +NS_IMPL_CYCLE_COLLECTION_CLASS(EffectCompositor) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(EffectCompositor) + for (auto& elementSet : tmp->mElementsToRestyle) { + elementSet.Clear(); + } +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(EffectCompositor) + for (auto& elementSet : tmp->mElementsToRestyle) { + for (auto iter = elementSet.Iter(); !iter.Done(); iter.Next()) { + CycleCollectionNoteChild(cb, iter.Key().mElement, + "EffectCompositor::mElementsToRestyle[]", + cb.Flags()); + } + } +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(EffectCompositor, AddRef) NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(EffectCompositor, Release) diff --git a/dom/animation/EffectCompositor.h b/dom/animation/EffectCompositor.h index 8f54de80f2e6..352855c2f792 100644 --- a/dom/animation/EffectCompositor.h +++ b/dom/animation/EffectCompositor.h @@ -7,12 +7,15 @@ #ifndef mozilla_EffectCompositor_h #define mozilla_EffectCompositor_h +#include "mozilla/EnumeratedArray.h" #include "mozilla/Maybe.h" #include "mozilla/Pair.h" +#include "mozilla/PseudoElementHashEntry.h" #include "mozilla/RefPtr.h" #include "nsCSSProperty.h" #include "nsCSSPseudoElements.h" #include "nsCycleCollectionParticipant.h" +#include "nsDataHashtable.h" #include "nsTArray.h" class nsCSSPropertySet; @@ -129,6 +132,15 @@ private: static nsPresContext* GetPresContext(dom::Element* aElement); nsPresContext* mPresContext; + + // Elements with a pending animation restyle. The associated bool value is + // true if a pending animation restyle has also been dispatched. For + // animations that can be throttled, we will add an entry to the hashtable to + // indicate that the style rule on the element is out of date but without + // posting a restyle to update it. + EnumeratedArray> + mElementsToRestyle; }; } // namespace mozilla diff --git a/dom/animation/PseudoElementHashEntry.h b/dom/animation/PseudoElementHashEntry.h new file mode 100644 index 000000000000..84aaf597ffef --- /dev/null +++ b/dom/animation/PseudoElementHashEntry.h @@ -0,0 +1,60 @@ +/* -*- 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/. */ + +#ifndef mozilla_PseudoElementHashEntry_h +#define mozilla_PseudoElementHashEntry_h + +#include "mozilla/dom/Element.h" +#include "mozilla/HashFunctions.h" +#include "nsCSSPseudoElements.h" +#include "PLDHashTable.h" + +namespace mozilla { + +struct PseudoElementHashKey +{ + dom::Element* mElement; + nsCSSPseudoElements::Type mPseudoType; +}; + +// A hash entry that uses a RefPtr, nsCSSPseudoElements::Type pair +class PseudoElementHashEntry : public PLDHashEntryHdr +{ +public: + typedef PseudoElementHashKey KeyType; + typedef const PseudoElementHashKey* KeyTypePointer; + + explicit PseudoElementHashEntry(KeyTypePointer aKey) + : mElement(aKey->mElement) + , mPseudoType(aKey->mPseudoType) { } + explicit PseudoElementHashEntry(const PseudoElementHashEntry& aCopy)=default; + + ~PseudoElementHashEntry() = default; + + KeyType GetKey() const { return {mElement, mPseudoType}; } + bool KeyEquals(KeyTypePointer aKey) const + { + return mElement == aKey->mElement && + mPseudoType == aKey->mPseudoType; + } + + static KeyTypePointer KeyToPointer(KeyType& aKey) { return &aKey; } + static PLDHashNumber HashKey(KeyTypePointer aKey) + { + if (!aKey) + return 0; + + return mozilla::HashGeneric(aKey->mElement, aKey->mPseudoType); + } + enum { ALLOW_MEMMOVE = true }; + + RefPtr mElement; + nsCSSPseudoElements::Type mPseudoType; +}; + +} // namespace mozilla + +#endif // mozilla_PseudoElementHashEntry_h diff --git a/dom/animation/moz.build b/dom/animation/moz.build index 18867759b983..e42a975d5b4c 100644 --- a/dom/animation/moz.build +++ b/dom/animation/moz.build @@ -23,6 +23,7 @@ EXPORTS.mozilla += [ 'EffectCompositor.h', 'EffectSet.h', 'PendingAnimationTracker.h', + 'PseudoElementHashEntry.h', ] UNIFIED_SOURCES += [