From 8f0095cd33558e9cc8a440047908e53b68906f5f Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Mon, 2 May 2011 17:24:22 -0700 Subject: Allows to render with an OpenGL context inside a TextureView. Change-Id: I59453f7fc3997f0502a1c5d325d37fed376fabc7 --- opengl/java/com/google/android/gles_jni/EGLImpl.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'opengl/java/com') diff --git a/opengl/java/com/google/android/gles_jni/EGLImpl.java b/opengl/java/com/google/android/gles_jni/EGLImpl.java index 8a7124d..f162d40 100644 --- a/opengl/java/com/google/android/gles_jni/EGLImpl.java +++ b/opengl/java/com/google/android/gles_jni/EGLImpl.java @@ -18,10 +18,10 @@ package com.google.android.gles_jni; import javax.microedition.khronos.egl.*; +import android.graphics.SurfaceTexture; import android.view.Surface; import android.view.SurfaceView; import android.view.SurfaceHolder; -import android.view.View; public class EGLImpl implements EGL10 { private EGLContextImpl mContext = new EGLContextImpl(-1); @@ -71,19 +71,28 @@ public class EGLImpl implements EGL10 { } public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) { - Surface sur; + Surface sur = null; if (native_window instanceof SurfaceView) { SurfaceView surfaceView = (SurfaceView)native_window; sur = surfaceView.getHolder().getSurface(); } else if (native_window instanceof SurfaceHolder) { SurfaceHolder holder = (SurfaceHolder)native_window; sur = holder.getSurface(); + } + + int eglSurfaceId; + if (sur != null) { + eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list); + } else if (native_window instanceof SurfaceTexture) { + eglSurfaceId = _eglCreateWindowSurfaceTexture(display, config, + ((SurfaceTexture) native_window).mSurfaceTexture, attrib_list); } else { throw new java.lang.UnsupportedOperationException( "eglCreateWindowSurface() can only be called with an instance of " + - "SurfaceView or SurfaceHolder at the moment, this will be fixed later."); + "SurfaceView, SurfaceHolder or SurfaceTexture at the moment, " + + "this will be fixed later."); } - int eglSurfaceId = _eglCreateWindowSurface(display, config, sur, attrib_list); + if (eglSurfaceId == 0) { return EGL10.EGL_NO_SURFACE; } @@ -134,6 +143,7 @@ public class EGLImpl implements EGL10 { private native int _eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list); private native void _eglCreatePixmapSurface(EGLSurface sur, EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list); private native int _eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list); + private native int _eglCreateWindowSurfaceTexture(EGLDisplay display, EGLConfig config, int native_window, int[] attrib_list); private native int _eglGetDisplay(Object native_display); private native int _eglGetCurrentContext(); private native int _eglGetCurrentDisplay(); -- cgit v1.1