示例#1
0
    /**
     * Ensures the current EGL context is the one we expect.
     *
     * @return {@link #SURFACE_STATE_ERROR} if the correct EGL context cannot be made current,
     *     {@link #SURFACE_STATE_UPDATED} if the EGL context was changed or {@link
     *     #SURFACE_STATE_SUCCESS} if the EGL context was the correct one
     */
    int checkCurrent() {
      if (mEglThread != Thread.currentThread()) {
        throw new IllegalStateException(
            "Hardware acceleration can only be used with a "
                + "single UI thread.\nOriginal thread: "
                + mEglThread
                + "\n"
                + "Current thread: "
                + Thread.currentThread());
      }

      if (!mEglContext.equals(sEgl.eglGetCurrentContext())
          || !mEglSurface.equals(sEgl.eglGetCurrentSurface(EGL_DRAW))) {
        if (!sEgl.eglMakeCurrent(sEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
          Log.e(LOG_TAG, "eglMakeCurrent failed " + GLUtils.getEGLErrorString(sEgl.eglGetError()));
          fallback(true);
          return SURFACE_STATE_ERROR;
        } else {
          if (mUpdateDirtyRegions) {
            enableDirtyRegions();
            mUpdateDirtyRegions = false;
          }
          return SURFACE_STATE_UPDATED;
        }
      }
      return SURFACE_STATE_SUCCESS;
    }
  public EGLContext eglGetCurrentContext() {
    begin("eglGetCurrentContext");
    end();

    EGLContext result = mEgl10.eglGetCurrentContext();
    returns(result);

    checkError();
    return result;
  }
示例#3
0
  public static boolean createEGLSurface() {
    if (SDLActivity.mEGLDisplay != null && SDLActivity.mEGLConfig != null) {
      EGL10 egl = (EGL10) EGLContext.getEGL();
      if (SDLActivity.mEGLContext == EGL10.EGL_NO_CONTEXT) createEGLContext();

      if (SDLActivity.mEGLSurface == EGL10.EGL_NO_SURFACE) {
        Log.v("SDL", "Creating new EGL Surface");
        SDLActivity.mEGLSurface =
            egl.eglCreateWindowSurface(
                SDLActivity.mEGLDisplay, SDLActivity.mEGLConfig, SDLActivity.mSurface, null);
        if (SDLActivity.mEGLSurface == EGL10.EGL_NO_SURFACE) {
          Log.e("SDL", "Couldn't create surface");
          return false;
        }
      } else Log.v("SDL", "EGL Surface remains valid");

      if (egl.eglGetCurrentContext() != SDLActivity.mEGLContext) {
        if (!egl.eglMakeCurrent(
            SDLActivity.mEGLDisplay,
            SDLActivity.mEGLSurface,
            SDLActivity.mEGLSurface,
            SDLActivity.mEGLContext)) {
          Log.e("SDL", "Old EGL Context doesnt work, trying with a new one");
          // TODO: Notify the user via a message that the old context could not be restored, and
          // that textures need to be manually restored.
          createEGLContext();
          if (!egl.eglMakeCurrent(
              SDLActivity.mEGLDisplay,
              SDLActivity.mEGLSurface,
              SDLActivity.mEGLSurface,
              SDLActivity.mEGLContext)) {
            Log.e("SDL", "Failed making EGL Context current");
            return false;
          }
        } else Log.v("SDL", "EGL Context made current");
      } else Log.v("SDL", "EGL Context remains current");

      return true;
    } else {
      Log.e(
          "SDL",
          "Surface creation failed, display = "
              + SDLActivity.mEGLDisplay
              + ", config = "
              + SDLActivity.mEGLConfig);
      return false;
    }
  }
        @Override
        public void onSurfaceChanged(final GL10 gl, final int width, final int height) {
          Log.i(TAG, "onSurfaceChanged; %d x %d", width, height);

          if (null != mMainSurface) {
            Log.v(TAG, "short-circuiting onSurfaceChanged");
            return;
          }

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

          int numAttribs = 0;
          final int[] configAttribs = new int[16];
          Arrays.fill(configAttribs, EGL10.EGL_NONE);

          Log.v(TAG, "--- window surface configuration ---");
          final VrAppSettings appSettings = mActivity.getAppSettings();
          if (appSettings.useSrgbFramebuffer) {
            final int EGL_GL_COLORSPACE_KHR = 0x309D;
            final int EGL_GL_COLORSPACE_SRGB_KHR = 0x3089;

            configAttribs[numAttribs++] = EGL_GL_COLORSPACE_KHR;
            configAttribs[numAttribs++] = EGL_GL_COLORSPACE_SRGB_KHR;
          }
          Log.v(TAG, "--- srgb framebuffer: %b", appSettings.useSrgbFramebuffer);

          if (appSettings.useProtectedFramebuffer) {
            final int EGL_PROTECTED_CONTENT_EXT = 0x32c0;

            configAttribs[numAttribs++] = EGL_PROTECTED_CONTENT_EXT;
            configAttribs[numAttribs++] = EGL14.EGL_TRUE;
          }
          Log.v(TAG, "--- protected framebuffer: %b", appSettings.useProtectedFramebuffer);

          configAttribs[numAttribs++] = EGL10.EGL_NONE;
          Log.v(TAG, "------------------------------------");

          // this is the display surface timewarp will hijack
          mMainSurface =
              egl.eglCreateWindowSurface(display, mConfig, mSurfaceView.getHolder(), configAttribs);
          Log.v(TAG, "mMainSurface: 0x%x", mMainSurface.hashCode());

          if (mMainSurface == EGL10.EGL_NO_SURFACE) {
            throw new IllegalStateException(
                "eglCreateWindowSurface() failed: 0x" + Integer.toHexString(egl.eglGetError()));
          }
          if (!egl.eglMakeCurrent(display, mMainSurface, mMainSurface, context)) {
            throw new IllegalStateException(
                "eglMakeCurrent() failed: 0x " + Integer.toHexString(egl.eglGetError()));
          }
          nativeOnSurfaceChanged(mPtr);

          // necessary to explicitly make the pbuffer current for the rendering thread;
          // TimeWarp took over the window surface
          if (!egl.eglMakeCurrent(display, mPixelBuffer, mPixelBuffer, context)) {
            throw new IllegalStateException(
                "Failed to make context current ; egl error 0x"
                    + Integer.toHexString(egl.eglGetError()));
          }

          startChoreographerThreadIfNotStarted();
          mViewManager.onSurfaceChanged(width, height);
        }