tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

LayerAnimationInfo.h (3484B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_LayerAnimationInfo_h
      8 #define mozilla_LayerAnimationInfo_h
      9 
     10 #include "NonCustomCSSPropertyId.h"
     11 #include "mozilla/Array.h"
     12 #include "nsCSSPropertyIDSet.h"
     13 #include "nsChangeHint.h"
     14 #include "nsDisplayItemTypes.h"  // For nsDisplayItem::Type
     15 
     16 namespace mozilla {
     17 
     18 struct LayerAnimationInfo {
     19  // Returns the corresponding display item type for |aProperty| when it is
     20  // animated on the compositor.
     21  // Returns DisplayItemType::TYPE_ZERO if |aProperty| cannot be animated on the
     22  // compositor.
     23  static DisplayItemType GetDisplayItemTypeForProperty(
     24      NonCustomCSSPropertyId aProperty);
     25 
     26  // Returns the corresponding CSS properties for |aDisplayItemType|.
     27  //
     28  // This function works only for display items tied to CSS properties that can
     29  // be animated on the compositor.
     30  static inline const nsCSSPropertyIDSet& GetCSSPropertiesFor(
     31      DisplayItemType aDisplayItemType) {
     32    static const nsCSSPropertyIDSet transformProperties =
     33        nsCSSPropertyIDSet::TransformLikeProperties();
     34    static const nsCSSPropertyIDSet opacityProperties =
     35        nsCSSPropertyIDSet{eCSSProperty_opacity};
     36    static const nsCSSPropertyIDSet backgroundColorProperties =
     37        nsCSSPropertyIDSet{eCSSProperty_background_color};
     38    static const nsCSSPropertyIDSet empty = nsCSSPropertyIDSet();
     39 
     40    switch (aDisplayItemType) {
     41      case DisplayItemType::TYPE_BACKGROUND_COLOR:
     42        return backgroundColorProperties;
     43      case DisplayItemType::TYPE_OPACITY:
     44        return opacityProperties;
     45      case DisplayItemType::TYPE_TRANSFORM:
     46        return transformProperties;
     47      default:
     48        MOZ_ASSERT_UNREACHABLE(
     49            "Should not be called for display item types "
     50            "that are not able to have animations on the "
     51            "compositor");
     52        return empty;
     53    }
     54  }
     55 
     56  // Returns the appropriate change hint for updating the display item for
     57  // |aDisplayItemType|.
     58  //
     59  // This function works only for display items tied to CSS properties that can
     60  // be animated on the compositor.
     61  static inline nsChangeHint GetChangeHintFor(
     62      DisplayItemType aDisplayItemType) {
     63    switch (aDisplayItemType) {
     64      case DisplayItemType::TYPE_BACKGROUND_COLOR:
     65        return nsChangeHint_RepaintFrame;
     66      case DisplayItemType::TYPE_OPACITY:
     67        return nsChangeHint_UpdateOpacityLayer;
     68      case DisplayItemType::TYPE_TRANSFORM:
     69        return nsChangeHint_UpdateTransformLayer;
     70      default:
     71        MOZ_ASSERT_UNREACHABLE(
     72            "Should not be called for display item types "
     73            "that are not able to have animations on the "
     74            "compositor");
     75        return nsChangeHint(0);
     76    }
     77  }
     78 
     79  // An array of DisplayItemType corresponding to the display item that we can
     80  // animate on the compositor.
     81  //
     82  // This is used to look up the appropriate change hint in cases when
     83  // animations need updating but no other change hint is generated.
     84  static const Array<DisplayItemType,
     85                     nsCSSPropertyIDSet::CompositorAnimatableDisplayItemCount()>
     86      sDisplayItemTypes;
     87 };
     88 
     89 }  // namespace mozilla
     90 
     91 #endif /* !defined(mozilla_LayerAnimationInfo_h) */