Пример #1
0
    @Override
    boolean initialize(Surface surface) throws Surface.OutOfResourcesException {
      if (isRequested() && !isEnabled()) {
        initializeEgl();
        mGl = createEglSurface(surface);
        mDestroyed = false;

        if (mGl != null) {
          int err = sEgl.eglGetError();
          if (err != EGL_SUCCESS) {
            destroy(true);
            setRequested(false);
          } else {
            if (mCanvas == null) {
              mCanvas = createCanvas();
            }
            if (mCanvas != null) {
              setEnabled(true);
            } else {
              Log.w(LOG_TAG, "Hardware accelerated Canvas could not be created");
            }
          }

          return mCanvas != null;
        }
      }
      return false;
    }
Пример #2
0
    @Override
    void destroy(boolean full) {
      if (full && mCanvas != null) {
        mCanvas = null;
      }

      if (!isEnabled() || mDestroyed) {
        setEnabled(false);
        return;
      }

      destroySurface();
      setEnabled(false);

      mDestroyed = true;
      mGl = null;
    }
Пример #3
0
    @Override
    void invalidate(Surface surface) {
      // Cancels any existing buffer to ensure we'll get a buffer
      // of the right size before we call eglSwapBuffers
      sEgl.eglMakeCurrent(sEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

      if (mEglSurface != null && mEglSurface != EGL_NO_SURFACE) {
        sEgl.eglDestroySurface(sEglDisplay, mEglSurface);
        mEglSurface = null;
        setEnabled(false);
      }

      if (surface.isValid()) {
        if (!createSurface(surface)) {
          return;
        }

        mUpdateDirtyRegions = true;

        if (mCanvas != null) {
          setEnabled(true);
        }
      }
    }