< prev index next >

src/java.desktop/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java

Print this page

        

*** 39,48 **** --- 39,49 ---- import java.awt.image.ColorModel; import java.awt.image.DataBuffer; import java.awt.image.DirectColorModel; import java.awt.image.VolatileImage; import java.awt.image.WritableRaster; + import java.util.HashMap; import sun.awt.CGraphicsConfig; import sun.awt.CGraphicsDevice; import sun.awt.image.OffScreenImage; import sun.awt.image.SunVolatileImage;
*** 82,91 **** --- 83,94 ---- private static native boolean initCGL(); private static native long getCGLConfigInfo(int displayID, int visualnum, int swapInterval); private static native int getOGLCapabilities(long configInfo); + private static final HashMap<Long, Integer> pGCRefCounts = new HashMap<>(); + /** * Returns GL_MAX_TEXTURE_SIZE from the shared opengl context. Must be * called under OGLRQ lock, because this method change current context. * * @return GL_MAX_TEXTURE_SIZE
*** 104,114 **** this.pixfmt = pixfmt; this.pConfigInfo = configInfo; this.oglCaps = oglCaps; this.maxTextureSize = maxTextureSize; context = new OGLContext(OGLRenderQueue.getInstance(), this); ! // add a record to the Disposer so that we destroy the native // CGLGraphicsConfigInfo data when this object goes away Disposer.addRecord(disposerReferent, new CGLGCDisposerRecord(pConfigInfo)); } --- 107,117 ---- this.pixfmt = pixfmt; this.pConfigInfo = configInfo; this.oglCaps = oglCaps; this.maxTextureSize = maxTextureSize; context = new OGLContext(OGLRenderQueue.getInstance(), this); ! refPConfigInfo(pConfigInfo); // add a record to the Disposer so that we destroy the native // CGLGraphicsConfigInfo data when this object goes away Disposer.addRecord(disposerReferent, new CGLGCDisposerRecord(pConfigInfo)); }
*** 167,176 **** --- 170,204 ---- int oglCaps = getOGLCapabilities(cfginfo); ContextCapabilities caps = new OGLContextCaps(oglCaps, ids[0]); return new CGLGraphicsConfig(device, pixfmt, cfginfo, textureSize, caps); } + static void refPConfigInfo(long pConfigInfo) { + synchronized (pGCRefCounts) { + Integer count = pGCRefCounts.get(pConfigInfo); + if (count == null) count = 0; + count++; + pGCRefCounts.put(pConfigInfo, count); + } + } + + static void deRefPConfigInfo(long pConfigInfo) { + synchronized (pGCRefCounts) { + Integer count = pGCRefCounts.get(pConfigInfo); + if (count != null) { + count--; + if (count == 0) { + OGLRenderQueue.disposeGraphicsConfig(pConfigInfo); + pGCRefCounts.remove(pConfigInfo); + } + else { + pGCRefCounts.put(pConfigInfo, count); + } + } + } + } + public static boolean isCGLAvailable() { return cglAvailable; } /**
*** 234,244 **** public CGLGCDisposerRecord(long pCfgInfo) { this.pCfgInfo = pCfgInfo; } public void dispose() { if (pCfgInfo != 0) { ! OGLRenderQueue.disposeGraphicsConfig(pCfgInfo); pCfgInfo = 0; } } } --- 262,272 ---- public CGLGCDisposerRecord(long pCfgInfo) { this.pCfgInfo = pCfgInfo; } public void dispose() { if (pCfgInfo != 0) { ! deRefPConfigInfo(pCfgInfo); pCfgInfo = 0; } } }
< prev index next >