Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/wr/WebRenderScrollData.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 "mozilla/layers/WebRenderScrollData.h"
8
9
#include "Layers.h"
10
#include "LayersLogging.h"
11
#include "mozilla/layers/WebRenderLayerManager.h"
12
#include "mozilla/layout/RenderFrameParent.h"
13
#include "mozilla/Unused.h"
14
#include "nsDisplayList.h"
15
#include "nsTArray.h"
16
#include "UnitTransforms.h"
17
18
namespace mozilla {
19
namespace layers {
20
21
WebRenderLayerScrollData::WebRenderLayerScrollData()
22
  : mDescendantCount(-1)
23
  , mTransformIsPerspective(false)
24
  , mEventRegionsOverride(EventRegionsOverride::NoOverride)
25
  , mScrollbarAnimationId(0)
26
  , mFixedPosScrollContainerId(FrameMetrics::NULL_SCROLL_ID)
27
0
{
28
0
}
29
30
WebRenderLayerScrollData::~WebRenderLayerScrollData()
31
0
{
32
0
}
33
34
void
35
WebRenderLayerScrollData::InitializeRoot(int32_t aDescendantCount)
36
0
{
37
0
  mDescendantCount = aDescendantCount;
38
0
}
39
40
void
41
WebRenderLayerScrollData::Initialize(WebRenderScrollData& aOwner,
42
                                     nsDisplayItem* aItem,
43
                                     int32_t aDescendantCount,
44
                                     const ActiveScrolledRoot* aStopAtAsr,
45
                                     const Maybe<gfx::Matrix4x4>& aAncestorTransform)
46
0
{
47
0
  MOZ_ASSERT(aDescendantCount >= 0); // Ensure value is valid
48
0
  MOZ_ASSERT(mDescendantCount == -1); // Don't allow re-setting an already set value
49
0
  mDescendantCount = aDescendantCount;
50
0
51
0
  MOZ_ASSERT(aItem);
52
0
  aItem->UpdateScrollData(&aOwner, this);
53
0
54
0
  const ActiveScrolledRoot* asr = aItem->GetActiveScrolledRoot();
55
0
  if (ActiveScrolledRoot::IsAncestor(asr, aStopAtAsr)) {
56
0
    // If the item's ASR is an ancestor of the stop-at ASR, then we don't need
57
0
    // any more metrics information because we'll end up duplicating what the
58
0
    // ancestor WebRenderLayerScrollData already has.
59
0
    asr = nullptr;
60
0
  }
61
0
62
0
  while (asr && asr != aStopAtAsr) {
63
0
    MOZ_ASSERT(aOwner.GetManager());
64
0
    FrameMetrics::ViewID scrollId = asr->GetViewId();
65
0
    if (Maybe<size_t> index = aOwner.HasMetadataFor(scrollId)) {
66
0
      mScrollIds.AppendElement(index.ref());
67
0
    } else {
68
0
      Maybe<ScrollMetadata> metadata = asr->mScrollableFrame->ComputeScrollMetadata(
69
0
          aOwner.GetManager(), aItem->ReferenceFrame(),
70
0
          ContainerLayerParameters(), nullptr);
71
0
      MOZ_ASSERT(metadata);
72
0
      MOZ_ASSERT(metadata->GetMetrics().GetScrollId() == scrollId);
73
0
      mScrollIds.AppendElement(aOwner.AddMetadata(metadata.ref()));
74
0
    }
75
0
    asr = asr->mParent;
76
0
  }
77
0
78
0
  // aAncestorTransform, if present, is the transform from an ancestor
79
0
  // nsDisplayTransform that was stored on the stacking context in order to
80
0
  // propagate it downwards in the tree. (i.e. |aItem| is a strict descendant of
81
0
  // the nsDisplayTranform which produced aAncestorTransform). We store this
82
0
  // separately from mTransform because in the case where we have multiple
83
0
  // scroll metadata on this layer item, the mAncestorTransform is associated
84
0
  // with the "topmost" scroll metadata, and the mTransform is associated with
85
0
  // the "bottommost" scroll metadata. The code in
86
0
  // WebRenderScrollDataWrapper::GetTransform() is responsible for combining
87
0
  // these transforms and exposing them appropriately. Also, we don't save the
88
0
  // ancestor transform for thumb layers, because those are a special case in
89
0
  // APZ; we need to keep the ancestor transform for the scrollable content that
90
0
  // the thumb scrolls, but not for the thumb itself, as it will result in
91
0
  // incorrect visual positioning of the thumb.
92
0
  if (aAncestorTransform && mScrollbarData.mScrollbarLayerType != ScrollbarLayerType::Thumb) {
93
0
    mAncestorTransform = *aAncestorTransform;
94
0
  }
95
0
}
96
97
int32_t
98
WebRenderLayerScrollData::GetDescendantCount() const
99
0
{
100
0
  MOZ_ASSERT(mDescendantCount >= 0); // check that it was set
101
0
  return mDescendantCount;
102
0
}
103
104
size_t
105
WebRenderLayerScrollData::GetScrollMetadataCount() const
106
0
{
107
0
  return mScrollIds.Length();
108
0
}
109
110
void
111
WebRenderLayerScrollData::AppendScrollMetadata(WebRenderScrollData& aOwner,
112
                                               const ScrollMetadata& aData)
113
0
{
114
0
  mScrollIds.AppendElement(aOwner.AddMetadata(aData));
115
0
}
116
117
const ScrollMetadata&
118
WebRenderLayerScrollData::GetScrollMetadata(const WebRenderScrollData& aOwner,
119
                                            size_t aIndex) const
120
0
{
121
0
  MOZ_ASSERT(aIndex < mScrollIds.Length());
122
0
  return aOwner.GetScrollMetadata(mScrollIds[aIndex]);
123
0
}
124
125
CSSTransformMatrix
126
WebRenderLayerScrollData::GetTransformTyped() const
127
0
{
128
0
  return ViewAs<CSSTransformMatrix>(GetTransform());
129
0
}
130
131
void
132
WebRenderLayerScrollData::Dump(const WebRenderScrollData& aOwner) const
133
0
{
134
0
  printf_stderr("LayerScrollData(%p) descendants %d\n", this, mDescendantCount);
135
0
  for (size_t i : mScrollIds) {
136
0
    printf_stderr("  metadata: %s\n", Stringify(aOwner.GetScrollMetadata(i)).c_str());
137
0
  }
138
0
  printf_stderr("  ancestor transform: %s\n", Stringify(mAncestorTransform).c_str());
139
0
  printf_stderr("  transform: %s perspective: %d visible: %s\n",
140
0
    Stringify(mTransform).c_str(), mTransformIsPerspective,
141
0
    Stringify(mVisibleRegion).c_str());
142
0
  printf_stderr("  event regions: %s override: 0x%x\n",
143
0
    Stringify(mEventRegions).c_str(), mEventRegionsOverride);
144
0
  if (mReferentId) {
145
0
    printf_stderr("  ref layers id: 0x%" PRIx64 "\n", uint64_t(*mReferentId));
146
0
  }
147
0
  printf_stderr("  scrollbar type: %d animation: %" PRIx64 "\n",
148
0
    (int)mScrollbarData.mScrollbarLayerType, mScrollbarAnimationId);
149
0
  printf_stderr("  fixed pos container: %" PRIu64 "\n",
150
0
    mFixedPosScrollContainerId);
151
0
}
152
153
WebRenderScrollData::WebRenderScrollData()
154
  : mManager(nullptr)
155
  , mIsFirstPaint(false)
156
  , mPaintSequenceNumber(0)
157
0
{
158
0
}
159
160
WebRenderScrollData::WebRenderScrollData(WebRenderLayerManager* aManager)
161
  : mManager(aManager)
162
  , mIsFirstPaint(false)
163
  , mPaintSequenceNumber(0)
164
0
{
165
0
}
166
167
WebRenderScrollData::~WebRenderScrollData()
168
0
{
169
0
}
170
171
WebRenderLayerManager*
172
WebRenderScrollData::GetManager() const
173
0
{
174
0
  return mManager;
175
0
}
176
177
size_t
178
WebRenderScrollData::AddMetadata(const ScrollMetadata& aMetadata)
179
0
{
180
0
  FrameMetrics::ViewID scrollId = aMetadata.GetMetrics().GetScrollId();
181
0
  auto insertResult = mScrollIdMap.insert(std::make_pair(scrollId, 0));
182
0
  if (insertResult.second) {
183
0
    // Insertion took place, therefore it's a scrollId we hadn't seen before
184
0
    insertResult.first->second = mScrollMetadatas.Length();
185
0
    mScrollMetadatas.AppendElement(aMetadata);
186
0
  } // else we didn't insert, because it already existed
187
0
  return insertResult.first->second;
188
0
}
189
190
size_t
191
WebRenderScrollData::AddLayerData(const WebRenderLayerScrollData& aData)
192
0
{
193
0
  mLayerScrollData.AppendElement(aData);
194
0
  return mLayerScrollData.Length() - 1;
195
0
}
196
197
size_t
198
WebRenderScrollData::GetLayerCount() const
199
0
{
200
0
  return mLayerScrollData.Length();
201
0
}
202
203
const WebRenderLayerScrollData*
204
WebRenderScrollData::GetLayerData(size_t aIndex) const
205
0
{
206
0
  if (aIndex >= mLayerScrollData.Length()) {
207
0
    return nullptr;
208
0
  }
209
0
  return &(mLayerScrollData.ElementAt(aIndex));
210
0
}
211
212
const ScrollMetadata&
213
WebRenderScrollData::GetScrollMetadata(size_t aIndex) const
214
0
{
215
0
  MOZ_ASSERT(aIndex < mScrollMetadatas.Length());
216
0
  return mScrollMetadatas[aIndex];
217
0
}
218
219
Maybe<size_t>
220
WebRenderScrollData::HasMetadataFor(const FrameMetrics::ViewID& aScrollId) const
221
0
{
222
0
  auto it = mScrollIdMap.find(aScrollId);
223
0
  return (it == mScrollIdMap.end() ? Nothing() : Some(it->second));
224
0
}
225
226
void
227
WebRenderScrollData::SetFocusTarget(const FocusTarget& aFocusTarget)
228
0
{
229
0
  mFocusTarget = aFocusTarget;
230
0
}
231
232
void
233
WebRenderScrollData::SetIsFirstPaint()
234
0
{
235
0
  mIsFirstPaint = true;
236
0
}
237
238
bool
239
WebRenderScrollData::IsFirstPaint() const
240
0
{
241
0
  return mIsFirstPaint;
242
0
}
243
244
void
245
WebRenderScrollData::SetPaintSequenceNumber(uint32_t aPaintSequenceNumber)
246
0
{
247
0
  mPaintSequenceNumber = aPaintSequenceNumber;
248
0
}
249
250
uint32_t
251
WebRenderScrollData::GetPaintSequenceNumber() const
252
0
{
253
0
  return mPaintSequenceNumber;
254
0
}
255
256
void
257
WebRenderScrollData::ApplyUpdates(const ScrollUpdatesMap& aUpdates,
258
                                  uint32_t aPaintSequenceNumber)
259
0
{
260
0
  for (const auto& update : aUpdates) {
261
0
    if (Maybe<size_t> index = HasMetadataFor(update.first)) {
262
0
      mScrollMetadatas[*index].GetMetrics().UpdatePendingScrollInfo(update.second);
263
0
    }
264
0
  }
265
0
  mPaintSequenceNumber = aPaintSequenceNumber;
266
0
}
267
268
void
269
WebRenderScrollData::Dump() const
270
0
{
271
0
  printf_stderr("WebRenderScrollData with %zu layers firstpaint: %d\n",
272
0
      mLayerScrollData.Length(), mIsFirstPaint);
273
0
  for (size_t i = 0; i < mLayerScrollData.Length(); i++) {
274
0
    mLayerScrollData.ElementAt(i).Dump(*this);
275
0
  }
276
0
}
277
278
bool
279
WebRenderScrollData::RepopulateMap()
280
0
{
281
0
  MOZ_ASSERT(mScrollIdMap.empty());
282
0
  for (size_t i = 0; i < mScrollMetadatas.Length(); i++) {
283
0
    FrameMetrics::ViewID scrollId = mScrollMetadatas[i].GetMetrics().GetScrollId();
284
0
    mScrollIdMap.emplace(scrollId, i);
285
0
  }
286
0
  return true;
287
0
}
288
289
} // namespace layers
290
} // namespace mozilla