Skip to content

Commit a249c3e

Browse files
committed
Backed out changeset 1cb2802bb09b (bug 298281) for causing build bustage at nsCSSRenderingGradients.h CLOSED TREE
1 parent 78b9b11 commit a249c3e

File tree

6 files changed

+86
-196
lines changed

6 files changed

+86
-196
lines changed

layout/painting/nsCSSRenderingGradients.cpp

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,45 +1189,6 @@ bool nsCSSGradientRenderer::TryPaintTilesWithExtendMode(
11891189
return true;
11901190
}
11911191

1192-
class MOZ_STACK_CLASS WrColorStopInterpolator
1193-
: public ColorStopInterpolator<WrColorStopInterpolator> {
1194-
public:
1195-
WrColorStopInterpolator(
1196-
const nsTArray<ColorStop>& aStops,
1197-
const StyleColorInterpolationMethod& aStyleColorInterpolationMethod,
1198-
float aOpacity, nsTArray<wr::GradientStop>& aResult)
1199-
: ColorStopInterpolator(aStops, aStyleColorInterpolationMethod),
1200-
mResult(aResult),
1201-
mOpacity(aOpacity),
1202-
mOutputStop(0) {}
1203-
1204-
void CreateStops() {
1205-
mResult.SetLengthAndRetainStorage(0);
1206-
// we always emit at least two stops (start and end) for each input stop,
1207-
// which avoids ambiguity with incomplete oklch/lch/hsv/hsb color stops for
1208-
// the last stop pair, where the last color stop can't be interpreted on its
1209-
// own because it actually depends on the previous stop.
1210-
mResult.SetLength(mStops.Length() * 2 + kFullRangeExtraStops);
1211-
mOutputStop = 0;
1212-
ColorStopInterpolator::CreateStops();
1213-
mResult.SetLength(mOutputStop);
1214-
}
1215-
1216-
void CreateStop(float aPosition, DeviceColor aColor) {
1217-
if (mOutputStop < mResult.Capacity()) {
1218-
mResult[mOutputStop].color = wr::ToColorF(aColor);
1219-
mResult[mOutputStop].color.a *= mOpacity;
1220-
mResult[mOutputStop].offset = aPosition;
1221-
mOutputStop++;
1222-
}
1223-
}
1224-
1225-
private:
1226-
nsTArray<wr::GradientStop>& mResult;
1227-
float mOpacity;
1228-
uint32_t mOutputStop;
1229-
};
1230-
12311192
void nsCSSGradientRenderer::BuildWebRenderParameters(
12321193
float aOpacity, wr::ExtendMode& aMode, nsTArray<wr::GradientStop>& aStops,
12331194
LayoutDevicePoint& aLineStart, LayoutDevicePoint& aLineEnd,
@@ -1260,9 +1221,44 @@ void nsCSSGradientRenderer::BuildWebRenderParameters(
12601221
if (mStops.Length() >= 2 &&
12611222
(styleColorInterpolationMethod.space != StyleColorSpace::Srgb ||
12621223
gfxPlatform::GetCMSMode() == CMSMode::All)) {
1263-
WrColorStopInterpolator interpolator(mStops, styleColorInterpolationMethod,
1264-
aOpacity, aStops);
1265-
interpolator.CreateStops();
1224+
aStops.SetLengthAndRetainStorage(0);
1225+
// this could be made tunable, but at 1.0/128 the error is largely
1226+
// irrelevant, as WebRender re-encodes it to 128 pairs of stops.
1227+
//
1228+
// note that we don't attempt to place the positions of these stops
1229+
// precisely at intervals, we just add this many extra stops across the
1230+
// range where it is convenient.
1231+
const int fullRangeExtraStops = 128;
1232+
// we always emit at least two stops (start and end) for each input stop,
1233+
// which avoids ambiguity with incomplete oklch/lch/hsv/hsb color stops for
1234+
// the last stop pair, where the last color stop can't be interpreted on its
1235+
// own because it actually depends on the previous stop.
1236+
aStops.SetLength(mStops.Length() * 2 + fullRangeExtraStops);
1237+
uint32_t outputStop = 0;
1238+
for (uint32_t i = 0; i < mStops.Length() - 1; i++) {
1239+
auto& start = mStops[i];
1240+
auto& end = i + 1 < mStops.Length() ? mStops[i + 1] : mStops[i];
1241+
StyleAbsoluteColor startColor = start.mColor;
1242+
StyleAbsoluteColor endColor = end.mColor;
1243+
int extraStops = (int)(floor(end.mPosition * fullRangeExtraStops) -
1244+
floor(start.mPosition * fullRangeExtraStops));
1245+
extraStops = clamped(extraStops, 1, fullRangeExtraStops);
1246+
float step = 1.0f / (float)extraStops;
1247+
for (int extraStop = 0;
1248+
extraStop <= extraStops && outputStop < aStops.Capacity();
1249+
extraStop++) {
1250+
auto lerp = (float)extraStop * step;
1251+
auto position =
1252+
start.mPosition + lerp * (end.mPosition - start.mPosition);
1253+
StyleAbsoluteColor color = Servo_InterpolateColor(
1254+
styleColorInterpolationMethod, &endColor, &startColor, lerp);
1255+
aStops[outputStop].color = wr::ToColorF(ToDeviceColor(color));
1256+
aStops[outputStop].color.a *= aOpacity;
1257+
aStops[outputStop].offset = (float)position;
1258+
outputStop++;
1259+
}
1260+
}
1261+
aStops.SetLength(outputStop);
12661262
} else {
12671263
aStops.SetLength(mStops.Length());
12681264
for (uint32_t i = 0; i < mStops.Length(); i++) {

layout/painting/nsCSSRenderingGradients.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,50 +38,6 @@ struct ColorStop {
3838
StyleAbsoluteColor mColor;
3939
};
4040

41-
template <class T>
42-
class MOZ_STACK_CLASS ColorStopInterpolator {
43-
public:
44-
ColorStopInterpolator(
45-
const nsTArray<ColorStop>& aStops,
46-
const StyleColorInterpolationMethod& aStyleColorInterpolationMethod)
47-
: mStyleColorInterpolationMethod(aStyleColorInterpolationMethod),
48-
mStops(aStops) {}
49-
50-
void CreateStops() {
51-
for (uint32_t i = 0; i < mStops.Length() - 1; i++) {
52-
const auto& start = mStops[i];
53-
const auto& end = mStops[i + 1];
54-
uint32_t extraStops =
55-
(uint32_t)(floor(end.mPosition * kFullRangeExtraStops) -
56-
floor(start.mPosition * kFullRangeExtraStops));
57-
extraStops = clamped(extraStops, 1U, kFullRangeExtraStops);
58-
float step = 1.0f / (float)extraStops;
59-
for (uint32_t extraStop = 0; extraStop <= extraStops; extraStop++) {
60-
auto progress = (float)extraStop * step;
61-
auto position =
62-
start.mPosition + progress * (end.mPosition - start.mPosition);
63-
StyleAbsoluteColor color =
64-
Servo_InterpolateColor(mStyleColorInterpolationMethod, &end.mColor,
65-
&start.mColor, progress);
66-
static_cast<T*>(this)->CreateStop(float(position),
67-
gfx::ToDeviceColor(color));
68-
}
69-
}
70-
}
71-
72-
protected:
73-
StyleColorInterpolationMethod mStyleColorInterpolationMethod;
74-
const nsTArray<ColorStop>& mStops;
75-
76-
// this could be made tunable, but at 1.0/128 the error is largely
77-
// irrelevant, as WebRender re-encodes it to 128 pairs of stops.
78-
//
79-
// note that we don't attempt to place the positions of these stops
80-
// precisely at intervals, we just add this many extra stops across the
81-
// range where it is convenient.
82-
inline static const uint32_t kFullRangeExtraStops = 128;
83-
};
84-
8541
class nsCSSGradientRenderer final {
8642
public:
8743
/**

layout/svg/SVGGradientFrame.cpp

Lines changed: 46 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "nsContentUtils.h"
2323
#include "SVGAnimatedTransformList.h"
2424

25+
// XXX Tight coupling with content classes ahead!
26+
2527
using namespace mozilla::dom;
2628
using namespace mozilla::dom::SVGGradientElement_Binding;
2729
using namespace mozilla::dom::SVGUnitTypes_Binding;
@@ -208,53 +210,21 @@ dom::SVGRadialGradientElement* SVGGradientFrame::GetRadialGradientWithLength(
208210
//----------------------------------------------------------------------
209211
// SVGPaintServerFrame methods:
210212

211-
// helpers
212-
213-
static ColorStop GetStopInformation(const nsIFrame* aStopFrame,
214-
float aGraphicOpacity,
215-
float& aLastPosition) {
213+
// helper
214+
static void GetStopInformation(nsIFrame* aStopFrame, float* aOffset,
215+
nscolor* aStopColor, float* aStopOpacity) {
216216
nsIContent* stopContent = aStopFrame->GetContent();
217217
MOZ_ASSERT(stopContent && stopContent->IsSVGElement(nsGkAtoms::stop));
218218

219-
float position;
220219
static_cast<SVGStopElement*>(stopContent)
221-
->GetAnimatedNumberValues(&position, nullptr);
222-
223-
position = clamped(position, 0.0f, 1.0f);
224-
225-
if (position < aLastPosition) {
226-
position = aLastPosition;
227-
} else {
228-
aLastPosition = position;
229-
}
230-
231-
const auto* svgReset = aStopFrame->StyleSVGReset();
220+
->GetAnimatedNumberValues(aOffset, nullptr);
232221

233-
sRGBColor stopColor =
234-
sRGBColor::FromABGR(svgReset->mStopColor.CalcColor(aStopFrame));
235-
stopColor.a *= svgReset->mStopOpacity * aGraphicOpacity;
236-
237-
return ColorStop(position, false,
238-
StyleAbsoluteColor::FromColor(stopColor.ToABGR()));
222+
const nsStyleSVGReset* styleSVGReset = aStopFrame->StyleSVGReset();
223+
*aOffset = mozilla::clamped(*aOffset, 0.0f, 1.0f);
224+
*aStopColor = styleSVGReset->mStopColor.CalcColor(aStopFrame);
225+
*aStopOpacity = styleSVGReset->mStopOpacity;
239226
}
240227

241-
class MOZ_STACK_CLASS SVGColorStopInterpolator
242-
: public ColorStopInterpolator<SVGColorStopInterpolator> {
243-
public:
244-
SVGColorStopInterpolator(
245-
gfxPattern* aGradient, const nsTArray<ColorStop>& aStops,
246-
const StyleColorInterpolationMethod& aStyleColorInterpolationMethod)
247-
: ColorStopInterpolator(aStops, aStyleColorInterpolationMethod),
248-
mGradient(aGradient) {}
249-
250-
void CreateStop(float aPosition, DeviceColor aColor) {
251-
mGradient->AddColorStop(aPosition, aColor);
252-
}
253-
254-
private:
255-
gfxPattern* mGradient;
256-
};
257-
258228
already_AddRefed<gfxPattern> SVGGradientFrame::GetPaintServerPattern(
259229
nsIFrame* aSource, const DrawTarget* aDrawTarget,
260230
const gfxMatrix& aContextMatrix, StyleSVGPaint nsStyleSVG::*aFillOrStroke,
@@ -270,21 +240,29 @@ already_AddRefed<gfxPattern> SVGGradientFrame::GetPaintServerPattern(
270240
mSource = aSource->IsTextFrame() ? aSource->GetParent() : aSource;
271241
}
272242

273-
AutoTArray<ColorStop, 8> stops;
274-
GetStops(&stops, aGraphicOpacity);
243+
AutoTArray<nsIFrame*, 8> stopFrames;
244+
GetStopFrames(&stopFrames);
275245

276-
uint32_t nStops = stops.Length();
246+
uint32_t nStops = stopFrames.Length();
277247

278248
// SVG specification says that no stops should be treated like
279249
// the corresponding fill or stroke had "none" specified.
280250
if (nStops == 0) {
251+
RefPtr<gfxPattern> pattern = new gfxPattern(DeviceColor());
281252
return do_AddRef(new gfxPattern(DeviceColor()));
282253
}
283254

284255
if (nStops == 1 || GradientVectorLengthIsZero()) {
256+
auto* lastStopFrame = stopFrames[nStops - 1];
257+
const auto* svgReset = lastStopFrame->StyleSVGReset();
285258
// The gradient paints a single colour, using the stop-color of the last
286259
// gradient step if there are more than one.
287-
return do_AddRef(new gfxPattern(ToDeviceColor(stops.LastElement().mColor)));
260+
float stopOpacity = svgReset->mStopOpacity;
261+
nscolor stopColor = svgReset->mStopColor.CalcColor(lastStopFrame);
262+
263+
sRGBColor stopColor2 = sRGBColor::FromABGR(stopColor);
264+
stopColor2.a *= stopOpacity * aGraphicOpacity;
265+
return do_AddRef(new gfxPattern(ToDeviceColor(stopColor2)));
288266
}
289267

290268
// Get the transform list (if there is one). We do this after the returns
@@ -323,16 +301,23 @@ already_AddRefed<gfxPattern> SVGGradientFrame::GetPaintServerPattern(
323301

324302
gradient->SetMatrix(patternMatrix);
325303

326-
if (StyleSVG()->mColorInterpolation == StyleColorInterpolation::Linearrgb) {
327-
static constexpr auto interpolationMethod = StyleColorInterpolationMethod{
328-
StyleColorSpace::SrgbLinear, StyleHueInterpolationMethod::Shorter};
329-
SVGColorStopInterpolator interpolator(gradient, stops, interpolationMethod);
330-
interpolator.CreateStops();
331-
} else {
332-
// setup standard sRGB stops
333-
for (const auto& stop : stops) {
334-
gradient->AddColorStop(stop.mPosition, ToDeviceColor(stop.mColor));
335-
}
304+
// setup stops
305+
float lastOffset = 0.0f;
306+
307+
for (uint32_t i = 0; i < nStops; i++) {
308+
float offset, stopOpacity;
309+
nscolor stopColor;
310+
311+
GetStopInformation(stopFrames[i], &offset, &stopColor, &stopOpacity);
312+
313+
if (offset < lastOffset)
314+
offset = lastOffset;
315+
else
316+
lastOffset = offset;
317+
318+
sRGBColor stopColor2 = sRGBColor::FromABGR(stopColor);
319+
stopColor2.a *= stopOpacity * aGraphicOpacity;
320+
gradient->AddColorStop(offset, ToDeviceColor(stopColor2));
336321
}
337322

338323
return gradient.forget();
@@ -366,16 +351,15 @@ SVGGradientFrame* SVGGradientFrame::GetReferencedGradient() {
366351
return do_QueryFrame(SVGObserverUtils::GetAndObserveTemplate(this, GetHref));
367352
}
368353

369-
void SVGGradientFrame::GetStops(nsTArray<ColorStop>* aStops,
370-
float aGraphicOpacity) {
371-
float lastPosition = 0.0f;
372-
for (const auto* stopFrame : mFrames) {
354+
void SVGGradientFrame::GetStopFrames(nsTArray<nsIFrame*>* aStopFrames) {
355+
nsIFrame* stopFrame = nullptr;
356+
for (stopFrame = mFrames.FirstChild(); stopFrame;
357+
stopFrame = stopFrame->GetNextSibling()) {
373358
if (stopFrame->IsSVGStopFrame()) {
374-
aStops->AppendElement(
375-
GetStopInformation(stopFrame, aGraphicOpacity, lastPosition));
359+
aStopFrames->AppendElement(stopFrame);
376360
}
377361
}
378-
if (aStops->Length() > 0) {
362+
if (aStopFrames->Length() > 0) {
379363
return;
380364
}
381365

@@ -393,7 +377,7 @@ void SVGGradientFrame::GetStops(nsTArray<ColorStop>* aStops,
393377

394378
SVGGradientFrame* next = GetReferencedGradient();
395379
if (next) {
396-
next->GetStops(aStops, aGraphicOpacity);
380+
next->GetStopFrames(aStopFrames);
397381
}
398382
}
399383

layout/svg/SVGGradientFrame.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "gfxMatrix.h"
1313
#include "gfxRect.h"
1414
#include "nsCOMPtr.h"
15-
#include "nsCSSRenderingGradients.h"
1615
#include "nsIFrame.h"
1716
#include "nsLiteralString.h"
1817

@@ -73,7 +72,8 @@ class SVGGradientFrame : public SVGPaintServerFrame {
7372
*/
7473
SVGGradientFrame* GetReferencedGradient();
7574

76-
void GetStops(nsTArray<ColorStop>* aStops, float aGraphicOpacity);
75+
// Optionally get a stop frame (returns stop index/count)
76+
void GetStopFrames(nsTArray<nsIFrame*>* aStopFrames);
7777

7878
const SVGAnimatedTransformList* GetGradientTransformList(
7979
nsIContent* aDefault);

testing/web-platform/tests/svg/pservers/reftests/gradient-color-interpolation.svg

Lines changed: 0 additions & 22 deletions
This file was deleted.

testing/web-platform/tests/svg/pservers/reftests/reference/gradient-color-interpolation-ref.svg

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)