fune/gfx/layers/wr/StackingContextHelper.cpp
Kartikaya Gupta 2e785a4671 Bug 1462961 - Refactor to save a nsDisplayTransform* instead of just the transform matrix. r=jrmuizel
Instead of just storing the gfx::Matrix from the nsDisplayTransform on
the stacking context for scrolldata use, we now store a pointer to the
entire nsDisplayTransform item. We will need this in the next patch.
This patch should not have any functional changes.

MozReview-Commit-ID: 7qsZpL3Ka0X

--HG--
extra : rebase_source : b42957c83ef0591e72fa5b58ceb6650fda96e0b2
2018-05-23 16:08:18 -04:00

99 lines
3.7 KiB
C++

/* -*- 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
* 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/. */
#include "mozilla/layers/StackingContextHelper.h"
#include "UnitTransforms.h"
#include "nsDisplayList.h"
namespace mozilla {
namespace layers {
StackingContextHelper::StackingContextHelper()
: mBuilder(nullptr)
, mScale(1.0f, 1.0f)
, mAffectsClipPositioning(false)
, mIsPreserve3D(false)
, mRasterizeLocally(false)
{
// mOrigin remains at 0,0
}
StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParentSC,
wr::DisplayListBuilder& aBuilder,
const nsTArray<wr::WrFilterOp>& aFilters,
const LayoutDeviceRect& aBounds,
const gfx::Matrix4x4* aBoundTransform,
const wr::WrAnimationProperty* aAnimation,
const float* aOpacityPtr,
const gfx::Matrix4x4* aTransformPtr,
const gfx::Matrix4x4* aPerspectivePtr,
const gfx::CompositionOp& aMixBlendMode,
bool aBackfaceVisible,
bool aIsPreserve3D,
const Maybe<nsDisplayTransform*>& aDeferredTransformItem,
const wr::WrClipId* aClipNodeId,
bool aRasterizeLocally)
: mBuilder(&aBuilder)
, mScale(1.0f, 1.0f)
, mDeferredTransformItem(aDeferredTransformItem)
, mIsPreserve3D(aIsPreserve3D)
, mRasterizeLocally(aRasterizeLocally || aParentSC.mRasterizeLocally)
{
// Compute scale for fallback rendering. We don't try to guess a scale for 3d
// transformed items
gfx::Matrix transform2d;
if (aBoundTransform && aBoundTransform->CanDraw2D(&transform2d)
&& !aPerspectivePtr
&& !aParentSC.mIsPreserve3D) {
mInheritedTransform = transform2d * aParentSC.mInheritedTransform;
mScale = mInheritedTransform.ScaleFactors(true);
if (aAnimation) {
mSnappingSurfaceTransform = gfx::Matrix::Scaling(mScale.width, mScale.height);
} else {
mSnappingSurfaceTransform = transform2d * aParentSC.mSnappingSurfaceTransform;
}
} else {
mInheritedTransform = aParentSC.mInheritedTransform;
mScale = aParentSC.mScale;
}
auto rasterSpace = mRasterizeLocally
? wr::GlyphRasterSpace::Local(std::max(mScale.width, mScale.height))
: wr::GlyphRasterSpace::Screen();
mReferenceFrameId = mBuilder->PushStackingContext(
wr::ToLayoutRect(aBounds),
aClipNodeId,
aAnimation,
aOpacityPtr,
aTransformPtr,
aIsPreserve3D ? wr::TransformStyle::Preserve3D : wr::TransformStyle::Flat,
aPerspectivePtr,
wr::ToMixBlendMode(aMixBlendMode),
aFilters,
aBackfaceVisible,
rasterSpace);
mAffectsClipPositioning = mReferenceFrameId.isSome() ||
(aBounds.TopLeft() != LayoutDevicePoint());
}
StackingContextHelper::~StackingContextHelper()
{
if (mBuilder) {
mBuilder->PopStackingContext(mReferenceFrameId.isSome());
}
}
const Maybe<nsDisplayTransform*>&
StackingContextHelper::GetDeferredTransformItem() const
{
return mDeferredTransformItem;
}
} // namespace layers
} // namespace mozilla