Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/wr/StackingContextHelper.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/StackingContextHelper.h"
8
9
#include "UnitTransforms.h"
10
#include "nsDisplayList.h"
11
12
namespace mozilla {
13
namespace layers {
14
15
StackingContextHelper::StackingContextHelper()
16
  : mBuilder(nullptr)
17
  , mScale(1.0f, 1.0f)
18
  , mAffectsClipPositioning(false)
19
  , mIsPreserve3D(false)
20
  , mRasterizeLocally(false)
21
0
{
22
0
  // mOrigin remains at 0,0
23
0
}
24
25
StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParentSC,
26
                                             wr::DisplayListBuilder& aBuilder,
27
                                             const nsTArray<wr::WrFilterOp>& aFilters,
28
                                             const LayoutDeviceRect& aBounds,
29
                                             const gfx::Matrix4x4* aBoundTransform,
30
                                             const wr::WrAnimationProperty* aAnimation,
31
                                             const float* aOpacityPtr,
32
                                             const gfx::Matrix4x4* aTransformPtr,
33
                                             const gfx::Matrix4x4* aPerspectivePtr,
34
                                             const gfx::CompositionOp& aMixBlendMode,
35
                                             bool aBackfaceVisible,
36
                                             bool aIsPreserve3D,
37
                                             const Maybe<nsDisplayTransform*>& aDeferredTransformItem,
38
                                             const wr::WrClipId* aClipNodeId,
39
                                             bool aAnimated)
40
  : mBuilder(&aBuilder)
41
  , mScale(1.0f, 1.0f)
42
  , mDeferredTransformItem(aDeferredTransformItem)
43
  , mIsPreserve3D(aIsPreserve3D)
44
  , mRasterizeLocally(aAnimated || aParentSC.mRasterizeLocally)
45
0
{
46
0
  // Compute scale for fallback rendering. We don't try to guess a scale for 3d
47
0
  // transformed items
48
0
  gfx::Matrix transform2d;
49
0
  if (aBoundTransform && aBoundTransform->CanDraw2D(&transform2d)
50
0
      && !aPerspectivePtr
51
0
      && !aParentSC.mIsPreserve3D) {
52
0
    mInheritedTransform = transform2d * aParentSC.mInheritedTransform;
53
0
    mScale = mInheritedTransform.ScaleFactors(true);
54
0
    if (aAnimated) {
55
0
      mSnappingSurfaceTransform = gfx::Matrix::Scaling(mScale.width, mScale.height);
56
0
    } else {
57
0
      mSnappingSurfaceTransform = transform2d * aParentSC.mSnappingSurfaceTransform;
58
0
    }
59
0
  } else {
60
0
    mInheritedTransform = aParentSC.mInheritedTransform;
61
0
    mScale = aParentSC.mScale;
62
0
  }
63
0
64
0
  auto rasterSpace = mRasterizeLocally
65
0
    ? wr::RasterSpace::Local(std::max(mScale.width, mScale.height))
66
0
    : wr::RasterSpace::Screen();
67
0
68
0
  mReferenceFrameId = mBuilder->PushStackingContext(
69
0
          wr::ToLayoutRect(aBounds),
70
0
          aClipNodeId,
71
0
          aAnimation,
72
0
          aOpacityPtr,
73
0
          aTransformPtr,
74
0
          aIsPreserve3D ? wr::TransformStyle::Preserve3D : wr::TransformStyle::Flat,
75
0
          aPerspectivePtr,
76
0
          wr::ToMixBlendMode(aMixBlendMode),
77
0
          aFilters,
78
0
          aBackfaceVisible,
79
0
          rasterSpace);
80
0
81
0
  mAffectsClipPositioning = mReferenceFrameId.isSome() ||
82
0
      (aBounds.TopLeft() != LayoutDevicePoint());
83
0
}
84
85
StackingContextHelper::~StackingContextHelper()
86
0
{
87
0
  if (mBuilder) {
88
0
    mBuilder->PopStackingContext(mReferenceFrameId.isSome());
89
0
  }
90
0
}
91
92
const Maybe<nsDisplayTransform*>&
93
StackingContextHelper::GetDeferredTransformItem() const
94
0
{
95
0
  return mDeferredTransformItem;
96
0
}
97
98
} // namespace layers
99
} // namespace mozilla