Java Code Examples for javax.microedition.khronos.egl.EGL10#eglCreateWindowSurface()

The following examples show how to use javax.microedition.khronos.egl.EGL10#eglCreateWindowSurface() . 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: GLTextureView.java    From PhotoMovie with Apache License 2.0 6 votes vote down vote up
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
                                      EGLConfig config, Object nativeWindow) {
    EGLSurface result = null;
    try {
        result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
    } catch (IllegalArgumentException e) {
        // This exception indicates that the surface flinger surface
        // is not valid. This can happen if the surface flinger surface has
        // been torn down, but the application has not yet been
        // notified via SurfaceHolder.Callback.surfaceDestroyed.
        // In theory the application should be notified first,
        // but in practice sometimes it is not. See b/4588890
        Log.e(TAG, "eglCreateWindowSurface", e);
    }
    return result;
}
 
Example 2
Source File: GLTextureView.java    From MD360Player4Android with Apache License 2.0 6 votes vote down vote up
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
                                      EGLConfig config, Object nativeWindow) {
    EGLSurface result = null;
    try {
        result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
    } catch (IllegalArgumentException e) {
        // This exception indicates that the surface flinger surface
        // is not valid. This can happen if the surface flinger surface has
        // been torn down, but the application has not yet been
        // notified via SurfaceHolder.Callback.surfaceDestroyed.
        // In theory the application should be notified first,
        // but in practice sometimes it is not. See b/4588890
        Log.e(TAG, "eglCreateWindowSurface", e);
    }
    return result;
}
 
Example 3
Source File: GLSurfaceView.java    From NewsMe with Apache License 2.0 6 votes vote down vote up
@Override
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
		EGLConfig config, Object nativeWindow) {
	EGLSurface result = null;
	try {
		result = egl.eglCreateWindowSurface(display, config,
				nativeWindow, null);
	} catch (IllegalArgumentException e) {
		// This exception indicates that the surface flinger surface
		// is not valid. This can happen if the surface flinger surface
		// has
		// been torn down, but the application has not yet been
		// notified via SurfaceHolder.Callback.surfaceDestroyed.
		// In theory the application should be notified first,
		// but in practice sometimes it is not. See b/4588890
		Log.e(TAG, "eglCreateWindowSurface", e);
	}
	return result;
}
 
Example 4
Source File: GLThread.java    From android-openGL-canvas with Apache License 2.0 6 votes vote down vote up
@Override
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
                                      EGLConfig config, Object nativeWindow) {

    int[] surfaceAttribs = {
            EGL10.EGL_NONE
    };
    EGLSurface result = null;
    try {
        result = egl.eglCreateWindowSurface(display, config, nativeWindow, surfaceAttribs);
    } catch (IllegalArgumentException e) {
        // This exception indicates that the surface flinger surface
        // is not valid. This can happen if the surface flinger surface has
        // been torn down, but the application has not yet been
        // notified via SurfaceHolder.Callback.surfaceDestroyed.
        // In theory the application should be notified first,
        // but in practice sometimes it is not. See b/4588890
        Log.e("DefaultWindow", "eglCreateWindowSurface", e);
    }
    return result;
}
 
Example 5
Source File: GLTextureView.java    From MusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
                                      EGLConfig config, Object nativeWindow) {
    EGLSurface result = null;
    try {
        result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
    } catch (IllegalArgumentException e) {
        // This exception indicates that the surface flinger surface
        // is not valid. This can happen if the surface flinger surface has
        // been torn down, but the application has not yet been
        // notified via SurfaceHolder.Callback.surfaceDestroyed.
        // In theory the application should be notified first,
        // but in practice sometimes it is not. See b/4588890
        Log.e(TAG, "eglCreateWindowSurface", e);
    }
    return result;
}
 
Example 6
Source File: BasicGLCube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example 7
Source File: SimpleLitGLCube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example 8
Source File: SimpleFPSDisplay.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example 9
Source File: BasicGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example 10
Source File: BasicGLCube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example 11
Source File: TextureGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example 12
Source File: EGL.java    From BambooPlayer with Apache License 2.0 4 votes vote down vote up
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display, EGLConfig config, Object nativeWindow) {
  return egl.eglCreateWindowSurface(display, config, nativeWindow, null);
}
 
Example 13
Source File: EGL.java    From react-native-android-vitamio with MIT License 4 votes vote down vote up
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display, EGLConfig config, Object nativeWindow) {
  return egl.eglCreateWindowSurface(display, config, nativeWindow, null);
}
 
Example 14
Source File: RenderView.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private boolean initGL() {
    egl10 = (EGL10) EGLContext.getEGL();

    eglDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglGetDisplay failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    int[] version = new int[2];
    if (!egl10.eglInitialize(eglDisplay, version)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglInitialize failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    int[] configsCount = new int[1];
    EGLConfig[] configs = new EGLConfig[1];
    int[] configSpec = new int[]{
            EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_ALPHA_SIZE, 8,
            EGL10.EGL_DEPTH_SIZE, 0,
            EGL10.EGL_STENCIL_SIZE, 0,
            EGL10.EGL_NONE
    };
    EGLConfig eglConfig;
    if (!egl10.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglChooseConfig failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    } else if (configsCount[0] > 0) {
        eglConfig = configs[0];
    } else {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglConfig not initialized");
        }
        finish();
        return false;
    }

    int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
    eglContext = egl10.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
    if (eglContext == null) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglCreateContext failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    if (surfaceTexture instanceof SurfaceTexture) {
        eglSurface = egl10.eglCreateWindowSurface(eglDisplay, eglConfig, surfaceTexture, null);
    } else {
        finish();
        return false;
    }

    if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("createWindowSurface failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }
    if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglMakeCurrent failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glDisable(GLES20.GL_DITHER);
    GLES20.glDisable(GLES20.GL_STENCIL_TEST);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    painting.setupShaders();
    checkBitmap();
    painting.setBitmap(bitmap);

    Utils.HasGLError();

    return true;
}
 
Example 15
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 16
Source File: RenderView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private boolean initGL() {
    egl10 = (EGL10) EGLContext.getEGL();

    eglDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglGetDisplay failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    int[] version = new int[2];
    if (!egl10.eglInitialize(eglDisplay, version)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglInitialize failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    int[] configsCount = new int[1];
    EGLConfig[] configs = new EGLConfig[1];
    int[] configSpec = new int[]{
            EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_ALPHA_SIZE, 8,
            EGL10.EGL_DEPTH_SIZE, 0,
            EGL10.EGL_STENCIL_SIZE, 0,
            EGL10.EGL_NONE
    };
    if (!egl10.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglChooseConfig failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    } else if (configsCount[0] > 0) {
        eglConfig = configs[0];
    } else {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglConfig not initialized");
        }
        finish();
        return false;
    }

    int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
    eglContext = egl10.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
    if (eglContext == null) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglCreateContext failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    if (surfaceTexture instanceof SurfaceTexture) {
        eglSurface = egl10.eglCreateWindowSurface(eglDisplay, eglConfig, surfaceTexture, null);
    } else {
        finish();
        return false;
    }

    if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("createWindowSurface failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }
    if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglMakeCurrent failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glDisable(GLES20.GL_DITHER);
    GLES20.glDisable(GLES20.GL_STENCIL_TEST);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    painting.setupShaders();
    checkBitmap();
    painting.setBitmap(bitmap);

    Utils.HasGLError();

    return true;
}
 
Example 17
Source File: EGL.java    From NetEasyNews with GNU General Public License v3.0 4 votes vote down vote up
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display, EGLConfig config, Object nativeWindow) {
  return egl.eglCreateWindowSurface(display, config, nativeWindow, null);
}
 
Example 18
Source File: EGL.java    From video-player with MIT License 4 votes vote down vote up
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display, EGLConfig config, Object nativeWindow) {
  return egl.eglCreateWindowSurface(display, config, nativeWindow, null);
}
 
Example 19
Source File: RenderView.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private boolean initGL() {
    egl10 = (EGL10) EGLContext.getEGL();

    eglDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglGetDisplay failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    int[] version = new int[2];
    if (!egl10.eglInitialize(eglDisplay, version)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglInitialize failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    int[] configsCount = new int[1];
    EGLConfig[] configs = new EGLConfig[1];
    int[] configSpec = new int[]{
            EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_ALPHA_SIZE, 8,
            EGL10.EGL_DEPTH_SIZE, 0,
            EGL10.EGL_STENCIL_SIZE, 0,
            EGL10.EGL_NONE
    };
    if (!egl10.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglChooseConfig failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    } else if (configsCount[0] > 0) {
        eglConfig = configs[0];
    } else {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglConfig not initialized");
        }
        finish();
        return false;
    }

    int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
    eglContext = egl10.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
    if (eglContext == null) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglCreateContext failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    if (surfaceTexture instanceof SurfaceTexture) {
        eglSurface = egl10.eglCreateWindowSurface(eglDisplay, eglConfig, surfaceTexture, null);
    } else {
        finish();
        return false;
    }

    if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("createWindowSurface failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }
    if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglMakeCurrent failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glDisable(GLES20.GL_DITHER);
    GLES20.glDisable(GLES20.GL_STENCIL_TEST);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    painting.setupShaders();
    checkBitmap();
    painting.setBitmap(bitmap);

    Utils.HasGLError();

    return true;
}
 
Example 20
Source File: RenderView.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private boolean initGL() {
    egl10 = (EGL10) EGLContext.getEGL();

    eglDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglGetDisplay failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    int[] version = new int[2];
    if (!egl10.eglInitialize(eglDisplay, version)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglInitialize failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    int[] configsCount = new int[1];
    EGLConfig[] configs = new EGLConfig[1];
    int[] configSpec = new int[]{
            EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_ALPHA_SIZE, 8,
            EGL10.EGL_DEPTH_SIZE, 0,
            EGL10.EGL_STENCIL_SIZE, 0,
            EGL10.EGL_NONE
    };
    EGLConfig eglConfig;
    if (!egl10.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglChooseConfig failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    } else if (configsCount[0] > 0) {
        eglConfig = configs[0];
    } else {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglConfig not initialized");
        }
        finish();
        return false;
    }

    int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
    eglContext = egl10.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
    if (eglContext == null) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglCreateContext failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    if (surfaceTexture instanceof SurfaceTexture) {
        eglSurface = egl10.eglCreateWindowSurface(eglDisplay, eglConfig, surfaceTexture, null);
    } else {
        finish();
        return false;
    }

    if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("createWindowSurface failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }
    if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("eglMakeCurrent failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
        }
        finish();
        return false;
    }

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glDisable(GLES20.GL_DITHER);
    GLES20.glDisable(GLES20.GL_STENCIL_TEST);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    painting.setupShaders();
    checkBitmap();
    painting.setBitmap(bitmap);

    Utils.HasGLError();

    return true;
}