summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2012-02-17 02:02:12 +0800
committerChih-Chung Chang <chihchung@google.com>2012-02-17 02:02:12 +0800
commit5b01ee731c6acbcef657746a23d5cfde2251ab7e (patch)
treec60b3f4a6162612b1b8d0cb3a112a12d9f4d2067
parent3f43ecbb1b7c8f24c9a6e3d6b9807a1d0ef2f2ab (diff)
downloadandroid_packages_apps_Snap-5b01ee731c6acbcef657746a23d5cfde2251ab7e.tar.gz
android_packages_apps_Snap-5b01ee731c6acbcef657746a23d5cfde2251ab7e.tar.bz2
android_packages_apps_Snap-5b01ee731c6acbcef657746a23d5cfde2251ab7e.zip
Simplify the reference from textures to GLCanvas.
Change-Id: Ia64e60ec4b920b707148f7c2b9373ce484a52d9f
-rw-r--r--src/com/android/gallery3d/ui/BasicTexture.java20
-rw-r--r--src/com/android/gallery3d/ui/GLRootView.java1
-rw-r--r--src/com/android/gallery3d/ui/NinePatchTexture.java2
-rw-r--r--src/com/android/gallery3d/ui/RawTexture.java2
4 files changed, 16 insertions, 9 deletions
diff --git a/src/com/android/gallery3d/ui/BasicTexture.java b/src/com/android/gallery3d/ui/BasicTexture.java
index 8946036e7..d3dfd745c 100644
--- a/src/com/android/gallery3d/ui/BasicTexture.java
+++ b/src/com/android/gallery3d/ui/BasicTexture.java
@@ -18,7 +18,6 @@ package com.android.gallery3d.ui;
import com.android.gallery3d.common.Utils;
-import java.lang.ref.WeakReference;
import java.util.WeakHashMap;
// BasicTexture is a Texture corresponds to a real GL texture.
@@ -45,7 +44,7 @@ abstract class BasicTexture implements Texture {
private boolean mHasBorder;
- protected WeakReference<GLCanvas> mCanvasRef = null;
+ protected GLCanvas mCanvasRef = null;
private static WeakHashMap<BasicTexture, Object> sAllTextures
= new WeakHashMap<BasicTexture, Object>();
private static ThreadLocal sInFinalizer = new ThreadLocal();
@@ -64,9 +63,7 @@ abstract class BasicTexture implements Texture {
}
protected void setAssociatedCanvas(GLCanvas canvas) {
- mCanvasRef = canvas == null
- ? null
- : new WeakReference<GLCanvas>(canvas);
+ mCanvasRef = canvas;
}
/**
@@ -134,7 +131,7 @@ abstract class BasicTexture implements Texture {
abstract protected boolean onBind(GLCanvas canvas);
public boolean isLoaded(GLCanvas canvas) {
- return mState == STATE_LOADED && mCanvasRef.get() == canvas;
+ return mState == STATE_LOADED;
}
// recycle() is called when the texture will never be used again,
@@ -153,7 +150,7 @@ abstract class BasicTexture implements Texture {
}
private void freeResource() {
- GLCanvas canvas = mCanvasRef == null ? null : mCanvasRef.get();
+ GLCanvas canvas = mCanvasRef;
if (canvas != null && isLoaded(canvas)) {
canvas.unloadTexture(this);
}
@@ -182,4 +179,13 @@ abstract class BasicTexture implements Texture {
}
}
}
+
+ public static void invalidateAllTextures() {
+ synchronized (sAllTextures) {
+ for (BasicTexture t : sAllTextures.keySet()) {
+ t.mState = STATE_UNLOADED;
+ t.setAssociatedCanvas(null);
+ }
+ }
+ }
}
diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java
index 3f2269f4f..27bc88539 100644
--- a/src/com/android/gallery3d/ui/GLRootView.java
+++ b/src/com/android/gallery3d/ui/GLRootView.java
@@ -239,6 +239,7 @@ public class GLRootView extends GLSurfaceView
+ ", gl10: " + gl1.toString());
Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY);
GalleryUtils.setRenderThread();
+ BasicTexture.invalidateAllTextures();
if (DEBUG_PROFILE) {
Log.d(TAG, "Start profiling");
Profile.enable(20); // take a sample every 20ms
diff --git a/src/com/android/gallery3d/ui/NinePatchTexture.java b/src/com/android/gallery3d/ui/NinePatchTexture.java
index 8c9928532..ac71774f5 100644
--- a/src/com/android/gallery3d/ui/NinePatchTexture.java
+++ b/src/com/android/gallery3d/ui/NinePatchTexture.java
@@ -168,7 +168,7 @@ public class NinePatchTexture extends ResourceTexture {
@Override
public void recycle() {
super.recycle();
- GLCanvas canvas = mCanvasRef == null ? null : mCanvasRef.get();
+ GLCanvas canvas = mCanvasRef;
if (canvas == null) return;
int n = mInstanceCache.size();
for (int i = 0; i < n; i++) {
diff --git a/src/com/android/gallery3d/ui/RawTexture.java b/src/com/android/gallery3d/ui/RawTexture.java
index c1be435d1..527880a35 100644
--- a/src/com/android/gallery3d/ui/RawTexture.java
+++ b/src/com/android/gallery3d/ui/RawTexture.java
@@ -37,7 +37,7 @@ class RawTexture extends BasicTexture {
@Override
protected boolean onBind(GLCanvas canvas) {
- if (mCanvasRef.get() != canvas) {
+ if (mCanvasRef != canvas) {
throw new RuntimeException("cannot bind to different canvas");
}
return true;