Esempio n. 1
0
  /**
   * After some initialization the method loops and renders the camera image whenever a new frame
   * arrived. The black and white byte array is binded to a texture by the bindCameraTexture method.
   * Afterwards an object can be rendered with this texture.
   */
  public void run() {
    init();

    running = true;

    while (running) {
      if (!running) return;

      // gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

      newFrameLock.waitUntilTrue(1000000);
      newFrameLock.setValue(false);
      bindCameraTexture(gl);
      gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

      // gl.glRotatef(1,0,0,1); //Rotate the camera image

      egl.eglSwapBuffers(dpy, surface);

      if (egl.eglGetError() == EGL11.EGL_CONTEXT_LOST) {
        Context c = getContext();
        if (c instanceof Activity) {
          ((Activity) c).finish();
        }
      }
    }
  }
  /**
   * Display the current render surface.
   *
   * @return false if the context has been lost.
   */
  public boolean swap() {
    mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);

    /*
     * Always check for EGL_CONTEXT_LOST, which means the context and all associated data were lost (For instance
     * because the device went to sleep). We need to sleep until we get a new surface.
     */
    return mEgl.eglGetError() != EGL11.EGL_CONTEXT_LOST;
  }
 public boolean eglSwapBuffers(EGLDisplay display, EGLSurface surface) {
   begin("eglInitialize");
   arg("display", display);
   arg("surface", surface);
   end();
   boolean result = mEgl10.eglSwapBuffers(display, surface);
   returns(result);
   checkError();
   return result;
 }
Esempio n. 4
0
  // EGL buffer flip
  public static void flipEGL() {
    try {
      EGL10 egl = (EGL10) EGLContext.getEGL();

      egl.eglWaitNative(EGL10.EGL_CORE_NATIVE_ENGINE, null);

      // drawing here

      egl.eglWaitGL();

      egl.eglSwapBuffers(SDLActivity.mEGLDisplay, SDLActivity.mEGLSurface);

    } catch (Exception e) {
      Log.v("SDL", "flipEGL(): " + e);
      for (StackTraceElement s : e.getStackTrace()) {
        Log.v("SDL", s.toString());
      }
    }
  }
Esempio n. 5
0
 public void swapBuffers() {
   EGL10 egl = (EGL10) EGLContext.getEGL();
   EGLDisplay display = egl.eglGetCurrentDisplay();
   EGLSurface surface = egl.eglGetCurrentSurface(EGL10.EGL_READ);
   egl.eglSwapBuffers(display, surface);
 }
Esempio n. 6
0
    @Override
    boolean draw(
        View view, View.AttachInfo attachInfo, HardwareDrawCallbacks callbacks, Rect dirty) {
      if (canDraw()) {
        if (!hasDirtyRegions()) {
          dirty = null;
        }
        attachInfo.mIgnoreDirtyState = true;
        attachInfo.mDrawingTime = SystemClock.uptimeMillis();

        view.mPrivateFlags |= View.PFLAG_DRAWN;

        final int surfaceState = checkCurrent();
        if (surfaceState != SURFACE_STATE_ERROR) {
          HardwareCanvas canvas = mCanvas;
          attachInfo.mHardwareCanvas = canvas;

          if (mProfileEnabled) {
            mProfileLock.lock();
          }

          // We had to change the current surface and/or context, redraw everything
          if (surfaceState == SURFACE_STATE_UPDATED) {
            dirty = null;
            beginFrame(null);
          } else {
            int[] size = mSurfaceSize;
            beginFrame(size);

            if (size[1] != mHeight || size[0] != mWidth) {
              mWidth = size[0];
              mHeight = size[1];

              canvas.setViewport(mWidth, mHeight);

              dirty = null;
            }
          }

          int saveCount = 0;
          int status = DisplayList.STATUS_DONE;

          try {
            view.mRecreateDisplayList =
                (view.mPrivateFlags & View.PFLAG_INVALIDATED) == View.PFLAG_INVALIDATED;
            view.mPrivateFlags &= ~View.PFLAG_INVALIDATED;

            long getDisplayListStartTime = 0;
            if (mProfileEnabled) {
              mProfileCurrentFrame += PROFILE_FRAME_DATA_COUNT;
              if (mProfileCurrentFrame >= mProfileData.length) {
                mProfileCurrentFrame = 0;
              }

              getDisplayListStartTime = System.nanoTime();
            }

            canvas.clearLayerUpdates();

            DisplayList displayList;
            Trace.traceBegin(Trace.TRACE_TAG_VIEW, "getDisplayList");
            try {
              displayList = view.getDisplayList();
            } finally {
              Trace.traceEnd(Trace.TRACE_TAG_VIEW);
            }

            Trace.traceBegin(Trace.TRACE_TAG_VIEW, "prepareFrame");
            try {
              status = onPreDraw(dirty);
            } finally {
              Trace.traceEnd(Trace.TRACE_TAG_VIEW);
            }
            saveCount = canvas.save();
            callbacks.onHardwarePreDraw(canvas);

            if (mProfileEnabled) {
              long now = System.nanoTime();
              float total = (now - getDisplayListStartTime) * 0.000001f;
              //noinspection PointlessArithmeticExpression
              mProfileData[mProfileCurrentFrame] = total;
            }

            if (displayList != null) {
              long drawDisplayListStartTime = 0;
              if (mProfileEnabled) {
                drawDisplayListStartTime = System.nanoTime();
              }

              Trace.traceBegin(Trace.TRACE_TAG_VIEW, "drawDisplayList");
              try {
                status |=
                    canvas.drawDisplayList(
                        displayList, mRedrawClip, DisplayList.FLAG_CLIP_CHILDREN);
              } finally {
                Trace.traceEnd(Trace.TRACE_TAG_VIEW);
              }

              if (mProfileEnabled) {
                long now = System.nanoTime();
                float total = (now - drawDisplayListStartTime) * 0.000001f;
                mProfileData[mProfileCurrentFrame + 1] = total;
              }

              handleFunctorStatus(attachInfo, status);
            } else {
              // Shouldn't reach here
              view.draw(canvas);
            }
          } finally {
            callbacks.onHardwarePostDraw(canvas);
            canvas.restoreToCount(saveCount);
            view.mRecreateDisplayList = false;

            mFrameCount++;

            if (mDebugDirtyRegions) {
              if (mDebugPaint == null) {
                mDebugPaint = new Paint();
                mDebugPaint.setColor(0x7fff0000);
              }

              if (dirty != null && (mFrameCount & 1) == 0) {
                canvas.drawRect(dirty, mDebugPaint);
              }
            }
          }

          onPostDraw();

          attachInfo.mIgnoreDirtyState = false;

          if ((status & DisplayList.STATUS_DREW) == DisplayList.STATUS_DREW) {
            long eglSwapBuffersStartTime = 0;
            if (mProfileEnabled) {
              eglSwapBuffersStartTime = System.nanoTime();
            }

            sEgl.eglSwapBuffers(sEglDisplay, mEglSurface);

            if (mProfileEnabled) {
              long now = System.nanoTime();
              float total = (now - eglSwapBuffersStartTime) * 0.000001f;
              mProfileData[mProfileCurrentFrame + 2] = total;
            }

            checkEglErrors();
          }

          if (mProfileEnabled) {
            mProfileLock.unlock();
          }

          return dirty == null;
        }
      }

      return false;
    }
Esempio n. 7
0
  public void swapBuffers() {
    egl.eglSwapBuffers(display, surface);

    // Must be called from the rendering thread
    if (!hasSurface) createSurface();
  }
Esempio n. 8
0
  public void run() {
    // Much of this code is from GLSurfaceView in the Google API Demos.
    // I encourage those interested to look there for documentation.
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

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

    int[] configSpec = {
      EGL10.EGL_RED_SIZE, 5,
      EGL10.EGL_GREEN_SIZE, 6,
      EGL10.EGL_BLUE_SIZE, 5,
      EGL10.EGL_DEPTH_SIZE, 16,
      EGL10.EGL_NONE
    };

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
    EGLConfig config = configs[0];

    EGLContext context = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null);

    EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, sHolder, null);
    egl.eglMakeCurrent(dpy, surface, surface, context);

    GL10 gl = (GL10) context.getGL();

    init(gl);

    int delta = -1;
    if (fps > 0) {
      delta = 1000 / fps;
    }
    long time = System.currentTimeMillis();

    running = true;
    while (running) {
      int w, h;
      synchronized (this) {
        w = width;
        h = height;
      }
      if (System.currentTimeMillis() - time < delta) {
        try {
          Thread.sleep(System.currentTimeMillis() - time);
        } catch (InterruptedException ex) {
        }
      }
      drawFrame(gl, w, h);
      egl.eglSwapBuffers(dpy, surface);

      if (egl.eglGetError() == EGL11.EGL_CONTEXT_LOST) {
        Context c = getContext();
        if (c instanceof Activity) {
          ((Activity) c).finish();
        }
      }
      time = System.currentTimeMillis();
    }
    egl.eglMakeCurrent(dpy, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    egl.eglDestroySurface(dpy, surface);
    egl.eglDestroyContext(dpy, context);
    egl.eglTerminate(dpy);
  }