Java Code Examples for android.opengl.EGL14#eglMakeCurrent()

The following examples show how to use android.opengl.EGL14#eglMakeCurrent() . 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: EGLBase.java    From AudioVideoPlayerSample with Apache License 2.0 6 votes vote down vote up
/**
 * change context to draw this window surface
 * @return
 */
private boolean makeCurrent(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) {
           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 2
Source File: InputSurface.java    From AndroidVideoSamples with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: EglCore.java    From AndroidPlayground with MIT License 6 votes vote down vote up
/**
 * 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: EncodeAndMuxTest.java    From Android-MediaCodec-Examples with Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source File: EglHelper.java    From AAVT with Apache License 2.0 6 votes vote down vote up
public boolean createGLESWithSurface(EGLConfigAttrs attrs,EGLContextAttrs ctxAttrs,Object surface){
    EGLConfig config=getConfig(attrs.surfaceType(EGL14.EGL_WINDOW_BIT).makeDefault(true));
    if(config==null){
        log("getConfig failed : "+EGL14.eglGetError());
        return false;
    }
    mEGLContext=createContext(config,EGL14.EGL_NO_CONTEXT,ctxAttrs.makeDefault(true));
    if(mEGLContext==EGL14.EGL_NO_CONTEXT){
        log("createContext failed : "+EGL14.eglGetError());
        return false;
    }
    mEGLSurface=createWindowSurface(surface);
    if(mEGLSurface==EGL14.EGL_NO_SURFACE){
        log("createWindowSurface failed : "+EGL14.eglGetError());
        return false;
    }
    if(!EGL14.eglMakeCurrent(mEGLDisplay,mEGLSurface,mEGLSurface,mEGLContext)){
        log("eglMakeCurrent failed : "+EGL14.eglGetError());
        return false;
    }
    return true;
}
 
Example 6
Source File: EglBase14Impl.java    From webrtc_android with MIT License 5 votes vote down vote up
@Override
public void makeCurrent() {
  checkIsNotReleased();
  if (eglSurface == EGL14.EGL_NO_SURFACE) {
    throw new RuntimeException("No EGLSurface - can't make current");
  }
  synchronized (EglBase.lock) {
    if (!EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
      throw new RuntimeException(
          "eglMakeCurrent failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
    }
  }
}
 
Example 7
Source File: EglCore.java    From mobile-ar-sensor-logger with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Makes our EGL context current, using the supplied surface for both "draw" and "read".
 */
public void makeCurrent(EGLSurface eglSurface) {
    if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
        // called makeCurrent() before create?
        Log.d(TAG, "NOTE: makeCurrent w/o display");
    }
    if (!EGL14.eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext)) {
        throw new RuntimeException("eglMakeCurrent failed");
    }
}
 
Example 8
Source File: InputSurface.java    From SiliCompressor with Apache License 2.0 5 votes vote down vote up
public void release() {
    if (EGL14.eglGetCurrentContext().equals(mEGLContext)) {
        EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    }
    EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
    EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
    mSurface.release();
    mEGLDisplay = null;
    mEGLContext = null;
    mEGLSurface = null;
    mSurface = null;
}
 
Example 9
Source File: InputSurface.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void release() {
    if (EGL14.eglGetCurrentContext().equals(mEGLContext)) {
        EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    }
    EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
    EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
    mSurface.release();
    mEGLDisplay = null;
    mEGLContext = null;
    mEGLSurface = null;
    mSurface = null;
}
 
Example 10
Source File: EGLEnvironment.java    From EZFilter with MIT License 5 votes vote down vote up
private void destroyWindowSurface(EGLSurface surface) {
    if (surface != EGL14.EGL_NO_SURFACE) {
        EGL14.eglMakeCurrent(mEglDisplay,
                EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
        EGL14.eglDestroySurface(mEglDisplay, surface);
    }
    surface = EGL14.EGL_NO_SURFACE;
}
 
Example 11
Source File: EglCore.java    From IjkVRPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * Makes our EGL context current, using the supplied surface for both "draw" and "read".
 */
public void makeCurrent(EGLSurface eglSurface) {
    if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
        // called makeCurrent() before create?
        Log.d(TAG, "NOTE: makeCurrent w/o display");
    }
    if (!EGL14.eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext)) {
        throw new RuntimeException("eglMakeCurrent failed");
    }
}
 
Example 12
Source File: EglCore.java    From LiveVideoBroadcaster with Apache License 2.0 5 votes vote down vote up
/**
 * Makes our EGL activity current, using the supplied "draw" and "read" surfaces.
 */
public void makeCurrent(EGLSurface drawSurface, EGLSurface readSurface) {
    if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
        // called makeCurrent() before create?
        Log.d(TAG, "NOTE: makeCurrent w/o display");
    }
    if (!EGL14.eglMakeCurrent(mEGLDisplay, drawSurface, readSurface, mEGLContext)) {
        throw new RuntimeException("eglMakeCurrent(draw,read) failed");
    }
}
 
Example 13
Source File: InputSurface.java    From android-transcoder with Apache License 2.0 4 votes vote down vote up
/**
 * Makes our EGL context and surface current.
 */
public void makeCurrent() {
    if (!EGL14.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) {
        throw new RuntimeException("eglMakeCurrent failed");
    }
}
 
Example 14
Source File: SketchUtils.java    From sketch with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static int getOpenGLMaxTextureSizeJB1() {
    // Then get a hold of the default display, and initialize.
    // This could get more complex if you have to deal with devices that could have multiple displays,
    // but will be sufficient for a typical phone/tablet:
    android.opengl.EGLDisplay dpy = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    EGL14.eglInitialize(dpy, vers, 0, vers, 1);

    // Next, we need to find a config. Since we won't use this context for rendering,
    // the exact attributes aren't very critical:
    int[] configAttr = {
            EGL14.EGL_COLOR_BUFFER_TYPE, EGL14.EGL_RGB_BUFFER,
            EGL14.EGL_LEVEL, 0,
            EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
            EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT,
            EGL14.EGL_NONE
    };
    android.opengl.EGLConfig[] configs = new android.opengl.EGLConfig[1];
    int[] numConfig = new int[1];
    EGL14.eglChooseConfig(dpy, configAttr, 0,
            configs, 0, 1, numConfig, 0);
    //noinspection StatementWithEmptyBody
    if (numConfig[0] == 0) {
        // TROUBLE! No config found.
    }
    android.opengl.EGLConfig config = configs[0];

    // To make a context current, which we will need later,
    // you need a rendering surface, even if you don't actually plan to render.
    // To satisfy this requirement, create a small offscreen (Pbuffer) surface:
    int[] surfAttr = {
            EGL14.EGL_WIDTH, 64,
            EGL14.EGL_HEIGHT, 64,
            EGL14.EGL_NONE
    };
    android.opengl.EGLSurface surf = EGL14.eglCreatePbufferSurface(dpy, config, surfAttr, 0);

    // Next, create the context:
    int[] ctxAttrib = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };
    android.opengl.EGLContext ctx = EGL14.eglCreateContext(dpy, config, EGL14.EGL_NO_CONTEXT, ctxAttrib, 0);

    // Ready to make the context current now:
    EGL14.eglMakeCurrent(dpy, surf, surf, ctx);

    // If all of the above succeeded (error checking was omitted), you can make your OpenGL calls now:
    int[] maxSize = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxSize, 0);

    // Once you're all done, you can tear down everything:
    EGL14.eglMakeCurrent(dpy, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
            EGL14.EGL_NO_CONTEXT);
    EGL14.eglDestroySurface(dpy, surf);
    EGL14.eglDestroyContext(dpy, ctx);
    EGL14.eglTerminate(dpy);

    return maxSize[0];
}
 
Example 15
Source File: CameraToMpegTest.java    From Android-MediaCodec-Examples with Apache License 2.0 4 votes vote down vote up
/**
 * Makes our EGL context and surface current.
 */
public void makeCurrent() {
    EGL14.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
    checkEglError("eglMakeCurrent");
}
 
Example 16
Source File: InputSurface.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void makeCurrent() {
    if (!EGL14.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) {
        throw new RuntimeException("eglMakeCurrent failed");
    }
}
 
Example 17
Source File: ColorFade.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void detachEglContext() {
    if (mEglDisplay != null) {
        EGL14.eglMakeCurrent(mEglDisplay,
                EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    }
}
 
Example 18
Source File: Converter.java    From VidEffects with Apache License 2.0 4 votes vote down vote up
private void initEgl(Surface inputSurface) {

        eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);

        if (eglDisplay == EGL14.EGL_NO_DISPLAY) {
            Log.e(TAG, "eglDisplay == EGL14.EGL_NO_DISPLAY: " + GLUtils.getEGLErrorString(EGL14.eglGetError()));
        }

        int[] version = new int[2];

        int[] attrsList = new int[]{
                EGL14.EGL_RED_SIZE, 8,
                EGL14.EGL_GREEN_SIZE, 8,
                EGL14.EGL_BLUE_SIZE, 8,
                EGL14.EGL_ALPHA_SIZE, 8,
                EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
                EGL_RECORDABLE_ANDROID, 1,
                EGL14.EGL_NONE
        };

        EGLConfig[] configs = new EGLConfig[1];

        int[] ctxAttrs = {
                EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL14.EGL_NONE
        };

        int[] surfaceAttrs = {
                EGL14.EGL_NONE
        };

        if (!EGL14.eglInitialize(eglDisplay, version, 0, version, 1)) {
            Log.e(TAG, "eglInitialize: " + GLUtils.getEGLErrorString(EGL14.eglGetError()));
        }

        if (!EGL14.eglChooseConfig(eglDisplay, attrsList, 0, configs, 0, configs.length, new int[configs.length], 0)) {
            Log.e(TAG, GLUtils.getEGLErrorString(EGL14.eglGetError()));
        }

        eglContext = EGL14.eglCreateContext(eglDisplay, configs[0], EGL14.EGL_NO_CONTEXT, ctxAttrs, 0);
        eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, configs[0], inputSurface, surfaceAttrs, 0);

        if (!EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
            Log.d(TAG, "eglMakeCurrent: " + GLUtils.getEGLErrorString(EGL14.eglGetError()));
        }
    }
 
Example 19
Source File: OutputSurface.java    From android-transcoder with Apache License 2.0 4 votes vote down vote up
/**
 * Makes our EGL context and surface current.
 */
public void makeCurrent() {
    if (!EGL14.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext)) {
        throw new RuntimeException("eglMakeCurrent failed");
    }
}
 
Example 20
Source File: EncodeAndMuxTest.java    From Android-MediaCodec-Examples with Apache License 2.0 4 votes vote down vote up
/**
 * Makes our EGL context and surface current.
 */
public void makeCurrent() {
    EGL14.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
    checkEglError("eglMakeCurrent");
}