layout/style/LayerAnimationInfo.h
author Andreea Pavel <apavel@mozilla.com>
Tue, 27 Nov 2018 15:33:29 +0200
changeset 507467 20898bcaaa0069be066b088fde0262169fc71261
parent 507423 359e81b35cfb72928457964fcf1c826db1404818
child 507676 d99d8f275d8bfa954671ea2663bbe37a561d7583
permissions -rw-r--r--
Backed out 2 changesets (bug 1504065) for failing Win reftest at child-in-animating-element-display-none.html on a CLOSED TREE Backed out changeset 129188370231 (bug 1504065) Backed out changeset 359e81b35cfb (bug 1504065)

/* -*- 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_LayerAnimationInfo_h
#define mozilla_LayerAnimationInfo_h

#include "nsChangeHint.h"
#include "nsCSSPropertyID.h"
#include "nsCSSPropertyIDSet.h"
#include "nsDisplayList.h" // For nsDisplayItem::Type
#include "mozilla/Array.h"

namespace mozilla {

struct LayerAnimationInfo {
  // Returns the corresponding display item type for |aProperty| when it is
  // animated on the compositor.
  // Returns DisplayItemType::TYPE_ZERO if |aProperty| cannot be animated on the
  // compositor.
  static DisplayItemType
  GetDisplayItemTypeForProperty(nsCSSPropertyID aProperty);

  // Returns the corresponding CSS properties for |aDisplayItemType|.
  //
  // This function works only for display items tied to CSS properties that can
  // be animated on the compositor.
  static inline const nsCSSPropertyIDSet&
  GetCSSPropertiesFor(DisplayItemType aDisplayItemType)
  {
    static const nsCSSPropertyIDSet transformProperties =
      nsCSSPropertyIDSet{ eCSSProperty_transform };
    static const nsCSSPropertyIDSet opacityProperties =
      nsCSSPropertyIDSet{ eCSSProperty_opacity };
    static const nsCSSPropertyIDSet empty = nsCSSPropertyIDSet();

    switch (aDisplayItemType) {
      case DisplayItemType::TYPE_OPACITY:
        return opacityProperties;
      case DisplayItemType::TYPE_TRANSFORM:
        return transformProperties;
      default:
        MOZ_ASSERT_UNREACHABLE("Should not be called for display item types "
                               "that are not able to have animations on the "
                               "compositor");
        return empty;
    }
  }

  // Returns the appropriate change hint for updating the display item for
  // |aDisplayItemType|.
  //
  // This function works only for display items tied to CSS properties that can
  // be animated on the compositor.
  static inline nsChangeHint
  GetChangeHintFor(DisplayItemType aDisplayItemType)
  {
    switch (aDisplayItemType) {
      case DisplayItemType::TYPE_OPACITY:
        return nsChangeHint_UpdateOpacityLayer;
      case DisplayItemType::TYPE_TRANSFORM:
        return nsChangeHint_UpdateTransformLayer;
      default:
        MOZ_ASSERT_UNREACHABLE("Should not be called for display item types "
                               "that are not able to have animations on the "
                               "compositor");
        return nsChangeHint(0);
    }
  }

  // An array of DisplayItemType corresponding to the display item taht we can
  // animate on the compositor.
  //
  // This is used to look up the appropriate change hint in cases when
  // animations need updating but no other change hint is generated.
  static const Array<DisplayItemType,
                     nsCSSPropertyIDSet::CompositorAnimatableCount()>
    sDisplayItemTypes;
};

} // namespace mozilla

#endif /* !defined(mozilla_LayerAnimationInfo_h) */