Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/layers/LayerAttributes.h
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
#ifndef mozilla_gfx_layers_LayerAttributes_h
8
#define mozilla_gfx_layers_LayerAttributes_h
9
10
#include "mozilla/Maybe.h"
11
#include "mozilla/gfx/Types.h"
12
#include "mozilla/layers/LayersTypes.h"
13
14
namespace IPC {
15
template <typename T> struct ParamTraits;
16
} // namespace IPC
17
18
namespace mozilla {
19
namespace layers {
20
21
enum class ScrollbarLayerType : uint8_t { None, Thumb, Container };
22
23
/**
24
 *  It stores data for scroll thumb layer or container layers.
25
 */
26
struct ScrollbarData {
27
private:
28
29
  /**
30
   * This constructor is for Thumb layer type.
31
   */
32
  ScrollbarData(ScrollDirection aDirection,
33
                float aThumbRatio,
34
                CSSCoord aThumbStart,
35
                CSSCoord aThumbLength,
36
                bool aThumbIsAsyncDraggable,
37
                CSSCoord aScrollTrackStart,
38
                CSSCoord aScrollTrackLength,
39
                uint64_t aTargetViewId)
40
    : mDirection(Some(aDirection))
41
    , mScrollbarLayerType(ScrollbarLayerType::Thumb)
42
    , mThumbRatio(aThumbRatio)
43
    , mThumbStart(aThumbStart)
44
    , mThumbLength(aThumbLength)
45
    , mThumbIsAsyncDraggable(aThumbIsAsyncDraggable)
46
    , mScrollTrackStart(aScrollTrackStart)
47
    , mScrollTrackLength(aScrollTrackLength)
48
    , mTargetViewId(aTargetViewId)
49
0
  {}
50
51
  /**
52
   * This constructor is for Container layer type.
53
   */
54
  ScrollbarData(const Maybe<ScrollDirection>& aDirection,
55
                uint64_t aTargetViewId)
56
    : mDirection(aDirection)
57
    , mScrollbarLayerType(ScrollbarLayerType::Container)
58
    , mTargetViewId(aTargetViewId)
59
0
  {}
60
61
public:
62
0
  ScrollbarData() = default;
63
64
  static ScrollbarData CreateForThumb(ScrollDirection aDirection,
65
                                      float aThumbRatio,
66
                                      CSSCoord aThumbStart,
67
                                      CSSCoord aThumbLength,
68
                                      bool aThumbIsAsyncDraggable,
69
                                      CSSCoord aScrollTrackStart,
70
                                      CSSCoord aScrollTrackLength,
71
                                      uint64_t aTargetViewId)
72
0
  {
73
0
    return ScrollbarData(aDirection,
74
0
                         aThumbRatio,
75
0
                         aThumbStart,
76
0
                         aThumbLength,
77
0
                         aThumbIsAsyncDraggable,
78
0
                         aScrollTrackStart,
79
0
                         aScrollTrackLength,
80
0
                         aTargetViewId);
81
0
  }
82
83
  static ScrollbarData CreateForScrollbarContainer(const Maybe<ScrollDirection>& aDirection,
84
                                                   uint64_t aTargetViewId)
85
0
  {
86
0
    return ScrollbarData(aDirection,
87
0
                         aTargetViewId);
88
0
  }
89
90
  /**
91
   * The mDirection contains a direction if mScrollbarLayerType is Thumb
92
   * or Container, otherwise it's empty.
93
   */
94
  Maybe<ScrollDirection> mDirection;
95
96
  /**
97
   * Indicate what kind of layer this data is for. All possibilities are defined in
98
   * enum ScrollbarLayerType
99
   */
100
  ScrollbarLayerType mScrollbarLayerType = ScrollbarLayerType::None;
101
102
  /**
103
   * The scrollbar thumb ratio is the ratio of the thumb position (in the CSS
104
   * pixels of the scrollframe's parent's space) to the scroll position (in the
105
   * CSS pixels of the scrollframe's space).
106
   */
107
  float mThumbRatio = 0.0f;
108
109
  CSSCoord mThumbStart;
110
  CSSCoord mThumbLength;
111
112
  /**
113
   * Whether the scrollbar thumb can be dragged asynchronously.
114
   */
115
  bool mThumbIsAsyncDraggable = false;
116
117
  CSSCoord mScrollTrackStart;
118
  CSSCoord mScrollTrackLength;
119
  uint64_t mTargetViewId = FrameMetrics::NULL_SCROLL_ID;
120
121
0
  bool operator==(const ScrollbarData& aOther) const {
122
0
    return mDirection == aOther.mDirection &&
123
0
           mScrollbarLayerType == aOther.mScrollbarLayerType &&
124
0
           mThumbRatio == aOther.mThumbRatio &&
125
0
           mThumbStart == aOther.mThumbStart &&
126
0
           mThumbLength == aOther.mThumbLength &&
127
0
           mThumbIsAsyncDraggable == aOther.mThumbIsAsyncDraggable &&
128
0
           mScrollTrackStart == aOther.mScrollTrackStart &&
129
0
           mScrollTrackLength == aOther.mScrollTrackLength &&
130
0
           mTargetViewId == aOther.mTargetViewId;
131
0
  }
132
0
  bool operator!=(const ScrollbarData& aOther) const {
133
0
    return !(*this == aOther);
134
0
  }
135
136
0
  bool IsThumb() const {
137
0
    return mScrollbarLayerType == ScrollbarLayerType::Thumb;
138
0
  }
139
};
140
141
/**
142
 * Infrequently changing layer attributes that require no special
143
 * serialization work.
144
 */
145
class SimpleLayerAttributes final
146
{
147
  friend struct IPC::ParamTraits<mozilla::layers::SimpleLayerAttributes>;
148
public:
149
  SimpleLayerAttributes()
150
   : mTransformIsPerspective(false),
151
     mPostXScale(1.0f),
152
     mPostYScale(1.0f),
153
     mContentFlags(0),
154
     mOpacity(1.0f),
155
     mIsFixedPosition(false),
156
     mMixBlendMode(gfx::CompositionOp::OP_OVER),
157
     mForceIsolatedGroup(false)
158
0
  {
159
0
  }
160
161
  /**
162
   * Setters.
163
   * All set methods return true if values changed, false otherwise.
164
   */
165
166
0
  bool SetPostScale(float aXScale, float aYScale) {
167
0
    if (mPostXScale == aXScale && mPostYScale == aYScale) {
168
0
      return false;
169
0
    }
170
0
    mPostXScale = aXScale;
171
0
    mPostYScale = aYScale;
172
0
    return true;
173
0
  }
174
175
0
  bool SetContentFlags(uint32_t aFlags) {
176
0
    if (aFlags == mContentFlags) {
177
0
      return false;
178
0
    }
179
0
    mContentFlags = aFlags;
180
0
    return true;
181
0
  }
182
183
0
  bool SetOpacity(float aOpacity) {
184
0
    if (aOpacity == mOpacity) {
185
0
      return false;
186
0
    }
187
0
    mOpacity = aOpacity;
188
0
    return true;
189
0
  }
190
191
0
  bool SetIsFixedPosition(bool aFixedPosition) {
192
0
    if (mIsFixedPosition == aFixedPosition) {
193
0
      return false;
194
0
    }
195
0
    mIsFixedPosition = aFixedPosition;
196
0
    return true;
197
0
  }
198
199
0
  bool SetScrollbarData(const ScrollbarData& aScrollbarData) {
200
0
    if (mScrollbarData == aScrollbarData)
201
0
    {
202
0
      return false;
203
0
    }
204
0
    mScrollbarData = aScrollbarData;
205
0
    return true;
206
0
  }
207
208
0
  bool SetMixBlendMode(gfx::CompositionOp aMixBlendMode) {
209
0
    if (mMixBlendMode == aMixBlendMode) {
210
0
      return false;
211
0
    }
212
0
    mMixBlendMode = aMixBlendMode;
213
0
    return true;
214
0
  }
215
216
0
  bool SetForceIsolatedGroup(bool aForceIsolatedGroup) {
217
0
    if (mForceIsolatedGroup == aForceIsolatedGroup) {
218
0
      return false;
219
0
    }
220
0
    mForceIsolatedGroup = aForceIsolatedGroup;
221
0
    return true;
222
0
  }
223
224
0
  bool SetTransform(const gfx::Matrix4x4& aMatrix) {
225
0
    if (mTransform == aMatrix) {
226
0
      return false;
227
0
    }
228
0
    mTransform = aMatrix;
229
0
    return true;
230
0
  }
231
232
0
  bool SetTransformIsPerspective(bool aIsPerspective) {
233
0
    if (mTransformIsPerspective == aIsPerspective) {
234
0
      return false;
235
0
    }
236
0
    mTransformIsPerspective = aIsPerspective;
237
0
    return true;
238
0
  }
239
240
0
  bool SetScrolledClip(const Maybe<LayerClip>& aScrolledClip) {
241
0
    if (mScrolledClip == aScrolledClip) {
242
0
      return false;
243
0
    }
244
0
    mScrolledClip = aScrolledClip;
245
0
    return true;
246
0
  }
247
248
  bool SetFixedPositionData(FrameMetrics::ViewID aTargetViewId,
249
                            const LayerPoint& aAnchor,
250
                            int32_t aSides)
251
0
  {
252
0
    if (mFixedPositionData &&
253
0
        mFixedPositionData->mScrollId == aTargetViewId &&
254
0
        mFixedPositionData->mAnchor == aAnchor &&
255
0
        mFixedPositionData->mSides == aSides) {
256
0
      return false;
257
0
    }
258
0
    if (!mFixedPositionData) {
259
0
      mFixedPositionData.emplace();
260
0
    }
261
0
    mFixedPositionData->mScrollId = aTargetViewId;
262
0
    mFixedPositionData->mAnchor = aAnchor;
263
0
    mFixedPositionData->mSides = aSides;
264
0
    return true;
265
0
  }
266
267
  bool SetStickyPositionData(FrameMetrics::ViewID aScrollId,
268
                             LayerRectAbsolute aOuter, LayerRectAbsolute aInner)
269
0
  {
270
0
    if (mStickyPositionData &&
271
0
        mStickyPositionData->mOuter.IsEqualEdges(aOuter) &&
272
0
        mStickyPositionData->mInner.IsEqualEdges(aInner)) {
273
0
      return false;
274
0
    }
275
0
    if (!mStickyPositionData) {
276
0
      mStickyPositionData.emplace();
277
0
    }
278
0
    mStickyPositionData->mScrollId = aScrollId;
279
0
    mStickyPositionData->mOuter = aOuter;
280
0
    mStickyPositionData->mInner = aInner;
281
0
    return true;
282
0
  }
283
284
  /**
285
   * This returns true if scrolling info is equivalent for the purposes of
286
   * APZ hit testing.
287
   */
288
0
  bool HitTestingInfoIsEqual(const SimpleLayerAttributes& aOther) const {
289
0
    if (mScrollbarData != aOther.mScrollbarData) {
290
0
      return false;
291
0
    }
292
0
    if (GetFixedPositionScrollContainerId() != aOther.GetFixedPositionScrollContainerId()) {
293
0
      return false;
294
0
    }
295
0
    if (mTransform != aOther.mTransform) {
296
0
      return false;
297
0
    }
298
0
    return true;
299
0
  }
300
301
  /**
302
   * Getters.
303
   */
304
305
0
  float GetPostXScale() const {
306
0
    return mPostXScale;
307
0
  }
308
309
0
  float GetPostYScale() const {
310
0
    return mPostYScale;
311
0
  }
312
313
0
  uint32_t GetContentFlags() const {
314
0
    return mContentFlags;
315
0
  }
316
317
0
  float GetOpacity() const {
318
0
    return mOpacity;
319
0
  }
320
321
0
  bool IsFixedPosition() const {
322
0
    return mIsFixedPosition;
323
0
  }
324
325
0
  const ScrollbarData& GetScrollbarData() const {
326
0
    return mScrollbarData;
327
0
  }
328
329
0
  gfx::CompositionOp GetMixBlendMode() const {
330
0
    return mMixBlendMode;
331
0
  }
332
333
0
  bool GetForceIsolatedGroup() const {
334
0
    return mForceIsolatedGroup;
335
0
  }
336
337
0
  const gfx::Matrix4x4& GetTransform() const {
338
0
    return mTransform;
339
0
  }
340
341
0
  bool GetTransformIsPerspective() const {
342
0
    return mTransformIsPerspective;
343
0
  }
344
345
0
  const Maybe<LayerClip>& GetScrolledClip() const {
346
0
    return mScrolledClip;
347
0
  }
348
349
0
  FrameMetrics::ViewID GetFixedPositionScrollContainerId() const {
350
0
    return mFixedPositionData
351
0
           ? mFixedPositionData->mScrollId
352
0
           : FrameMetrics::NULL_SCROLL_ID;
353
0
  }
354
355
0
  LayerPoint GetFixedPositionAnchor() const {
356
0
    return mFixedPositionData ? mFixedPositionData->mAnchor : LayerPoint();
357
0
  }
358
359
0
  int32_t GetFixedPositionSides() const {
360
0
    return mFixedPositionData ? mFixedPositionData->mSides : eSideBitsNone;
361
0
  }
362
363
0
  bool IsStickyPosition() const {
364
0
    return !!mStickyPositionData;
365
0
  }
366
367
0
  FrameMetrics::ViewID GetStickyScrollContainerId() const {
368
0
    return mStickyPositionData->mScrollId;
369
0
  }
370
371
0
  const LayerRectAbsolute& GetStickyScrollRangeOuter() const {
372
0
    return mStickyPositionData->mOuter;
373
0
  }
374
375
0
  const LayerRectAbsolute& GetStickyScrollRangeInner() const {
376
0
    return mStickyPositionData->mInner;
377
0
  }
378
379
0
  bool operator ==(const SimpleLayerAttributes& aOther) const {
380
0
    return mTransform == aOther.mTransform &&
381
0
           mTransformIsPerspective == aOther.mTransformIsPerspective &&
382
0
           mScrolledClip == aOther.mScrolledClip &&
383
0
           mPostXScale == aOther.mPostXScale &&
384
0
           mPostYScale == aOther.mPostYScale &&
385
0
           mContentFlags == aOther.mContentFlags &&
386
0
           mOpacity == aOther.mOpacity &&
387
0
           mIsFixedPosition == aOther.mIsFixedPosition &&
388
0
           mScrollbarData == aOther.mScrollbarData &&
389
0
           mMixBlendMode == aOther.mMixBlendMode &&
390
0
           mForceIsolatedGroup == aOther.mForceIsolatedGroup;
391
0
  }
392
393
private:
394
  gfx::Matrix4x4 mTransform;
395
  bool mTransformIsPerspective;
396
  Maybe<LayerClip> mScrolledClip;
397
  float mPostXScale;
398
  float mPostYScale;
399
  uint32_t mContentFlags;
400
  float mOpacity;
401
  bool mIsFixedPosition;
402
  ScrollbarData mScrollbarData;
403
  gfx::CompositionOp mMixBlendMode;
404
  bool mForceIsolatedGroup;
405
406
  struct FixedPositionData {
407
    FrameMetrics::ViewID mScrollId;
408
    LayerPoint mAnchor;
409
    int32_t mSides;
410
  };
411
  Maybe<FixedPositionData> mFixedPositionData;
412
413
  struct StickyPositionData {
414
    FrameMetrics::ViewID mScrollId;
415
    LayerRectAbsolute mOuter;
416
    LayerRectAbsolute mInner;
417
  };
418
  Maybe<StickyPositionData> mStickyPositionData;
419
420
  /**
421
   * This class may only contain plain-old-data members that can be safely
422
   * copied over IPC. Make sure to add new members to operator ==.
423
   */
424
};
425
426
} // namespace layers
427
} // namespace mozilla
428
429
#endif // mozilla_gfx_layers_LayerAttributes_h