Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/font/FontStrikeDisposer.java
41154 views
1
/*
2
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
26
package sun.font;
27
28
import java.lang.ref.Reference;
29
import java.util.concurrent.ConcurrentHashMap;
30
import sun.java2d.Disposer;
31
import sun.java2d.DisposerRecord;
32
33
/*
34
* This keeps track of data that needs to be cleaned up once a
35
* strike is freed.
36
* a) The native memory that is the glyph image cache.
37
* b) removing the "desc" key from the strike's map.
38
* This is safe to do because this disposer is invoked only when the
39
* reference object has been cleared, which means the value indexed by
40
* this key is just an empty reference object.
41
* It is possible that a new FontStrike has been created that would
42
* be referenced by the same (equals) key. If it is placed in the map
43
* before this disposer is executed, then we do not want to remove that
44
* object. We should only remove an object where the value is null.
45
* So we first verify that the key still points to a cleared reference.
46
* Updates to the map thus need to be synchronized.
47
*
48
* A WeakHashmap will automatically clean up, but we might maintain a
49
* reference to the "desc" key in the FontStrike (value) which would
50
* prevent the keys from being discarded. And since the strike is the only
51
* place is likely we would maintain such a strong reference, then the map
52
* entries would be removed much more promptly than we need.
53
*/
54
55
class FontStrikeDisposer
56
implements DisposerRecord, Disposer.PollDisposable {
57
58
ConcurrentHashMap<FontStrikeDesc, Reference<FontStrike>> strikeCache;
59
FontStrikeDesc desc;
60
long[] longGlyphImages;
61
int [] intGlyphImages;
62
int [][] segIntGlyphImages;
63
long[][] segLongGlyphImages;
64
long pScalerContext = 0L;
65
boolean disposed = false;
66
boolean comp = false;
67
68
public FontStrikeDisposer(Font2D font2D, FontStrikeDesc desc,
69
long pContext, int[] images) {
70
this.strikeCache = font2D.strikeCache;
71
this.desc = desc;
72
this.pScalerContext = pContext;
73
this.intGlyphImages = images;
74
}
75
76
public FontStrikeDisposer(Font2D font2D, FontStrikeDesc desc,
77
long pContext, long[] images) {
78
this.strikeCache = font2D.strikeCache;
79
this.desc = desc;
80
this.pScalerContext = pContext;
81
this.longGlyphImages = images;
82
}
83
84
public FontStrikeDisposer(Font2D font2D, FontStrikeDesc desc,
85
long pContext) {
86
this.strikeCache = font2D.strikeCache;
87
this.desc = desc;
88
this.pScalerContext = pContext;
89
}
90
91
public FontStrikeDisposer(Font2D font2D, FontStrikeDesc desc) {
92
this.strikeCache = font2D.strikeCache;
93
this.desc = desc;
94
this.comp = true;
95
}
96
97
public synchronized void dispose() {
98
if (!disposed) {
99
Reference<FontStrike> ref = strikeCache.get(desc);
100
if (ref != null) {
101
Object o = ref.get();
102
if (o == null) {
103
strikeCache.remove(desc);
104
}
105
}
106
StrikeCache.disposeStrike(this);
107
disposed = true;
108
}
109
}
110
}
111
112