OSDN Git Service

Fix b/5392171 and b/5389281.
authorYuli Huang <yuli@google.com>
Tue, 11 Oct 2011 13:23:22 +0000 (21:23 +0800)
committerYuli Huang <yuli@google.com>
Wed, 12 Oct 2011 09:02:27 +0000 (17:02 +0800)
1. Fix b/5392171 by moving effect context creation into Filter to make
sure it'd be created when needed.
2. Revise the fix for b/5389281 by clearing surface background even
there's no photo.

Change-Id: I212a552291c7df28b75a909bf6560634ba061e9f

src/com/android/gallery3d/photoeditor/FilterStack.java
src/com/android/gallery3d/photoeditor/PhotoView.java
src/com/android/gallery3d/photoeditor/RendererUtils.java
src/com/android/gallery3d/photoeditor/filters/Filter.java

index e84c92e..7a15509 100644 (file)
@@ -238,8 +238,10 @@ public class FilterStack {
             @Override
             public void run() {
                 Filter.releaseContext();
+                // Textures will be automatically deleted when GL context is lost.
+                photoView.setPhoto(null, false);
+                source = null;
                 for (int i = 0; i < buffers.length; i++) {
-                    // Textures will be automatically deleted when GL context is lost.
                     buffers[i] = null;
                 }
             }
@@ -249,14 +251,6 @@ public class FilterStack {
 
     public void onResume() {
         photoView.onResume();
-        photoView.queue(new Runnable() {
-
-            @Override
-            public void run() {
-                // Create effect context after GL context is created or recreated.
-                Filter.createContextWithCurrentGlContext();
-            }
-        });
         paused = false;
     }
 }
index b2e5103..edb3624 100644 (file)
@@ -153,6 +153,7 @@ public class PhotoView extends GLSurfaceView {
             if (!queue.isEmpty()) {
                 requestRender();
             }
+            RendererUtils.renderBackground();
             if (photo != null) {
                 RendererUtils.renderTexture(renderContext, photo.texture(), viewWidth, viewHeight);
             }
index a0cd598..ff593d4 100644 (file)
@@ -174,6 +174,11 @@ public class RendererUtils {
         context.posVertices = createVerticesBuffer(vertices);
     }
 
+    public static void renderBackground() {
+        GLES20.glClearColor(0, 0, 0, 1);
+        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
+    }
+
     public static void renderTexture(
             RenderContext context, int texture, int viewWidth, int viewHeight) {
         // Use our shader program
@@ -204,8 +209,6 @@ public class RendererUtils {
         GLES20.glUniform1i(context.texSamplerHandle, 0);
 
         // Draw!
-        GLES20.glClearColor(0, 0, 0, 1);
-        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
         GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
     }
 
index 1fd1f7e..8c00dbb 100644 (file)
@@ -37,10 +37,9 @@ public abstract class Filter {
 
     private boolean isValid;
 
-    public static void createContextWithCurrentGlContext() {
-        context = EffectContext.createWithCurrentGlContext();
-    }
-
+    /**
+     * Filter context should be released before the current GL context is lost.
+     */
     public static void releaseContext() {
         if (context != null) {
             // Release all effects created with the releasing context.
@@ -63,6 +62,9 @@ public abstract class Filter {
     protected Effect getEffect(String name) {
         Effect effect = effects.get(this);
         if (effect == null) {
+            if (context == null) {
+                context = EffectContext.createWithCurrentGlContext();
+            }
             effect = context.getFactory().createEffect(name);
             effect.setParameter("tile_size", DEFAULT_TILE_SIZE);
             effects.put(this, effect);