From 5befcd43a92820da3f688bd3a6df411a3e13f332 Mon Sep 17 00:00:00 2001 From: reuk Date: Fri, 30 Aug 2024 13:39:03 +0100 Subject: [PATCH] EdgeTable: Use CopyableHeapBlock in implementation --- .../juce_graphics/geometry/juce_EdgeTable.cpp | 71 +++++++------------ .../juce_graphics/geometry/juce_EdgeTable.h | 10 +-- 2 files changed, 27 insertions(+), 54 deletions(-) diff --git a/modules/juce_graphics/geometry/juce_EdgeTable.cpp b/modules/juce_graphics/geometry/juce_EdgeTable.cpp index f1dd932f70..99a647f8b1 100644 --- a/modules/juce_graphics/geometry/juce_EdgeTable.cpp +++ b/modules/juce_graphics/geometry/juce_EdgeTable.cpp @@ -47,7 +47,7 @@ EdgeTable::EdgeTable (Rectangle 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 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 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 (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 newTable (getEdgeTableAllocationSize (newLineStrideElements, bounds.getHeight())); - copyEdgeTableData (newTable, + CopyableHeapBlock 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 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;) { diff --git a/modules/juce_graphics/geometry/juce_EdgeTable.h b/modules/juce_graphics/geometry/juce_EdgeTable.h index 1f4df7e18c..51dc4e77cc 100644 --- a/modules/juce_graphics/geometry/juce_EdgeTable.h +++ b/modules/juce_graphics/geometry/juce_EdgeTable.h @@ -72,12 +72,6 @@ public: /** Creates an edge table containing a rectangle list. */ explicit EdgeTable (const RectangleList& rectanglesToAdd); - /** Creates a copy of another edge table. */ - EdgeTable (const EdgeTable&); - - /** Copies from another edge table. */ - EdgeTable& operator= (const EdgeTable&); - //============================================================================== void clipToRectangle (Rectangle r); void excludeRectangle (Rectangle r); @@ -117,7 +111,7 @@ public: template 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 table; + CopyableHeapBlock table; Rectangle bounds; int maxEdgesPerLine, lineStrideElements; bool needToCheckEmptiness = true;