Skip to content

Commit

Permalink
merge: updated to Marlin renderer 0.9.4.5 (fix Stroker and Filler pat…
Browse files Browse the repository at this point in the history
…h clipper to support huge coordinates up to 1E15)
  • Loading branch information
bourgesl committed Oct 30, 2021
1 parent fd97127 commit 7492844
Show file tree
Hide file tree
Showing 34 changed files with 3,839 additions and 489 deletions.
9 changes: 6 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>org.marlin</groupId>
<artifactId>marlinfx</artifactId>
<packaging>jar</packaging>
<version>0.9.3.1-Unsafe-OpenJDK9</version>
<version>0.9.4.5-Unsafe-OpenJFX11</version>
<name>Marlin software rasterizer</name>

<url>https://github.com/bourgesl/marlin-renderer</url>
Expand Down Expand Up @@ -67,8 +67,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<configuration>
<source>9</source>
<target>9</target>
<source>11</source>
<target>11</target>
<debug>true</debug>
<encoding>UTF-8</encoding>
<showDeprecation>true</showDeprecation>
Expand Down Expand Up @@ -111,6 +111,9 @@
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<includes>
<include>com/sun/**</include>
</includes>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;

import static com.sun.marlin.MarlinConst.DO_STATS;
import static com.sun.marlin.MarlinConst.DO_CHECKS;
import static com.sun.marlin.MarlinConst.DO_CLEAN_DIRTY;
import static com.sun.marlin.MarlinConst.DO_LOG_WIDEN_ARRAY;
import static com.sun.marlin.MarlinConst.DO_LOG_OVERSIZE;

import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;

Expand All @@ -38,27 +45,23 @@
import com.sun.marlin.ArrayCacheConst.CacheStats;

/*
* Note that the [BYTE/INT/FLOAT/DOUBLE]ArrayCache files are nearly identical except
* Note that the ArrayCache[BYTE/INT/FLOAT/DOUBLE] files are nearly identical except
* for a few type and name differences. Typically, the [BYTE]ArrayCache.java file
* is edited manually and then [INT/FLOAT/DOUBLE]ArrayCache.java
* files are generated with the following command lines:
*/
// % sed -e 's/(b\yte)[ ]*//g' -e 's/b\yte/int/g' -e 's/B\yte/Int/g' < B\yteArrayCache.java > IntArrayCache.java
// % sed -e 's/(b\yte)[ ]*0/0.0f/g' -e 's/(b\yte)[ ]*/(float) /g' -e 's/b\yte/float/g' -e 's/B\yte/Float/g' < B\yteArrayCache.java > FloatArrayCache.java
// % sed -e 's/(b\yte)[ ]*0/0.0d/g' -e 's/(b\yte)[ ]*/(double) /g' -e 's/b\yte/double/g' -e 's/B\yte/Double/g' < B\yteArrayCache.java > DoubleArrayCache.java

public final class ByteArrayCache implements MarlinConst {
final class ArrayCacheByte {

final boolean clean;
/* members */
private final int bucketCapacity;
private WeakReference<Bucket[]> refBuckets = null;
final CacheStats stats;

ByteArrayCache(final boolean clean, final int bucketCapacity) {
this.clean = clean;
ArrayCacheByte(final int bucketCapacity) {
this.bucketCapacity = bucketCapacity;
this.stats = (DO_STATS) ?
new CacheStats(getLogPrefix(clean) + "ByteArrayCache") : null;
new CacheStats("ArrayCacheByte(Dirty)") : null;
}

Bucket getCacheBucket(final int length) {
Expand All @@ -75,7 +78,7 @@ private Bucket[] getBuckets() {
buckets = new Bucket[BUCKETS];

for (int i = 0; i < BUCKETS; i++) {
buckets[i] = new Bucket(clean, ARRAY_SIZES[i], bucketCapacity,
buckets[i] = new Bucket(ARRAY_SIZES[i], bucketCapacity,
(DO_STATS) ? stats.bucketStats[i] : null);
}

Expand All @@ -93,12 +96,10 @@ static final class Reference {

// initial array reference (direct access)
final byte[] initial;
private final boolean clean;
private final ByteArrayCache cache;
private final ArrayCacheByte cache;

Reference(final ByteArrayCache cache, final int initialSize) {
Reference(final ArrayCacheByte cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
Expand All @@ -113,7 +114,7 @@ byte[] getArray(final int length) {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) {
logInfo(getLogPrefix(clean) + "ByteArrayCache: "
logInfo("ArrayCacheByte(Dirty): "
+ "getArray[oversize]: length=\t" + length);
}
return createArray(length);
Expand Down Expand Up @@ -141,14 +142,18 @@ byte[] widenArray(final byte[] array, final int usedSize,
putArray(array, 0, usedSize); // ensure array is cleared

if (DO_LOG_WIDEN_ARRAY) {
logInfo(getLogPrefix(clean) + "ByteArrayCache: "
logInfo("ArrayCacheByte(Dirty): "
+ "widenArray[" + res.length
+ "]: usedSize=\t" + usedSize + "\tlength=\t" + length
+ "\tneeded length=\t" + needSize);
}
return res;
}

boolean doCleanRef(final byte[] array) {
return DO_CLEAN_DIRTY || (array != initial);
}

byte[] putArray(final byte[] array)
{
// dirty array helper:
Expand All @@ -159,7 +164,7 @@ byte[] putArray(final byte[] array, final int fromIndex,
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
if (DO_CLEAN_DIRTY && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, (byte)0);
}
Expand All @@ -176,15 +181,13 @@ static final class Bucket {

private int tail = 0;
private final int arraySize;
private final boolean clean;
private final byte[][] arrays;
private final BucketStats stats;

Bucket(final boolean clean, final int arraySize,
Bucket(final int arraySize,
final int capacity, final BucketStats stats)
{
this.arraySize = arraySize;
this.clean = clean;
this.stats = stats;
this.arrays = new byte[capacity][];
}
Expand All @@ -208,7 +211,7 @@ byte[] getArray() {
void putArray(final byte[] array)
{
if (DO_CHECKS && (array.length != arraySize)) {
logInfo(getLogPrefix(clean) + "ByteArrayCache: "
logInfo("ArrayCacheByte(Dirty): "
+ "bad length = " + array.length);
return;
}
Expand All @@ -223,7 +226,7 @@ void putArray(final byte[] array)
stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "ByteArrayCache: "
logInfo("ArrayCacheByte(Dirty): "
+ "array capacity exceeded !");
}
}
Expand All @@ -243,8 +246,8 @@ static void fill(final byte[] array, final int fromIndex,
}
}

public static void check(final byte[] array, final int fromIndex,
final int toIndex, final byte value)
static void check(final byte[] array, final int fromIndex,
final int toIndex, final byte value)
{
if (DO_CHECKS) {
// check zero on full array:
Expand All @@ -262,8 +265,4 @@ public static void check(final byte[] array, final int fromIndex,
}
}
}

static String getLogPrefix(final boolean clean) {
return (clean) ? "Clean" : "Dirty";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;

import static com.sun.marlin.MarlinConst.DO_STATS;
import static com.sun.marlin.MarlinConst.DO_CHECKS;
import static com.sun.marlin.MarlinConst.DO_CLEAN_DIRTY;
import static com.sun.marlin.MarlinConst.DO_LOG_WIDEN_ARRAY;
import static com.sun.marlin.MarlinConst.DO_LOG_OVERSIZE;

import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;

Expand All @@ -38,27 +45,23 @@
import com.sun.marlin.ArrayCacheConst.CacheStats;

/*
* Note that the [BYTE/INT/FLOAT/DOUBLE]ArrayCache files are nearly identical except
* Note that the ArrayCache[BYTE/INT/FLOAT/DOUBLE] files are nearly identical except
* for a few type and name differences. Typically, the [BYTE]ArrayCache.java file
* is edited manually and then [INT/FLOAT/DOUBLE]ArrayCache.java
* files are generated with the following command lines:
*/
// % sed -e 's/(b\yte)[ ]*//g' -e 's/b\yte/int/g' -e 's/B\yte/Int/g' < B\yteArrayCache.java > IntArrayCache.java
// % sed -e 's/(b\yte)[ ]*0/0.0f/g' -e 's/(b\yte)[ ]*/(float) /g' -e 's/b\yte/float/g' -e 's/B\yte/Float/g' < B\yteArrayCache.java > FloatArrayCache.java
// % sed -e 's/(b\yte)[ ]*0/0.0d/g' -e 's/(b\yte)[ ]*/(double) /g' -e 's/b\yte/double/g' -e 's/B\yte/Double/g' < B\yteArrayCache.java > DoubleArrayCache.java

public final class DoubleArrayCache implements MarlinConst {
final class ArrayCacheDouble {

final boolean clean;
/* members */
private final int bucketCapacity;
private WeakReference<Bucket[]> refBuckets = null;
final CacheStats stats;

DoubleArrayCache(final boolean clean, final int bucketCapacity) {
this.clean = clean;
ArrayCacheDouble(final int bucketCapacity) {
this.bucketCapacity = bucketCapacity;
this.stats = (DO_STATS) ?
new CacheStats(getLogPrefix(clean) + "DoubleArrayCache") : null;
new CacheStats("ArrayCacheDouble(Dirty)") : null;
}

Bucket getCacheBucket(final int length) {
Expand All @@ -75,7 +78,7 @@ private Bucket[] getBuckets() {
buckets = new Bucket[BUCKETS];

for (int i = 0; i < BUCKETS; i++) {
buckets[i] = new Bucket(clean, ARRAY_SIZES[i], bucketCapacity,
buckets[i] = new Bucket(ARRAY_SIZES[i], bucketCapacity,
(DO_STATS) ? stats.bucketStats[i] : null);
}

Expand All @@ -93,12 +96,10 @@ static final class Reference {

// initial array reference (direct access)
final double[] initial;
private final boolean clean;
private final DoubleArrayCache cache;
private final ArrayCacheDouble cache;

Reference(final DoubleArrayCache cache, final int initialSize) {
Reference(final ArrayCacheDouble cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
Expand All @@ -113,7 +114,7 @@ static final class Reference {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) {
logInfo(getLogPrefix(clean) + "DoubleArrayCache: "
logInfo("ArrayCacheDouble(Dirty): "
+ "getArray[oversize]: length=\t" + length);
}
return createArray(length);
Expand Down Expand Up @@ -141,14 +142,18 @@ static final class Reference {
putArray(array, 0, usedSize); // ensure array is cleared

if (DO_LOG_WIDEN_ARRAY) {
logInfo(getLogPrefix(clean) + "DoubleArrayCache: "
logInfo("ArrayCacheDouble(Dirty): "
+ "widenArray[" + res.length
+ "]: usedSize=\t" + usedSize + "\tlength=\t" + length
+ "\tneeded length=\t" + needSize);
}
return res;
}

boolean doCleanRef(final double[] array) {
return DO_CLEAN_DIRTY || (array != initial);
}

double[] putArray(final double[] array)
{
// dirty array helper:
Expand All @@ -159,7 +164,7 @@ static final class Reference {
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
if (DO_CLEAN_DIRTY && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, 0.0d);
}
Expand All @@ -176,15 +181,13 @@ static final class Bucket {

private int tail = 0;
private final int arraySize;
private final boolean clean;
private final double[][] arrays;
private final BucketStats stats;

Bucket(final boolean clean, final int arraySize,
Bucket(final int arraySize,
final int capacity, final BucketStats stats)
{
this.arraySize = arraySize;
this.clean = clean;
this.stats = stats;
this.arrays = new double[capacity][];
}
Expand All @@ -208,7 +211,7 @@ static final class Bucket {
void putArray(final double[] array)
{
if (DO_CHECKS && (array.length != arraySize)) {
logInfo(getLogPrefix(clean) + "DoubleArrayCache: "
logInfo("ArrayCacheDouble(Dirty): "
+ "bad length = " + array.length);
return;
}
Expand All @@ -223,7 +226,7 @@ void putArray(final double[] array)
stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "DoubleArrayCache: "
logInfo("ArrayCacheDouble(Dirty): "
+ "array capacity exceeded !");
}
}
Expand All @@ -243,8 +246,8 @@ static void fill(final double[] array, final int fromIndex,
}
}

public static void check(final double[] array, final int fromIndex,
final int toIndex, final double value)
static void check(final double[] array, final int fromIndex,
final int toIndex, final double value)
{
if (DO_CHECKS) {
// check zero on full array:
Expand All @@ -262,8 +265,4 @@ public static void check(final double[] array, final int fromIndex,
}
}
}

static String getLogPrefix(final boolean clean) {
return (clean) ? "Clean" : "Dirty";
}
}
Loading

0 comments on commit 7492844

Please sign in to comment.