2017-10-27 20:33:53 +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
|
2017-01-27 14:57:44 +03:00
|
|
|
* 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 DISPLAYITEMCLIPCHAIN_H_
|
|
|
|
#define DISPLAYITEMCLIPCHAIN_H_
|
|
|
|
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "DisplayItemClip.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
class nsIScrollableFrame;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
struct ActiveScrolledRoot;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A DisplayItemClipChain is a linked list of DisplayItemClips where each clip
|
|
|
|
* is associated with an active scrolled root that describes what the clip
|
|
|
|
* moves with.
|
|
|
|
* We use a chain instead of just one intersected clip due to async scrolling:
|
|
|
|
* A clip that moves along with a display item can be fused to the item's
|
|
|
|
* contents when drawing the layer contents, but all other clips in the chain
|
|
|
|
* need to be kept separate so that they can be applied at composition time,
|
|
|
|
* after any async scroll offsets have been applied.
|
|
|
|
* The clip chain is created during display list construction by the builder's
|
|
|
|
* DisplayListClipState.
|
|
|
|
* The clip chain order is determined by the active scrolled root order.
|
|
|
|
* For every DisplayItemClipChain object |clipChain|, the following holds:
|
2018-09-04 23:46:21 +03:00
|
|
|
* !clipChain->mParent ||
|
|
|
|
* ActiveScrolledRoot::IsAncestor(clipChain->mParent->mASR, clipChain->mASR).
|
2017-01-27 14:57:44 +03:00
|
|
|
* The clip chain can skip over active scrolled roots. That just means that
|
|
|
|
* there is no clip that moves with the skipped ASR in this chain.
|
|
|
|
*/
|
2018-09-04 23:46:21 +03:00
|
|
|
struct DisplayItemClipChain
|
|
|
|
{
|
2017-01-27 14:57:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the display item clip in this chain that moves with aASR, or nullptr
|
|
|
|
* if no such clip exists. aClipChain can be null.
|
|
|
|
*/
|
2018-09-04 23:46:21 +03:00
|
|
|
static const DisplayItemClip* ClipForASR(
|
|
|
|
const DisplayItemClipChain* aClipChain,
|
|
|
|
const ActiveScrolledRoot* aASR);
|
2017-01-27 14:57:44 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
static bool Equal(const DisplayItemClipChain* aClip1,
|
|
|
|
const DisplayItemClipChain* aClip2);
|
2018-01-06 17:52:58 +03:00
|
|
|
/**
|
|
|
|
* Hash function that returns the same value for any two clips A and B
|
|
|
|
* where Equal(A, B) is true.
|
|
|
|
*/
|
|
|
|
static uint32_t Hash(const DisplayItemClipChain* aClip);
|
2017-01-27 14:57:44 +03:00
|
|
|
|
|
|
|
static nsCString ToString(const DisplayItemClipChain* aClipChain);
|
|
|
|
|
|
|
|
bool HasRoundedCorners() const;
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
void AddRef() { mRefCount++; }
|
|
|
|
void Release()
|
|
|
|
{
|
2017-09-27 07:10:16 +03:00
|
|
|
MOZ_ASSERT(mRefCount > 0);
|
|
|
|
mRefCount--;
|
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
DisplayItemClipChain(const DisplayItemClip& aClip,
|
|
|
|
const ActiveScrolledRoot* aASR,
|
|
|
|
const DisplayItemClipChain* aParent)
|
2017-09-27 07:10:16 +03:00
|
|
|
: mClip(aClip)
|
|
|
|
, mASR(aASR)
|
|
|
|
, mParent(aParent)
|
2018-01-20 07:47:29 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mOnStack(true)
|
|
|
|
#endif
|
2018-09-04 23:46:21 +03:00
|
|
|
{
|
|
|
|
}
|
2017-09-27 07:10:16 +03:00
|
|
|
|
2018-01-20 07:47:29 +03:00
|
|
|
DisplayItemClipChain()
|
2018-06-15 19:13:05 +03:00
|
|
|
: mASR(nullptr)
|
2018-01-20 07:47:29 +03:00
|
|
|
#ifdef DEBUG
|
2018-06-15 19:13:05 +03:00
|
|
|
, mOnStack(true)
|
2018-01-20 07:47:29 +03:00
|
|
|
#endif
|
2018-09-04 23:46:21 +03:00
|
|
|
{
|
|
|
|
}
|
2017-09-27 07:10:16 +03:00
|
|
|
|
2017-01-27 14:57:44 +03:00
|
|
|
DisplayItemClip mClip;
|
|
|
|
const ActiveScrolledRoot* mASR;
|
2017-09-27 07:10:16 +03:00
|
|
|
RefPtr<const DisplayItemClipChain> mParent;
|
2017-11-21 03:46:48 +03:00
|
|
|
uint32_t mRefCount = 0;
|
2018-01-20 07:47:29 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mOnStack;
|
|
|
|
#endif
|
2017-01-27 14:57:44 +03:00
|
|
|
};
|
|
|
|
|
2018-01-06 17:52:58 +03:00
|
|
|
struct DisplayItemClipChainHasher
|
|
|
|
{
|
|
|
|
typedef const DisplayItemClipChain* Key;
|
|
|
|
|
|
|
|
std::size_t operator()(const Key& aKey) const
|
|
|
|
{
|
|
|
|
return DisplayItemClipChain::Hash(aKey);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DisplayItemClipChainEqualer
|
|
|
|
{
|
|
|
|
typedef const DisplayItemClipChain* Key;
|
|
|
|
|
|
|
|
bool operator()(const Key& lhs, const Key& rhs) const
|
|
|
|
{
|
|
|
|
return DisplayItemClipChain::Equal(lhs, rhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-27 14:57:44 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* DISPLAYITEMCLIPCHAIN_H_ */
|