2015-12-04 02:34:12 +03:00
|
|
|
/* -*- 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_EffectCompositor_h
|
|
|
|
#define mozilla_EffectCompositor_h
|
|
|
|
|
2018-11-22 07:00:42 +03:00
|
|
|
#include "mozilla/AnimationPerformanceWarning.h"
|
2019-05-20 08:48:29 +03:00
|
|
|
#include "mozilla/AnimationTarget.h"
|
2016-01-13 01:54:53 +03:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2019-05-20 08:48:29 +03:00
|
|
|
#include "mozilla/HashTable.h"
|
2016-01-06 05:04:04 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2016-01-15 09:15:47 +03:00
|
|
|
#include "mozilla/OwningNonNull.h"
|
2016-01-13 01:54:53 +03:00
|
|
|
#include "mozilla/PseudoElementHashEntry.h"
|
2015-12-04 02:34:12 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2017-08-11 22:54:35 +03:00
|
|
|
#include "mozilla/ServoTypes.h"
|
2016-08-17 04:37:48 +03:00
|
|
|
#include "nsCSSPropertyID.h"
|
2016-01-13 01:54:53 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2016-01-13 01:54:53 +03:00
|
|
|
#include "nsDataHashtable.h"
|
2015-12-04 02:34:12 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
|
2016-08-17 04:46:58 +03:00
|
|
|
class nsCSSPropertyIDSet;
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2016-01-06 05:04:05 +03:00
|
|
|
class nsIFrame;
|
2016-01-06 05:04:05 +03:00
|
|
|
class nsPresContext;
|
2019-04-22 22:57:59 +03:00
|
|
|
enum class DisplayItemType : uint8_t;
|
2017-03-17 07:23:21 +03:00
|
|
|
struct RawServoAnimationValueMap;
|
2016-01-06 05:04:04 +03:00
|
|
|
|
2015-12-04 02:34:12 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
class ComputedStyle;
|
2016-01-06 05:04:05 +03:00
|
|
|
class EffectSet;
|
2016-01-13 01:54:55 +03:00
|
|
|
class RestyleTracker;
|
2016-11-16 00:30:57 +03:00
|
|
|
class StyleAnimationValue;
|
2016-12-04 02:07:40 +03:00
|
|
|
struct AnimationProperty;
|
2016-04-28 18:22:43 +03:00
|
|
|
struct NonOwningAnimationTarget;
|
2016-01-06 05:04:05 +03:00
|
|
|
|
2015-12-04 02:34:12 +03:00
|
|
|
namespace dom {
|
|
|
|
class Animation;
|
2016-01-06 05:04:04 +03:00
|
|
|
class Element;
|
2019-05-20 09:04:23 +03:00
|
|
|
class KeyframeEffect;
|
2015-12-04 02:34:12 +03:00
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
class EffectCompositor {
|
|
|
|
public:
|
2016-01-13 01:54:53 +03:00
|
|
|
explicit EffectCompositor(nsPresContext* aPresContext)
|
|
|
|
: mPresContext(aPresContext) {}
|
|
|
|
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(EffectCompositor)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(EffectCompositor)
|
|
|
|
|
|
|
|
void Disconnect() { mPresContext = nullptr; }
|
|
|
|
|
2016-01-06 05:04:05 +03:00
|
|
|
// Animations can be applied at two different levels in the CSS cascade:
|
2017-01-24 10:33:10 +03:00
|
|
|
enum class CascadeLevel : uint32_t {
|
2016-01-06 05:04:05 +03:00
|
|
|
// The animations sheet (CSS animations, script-generated animations,
|
|
|
|
// and CSS transitions that are no longer tied to CSS markup)
|
2017-01-24 10:33:10 +03:00
|
|
|
Animations = 0,
|
2016-01-06 05:04:05 +03:00
|
|
|
// The transitions sheet (CSS transitions that are tied to CSS markup)
|
2017-01-24 10:33:10 +03:00
|
|
|
Transitions = 1
|
2016-01-06 05:04:05 +03:00
|
|
|
};
|
2016-01-06 05:04:06 +03:00
|
|
|
// We don't define this as part of CascadeLevel as then we'd have to add
|
|
|
|
// explicit checks for the Count enum value everywhere CascadeLevel is used.
|
|
|
|
static const size_t kCascadeLevelCount =
|
|
|
|
static_cast<size_t>(CascadeLevel::Transitions) + 1;
|
2016-01-06 05:04:05 +03:00
|
|
|
|
2016-01-13 01:54:53 +03:00
|
|
|
// NOTE: This can return null after Disconnect().
|
|
|
|
nsPresContext* PresContext() const { return mPresContext; }
|
|
|
|
|
2016-01-13 01:54:53 +03:00
|
|
|
enum class RestyleType {
|
|
|
|
// Animation style has changed but the compositor is applying the same
|
|
|
|
// change so we might be able to defer updating the main thread until it
|
|
|
|
// becomes necessary.
|
|
|
|
Throttled,
|
|
|
|
// Animation style has changed and needs to be updated on the main thread.
|
|
|
|
Standard,
|
|
|
|
// Animation style has changed and needs to be updated on the main thread
|
|
|
|
// as well as forcing animations on layers to be updated.
|
|
|
|
// This is needed in cases such as when an animation becomes paused or has
|
2016-01-13 01:54:53 +03:00
|
|
|
// its playback rate changed. In such cases, although the computed style
|
2016-01-13 01:54:53 +03:00
|
|
|
// and refresh driver time might not change, we still need to ensure the
|
|
|
|
// corresponding animations on layers are updated to reflect the new
|
|
|
|
// configuration of the animation.
|
|
|
|
Layer
|
|
|
|
};
|
|
|
|
|
2016-01-13 01:54:53 +03:00
|
|
|
// Notifies the compositor that the animation rule for the specified
|
|
|
|
// (pseudo-)element at the specified cascade level needs to be updated.
|
|
|
|
// The specified steps taken to update the animation rule depend on
|
|
|
|
// |aRestyleType| whose values are described above.
|
2019-02-19 16:44:33 +03:00
|
|
|
void RequestRestyle(dom::Element* aElement, PseudoStyleType aPseudoType,
|
2016-01-13 01:54:53 +03:00
|
|
|
RestyleType aRestyleType, CascadeLevel aCascadeLevel);
|
|
|
|
|
2016-01-13 01:54:54 +03:00
|
|
|
// Schedule an animation restyle. This is called automatically by
|
|
|
|
// RequestRestyle when necessary. However, it is exposed here since we also
|
|
|
|
// need to perform this step when triggering transitions *without* also
|
|
|
|
// invalidating the animation style rule (which RequestRestyle would do).
|
|
|
|
void PostRestyleForAnimation(dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType,
|
2016-01-13 01:54:54 +03:00
|
|
|
CascadeLevel aCascadeLevel);
|
|
|
|
|
2016-01-13 01:54:55 +03:00
|
|
|
// Posts an animation restyle for any elements whose animation style rule
|
|
|
|
// is out of date but for which an animation restyle has not yet been
|
|
|
|
// posted because updates on the main thread are throttled.
|
|
|
|
void PostRestyleForThrottledAnimations();
|
|
|
|
|
2018-02-21 01:00:20 +03:00
|
|
|
// Clear all pending restyle requests for the given (pseudo-) element (and its
|
2019-03-26 07:48:26 +03:00
|
|
|
// ::before, ::after and ::marker elements if the given element is not
|
|
|
|
// pseudo).
|
2018-02-21 01:00:20 +03:00
|
|
|
void ClearRestyleRequestsFor(dom::Element* aElement);
|
|
|
|
|
2017-03-27 13:43:04 +03:00
|
|
|
// Called when computed style on the specified (pseudo-) element might
|
2016-04-01 03:31:51 +03:00
|
|
|
// have changed so that any context-sensitive values stored within
|
|
|
|
// animation effects (e.g. em-based endpoints used in keyframe effects)
|
|
|
|
// can be re-resolved to computed values.
|
2018-04-09 14:15:59 +03:00
|
|
|
void UpdateEffectProperties(const ComputedStyle* aStyle,
|
2016-04-01 03:31:51 +03:00
|
|
|
dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType);
|
2016-04-01 03:31:51 +03:00
|
|
|
|
2019-05-20 09:04:23 +03:00
|
|
|
// Get the animation rule for the appropriate level of the cascade for
|
|
|
|
// a (pseudo-)element. Called from the Servo side.
|
|
|
|
//
|
2019-03-21 20:00:27 +03:00
|
|
|
// The animation rule is stored in |RawServoAnimationValueMap|.
|
2017-03-17 07:23:21 +03:00
|
|
|
// We need to be careful while doing any modification because it may cause
|
|
|
|
// some thread-safe issues.
|
2019-03-21 20:00:27 +03:00
|
|
|
bool GetServoAnimationRule(const dom::Element* aElement,
|
|
|
|
PseudoStyleType aPseudoType,
|
|
|
|
CascadeLevel aCascadeLevel,
|
|
|
|
RawServoAnimationValueMap* aAnimationValues);
|
2017-01-24 10:27:56 +03:00
|
|
|
|
2019-05-20 09:04:23 +03:00
|
|
|
// A variant on GetServoAnimationRule that composes all the effects for an
|
|
|
|
// element up to and including |aEffect|.
|
|
|
|
//
|
|
|
|
// Note that |aEffect| might not be in the EffectSet since we can use this for
|
|
|
|
// committing the computed style of a removed Animation.
|
|
|
|
bool ComposeServoAnimationRuleForEffect(
|
|
|
|
dom::KeyframeEffect& aEffect, CascadeLevel aCascadeLevel,
|
|
|
|
RawServoAnimationValueMap* aAnimationValues);
|
|
|
|
|
2016-01-13 01:54:55 +03:00
|
|
|
bool HasPendingStyleUpdates() const;
|
|
|
|
|
2015-12-10 00:28:10 +03:00
|
|
|
static bool HasAnimationsForCompositor(const nsIFrame* aFrame,
|
2019-03-02 00:13:03 +03:00
|
|
|
DisplayItemType aType);
|
2015-12-10 00:28:10 +03:00
|
|
|
|
2015-12-04 02:34:12 +03:00
|
|
|
static nsTArray<RefPtr<dom::Animation>> GetAnimationsForCompositor(
|
2019-03-02 00:13:03 +03:00
|
|
|
const nsIFrame* aFrame, const nsCSSPropertyIDSet& aPropertySet);
|
2016-01-06 05:04:04 +03:00
|
|
|
|
2019-03-02 00:13:01 +03:00
|
|
|
static void ClearIsRunningOnCompositor(const nsIFrame* aFrame,
|
|
|
|
DisplayItemType aType);
|
2016-01-06 05:04:05 +03:00
|
|
|
|
|
|
|
// Update animation cascade results for the specified (pseudo-)element
|
|
|
|
// but only if we have marked the cascade as needing an update due a
|
|
|
|
// the change in the set of effects or a change in one of the effects'
|
|
|
|
// "in effect" state.
|
2017-05-19 10:58:47 +03:00
|
|
|
//
|
2016-01-06 05:04:05 +03:00
|
|
|
// This method does NOT detect if other styles that apply above the
|
|
|
|
// animation level of the cascade have changed.
|
2018-03-28 18:29:42 +03:00
|
|
|
static void MaybeUpdateCascadeResults(dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType);
|
2016-01-06 05:04:05 +03:00
|
|
|
|
2018-02-23 03:05:26 +03:00
|
|
|
// Update the mPropertiesWithImportantRules and
|
|
|
|
// mPropertiesForAnimationsLevel members of the given EffectSet, and also
|
|
|
|
// request any restyles required by changes to the cascade result.
|
|
|
|
//
|
|
|
|
// NOTE: This can be expensive so we should only call it if styles that apply
|
|
|
|
// above the animation level of the cascade might have changed. For all
|
|
|
|
// other cases we should call MaybeUpdateCascadeResults.
|
|
|
|
//
|
|
|
|
// This is typically reserved for internal callers but is public here since
|
|
|
|
// when we detect changes to the cascade on the Servo side we can't call
|
|
|
|
// MarkCascadeNeedsUpdate during the traversal so instead we call this as part
|
|
|
|
// of a follow-up sequential task.
|
2018-03-28 18:29:42 +03:00
|
|
|
static void UpdateCascadeResults(EffectSet& aEffectSet,
|
2018-02-23 03:05:26 +03:00
|
|
|
dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType);
|
2018-02-23 03:05:26 +03:00
|
|
|
|
2016-01-06 05:04:04 +03:00
|
|
|
// Helper to fetch the corresponding element and pseudo-type from a frame.
|
|
|
|
//
|
|
|
|
// For frames corresponding to pseudo-elements, the returned element is the
|
|
|
|
// element on which we store the animations (i.e. the EffectSet and/or
|
|
|
|
// AnimationCollection), *not* the generated content.
|
|
|
|
//
|
2019-03-18 07:10:30 +03:00
|
|
|
// For display:table content, which maintains a distinction between primary
|
|
|
|
// frame (table wrapper frame) and style frame (inner table frame), animations
|
|
|
|
// are stored on the content associated with the _style_ frame even though
|
|
|
|
// some (particularly transform-like animations) may be applied to the
|
|
|
|
// _primary_ frame. As a result, callers will typically want to pass the style
|
|
|
|
// frame to this function.
|
|
|
|
//
|
2016-01-06 05:04:04 +03:00
|
|
|
// Returns an empty result when a suitable element cannot be found including
|
|
|
|
// when the frame represents a pseudo-element on which we do not support
|
|
|
|
// animations.
|
2016-03-21 11:49:50 +03:00
|
|
|
static Maybe<NonOwningAnimationTarget> GetAnimationElementAndPseudoForFrame(
|
2016-01-06 05:04:04 +03:00
|
|
|
const nsIFrame* aFrame);
|
2016-01-06 05:04:04 +03:00
|
|
|
|
2019-03-18 07:10:30 +03:00
|
|
|
// Associates a performance warning with effects on |aFrame| that animate
|
2019-03-21 20:40:11 +03:00
|
|
|
// properties in |aPropertySet|.
|
2016-03-04 11:54:25 +03:00
|
|
|
static void SetPerformanceWarning(
|
2019-03-21 20:40:11 +03:00
|
|
|
const nsIFrame* aFrame, const nsCSSPropertyIDSet& aPropertySet,
|
2016-03-04 11:54:25 +03:00
|
|
|
const AnimationPerformanceWarning& aWarning);
|
2016-03-04 00:36:36 +03:00
|
|
|
|
2017-03-08 23:20:17 +03:00
|
|
|
// Do a bunch of stuff that we should avoid doing during the parallel
|
|
|
|
// traversal (e.g. changing member variables) for all elements that we expect
|
|
|
|
// to restyle on the next traversal.
|
2017-05-19 11:16:41 +03:00
|
|
|
//
|
2017-03-10 05:53:19 +03:00
|
|
|
// Returns true if there are elements needing a restyle for animation.
|
2017-08-11 22:54:35 +03:00
|
|
|
bool PreTraverse(ServoTraversalFlags aFlags);
|
2017-03-08 23:20:17 +03:00
|
|
|
|
2017-04-04 14:12:54 +03:00
|
|
|
// Similar to the above but for all elements in the subtree rooted
|
|
|
|
// at aElement.
|
2018-11-22 07:00:42 +03:00
|
|
|
bool PreTraverseInSubtree(ServoTraversalFlags aFlags, dom::Element* aRoot);
|
2017-04-04 14:12:54 +03:00
|
|
|
|
2019-05-20 08:48:29 +03:00
|
|
|
// Record a (pseudo-)element that may have animations that can be removed.
|
|
|
|
void NoteElementForReducing(const NonOwningAnimationTarget& aTarget);
|
|
|
|
|
|
|
|
bool NeedsReducing() const { return !mElementsToReduce.empty(); }
|
|
|
|
void ReduceAnimations();
|
|
|
|
|
2017-06-08 04:22:25 +03:00
|
|
|
// Returns the target element for restyling.
|
|
|
|
//
|
2019-03-26 07:48:26 +03:00
|
|
|
// If |aPseudoType| is ::after, ::before or ::marker, returns the generated
|
2017-06-08 04:22:25 +03:00
|
|
|
// content element of which |aElement| is the parent. If |aPseudoType| is any
|
2019-02-19 16:44:33 +03:00
|
|
|
// other pseudo type (other than PseudoStyleType::NotPseudo) returns nullptr.
|
2017-06-08 04:22:25 +03:00
|
|
|
// Otherwise, returns |aElement|.
|
|
|
|
static dom::Element* GetElementToRestyle(dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType);
|
2017-06-08 04:22:25 +03:00
|
|
|
|
2018-11-22 07:00:42 +03:00
|
|
|
// Returns true if any type of compositor animations on |aFrame| allow
|
|
|
|
// runnning on the compositor.
|
|
|
|
// Sets the reason in |aWarning| if the result is false.
|
|
|
|
static bool AllowCompositorAnimationsOnFrame(
|
2019-01-08 09:42:56 +03:00
|
|
|
const nsIFrame* aFrame,
|
2018-11-22 07:00:42 +03:00
|
|
|
AnimationPerformanceWarning::Type& aWarning /* out */);
|
|
|
|
|
2016-01-13 01:54:53 +03:00
|
|
|
private:
|
|
|
|
~EffectCompositor() = default;
|
|
|
|
|
2016-01-06 05:04:05 +03:00
|
|
|
// Get the properties in |aEffectSet| that we are able to animate on the
|
|
|
|
// compositor but which are also specified at a higher level in the cascade
|
2017-05-19 10:58:47 +03:00
|
|
|
// than the animations level.
|
|
|
|
static nsCSSPropertyIDSet GetOverriddenProperties(
|
|
|
|
EffectSet& aEffectSet, dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType);
|
2016-01-06 05:04:05 +03:00
|
|
|
|
|
|
|
static nsPresContext* GetPresContext(dom::Element* aElement);
|
2016-01-13 01:54:53 +03:00
|
|
|
|
|
|
|
nsPresContext* mPresContext;
|
2016-01-13 01:54:53 +03:00
|
|
|
|
|
|
|
// 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<CascadeLevel, CascadeLevel(kCascadeLevelCount),
|
|
|
|
nsDataHashtable<PseudoElementHashEntry, bool>>
|
|
|
|
mElementsToRestyle;
|
2016-01-15 09:15:47 +03:00
|
|
|
|
2017-05-11 08:08:35 +03:00
|
|
|
bool mIsInPreTraverse = false;
|
2019-05-20 08:48:29 +03:00
|
|
|
|
|
|
|
HashSet<OwningAnimationTarget> mElementsToReduce;
|
2015-12-04 02:34:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_EffectCompositor_h
|