public boolean eglGetConfigs(
      EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config) {
    begin("eglGetConfigs");
    arg("display", display);
    arg("config_size", config_size);
    end();

    boolean result = mEgl10.eglGetConfigs(display, configs, config_size, num_config);
    arg("configs", configs);
    arg("num_config", num_config);
    returns(result);
    checkError();
    return result;
  }
Пример #2
0
  /*
   * OpenGL help
   */
  public static EGLConfig getEglConfig565(EGL10 egl, EGLDisplay display) {
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    EGLConfig[] conf = new EGLConfig[100];
    int[] num_conf = new int[100];
    egl.eglGetConfigs(display, conf, 100, num_conf);

    int[] red = new int[1];
    int[] blue = new int[1];
    int[] green = new int[1];

    for (int i = 0; i < 100; i++) {
      if (conf[i] == null) break;
      egl.eglGetConfigAttrib(display, conf[i], EGL10.EGL_RED_SIZE, red);
      egl.eglGetConfigAttrib(display, conf[i], EGL10.EGL_BLUE_SIZE, blue);
      egl.eglGetConfigAttrib(display, conf[i], EGL10.EGL_GREEN_SIZE, green);
      if (red[0] == 5 && green[0] == 6 && blue[0] == 5) {
        return conf[i];
      }
    }
    return null;
  }
        @Override
        public EGLConfig chooseConfig(final EGL10 egl, final EGLDisplay display) {
          final int[] numberConfigs = new int[1];
          if (!egl.eglGetConfigs(display, null, 0, numberConfigs)) {
            throw new IllegalStateException("Unable to retrieve number of egl configs available.");
          }
          final EGLConfig[] configs = new EGLConfig[numberConfigs[0]];
          if (!egl.eglGetConfigs(display, configs, configs.length, numberConfigs)) {
            throw new IllegalStateException("Unable to retrieve egl configs available.");
          }

          final int[] configAttribs = {
            EGL10.EGL_ALPHA_SIZE, 8, // need alpha for the multi-pass
            // timewarp compositor
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_DEPTH_SIZE, 0,
            EGL10.EGL_SAMPLES, 0,
            EGL10.EGL_NONE
          };

          EGLConfig config = null;
          for (int i = 0; i < numberConfigs[0]; ++i) {
            final int[] value = new int[1];

            final int EGL_OPENGL_ES3_BIT_KHR = 0x0040;
            if (!egl.eglGetConfigAttrib(display, configs[i], EGL10.EGL_RENDERABLE_TYPE, value)) {
              Log.v(TAG, "eglGetConfigAttrib for EGL_RENDERABLE_TYPE failed");
              continue;
            }
            if ((value[0] & EGL_OPENGL_ES3_BIT_KHR) != EGL_OPENGL_ES3_BIT_KHR) {
              continue;
            }

            if (!egl.eglGetConfigAttrib(display, configs[i], EGL10.EGL_SURFACE_TYPE, value)) {
              Log.v(TAG, "eglGetConfigAttrib for EGL_SURFACE_TYPE failed");
              continue;
            }
            if ((value[0] & (EGL10.EGL_WINDOW_BIT | EGL10.EGL_PBUFFER_BIT))
                != (EGL10.EGL_WINDOW_BIT | EGL10.EGL_PBUFFER_BIT)) {
              continue;
            }

            int j = 0;
            for (; configAttribs[j] != EGL10.EGL_NONE; j += 2) {
              if (!egl.eglGetConfigAttrib(display, configs[i], configAttribs[j], value)) {
                Log.v(TAG, "eglGetConfigAttrib for " + configAttribs[j] + " failed");
                continue;
              }
              if (value[0] != configAttribs[j + 1]) {
                break;
              }
            }
            if (configAttribs[j] == EGL10.EGL_NONE) {
              config = configs[i];
              break;
            }
          }
          return config;
        }
    @Override
    public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
      int[] numConfigs = new int[1];
      if (egl.eglGetConfigs(display, null, 0, numConfigs)) {
        EGLConfig[] configs = new EGLConfig[numConfigs[0]];
        int[] EGLattribs = {
          EGL10.EGL_RED_SIZE, configAttribs[0],
          EGL10.EGL_GREEN_SIZE, configAttribs[1],
          EGL10.EGL_BLUE_SIZE, configAttribs[2],
          EGL10.EGL_ALPHA_SIZE, configAttribs[3],
          EGL10.EGL_DEPTH_SIZE, configAttribs[4],
          EGL10.EGL_STENCIL_SIZE, configAttribs[5],
          EGL10.EGL_RENDERABLE_TYPE, 4, // EGL_OPENGL_ES2_BIT
          EGL10.EGL_NONE
        };
        int[] choosedConfigNum = new int[1];

        egl.eglChooseConfig(display, EGLattribs, configs, numConfigs[0], choosedConfigNum);
        if (choosedConfigNum[0] > 0) {
          return selectConfig(egl, display, configs, configAttribs);
        } else {
          int[] defaultEGLattribs = {
            EGL10.EGL_RED_SIZE, 5,
            EGL10.EGL_GREEN_SIZE, 6,
            EGL10.EGL_BLUE_SIZE, 5,
            EGL10.EGL_ALPHA_SIZE, 0,
            EGL10.EGL_DEPTH_SIZE, 0,
            EGL10.EGL_STENCIL_SIZE, 0,
            EGL10.EGL_RENDERABLE_TYPE, 4, // EGL_OPENGL_ES2_BIT
            EGL10.EGL_NONE
          };
          int[] defaultEGLattribsAlpha = {
            EGL10.EGL_RED_SIZE, 4,
            EGL10.EGL_GREEN_SIZE, 4,
            EGL10.EGL_BLUE_SIZE, 4,
            EGL10.EGL_ALPHA_SIZE, 4,
            EGL10.EGL_DEPTH_SIZE, 0,
            EGL10.EGL_STENCIL_SIZE, 0,
            EGL10.EGL_RENDERABLE_TYPE, 4, // EGL_OPENGL_ES2_BIT
            EGL10.EGL_NONE
          };
          int[] attribs = null;
          // choose one can use
          if (this.configAttribs[3] == 0) {
            egl.eglChooseConfig(
                display, defaultEGLattribs, configs, numConfigs[0], choosedConfigNum);
            attribs = new int[] {5, 6, 5, 0, 0, 0};
          } else {
            egl.eglChooseConfig(
                display, defaultEGLattribsAlpha, configs, numConfigs[0], choosedConfigNum);
            attribs = new int[] {4, 4, 4, 4, 0, 0};
          }
          if (choosedConfigNum[0] > 0) {
            return selectConfig(egl, display, configs, attribs);
          } else {
            Log.e(DEVICE_POLICY_SERVICE, "Can not select an EGLConfig for rendering.");
            return null;
          }
        }
      }
      Log.e(DEVICE_POLICY_SERVICE, "Can not select an EGLConfig for rendering.");
      return null;
    }
Пример #5
0
  /** @return OpenGL ES major version 1, 2, or 3 or some non-positive number for error */
  private static int getDetectedVersion() {
    /*
     * Get all the device configurations and check the EGL_RENDERABLE_TYPE attribute
     * to determine the highest ES version supported by any config. The
     * EGL_KHR_create_context extension is required to check for ES3 support; if the
     * extension is not present this test will fail to detect ES3 support. This
     * effectively makes the extension mandatory for ES3-capable devices.
     */

    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    int[] numConfigs = new int[1];

    if (egl.eglInitialize(display, null)) {
      try {
        boolean checkES3 =
            hasExtension(
                egl.eglQueryString(display, EGL10.EGL_EXTENSIONS), "EGL_KHR_create_context");
        if (egl.eglGetConfigs(display, null, 0, numConfigs)) {
          EGLConfig[] configs = new EGLConfig[numConfigs[0]];
          if (egl.eglGetConfigs(display, configs, numConfigs[0], numConfigs)) {
            int highestEsVersion = 0;
            int[] value = new int[1];
            for (int i = 0; i < numConfigs[0]; i++) {
              if (egl.eglGetConfigAttrib(display, configs[i], EGL10.EGL_RENDERABLE_TYPE, value)) {
                if (checkES3 && ((value[0] & EGL_OPENGL_ES3_BIT_KHR) == EGL_OPENGL_ES3_BIT_KHR)) {
                  if (highestEsVersion < 3) highestEsVersion = 3;
                } else if ((value[0] & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT) {
                  if (highestEsVersion < 2) highestEsVersion = 2;
                } else if ((value[0] & EGL_OPENGL_ES_BIT) == EGL_OPENGL_ES_BIT) {
                  if (highestEsVersion < 1) highestEsVersion = 1;
                }
              } else {
                Log.w(
                    TAG,
                    "Getting config attribute with "
                        + "EGL10#eglGetConfigAttrib failed "
                        + "("
                        + i
                        + "/"
                        + numConfigs[0]
                        + "): "
                        + egl.eglGetError());
              }
            }
            return highestEsVersion;
          } else {
            Log.e(TAG, "Getting configs with EGL10#eglGetConfigs failed: " + egl.eglGetError());
            return -1;
          }
        } else {
          Log.e(
              TAG,
              "Getting number of configs with EGL10#eglGetConfigs failed: " + egl.eglGetError());
          return -2;
        }
      } finally {
        egl.eglTerminate(display);
      }
    } else {
      Log.e(TAG, "Couldn't initialize EGL.");
      return -3;
    }
  }