Path: blob/master/src/java.desktop/macosx/classes/sun/font/CStrikeDisposer.java
41153 views
/*1* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.font;2627/*28* This keeps track of data that needs to be cleaned up once a29* strike is freed.30* a) The native memory that is the glyph image cache.31* b) removing the "desc" key from the strike's map.32* This is safe to do because this disposer is invoked only when the33* reference object has been cleared, which means the value indexed by34* this key is just an empty reference object.35* It is possible that a new FontStrike has been created that would36* be referenced by the same (equals) key. If it is placed in the map37* before this disposer is executed, then we do not want to remove that38* object. We should only remove an object where the value is null.39* So we first verify that the key still points to a cleared reference.40* Updates to the map thus need to be synchronized.41*42* A WeakHashmap will automatically clean up, but we might maintain a43* reference to the "desc" key in the FontStrike (value) which would44* prevent the keys from being discarded. And since the strike is the only45* place is likely we would maintain such a strong reference, then the map46* entries would be removed much more promptly than we need.47*/48class CStrikeDisposer extends FontStrikeDisposer {4950long pNativeScalerContext;5152public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc,53long pContext, int[] images)54{55super(font2D, desc, 0L, images);56pNativeScalerContext = pContext;57}5859public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc,60long pContext, long[] images)61{62super(font2D, desc, 0L, images);63pNativeScalerContext = pContext;64}6566public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc,67long pContext)68{69super(font2D, desc, 0L);70pNativeScalerContext = pContext;71}7273public CStrikeDisposer(Font2D font2D, FontStrikeDesc desc) {74super(font2D, desc);75}7677public synchronized void dispose() {78if (!disposed) {79if (pNativeScalerContext != 0L) {80freeNativeScalerContext(pNativeScalerContext);81}82super.dispose();83}84}8586private native void freeNativeScalerContext(long pContext);8788protected static native void removeGlyphInfoFromCache(long glyphInfo);89}909192