Java Code Examples for javax.microedition.khronos.egl.EGLContext#getEGL()

The following examples show how to use javax.microedition.khronos.egl.EGLContext#getEGL() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResizingSurfaceView.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
/**
 * Clears the frames from the current surface.  This should only be called when
 * the implementing video view has finished playback or otherwise released
 * the surface
 */
@Override
public void clearSurface() {
    try {
        EGL10 gl10 = (EGL10) EGLContext.getEGL();
        EGLDisplay display = gl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        gl10.eglInitialize(display, null);

        EGLConfig[] configs = new EGLConfig[1];
        gl10.eglChooseConfig(display, GL_CLEAR_CONFIG_ATTRIBUTES, configs, configs.length, new int[1]);
        EGLContext context = gl10.eglCreateContext(display, configs[0], EGL10.EGL_NO_CONTEXT, GL_CLEAR_CONTEXT_ATTRIBUTES);
        EGLSurface eglSurface = gl10.eglCreateWindowSurface(display, configs[0], this, new int[]{EGL10.EGL_NONE});

        gl10.eglMakeCurrent(display, eglSurface, eglSurface, context);
        gl10.eglSwapBuffers(display, eglSurface);
        gl10.eglDestroySurface(display, eglSurface);
        gl10.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        gl10.eglDestroyContext(display, context);

        gl10.eglTerminate(display);
    } catch (Exception e) {
        Log.e(TAG, "Error clearing surface", e);
    }
}
 
Example 2
Source File: EGL.java    From BambooPlayer with Apache License 2.0 6 votes vote down vote up
public void start() {
  mEgl = (EGL10) EGLContext.getEGL();
  mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

  if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
    throw new RuntimeException("eglGetDisplay failed");
  }

  int[] version = new int[2];
  if (!mEgl.eglInitialize(mEglDisplay, version)) {
    throw new RuntimeException("eglInitialize failed");
  }
  mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);

  mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
  if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
    mEglContext = null;
    throwEglException("createContext");
  }

  mEglSurface = null;
}
 
Example 3
Source File: GLConfiguration.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
public static void checkConfiguration() {
    final EGL10 egl = (EGL10) EGLContext.getEGL();
    final EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
        throw new RuntimeException("Your device cannot support EGL");
    }

    final int[] version = new int[2];
    if (!egl.eglInitialize(eglDisplay, version)) {
        throw new RuntimeException("Your device cannot support EGL");
    }

    try {
        if (getConfigChooser().chooseConfig(egl, eglDisplay) == null) {
            throw new RuntimeException("Your device cannot support required GLES configuration");
        }
    } catch (final Throwable th) {
        throw new RuntimeException("Your device cannot support required GLES configuration");
    } finally {
        egl.eglTerminate(eglDisplay);
    }
}
 
Example 4
Source File: BlockingGLTextureView.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize EGL for a given configuration spec.
 */
public void start() {
    /*
     * Get an EGL instance
     */
    mEgl = (EGL10) EGLContext.getEGL();

    /*
     * Get to the default display.
     */
    mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
        throw new RuntimeException("eglGetDisplay failed");
    }

    /*
     * We can now initialize EGL for that display
     */
    int[] version = new int[2];
    if (!mEgl.eglInitialize(mEglDisplay, version)) {
        throw new RuntimeException("eglInitialize failed");
    }
    mEglConfig = chooseEglConfig();

    /*
    * Create an EGL context. We want to do this as rarely as we can, because an
    * EGL context is a somewhat heavy object.
    */
    mEglContext = createContext(mEgl, mEglDisplay, mEglConfig);

    if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
        mEglContext = null;
        throwEglException("createContext");
    }

    mEglSurface = null;
}
 
Example 5
Source File: BitmapUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static int getMaxTextureSize() {
  final int MAX_ALLOWED_TEXTURE_SIZE = 2048;

  EGL10 egl = (EGL10) EGLContext.getEGL();
  EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

  int[] version = new int[2];
  egl.eglInitialize(display, version);

  int[] totalConfigurations = new int[1];
  egl.eglGetConfigs(display, null, 0, totalConfigurations);

  EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
  egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

  int[] textureSize = new int[1];
  int maximumTextureSize = 0;

  for (int i = 0; i < totalConfigurations[0]; i++) {
    egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

    if (maximumTextureSize < textureSize[0])
      maximumTextureSize = textureSize[0];
  }

  egl.eglTerminate(display);

  return Math.min(maximumTextureSize, MAX_ALLOWED_TEXTURE_SIZE);
}
 
Example 6
Source File: PixelBuffer.java    From In77Camera with MIT License 5 votes vote down vote up
public PixelBuffer(final int width, final int height) {
    mWidth = width;
    mHeight = height;

    int[] version = new int[2];
    int[] attribList = new int[] {
            EGL_WIDTH, mWidth,
            EGL_HEIGHT, mHeight,
            EGL_NONE
    };

    // No error checking performed, minimum required code to elucidate logic
    mEGL = (EGL10) EGLContext.getEGL();
    mEGLDisplay = mEGL.eglGetDisplay(EGL_DEFAULT_DISPLAY);
    mEGL.eglInitialize(mEGLDisplay, version);
    mEGLConfig = chooseConfig(); // Choosing a config is a little more
                                 // complicated

    // mEGLContext = mEGL.eglCreateContext(mEGLDisplay, mEGLConfig,
    // EGL_NO_CONTEXT, null);
    int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
    int[] attrib_list = {
            EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL10.EGL_NONE
    };
    mEGLContext = mEGL.eglCreateContext(mEGLDisplay, mEGLConfig, EGL_NO_CONTEXT, attrib_list);

    mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, attribList);
    mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);

    mGL = (GL10) mEGLContext.getGL();

    // Record thread owner of OpenGL context
    mThreadOwner = Thread.currentThread().getName();
}
 
Example 7
Source File: OutputSurface.java    From AndroidVideoSamples with Apache License 2.0 5 votes vote down vote up
/**
 * Prepares EGL. We want a GLES 2.0 context and a surface that supports pbuffer.
 */
private void eglSetup( int width, int height ) {
   mEGL = (EGL10) EGLContext.getEGL();
   mEGLDisplay = mEGL.eglGetDisplay( EGL10.EGL_DEFAULT_DISPLAY );
   if ( !mEGL.eglInitialize( mEGLDisplay, null ) ) {
      throw new RuntimeException( "unable to initialize EGL10" );
   }
   // Configure EGL for pbuffer and OpenGL ES 2.0. We want enough RGB bits
   // to be able to tell if the frame is reasonable.
   int[] attribList = { EGL10.EGL_RED_SIZE, 8, EGL10.EGL_GREEN_SIZE, 8, EGL10.EGL_BLUE_SIZE, 8, EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE };
   EGLConfig[] configs = new EGLConfig[1];
   int[] numConfigs = new int[1];
   if ( !mEGL.eglChooseConfig( mEGLDisplay, attribList, configs, 1, numConfigs ) ) {
      throw new RuntimeException( "unable to find RGB888+pbuffer EGL config" );
   }
   // Configure context for OpenGL ES 2.0.
   int[] attrib_list = { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
   mEGLContext = mEGL.eglCreateContext( mEGLDisplay, configs[0], EGL10.EGL_NO_CONTEXT, attrib_list );
   checkEglError( "eglCreateContext" );
   if ( mEGLContext == null ) {
      throw new RuntimeException( "null context" );
   }
   // Create a pbuffer surface. By using this for output, we can use glReadPixels
   // to test values in the output.
   int[] surfaceAttribs = { EGL10.EGL_WIDTH, width, EGL10.EGL_HEIGHT, height, EGL10.EGL_NONE };
   mEGLSurface = mEGL.eglCreatePbufferSurface( mEGLDisplay, configs[0], surfaceAttribs );
   checkEglError( "eglCreatePbufferSurface" );
   if ( mEGLSurface == null ) {
      throw new RuntimeException( "surface was null" );
   }
}
 
Example 8
Source File: PixelBuffer.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
public PixelBuffer(final int width, final int height) {
    mWidth = width;
    mHeight = height;

    int[] version = new int[2];
    int[] attribList = new int[] {
            EGL_WIDTH, mWidth,
            EGL_HEIGHT, mHeight,
            EGL_NONE
    };

    // No error checking performed, minimum required code to elucidate logic
    mEGL = (EGL10) EGLContext.getEGL();
    mEGLDisplay = mEGL.eglGetDisplay(EGL_DEFAULT_DISPLAY);
    mEGL.eglInitialize(mEGLDisplay, version);
    mEGLConfig = chooseConfig(); // Choosing a config is a little more
                                 // complicated

    // mEGLContext = mEGL.eglCreateContext(mEGLDisplay, mEGLConfig,
    // EGL_NO_CONTEXT, null);
    int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
    int[] attrib_list = {
            EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL10.EGL_NONE
    };
    mEGLContext = mEGL.eglCreateContext(mEGLDisplay, mEGLConfig, EGL_NO_CONTEXT, attrib_list);

    mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, attribList);
    mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);

    mGL = (GL10) mEGLContext.getGL();

    // Record thread owner of OpenGL context
    mThreadOwner = Thread.currentThread().getName();
}
 
Example 9
Source File: ImgHelper.java    From 4pdaClient-plus with Apache License 2.0 5 votes vote down vote up
public static int getMaxTextureSize() {
    // Safe minimum default size
    final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

    // Get EGL Display
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    // Initialise
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Query total number of configurations
    int[] totalConfigurations = new int[1];
    egl.eglGetConfigs(display, null, 0, totalConfigurations);

    // Query actual list configurations
    EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
    egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

    int[] textureSize = new int[1];
    int maximumTextureSize = 0;

    // Iterate through all the configurations to located the maximum texture size
    for (int i = 0; i < totalConfigurations[0]; i++) {
        // Only need to check for width since opengl textures are always squared
        egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

        // Keep track of the maximum texture size
        if (maximumTextureSize < textureSize[0])
            maximumTextureSize = textureSize[0];
    }

    // Release
    egl.eglTerminate(display);

    // Return largest texture size found, or default
    return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
}
 
Example 10
Source File: EGLBase10.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * 現在のスレッドの既存のレンダリングコンテキストがあればそれを共有して
 * 新しいレンダリングコンテキストを生成する
 * 既存のレンダリングコンテキストが存在していなければ独立したレンダリングコンテキストを
 * 生成する
 * @param maxClientVersion
 * @param withDepthBuffer
 * @param stencilBits
 * @param isRecordable
 * @return
 */
/*package*/ static EGLBase createFromCurrentImpl(final int maxClientVersion,
	final boolean withDepthBuffer, final int stencilBits, final boolean isRecordable) {

	Context context = null;
	final EGL10 egl10 = (EGL10)EGLContext.getEGL();
	final EGLContext currentContext = egl10.eglGetCurrentContext();
	final EGLSurface currentSurface = egl10.eglGetCurrentSurface(EGL10.EGL_DRAW);
	if ((currentContext != null) && (currentSurface != null)) {
		context = wrap(currentContext);
	}
	return new EGLBase10(maxClientVersion, context, withDepthBuffer, stencilBits, isRecordable);
}
 
Example 11
Source File: OBVideoPlayer.java    From GLEXP-Team-onebillion with Apache License 2.0 4 votes vote down vote up
private void clearSurface(SurfaceTexture texture)
{
    if(texture == null){
        return;
    }

    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    egl.eglInitialize(display, null);

    int[] attribList = {
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_ALPHA_SIZE, 8,
            EGL10.EGL_RENDERABLE_TYPE, EGL10.EGL_WINDOW_BIT,
            EGL10.EGL_NONE, 0,
            EGL10.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    egl.eglChooseConfig(display, attribList, configs, configs.length, numConfigs);
    EGLConfig config = configs[0];
    EGLContext context = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, new int[]{
            12440, 2,
            EGL10.EGL_NONE
    });
    EGLSurface eglSurface = egl.eglCreateWindowSurface(display, config, texture,
            new int[]{
                    EGL10.EGL_NONE
            });

    egl.eglMakeCurrent(display, eglSurface, eglSurface, context);
    GLES20.glClearColor(0, 0, 0, 1);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    egl.eglSwapBuffers(display, eglSurface);
    egl.eglDestroySurface(display, eglSurface);
    egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
            EGL10.EGL_NO_CONTEXT);
    egl.eglDestroyContext(display, context);
    egl.eglTerminate(display);
}
 
Example 12
Source File: SketchUtils.java    From sketch with Apache License 2.0 4 votes vote down vote up
private static int getOpenGLMaxTextureSizeBase() {
    // In JELLY_BEAN will collapse
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN) {
        return 0;
    }

    EGL10 egl = (EGL10) EGLContext.getEGL();

    EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    egl.eglInitialize(dpy, vers);

    int[] configAttr = {
            EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RGB_BUFFER,
            EGL10.EGL_LEVEL, 0,
            EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
            EGL10.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfig = new int[1];
    egl.eglChooseConfig(dpy, configAttr, configs, 1, numConfig);
    //noinspection StatementWithEmptyBody
    if (numConfig[0] == 0) {
        // TROUBLE! No config found.
    }
    EGLConfig config = configs[0];

    int[] surfAttr = new int[]{
            EGL10.EGL_WIDTH, 64,
            EGL10.EGL_HEIGHT, 64,
            EGL10.EGL_NONE
    };
    EGLSurface surf = egl.eglCreatePbufferSurface(dpy, config, surfAttr);
    final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;  // missing in EGL10
    int[] ctxAttrib = {
            EGL_CONTEXT_CLIENT_VERSION, 1,
            EGL10.EGL_NONE
    };
    EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, ctxAttrib);
    egl.eglMakeCurrent(dpy, surf, surf, ctx);
    int[] maxSize = new int[1];
    GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0);

    egl.eglMakeCurrent(dpy, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    egl.eglDestroySurface(dpy, surf);
    egl.eglDestroyContext(dpy, ctx);
    egl.eglTerminate(dpy);

    return maxSize[0];
}
 
Example 13
Source File: GLSurfaceView.java    From EZFilter with MIT License 4 votes vote down vote up
/**
 * Initialize EGL for a given configuration spec.
 */
public void start() {
    if (LOG_EGL) {
        Log.w("EglHelper", "start() tid=" + Thread.currentThread().getId());
    }
    /*
     * Get an EGL instance
     */
    mEgl = (EGL10) EGLContext.getEGL();

    /*
     * Get to the default display.
     */
    mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
        throw new RuntimeException("eglGetDisplay failed");
    }

    /*
     * We can now initialize EGL for that display
     */
    int[] version = new int[2];
    if (!mEgl.eglInitialize(mEglDisplay, version)) {
        throw new RuntimeException("eglInitialize failed");
    }
    GLSurfaceView view = mGLSurfaceViewWeakRef.get();
    if (view == null) {
        mEglConfig = null;
        mEglContext = null;
    } else {
        mEglConfig = view.mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);

        /*
        * Create an EGL context. We want to do this as rarely as we can, because an
        * EGL context is a somewhat heavy object.
        */
        mEglContext = view.mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
    }
    if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
        mEglContext = null;
        throwEglException("createContext");
    }
    if (LOG_EGL) {
        Log.w("EglHelper", "createContext " + mEglContext + " tid=" + Thread.currentThread().getId());
    }

    mEglSurface = null;
}
 
Example 14
Source File: OutputSurface.java    From LiveMultimedia with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares EGL.  We want a GLES 2.0 context and a surface that supports pbuffer.
 */
private void eglSetup(int width, int height) {
    mEGL = (EGL10)EGLContext.getEGL();
    mEGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (!mEGL.eglInitialize(mEGLDisplay, null)) {
        throw new RuntimeException("unable to initialize EGL10");
    }

    // Configure EGL for pbuffer and OpenGL ES 2.0.  We want enough RGB bits
    // to be able to tell if the frame is reasonable.
    int[] attribList = {
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
            EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
            EGL10.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    if (!mEGL.eglChooseConfig(mEGLDisplay, attribList, configs, 1, numConfigs)) {
        throw new RuntimeException("unable to find RGB888+pbuffer EGL config");
    }

    // Configure context for OpenGL ES 2.0.
    int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL10.EGL_NONE
    };
    mEGLContext = mEGL.eglCreateContext(mEGLDisplay, configs[0], EGL10.EGL_NO_CONTEXT,
            attrib_list);
    checkEglError("eglCreateContext");
    if (mEGLContext == null) {
        throw new RuntimeException("null context");
    }

    // Create a pbuffer surface.  By using this for output, we can use glReadPixels
    // to test values in the output.
    int[] surfaceAttribs = {
            EGL10.EGL_WIDTH, width,
            EGL10.EGL_HEIGHT, height,
            EGL10.EGL_NONE
    };
    mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, configs[0], surfaceAttribs);
    checkEglError("eglCreatePbufferSurface");
    if (mEGLSurface == null) {
        throw new RuntimeException("surface was null");
    }
}
 
Example 15
Source File: OutputSurface.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void eglSetup(int width, int height) {
    mEGL = (EGL10) EGLContext.getEGL();
    mEGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    if (mEGLDisplay == EGL10.EGL_NO_DISPLAY) {
        throw new RuntimeException("unable to get EGL10 display");
    }

    if (!mEGL.eglInitialize(mEGLDisplay, null)) {
        mEGLDisplay = null;
        throw new RuntimeException("unable to initialize EGL10");
    }

    int[] attribList = {
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_ALPHA_SIZE, 8,
            EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
            EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
            EGL10.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    if (!mEGL.eglChooseConfig(mEGLDisplay, attribList, configs, configs.length, numConfigs)) {
        throw new RuntimeException("unable to find RGB888+pbuffer EGL config");
    }
    int[] attrib_list = {
            EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL10.EGL_NONE
    };
    mEGLContext = mEGL.eglCreateContext(mEGLDisplay, configs[0], EGL10.EGL_NO_CONTEXT, attrib_list);
    checkEglError("eglCreateContext");
    if (mEGLContext == null) {
        throw new RuntimeException("null context");
    }
    int[] surfaceAttribs = {
            EGL10.EGL_WIDTH, width,
            EGL10.EGL_HEIGHT, height,
            EGL10.EGL_NONE
    };
    mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, configs[0], surfaceAttribs);
    checkEglError("eglCreatePbufferSurface");
    if (mEGLSurface == null) {
        throw new RuntimeException("surface was null");
    }
}
 
Example 16
Source File: GLTextureView.java    From PhotoMovie with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize EGL for a given configuration spec.
 */
public void start() {
    if (LOG_EGL) {
        Log.w("EglHelper", "start() tid=" + Thread.currentThread().getId());
    }
    /*
     * Get an EGL instance
     */
    mEgl = (EGL10) EGLContext.getEGL();

    /*
     * Get to the default display.
     */
    mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
        throw new RuntimeException("eglGetDisplay failed");
    }

    /*
     * We can now initialize EGL for that display
     */
    int[] version = new int[2];
    if (!mEgl.eglInitialize(mEglDisplay, version)) {
        throw new RuntimeException("eglInitialize failed");
    }
    GLTextureView view = mGLSurfaceViewWeakRef.get();
    if (view == null) {
        mEglConfig = null;
        mEglContext = null;
    } else {
        mEglConfig = view.mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);

        /*
         * Create an EGL context. We want to do this as rarely as we can, because an
         * EGL context is a somewhat heavy object.
         */
        mEglContext = view.mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
    }
    if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
        mEglContext = null;
        throwEglException("createContext");
    }
    if (LOG_EGL) {
        Log.w("EglHelper", "createContext " + mEglContext + " tid=" + Thread.currentThread().getId());
    }

    mEglSurface = null;
}
 
Example 17
Source File: EglBase10.java    From UltraGpuImage with MIT License 4 votes vote down vote up
public EglBase10(Context sharedContext, int[] configAttributes) {
  this.egl = (EGL10) EGLContext.getEGL();
  eglDisplay = getEglDisplay();
  eglConfig = getEglConfig(eglDisplay, configAttributes);
  eglContext = createEglContext(sharedContext, eglDisplay, eglConfig);
}
 
Example 18
Source File: GlTextureView.java    From ParticleView with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize EGL for a given configuration spec.
 * @param configSpec
 */
public void start() {
    if (LOG_EGL) {
        Log.w("EglHelper", "start() tid=" + Thread.currentThread().getId());
    }
    /*
     * Get an EGL instance
     */
    mEgl = (EGL10) EGLContext.getEGL();

    /*
     * Get to the default display.
     */
    mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
        throw new RuntimeException("eglGetDisplay failed");
    }

    /*
     * We can now initialize EGL for that display
     */
    int[] version = new int[2];
    if(!mEgl.eglInitialize(mEglDisplay, version)) {
        throw new RuntimeException("eglInitialize failed");
    }
    GlTextureView view = mGLTextureViewWeakRef.get();
    if (view == null) {
        mEglConfig = null;
        mEglContext = null;
    } else {
        mEglConfig = view.mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);

        /*
        * Create an EGL context. We want to do this as rarely as we can, because an
        * EGL context is a somewhat heavy object.
        */
        mEglContext = view.mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
    }
    if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
        mEglContext = null;
        throwEglException("createContext");
    }
    if (LOG_EGL) {
        Log.w("EglHelper", "createContext " + mEglContext + " tid=" + Thread.currentThread().getId());
    }

    mEglSurface = null;
}
 
Example 19
Source File: BitmapUtils.java    From giffun with Apache License 2.0 4 votes vote down vote up
/**
 * Get the max size of bitmap allowed to be rendered on the device.<br>
 * http://stackoverflow.com/questions/7428996/hw-accelerated-activity-how-to-get-opengl-texture-size-limit.
 */
private static int getMaxTextureSize() {
  // Safe minimum default size
  final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

  try {
    // Get EGL Display
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    // Initialise
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Query total number of configurations
    int[] totalConfigurations = new int[1];
    egl.eglGetConfigs(display, null, 0, totalConfigurations);

    // Query actual list configurations
    EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
    egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

    int[] textureSize = new int[1];
    int maximumTextureSize = 0;

    // Iterate through all the configurations to located the maximum texture size
    for (int i = 0; i < totalConfigurations[0]; i++) {
      // Only need to check for width since opengl textures are always squared
      egl.eglGetConfigAttrib(
          display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

      // Keep track of the maximum texture size
      if (maximumTextureSize < textureSize[0]) {
        maximumTextureSize = textureSize[0];
      }
    }

    // Release
    egl.eglTerminate(display);

    // Return largest texture size found, or default
    return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
  } catch (Exception e) {
    return IMAGE_MAX_BITMAP_DIMENSION;
  }
}
 
Example 20
Source File: BitmapUtils.java    From Lassi-Android with MIT License 4 votes vote down vote up
/**
 * Get the max size of bitmap allowed to be rendered on the device.<br>
 * http://stackoverflow.com/questions/7428996/hw-accelerated-activity-how-to-get-opengl-texture-size-limit.
 */
private static int getMaxTextureSize() {
    // Safe minimum default size
    final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

    try {
        // Get EGL Display
        EGL10 egl = (EGL10) EGLContext.getEGL();
        EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

        // Initialise
        int[] version = new int[2];
        egl.eglInitialize(display, version);

        // Query total number of configurations
        int[] totalConfigurations = new int[1];
        egl.eglGetConfigs(display, null, 0, totalConfigurations);

        // Query actual list configurations
        EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
        egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

        int[] textureSize = new int[1];
        int maximumTextureSize = 0;

        // Iterate through all the configurations to located the maximum texture size
        for (int i = 0; i < totalConfigurations[0]; i++) {
            // Only need to check for width since opengl textures are always squared
            egl.eglGetConfigAttrib(
                    display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

            // Keep track of the maximum texture size
            if (maximumTextureSize < textureSize[0]) {
                maximumTextureSize = textureSize[0];
            }
        }

        // Release
        egl.eglTerminate(display);

        // Return largest texture size found, or default
        return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
    } catch (Exception e) {
        Logger.INSTANCE.e(logTag, "getMaxTextureSize >> " + e);
        return IMAGE_MAX_BITMAP_DIMENSION;

    }
}