android.opengl.EGL14 Java Examples
The following examples show how to use
android.opengl.EGL14.
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: InputSurface.java From LiveMultimedia with Apache License 2.0 | 6 votes |
/** * Discard all resources held by this class, notably the EGL context. Also releases the * Surface that was passed to our constructor. */ public void release() { if (EGL14.eglGetCurrentContext().equals(mEGLContext)) { // Clear the current context and surface to ensure they are discarded immediately. EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); } EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface); EGL14.eglDestroyContext(mEGLDisplay, mEGLContext); //EGL14.eglTerminate(mEGLDisplay); mSurface.release(); // null everything out so future attempts to use this object will cause an NPE mEGLDisplay = null; mEGLContext = null; mEGLSurface = null; mSurface = null; }
Example #2
Source File: EGLBase.java From MegviiFacepp-Android-SDK with Apache License 2.0 | 6 votes |
/** * change context to draw this window surface * @return */ private boolean makeCurrent(final EGLSurface surface) { // if (DEBUG) Log.v(TAG, "makeCurrent:"); if (mEglDisplay == null) { if (DEBUG) Log.d(TAG, "makeCurrent:eglDisplay not initialized"); } if (surface == null || surface == EGL14.EGL_NO_SURFACE) { final int error = EGL14.eglGetError(); if (error == EGL14.EGL_BAD_NATIVE_WINDOW) { Log.e(TAG, "makeCurrent:returned EGL_BAD_NATIVE_WINDOW."); } return false; } // attach EGL renderring context to specific EGL window surface if (!EGL14.eglMakeCurrent(mEglDisplay, surface, surface, mEglContext)) { Log.w(TAG, "eglMakeCurrent:" + EGL14.eglGetError()); return false; } return true; }
Example #3
Source File: EglCore.java From sealrtc-android with MIT License | 6 votes |
/** * Discards all resources held by this class, notably the EGL context. This must be called from * the thread where the context was created. * * <p>On completion, no context will be current. */ public void release() { if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) { // Android is unusual in that it uses a reference-counted EGLDisplay. So for // every eglInitialize() we need an eglTerminate(). EGL14.eglMakeCurrent( mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); EGL14.eglDestroyContext(mEGLDisplay, mEGLContext); EGL14.eglReleaseThread(); EGL14.eglTerminate(mEGLDisplay); } mEGLDisplay = EGL14.EGL_NO_DISPLAY; mEGLContext = EGL14.EGL_NO_CONTEXT; mEGLConfig = null; }
Example #4
Source File: EGLBase.java From UVCCameraZxing with Apache License 2.0 | 6 votes |
private void destroyContext() { if (DEBUG) Log.v(TAG, "destroyContext:"); if (!EGL14.eglDestroyContext(mEglDisplay, mEglContext)) { Log.e("destroyContext", "display:" + mEglDisplay + " context: " + mEglContext); Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError()); } mEglContext = EGL14.EGL_NO_CONTEXT; if (mDefaultContext != EGL14.EGL_NO_CONTEXT) { if (!EGL14.eglDestroyContext(mEglDisplay, mDefaultContext)) { Log.e("destroyContext", "display:" + mEglDisplay + " context: " + mDefaultContext); Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError()); } mDefaultContext = EGL14.EGL_NO_CONTEXT; } }
Example #5
Source File: EGLSurfaceTexture.java From Telegram with GNU General Public License v2.0 | 6 votes |
private static EGLContext createEGLContext( EGLDisplay display, EGLConfig config, @SecureMode int secureMode) { int[] glAttributes; if (secureMode == SECURE_MODE_NONE) { glAttributes = new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; } else { glAttributes = new int[] { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL_PROTECTED_CONTENT_EXT, EGL14.EGL_TRUE, EGL14.EGL_NONE }; } EGLContext context = EGL14.eglCreateContext( display, config, android.opengl.EGL14.EGL_NO_CONTEXT, glAttributes, 0); if (context == null) { throw new GlException("eglCreateContext failed"); } return context; }
Example #6
Source File: EGLSurfaceTexture.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private static EGLConfig chooseEGLConfig(EGLDisplay display) { EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[1]; boolean success = EGL14.eglChooseConfig( display, EGL_CONFIG_ATTRIBUTES, /* attrib_listOffset= */ 0, configs, /* configsOffset= */ 0, /* config_size= */ 1, numConfigs, /* num_configOffset= */ 0); if (!success || numConfigs[0] <= 0 || configs[0] == null) { throw new GlException( Util.formatInvariant( /* format= */ "eglChooseConfig failed: success=%b, numConfigs[0]=%d, configs[0]=%s", success, numConfigs[0], configs[0])); } return configs[0]; }
Example #7
Source File: GLMovieRecorder.java From PhotoMovie with Apache License 2.0 | 6 votes |
/** * Discards all resources held by this class, notably the EGL context. Also releases the * Surface that was passed to our constructor. */ public void release() { if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) { EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface); EGL14.eglDestroyContext(mEGLDisplay, mEGLContext); EGL14.eglReleaseThread(); EGL14.eglTerminate(mEGLDisplay); } mSurface.release(); mEGLDisplay = EGL14.EGL_NO_DISPLAY; mEGLContext = EGL14.EGL_NO_CONTEXT; mEGLSurface = EGL14.EGL_NO_SURFACE; mSurface = null; }
Example #8
Source File: InputSurface.java From AndroidVideoSamples with Apache License 2.0 | 6 votes |
/** * Discard all resources held by this class, notably the EGL context. Also releases the Surface that was passed to our constructor. */ public void release() { if ( EGL14.eglGetCurrentContext().equals( mEGLContext ) ) { // Clear the current context and surface to ensure they are discarded immediately. EGL14.eglMakeCurrent( mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT ); } EGL14.eglDestroySurface( mEGLDisplay, mEGLSurface ); EGL14.eglDestroyContext( mEGLDisplay, mEGLContext ); // EGL14.eglTerminate(mEGLDisplay); mSurface.release(); // null everything out so future attempts to use this object will cause an NPE mEGLDisplay = null; mEGLContext = null; mEGLSurface = null; mSurface = null; }
Example #9
Source File: EGLBase.java From CameraRecorder-android with MIT License | 6 votes |
private void destroyContext() { if (DEBUG) Log.v(TAG, "destroyContext:"); if (!EGL14.eglDestroyContext(eglDisplay, eglContext)) { Log.e("destroyContext", "display:" + eglDisplay + " context: " + eglContext); Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError()); } eglContext = EGL14.EGL_NO_CONTEXT; if (defaultContext != EGL14.EGL_NO_CONTEXT) { if (!EGL14.eglDestroyContext(eglDisplay, defaultContext)) { Log.e("destroyContext", "display:" + eglDisplay + " context: " + defaultContext); Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError()); } defaultContext = EGL14.EGL_NO_CONTEXT; } }
Example #10
Source File: EGLSurfaceTexture.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private static EGLContext createEGLContext( EGLDisplay display, EGLConfig config, @SecureMode int secureMode) { int[] glAttributes; if (secureMode == SECURE_MODE_NONE) { glAttributes = new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; } else { glAttributes = new int[] { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL_PROTECTED_CONTENT_EXT, EGL14.EGL_TRUE, EGL14.EGL_NONE }; } EGLContext context = EGL14.eglCreateContext( display, config, android.opengl.EGL14.EGL_NO_CONTEXT, glAttributes, 0); if (context == null) { throw new GlException("eglCreateContext failed"); } return context; }
Example #11
Source File: GLSurfaceView.java From unity-ads-android with Apache License 2.0 | 6 votes |
private int[] filterConfigSpec(int[] configSpec) { if (mEGLContextClientVersion != 2 && mEGLContextClientVersion != 3) { return configSpec; } /* We know none of the subclasses define EGL_RENDERABLE_TYPE. * And we know the configSpec is well formed. */ int len = configSpec.length; int[] newConfigSpec = new int[len + 2]; System.arraycopy(configSpec, 0, newConfigSpec, 0, len-1); newConfigSpec[len-1] = EGL10.EGL_RENDERABLE_TYPE; if (mEGLContextClientVersion == 2) { newConfigSpec[len] = EGL14.EGL_OPENGL_ES2_BIT; /* EGL_OPENGL_ES2_BIT */ } else { newConfigSpec[len] = EGLExt.EGL_OPENGL_ES3_BIT_KHR; /* EGL_OPENGL_ES3_BIT_KHR */ } newConfigSpec[len+1] = EGL10.EGL_NONE; return newConfigSpec; }
Example #12
Source File: DecoderSurface.java From Mp4Composer-android with MIT License | 6 votes |
/** * Discard all resources held by this class, notably the EGL context. */ void release() { if (eglDisplay != EGL14.EGL_NO_DISPLAY) { EGL14.eglDestroySurface(eglDisplay, eglSurface); EGL14.eglDestroyContext(eglDisplay, eglContext); EGL14.eglReleaseThread(); EGL14.eglTerminate(eglDisplay); } surface.release(); previewTexture.release(); // this causes a bunch of warnings that appear harmless but might confuse someone: // W BufferQueue: [unnamed-3997-2] cancelBuffer: BufferQueue has been abandoned! //surfaceTexture.release(); eglDisplay = EGL14.EGL_NO_DISPLAY; eglContext = EGL14.EGL_NO_CONTEXT; eglSurface = EGL14.EGL_NO_SURFACE; filter.release(); filter = null; surface = null; previewTexture = null; }
Example #13
Source File: OutputSurface.java From phoenix with Apache License 2.0 | 6 votes |
/** * Discard all resources held by this class, notably the EGL context. */ public void release() { if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) { EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface); EGL14.eglDestroyContext(mEGLDisplay, mEGLContext); EGL14.eglReleaseThread(); EGL14.eglTerminate(mEGLDisplay); } 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(); mEGLDisplay = EGL14.EGL_NO_DISPLAY; mEGLContext = EGL14.EGL_NO_CONTEXT; mEGLSurface = EGL14.EGL_NO_SURFACE; mTextureRender = null; mSurface = null; mSurfaceTexture = null; }
Example #14
Source File: EglCore.java From MockCamera with Apache License 2.0 | 6 votes |
/** * Discards all resources held by this class, notably the EGL context. This must be * called from the thread where the context was created. * <p/> * On completion, no context will be current. */ public void release() { if (eGLDisplay != EGL14.EGL_NO_DISPLAY) { // Android is unusual in that it uses a reference-counted EGLDisplay. So for // every eglInitialize() we need an eglTerminate(). EGL14.eglMakeCurrent(eGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); EGL14.eglDestroyContext(eGLDisplay, eGLContext); EGL14.eglReleaseThread(); EGL14.eglTerminate(eGLDisplay); } eGLDisplay = EGL14.EGL_NO_DISPLAY; eGLContext = EGL14.EGL_NO_CONTEXT; eGLConfig = null; }
Example #15
Source File: GlPreviewRenderer.java From GPUVideo-android with MIT License | 5 votes |
public void setVideoEncoder(final MediaVideoEncoder encoder) { glView.queueEvent(new Runnable() { @Override public void run() { synchronized (GlPreviewRenderer.this) { if (encoder != null) { encoder.setEglContext(EGL14.eglGetCurrentContext(), texName); } videoEncoder = encoder; } } }); }
Example #16
Source File: EglBaseSurface.java From Lassi-Android with MIT License | 5 votes |
/** * Returns the surface's height, in pixels. */ public int getHeight() { if (mHeight < 0) { return mEglCore.querySurface(mEGLSurface, EGL14.EGL_HEIGHT); } else { return mHeight; } }
Example #17
Source File: EglCore.java From IjkVRPlayer with Apache License 2.0 | 5 votes |
/** * Writes the current display, context, and surface to the log. */ public static void logCurrent(String msg) { EGLDisplay display; EGLContext context; EGLSurface surface; display = EGL14.eglGetCurrentDisplay(); context = EGL14.eglGetCurrentContext(); surface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW); Log.i(TAG, "Current EGL (" + msg + "): display=" + display + ", context=" + context + ", surface=" + surface); }
Example #18
Source File: EglSurfaceBase.java From RtmpPublisher with Apache License 2.0 | 5 votes |
/** * Creates an off-screen surface. */ public void createOffscreenSurface(int width, int height) { if (mEGLSurface != EGL14.EGL_NO_SURFACE) { throw new IllegalStateException("surface already created"); } mEGLSurface = mEglCore.createOffscreenSurface(width, height); mWidth = width; mHeight = height; }
Example #19
Source File: EglBaseSurface.java From Lassi-Android with MIT License | 5 votes |
/** * Creates an off-screen surface. */ public void createOffscreenSurface(int width, int height) { if (mEGLSurface != EGL14.EGL_NO_SURFACE) { throw new IllegalStateException("surface already created"); } mEGLSurface = mEglCore.createOffscreenSurface(width, height); mWidth = width; mHeight = height; }
Example #20
Source File: EglCore.java From grafika with Apache License 2.0 | 5 votes |
/** * Finds a suitable EGLConfig. * * @param flags Bit flags from constructor. * @param version Must be 2 or 3. */ private EGLConfig getConfig(int flags, int version) { int renderableType = EGL14.EGL_OPENGL_ES2_BIT; if (version >= 3) { renderableType |= EGLExt.EGL_OPENGL_ES3_BIT_KHR; } // The actual surface is generally RGBA or RGBX, so situationally omitting alpha // doesn't really help. It can also lead to a huge performance hit on glReadPixels() // when reading into a GL_RGBA buffer. int[] attribList = { EGL14.EGL_RED_SIZE, 8, EGL14.EGL_GREEN_SIZE, 8, EGL14.EGL_BLUE_SIZE, 8, EGL14.EGL_ALPHA_SIZE, 8, //EGL14.EGL_DEPTH_SIZE, 16, //EGL14.EGL_STENCIL_SIZE, 8, EGL14.EGL_RENDERABLE_TYPE, renderableType, EGL14.EGL_NONE, 0, // placeholder for recordable [@-3] EGL14.EGL_NONE }; if ((flags & FLAG_RECORDABLE) != 0) { attribList[attribList.length - 3] = EGL_RECORDABLE_ANDROID; attribList[attribList.length - 2] = 1; } EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig"); return null; } return configs[0]; }
Example #21
Source File: InputSurface.java From SimpleVideoEdit with Apache License 2.0 | 5 votes |
/** * Checks for EGL errors. */ private void checkEglError(String msg) { int error; if ((error = EGL14.eglGetError()) != EGL14.EGL_SUCCESS) { throw new RuntimeException(msg + ": EGL error: 0x" + Integer.toHexString(error)); } }
Example #22
Source File: EglSurfaceBase.java From Fatigue-Detection with MIT License | 5 votes |
/** * Creates an off-screen surface. */ public void createOffscreenSurface(int width, int height) { if (mEGLSurface != EGL14.EGL_NO_SURFACE) { throw new IllegalStateException("surface already created"); } mEGLSurface = mEglCore.createOffscreenSurface(width, height); mWidth = width; mHeight = height; }
Example #23
Source File: EglCore.java From LiveVideoBroadcaster with Apache License 2.0 | 5 votes |
@Override protected void finalize() throws Throwable { try { if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) { // We're limited here -- finalizers don't run on the thread that holds // the EGL state, so if a surface or activity is still current on another // thread we can't fully release it here. Exceptions thrown from here // are quietly discarded. Complain in the log file. Log.w(TAG, "WARNING: EglCore was not explicitly released -- state may be leaked"); release(); } } finally { super.finalize(); } }
Example #24
Source File: EGLBase14.java From libcommon with Apache License 2.0 | 5 votes |
@Override public void release() { // if (DEBUG) Log.v(TAG, "EglSurface:release:"); mEglBase.makeDefault(); if (mOwnSurface) { mEglBase.destroyWindowSurface(mEglSurface); } mEglSurface = EGL14.EGL_NO_SURFACE; }
Example #25
Source File: EglSurfaceBase.java From sealrtc-android with MIT License | 5 votes |
/** * Creates a window surface. * * <p> * * @param surface May be a Surface or SurfaceTexture. */ public void createWindowSurface(Object surface) { if (mEGLSurface != EGL14.EGL_NO_SURFACE) { throw new IllegalStateException("surface already created"); } mEGLSurface = mEglCore.createWindowSurface(surface); // Don't cache width/height here, because the size of the underlying surface can change // out from under us (see e.g. HardwareScalerActivity). // mWidth = mEglCore.querySurface(mEGLSurface, EGL14.EGL_WIDTH); // mHeight = mEglCore.querySurface(mEGLSurface, EGL14.EGL_HEIGHT); }
Example #26
Source File: GLThread.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override public android.opengl.EGLContext createContextAPI17(android.opengl.EGLDisplay display, android.opengl.EGLConfig eglConfig, android.opengl.EGLContext sharedContext) { int[] attrib_list = { EGL14.EGL_CONTEXT_CLIENT_VERSION, contextClientVersion, EGL14.EGL_NONE}; return EGL14.eglCreateContext(display, eglConfig, sharedContext, attrib_list, 0); }
Example #27
Source File: EglCore.java From pause-resume-video-recording with Apache License 2.0 | 5 votes |
/** * Finds a suitable EGLConfig. * * @param flags Bit flags from constructor. * @param version Must be 2 or 3. */ private EGLConfig getConfig(int flags, int version) { int renderableType = EGL14.EGL_OPENGL_ES2_BIT; if (version >= 3) { renderableType |= EGLExt.EGL_OPENGL_ES3_BIT_KHR; } // The actual surface is generally RGBA or RGBX, so situationally omitting alpha // doesn't really help. It can also lead to a huge performance hit on glReadPixels() // when reading into a GL_RGBA buffer. int[] attribList = { EGL14.EGL_RED_SIZE, 8, EGL14.EGL_GREEN_SIZE, 8, EGL14.EGL_BLUE_SIZE, 8, EGL14.EGL_ALPHA_SIZE, 8, //EGL14.EGL_DEPTH_SIZE, 16, //EGL14.EGL_STENCIL_SIZE, 8, EGL14.EGL_RENDERABLE_TYPE, renderableType, EGL14.EGL_NONE, 0, // placeholder for recordable [@-3] EGL14.EGL_NONE }; if ((flags & FLAG_RECORDABLE) != 0) { attribList[attribList.length - 3] = EGL_RECORDABLE_ANDROID; attribList[attribList.length - 2] = 1; } EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig"); return null; } return configs[0]; }
Example #28
Source File: EGLBase14.java From libcommon with Apache License 2.0 | 5 votes |
private EGLConfig internalGetConfig(final int[] attribList) { final EGLConfig[] configs = new EGLConfig[1]; final int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(mEglDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { return null; } return configs[0]; }
Example #29
Source File: EglCore.java From MockCamera with Apache License 2.0 | 5 votes |
@Override protected void finalize() throws Throwable { try { if (eGLDisplay != EGL14.EGL_NO_DISPLAY) { // We're limited here -- finalizers don't run on the thread that holds // the EGL state, so if a surface or context is still current on another // thread we can't fully release it here. Exceptions thrown from here // are quietly discarded. Complain in the log file. Log.w(TAG, "WARNING: EglCore was not explicitly released -- state may be leaked"); release(); } } finally { super.finalize(); } }
Example #30
Source File: EglCore.java From VideoRecorder with Apache License 2.0 | 5 votes |
/** * Creates an EGL surface associated with an offscreen buffer. */ public EGLSurface createOffscreenSurface(int width, int height) { int[] surfaceAttribs = { EGL14.EGL_WIDTH, width, EGL14.EGL_HEIGHT, height, EGL14.EGL_NONE }; EGLSurface eglSurface = EGL14.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, surfaceAttribs, 0); checkEglError("eglCreatePbufferSurface"); if (eglSurface == null) { throw new RuntimeException("surface was null"); } return eglSurface; }