diff options
author | Harvey Harrison <[email protected]> | 2012-01-08 15:05:00 -0800 |
---|---|---|
committer | Harvey Harrison <[email protected]> | 2012-01-08 15:05:00 -0800 |
commit | 99ba700abc8837e0b4ce557c9052bd8b0f1a5983 (patch) | |
tree | b6fd221c2a596d2d0ac72bd7b7d36669136bb565 /src | |
parent | 150daa7d3e596b6905014234e186604e2dfd1ed8 (diff) |
j3dcore: annotate lists of TextureRetained, change to explicit null checks
The existing code was using instanceof as a null-check in practice, annotate the lists
and helper functions with explicit types and make the null checks more obvious.
Signed-off-by: Harvey Harrison <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/classes/share/javax/media/j3d/Canvas3D.java | 42 | ||||
-rw-r--r-- | src/classes/share/javax/media/j3d/Renderer.java | 29 |
2 files changed, 28 insertions, 43 deletions
diff --git a/src/classes/share/javax/media/j3d/Canvas3D.java b/src/classes/share/javax/media/j3d/Canvas3D.java index c32b37e..d4f1ad6 100644 --- a/src/classes/share/javax/media/j3d/Canvas3D.java +++ b/src/classes/share/javax/media/j3d/Canvas3D.java @@ -880,10 +880,10 @@ ArrayList<Integer> textureIdResourceFreeList = new ArrayList<Integer>(); Point newPosition = new Point(); Dimension newSize = new Dimension(); - // Remember OGL context resources to free - // before context is destroy. - // It is used when sharedCtx = false; - ArrayList textureIDResourceTable = new ArrayList(5); +// Remember OGL context resources to free +// before context is destroy. +// It is used when sharedCtx = false; +ArrayList<TextureRetained> textureIDResourceTable = new ArrayList<TextureRetained>(5); // The following variables are used by the lazy download of // states code to keep track of the set of current to be update bins @@ -3919,7 +3919,6 @@ ArrayList<Integer> textureIdResourceFreeList = new ArrayList<Integer>(); // use by D3D only void resetTextureBin() { - Object obj; TextureRetained tex; // We don't use rdr.objectId for background texture in D3D @@ -3931,14 +3930,12 @@ ArrayList<Integer> textureIdResourceFreeList = new ArrayList<Integer>(); graphics2D.objectId = -1; } - for (int id = textureIDResourceTable.size()-1; id >= 0; id--) { - obj = textureIDResourceTable.get(id); - if (obj != null) { - if (obj instanceof TextureRetained) { - tex = (TextureRetained) obj; - tex.resourceCreationMask &= ~canvasBit; + for (int id = textureIDResourceTable.size() - 1; id >= 0; id--) { + tex = textureIDResourceTable.get(id); + if (tex != null) { + tex.resourceCreationMask &= ~canvasBit; + } - } } } @@ -4786,7 +4783,7 @@ ArrayList<Integer> textureIdResourceFreeList = new ArrayList<Integer>(); * of texture is -1 one time only. * This is always call from Renderer thread. */ - void addTextureResource(int id, Object obj) { +void addTextureResource(int id, TextureRetained obj) { if (id <= 0) { return; } @@ -4839,9 +4836,8 @@ ArrayList<Integer> textureIdResourceFreeList = new ArrayList<Integer>(); textureIDResourceTable.size() + " val = " + val); } else { - Object obj = textureIDResourceTable.get(val); - if (obj instanceof TextureRetained) { - TextureRetained tex = (TextureRetained) obj; + TextureRetained tex = textureIDResourceTable.get(val); + if (tex != null) { synchronized (tex.resourceLock) { tex.resourceCreationMask &= ~canvasBit; if (tex.resourceCreationMask == 0) { @@ -4860,9 +4856,6 @@ ArrayList<Integer> textureIdResourceFreeList = new ArrayList<Integer>(); void freeContextResources(Renderer rdr, boolean freeBackground, Context ctx) { - - - Object obj; TextureRetained tex; // Just return if we don't have a valid renderer or context @@ -4878,18 +4871,16 @@ ArrayList<Integer> textureIdResourceFreeList = new ArrayList<Integer>(); } for (int id = textureIDResourceTable.size()-1; id >= 0; id--) { - obj = textureIDResourceTable.get(id); - if (obj == null) { - continue; - } + tex = textureIDResourceTable.get(id); + if (tex == null) { + continue; + } // Issue 403 : this assertion doesn't hold in some cases // TODO KCR : determine why this is the case // assert id == ((TextureRetained)obj).objectId; freeTexture(ctx, id); - if (obj instanceof TextureRetained) { - tex = (TextureRetained) obj; synchronized (tex.resourceLock) { tex.resourceCreationMask &= ~canvasBit; if (tex.resourceCreationMask == 0) { @@ -4897,7 +4888,6 @@ ArrayList<Integer> textureIdResourceFreeList = new ArrayList<Integer>(); tex.freeTextureId(id); } } - } } textureIDResourceTable.clear(); diff --git a/src/classes/share/javax/media/j3d/Renderer.java b/src/classes/share/javax/media/j3d/Renderer.java index 5afabdc..d4655a6 100644 --- a/src/classes/share/javax/media/j3d/Renderer.java +++ b/src/classes/share/javax/media/j3d/Renderer.java @@ -175,10 +175,10 @@ ArrayList<Integer> displayListResourceFreeList = new ArrayList<Integer>(); // dirtyDlistPerRinfoList, dirtyRenderAtomList size > 0 boolean dirtyDisplayList = false; - // Remember OGL context resources to free - // before context is destroy. - // It is used when sharedCtx = true; - ArrayList textureIDResourceTable = new ArrayList(5); +// Remember OGL context resources to free +// before context is destroy. +// It is used when sharedCtx = true; +ArrayList<TextureRetained> textureIDResourceTable = new ArrayList<TextureRetained>(5); // Instrumentation of Java 3D renderer private long lastSwapTime = System.nanoTime(); @@ -1651,7 +1651,7 @@ ArrayList<Integer> displayListResourceFreeList = new ArrayList<Integer>(); synchronized (VirtualUniverse.mc.contextCreationLock) { for (int i=listOfCanvases.size()-1; i >=0; i--) { - cv = (Canvas3D) listOfCanvases.get(i); + cv = listOfCanvases.get(i); if ((cv.screen != null) && (cv.ctx != null)) { // Issue 326 : don't check display variable here @@ -1731,9 +1731,8 @@ ArrayList<Integer> displayListResourceFreeList = new ArrayList<Integer>(); textureIDResourceTable.size() + " val = " + val); } else { - Object obj = textureIDResourceTable.get(val); - if (obj instanceof TextureRetained) { - TextureRetained tex = (TextureRetained) obj; + TextureRetained tex = textureIDResourceTable.get(val); + if (tex != null) { synchronized (tex.resourceLock) { tex.resourceCreationMask &= ~rendererBit; if (tex.resourceCreationMask == 0) { @@ -1754,7 +1753,7 @@ ArrayList<Integer> displayListResourceFreeList = new ArrayList<Integer>(); } } - final void addTextureResource(int id, Object obj) { +final void addTextureResource(int id, TextureRetained obj) { if (textureIDResourceTable.size() <= id) { for (int i=textureIDResourceTable.size(); i < id; i++) { @@ -1767,24 +1766,20 @@ ArrayList<Integer> displayListResourceFreeList = new ArrayList<Integer>(); } void freeContextResources() { - Object obj; TextureRetained tex; for (int id = textureIDResourceTable.size()-1; id >= 0; id--) { - obj = textureIDResourceTable.get(id); - if (obj == null) { - continue; - } + tex = textureIDResourceTable.get(id); + if (tex == null) { + continue; + } Canvas3D.freeTexture(sharedCtx, id); - if (obj instanceof TextureRetained) { - tex = (TextureRetained) obj; synchronized (tex.resourceLock) { tex.resourceCreationMask &= ~rendererBit; if (tex.resourceCreationMask == 0) { tex.freeTextureId(id); } } - } } textureIDResourceTable.clear(); |