Commit 239a5280 authored by Alexis Beingessner's avatar Alexis Beingessner
Browse files

Bug 1435094 - wire up GlyphRasterSpace to nsDisplayTransform. r=kats,mstange

When a transform thinks it's animated we should abandon screen rasterization
and instead favour local rasterization. This produces a more visually
pleasant rendering, as pixel-snapping "wobbles" the text between
frames.

The float scale of GlyphRasterSpace::Local is currently unused, but this
PR tries its best to set it to a reasonable value, based on discussion
with glennw about the intended semantics. We agreed it should specify
the scale *relative* to the parent stacking context, which means it's
just whatever scaling the stacking context's transform applies. It's
possible we'll need to clamp this value or make it properly 2-dimensional
later on.

Some book-keeping is added to StackingContextHelper to ensure that
GlyphRasterSpace::Screen is never requested by a descendent
of a stacking context using GlyphRasterSpace::Local.

nsDisplayMask is changed to use a StackingContextHelper to ensure
rasterSpace is properly propagated.

In addition, this is the first commit making use of cbindgen's new support
for bridging Rust enums natively into C++! This bumps our minimum cbindgen
to 6.0.0 (just released).

MozReview-Commit-ID: 9AlsB6nUheB

--HG--
extra : rebase_source : 247e5b197e998682cb4bb74f6f9319a9a4dd3264
parent 6dd00bfc
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -327,7 +327,9 @@ AsyncImagePipelineManager::ApplyAsyncImages()
                                nullptr,
                                pipeline->mMixBlendMode,
                                nsTArray<wr::WrFilterOp>(),
                                true);
                                true,
                                // This is fine to do unconditionally because we only push images here.
                                wr::GlyphRasterSpace::Screen());

    LayoutDeviceRect rect(0, 0, pipeline->mCurrentTexture->GetSize().width, pipeline->mCurrentTexture->GetSize().height);
    if (pipeline->mScaleToSize.isSome()) {
+12 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ StackingContextHelper::StackingContextHelper()
  , mScale(1.0f, 1.0f)
  , mAffectsClipPositioning(false)
  , mIsPreserve3D(false)
  , mRasterizeLocally(false)
{
  // mOrigin remains at 0,0
}
@@ -33,11 +34,14 @@ StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParen
                                             const gfx::CompositionOp& aMixBlendMode,
                                             bool aBackfaceVisible,
                                             bool aIsPreserve3D,
                                             const Maybe<gfx::Matrix4x4>& aTransformForScrollData)
                                             const Maybe<gfx::Matrix4x4>& aTransformForScrollData,
                                             const wr::WrClipId* aClipNodeId,
                                             bool aRasterizeLocally)
  : mBuilder(&aBuilder)
  , mScale(1.0f, 1.0f)
  , mTransformForScrollData(aTransformForScrollData)
  , mIsPreserve3D(aIsPreserve3D)
  , mRasterizeLocally(aRasterizeLocally || aParentSC.mRasterizeLocally)
{
  // Compute scale for fallback rendering. We don't try to guess a scale for 3d
  // transformed items
@@ -52,8 +56,12 @@ StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParen
    mScale = aParentSC.mScale;
  }

  auto rasterSpace = mRasterizeLocally
    ? wr::GlyphRasterSpace::Local(std::max(mScale.width, mScale.height))
    : wr::GlyphRasterSpace::Screen();

  mBuilder->PushStackingContext(wr::ToLayoutRect(aBounds),
                                nullptr,
                                aClipNodeId,
                                aAnimation,
                                aOpacityPtr,
                                aTransformPtr,
@@ -61,7 +69,8 @@ StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParen
                                aPerspectivePtr,
                                wr::ToMixBlendMode(aMixBlendMode),
                                aFilters,
                                aBackfaceVisible);
                                aBackfaceVisible,
                                rasterSpace);

  mAffectsClipPositioning =
      (aTransformPtr && !aTransformPtr->IsIdentity()) ||
+4 −1
Original line number Diff line number Diff line
@@ -39,7 +39,9 @@ public:
                        const gfx::CompositionOp& aMixBlendMode = gfx::CompositionOp::OP_OVER,
                        bool aBackfaceVisible = true,
                        bool aIsPreserve3D = false,
                        const Maybe<gfx::Matrix4x4>& aTransformForScrollData = Nothing());
                        const Maybe<gfx::Matrix4x4>& aTransformForScrollData = Nothing(),
                        const wr::WrClipId* aClipNodeId = nullptr,
                        bool aRasterizeLocally = false);
  // This version of the constructor should only be used at the root level
  // of the tree, so that we have a StackingContextHelper to pass down into
  // the RenderLayer traversal, but don't actually want it to push a stacking
@@ -68,6 +70,7 @@ private:
  bool mAffectsClipPositioning;
  Maybe<gfx::Matrix4x4> mTransformForScrollData;
  bool mIsPreserve3D;
  bool mRasterizeLocally;
};

} // namespace layers
+8 −4
Original line number Diff line number Diff line
@@ -774,7 +774,8 @@ DisplayListBuilder::PushStackingContext(const wr::LayoutRect& aBounds,
                                        const gfx::Matrix4x4* aPerspective,
                                        const wr::MixBlendMode& aMixBlendMode,
                                        const nsTArray<wr::WrFilterOp>& aFilters,
                                        bool aIsBackfaceVisible)
                                        bool aIsBackfaceVisible,
                                        const wr::GlyphRasterSpace& aRasterSpace)
{
  wr::LayoutTransform matrix;
  if (aTransform) {
@@ -785,13 +786,16 @@ DisplayListBuilder::PushStackingContext(const wr::LayoutRect& aBounds,
  if (aPerspective) {
    perspective = ToLayoutTransform(*aPerspective);
  }

  const wr::LayoutTransform* maybePerspective = aPerspective ? &perspective : nullptr;
  const size_t* maybeClipNodeId = aClipNodeId ? &aClipNodeId->id : nullptr;
  WRDL_LOG("PushStackingContext b=%s t=%s\n", mWrState, Stringify(aBounds).c_str(),
      aTransform ? Stringify(*aTransform).c_str() : "none");
  wr_dp_push_stacking_context(mWrState, aBounds, maybeClipNodeId, aAnimation, aOpacity,
                              maybeTransform, aTransformStyle, maybePerspective,
                              aMixBlendMode, aFilters.Elements(), aFilters.Length(), aIsBackfaceVisible);
  wr_dp_push_stacking_context(mWrState, aBounds, maybeClipNodeId, aAnimation,
                              aOpacity, maybeTransform, aTransformStyle,
                              maybePerspective, aMixBlendMode,
                              aFilters.Elements(), aFilters.Length(),
                              aIsBackfaceVisible, aRasterSpace);
}

void
+2 −1
Original line number Diff line number Diff line
@@ -266,7 +266,8 @@ public:
                           const gfx::Matrix4x4* aPerspective,
                           const wr::MixBlendMode& aMixBlendMode,
                           const nsTArray<wr::WrFilterOp>& aFilters,
                           bool aIsBackfaceVisible);
                           bool aIsBackfaceVisible,
                           const wr::GlyphRasterSpace& aRasterSpace);
  void PopStackingContext();

  wr::WrClipId DefineClip(const Maybe<wr::WrScrollId>& aAncestorScrollId,
Loading