OSDN Git Service

Fix flashing in "Make available offline".
authorOwen Lin <owenlin@google.com>
Wed, 4 Apr 2012 04:22:59 +0000 (12:22 +0800)
committerOwen Lin <owenlin@google.com>
Thu, 5 Apr 2012 09:54:28 +0000 (17:54 +0800)
Change-Id: I84f0896c6038eb21d32e0d5fe0cafec5d339e6ec

src/com/android/gallery3d/ui/FadeInTexture.java
src/com/android/gallery3d/ui/GLCanvasImpl.java

index c88fb47..17ab715 100644 (file)
@@ -21,6 +21,7 @@ import com.android.gallery3d.common.Utils;
 // FadeInTexture is a texture which begins with a color, then gradually animates
 // into a given texture.
 public class FadeInTexture implements Texture {
+    @SuppressWarnings("unused")
     private static final String TAG = "FadeInTexture";
 
     // The duration of the animation in milliseconds
index 6411a31..f822951 100644 (file)
@@ -441,8 +441,8 @@ public class GLCanvasImpl implements GLCanvas {
 
     private void drawMixed(BasicTexture from, int toColor,
             float ratio, int x, int y, int width, int height, float alpha) {
-
-        if (ratio <= 0) {
+        // change from 0 to 0.01f to prevent getting divided by zero below
+        if (ratio <= 0.01f) {
             drawTexture(from, x, y, width, height, alpha);
             return;
         } else if (ratio >= 1) {
@@ -459,30 +459,26 @@ public class GLCanvasImpl implements GLCanvas {
         //
         // The formula we want:
         //     alpha * ((1 - ratio) * from + ratio * to)
+        //
         // The formula that GL supports is in the form of:
-        //     combo * (modulate * from) + (1 - combo) * to
+        //     combo * from + (1 - combo) * to * scale
         //
-        // So, we have combo = 1 - alpha * ratio
-        //     and     modulate = alpha * (1f - ratio) / combo
+        // So, we have combo = alpha * (1 - ratio)
+        //     and     scale = alpha * ratio / (1 - combo)
         //
-        float comboRatio = 1 - alpha * ratio;
-
-        // handle the case that (1 - comboRatio) == 0
-        if (alpha < OPAQUE_ALPHA) {
-            mGLState.setTextureAlpha(alpha * (1f - ratio) / comboRatio);
-        } else {
-            mGLState.setTextureAlpha(1f);
-        }
+        float combo = alpha * (1 - ratio);
+        float scale = alpha * ratio / (1 - combo);
 
         // Interpolate the RGB and alpha values between both textures.
         mGLState.setTexEnvMode(GL11.GL_COMBINE);
+
         // Specify the interpolation factor via the alpha component of
         // GL_TEXTURE_ENV_COLORs.
         // RGB component are get from toColor and will used as SRC1
-        float colorAlpha = (float) (toColor >>> 24) / (0xff * 0xff);
-        setTextureColor(((toColor >>> 16) & 0xff) * colorAlpha,
-                ((toColor >>> 8) & 0xff) * colorAlpha,
-                (toColor & 0xff) * colorAlpha, comboRatio);
+        float colorScale = scale * (toColor >>> 24) / (0xff * 0xff);
+        setTextureColor(((toColor >>> 16) & 0xff) * colorScale,
+                ((toColor >>> 8) & 0xff) * colorScale,
+                (toColor & 0xff) * colorScale, combo);
         gl.glTexEnvfv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, mTextureColor, 0);
 
         gl.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_COMBINE_RGB, GL11.GL_INTERPOLATE);