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

The following examples show how to use javax.microedition.khronos.egl.EGL10#EGL_NO_SURFACE . 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: ExtractMpegFramesTest.java    From Android-MediaCodec-Examples with Apache License 2.0 6 votes vote down vote up
/**
 * Discard all resources held by this class, notably the EGL context.
 */
public void release() {
    if (mEGLDisplay != EGL10.EGL_NO_DISPLAY) {
        mEgl.eglDestroySurface(mEGLDisplay, mEGLSurface);
        mEgl.eglDestroyContext(mEGLDisplay, mEGLContext);
        //mEgl.eglReleaseThread();
        mEgl.eglMakeCurrent(mEGLDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
                EGL10.EGL_NO_CONTEXT);
        mEgl.eglTerminate(mEGLDisplay);
    }
    mEGLDisplay = EGL10.EGL_NO_DISPLAY;
    mEGLContext = EGL10.EGL_NO_CONTEXT;
    mEGLSurface = EGL10.EGL_NO_SURFACE;

    mSurface.release();

    // this causes a bunch of warnings that appear harmless but might confuse someone:
    //  W BufferQueue: [unnamed-3997-2] cancelBuffer: BufferQueue has been abandoned!
    //mSurfaceTexture.release();

    mTextureRender = null;
    mSurface = null;
    mSurfaceTexture = null;
}
 
Example 2
Source File: EglExtensionRetriever.java    From YalpStore with GNU General Public License v2.0 6 votes vote down vote up
private static void addExtensionsForConfig(EGL10 egl10, EGLDisplay egldisplay, EGLConfig eglconfig, int ai[], int ai1[], Set<String> set) {
    EGLContext eglContext = egl10.eglCreateContext(egldisplay, eglconfig, EGL10.EGL_NO_CONTEXT, ai1);
    if (eglContext == EGL10.EGL_NO_CONTEXT) {
        return;
    }
    javax.microedition.khronos.egl.EGLSurface eglSurface = egl10.eglCreatePbufferSurface(egldisplay, eglconfig, ai);
    if (eglSurface == EGL10.EGL_NO_SURFACE) {
        egl10.eglDestroyContext(egldisplay, eglContext);
    } else {
        egl10.eglMakeCurrent(egldisplay, eglSurface, eglSurface, eglContext);
        String s = GLES10.glGetString(7939);
        if (!TextUtils.isEmpty(s)) {
            String as[] = s.split(" ");
            int i = as.length;
            for (int j = 0; j < i; j++) {
                set.add(as[j]);
            }
        }
        egl10.eglMakeCurrent(egldisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        egl10.eglDestroySurface(egldisplay, eglSurface);
        egl10.eglDestroyContext(egldisplay, eglContext);
    }
}
 
Example 3
Source File: EGL.java    From NetEasyNews with GNU General Public License v3.0 5 votes vote down vote up
public void destroySurface() {
  if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {
    mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay, mEglSurface);
    mEglSurface = null;
  }
}
 
Example 4
Source File: GLTextureView.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
private void destroySurfaceImp() {
    if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {
        mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE,
                EGL10.EGL_NO_SURFACE,
                EGL10.EGL_NO_CONTEXT);
        GLTextureView view = mGLTextureViewWeakRef.get();
        if (view != null) {
            view.mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay, mEglSurface);
        }
        mEglSurface = null;
    }
}
 
Example 5
Source File: EglBase10.java    From VideoCRE with MIT License 5 votes vote down vote up
@Override
public void makeCurrent() {
  checkIsNotReleased();
  if (eglSurface == EGL10.EGL_NO_SURFACE) {
    throw new RuntimeException("No EGLSurface - can't make current");
  }
  synchronized (EglBase.lock) {
    if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
      throw new RuntimeException(
          "eglMakeCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
    }
  }
}
 
Example 6
Source File: GLSurfaceView.java    From EZFilter with MIT License 5 votes vote down vote up
private void destroySurfaceImp() {
    if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {
        mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE,
                EGL10.EGL_NO_SURFACE,
                EGL10.EGL_NO_CONTEXT);
        GLSurfaceView view = mGLSurfaceViewWeakRef.get();
        if (view != null) {
            view.mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay, mEglSurface);
        }
        mEglSurface = null;
    }
}
 
Example 7
Source File: EGL.java    From HPlayer with Apache License 2.0 5 votes vote down vote up
public void destroySurface() {
  if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {
    mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay, mEglSurface);
    mEglSurface = null;
  }
}
 
Example 8
Source File: GLSurfaceView.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
public void destroySurface() {
	if (LOG_EGL) {
		Log.w("EglHelper", "destroySurface()  tid="
				+ Thread.currentThread().getId());
	}
	if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {
		mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE,
				EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
		mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay,
				mEglSurface);
		mEglSurface = null;
	}
}
 
Example 9
Source File: EglBase10Impl.java    From webrtc_android with MIT License 5 votes vote down vote up
@Override
public void swapBuffers() {
  checkIsNotReleased();
  if (eglSurface == EGL10.EGL_NO_SURFACE) {
    throw new RuntimeException("No EGLSurface - can't swap buffers");
  }
  synchronized (EglBase.lock) {
    egl.eglSwapBuffers(eglDisplay, eglSurface);
  }
}
 
Example 10
Source File: EglBase10.java    From VideoCRE with MIT License 5 votes vote down vote up
@Override
public void releaseSurface() {
  if (eglSurface != EGL10.EGL_NO_SURFACE) {
    egl.eglDestroySurface(eglDisplay, eglSurface);
    eglSurface = EGL10.EGL_NO_SURFACE;
  }
}
 
Example 11
Source File: EGL.java    From react-native-android-vitamio with MIT License 5 votes vote down vote up
public void destroySurface() {
  if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {
    mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay, mEglSurface);
    mEglSurface = null;
  }
}
 
Example 12
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 13
Source File: GLSurfaceView.java    From NewsMe with Apache License 2.0 4 votes vote down vote up
public GL createSurface(SurfaceHolder holder) {
	if (LOG_EGL) {
		Log.w("EglHelper", "createSurface()  tid="
				+ Thread.currentThread().getId());
	}
	/*
	 * Check preconditions.
	 */
	if (mEgl == null) {
		throw new RuntimeException("egl not initialized");
	}
	if (mEglDisplay == null) {
		throw new RuntimeException("eglDisplay not initialized");
	}
	if (mEglConfig == null) {
		throw new RuntimeException("mEglConfig not initialized");
	}
	/*
	 * The window size has changed, so we need to create a new surface.
	 */
	if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {

		/*
		 * Unbind and destroy the old EGL surface, if there is one.
		 */
		mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE,
				EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
		mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay,
				mEglSurface);
	}

	/*
	 * Create an EGL surface we can render into.
	 */
	mEglSurface = mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
			mEglDisplay, mEglConfig, holder);

	if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
		int error = mEgl.eglGetError();
		if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
			Log.e("EglHelper",
					"createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
		}
		return null;
	}

	/*
	 * Before we can issue GL commands, we need to make sure the context
	 * is current and bound to a surface.
	 */
	if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
			mEglContext)) {
		throwEglException("eglMakeCurrent");
	}

	GL gl = mEglContext.getGL();
	if (mGLWrapper != null) {
		gl = mGLWrapper.wrap(gl);
	}

	// if ((mDebugFlags & (DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS))
	// != 0) {
	// int configFlags = 0;
	// Writer log = null;
	// if ((mDebugFlags & DEBUG_CHECK_GL_ERROR) != 0) {
	// configFlags |= GLDebugHelper.CONFIG_CHECK_GL_ERROR;
	// }
	// if ((mDebugFlags & DEBUG_LOG_GL_CALLS) != 0) {
	// log = new LogWriter();
	// }
	// gl = GLDebugHelper.wrap(gl, configFlags, log);
	// }
	return gl;
}
 
Example 14
Source File: GLTextureView.java    From ZGDanmaku with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface() {
    if (LOG_EGL) {
        Log.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
    }
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    GLTextureView view = mGLTextureViewWeakRef.get();
    if (view != null) {
        mEglSurface = view.mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
                mEglDisplay, mEglConfig, view.getSurfaceTexture());
    } else {
        mEglSurface = null;
    }

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * Before we can issue GL commands, we need to make sure
     * the context is current and bound to a surface.
     */
    if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}
 
Example 15
Source File: BlockingGLTextureView.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceTexture surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface(SurfaceTexture surface) {
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    if (surface != null) {
        mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, surface, null);
    } else {
        mEglSurface = null;
    }

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * Before we can issue GL commands, we need to make sure
     * the context is current and bound to a surface.
     */
    if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}
 
Example 16
Source File: myGLTextureView.java    From opengl with Apache License 2.0 4 votes vote down vote up
private void initGL() {

        mEgl = (EGL10) EGLContext.getEGL();
        mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
            throw new RuntimeException("eglGetDisplay failed "
                    + GLUtils.getEGLErrorString(mEgl.eglGetError()));
        }
        int[] version = new int[2];
        if (!mEgl.eglInitialize(mEglDisplay, version)) {
            throw new RuntimeException("eglInitialize failed "
                    + GLUtils.getEGLErrorString(mEgl.eglGetError()));
        }
        int[] configsCount = new int[1];
        EGLConfig[] configs = new EGLConfig[1];
        int[] configSpec = {
                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, 16,  //was 0
                EGL10.EGL_STENCIL_SIZE, 0,
                EGL10.EGL_NONE
        };
        eglConfig = null;
        if (!mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1,
                configsCount)) {
            throw new IllegalArgumentException(
                    "eglChooseConfig failed "
                            + GLUtils.getEGLErrorString(mEgl
                            .eglGetError()));
        } else if (configsCount[0] > 0) {
            eglConfig = configs[0];
        }
        if (eglConfig == null) {
            throw new RuntimeException("eglConfig not initialized");
        }
        int[] attrib_list = {
                EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE
        };
        mEglContext = mEgl.eglCreateContext(mEglDisplay,
                eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
        checkEglError();
        mEglSurface = mEgl.eglCreateWindowSurface(
                mEglDisplay, eglConfig, mSurface, null);
        checkEglError();
        if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
            int error = mEgl.eglGetError();
            if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
                Log.e(TAG,
                        "eglCreateWindowSurface returned EGL10.EGL_BAD_NATIVE_WINDOW");
                return;
            }
            throw new RuntimeException(
                    "eglCreateWindowSurface failed "
                            + GLUtils.getEGLErrorString(error));
        }
        if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface,
                mEglSurface, mEglContext)) {
            throw new RuntimeException("eglMakeCurrent failed "
                    + GLUtils.getEGLErrorString(mEgl.eglGetError()));
        }
        checkEglError();
        mGl = (GL10) mEglContext.getGL();
        checkEglError();
    }
 
Example 17
Source File: EglHelper.java    From android-openGL-canvas with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
@Override
public boolean createSurface(Object surface) {
    Loggers.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    mEglSurface = eglWindowSurfaceFactory.createWindowSurface(mEgl,
            mEglDisplay, mEglConfig, surface);

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * Before we can issue GL commands, we need to make sure
     * the context is current and bound to a surface.
     */
    if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}
 
Example 18
Source File: VisualizerRenderer.java    From MusicVisualization with Apache License 2.0 4 votes vote down vote up
private boolean initGL(SurfaceTexture texture) {
    mEgl10 = (EGL10) EGLContext.getEGL();

    mEglDisplay = mEgl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (mEglDisplay == EGL10.EGL_NO_DISPLAY) return false;

    int[] version = new int[2];
    if (!mEgl10.eglInitialize(mEglDisplay, version)) return false;

    int[] configsCount = new int[1];
    EGLConfig[] configs = new EGLConfig[1];
    int[] configSpec = {
            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 = null;
    if (!mEgl10.eglChooseConfig(mEglDisplay, configSpec, configs, 1, configsCount)) {
        return false;
    } else if (configsCount[0] > 0) {
        eglConfig = configs[0];
    }
    if (eglConfig == null) return false;

    mEglContext = mEgl10.eglCreateContext(
            mEglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT,
            new int[]{EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE});
    mEglSurface = mEgl10.eglCreateWindowSurface(mEglDisplay, eglConfig, texture, null);

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) return false;
    if (!mEgl10.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) return false;

    return true;
}
 
Example 19
Source File: GLSurfaceView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface() {
	if (LOG_EGL) {
		Log.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
	}
	/*
	 * Check preconditions.
	 */
	if (mEgl == null) {
		throw new RuntimeException("egl not initialized");
	}
	if (mEglDisplay == null) {
		throw new RuntimeException("eglDisplay not initialized");
	}
	if (mEglConfig == null) {
		throw new RuntimeException("mEglConfig not initialized");
	}

	/*
	 *  The window size has changed, so we need to create a new
	 *  surface.
	 */
	destroySurfaceImp();

	/*
	 * Create an EGL surface we can render into.
	 */
	GLSurfaceView view = mGLSurfaceViewWeakRef.get();
	if (view != null) {
		mEglSurface = view.mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
				mEglDisplay, mEglConfig, view.getHolder());
	} else {
		mEglSurface = null;
	}

	if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
		int error = mEgl.eglGetError();
		if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
			Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
		}
		return false;
	}

	/*
	 * Before we can issue GL commands, we need to make sure
	 * the context is current and bound to a surface.
	 */
	if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
		/*
		 * Could not make the context current, probably because the underlying
		 * SurfaceView surface has been destroyed.
		 */
		logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
		return false;
	}

	return true;
}
 
Example 20
Source File: GLTextureView.java    From alpha-movie with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface() {
    if (LOG_EGL) {
        Log.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
    }
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    GLTextureView view = mGLSurfaceViewWeakRef.get();
    if (view != null) {
        mEglSurface = view.mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
                mEglDisplay, mEglConfig, view.getSurfaceTexture());
    } else {
        mEglSurface = null;
    }

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * Before we can issue GL commands, we need to make sure
     * the context is current and bound to a surface.
     */
    if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}