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

The following examples show how to use javax.microedition.khronos.egl.EGL10#eglDestroyContext() . 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: 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 2
Source File: DeviceConfiguration.java    From android_packages_apps_GmsCore with Apache License 2.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) {
        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 (s != null && !s.isEmpty()) {
                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: GLTextureView.java    From ZGDanmaku with Apache License 2.0 5 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display,
                           EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
        if (LOG_THREADS) {
            Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
        }
        EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
    }
}
 
Example 4
Source File: GLSurfaceView.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
@Override
public void destroyContext(EGL10 egl, EGLDisplay display,
		EGLContext context) {
	if (!egl.eglDestroyContext(display, context)) {
		Log.e("DefaultContextFactory", "display:" + display
				+ " context: " + context);
		if (LOG_THREADS) {
			Log.i("DefaultContextFactory", "tid="
					+ Thread.currentThread().getId());
		}
		throw new RuntimeException("eglDestroyContext failed: " + ""); // +
																		// EGLLogWrapper.getErrorString(egl.eglGetError()));
	}
}
 
Example 5
Source File: GLThread.java    From android-openGL-canvas with Apache License 2.0 5 votes vote down vote up
@Override
public void destroyContext(EGL10 egl, EGLDisplay display,
                           EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        FileLogger.e(TAG, "DefaultContextFactory " + "display:" + display + " context: " + context);
        EglHelper.throwEglException("eglDestroyContext", egl.eglGetError());
    }
}
 
Example 6
Source File: TextureVideoView.java    From texturevideoview with Apache License 2.0 5 votes vote down vote up
/**
 * Clears the surface texture by attaching a GL context and clearing it.
 * Code taken from <a href="http://stackoverflow.com/a/31582209">Hugo Gresse's answer on stackoverflow.com</a>.
 */
private void clearSurface() {
    if (mSurface == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        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,      // placeholder for recordable [@-3]
        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, mSurface, 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 7
Source File: GLTextureView.java    From android-RoundedTextureView with Apache License 2.0 5 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
  if (!egl.eglDestroyContext(display, context)) {
    Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
    if (LOG_THREADS) {
      Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
    }
    EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
  }
}
 
Example 8
Source File: DefaultContextFactory.java    From GPUVideo-android with MIT License 5 votes vote down vote up
@Override
public void destroyContext(final EGL10 egl, final EGLDisplay display, final EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        Log.e(TAG, "display:" + display + " context: " + context);
        throw new RuntimeException("eglDestroyContext" + egl.eglGetError());
    }
}
 
Example 9
Source File: GOSurfaceView.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void destroyContext(EGL10 arg0, EGLDisplay arg1, EGLContext arg2) {
	Log.w("gl", "Invalidating texture context");
	if(drawcontext != null) drawcontext.invalidateContext();
	AndroidTextDrawer.invalidateTextures();
	IContextDestroyedListener listener = contextDestroyedListener;
	if (listener != null) {
		listener.glContextDestroyed();
	}
	arg0.eglDestroyContext(arg1, arg2);
}
 
Example 10
Source File: DefaultContextFactory.java    From CameraRecorder-android with MIT License 5 votes vote down vote up
@Override
public void destroyContext(final EGL10 egl, final EGLDisplay display, final EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        Log.e(TAG, "display:" + display + " context: " + context);
        throw new RuntimeException("eglDestroyContext" + egl.eglGetError());
    }
}
 
Example 11
Source File: GLSurfaceView.java    From unity-ads-android with Apache License 2.0 5 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display,
						   EGLContext context) {
	if (!egl.eglDestroyContext(display, context)) {
		Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
		if (LOG_THREADS) {
			Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
		}
		EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
	}
}
 
Example 12
Source File: GLTextureView.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display,
                           EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
        if (LOG_THREADS) {
            Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
        }
        EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
    }
}
 
Example 13
Source File: ResizingTextureView.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
/**
 * Clears the frames from the current surface.  This should only be called when
 * the implementing video view has finished playback or otherwise released
 * the surface
 */
@Override
public void clearSurface() {
    if (getSurfaceTexture() == null) {
        return;
    }

    try {
        EGL10 gl10 = (EGL10) EGLContext.getEGL();
        EGLDisplay display = gl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        gl10.eglInitialize(display, null);

        EGLConfig[] configs = new EGLConfig[1];
        gl10.eglChooseConfig(display, GL_CLEAR_CONFIG_ATTRIBUTES, configs, configs.length, new int[1]);
        EGLContext context = gl10.eglCreateContext(display, configs[0], EGL10.EGL_NO_CONTEXT, GL_CLEAR_CONTEXT_ATTRIBUTES);
        EGLSurface eglSurface = gl10.eglCreateWindowSurface(display, configs[0], getSurfaceTexture(), new int[]{EGL10.EGL_NONE});

        gl10.eglMakeCurrent(display, eglSurface, eglSurface, context);
        gl10.eglSwapBuffers(display, eglSurface);
        gl10.eglDestroySurface(display, eglSurface);
        gl10.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        gl10.eglDestroyContext(display, context);

        gl10.eglTerminate(display);
    } catch (Exception e) {
        Log.e(TAG, "Error clearing surface", e);
    }
}
 
Example 14
Source File: ViEAndroidGLES20.java    From webrtc-app-mono with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
    egl.eglDestroyContext(display, context);
}
 
Example 15
Source File: EGL.java    From BambooPlayer with Apache License 2.0 4 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
  if (!egl.eglDestroyContext(display, context)) {
    Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
    throw new RuntimeException("eglDestroyContext failed: ");
  }
}
 
Example 16
Source File: EglUtils.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static int getMaxTextureEgl10() {
    EGL10 egl = (EGL10) javax.microedition.khronos.egl.EGLContext.getEGL();

    javax.microedition.khronos.egl.EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    egl.eglInitialize(dpy, vers);

    int[] configAttr = {
            EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RGB_BUFFER,
            EGL10.EGL_LEVEL, 0,
            EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
            EGL10.EGL_NONE
    };
    javax.microedition.khronos.egl.EGLConfig[] configs = new javax.microedition.khronos.egl.EGLConfig[1];
    int[] numConfig = new int[1];
    egl.eglChooseConfig(dpy, configAttr, configs, 1, numConfig);
    if (numConfig[0] == 0) {
        return 0;
    }
    javax.microedition.khronos.egl.EGLConfig config = configs[0];

    int[] surfAttr = {
            EGL10.EGL_WIDTH, 64,
            EGL10.EGL_HEIGHT, 64,
            EGL10.EGL_NONE
    };
    javax.microedition.khronos.egl.EGLSurface surf = egl.eglCreatePbufferSurface(dpy, config, surfAttr);
    final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;  // missing in EGL10
    int[] ctxAttrib = {
            EGL_CONTEXT_CLIENT_VERSION, 1,
            EGL10.EGL_NONE
    };
    javax.microedition.khronos.egl.EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, ctxAttrib);
    egl.eglMakeCurrent(dpy, surf, surf, ctx);
    int[] maxSize = new int[1];
    GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
    egl.eglMakeCurrent(dpy, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
            EGL10.EGL_NO_CONTEXT);
    egl.eglDestroySurface(dpy, surf);
    egl.eglDestroyContext(dpy, ctx);
    egl.eglTerminate(dpy);

    return maxSize[0];
}
 
Example 17
Source File: EGL.java    From video-player with MIT License 4 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
  if (!egl.eglDestroyContext(display, context)) {
    Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
    throw new RuntimeException("eglDestroyContext failed: ");
  }
}
 
Example 18
Source File: EglUtils.java    From Matisse-Kotlin with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static int getMaxTextureEgl10() {
    EGL10 egl = (EGL10) javax.microedition.khronos.egl.EGLContext.getEGL();

    javax.microedition.khronos.egl.EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    egl.eglInitialize(dpy, vers);

    int[] configAttr = {
            EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RGB_BUFFER,
            EGL10.EGL_LEVEL, 0,
            EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
            EGL10.EGL_NONE
    };
    javax.microedition.khronos.egl.EGLConfig[] configs = new javax.microedition.khronos.egl.EGLConfig[1];
    int[] numConfig = new int[1];
    egl.eglChooseConfig(dpy, configAttr, configs, 1, numConfig);
    if (numConfig[0] == 0) {
        return 0;
    }
    javax.microedition.khronos.egl.EGLConfig config = configs[0];

    int[] surfAttr = {
            EGL10.EGL_WIDTH, 64,
            EGL10.EGL_HEIGHT, 64,
            EGL10.EGL_NONE
    };
    javax.microedition.khronos.egl.EGLSurface surf = egl.eglCreatePbufferSurface(dpy, config, surfAttr);
    final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;  // missing in EGL10
    int[] ctxAttrib = {
            EGL_CONTEXT_CLIENT_VERSION, 1,
            EGL10.EGL_NONE
    };
    javax.microedition.khronos.egl.EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, ctxAttrib);
    egl.eglMakeCurrent(dpy, surf, surf, ctx);
    int[] maxSize = new int[1];
    GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
    egl.eglMakeCurrent(dpy, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
            EGL10.EGL_NO_CONTEXT);
    egl.eglDestroySurface(dpy, surf);
    egl.eglDestroyContext(dpy, ctx);
    egl.eglTerminate(dpy);

    return maxSize[0];
}
 
Example 19
Source File: ActivityManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Adds all supported GL extensions for a provided EGLConfig to a set by creating an EGLContext
 * and EGLSurface and querying extensions.
 *
 * @param egl An EGL API object
 * @param display An EGLDisplay to create a context and surface with
 * @param config The EGLConfig to get the extensions for
 * @param surfaceSize eglCreatePbufferSurface generic parameters
 * @param contextAttribs eglCreateContext generic parameters
 * @param glExtensions A Set<String> to add GL extensions to
 */
private static void addExtensionsForConfig(
        EGL10 egl,
        EGLDisplay display,
        EGLConfig config,
        int[] surfaceSize,
        int[] contextAttribs,
        Set<String> glExtensions) {
    // Create a context.
    EGLContext context =
            egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, contextAttribs);
    // No-op if we can't create a context.
    if (context == EGL10.EGL_NO_CONTEXT) {
        return;
    }

    // Create a surface.
    EGLSurface surface = egl.eglCreatePbufferSurface(display, config, surfaceSize);
    if (surface == EGL10.EGL_NO_SURFACE) {
        egl.eglDestroyContext(display, context);
        return;
    }

    // Update the current surface and context.
    egl.eglMakeCurrent(display, surface, surface, context);

    // Get the list of extensions.
    String extensionList = GLES10.glGetString(GLES10.GL_EXTENSIONS);
    if (!TextUtils.isEmpty(extensionList)) {
        // The list of extensions comes from the driver separated by spaces.
        // Split them apart and add them into a Set for deduping purposes.
        for (String extension : extensionList.split(" ")) {
            glExtensions.add(extension);
        }
    }

    // Tear down the context and surface for this config.
    egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    egl.eglDestroySurface(display, surface);
    egl.eglDestroyContext(display, context);
}
 
Example 20
Source File: EglUtils.java    From EasyPhotos with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static int getMaxTextureEgl10() {
    EGL10 egl = (EGL10) javax.microedition.khronos.egl.EGLContext.getEGL();

    javax.microedition.khronos.egl.EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    egl.eglInitialize(dpy, vers);

    int[] configAttr = {
            EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RGB_BUFFER,
            EGL10.EGL_LEVEL, 0,
            EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT,
            EGL10.EGL_NONE
    };
    javax.microedition.khronos.egl.EGLConfig[] configs = new javax.microedition.khronos.egl.EGLConfig[1];
    int[] numConfig = new int[1];
    egl.eglChooseConfig(dpy, configAttr, configs, 1, numConfig);
    if (numConfig[0] == 0) {
        return 0;
    }
    javax.microedition.khronos.egl.EGLConfig config = configs[0];

    int[] surfAttr = {
            EGL10.EGL_WIDTH, 64,
            EGL10.EGL_HEIGHT, 64,
            EGL10.EGL_NONE
    };
    javax.microedition.khronos.egl.EGLSurface surf = egl.eglCreatePbufferSurface(dpy, config, surfAttr);
    final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;  // missing in EGL10
    int[] ctxAttrib = {
            EGL_CONTEXT_CLIENT_VERSION, 1,
            EGL10.EGL_NONE
    };
    javax.microedition.khronos.egl.EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, ctxAttrib);
    egl.eglMakeCurrent(dpy, surf, surf, ctx);
    int[] maxSize = new int[1];
    GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
    egl.eglMakeCurrent(dpy, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
            EGL10.EGL_NO_CONTEXT);
    egl.eglDestroySurface(dpy, surf);
    egl.eglDestroyContext(dpy, ctx);
    egl.eglTerminate(dpy);

    return maxSize[0];
}