Java Code Examples for javax.microedition.khronos.egl.EGL10#EGL_NO_DISPLAY

The following examples show how to use javax.microedition.khronos.egl.EGL10#EGL_NO_DISPLAY . 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: EGL.java    From video-player with MIT License 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 2
Source File: EGL.java    From react-native-android-vitamio with MIT License 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: EglBase10.java    From VideoCRE with MIT License 5 votes vote down vote up
@Override
public void release() {
  checkIsNotReleased();
  releaseSurface();
  detachCurrent();
  egl.eglDestroyContext(eglDisplay, eglContext);
  egl.eglTerminate(eglDisplay);
  eglContext = EGL10.EGL_NO_CONTEXT;
  eglDisplay = EGL10.EGL_NO_DISPLAY;
  eglConfig = null;
}
 
Example 4
Source File: VideoRenderThread.java    From ParsingPlayer with GNU Lesser General Public License v2.1 5 votes vote down vote up
@WorkerThread
private void shutdownEGL() {
    LogUtil.d(TAG, "shutdownEGL");
    egl10.eglMakeCurrent(eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    egl10.eglDestroyContext(eglDisplay, eglContext);
    egl10.eglDestroySurface(eglDisplay, eglSurface);
    egl10.eglTerminate(eglDisplay);
    eglContext = EGL10.EGL_NO_CONTEXT;
    eglSurface = EGL10.EGL_NO_SURFACE;
    eglDisplay = EGL10.EGL_NO_DISPLAY;
}
 
Example 5
Source File: BlockingGLTextureView.java    From TurboLauncher 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 6
Source File: EGLBase10.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
	 * 関連するリソースを破棄する
	 */
	@Override
    public void release() {
//		if (DEBUG) Log.v(TAG, "release:");
    	destroyContext();
        mContext = EGL_NO_CONTEXT;
   		if (mEgl == null) return;
   		mEgl.eglMakeCurrent(mEglDisplay,
   			EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
//		mEgl.eglReleaseThread();	// XXX これを入れるとハングアップする機種がある
   		mEgl.eglTerminate(mEglDisplay);
    	mEglDisplay = EGL10.EGL_NO_DISPLAY;
		mEglConfig = null;
   		mEgl = null;
    }
 
Example 7
Source File: EglBase10.java    From VideoCRE with MIT License 5 votes vote down vote up
private EGLDisplay getEglDisplay() {
  EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
  if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
    throw new RuntimeException(
        "Unable to get EGL10 display: 0x" + Integer.toHexString(egl.eglGetError()));
  }
  int[] version = new int[2];
  if (!egl.eglInitialize(eglDisplay, version)) {
    throw new RuntimeException(
        "Unable to initialize EGL10: 0x" + Integer.toHexString(egl.eglGetError()));
  }
  return eglDisplay;
}
 
Example 8
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 9
Source File: EglBase10Impl.java    From webrtc_android with MIT License 5 votes vote down vote up
@Override
public void release() {
  checkIsNotReleased();
  releaseSurface();
  detachCurrent();
  egl.eglDestroyContext(eglDisplay, eglContext);
  egl.eglTerminate(eglDisplay);
  eglContext = EGL10.EGL_NO_CONTEXT;
  eglDisplay = EGL10.EGL_NO_DISPLAY;
  eglConfig = null;
}
 
Example 10
Source File: GLSurfaceView.java    From NewsMe 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");
	}
	mEglConfig = 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 = 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 11
Source File: OutputSurface.java    From VideoCompressor with Apache License 2.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 12
Source File: EglBase10Impl.java    From webrtc_android with MIT License 4 votes vote down vote up
private void checkIsNotReleased() {
  if (eglDisplay == EGL10.EGL_NO_DISPLAY || eglContext == EGL10.EGL_NO_CONTEXT
      || eglConfig == null) {
    throw new RuntimeException("This object has been released");
  }
}
 
Example 13
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;
}
 
Example 14
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 15
Source File: OutputSurface.java    From talk-android with MIT License 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: 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: GLTextureView.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");
    }
    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 18
Source File: GLSurfaceView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
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 19
Source File: OutputSurface.java    From Telegram-FOSS 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 20
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");
    }
}