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
This commit is contained in:
Jonathan Kew
2024-12-13 10:41:06 +00:00
parent 84f0c71086
commit 62de1036d1
3 changed files with 22 additions and 25 deletions

View File

@@ -1015,9 +1015,9 @@ void nsCSSGradientRenderer::Paint(gfxContext& aContext, const nsRect& aDest,
GradientStopInterpolator(
const nsTArray<ColorStop>& aStops,
const StyleColorInterpolationMethod& aStyleColorInterpolationMethod,
bool aExtendLastStop, nsTArray<gfx::GradientStop>& aResult)
bool aExtend, nsTArray<gfx::GradientStop>& 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<gfx::GradientStop>& 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<ColorStop>& aStops,
const StyleColorInterpolationMethod& aStyleColorInterpolationMethod,
float aOpacity, nsTArray<wr::GradientStop>& aResult, bool aExtendLastStop)
: ColorStopInterpolator(aStops, aStyleColorInterpolationMethod,
aExtendLastStop),
float aOpacity, nsTArray<wr::GradientStop>& 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());

View File

@@ -45,20 +45,19 @@ class MOZ_STACK_CLASS ColorStopInterpolator {
ColorStopInterpolator(
const nsTArray<ColorStop>& 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.

View File

@@ -230,9 +230,8 @@ class MOZ_STACK_CLASS SVGColorStopInterpolator
SVGColorStopInterpolator(
gfxPattern* aGradient, const nsTArray<ColorStop>& 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<gfxPattern> 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();