mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-22 01:34:21 +00:00
EdgeTable: Use CopyableHeapBlock in implementation
This commit is contained in:
parent
2733c60a99
commit
5befcd43a9
2 changed files with 27 additions and 54 deletions
|
|
@ -47,7 +47,7 @@ EdgeTable::EdgeTable (Rectangle<int> area, const Path& path, const AffineTransfo
|
|||
lineStrideElements (maxEdgesPerLine * 2 + 1)
|
||||
{
|
||||
allocate();
|
||||
int* t = table;
|
||||
int* t = table.data();
|
||||
|
||||
for (int i = bounds.getHeight(); --i >= 0;)
|
||||
{
|
||||
|
|
@ -125,7 +125,7 @@ EdgeTable::EdgeTable (Rectangle<int> rectangleToAdd)
|
|||
|
||||
auto x1 = scale * rectangleToAdd.getX();
|
||||
auto x2 = scale * rectangleToAdd.getRight();
|
||||
int* t = table;
|
||||
int* t = table.data();
|
||||
|
||||
for (int i = rectangleToAdd.getHeight(); --i >= 0;)
|
||||
{
|
||||
|
|
@ -227,7 +227,7 @@ EdgeTable::EdgeTable (Rectangle<float> rectangleToAdd)
|
|||
}
|
||||
|
||||
int lineY = 0;
|
||||
int* t = table;
|
||||
int* t = table.data();
|
||||
|
||||
if ((y1 / scale) == (y2 / scale))
|
||||
{
|
||||
|
|
@ -291,27 +291,6 @@ static void copyEdgeTableData (int* dest,
|
|||
}
|
||||
}
|
||||
|
||||
EdgeTable::EdgeTable (const EdgeTable& other)
|
||||
{
|
||||
operator= (other);
|
||||
}
|
||||
|
||||
EdgeTable& EdgeTable::operator= (const EdgeTable& other)
|
||||
{
|
||||
bounds = other.bounds;
|
||||
maxEdgesPerLine = other.maxEdgesPerLine;
|
||||
lineStrideElements = other.lineStrideElements;
|
||||
needToCheckEmptiness = other.needToCheckEmptiness;
|
||||
|
||||
allocate();
|
||||
copyEdgeTableData (table,
|
||||
(size_t) lineStrideElements,
|
||||
other.table,
|
||||
(size_t) lineStrideElements,
|
||||
(size_t) bounds.getHeight());
|
||||
return *this;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
static size_t getEdgeTableAllocationSize (int lineStride, int height) noexcept
|
||||
{
|
||||
|
|
@ -321,12 +300,12 @@ static size_t getEdgeTableAllocationSize (int lineStride, int height) noexcept
|
|||
|
||||
void EdgeTable::allocate()
|
||||
{
|
||||
table.malloc (getEdgeTableAllocationSize (lineStrideElements, bounds.getHeight()));
|
||||
table = CopyableHeapBlock<int> (getEdgeTableAllocationSize (lineStrideElements, bounds.getHeight()));
|
||||
}
|
||||
|
||||
void EdgeTable::clearLineSizes() noexcept
|
||||
{
|
||||
int* t = table;
|
||||
int* t = table.data();
|
||||
|
||||
for (int i = bounds.getHeight(); --i >= 0;)
|
||||
{
|
||||
|
|
@ -338,7 +317,7 @@ void EdgeTable::clearLineSizes() noexcept
|
|||
void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) noexcept
|
||||
{
|
||||
// Convert the table from relative windings to absolute levels..
|
||||
int* lineStart = table;
|
||||
int* lineStart = table.data();
|
||||
|
||||
for (int y = bounds.getHeight(); --y >= 0;)
|
||||
{
|
||||
|
|
@ -409,14 +388,14 @@ void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine)
|
|||
jassert (bounds.getHeight() > 0);
|
||||
auto newLineStrideElements = maxEdgesPerLine * 2 + 1;
|
||||
|
||||
HeapBlock<int> newTable (getEdgeTableAllocationSize (newLineStrideElements, bounds.getHeight()));
|
||||
copyEdgeTableData (newTable,
|
||||
CopyableHeapBlock<int> newTable (getEdgeTableAllocationSize (newLineStrideElements, bounds.getHeight()));
|
||||
copyEdgeTableData (newTable.data(),
|
||||
(size_t) newLineStrideElements,
|
||||
table,
|
||||
table.data(),
|
||||
(size_t) lineStrideElements,
|
||||
(size_t) bounds.getHeight());
|
||||
|
||||
table.swapWith (newTable);
|
||||
table = std::move (newTable);
|
||||
lineStrideElements = newLineStrideElements;
|
||||
}
|
||||
}
|
||||
|
|
@ -441,13 +420,13 @@ void EdgeTable::addEdgePoint (const int x, const int y, const int winding)
|
|||
{
|
||||
jassert (y >= 0 && y < bounds.getHeight());
|
||||
|
||||
auto* line = table + lineStrideElements * y;
|
||||
auto* line = table.data() + lineStrideElements * y;
|
||||
auto numPoints = line[0];
|
||||
|
||||
if (numPoints >= maxEdgesPerLine)
|
||||
{
|
||||
remapWithExtraSpace (numPoints);
|
||||
line = table + lineStrideElements * y;
|
||||
line = table.data() + lineStrideElements * y;
|
||||
}
|
||||
|
||||
line[0] = numPoints + 1;
|
||||
|
|
@ -460,13 +439,13 @@ void EdgeTable::addEdgePointPair (int x1, int x2, int y, int winding)
|
|||
{
|
||||
jassert (y >= 0 && y < bounds.getHeight());
|
||||
|
||||
auto* line = table + lineStrideElements * y;
|
||||
auto* line = table.data() + lineStrideElements * y;
|
||||
auto numPoints = line[0];
|
||||
|
||||
if (numPoints + 1 >= maxEdgesPerLine)
|
||||
{
|
||||
remapWithExtraSpace (numPoints + 1);
|
||||
line = table + lineStrideElements * y;
|
||||
line = table.data() + lineStrideElements * y;
|
||||
}
|
||||
|
||||
line[0] = numPoints + 2;
|
||||
|
|
@ -481,7 +460,7 @@ void EdgeTable::translate (float dx, int dy) noexcept
|
|||
{
|
||||
bounds.translate ((int) std::floor (dx), dy);
|
||||
|
||||
int* lineStart = table;
|
||||
int* lineStart = table.data();
|
||||
auto intDx = (int) (dx * 256.0f);
|
||||
|
||||
for (int i = bounds.getHeight(); --i >= 0;)
|
||||
|
|
@ -500,7 +479,7 @@ void EdgeTable::translate (float dx, int dy) noexcept
|
|||
|
||||
void EdgeTable::multiplyLevels (float amount)
|
||||
{
|
||||
int* lineStart = table;
|
||||
int* lineStart = table.data();
|
||||
auto multiplier = (int) (amount * 256.0f);
|
||||
|
||||
for (int y = 0; y < bounds.getHeight(); ++y)
|
||||
|
|
@ -521,7 +500,7 @@ void EdgeTable::intersectWithEdgeTableLine (const int y, const int* const otherL
|
|||
{
|
||||
jassert (y >= 0 && y < bounds.getHeight());
|
||||
|
||||
auto* srcLine = table + lineStrideElements * y;
|
||||
auto* srcLine = table.data() + lineStrideElements * y;
|
||||
const auto srcNum1 = *srcLine;
|
||||
|
||||
if (srcNum1 == 0)
|
||||
|
|
@ -614,15 +593,15 @@ void EdgeTable::intersectWithEdgeTableLine (const int y, const int* const otherL
|
|||
std::copy (srcLine1.begin(), srcLine1.end(), stackBuffer);
|
||||
|
||||
remapTableForNumEdges (jmax (256, destTotal * 2));
|
||||
srcLine = table + lineStrideElements * y;
|
||||
srcLine = table.data() + lineStrideElements * y;
|
||||
|
||||
reseat (srcLine1, table + lineStrideElements * bounds.getHeight());
|
||||
reseat (srcLine1, table.data() + lineStrideElements * bounds.getHeight());
|
||||
std::copy (stackBuffer, stackBuffer + srcLine1.size(), srcLine1.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
remapTableForNumEdges (jmax (256, destTotal * 2));
|
||||
srcLine = table + lineStrideElements * y;
|
||||
srcLine = table.data() + lineStrideElements * y;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -632,7 +611,7 @@ void EdgeTable::intersectWithEdgeTableLine (const int y, const int* const otherL
|
|||
if (! isUsingTempSpace)
|
||||
{
|
||||
isUsingTempSpace = true;
|
||||
auto* temp = table + lineStrideElements * bounds.getHeight();
|
||||
auto* temp = table.data() + lineStrideElements * bounds.getHeight();
|
||||
std::copy (srcLine1.begin(), srcLine1.end(), temp);
|
||||
reseat (srcLine1, temp);
|
||||
}
|
||||
|
|
@ -648,7 +627,7 @@ void EdgeTable::intersectWithEdgeTableLine (const int y, const int* const otherL
|
|||
{
|
||||
srcLine[0] = destTotal;
|
||||
remapTableForNumEdges (jmax (256, destTotal * 2));
|
||||
srcLine = table + lineStrideElements * y;
|
||||
srcLine = table.data() + lineStrideElements * y;
|
||||
}
|
||||
|
||||
++destTotal;
|
||||
|
|
@ -724,7 +703,7 @@ void EdgeTable::clipToRectangle (Rectangle<int> r)
|
|||
{
|
||||
auto x1 = scale * clipped.getX();
|
||||
auto x2 = scale * jmin (bounds.getRight(), clipped.getRight());
|
||||
int* line = table + lineStrideElements * top;
|
||||
int* line = table.data() + lineStrideElements * top;
|
||||
|
||||
for (int i = bottom - top; --i >= 0;)
|
||||
{
|
||||
|
|
@ -783,7 +762,7 @@ void EdgeTable::clipToEdgeTable (const EdgeTable& other)
|
|||
for (int i = 0; i < top; ++i)
|
||||
table[(size_t) lineStrideElements * (size_t) i] = 0;
|
||||
|
||||
auto* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
|
||||
auto* otherLine = other.table.data() + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
|
||||
|
||||
for (int i = top; i < bottom; ++i)
|
||||
{
|
||||
|
|
@ -844,7 +823,7 @@ bool EdgeTable::isEmpty() noexcept
|
|||
if (needToCheckEmptiness)
|
||||
{
|
||||
needToCheckEmptiness = false;
|
||||
int* t = table;
|
||||
int* t = table.data();
|
||||
|
||||
for (int i = bounds.getHeight(); --i >= 0;)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -72,12 +72,6 @@ public:
|
|||
/** Creates an edge table containing a rectangle list. */
|
||||
explicit EdgeTable (const RectangleList<float>& rectanglesToAdd);
|
||||
|
||||
/** Creates a copy of another edge table. */
|
||||
EdgeTable (const EdgeTable&);
|
||||
|
||||
/** Copies from another edge table. */
|
||||
EdgeTable& operator= (const EdgeTable&);
|
||||
|
||||
//==============================================================================
|
||||
void clipToRectangle (Rectangle<int> r);
|
||||
void excludeRectangle (Rectangle<int> r);
|
||||
|
|
@ -117,7 +111,7 @@ public:
|
|||
template <class EdgeTableIterationCallback>
|
||||
void iterate (EdgeTableIterationCallback& iterationCallback) const noexcept
|
||||
{
|
||||
const int* lineStart = table;
|
||||
const int* lineStart = table.data();
|
||||
|
||||
for (int y = 0; y < bounds.getHeight(); ++y)
|
||||
{
|
||||
|
|
@ -210,7 +204,7 @@ private:
|
|||
bool operator< (const LineItem& other) const noexcept { return x < other.x; }
|
||||
};
|
||||
|
||||
HeapBlock<int> table;
|
||||
CopyableHeapBlock<int> table;
|
||||
Rectangle<int> bounds;
|
||||
int maxEdgesPerLine, lineStrideElements;
|
||||
bool needToCheckEmptiness = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue