From 62de1036d105dceb52ef2cf95406b5f8b803baae Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Fri, 13 Dec 2024 10:41:06 +0000 Subject: [PATCH] Bug 1936569 - Rename extendLastStop to just extend, as it applies to both ends of the gradient. r=gfx-reviewers,lsalzman No behavior change; this is just renaming the variable for clarity. Differential Revision: https://phabricator.services.mozilla.com/D231942 --- layout/painting/nsCSSRenderingGradients.cpp | 23 ++++++++++----------- layout/painting/nsCSSRenderingGradients.h | 17 +++++++-------- layout/svg/SVGGradientFrame.cpp | 7 +++---- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/layout/painting/nsCSSRenderingGradients.cpp b/layout/painting/nsCSSRenderingGradients.cpp index 68e778594d4c..80e190a31223 100644 --- a/layout/painting/nsCSSRenderingGradients.cpp +++ b/layout/painting/nsCSSRenderingGradients.cpp @@ -1015,9 +1015,9 @@ void nsCSSGradientRenderer::Paint(gfxContext& aContext, const nsRect& aDest, GradientStopInterpolator( const nsTArray& aStops, const StyleColorInterpolationMethod& aStyleColorInterpolationMethod, - bool aExtendLastStop, nsTArray& aResult) + bool aExtend, nsTArray& aResult) : ColorStopInterpolator(aStops, aStyleColorInterpolationMethod, - aExtendLastStop), + aExtend), mStops(aResult) {} void CreateStop(float aPosition, gfx::DeviceColor aColor) { mStops.AppendElement(gfx::GradientStop{aPosition, aColor}); @@ -1027,10 +1027,10 @@ void nsCSSGradientRenderer::Paint(gfxContext& aContext, const nsRect& aDest, nsTArray& mStops; }; - bool extendLastStop = !isRepeat && styleColorInterpolationMethod.hue == - StyleHueInterpolationMethod::Longer; + bool extend = !isRepeat && styleColorInterpolationMethod.hue == + StyleHueInterpolationMethod::Longer; GradientStopInterpolator interpolator(mStops, styleColorInterpolationMethod, - extendLastStop, rawStops); + extend, rawStops); interpolator.CreateStops(); } else { rawStops.SetLength(mStops.Length()); @@ -1226,9 +1226,8 @@ class MOZ_STACK_CLASS WrColorStopInterpolator WrColorStopInterpolator( const nsTArray& aStops, const StyleColorInterpolationMethod& aStyleColorInterpolationMethod, - float aOpacity, nsTArray& aResult, bool aExtendLastStop) - : ColorStopInterpolator(aStops, aStyleColorInterpolationMethod, - aExtendLastStop), + float aOpacity, nsTArray& aResult, bool aExtend) + : ColorStopInterpolator(aStops, aStyleColorInterpolationMethod, aExtend), mResult(aResult), mOpacity(aOpacity), mOutputStop(0) {} @@ -1304,11 +1303,11 @@ void nsCSSGradientRenderer::BuildWebRenderParameters( // gradient, we have to pretend there is another stop at position=1.0 that // duplicates the last stop, this is probably only used for things like a // color wheel. No such problem for SVG as it doesn't have that complexity. - bool extendLastStop = aMode == wr::ExtendMode::Clamp && - styleColorInterpolationMethod.hue == - StyleHueInterpolationMethod::Longer; + bool extend = aMode == wr::ExtendMode::Clamp && + styleColorInterpolationMethod.hue == + StyleHueInterpolationMethod::Longer; WrColorStopInterpolator interpolator(mStops, styleColorInterpolationMethod, - aOpacity, aStops, extendLastStop); + aOpacity, aStops, extend); interpolator.CreateStops(); } else { aStops.SetLength(mStops.Length()); diff --git a/layout/painting/nsCSSRenderingGradients.h b/layout/painting/nsCSSRenderingGradients.h index 452371a32fb8..3131de22c6b3 100644 --- a/layout/painting/nsCSSRenderingGradients.h +++ b/layout/painting/nsCSSRenderingGradients.h @@ -45,20 +45,19 @@ class MOZ_STACK_CLASS ColorStopInterpolator { ColorStopInterpolator( const nsTArray& aStops, const StyleColorInterpolationMethod& aStyleColorInterpolationMethod, - bool aExtendLastStop) + bool aExtend) : mStyleColorInterpolationMethod(aStyleColorInterpolationMethod), mStops(aStops), - mExtendLastStop(aExtendLastStop) {} + mExtend(aExtend) {} void CreateStops() { // This loop intentionally iterates extra stops at the beginning and end // if extending was requested. - uint32_t iterStops = mStops.Length() - 1 + (mExtendLastStop ? 2 : 0); + uint32_t iterStops = mStops.Length() - 1 + (mExtend ? 2 : 0); for (uint32_t i = 0; i < iterStops; i++) { - auto thisindex = mExtendLastStop ? (i == 0 ? 0 : i - 1) : i; - auto nextindex = mExtendLastStop && (i == iterStops - 1 || i == 0) - ? thisindex - : thisindex + 1; + auto thisindex = mExtend ? (i == 0 ? 0 : i - 1) : i; + auto nextindex = + mExtend && (i == iterStops - 1 || i == 0) ? thisindex : thisindex + 1; const auto& start = mStops[thisindex]; const auto& end = mStops[nextindex]; float startPosition = start.mPosition; @@ -68,7 +67,7 @@ class MOZ_STACK_CLASS ColorStopInterpolator { // This is never the case on SVG gradients as they only use shorter hue. // // See https://bugzilla.mozilla.org/show_bug.cgi?id=1885716 for more info. - if (mExtendLastStop) { + if (mExtend) { if (i == 0) { startPosition = std::min(startPosition, 0.0f); } @@ -100,7 +99,7 @@ class MOZ_STACK_CLASS ColorStopInterpolator { // This indicates that we want to extend the endPosition on the last stop, // which only matters if this is a CSS non-repeating gradient with // StyleHueInterpolationMethod::Longer (only valid for hsl/hwb/lch/oklch). - bool mExtendLastStop; + bool mExtend; // This could be made tunable, but at 1.0/128 the error is largely // irrelevant, as WebRender re-encodes it to 128 pairs of stops. diff --git a/layout/svg/SVGGradientFrame.cpp b/layout/svg/SVGGradientFrame.cpp index ea48c9ac3660..865e113003ac 100644 --- a/layout/svg/SVGGradientFrame.cpp +++ b/layout/svg/SVGGradientFrame.cpp @@ -230,9 +230,8 @@ class MOZ_STACK_CLASS SVGColorStopInterpolator SVGColorStopInterpolator( gfxPattern* aGradient, const nsTArray& aStops, const StyleColorInterpolationMethod& aStyleColorInterpolationMethod, - bool aExtendLastStop) - : ColorStopInterpolator(aStops, aStyleColorInterpolationMethod, - aExtendLastStop), + bool aExtend) + : ColorStopInterpolator(aStops, aStyleColorInterpolationMethod, aExtend), mGradient(aGradient) {} void CreateStop(float aPosition, DeviceColor aColor) { @@ -245,7 +244,7 @@ class MOZ_STACK_CLASS SVGColorStopInterpolator already_AddRefed SVGGradientFrame::GetPaintServerPattern( nsIFrame* aSource, const DrawTarget* aDrawTarget, - const gfxMatrix& aContextMatrix, StyleSVGPaint nsStyleSVG::*aFillOrStroke, + const gfxMatrix& aContextMatrix, StyleSVGPaint nsStyleSVG::* aFillOrStroke, float aGraphicOpacity, imgDrawingParams& aImgParams, const gfxRect* aOverrideBounds) { uint16_t gradientUnits = GetGradientUnits();