@@ -80,6 +80,7 @@ final class ElectronBeam {
8080 private EGLContext mEglContext ;
8181 private EGLSurface mEglSurface ;
8282 private boolean mSurfaceVisible ;
83+ private float mSurfaceAlpha ;
8384
8485 // Texture names. We only use one texture, which contains the screenshot.
8586 private final int [] mTexNames = new int [1 ];
@@ -90,9 +91,20 @@ final class ElectronBeam {
9091 private final FloatBuffer mVertexBuffer = createNativeFloatBuffer (8 );
9192 private final FloatBuffer mTexCoordBuffer = createNativeFloatBuffer (8 );
9293
94+ /**
95+ * Animates an electron beam warming up.
96+ */
9397 public static final int MODE_WARM_UP = 0 ;
98+
99+ /**
100+ * Animates an electron beam shutting off.
101+ */
94102 public static final int MODE_COOL_DOWN = 1 ;
95- public static final int MODE_BLANK = 2 ;
103+
104+ /**
105+ * Animates a simple dim layer to fade the contents of the screen in or out progressively.
106+ */
107+ public static final int MODE_FADE = 2 ;
96108
97109 public ElectronBeam (Display display ) {
98110 mDisplay = display ;
@@ -138,7 +150,7 @@ public boolean prepare(int mode) {
138150
139151 private boolean tryPrepare () {
140152 if (createSurface ()) {
141- if (mMode == MODE_BLANK ) {
153+ if (mMode == MODE_FADE ) {
142154 return true ;
143155 }
144156 return createEglContext ()
@@ -182,7 +194,7 @@ public boolean draw(float level) {
182194 return false ;
183195 }
184196
185- if (mMode == MODE_BLANK ) {
197+ if (mMode == MODE_FADE ) {
186198 return showSurface (1.0f - level );
187199 }
188200
@@ -504,7 +516,7 @@ private boolean createSurface() {
504516 if (mSurface == null ) {
505517 try {
506518 int flags ;
507- if (mMode == MODE_BLANK ) {
519+ if (mMode == MODE_FADE ) {
508520 flags = Surface .FX_SURFACE_DIM | Surface .HIDDEN ;
509521 } else {
510522 flags = Surface .OPAQUE | Surface .HIDDEN ;
@@ -579,11 +591,12 @@ private void destroySurface() {
579591 }
580592 mSurface = null ;
581593 mSurfaceVisible = false ;
594+ mSurfaceAlpha = 0f ;
582595 }
583596 }
584597
585598 private boolean showSurface (float alpha ) {
586- if (!mSurfaceVisible ) {
599+ if (!mSurfaceVisible || mSurfaceAlpha != alpha ) {
587600 Surface .openTransaction ();
588601 try {
589602 mSurface .setLayer (ELECTRON_BEAM_LAYER );
@@ -593,6 +606,7 @@ private boolean showSurface(float alpha) {
593606 Surface .closeTransaction ();
594607 }
595608 mSurfaceVisible = true ;
609+ mSurfaceAlpha = alpha ;
596610 }
597611 return true ;
598612 }
@@ -683,5 +697,6 @@ public void dump(PrintWriter pw) {
683697 pw .println (" mDisplayWidth=" + mDisplayWidth );
684698 pw .println (" mDisplayHeight=" + mDisplayHeight );
685699 pw .println (" mSurfaceVisible=" + mSurfaceVisible );
700+ pw .println (" mSurfaceAlpha=" + mSurfaceAlpha );
686701 }
687702}
0 commit comments