tor-browser

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

DisplayItemClipChain.h (3912B)


      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 DISPLAYITEMCLIPCHAIN_H_
      8 #define DISPLAYITEMCLIPCHAIN_H_
      9 
     10 #include "DisplayItemClip.h"
     11 #include "mozilla/Assertions.h"
     12 #include "nsString.h"
     13 
     14 namespace mozilla {
     15 
     16 struct ActiveScrolledRoot;
     17 
     18 /**
     19 * A DisplayItemClipChain is a linked list of DisplayItemClips where each clip
     20 * is associated with an active scrolled root that describes what the clip
     21 * moves with.
     22 * We use a chain instead of just one intersected clip due to async scrolling:
     23 * A clip that moves along with a display item can be fused to the item's
     24 * contents when drawing the layer contents, but all other clips in the chain
     25 * need to be kept separate so that they can be applied at composition time,
     26 * after any async scroll offsets have been applied.
     27 * The clip chain is created during display list construction by the builder's
     28 * DisplayListClipState.
     29 * The clip chain order is determined by the active scrolled root order.
     30 * For every DisplayItemClipChain object |clipChain|, the following holds:
     31 * !clipChain->mParent ||
     32 * ActiveScrolledRoot::IsAncestor(clipChain->mParent->mASR, clipChain->mASR).
     33 * The clip chain can skip over active scrolled roots. That just means that
     34 * there is no clip that moves with the skipped ASR in this chain.
     35 */
     36 struct DisplayItemClipChain {
     37  /**
     38   * Get the display item clip in this chain that moves with aASR, or nullptr
     39   * if no such clip exists. aClipChain can be null.
     40   */
     41  static const DisplayItemClip* ClipForASR(
     42      const DisplayItemClipChain* aClipChain, const ActiveScrolledRoot* aASR);
     43 
     44  static bool Equal(const DisplayItemClipChain* aClip1,
     45                    const DisplayItemClipChain* aClip2);
     46  /**
     47   * Hash function that returns the same value for any two clips A and B
     48   * where Equal(A, B) is true.
     49   */
     50  static uint32_t Hash(const DisplayItemClipChain* aClip);
     51 
     52  static nsCString ToString(const DisplayItemClipChain* aClipChain);
     53 
     54  bool HasRoundedCorners() const;
     55 
     56  void AddRef() { mRefCount++; }
     57  void Release() {
     58    MOZ_ASSERT(mRefCount > 0);
     59    mRefCount--;
     60  }
     61 
     62  DisplayItemClipChain(const DisplayItemClip& aClip,
     63                       const ActiveScrolledRoot* aASR,
     64                       const DisplayItemClipChain* aParent,
     65                       DisplayItemClipChain* aNextClipChainToDestroy)
     66      : mClip(aClip),
     67        mASR(aASR),
     68        mParent(aParent),
     69        mNextClipChainToDestroy(aNextClipChainToDestroy)
     70 #if defined(DEBUG) || defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
     71        ,
     72        mOnStack(true)
     73 #endif
     74  {
     75  }
     76 
     77  DisplayItemClipChain()
     78      : mASR(nullptr),
     79        mNextClipChainToDestroy(nullptr)
     80 #if defined(DEBUG) || defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
     81        ,
     82        mOnStack(true)
     83 #endif
     84  {
     85  }
     86 
     87  bool IsDisplayportClip() const { return mKind == ClipKind::Displayport; }
     88 
     89  enum class ClipKind : uint8_t { Displayport, Other };
     90 
     91  DisplayItemClip mClip;
     92  const ActiveScrolledRoot* mASR;
     93  RefPtr<const DisplayItemClipChain> mParent;
     94  uint32_t mRefCount = 0;
     95  ClipKind mKind = ClipKind::Other;
     96  DisplayItemClipChain* mNextClipChainToDestroy;
     97 #if defined(DEBUG) || defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
     98  bool mOnStack;
     99 #endif
    100 };
    101 
    102 struct DisplayItemClipChainHasher {
    103  typedef const DisplayItemClipChain* Key;
    104 
    105  std::size_t operator()(const Key& aKey) const {
    106    return DisplayItemClipChain::Hash(aKey);
    107  }
    108 };
    109 
    110 struct DisplayItemClipChainEqualer {
    111  typedef const DisplayItemClipChain* Key;
    112 
    113  bool operator()(const Key& lhs, const Key& rhs) const {
    114    return DisplayItemClipChain::Equal(lhs, rhs);
    115  }
    116 };
    117 
    118 }  // namespace mozilla
    119 
    120 #endif /* DISPLAYITEMCLIPCHAIN_H_ */