/src/mozilla-central/layout/painting/DisplayItemClipChain.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "DisplayItemClipChain.h" |
8 | | |
9 | | #include "nsDisplayList.h" |
10 | | |
11 | | namespace mozilla { |
12 | | |
13 | | /* static */ const DisplayItemClip* |
14 | | DisplayItemClipChain::ClipForASR(const DisplayItemClipChain* aClipChain, |
15 | | const ActiveScrolledRoot* aASR) |
16 | 0 | { |
17 | 0 | while (aClipChain && |
18 | 0 | !ActiveScrolledRoot::IsAncestor(aClipChain->mASR, aASR)) { |
19 | 0 | aClipChain = aClipChain->mParent; |
20 | 0 | } |
21 | 0 | return (aClipChain && aClipChain->mASR == aASR) ? &aClipChain->mClip |
22 | 0 | : nullptr; |
23 | 0 | } |
24 | | |
25 | | bool |
26 | | DisplayItemClipChain::Equal(const DisplayItemClipChain* aClip1, |
27 | | const DisplayItemClipChain* aClip2) |
28 | 0 | { |
29 | 0 | if (aClip1 == aClip2) { |
30 | 0 | return true; |
31 | 0 | } |
32 | 0 | |
33 | 0 | if (!aClip1 || !aClip2) { |
34 | 0 | return false; |
35 | 0 | } |
36 | 0 | |
37 | 0 | bool ret = aClip1->mASR == aClip2->mASR && aClip1->mClip == aClip2->mClip && |
38 | 0 | Equal(aClip1->mParent, aClip2->mParent); |
39 | 0 | // Sanity check: if two clip chains are equal they must hash to the same |
40 | 0 | // thing too, or Bad Things (TM) will happen. |
41 | 0 | MOZ_ASSERT(!ret || (Hash(aClip1) == Hash(aClip2))); |
42 | 0 | return ret; |
43 | 0 | } |
44 | | |
45 | | uint32_t |
46 | | DisplayItemClipChain::Hash(const DisplayItemClipChain* aClip) |
47 | 0 | { |
48 | 0 | if (!aClip) { |
49 | 0 | return 0; |
50 | 0 | } |
51 | 0 | |
52 | 0 | // We include the number of rounded rects in the hash but not their contents. |
53 | 0 | // This is to keep the hash fast, because most clips will not have rounded |
54 | 0 | // rects and including them will slow down the hash in the common case. Note |
55 | 0 | // that the ::Equal check still checks the rounded rect contents, so in case |
56 | 0 | // of hash collisions the clip chains can still be distinguished using that. |
57 | 0 | uint32_t hash = HashGeneric(aClip->mASR, aClip->mClip.GetRoundedRectCount()); |
58 | 0 | if (aClip->mClip.HasClip()) { |
59 | 0 | const nsRect& rect = aClip->mClip.GetClipRect(); |
60 | 0 | // empty rects are considered equal in DisplayItemClipChain::Equal, even |
61 | 0 | // though they may have different x and y coordinates. So make sure they |
62 | 0 | // hash to the same thing in those cases too. |
63 | 0 | if (!rect.IsEmpty()) { |
64 | 0 | hash = AddToHash(hash, rect.x, rect.y, rect.width, rect.height); |
65 | 0 | } |
66 | 0 | } |
67 | 0 |
|
68 | 0 | return hash; |
69 | 0 | } |
70 | | |
71 | | /* static */ nsCString |
72 | | DisplayItemClipChain::ToString(const DisplayItemClipChain* aClipChain) |
73 | 0 | { |
74 | 0 | nsAutoCString str; |
75 | 0 | for (auto* sc = aClipChain; sc; sc = sc->mParent) { |
76 | 0 | if (sc->mASR) { |
77 | 0 | str.AppendPrintf("0x%p <%s> [0x%p]", |
78 | 0 | sc, |
79 | 0 | sc->mClip.ToString().get(), |
80 | 0 | sc->mASR->mScrollableFrame); |
81 | 0 | } else { |
82 | 0 | str.AppendPrintf("0x%p <%s> [root asr]", sc, sc->mClip.ToString().get()); |
83 | 0 | } |
84 | 0 | if (sc->mParent) { |
85 | 0 | str.AppendLiteral(", "); |
86 | 0 | } |
87 | 0 | } |
88 | 0 | return std::move(str); |
89 | 0 | } |
90 | | |
91 | | bool |
92 | | DisplayItemClipChain::HasRoundedCorners() const |
93 | 0 | { |
94 | 0 | return mClip.GetRoundedRectCount() > 0 || |
95 | 0 | (mParent && mParent->HasRoundedCorners()); |
96 | 0 | } |
97 | | |
98 | | } // namespace mozilla |