Commit 875be605 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

SplashClip: we don't need to keep the paths around

Since we never used them for anything ^_^

Saves yet another 40% in file from issue #1126
parent 849e4bbb
Pipeline #389833 passed with stages
in 8 minutes and 54 seconds
......@@ -2367,7 +2367,7 @@ SplashError Splash::fillWithPattern(SplashPath *path, bool eo, SplashPattern *pa
yMinI = yMinI * splashAASize;
yMaxI = (yMaxI + 1) * splashAASize - 1;
}
SplashXPathScanner scanner(&xPath, eo, yMinI, yMaxI);
SplashXPathScanner scanner(xPath, eo, yMinI, yMaxI);
// get the min and max x and y values
if (vectorAntialias && !inShading) {
......@@ -2518,7 +2518,7 @@ SplashError Splash::xorFill(SplashPath *path, bool eo)
}
SplashXPath xPath(path, state->matrix, state->flatness, true);
xPath.sort();
SplashXPathScanner scanner(&xPath, eo, state->clip->getYMinI(), state->clip->getYMaxI());
SplashXPathScanner scanner(xPath, eo, state->clip->getYMinI(), state->clip->getYMaxI());
// get the min and max x and y values
scanner.getBBox(&xMinI, &yMinI, &xMaxI, &yMaxI);
......@@ -6118,7 +6118,7 @@ SplashError Splash::shadedFill(SplashPath *path, bool hasBBox, SplashPattern *pa
yMinI = yMinI * splashAASize;
yMaxI = (yMaxI + 1) * splashAASize - 1;
}
SplashXPathScanner scanner(&xPath, false, yMinI, yMaxI);
SplashXPathScanner scanner(xPath, false, yMinI, yMaxI);
// get the min and max x and y values
if (vectorAntialias) {
......
......@@ -64,7 +64,6 @@ SplashClip::SplashClip(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoo
yMinI = splashFloor(yMin);
xMaxI = splashCeil(xMax) - 1;
yMaxI = splashCeil(yMax) - 1;
paths = nullptr;
flags = nullptr;
length = size = 0;
}
......@@ -84,23 +83,15 @@ SplashClip::SplashClip(const SplashClip *clip)
yMaxI = clip->yMaxI;
length = clip->length;
size = clip->size;
paths = (SplashXPath **)gmallocn(size, sizeof(SplashXPath *));
flags = (unsigned char *)gmallocn(size, sizeof(unsigned char));
scanners = clip->scanners;
for (i = 0; i < length; ++i) {
paths[i] = clip->paths[i]->copy();
flags[i] = clip->flags[i];
}
}
SplashClip::~SplashClip()
{
int i;
for (i = 0; i < length; ++i) {
delete paths[i];
}
gfree(paths);
gfree(flags);
}
......@@ -113,21 +104,13 @@ void SplashClip::grow(int nPaths)
while (size < length + nPaths) {
size *= 2;
}
paths = (SplashXPath **)greallocn(paths, size, sizeof(SplashXPath *));
flags = (unsigned char *)greallocn(flags, size, sizeof(unsigned char));
}
}
void SplashClip::resetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1)
{
int i;
for (i = 0; i < length; ++i) {
delete paths[i];
}
gfree(paths);
gfree(flags);
paths = nullptr;
flags = nullptr;
scanners = {};
length = size = 0;
......@@ -197,37 +180,33 @@ SplashError SplashClip::clipToRect(SplashCoord x0, SplashCoord y0, SplashCoord x
SplashError SplashClip::clipToPath(SplashPath *path, SplashCoord *matrix, SplashCoord flatness, bool eo)
{
SplashXPath *xPath;
int yMinAA, yMaxAA;
xPath = new SplashXPath(path, matrix, flatness, true);
SplashXPath xPath(path, matrix, flatness, true);
// check for an empty path
if (xPath->length == 0) {
if (xPath.length == 0) {
xMax = xMin - 1;
yMax = yMin - 1;
xMaxI = splashCeil(xMax) - 1;
yMaxI = splashCeil(yMax) - 1;
delete xPath;
// check for a rectangle
} else if (xPath->length == 4
&& ((xPath->segs[0].x0 == xPath->segs[0].x1 && xPath->segs[0].x0 == xPath->segs[1].x0 && xPath->segs[0].x0 == xPath->segs[3].x1 && xPath->segs[2].x0 == xPath->segs[2].x1 && xPath->segs[2].x0 == xPath->segs[1].x1
&& xPath->segs[2].x0 == xPath->segs[3].x0 && xPath->segs[1].y0 == xPath->segs[1].y1 && xPath->segs[1].y0 == xPath->segs[0].y1 && xPath->segs[1].y0 == xPath->segs[2].y0 && xPath->segs[3].y0 == xPath->segs[3].y1
&& xPath->segs[3].y0 == xPath->segs[0].y0 && xPath->segs[3].y0 == xPath->segs[2].y1)
|| (xPath->segs[0].y0 == xPath->segs[0].y1 && xPath->segs[0].y0 == xPath->segs[1].y0 && xPath->segs[0].y0 == xPath->segs[3].y1 && xPath->segs[2].y0 == xPath->segs[2].y1 && xPath->segs[2].y0 == xPath->segs[1].y1
&& xPath->segs[2].y0 == xPath->segs[3].y0 && xPath->segs[1].x0 == xPath->segs[1].x1 && xPath->segs[1].x0 == xPath->segs[0].x1 && xPath->segs[1].x0 == xPath->segs[2].x0 && xPath->segs[3].x0 == xPath->segs[3].x1
&& xPath->segs[3].x0 == xPath->segs[0].x0 && xPath->segs[3].x0 == xPath->segs[2].x1))) {
clipToRect(xPath->segs[0].x0, xPath->segs[0].y0, xPath->segs[2].x0, xPath->segs[2].y0);
delete xPath;
} else if (xPath.length == 4
&& ((xPath.segs[0].x0 == xPath.segs[0].x1 && xPath.segs[0].x0 == xPath.segs[1].x0 && xPath.segs[0].x0 == xPath.segs[3].x1 && xPath.segs[2].x0 == xPath.segs[2].x1 && xPath.segs[2].x0 == xPath.segs[1].x1
&& xPath.segs[2].x0 == xPath.segs[3].x0 && xPath.segs[1].y0 == xPath.segs[1].y1 && xPath.segs[1].y0 == xPath.segs[0].y1 && xPath.segs[1].y0 == xPath.segs[2].y0 && xPath.segs[3].y0 == xPath.segs[3].y1
&& xPath.segs[3].y0 == xPath.segs[0].y0 && xPath.segs[3].y0 == xPath.segs[2].y1)
|| (xPath.segs[0].y0 == xPath.segs[0].y1 && xPath.segs[0].y0 == xPath.segs[1].y0 && xPath.segs[0].y0 == xPath.segs[3].y1 && xPath.segs[2].y0 == xPath.segs[2].y1 && xPath.segs[2].y0 == xPath.segs[1].y1
&& xPath.segs[2].y0 == xPath.segs[3].y0 && xPath.segs[1].x0 == xPath.segs[1].x1 && xPath.segs[1].x0 == xPath.segs[0].x1 && xPath.segs[1].x0 == xPath.segs[2].x0 && xPath.segs[3].x0 == xPath.segs[3].x1
&& xPath.segs[3].x0 == xPath.segs[0].x0 && xPath.segs[3].x0 == xPath.segs[2].x1))) {
clipToRect(xPath.segs[0].x0, xPath.segs[0].y0, xPath.segs[2].x0, xPath.segs[2].y0);
} else {
grow(1);
if (antialias) {
xPath->aaScale();
xPath.aaScale();
}
xPath->sort();
paths[length] = xPath;
xPath.sort();
flags[length] = eo ? splashClipEO : 0;
if (antialias) {
yMinAA = yMinI * splashAASize;
......
......@@ -123,7 +123,6 @@ protected:
bool antialias;
SplashCoord xMin, yMin, xMax, yMax;
int xMinI, yMinI, xMaxI, yMaxI;
SplashXPath **paths;
unsigned char *flags;
std::vector<std::shared_ptr<SplashXPathScanner>> scanners;
int length, size;
......
......@@ -242,14 +242,6 @@ void SplashXPath::strokeAdjust(SplashXPathAdjust *adjust, SplashCoord *xp, Splas
}
}
SplashXPath::SplashXPath(const SplashXPath *xPath)
{
length = xPath->length;
size = xPath->size;
segs = (SplashXPathSeg *)gmallocn(size, sizeof(SplashXPathSeg));
memcpy(segs, xPath->segs, length * sizeof(SplashXPathSeg));
}
SplashXPath::~SplashXPath()
{
gfree(segs);
......
......@@ -65,9 +65,6 @@ public:
// subpaths.
SplashXPath(SplashPath *path, SplashCoord *matrix, SplashCoord flatness, bool closeSubpaths, bool adjustLines = false, int linePosI = 0);
// Copy an expanded path.
SplashXPath *copy() const { return new SplashXPath(this); }
~SplashXPath();
SplashXPath(const SplashXPath &) = delete;
......@@ -81,7 +78,6 @@ public:
void sort();
protected:
SplashXPath(const SplashXPath *xPath);
void transform(SplashCoord *matrix, SplashCoord xi, SplashCoord yi, SplashCoord *xo, SplashCoord *yo);
void strokeAdjust(SplashXPathAdjust *adjust, SplashCoord *xp, SplashCoord *yp);
void grow(int nSegs);
......
......@@ -38,9 +38,9 @@
// SplashXPathScanner
//------------------------------------------------------------------------
SplashXPathScanner::SplashXPathScanner(const SplashXPath *xPath, bool eoA, int clipYMin, int clipYMax)
SplashXPathScanner::SplashXPathScanner(const SplashXPath &xPath, bool eoA, int clipYMin, int clipYMax)
{
SplashXPathSeg *seg;
const SplashXPathSeg *seg;
SplashCoord xMinFP, yMinFP, xMaxFP, yMaxFP;
int i;
......@@ -50,8 +50,8 @@ SplashXPathScanner::SplashXPathScanner(const SplashXPath *xPath, bool eoA, int c
// compute the bbox
xMin = yMin = 1;
xMax = yMax = 0;
if (xPath->length > 0) {
seg = &xPath->segs[0];
if (xPath.length > 0) {
seg = &xPath.segs[0];
if (unlikely(std::isnan(seg->x0) || std::isnan(seg->x1) || std::isnan(seg->y0) || std::isnan(seg->y1))) {
return;
}
......@@ -69,8 +69,8 @@ SplashXPathScanner::SplashXPathScanner(const SplashXPath *xPath, bool eoA, int c
yMinFP = seg->y0;
yMaxFP = seg->y1;
}
for (i = 1; i < xPath->length; ++i) {
seg = &xPath->segs[i];
for (i = 1; i < xPath.length; ++i) {
seg = &xPath.segs[i];
if (unlikely(std::isnan(seg->x0) || std::isnan(seg->x1) || std::isnan(seg->y0) || std::isnan(seg->y1))) {
return;
}
......@@ -224,9 +224,9 @@ SplashXPathScanIterator::SplashXPathScanIterator(const SplashXPathScanner &scann
}
}
void SplashXPathScanner::computeIntersections(const SplashXPath *xPath)
void SplashXPathScanner::computeIntersections(const SplashXPath &xPath)
{
SplashXPathSeg *seg;
const SplashXPathSeg *seg;
SplashCoord segXMin, segXMax, segYMin, segYMax, xx0, xx1;
int x, y, y0, y1, i;
......@@ -237,8 +237,8 @@ void SplashXPathScanner::computeIntersections(const SplashXPath *xPath)
// build the list of all intersections
allIntersections.resize(yMax - yMin + 1);
for (i = 0; i < xPath->length; ++i) {
seg = &xPath->segs[i];
for (i = 0; i < xPath.length; ++i) {
seg = &xPath.segs[i];
if (seg->flags & splashXPathFlip) {
segYMin = seg->y1;
segYMax = seg->y0;
......
......@@ -51,7 +51,7 @@ class SplashXPathScanner
{
public:
// Create a new SplashXPathScanner object. <xPathA> must be sorted.
SplashXPathScanner(const SplashXPath *xPath, bool eoA, int clipYMin, int clipYMax);
SplashXPathScanner(const SplashXPath &xPath, bool eoA, int clipYMin, int clipYMax);
~SplashXPathScanner();
......@@ -94,7 +94,7 @@ public:
void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y) const;
private:
void computeIntersections(const SplashXPath *xPath);
void computeIntersections(const SplashXPath &xPath);
bool addIntersection(double segYMin, double segYMax, int y, int x0, int x1, int count);
bool eo;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment