summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2012-05-18 11:30:26 -0700
committerOwen Lin <owenlin@google.com>2012-05-22 14:28:35 -0700
commit68386e085d3e2338be74996ff99672ff849467cb (patch)
tree74e1bcd78e4c172ecbd04946f1a5c4c624d265fd
parentc5c5f2558e9ed3bc46a94c5515481b1dac9ffd77 (diff)
downloadandroid_packages_apps_Snap-68386e085d3e2338be74996ff99672ff849467cb.tar.gz
android_packages_apps_Snap-68386e085d3e2338be74996ff99672ff849467cb.tar.bz2
android_packages_apps_Snap-68386e085d3e2338be74996ff99672ff849467cb.zip
Add a new state uploading to UploadedTexture.
This state means the texture is being uploaded in background and should not be drawn now to prevent janking. Sometimes, we may lose GLContext and we will need to reupload textures again. In this case, we would like to upload these texture in foreground instead of using TextureUploader. (for simplicity since this won't happen too often). bug: 6519344 Change-Id: Ic5d7547c6a0eb4b044b79aa0eb4eb52397faac03
-rw-r--r--src/com/android/gallery3d/app/AlbumPage.java6
-rw-r--r--src/com/android/gallery3d/ui/AlbumSetSlotRenderer.java10
-rw-r--r--src/com/android/gallery3d/ui/AlbumSlotRenderer.java8
-rw-r--r--src/com/android/gallery3d/ui/BasicTexture.java6
-rw-r--r--src/com/android/gallery3d/ui/ExtTexture.java4
-rw-r--r--src/com/android/gallery3d/ui/GLCanvasImpl.java4
-rw-r--r--src/com/android/gallery3d/ui/GLRootView.java12
-rw-r--r--src/com/android/gallery3d/ui/NinePatchTexture.java2
-rw-r--r--src/com/android/gallery3d/ui/PhotoFallbackEffect.java2
-rw-r--r--src/com/android/gallery3d/ui/PhotoView.java1
-rw-r--r--src/com/android/gallery3d/ui/RawTexture.java4
-rw-r--r--src/com/android/gallery3d/ui/TextureUploader.java16
-rw-r--r--src/com/android/gallery3d/ui/TileImageView.java8
-rw-r--r--src/com/android/gallery3d/ui/UploadedTexture.java21
-rw-r--r--tests/src/com/android/gallery3d/ui/TextureTest.java28
15 files changed, 80 insertions, 52 deletions
diff --git a/src/com/android/gallery3d/app/AlbumPage.java b/src/com/android/gallery3d/app/AlbumPage.java
index b5ad2a5c6..090ba0891 100644
--- a/src/com/android/gallery3d/app/AlbumPage.java
+++ b/src/com/android/gallery3d/app/AlbumPage.java
@@ -176,9 +176,11 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
if (!more) {
mResumeEffect = null;
mAlbumView.setSlotFilter(null);
- } else {
- invalidate();
}
+ // We want to render one more time even when no more effect
+ // required. So that the animated thumbnails could be draw
+ // with declarations in super.render().
+ invalidate();
}
canvas.restore();
}
diff --git a/src/com/android/gallery3d/ui/AlbumSetSlotRenderer.java b/src/com/android/gallery3d/ui/AlbumSetSlotRenderer.java
index b0e615392..ac810336d 100644
--- a/src/com/android/gallery3d/ui/AlbumSetSlotRenderer.java
+++ b/src/com/android/gallery3d/ui/AlbumSetSlotRenderer.java
@@ -99,9 +99,9 @@ public class AlbumSetSlotRenderer extends AbstractSlotRenderer {
}
}
- private static Texture checkTexture(GLCanvas canvas, Texture texture) {
- return ((texture == null) || ((texture instanceof UploadedTexture)
- && !((UploadedTexture) texture).isContentValid(canvas)))
+ private static Texture checkTexture(Texture texture) {
+ return ((texture instanceof UploadedTexture)
+ && ((UploadedTexture) texture).isUploading())
? null
: texture;
}
@@ -142,7 +142,7 @@ public class AlbumSetSlotRenderer extends AbstractSlotRenderer {
GLCanvas canvas, AlbumSetEntry entry, int width, int height) {
int renderRequestFlags = 0;
- Texture content = checkTexture(canvas, entry.content);
+ Texture content = checkTexture(entry.content);
if (content == null) {
content = mWaitLoadingTexture;
entry.isWaitLoadingDisplayed = true;
@@ -173,7 +173,7 @@ public class AlbumSetSlotRenderer extends AbstractSlotRenderer {
GLCanvas canvas, AlbumSetEntry entry, int width, int height) {
// We show the loading message only when the album is still loading
// (Not when we are still preparing the label)
- Texture content = checkTexture(canvas, entry.label);
+ Texture content = checkTexture(entry.label);
if (entry.album == null) {
content = mDataWindow.getLoadingTexture();
}
diff --git a/src/com/android/gallery3d/ui/AlbumSlotRenderer.java b/src/com/android/gallery3d/ui/AlbumSlotRenderer.java
index 5f1e3a132..9723f4cb3 100644
--- a/src/com/android/gallery3d/ui/AlbumSlotRenderer.java
+++ b/src/com/android/gallery3d/ui/AlbumSlotRenderer.java
@@ -89,9 +89,9 @@ public class AlbumSlotRenderer extends AbstractSlotRenderer {
}
}
- private static Texture checkTexture(GLCanvas canvas, Texture texture) {
- return ((texture == null) || ((texture instanceof UploadedTexture)
- && !((UploadedTexture) texture).isContentValid(canvas)))
+ private static Texture checkTexture(Texture texture) {
+ return (texture instanceof UploadedTexture)
+ && ((UploadedTexture) texture).isUploading()
? null
: texture;
}
@@ -104,7 +104,7 @@ public class AlbumSlotRenderer extends AbstractSlotRenderer {
int renderRequestFlags = 0;
- Texture content = checkTexture(canvas, entry.content);
+ Texture content = checkTexture(entry.content);
if (content == null) {
content = mWaitLoadingTexture;
entry.isWaitDisplayed = true;
diff --git a/src/com/android/gallery3d/ui/BasicTexture.java b/src/com/android/gallery3d/ui/BasicTexture.java
index 68a5b7d32..78559270f 100644
--- a/src/com/android/gallery3d/ui/BasicTexture.java
+++ b/src/com/android/gallery3d/ui/BasicTexture.java
@@ -139,7 +139,7 @@ abstract class BasicTexture implements Texture {
// Returns the GL texture target for this texture (e.g. GL_TEXTURE_2D).
abstract protected int getTarget();
- public boolean isLoaded(GLCanvas canvas) {
+ public boolean isLoaded() {
return mState == STATE_LOADED;
}
@@ -160,10 +160,10 @@ abstract class BasicTexture implements Texture {
private void freeResource() {
GLCanvas canvas = mCanvasRef;
- if (canvas != null && isLoaded(canvas)) {
+ if (canvas != null && isLoaded()) {
canvas.unloadTexture(this);
}
- mState = BasicTexture.STATE_UNLOADED;
+ mState = STATE_UNLOADED;
setAssociatedCanvas(null);
}
diff --git a/src/com/android/gallery3d/ui/ExtTexture.java b/src/com/android/gallery3d/ui/ExtTexture.java
index d8267d1bf..9319d8ccd 100644
--- a/src/com/android/gallery3d/ui/ExtTexture.java
+++ b/src/com/android/gallery3d/ui/ExtTexture.java
@@ -60,12 +60,12 @@ public class ExtTexture extends BasicTexture {
GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
setAssociatedCanvas(canvas);
- mState = UploadedTexture.STATE_LOADED;
+ mState = STATE_LOADED;
}
@Override
protected boolean onBind(GLCanvas canvas) {
- if (!isLoaded(canvas)) {
+ if (!isLoaded()) {
uploadToCanvas(canvas);
}
diff --git a/src/com/android/gallery3d/ui/GLCanvasImpl.java b/src/com/android/gallery3d/ui/GLCanvasImpl.java
index 1efe5af4e..ff3e9e574 100644
--- a/src/com/android/gallery3d/ui/GLCanvasImpl.java
+++ b/src/com/android/gallery3d/ui/GLCanvasImpl.java
@@ -661,7 +661,7 @@ public class GLCanvasImpl implements GLCanvas {
// so we synchronized on the mUnboundTextures object.
public boolean unloadTexture(BasicTexture t) {
synchronized (mUnboundTextures) {
- if (!t.isLoaded(this)) return false;
+ if (!t.isLoaded()) return false;
mUnboundTextures.add(t.mId);
return true;
}
@@ -786,7 +786,7 @@ public class GLCanvasImpl implements GLCanvas {
} else {
setSize(texture.getWidth(), texture.getHeight());
- if (!texture.isLoaded(this)) texture.prepare(this);
+ if (!texture.isLoaded()) texture.prepare(this);
gl11ep.glFramebufferTexture2DOES(
GL11ExtensionPack.GL_FRAMEBUFFER_OES,
diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java
index 8b8299287..f78e6e6bf 100644
--- a/src/com/android/gallery3d/ui/GLRootView.java
+++ b/src/com/android/gallery3d/ui/GLRootView.java
@@ -252,8 +252,15 @@ public class GLRootView extends GLSurfaceView
// The GL Object has changed
Log.i(TAG, "GLObject has changed from " + mGL + " to " + gl);
}
- mGL = gl;
- mCanvas = new GLCanvasImpl(gl);
+ mRenderLock.lock();
+ try {
+ mGL = gl;
+ mCanvas = new GLCanvasImpl(gl);
+ BasicTexture.invalidateAllTextures();
+ } finally {
+ mRenderLock.unlock();
+ }
+
if (DEBUG_FPS || DEBUG_PROFILE) {
setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
} else {
@@ -272,7 +279,6 @@ 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 957229eb5..fa0e9cdc3 100644
--- a/src/com/android/gallery3d/ui/NinePatchTexture.java
+++ b/src/com/android/gallery3d/ui/NinePatchTexture.java
@@ -157,7 +157,7 @@ public class NinePatchTexture extends ResourceTexture {
@Override
public void draw(GLCanvas canvas, int x, int y, int w, int h) {
- if (!isLoaded(canvas)) {
+ if (!isLoaded()) {
mInstanceCache.clear();
}
diff --git a/src/com/android/gallery3d/ui/PhotoFallbackEffect.java b/src/com/android/gallery3d/ui/PhotoFallbackEffect.java
index cd930bdd3..3ca09ab96 100644
--- a/src/com/android/gallery3d/ui/PhotoFallbackEffect.java
+++ b/src/com/android/gallery3d/ui/PhotoFallbackEffect.java
@@ -87,7 +87,7 @@ public class PhotoFallbackEffect extends Animation implements SlotFilter {
}
private void drawEntry(GLCanvas canvas, Entry entry) {
- if (!entry.texture.isLoaded(canvas)) return;
+ if (!entry.texture.isLoaded()) return;
int w = entry.texture.getWidth();
int h = entry.texture.getHeight();
diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java
index 654fcd586..a15dd612c 100644
--- a/src/com/android/gallery3d/ui/PhotoView.java
+++ b/src/com/android/gallery3d/ui/PhotoView.java
@@ -1323,7 +1323,6 @@ public class PhotoView extends GLView {
return mPositionController.getPosition(index);
}
-
public PhotoFallbackEffect buildFallbackEffect(GLView root, GLCanvas canvas) {
Rect location = new Rect();
Utils.assertTrue(root.getBoundsOf(this, location));
diff --git a/src/com/android/gallery3d/ui/RawTexture.java b/src/com/android/gallery3d/ui/RawTexture.java
index e1af7d209..4c0d9d365 100644
--- a/src/com/android/gallery3d/ui/RawTexture.java
+++ b/src/com/android/gallery3d/ui/RawTexture.java
@@ -68,13 +68,13 @@ public class RawTexture extends BasicTexture {
0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, null);
mId = sTextureId[0];
- mState = UploadedTexture.STATE_LOADED;
+ mState = STATE_LOADED;
setAssociatedCanvas(canvas);
}
@Override
protected boolean onBind(GLCanvas canvas) {
- if (isLoaded(canvas)) return true;
+ if (isLoaded()) return true;
Log.w(TAG, "lost the content due to context change");
return false;
}
diff --git a/src/com/android/gallery3d/ui/TextureUploader.java b/src/com/android/gallery3d/ui/TextureUploader.java
index ff7830fa2..714b09795 100644
--- a/src/com/android/gallery3d/ui/TextureUploader.java
+++ b/src/com/android/gallery3d/ui/TextureUploader.java
@@ -36,8 +36,12 @@ public class TextureUploader implements OnGLIdleListener {
}
public synchronized void clear() {
- mFgTextures.clear();
- mBgTextures.clear();
+ while (!mFgTextures.isEmpty()) {
+ mFgTextures.pop().setIsUploading(false);
+ }
+ while (!mBgTextures.isEmpty()) {
+ mBgTextures.pop().setIsUploading(false);
+ }
}
// caller should hold synchronized on "this"
@@ -48,12 +52,16 @@ public class TextureUploader implements OnGLIdleListener {
}
public synchronized void addBgTexture(UploadedTexture t) {
+ if (t.isContentValid()) return;
mBgTextures.addLast(t);
+ t.setIsUploading(true);
queueSelfIfNeed();
}
public synchronized void addFgTexture(UploadedTexture t) {
+ if (t.isContentValid()) return;
mFgTextures.addLast(t);
+ t.setIsUploading(true);
queueSelfIfNeed();
}
@@ -64,7 +72,9 @@ public class TextureUploader implements OnGLIdleListener {
synchronized (this) {
if (deque.isEmpty()) break;
t = deque.removeFirst();
- if (t.isContentValid(canvas)) continue;
+ t.setIsUploading(false);
+ if (t.isContentValid()) continue;
+
// this has to be protected by the synchronized block
// to prevent the inner bitmap get recycled
t.updateContent(canvas);
diff --git a/src/com/android/gallery3d/ui/TileImageView.java b/src/com/android/gallery3d/ui/TileImageView.java
index 2f8f22333..0c6086d1c 100644
--- a/src/com/android/gallery3d/ui/TileImageView.java
+++ b/src/com/android/gallery3d/ui/TileImageView.java
@@ -457,7 +457,7 @@ public class TileImageView extends GLView {
int n = mActiveTiles.size();
for (int i = 0; i < n; i++) {
Tile tile = mActiveTiles.valueAt(i);
- if (!tile.isContentValid(canvas)) queueForDecode(tile);
+ if (!tile.isContentValid()) queueForDecode(tile);
}
}
@@ -558,7 +558,7 @@ public class TileImageView extends GLView {
tile = mUploadQueue.pop();
}
if (tile == null || quota <= 0) break;
- if (!tile.isContentValid(canvas)) {
+ if (!tile.isContentValid()) {
Utils.assertTrue(tile.mTileState == STATE_DECODED);
tile.updateContent(canvas);
--quota;
@@ -580,7 +580,7 @@ public class TileImageView extends GLView {
Tile tile = getTile(tx, ty, level);
if (tile != null) {
- if (!tile.isContentValid(canvas)) {
+ if (!tile.isContentValid()) {
if (tile.mTileState == STATE_DECODED) {
if (mUploadQuota > 0) {
--mUploadQuota;
@@ -609,7 +609,7 @@ public class TileImageView extends GLView {
static boolean drawTile(
Tile tile, GLCanvas canvas, RectF source, RectF target) {
while (true) {
- if (tile.isContentValid(canvas)) {
+ if (tile.isContentValid()) {
// offset source rectangle for the texture border.
source.offset(TILE_BORDER, TILE_BORDER);
canvas.drawTexture(tile, source, target);
diff --git a/src/com/android/gallery3d/ui/UploadedTexture.java b/src/com/android/gallery3d/ui/UploadedTexture.java
index 24c8d1db6..0fe506735 100644
--- a/src/com/android/gallery3d/ui/UploadedTexture.java
+++ b/src/com/android/gallery3d/ui/UploadedTexture.java
@@ -52,6 +52,9 @@ abstract class UploadedTexture extends BasicTexture {
@SuppressWarnings("unused")
private static final String TAG = "Texture";
private boolean mContentValid = true;
+
+ // indicate this textures is being uploaded in background
+ private boolean mIsUploading = false;
private boolean mOpaque = true;
private boolean mThrottled = false;
private static int sUploadedCount;
@@ -72,6 +75,14 @@ abstract class UploadedTexture extends BasicTexture {
}
}
+ protected void setIsUploading(boolean uploading) {
+ mIsUploading = uploading;
+ }
+
+ public boolean isUploading() {
+ return mIsUploading;
+ }
+
private static class BorderKey implements Cloneable {
public boolean vertical;
public Config config;
@@ -165,8 +176,8 @@ abstract class UploadedTexture extends BasicTexture {
/**
* Whether the content on GPU is valid.
*/
- public boolean isContentValid(GLCanvas canvas) {
- return isLoaded(canvas) && mContentValid;
+ public boolean isContentValid() {
+ return isLoaded() && mContentValid;
}
/**
@@ -174,7 +185,7 @@ abstract class UploadedTexture extends BasicTexture {
* @param canvas
*/
public void updateContent(GLCanvas canvas) {
- if (!isLoaded(canvas)) {
+ if (!isLoaded()) {
if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) {
return;
}
@@ -284,7 +295,7 @@ abstract class UploadedTexture extends BasicTexture {
// Update texture state.
setAssociatedCanvas(canvas);
mId = sTextureId[0];
- mState = UploadedTexture.STATE_LOADED;
+ mState = STATE_LOADED;
mContentValid = true;
} else {
mState = STATE_ERROR;
@@ -295,7 +306,7 @@ abstract class UploadedTexture extends BasicTexture {
@Override
protected boolean onBind(GLCanvas canvas) {
updateContent(canvas);
- return isContentValid(canvas);
+ return isContentValid();
}
@Override
diff --git a/tests/src/com/android/gallery3d/ui/TextureTest.java b/tests/src/com/android/gallery3d/ui/TextureTest.java
index be2356c8e..9e34083b8 100644
--- a/tests/src/com/android/gallery3d/ui/TextureTest.java
+++ b/tests/src/com/android/gallery3d/ui/TextureTest.java
@@ -20,10 +20,10 @@ import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.test.suitebuilder.annotation.SmallTest;
-import javax.microedition.khronos.opengles.GL11;
-
import junit.framework.TestCase;
+import javax.microedition.khronos.opengles.GL11;
+
@SmallTest
public class TextureTest extends TestCase {
@SuppressWarnings("unused")
@@ -34,7 +34,7 @@ public class TextureTest extends TestCase {
int mOpaqueCalled;
MyBasicTexture(GLCanvas canvas, int id) {
- super(canvas, id, BasicTexture.STATE_UNLOADED);
+ super(canvas, id, 0);
}
@Override
@@ -54,7 +54,7 @@ public class TextureTest extends TestCase {
}
void upload() {
- mState = STATE_LOADED;
+ mState |= STATE_BIT_LOADED;
}
}
@@ -76,13 +76,13 @@ public class TextureTest extends TestCase {
assertEquals(4, texture.getTextureWidth());
assertEquals(8, texture.getTextureHeight());
- assertFalse(texture.isLoaded(canvas));
+ assertFalse(texture.isLoaded());
texture.upload();
- assertTrue(texture.isLoaded(canvas));
+ assertTrue(texture.isLoaded());
// For a different GL, it's not loaded.
GLCanvas canvas2 = new GLCanvasImpl(new GLStub());
- assertFalse(texture.isLoaded(canvas2));
+ assertFalse(texture.isLoaded());
assertEquals(0, texture.mOnBindCalled);
assertEquals(0, texture.mOpaqueCalled);
@@ -143,20 +143,20 @@ public class TextureTest extends TestCase {
assertEquals(0, texture.mGetCalled);
texture.draw(canvas, 0, 0);
assertEquals(1, texture.mGetCalled);
- assertTrue(texture.isLoaded(canvas));
- assertTrue(texture.isContentValid(canvas));
+ assertTrue(texture.isLoaded());
+ assertTrue(texture.isContentValid());
// invalidate content and it should be freed.
texture.invalidateContent();
- assertFalse(texture.isContentValid(canvas));
+ assertFalse(texture.isContentValid());
assertEquals(1, texture.mFreeCalled);
- assertTrue(texture.isLoaded(canvas)); // But it's still loaded
+ assertTrue(texture.isLoaded()); // But it's still loaded
// draw it again and the bitmap should be fetched again.
texture.draw(canvas, 0, 0);
assertEquals(2, texture.mGetCalled);
- assertTrue(texture.isLoaded(canvas));
- assertTrue(texture.isContentValid(canvas));
+ assertTrue(texture.isLoaded());
+ assertTrue(texture.isContentValid());
// recycle the texture and it should be freed again.
texture.recycle();
@@ -168,7 +168,7 @@ public class TextureTest extends TestCase {
class MyTextureForMixed extends BasicTexture {
MyTextureForMixed(GLCanvas canvas, int id) {
- super(canvas, id, BasicTexture.STATE_UNLOADED);
+ super(canvas, id, 0);
}
@Override