private void returnScreenshot3DToCaller(
      final GVRScreenshot3DCallback callback,
      final byte[][] byteArrays,
      final int width,
      final int height) {

    if (byteArrays.length != 6) {
      throw new IllegalArgumentException("byteArrays length is not 6.");
    } else {
      // run the callback function in a background thread
      Threads.spawn(
          new Runnable() {
            public void run() {
              final Bitmap[] bitmapArray = new Bitmap[6];
              Runnable[] threads = new Runnable[6];

              for (int i = 0; i < 6; i++) {
                final int index = i;
                threads[i] =
                    new Runnable() {
                      public void run() {
                        byte[] bytearray = byteArrays[index];
                        byteArrays[index] = null;
                        Bitmap bitmap = ImageUtils.generateBitmapFlipV(bytearray, width, height);
                        synchronized (this) {
                          bitmapArray[index] = bitmap;
                          notify();
                        }
                      }
                    };
              }

              for (Runnable thread : threads) {
                Threads.spawnLow(thread);
              }

              for (int i = 0; i < 6; i++) {
                synchronized (threads[i]) {
                  if (bitmapArray[i] == null) {
                    try {
                      threads[i].wait();
                    } catch (InterruptedException e) {
                      e.printStackTrace();
                    }
                  }
                }
              }

              callback.onScreenCaptured(bitmapArray);
            }
          });
    }
  }
 private void returnScreenshotToCaller(
     final GVRScreenshotCallback callback, final int width, final int height) {
   // run the callback function in a background thread
   final byte[] byteArray = Arrays.copyOf(mReadbackBuffer.array(), mReadbackBuffer.array().length);
   Threads.spawn(
       new Runnable() {
         public void run() {
           final Bitmap capturedBitmap = ImageUtils.generateBitmapFlipV(byteArray, width, height);
           callback.onScreenCaptured(capturedBitmap);
         }
       });
 }
  /**
   * Add a Future {@link GVREyePointee} to this holder
   *
   * @param eyePointee A Future {@link GVREyePointee}, probably from {@link
   *     GVRRenderData#getMeshEyePointee()}
   */
  public void addPointee(final Future<GVREyePointee> eyePointee) {
    // The Future<GVREyePointee> may well actually be a FutureWrapper, not a
    // 'real' Future
    if (eyePointee.isDone()) {
      addFutureEyePointee(eyePointee);
    } else {
      Threads.spawn(
          new Runnable() {

            @Override
            public void run() {
              addFutureEyePointee(eyePointee);
            }
          });
    }
  }
Beispiel #4
0
  /**
   * Asynchronously set the {@link GVRMesh mesh} to be rendered.
   *
   * <p>Uses a background thread from the thread pool to wait for the {@code Future.get()} method;
   * unless you are loading dozens of meshes asynchronously, the extra overhead should be modest
   * compared to the cost of loading a mesh.
   *
   * @param mesh The mesh to be rendered.
   * @since 1.6.7
   */
  public void setMesh(final Future<GVRMesh> mesh) {
    synchronized (this) {
      mFutureMesh = mesh;
    }
    Threads.spawn(
        new Runnable() {

          @Override
          public void run() {
            try {
              setMesh(mesh.get());
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });
  }