Add isOpaque() to Texture, which is used to determine whether to disable GL_BLEND.
Fix a possible breakage in https://android-git.corp.google.com/g/#change,52757.
Change-Id: I0857e4244e31be9be8c2e29d563d926cca45ceb6
diff --git a/new3d/src/com/android/gallery3d/ui/BitmapTexture.java b/new3d/src/com/android/gallery3d/ui/BitmapTexture.java
index f455a78..290d269 100644
--- a/new3d/src/com/android/gallery3d/ui/BitmapTexture.java
+++ b/new3d/src/com/android/gallery3d/ui/BitmapTexture.java
@@ -2,6 +2,7 @@
import android.graphics.Bitmap;
import android.opengl.GLUtils;
+import android.util.Log;
import javax.microedition.khronos.opengles.GL11;
import javax.microedition.khronos.opengles.GL11Ext;
@@ -10,6 +11,7 @@
@SuppressWarnings("unused")
private static final String TAG = "Texture";
+ private boolean mOpaque;
protected BitmapTexture() {
super(null, 0, STATE_UNLOADED);
@@ -60,8 +62,11 @@
int widthExt = Util.nextPowerOf2(width);
int heightExt = Util.nextPowerOf2(height);
int format = GLUtils.getInternalFormat(bitmap);
+ mOpaque =
+ (format == GL11.GL_RGB || format == GL11.GL_LUMINANCE);
int type = GLUtils.getType(bitmap);
+
mTextureWidth = widthExt;
mTextureHeight = heightExt;
gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format,
@@ -106,4 +111,9 @@
}
return true;
}
+
+ @Override
+ public boolean isOpaque() {
+ return mOpaque ;
+ }
}
diff --git a/new3d/src/com/android/gallery3d/ui/ColorTexture.java b/new3d/src/com/android/gallery3d/ui/ColorTexture.java
index a037685..ada5ac8 100644
--- a/new3d/src/com/android/gallery3d/ui/ColorTexture.java
+++ b/new3d/src/com/android/gallery3d/ui/ColorTexture.java
@@ -16,6 +16,10 @@
package com.android.gallery3d.ui;
+import android.graphics.Color;
+
+import javax.microedition.khronos.opengles.GL11;
+
class ColorTexture implements Texture {
private int mColor;
@@ -30,4 +34,9 @@
public void draw(GLRootView root, int x, int y, int w, int h) {
root.drawColor(x, y, w, h, mColor);
}
+
+ public boolean isOpaque() {
+ int alpha = mColor >>> 24;
+ return alpha != 0;
+ }
}
diff --git a/new3d/src/com/android/gallery3d/ui/GLRootView.java b/new3d/src/com/android/gallery3d/ui/GLRootView.java
index abb2325..a53aa12 100644
--- a/new3d/src/com/android/gallery3d/ui/GLRootView.java
+++ b/new3d/src/com/android/gallery3d/ui/GLRootView.java
@@ -300,7 +300,7 @@
}
}
- public void drawRect(int x, int y, int width, int height) {
+ private void drawRect(int x, int y, int width, int height) {
float matrix[] = mMatrixValues;
mTransformation.getMatrix().getValues(matrix);
drawRect(x, y, width, height, matrix);
@@ -331,7 +331,7 @@
public void drawNinePatch(
NinePatchTexture tex, int x, int y, int width, int height) {
-
+ isToEnableGL_BLEND(tex);
NinePatchChunk chunk = tex.getNinePatchChunk();
// The code should be easily extended to handle the general cases by
@@ -549,6 +549,7 @@
}
public void drawColor(int x, int y, int width, int height, int color) {
+ setBlendEnabled(color);
float alpha = mTransformation.getAlpha();
GL11 gl = mGL;
if (mTexture2DEnabled) {
@@ -571,7 +572,7 @@
public void drawTexture(BasicTexture texture,
int x, int y, int width, int height, float alpha) {
-
+ isToEnableGL_BLEND(texture);
if (!mTexture2DEnabled) {
mGL.glEnable(GL11.GL_TEXTURE_2D);
mTexture2DEnabled = true;
@@ -608,6 +609,23 @@
}
}
+ private void isToEnableGL_BLEND(Texture texture) {
+ if (!texture.isOpaque()) {
+ mGL.glEnable(GL11.GL_BLEND);
+ } else {
+ mGL.glDisable(GL11.GL_BLEND);
+ }
+ }
+
+ private void setBlendEnabled(int color) {
+ int alpha = Color.alpha(color);
+ if (alpha != 0) {
+ mGL.glEnable(GL11.GL_BLEND);
+ } else {
+ mGL.glDisable(GL11.GL_BLEND);
+ }
+ }
+
private static boolean isMatrixRotatedOrFlipped(float matrix[]) {
return matrix[Matrix.MSKEW_X] != 0 || matrix[Matrix.MSKEW_Y] != 0
|| matrix[Matrix.MSCALE_X] < 0 || matrix[Matrix.MSCALE_Y] > 0;
diff --git a/new3d/src/com/android/gallery3d/ui/MediaSetSlotAdapter.java b/new3d/src/com/android/gallery3d/ui/MediaSetSlotAdapter.java
index 9844582..28f8866 100644
--- a/new3d/src/com/android/gallery3d/ui/MediaSetSlotAdapter.java
+++ b/new3d/src/com/android/gallery3d/ui/MediaSetSlotAdapter.java
@@ -124,5 +124,9 @@
}
}
+ public void freeSlot(int index, DisplayItemPanel panel) {
+ // TODO: Need to implement the method.
+ }
+
}
diff --git a/new3d/src/com/android/gallery3d/ui/RawTexture.java b/new3d/src/com/android/gallery3d/ui/RawTexture.java
index 35eb3bf..5b42ec0 100644
--- a/new3d/src/com/android/gallery3d/ui/RawTexture.java
+++ b/new3d/src/com/android/gallery3d/ui/RawTexture.java
@@ -51,4 +51,9 @@
public void drawBack(GLRootView root, int x, int y, int w, int h) {
root.drawTexture(this, x, y, w, h, 1f);
}
+
+ @Override
+ public boolean isOpaque() {
+ return false;
+ }
}
diff --git a/new3d/src/com/android/gallery3d/ui/Texture.java b/new3d/src/com/android/gallery3d/ui/Texture.java
index 1515bf0..c8a3ebc 100644
--- a/new3d/src/com/android/gallery3d/ui/Texture.java
+++ b/new3d/src/com/android/gallery3d/ui/Texture.java
@@ -19,4 +19,5 @@
interface Texture {
public void draw(GLRootView root, int x, int y);
public void draw(GLRootView root, int x, int y, int w, int h);
+ public boolean isOpaque();
}