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

The following examples show how to use javax.microedition.khronos.egl.EGL10#eglGetDisplay() . 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 HPlayer with Apache License 2.0 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: GLConfiguration.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
public static void checkConfiguration() {
    final EGL10 egl = (EGL10) EGLContext.getEGL();
    final EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
        throw new RuntimeException("Your device cannot support EGL");
    }

    final int[] version = new int[2];
    if (!egl.eglInitialize(eglDisplay, version)) {
        throw new RuntimeException("Your device cannot support EGL");
    }

    try {
        if (getConfigChooser().chooseConfig(egl, eglDisplay) == null) {
            throw new RuntimeException("Your device cannot support required GLES configuration");
        }
    } catch (final Throwable th) {
        throw new RuntimeException("Your device cannot support required GLES configuration");
    } finally {
        egl.eglTerminate(eglDisplay);
    }
}
 
Example 3
Source File: AndEngine.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
private static void checkEGLConfigChooserSupport() throws DeviceNotSupportedException {
	/* Get an EGL instance. */
	final EGL10 egl = (EGL10) EGLContext.getEGL();

	/* Get to the default display. */
	final EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

	/* We can now initialize EGL for that display. */
	final int[] version = new int[2];
	egl.eglInitialize(eglDisplay, version);

	final ConfigChooser configChooser = new ConfigChooser(false); // TODO Doesn't correlate to possible multisampling request in EngineOptions...

	try {
		configChooser.chooseConfig(egl, eglDisplay);
	} catch (final IllegalArgumentException e) {
		throw new DeviceNotSupportedException(DeviceNotSupportedCause.EGLCONFIG_NOT_FOUND, e);
	}
}
 
Example 4
Source File: EGL.java    From BambooPlayer with Apache License 2.0 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 5
Source File: EGL.java    From NetEasyNews with GNU General Public License v3.0 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 6
Source File: SimpleLitGLCube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example 7
Source File: EglExtensionRetriever.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
public static List<String> getEglExtensions() {
    Set<String> glExtensions = new HashSet<>();
    EGL10 egl10 = (EGL10) EGLContext.getEGL();
    if (egl10 == null) {
        return new ArrayList<>();
    }
    EGLDisplay display = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    egl10.eglInitialize(display, new int[2]);
    int cf[] = new int[1];
    if (egl10.eglGetConfigs(display, null, 0, cf)) {
        EGLConfig[] configs = new EGLConfig[cf[0]];
        if (egl10.eglGetConfigs(display, configs, cf[0], cf)) {
            int[] a1 = new int[] {EGL10.EGL_WIDTH, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_HEIGHT, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_NONE};
            int[] a2 = new int[] {12440, EGL10.EGL_PIXMAP_BIT, EGL10.EGL_NONE};
            int[] a3 = new int[1];
            for (int i = 0; i < cf[0]; i++) {
                egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_CONFIG_CAVEAT, a3);
                if (a3[0] != EGL10.EGL_SLOW_CONFIG) {
                    egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_SURFACE_TYPE, a3);
                    if ((1 & a3[0]) != 0) {
                        egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_RENDERABLE_TYPE, a3);
                        if ((1 & a3[0]) != 0) {
                            addExtensionsForConfig(egl10, display, configs[i], a1, null, glExtensions);
                        }
                        if ((4 & a3[0]) != 0) {
                            addExtensionsForConfig(egl10, display, configs[i], a1, a2, glExtensions);
                        }
                    }
                }
            }
        }
    }
    egl10.eglTerminate(display);
    List<String> sorted = new ArrayList<>(glExtensions);
    Collections.sort(sorted);
    return sorted;
}
 
Example 8
Source File: BitmapUtil.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
public static int getMaxTextureSize() {
  final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

  EGL10 egl = (EGL10) EGLContext.getEGL();
  EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

  int[] version = new int[2];
  egl.eglInitialize(display, version);

  int[] totalConfigurations = new int[1];
  egl.eglGetConfigs(display, null, 0, totalConfigurations);

  EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
  egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

  int[] textureSize = new int[1];
  int maximumTextureSize = 0;

  for (int i = 0; i < totalConfigurations[0]; i++) {
    egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

    if (maximumTextureSize < textureSize[0])
      maximumTextureSize = textureSize[0];
  }

  egl.eglTerminate(display);

  return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
}
 
Example 9
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 10
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 11
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 12
Source File: OBVideoPlayer.java    From GLEXP-Team-onebillion with Apache License 2.0 4 votes vote down vote up
private void clearSurface(SurfaceTexture texture)
{
    if(texture == null){
        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,
            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, texture,
            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 13
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 14
Source File: ActivityManagerShellCommand.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
Set<String> getGlExtensionsFromDriver() {
    Set<String> glExtensions = new HashSet<>();

    // Get the EGL implementation.
    EGL10 egl = (EGL10) EGLContext.getEGL();
    if (egl == null) {
        getErrPrintWriter().println("Warning: couldn't get EGL");
        return glExtensions;
    }

    // Get the default display and initialize it.
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Call getConfigs() in order to find out how many there are.
    int[] numConfigs = new int[1];
    if (!egl.eglGetConfigs(display, null, 0, numConfigs)) {
        getErrPrintWriter().println("Warning: couldn't get EGL config count");
        return glExtensions;
    }

    // Allocate space for all configs and ask again.
    EGLConfig[] configs = new EGLConfig[numConfigs[0]];
    if (!egl.eglGetConfigs(display, configs, numConfigs[0], numConfigs)) {
        getErrPrintWriter().println("Warning: couldn't get EGL configs");
        return glExtensions;
    }

    // Allocate surface size parameters outside of the main loop to cut down
    // on GC thrashing.  1x1 is enough since we are only using it to get at
    // the list of extensions.
    int[] surfaceSize =
            new int[] {
                    EGL10.EGL_WIDTH, 1,
                    EGL10.EGL_HEIGHT, 1,
                    EGL10.EGL_NONE
            };

    // For when we need to create a GLES2.0 context.
    final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
    int[] gles2 = new int[] {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};

    // For getting return values from eglGetConfigAttrib
    int[] attrib = new int[1];

    for (int i = 0; i < numConfigs[0]; i++) {
        // Get caveat for this config in order to skip slow (i.e. software) configs.
        egl.eglGetConfigAttrib(display, configs[i], EGL10.EGL_CONFIG_CAVEAT, attrib);
        if (attrib[0] == EGL10.EGL_SLOW_CONFIG) {
            continue;
        }

        // If the config does not support pbuffers we cannot do an eglMakeCurrent
        // on it in addExtensionsForConfig(), so skip it here. Attempting to make
        // it current with a pbuffer will result in an EGL_BAD_MATCH error
        egl.eglGetConfigAttrib(display, configs[i], EGL10.EGL_SURFACE_TYPE, attrib);
        if ((attrib[0] & EGL10.EGL_PBUFFER_BIT) == 0) {
            continue;
        }

        final int EGL_OPENGL_ES_BIT = 0x0001;
        final int EGL_OPENGL_ES2_BIT = 0x0004;
        egl.eglGetConfigAttrib(display, configs[i], EGL10.EGL_RENDERABLE_TYPE, attrib);
        if ((attrib[0] & EGL_OPENGL_ES_BIT) != 0) {
            addExtensionsForConfig(egl, display, configs[i], surfaceSize, null, glExtensions);
        }
        if ((attrib[0] & EGL_OPENGL_ES2_BIT) != 0) {
            addExtensionsForConfig(egl, display, configs[i], surfaceSize, gles2, glExtensions);
        }
    }

    // Release all EGL resources.
    egl.eglTerminate(display);

    return glExtensions;
}
 
Example 15
Source File: BitmapUtils.java    From Android-Image-Cropper with Apache License 2.0 4 votes vote down vote up
/**
 * Get the max size of bitmap allowed to be rendered on the device.<br>
 * http://stackoverflow.com/questions/7428996/hw-accelerated-activity-how-to-get-opengl-texture-size-limit.
 */
private static int getMaxTextureSize() {
  // Safe minimum default size
  final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

  try {
    // Get EGL Display
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    // Initialise
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Query total number of configurations
    int[] totalConfigurations = new int[1];
    egl.eglGetConfigs(display, null, 0, totalConfigurations);

    // Query actual list configurations
    EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
    egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

    int[] textureSize = new int[1];
    int maximumTextureSize = 0;

    // Iterate through all the configurations to located the maximum texture size
    for (int i = 0; i < totalConfigurations[0]; i++) {
      // Only need to check for width since opengl textures are always squared
      egl.eglGetConfigAttrib(
          display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

      // Keep track of the maximum texture size
      if (maximumTextureSize < textureSize[0]) {
        maximumTextureSize = textureSize[0];
      }
    }

    // Release
    egl.eglTerminate(display);

    // Return largest texture size found, or default
    return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
  } catch (Exception e) {
    return IMAGE_MAX_BITMAP_DIMENSION;
  }
}
 
Example 16
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 17
Source File: OutputSurface.java    From SiliCompressor 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 18
Source File: BitmapUtils.java    From timecat with Apache License 2.0 4 votes vote down vote up
/**
 * Get the max size of bitmap allowed to be rendered on the device.<br>
 * http://stackoverflow.com/questions/7428996/hw-accelerated-activity-how-to-get-opengl-texture-size-limit.
 */
private static int getMaxTextureSize() {
    // Safe minimum default size
    final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

    try {
        // Get EGL Display
        EGL10 egl = (EGL10) EGLContext.getEGL();
        EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

        // Initialise
        int[] version = new int[2];
        egl.eglInitialize(display, version);

        // Query total number of configurations
        int[] totalConfigurations = new int[1];
        egl.eglGetConfigs(display, null, 0, totalConfigurations);

        // Query actual list configurations
        EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
        egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

        int[] textureSize = new int[1];
        int maximumTextureSize = 0;

        // Iterate through all the configurations to located the maximum texture size
        for (int i = 0; i < totalConfigurations[0]; i++) {
            // Only need to check for width since opengl textures are always squared
            egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

            // Keep track of the maximum texture size
            if (maximumTextureSize < textureSize[0]) {
                maximumTextureSize = textureSize[0];
            }
        }

        // Release
        egl.eglTerminate(display);

        // Return largest texture size found, or default
        return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
    } catch (Exception e) {
        return IMAGE_MAX_BITMAP_DIMENSION;
    }
}
 
Example 19
Source File: OutputSurface.java    From SimpleVideoEditor with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares EGL.  We want a GLES 2.0 context and a surface that supports pbuffer.
 */
private void eglSetup(int width, int height) {
    mEGL = (EGL10) EGLContext.getEGL();
    mEGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (!mEGL.eglInitialize(mEGLDisplay, null)) {
        throw new RuntimeException("unable to initialize EGL10");
    }
    // Configure EGL for pbuffer and OpenGL ES 2.0.  We want enough RGB bits
    // to be able to tell if the frame is reasonable.
    int[] attribList = {
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_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, 1, numConfigs)) {
        throw new RuntimeException("unable to find RGB888+pbuffer EGL config");
    }
    // Configure context for OpenGL ES 2.0.
    int[] attrib_list = {
            EGL14.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");
    }
    // Create a pbuffer surface.  By using this for output, we can use glReadPixels
    // to test values in the output.
    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: GLTextureView.java    From MD360Player4Android 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;
}