提交 f755e87f 编写于 作者: C ceisserer

7023589: Xrender : NullPointerException in sun.font.XRGlyphCache.freeGlyphs running Java 2D demo

Reviewed-by: prr
上级 d4aed30b
...@@ -319,8 +319,7 @@ public final class StrikeCache { ...@@ -319,8 +319,7 @@ public final class StrikeCache {
ArrayList<Long> gids = null; ArrayList<Long> gids = null;
for (int i = 0; i < glyphPtrs.length; i++) { for (int i = 0; i < glyphPtrs.length; i++) {
if (glyphPtrs[i] != 0 && unsafe.getByte(glyphPtrs[i] + managedOffset) == 0 if (glyphPtrs[i] != 0 && unsafe.getByte(glyphPtrs[i] + managedOffset) == 0) {
&& unsafe.getInt(glyphPtrs[i] + cacheCellOffset) != 0) {
if (gids == null) { if (gids == null) {
gids = new ArrayList<Long>(); gids = new ArrayList<Long>();
...@@ -330,6 +329,8 @@ public final class StrikeCache { ...@@ -330,6 +329,8 @@ public final class StrikeCache {
} }
if (gids != null) { if (gids != null) {
// Any reference by the disposers to the native glyph ptrs
// must be done before this returns.
notifyDisposeListeners(gids); notifyDisposeListeners(gids);
} }
} }
...@@ -345,8 +346,7 @@ public final class StrikeCache { ...@@ -345,8 +346,7 @@ public final class StrikeCache {
for (int i=0; i < glyphPtrs.length; i++) { for (int i=0; i < glyphPtrs.length; i++) {
if (glyphPtrs[i] != 0 if (glyphPtrs[i] != 0
&& unsafe.getByte(glyphPtrs[i] + managedOffset) == 0 && unsafe.getByte(glyphPtrs[i] + managedOffset) == 0) {
&& unsafe.getInt(glyphPtrs[i] + cacheCellOffset) != 0) {
if (gids == null) { if (gids == null) {
gids = new ArrayList<Long>(); gids = new ArrayList<Long>();
...@@ -356,6 +356,8 @@ public final class StrikeCache { ...@@ -356,6 +356,8 @@ public final class StrikeCache {
} }
if (gids != null) { if (gids != null) {
// Any reference by the disposers to the native glyph ptrs
// must be done before this returns.
notifyDisposeListeners(gids); notifyDisposeListeners(gids);
} }
} }
......
...@@ -70,9 +70,14 @@ public class XRGlyphCache implements GlyphDisposedListener { ...@@ -70,9 +70,14 @@ public class XRGlyphCache implements GlyphDisposedListener {
try { try {
SunToolkit.awtLock(); SunToolkit.awtLock();
ArrayList<Integer> glyphIDList = new ArrayList<Integer>(glyphPtrList.size()); GrowableIntArray glyphIDList = new GrowableIntArray(1, glyphPtrList.size());
for (long glyphPtr : glyphPtrList) { for (long glyphPtr : glyphPtrList) {
glyphIDList.add(XRGlyphCacheEntry.getGlyphID(glyphPtr)); int glyphID = XRGlyphCacheEntry.getGlyphID(glyphPtr);
//Check if glyph hasn't been freed already
if (glyphID != 0) {
glyphIDList.addInt(glyphID);
}
} }
freeGlyphs(glyphIDList); freeGlyphs(glyphIDList);
} finally { } finally {
...@@ -83,7 +88,6 @@ public class XRGlyphCache implements GlyphDisposedListener { ...@@ -83,7 +88,6 @@ public class XRGlyphCache implements GlyphDisposedListener {
protected int getFreeGlyphID() { protected int getFreeGlyphID() {
if (freeGlyphIDs.size() > 0) { if (freeGlyphIDs.size() > 0) {
int newID = freeGlyphIDs.remove(freeGlyphIDs.size() - 1); int newID = freeGlyphIDs.remove(freeGlyphIDs.size() - 1);
;
return newID; return newID;
} }
return nextID++; return nextID++;
...@@ -246,7 +250,7 @@ public class XRGlyphCache implements GlyphDisposedListener { ...@@ -246,7 +250,7 @@ public class XRGlyphCache implements GlyphDisposedListener {
glyph.setPinned(); glyph.setPinned();
} }
ArrayList<Integer> deleteGlyphList = new ArrayList<Integer>(); GrowableIntArray deleteGlyphList = new GrowableIntArray(1, 10);
int pixelsToRelease = cachedPixels - MAX_CACHED_PIXELS; int pixelsToRelease = cachedPixels - MAX_CACHED_PIXELS;
for (int i = cacheList.size() - 1; i >= 0 && pixelsToRelease > 0; i--) { for (int i = cacheList.size() - 1; i >= 0 && pixelsToRelease > 0; i--) {
...@@ -254,7 +258,7 @@ public class XRGlyphCache implements GlyphDisposedListener { ...@@ -254,7 +258,7 @@ public class XRGlyphCache implements GlyphDisposedListener {
if (!entry.isPinned()) { if (!entry.isPinned()) {
pixelsToRelease -= entry.getPixelCnt(); pixelsToRelease -= entry.getPixelCnt();
deleteGlyphList.add(new Integer(entry.getGlyphID())); deleteGlyphList.addInt(entry.getGlyphID());
} }
} }
...@@ -265,26 +269,23 @@ public class XRGlyphCache implements GlyphDisposedListener { ...@@ -265,26 +269,23 @@ public class XRGlyphCache implements GlyphDisposedListener {
freeGlyphs(deleteGlyphList); freeGlyphs(deleteGlyphList);
} }
private void freeGlyphs(List<Integer> glyphIdList) { private void freeGlyphs(GrowableIntArray glyphIdList) {
GrowableIntArray removedLCDGlyphs = new GrowableIntArray(1, 10);
GrowableIntArray removedGrayscaleGlyphs = new GrowableIntArray(1, 10);
freeGlyphIDs.addAll(glyphIdList); for (int i=0; i < glyphIdList.getSize(); i++) {
int glyphId = glyphIdList.getInt(i);
freeGlyphIDs.add(glyphId);
GrowableIntArray removedLCDGlyphs = new GrowableIntArray(1, 1); tmp.setValue(glyphId);
GrowableIntArray removedGrayscaleGlyphs = new GrowableIntArray(1, 1);
for (Integer glyphId : glyphIdList) {
tmp.setValue(glyphId.intValue());
XRGlyphCacheEntry entry = cacheMap.get(tmp); XRGlyphCacheEntry entry = cacheMap.get(tmp);
cachedPixels -= entry.getPixelCnt(); cachedPixels -= entry.getPixelCnt();
int removedGlyphID = entry.getGlyphID();
tmp.setValue(removedGlyphID);
cacheMap.remove(tmp); cacheMap.remove(tmp);
if (entry.getGlyphSet() == grayGlyphSet) { if (entry.getGlyphSet() == grayGlyphSet) {
removedGrayscaleGlyphs.addInt(removedGlyphID); removedGrayscaleGlyphs.addInt(glyphId);
} else { } else {
removedLCDGlyphs.addInt(removedGlyphID); removedLCDGlyphs.addInt(glyphId);
} }
entry.setGlyphID(0); entry.setGlyphID(0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册