summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOwen Lin <owenlin@google.com>2010-05-05 16:39:54 +0800
committerOwen Lin <owenlin@google.com>2010-05-07 11:14:08 +0800
commitcdf69cba3617c446e4fe9a92b4b4199c6ed36d01 (patch)
treed8d42b367315fd55bc0513de5914bf8675ba4dfa /src
parent92bbffb8dc01597dedc5809fd1fd69601fa8adaa (diff)
downloadLegacyCamera-cdf69cba3617c446e4fe9a92b4b4199c6ed36d01.zip
LegacyCamera-cdf69cba3617c446e4fe9a92b4b4199c6ed36d01.tar.gz
LegacyCamera-cdf69cba3617c446e4fe9a92b4b4199c6ed36d01.tar.bz2
Move the texture coordinate 0.5 pixel inner so that GL won't get garbage
data. So that GL won't get garbage data when do sampling. Change-Id: I58a88c2fb1166e0c3991edfd320c69633c89d102
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/Camera.java3
-rw-r--r--src/com/android/camera/ui/GLRootView.java3
-rw-r--r--src/com/android/camera/ui/Texture.java46
3 files changed, 31 insertions, 21 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index f59e020..7f928bd 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -45,6 +45,7 @@ import android.os.Bundle;
import android.os.Debug;
import android.os.Environment;
import android.os.Handler;
+import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
import android.os.SystemClock;
@@ -370,7 +371,7 @@ public class Camera extends NoSearchActivity implements View.OnClickListener,
}
private void addIdleHandler() {
- MessageQueue queue = getMainLooper().myQueue();
+ MessageQueue queue = Looper.myQueue();
queue.addIdleHandler(new MessageQueue.IdleHandler() {
public boolean queueIdle() {
ImageManager.ensureOSXCompatibleFolder();
diff --git a/src/com/android/camera/ui/GLRootView.java b/src/com/android/camera/ui/GLRootView.java
index 30adccb..dc10be4 100644
--- a/src/com/android/camera/ui/GLRootView.java
+++ b/src/com/android/camera/ui/GLRootView.java
@@ -525,8 +525,7 @@ public class GLRootView extends GLSurfaceView
}
texture.setSize(width, height);
- texture.setTexCoordSize(
- (float) width / newWidth, (float) height / newHeight);
+ texture.setTextureSize(newWidth, newHeight);
}
public synchronized void queueEventOrThrowException(Runnable runnable) {
diff --git a/src/com/android/camera/ui/Texture.java b/src/com/android/camera/ui/Texture.java
index 0d4b6a1..e1d6e39 100644
--- a/src/com/android/camera/ui/Texture.java
+++ b/src/com/android/camera/ui/Texture.java
@@ -26,8 +26,8 @@ public abstract class Texture {
protected int mWidth = UNSPECIFIED;
protected int mHeight = UNSPECIFIED;
- private float mTexCoordWidth = 1.0f;
- private float mTexCoordHeight = 1.0f;
+ private int mTextureWidth;
+ private int mTextureHeight;
protected Texture(GL11 gl, int id, int state) {
mGL = gl;
@@ -44,9 +44,14 @@ public abstract class Texture {
mHeight = height;
}
- protected void setTexCoordSize(float width, float height) {
- mTexCoordWidth = width;
- mTexCoordHeight = height;
+ /**
+ * Sets the size of the texture. Due to the limit of OpenGL, the texture
+ * size must be of power of 2, the size of the content may not be the size
+ * of the texture.
+ */
+ protected void setTextureSize(int width, int height) {
+ mTextureWidth = width;
+ mTextureHeight = height;
}
public int getId() {
@@ -102,8 +107,9 @@ public abstract class Texture {
int heightExt = Util.nextPowerOf2(height);
int format = GLUtils.getInternalFormat(bitmap);
int type = GLUtils.getType(bitmap);
- mTexCoordWidth = (float) width / widthExt;
- mTexCoordHeight = (float) height / heightExt;
+
+ mTextureWidth = widthExt;
+ mTextureHeight = heightExt;
gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format,
widthExt, heightExt, 0, format, type, null);
GLUtils.texSubImage2D(
@@ -155,16 +161,20 @@ public abstract class Texture {
}
public void getTextureCoords(float coord[], int offset) {
- float w = mTexCoordWidth;
- float h = mTexCoordHeight;
-
- coord[offset++] = 0;
- coord[offset++] = 0;
- coord[offset++] = w;
- coord[offset++] = 0;
- coord[offset++] = 0;
- coord[offset++] = h;
- coord[offset++] = w;
- coord[offset] = h;
+ // Shrinks the texture coordinates inner by 0.5 pixel so that GL won't
+ // sample on garbage data.
+ float left = 0.5f / mTextureWidth;
+ float right = (mWidth - 0.5f) / mTextureWidth;
+ float top = 0.5f / mTextureHeight;
+ float bottom = (mHeight - 0.5f) / mTextureHeight;
+
+ coord[offset++] = left;
+ coord[offset++] = top;
+ coord[offset++] = right;
+ coord[offset++] = top;
+ coord[offset++] = left;
+ coord[offset++] = bottom;
+ coord[offset++] = right;
+ coord[offset] = bottom;
}
}