commit 6672d895baab4d237d0fbf430efb2f1253aa87d8
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Jun 27 12:08:03 2018 +0100

    I am pretty sure this time the flashing issues on Mali T880 r12 driver are finally fixed.
    
    The fix: a queue of FBOs render to, just like before, but this time in DistortedScreen we blit not the current FBO, but the one computed several frames ago.
    
    This of course introduces a delay and uses more memory, but it appears to work and does not seem to have any effects on speed.

diff --git a/src/main/java/org/distorted/library/main/Distorted.java b/src/main/java/org/distorted/library/main/Distorted.java
index cc1b7eb..e44f451 100644
--- a/src/main/java/org/distorted/library/main/Distorted.java
+++ b/src/main/java/org/distorted/library/main/Distorted.java
@@ -82,8 +82,12 @@ public class Distorted
    * Work around bugs in ARM Mali driver by, instead to a single FBO, rendering to a circular queue
    * of FBO_QUEUE_SIZE FBOs. (otherwise we sometimes get a 'full pipeline flush' and the end result
    * might be missing part of the Objects)
+   *
+   * This bug only exists on Mali driver r12. TODO: on other platforms, make this equal to 1.
+   *
+   * https://community.arm.com/graphics/f/discussions/10285/opengl-es-3-1-on-mali-t880-flashes
    */
-  public static final int FBO_QUEUE_SIZE = 4;
+  public static final int FBO_QUEUE_SIZE = 3;
 
   private static boolean mInitialized=false;
 
@@ -125,7 +129,12 @@ public class Distorted
     final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
     final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
     android.util.Log.e("DISTORTED", "Using OpenGL ES "+configurationInfo.getGlEsVersion());
-
+    /*
+    android.util.Log.e("DISTORTED", "GLSL Version "+GLES31.glGetString(GLES31.GL_SHADING_LANGUAGE_VERSION));
+    android.util.Log.e("DISTORTED", "GL Version "  +GLES31.glGetString(GLES31.GL_VERSION));
+    android.util.Log.e("DISTORTED", "GL Vendor "   +GLES31.glGetString(GLES31.GL_VENDOR));
+    android.util.Log.e("DISTORTED", "GL Renderer " +GLES31.glGetString(GLES31.GL_RENDERER));
+    */
     GLSL = ( (configurationInfo.reqGlEsVersion>>16)>=3 ? 310 : 100 );
     GLSL_VERSION= (GLSL==100 ? "#version 100\n" : "#version 310 es\n");
 
diff --git a/src/main/java/org/distorted/library/main/DistortedScreen.java b/src/main/java/org/distorted/library/main/DistortedScreen.java
index 3044b76..f25cf41 100644
--- a/src/main/java/org/distorted/library/main/DistortedScreen.java
+++ b/src/main/java/org/distorted/library/main/DistortedScreen.java
@@ -55,7 +55,7 @@ public class DistortedScreen extends DistortedFramebuffer
   private static MatrixEffectMove mMoveEffect = new MatrixEffectMove( new Static3D(5,5,0) );
   ///// END DEBUGGING //////////////////////////
 
-  private int mCurrFBO;
+  private int mCurrFBO, mLastFBO;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
@@ -70,6 +70,7 @@ public class DistortedScreen extends DistortedFramebuffer
     super(Distorted.FBO_QUEUE_SIZE,1,BOTH_DEPTH_STENCIL, TYPE_SYST, 1,1);
     mShowFPS = false;
     mCurrFBO = 0;
+    mLastFBO = 1;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -83,6 +84,9 @@ public class DistortedScreen extends DistortedFramebuffer
  */
   public int render(long time)
     {
+    if( ++mCurrFBO>=Distorted.FBO_QUEUE_SIZE ) mCurrFBO=0;
+    if( ++mLastFBO>=Distorted.FBO_QUEUE_SIZE ) mLastFBO=0;
+
     if( mShowFPS )
       {
       if( lastTime==0 ) lastTime = time;
@@ -106,7 +110,14 @@ public class DistortedScreen extends DistortedFramebuffer
     int numrender = super.render(time,mCurrFBO);
 
     GLES31.glBindFramebuffer(GLES31.GL_FRAMEBUFFER, 0);
-    setAsInput(mCurrFBO,0);
+
+    // workaround for the Mali issues: blit the framebuffer we have computed Distorted.FBO_QUEUE_SIZE
+    // frames ago. Looks like FBO_QUEUE_SIZE=2 solves the issue already but I decided to play it safe and
+    // make it equal to 3.
+    // This of course introduces a delay and uses more memory, but it does not appear to have any effect
+    // on speed. Maybe a slight positive effect if any!
+    setAsInput(mLastFBO,0);
+
     GLES31.glColorMask(true,true,true,true);
     GLES31.glDepthMask(false);
     GLES31.glDisable(GLES31.GL_STENCIL_TEST);
@@ -120,9 +131,6 @@ public class DistortedScreen extends DistortedFramebuffer
       fpsEffects.drawPriv(fpsW / 2.0f, fpsH / 2.0f, fpsMesh, this, time, 0);
       }
 
-    mCurrFBO++;
-    if( mCurrFBO>=Distorted.FBO_QUEUE_SIZE ) mCurrFBO=0;
-
     return numrender+1;
     }
 
