From c3441bcb11dc414911dd5681fd01ca1d2dde74d2 Mon Sep 17 00:00:00 2001 From: Leif Hendrik Wilden Date: Mon, 12 Feb 2018 14:30:11 -0800 Subject: Switch Colors screensaver from a texture view to a surface view. Test: Verified screensaver renders properly on ATV. Bug: 69978677 Change-Id: I04a947b1cfda6fbeeb3d2847ab7874cee886a90f --- src/com/android/dreams/basic/Colors.java | 39 +++++++++------------- src/com/android/dreams/basic/ColorsGLRenderer.java | 5 +-- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/com/android/dreams/basic/Colors.java b/src/com/android/dreams/basic/Colors.java index aaacfcd..9a75146 100644 --- a/src/com/android/dreams/basic/Colors.java +++ b/src/com/android/dreams/basic/Colors.java @@ -16,10 +16,10 @@ package com.android.dreams.basic; -import android.graphics.SurfaceTexture; import android.service.dreams.DreamService; import android.util.Log; -import android.view.TextureView; +import android.view.SurfaceHolder; +import android.view.SurfaceView; import android.os.Handler; import android.os.HandlerThread; @@ -29,7 +29,7 @@ import android.os.HandlerThread; * This dream performs its rendering using OpenGL on a separate rendering thread. *

*/ -public class Colors extends DreamService implements TextureView.SurfaceTextureListener { +public class Colors extends DreamService implements SurfaceHolder.Callback { static final String TAG = Colors.class.getSimpleName(); static final boolean DEBUG = false; @@ -38,7 +38,7 @@ public class Colors extends DreamService implements TextureView.SurfaceTextureLi Log.v(TAG, String.format(fmt, args)); } - private TextureView mTextureView; + private SurfaceView mSurfaceView; // The handler thread and handler on which the GL renderer is running. private HandlerThread mRendererHandlerThread; @@ -53,8 +53,8 @@ public class Colors extends DreamService implements TextureView.SurfaceTextureLi setInteractive(false); - mTextureView = new TextureView(this); - mTextureView.setSurfaceTextureListener(this); + mSurfaceView = new SurfaceView(this); + mSurfaceView.getHolder().addCallback(this); if (mRendererHandlerThread == null) { mRendererHandlerThread = new HandlerThread(TAG); @@ -69,13 +69,13 @@ public class Colors extends DreamService implements TextureView.SurfaceTextureLi setInteractive(false); setLowProfile(true); setFullscreen(true); - setContentView(mTextureView); + setContentView(mSurfaceView); } @Override - public void onSurfaceTextureAvailable(final SurfaceTexture surface, - final int width, final int height) { - LOG("onSurfaceTextureAvailable(%s, %d, %d)", surface, width, height); + public void surfaceCreated(SurfaceHolder holder) { + LOG("surfaceCreated(%s, %d, %d)", holder.getSurface(), + holder.getSurfaceFrame().width(), holder.getSurfaceFrame().height()); mRendererHandler.post(new Runnable() { @Override @@ -83,16 +83,16 @@ public class Colors extends DreamService implements TextureView.SurfaceTextureLi if (mRenderer != null) { mRenderer.stop(); } - mRenderer = new ColorsGLRenderer(surface, width, height); + mRenderer = new ColorsGLRenderer(holder.getSurface(), + holder.getSurfaceFrame().width(), holder.getSurfaceFrame().height()); mRenderer.start(); } }); } @Override - public void onSurfaceTextureSizeChanged(SurfaceTexture surface, - final int width, final int height) { - LOG("onSurfaceTextureSizeChanged(%s, %d, %d)", surface, width, height); + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + LOG("surfaceChanged(%s, %d, %d, %d)", holder.getSurface(), format, width, height); mRendererHandler.post(new Runnable() { @Override @@ -105,8 +105,8 @@ public class Colors extends DreamService implements TextureView.SurfaceTextureLi } @Override - public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { - LOG("onSurfaceTextureDestroyed(%s)", surface); + public void surfaceDestroyed(SurfaceHolder holder) { + LOG("surfaceDestroyed(%s)", holder.getSurface()); mRendererHandler.post(new Runnable() { @Override @@ -124,12 +124,5 @@ public class Colors extends DreamService implements TextureView.SurfaceTextureLi } catch (InterruptedException e) { LOG("Error while waiting for renderer", e); } - - return true; - } - - @Override - public void onSurfaceTextureUpdated(SurfaceTexture surface) { - LOG("onSurfaceTextureUpdated(%s)", surface); } } diff --git a/src/com/android/dreams/basic/ColorsGLRenderer.java b/src/com/android/dreams/basic/ColorsGLRenderer.java index 91e4432..6c4b466 100644 --- a/src/com/android/dreams/basic/ColorsGLRenderer.java +++ b/src/com/android/dreams/basic/ColorsGLRenderer.java @@ -20,6 +20,7 @@ import android.graphics.Color; import android.graphics.SurfaceTexture; import android.util.Log; import android.view.Choreographer; +import android.view.Surface; import android.os.SystemClock; import javax.microedition.khronos.egl.EGL10; @@ -54,7 +55,7 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback { Log.v(TAG, String.format(fmt, args)); } - private final SurfaceTexture mSurface; + private final Surface mSurface; private int mWidth; private int mHeight; @@ -70,7 +71,7 @@ final class ColorsGLRenderer implements Choreographer.FrameCallback { private EGLContext mEglContext; private EGLSurface mEglSurface; - public ColorsGLRenderer(SurfaceTexture surface, int width, int height) { + public ColorsGLRenderer(Surface surface, int width, int height) { mSurface = surface; mWidth = width; mHeight = height; -- cgit v1.2.3