diff options
author | Romain Guy <romainguy@google.com> | 2011-06-10 15:40:36 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2011-06-10 15:44:09 -0700 |
commit | 451ce44a18e4c48f8a43aa250957f76967a35d31 (patch) | |
tree | d9424d45f00843e584097c1dec19a53ec6f96e3c /tests/HwAccelerationTest/src/com/android/test/hwui | |
parent | 181d0a6ccedee03789919d53c46540a8df751896 (diff) | |
download | frameworks_base-451ce44a18e4c48f8a43aa250957f76967a35d31.zip frameworks_base-451ce44a18e4c48f8a43aa250957f76967a35d31.tar.gz frameworks_base-451ce44a18e4c48f8a43aa250957f76967a35d31.tar.bz2 |
Add onSurfaceTextureDestroyed() callback.
This is needed for Renderscript and it also makes implementations
of TextureView cleaner. This change also hooks up the onSurfaceTextureSizeCHanged()
callback whenever the view size changes.
Change-Id: I2f972ee4504d800329defefacf32cf20547d31a3
Diffstat (limited to 'tests/HwAccelerationTest/src/com/android/test/hwui')
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java | 49 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java | 65 |
2 files changed, 78 insertions, 36 deletions
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java index 7f97098..9bb5ba8 100644 --- a/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/GLTextureViewActivity.java @@ -52,13 +52,7 @@ public class GLTextureViewActivity extends Activity implements TextureView.Surfa } @Override - protected void onDestroy() { - super.onDestroy(); - mRenderThread.finish(); - } - - @Override - public void onSurfaceTextureAvailable(SurfaceTexture surface) { + public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { mRenderThread = new RenderThread(surface); mRenderThread.start(); @@ -81,6 +75,16 @@ public class GLTextureViewActivity extends Activity implements TextureView.Surfa public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { } + @Override + public void onSurfaceTextureDestroyed(SurfaceTexture surface) { + mRenderThread.finish(); + try { + mRenderThread.join(); + } catch (InterruptedException e) { + Log.e(RenderThread.LOG_TAG, "Could not wait for render thread"); + } + } + private static class RenderThread extends Thread { private static final String LOG_TAG = "GLTextureView"; @@ -108,26 +112,23 @@ public class GLTextureViewActivity extends Activity implements TextureView.Surfa public void run() { initGL(); - float red = 0.0f; + float red = 1.0f; while (!mFinished) { checkCurrent(); + Log.d(LOG_TAG, "Rendering frame"); + GLES20.glClearColor(red, 0.0f, 0.0f, 1.0f); - int error = GLES20.glGetError(); - if (error != GLES20.GL_NO_ERROR) { - Log.w(LOG_TAG, "GL error = 0x" + Integer.toHexString(error)); - } + checkGlError(); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); - error = GLES20.glGetError(); - if (error != GLES20.GL_NO_ERROR) { - Log.w(LOG_TAG, "GL error = 0x" + Integer.toHexString(error)); - } + checkGlError(); if (!mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) { throw new RuntimeException("Cannot swap buffers"); } - + checkEglError(); + try { Thread.sleep(20); } catch (InterruptedException e) { @@ -141,6 +142,20 @@ public class GLTextureViewActivity extends Activity implements TextureView.Surfa finishGL(); } + private void checkEglError() { + int error = mEgl.eglGetError(); + if (error != EGL10.EGL_SUCCESS) { + Log.w(LOG_TAG, "EGL error = 0x" + Integer.toHexString(error)); + } + } + + private void checkGlError() { + int error = GLES20.glGetError(); + if (error != GLES20.GL_NO_ERROR) { + Log.w(LOG_TAG, "GL error = 0x" + Integer.toHexString(error)); + } + } + private void finishGL() { mEgl.eglDestroyContext(mEglDisplay, mEglContext); mEgl.eglDestroySurface(mEglDisplay, mEglSurface); diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java index 2feda57..fa2e39a 100644 --- a/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/TextureViewActivity.java @@ -16,6 +16,7 @@ package com.android.test.hwui; +import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.app.Activity; @@ -25,6 +26,7 @@ import android.os.Bundle; import android.view.Gravity; import android.view.TextureView; import android.view.View; +import android.widget.Button; import android.widget.FrameLayout; import java.io.IOException; @@ -33,27 +35,44 @@ import java.io.IOException; public class TextureViewActivity extends Activity implements TextureView.SurfaceTextureListener { private Camera mCamera; private TextureView mTextureView; + private FrameLayout mContent; + private AnimatorSet mAnimatorSet; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mContent = new FrameLayout(this); + mTextureView = new TextureView(this); mTextureView.setSurfaceTextureListener(this); - setContentView(mTextureView, new FrameLayout.LayoutParams(500, 400, Gravity.CENTER)); - } + Button button = new Button(this); + button.setText("Remove/Add"); + button.setOnClickListener(new View.OnClickListener() { + private boolean mAdded = true; - @Override - protected void onDestroy() { - super.onDestroy(); + @Override + public void onClick(View v) { + if (mAdded) { + mAnimatorSet.cancel(); + mContent.removeView(mTextureView); + } else { + mContent.addView(mTextureView); + } + mAdded = !mAdded; + } + }); - mCamera.stopPreview(); - mCamera.release(); + mContent.addView(mTextureView, new FrameLayout.LayoutParams(500, 400, Gravity.CENTER)); + mContent.addView(button, new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, + Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)); + setContentView(mContent); } @Override - public void onSurfaceTextureAvailable(SurfaceTexture surface) { + public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { mCamera = Camera.open(); try { @@ -66,27 +85,35 @@ public class TextureViewActivity extends Activity implements TextureView.Surface mTextureView.setCameraDistance(5000); - ObjectAnimator animator = ObjectAnimator.ofFloat(mTextureView, "rotationY", 0.0f, 360.0f); - animator.setRepeatMode(ObjectAnimator.REVERSE); - animator.setRepeatCount(ObjectAnimator.INFINITE); - animator.setDuration(4000); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + ObjectAnimator rotationY = ObjectAnimator.ofFloat(mTextureView, "rotationY", 0.0f, 360.0f); + rotationY.setRepeatMode(ObjectAnimator.REVERSE); + rotationY.setRepeatCount(ObjectAnimator.INFINITE); + rotationY.setDuration(4000); + rotationY.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { ((View) mTextureView.getParent()).invalidate(); } }); - animator.start(); - animator = ObjectAnimator.ofFloat(mTextureView, "alpha", 1.0f, 0.0f); - animator.setRepeatMode(ObjectAnimator.REVERSE); - animator.setRepeatCount(ObjectAnimator.INFINITE); - animator.setDuration(4000); - animator.start(); + ObjectAnimator alpha = ObjectAnimator.ofFloat(mTextureView, "alpha", 1.0f, 0.0f); + alpha.setRepeatMode(ObjectAnimator.REVERSE); + alpha.setRepeatCount(ObjectAnimator.INFINITE); + alpha.setDuration(4000); + + mAnimatorSet = new AnimatorSet(); + mAnimatorSet.play(alpha).with(rotationY); + mAnimatorSet.start(); } @Override public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { // Ignored, the Camera does all the work for us } + + @Override + public void onSurfaceTextureDestroyed(SurfaceTexture surface) { + mCamera.stopPreview(); + mCamera.release(); + } } |