Browse Source

Added some heuristics to EdgeTable to try to improve the table size prediction

tags/2021-05-28
jules 8 years ago
parent
commit
24f023bb23
2 changed files with 9 additions and 5 deletions
  1. +7
    -3
      modules/juce_graphics/geometry/juce_EdgeTable.cpp
  2. +2
    -2
      modules/juce_graphics/geometry/juce_Path.h

+ 7
- 3
modules/juce_graphics/geometry/juce_EdgeTable.cpp View File

@@ -32,8 +32,12 @@ const int juce_edgeTableDefaultEdgesPerLine = 32;
//============================================================================== //==============================================================================
EdgeTable::EdgeTable (Rectangle<int> area, const Path& path, const AffineTransform& transform) EdgeTable::EdgeTable (Rectangle<int> area, const Path& path, const AffineTransform& transform)
: bounds (area), : bounds (area),
maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
lineStrideElements (juce_edgeTableDefaultEdgesPerLine * 2 + 1)
// this is a very vague heuristic to make a rough guess at a good table size
// for a given path, such that it's big enough to mostly avoid remapping, but also
// not so big that it's wasteful for simple paths.
maxEdgesPerLine (jmax (juce_edgeTableDefaultEdgesPerLine / 2,
4 * (int) std::sqrt (path.numElements))),
lineStrideElements (maxEdgesPerLine * 2 + 1)
{ {
allocate(); allocate();
int* t = table; int* t = table;
@@ -404,7 +408,7 @@ void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine)
inline void EdgeTable::remapWithExtraSpace (int numPoints) inline void EdgeTable::remapWithExtraSpace (int numPoints)
{ {
remapTableForNumEdges (numPoints + jmax (juce_edgeTableDefaultEdgesPerLine, numPoints / 2));
remapTableForNumEdges (numPoints * 2);
jassert (numPoints < maxEdgesPerLine); jassert (numPoints < maxEdgesPerLine);
} }


+ 2
- 2
modules/juce_graphics/geometry/juce_Path.h View File

@@ -781,9 +781,7 @@ public:
void loadPathFromData (const void* data, size_t numberOfBytes); void loadPathFromData (const void* data, size_t numberOfBytes);
/** Stores the path by writing it out to a stream. /** Stores the path by writing it out to a stream.
After writing out a path, you can reload it using loadPathFromStream(). After writing out a path, you can reload it using loadPathFromStream().
@see loadPathFromStream, loadPathFromData @see loadPathFromStream, loadPathFromData
*/ */
void writePathToStream (OutputStream& destination) const; void writePathToStream (OutputStream& destination) const;
@@ -803,6 +801,8 @@ private:
//============================================================================== //==============================================================================
friend class PathFlatteningIterator; friend class PathFlatteningIterator;
friend class Path::Iterator; friend class Path::Iterator;
friend class EdgeTable;
ArrayAllocationBase<float, DummyCriticalSection> data; ArrayAllocationBase<float, DummyCriticalSection> data;
size_t numElements = 0; size_t numElements = 0;


Loading…
Cancel
Save