| | |
| | | import android.opengl.Matrix;
|
| | | import android.util.Log;
|
| | | import android.view.Surface;
|
| | |
|
| | | import java.nio.Buffer;
|
| | | import java.nio.ByteBuffer;
|
| | | import javax.microedition.khronos.egl.EGL10;
|
| | | import javax.microedition.khronos.egl.EGLConfig;
|
| | |
| | | }
|
| | | checkEglError("before makeCurrent");
|
| | | if (!mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) {
|
| | | throw new RuntimeException("eglMakeCurrent failed");
|
| | | //throw new RuntimeException("eglMakeCurrent failed");
|
| | | }
|
| | | }
|
| | | /**
|
| | |
| | | mFrameSyncObject.wait(TIMEOUT_MS);
|
| | | if (!mFrameAvailable) {
|
| | | // TODO: if "spurious wakeup", continue while loop
|
| | | throw new RuntimeException("Surface frame wait timed out");
|
| | | //throw new RuntimeException("Surface frame wait timed out");
|
| | | return;
|
| | | }
|
| | | } catch (InterruptedException ie) {
|
| | | // shouldn't happen
|
| | |
| | | }
|
| | | @Override
|
| | | public void onFrameAvailable(SurfaceTexture st) {
|
| | | if (VERBOSE) Log.d(TAG, "new frame available");
|
| | | //if (VERBOSE)
|
| | | Log.d(TAG, "new frame available");
|
| | | synchronized (mFrameSyncObject) {
|
| | | if (mFrameAvailable) {
|
| | | throw new RuntimeException("mFrameAvailable already set, frame could be dropped");
|
| | |
| | | mFrameAvailable = true;
|
| | | mFrameSyncObject.notifyAll();
|
| | | }
|
| | |
|
| | | }
|
| | | /**
|
| | | * Checks for EGL errors.
|
| | |
| | | failed = true;
|
| | | }
|
| | | if (failed) {
|
| | | throw new RuntimeException("EGL error encountered (see log)");
|
| | | //throw new RuntimeException("EGL error encountered (see log)");
|
| | | }
|
| | | }
|
| | |
|
| | | public byte[] readPixels()
|
| | | {
|
| | | ByteBuffer buf = ByteBuffer.allocateDirect( 640 * 480 * 4);
|
| | | mTextureRender.readPixels(buf);
|
| | | byte[] newbuf = new byte[640 * 480 * 4];
|
| | | buf.get(newbuf);
|
| | | return newbuf;
|
| | | }
|
| | | } |