2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.java2d.pisces;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* An object used to cache pre-rendered complex paths.
|
|
30 |
*
|
|
31 |
* @see PiscesRenderer#render
|
|
32 |
*/
|
|
33 |
public final class PiscesCache {
|
|
34 |
|
|
35 |
int bboxX0, bboxY0, bboxX1, bboxY1;
|
|
36 |
|
|
37 |
byte[] rowAARLE;
|
|
38 |
int alphaRLELength;
|
|
39 |
|
|
40 |
int[] rowOffsetsRLE;
|
|
41 |
int[] minTouched;
|
|
42 |
int alphaRows;
|
|
43 |
|
|
44 |
private PiscesCache() {}
|
|
45 |
|
|
46 |
public static PiscesCache createInstance() {
|
|
47 |
return new PiscesCache();
|
|
48 |
}
|
|
49 |
|
|
50 |
private static final float ROWAA_RLE_FACTOR = 1.5f;
|
|
51 |
private static final float TOUCHED_FACTOR = 1.5f;
|
|
52 |
private static final int MIN_TOUCHED_LEN = 64;
|
|
53 |
|
|
54 |
private void reallocRowAARLE(int newLength) {
|
|
55 |
if (rowAARLE == null) {
|
|
56 |
rowAARLE = new byte[newLength];
|
|
57 |
} else if (rowAARLE.length < newLength) {
|
|
58 |
int len = Math.max(newLength,
|
|
59 |
(int)(rowAARLE.length*ROWAA_RLE_FACTOR));
|
|
60 |
byte[] newRowAARLE = new byte[len];
|
|
61 |
System.arraycopy(rowAARLE, 0, newRowAARLE, 0, rowAARLE.length);
|
|
62 |
rowAARLE = newRowAARLE;
|
|
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
private void reallocRowInfo(int newHeight) {
|
|
67 |
if (minTouched == null) {
|
|
68 |
int len = Math.max(newHeight, MIN_TOUCHED_LEN);
|
|
69 |
minTouched = new int[len];
|
|
70 |
rowOffsetsRLE = new int[len];
|
|
71 |
} else if (minTouched.length < newHeight) {
|
|
72 |
int len = Math.max(newHeight,
|
|
73 |
(int)(minTouched.length*TOUCHED_FACTOR));
|
|
74 |
int[] newMinTouched = new int[len];
|
|
75 |
int[] newRowOffsetsRLE = new int[len];
|
|
76 |
System.arraycopy(minTouched, 0, newMinTouched, 0,
|
|
77 |
alphaRows);
|
|
78 |
System.arraycopy(rowOffsetsRLE, 0, newRowOffsetsRLE, 0,
|
|
79 |
alphaRows);
|
|
80 |
minTouched = newMinTouched;
|
|
81 |
rowOffsetsRLE = newRowOffsetsRLE;
|
|
82 |
}
|
|
83 |
}
|
|
84 |
|
|
85 |
void addRLERun(byte val, int runLen) {
|
|
86 |
reallocRowAARLE(alphaRLELength + 2);
|
|
87 |
rowAARLE[alphaRLELength++] = val;
|
|
88 |
rowAARLE[alphaRLELength++] = (byte)runLen;
|
|
89 |
}
|
|
90 |
|
|
91 |
void startRow(int y, int x0, int x1) {
|
|
92 |
if (alphaRows == 0) {
|
|
93 |
bboxY0 = y;
|
|
94 |
bboxY1 = y+1;
|
|
95 |
bboxX0 = x0;
|
|
96 |
bboxX1 = x1+1;
|
|
97 |
} else {
|
|
98 |
if (bboxX0 > x0) bboxX0 = x0;
|
3008
|
99 |
if (bboxX1 < x1 + 1) bboxX1 = x1 + 1;
|
2
|
100 |
while (bboxY1++ < y) {
|
|
101 |
reallocRowInfo(alphaRows+1);
|
|
102 |
minTouched[alphaRows] = 0;
|
|
103 |
// Assuming last 2 entries in rowAARLE are 0,0
|
|
104 |
rowOffsetsRLE[alphaRows] = alphaRLELength-2;
|
|
105 |
alphaRows++;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
reallocRowInfo(alphaRows+1);
|
|
109 |
minTouched[alphaRows] = x0;
|
|
110 |
rowOffsetsRLE[alphaRows] = alphaRLELength;
|
|
111 |
alphaRows++;
|
|
112 |
}
|
|
113 |
|
|
114 |
public synchronized void dispose() {
|
|
115 |
rowAARLE = null;
|
|
116 |
alphaRLELength = 0;
|
|
117 |
|
|
118 |
minTouched = null;
|
|
119 |
rowOffsetsRLE = null;
|
|
120 |
alphaRows = 0;
|
|
121 |
|
|
122 |
bboxX0 = bboxY0 = bboxX1 = bboxY1 = 0;
|
|
123 |
}
|
|
124 |
|
|
125 |
public void print(java.io.PrintStream out) {
|
|
126 |
synchronized (out) {
|
|
127 |
out.println("bbox = ["+
|
|
128 |
bboxX0+", "+bboxY0+" => "+
|
|
129 |
bboxX1+", "+bboxY1+"]");
|
|
130 |
|
|
131 |
out.println("alphRLELength = "+alphaRLELength);
|
|
132 |
|
|
133 |
for (int y = bboxY0; y < bboxY1; y++) {
|
|
134 |
int i = y-bboxY0;
|
|
135 |
out.println("row["+i+"] == {"+
|
|
136 |
"minX = "+minTouched[i]+
|
|
137 |
", off = "+rowOffsetsRLE[i]+"}");
|
|
138 |
}
|
|
139 |
|
|
140 |
for (int i = 0; i < alphaRLELength; i += 2) {
|
|
141 |
out.println("rle["+i+"] = "+
|
|
142 |
(rowAARLE[i+1]&0xff)+" of "+(rowAARLE[i]&0xff));
|
|
143 |
}
|
|
144 |
}
|
|
145 |
}
|
|
146 |
}
|