Skip to content

Commit 5e0ded0

Browse files
Alexey BakhtinRealCLanger
authored andcommitted
8364373: Transform Affine transformations
Reviewed-by: andrew Backport-of: 6da25e4f8c2f1100360728eb536cc10809d46bc7
1 parent 64df6c6 commit 5e0ded0

2 files changed

Lines changed: 39 additions & 18 deletions

File tree

src/java.desktop/share/classes/sun/awt/geom/AreaOp.java

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -146,6 +146,8 @@ private AreaOp() {
146146
public static final int RSTAG_INSIDE = 1;
147147
public static final int RSTAG_OUTSIDE = -1;
148148

149+
public static final int MAX_LINK_COUNT = 1024;
150+
149151
public abstract void newRow();
150152

151153
public abstract int classify(Edge e);
@@ -195,6 +197,25 @@ public int compare(Edge o1, Edge o2) {
195197
}
196198
};
197199

200+
private void consumeSubCurves(Vector<CurveLink> subcurves,
201+
Vector<ChainEnd> chains,
202+
Vector<Curve> curve) {
203+
finalizeSubCurves(subcurves, chains);
204+
Enumeration<CurveLink> enum_ = subcurves.elements();
205+
while (enum_.hasMoreElements()) {
206+
CurveLink link = enum_.nextElement();
207+
curve.add(link.getMoveto());
208+
CurveLink nextlink = link;
209+
while ((nextlink = nextlink.getNext()) != null) {
210+
if (!link.absorb(nextlink)) {
211+
curve.add(link.getSubCurve());
212+
link = nextlink;
213+
}
214+
}
215+
curve.add(link.getSubCurve());
216+
}
217+
}
218+
198219
private Vector<Curve> pruneEdges(Vector<Edge> edges) {
199220
int numedges = edges.size();
200221
if (numedges < 2) {
@@ -218,6 +239,8 @@ private Vector<Curve> pruneEdges(Vector<Edge> edges) {
218239
Vector<CurveLink> subcurves = new Vector<>();
219240
Vector<ChainEnd> chains = new Vector<>();
220241
Vector<CurveLink> links = new Vector<>();
242+
Vector<Curve> ret = new Vector<>();
243+
int linkCount = 0;
221244
// Active edges are between left (inclusive) and right (exclusive)
222245
while (left < numedges) {
223246
double y = yrange[0];
@@ -390,27 +413,22 @@ private Vector<Curve> pruneEdges(Vector<Edge> edges) {
390413
System.out.println(" "+link.getSubCurve());
391414
}
392415
}
416+
// If we have complex area calculation, we should consume the
417+
// intermediate subcurves to optimize memory footprint
418+
if (linkCount >= MAX_LINK_COUNT) {
419+
consumeSubCurves(subcurves, chains, ret);
420+
linkCount = 0;
421+
chains.clear();
422+
subcurves.clear();
423+
}
424+
linkCount += links.size();
393425
resolveLinks(subcurves, chains, links);
394426
links.clear();
395427
// Finally capture the bottom of the valid Y range as the top
396428
// of the next Y range.
397429
yrange[0] = yend;
398430
}
399-
finalizeSubCurves(subcurves, chains);
400-
Vector<Curve> ret = new Vector<>();
401-
Enumeration<CurveLink> enum_ = subcurves.elements();
402-
while (enum_.hasMoreElements()) {
403-
CurveLink link = enum_.nextElement();
404-
ret.add(link.getMoveto());
405-
CurveLink nextlink = link;
406-
while ((nextlink = nextlink.getNext()) != null) {
407-
if (!link.absorb(nextlink)) {
408-
ret.add(link.getSubCurve());
409-
link = nextlink;
410-
}
411-
}
412-
ret.add(link.getSubCurve());
413-
}
431+
consumeSubCurves(subcurves, chains, ret);
414432
return ret;
415433
}
416434

src/java.desktop/share/classes/sun/awt/geom/Curve.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1046,6 +1046,9 @@ public int compareTo(Curve that, double[] yrange) {
10461046
double bump = ymin;
10471047
double maxbump = Math.min(ymin * 1E13, (y1 - y0) * .1);
10481048
double y = y0 + bump;
1049+
if (!Double.isFinite(y1)) {
1050+
return 0;
1051+
}
10491052
while (y <= y1) {
10501053
if (fairlyClose(this.XforY(y), that.XforY(y))) {
10511054
if ((bump *= 2) > maxbump) {
@@ -1319,7 +1322,7 @@ public double refineTforY(double t0, double yt0, double y0) {
13191322

13201323
public boolean fairlyClose(double v1, double v2) {
13211324
return (Math.abs(v1 - v2) <
1322-
Math.max(Math.abs(v1), Math.abs(v2)) * 1E-10);
1325+
Math.max(Math.abs(v1), Math.abs(v2)) * 1E-8);
13231326
}
13241327

13251328
public abstract int getSegment(double[] coords);

0 commit comments

Comments
 (0)