Beispiel #1
0
 @Test
 public void testGet() throws Exception {
   CloseableReference<byte[]> arrayRef = mArray.get(1);
   assertSame(mArray.mByteArraySoftRef.get(), arrayRef.get());
   assertEquals(4, arrayRef.get().length);
   assertEquals(0, mArray.mSemaphore.availablePermits());
 }
 private void doPostprocessing(
     CloseableReference<CloseableImage> sourceImageRef, boolean isLast) {
   Preconditions.checkArgument(CloseableReference.isValid(sourceImageRef));
   if (!shouldPostprocess(sourceImageRef.get())) {
     maybeNotifyOnNewResult(sourceImageRef, isLast);
     return;
   }
   mListener.onProducerStart(mRequestId, NAME);
   CloseableReference<CloseableImage> destImageRef = null;
   try {
     try {
       destImageRef = postprocessInternal(sourceImageRef.get());
     } catch (Exception e) {
       mListener.onProducerFinishWithFailure(
           mRequestId, NAME, e, getExtraMap(mListener, mRequestId, mPostprocessor));
       maybeNotifyOnFailure(e);
       return;
     }
     mListener.onProducerFinishWithSuccess(
         mRequestId, NAME, getExtraMap(mListener, mRequestId, mPostprocessor));
     maybeNotifyOnNewResult(destImageRef, isLast);
   } finally {
     CloseableReference.closeSafely(destImageRef);
   }
 }
Beispiel #3
0
  @Test
  public void testGet_Realloc() {
    CloseableReference<byte[]> arrayRef = mArray.get(1);
    final byte[] smallArray = arrayRef.get();
    arrayRef.close();

    arrayRef = mArray.get(7);
    assertEquals(8, arrayRef.get().length);
    assertSame(mArray.mByteArraySoftRef.get(), arrayRef.get());
    assertNotSame(smallArray, arrayRef.get());
  }
Beispiel #4
0
 @Test
 public void testTrimUnsuccessful() {
   CloseableReference<byte[]> arrayRef = mArray.get(7);
   mArray.trim(MemoryTrimType.OnCloseToDalvikHeapLimit);
   assertSame(arrayRef.get(), mArray.mByteArraySoftRef.get());
   assertEquals(0, mArray.mSemaphore.availablePermits());
 }
Beispiel #5
0
 /**
  * Checks if the Bitmap created by Fresco's internal methods is same as the Bitmap created by
  * Bitmap class' methods.
  *
  * @param bitmapReference The Bitmap Reference created to check
  * @param reference The Bitmap generated from Bitmap class function
  */
 public void checkValid(CloseableReference<Bitmap> bitmapReference, Bitmap reference) {
   if (Build.VERSION.SDK_INT < 12) {
     mValidityTextView.setText(R.string.ignoring_check);
   } else if (bitmapReference.get().sameAs(reference)) {
     mValidityTextView.setText(R.string.correct_bitmap);
   } else {
     mValidityTextView.setText(R.string.incorrect_bitmap);
   }
 }
Beispiel #6
0
  public void setImageBitmap(CloseableReference<Bitmap> bitmapReference) {
    // Note: This is not a recommended way to load Bitmap.
    // This sample is intended to test the internal methods, and show how to use them.
    Bitmap bitmap = bitmapReference.get();
    mImageView.setImageBitmap(bitmap);
    mImageView.getLayoutParams().width = (int) (bitmap.getWidth() * mConversionFactor);
    mImageView.getLayoutParams().height = (int) (bitmap.getHeight() * mConversionFactor);

    if (mCurrentBitmapReference != null && mCurrentBitmapReference.isValid()) {
      mCurrentBitmapReference.close();
    }
    mCurrentBitmapReference = bitmapReference;
  }
    /** Performs the decode synchronously. */
    private void doDecode(long queueTime) {
      CloseableReference<PooledByteBuffer> bytesRef;
      boolean isLast;
      synchronized (ProgressiveDecoder.this) {
        bytesRef = mImageBytesRef;
        mImageBytesRef = null;
        isLast = mIsLast;
        mIsDecodeSubmitted = false;
        mLastDecodeTime = SystemClock.uptimeMillis();
      }

      try {
        if (isFinished() || !CloseableReference.isValid(bytesRef)) {
          return;
        }

        ImageFormat format = isLast ? ImageFormat.UNKNOWN : getImageFormat(bytesRef);
        int length = isLast ? bytesRef.get().size() : getIntermediateImageEndOffset(bytesRef);
        QualityInfo quality = isLast ? ImmutableQualityInfo.FULL_QUALITY : getQualityInfo(bytesRef);

        mProducerListener.onProducerStart(mProducerContext.getId(), PRODUCER_NAME);
        CloseableImage decodedImage;
        try {
          decodedImage =
              mImageDecoder.decodeImage(bytesRef, format, length, quality, mImageDecodeOptions);
        } catch (Exception e) {
          Map<String, String> extraMap = getExtraMap(queueTime, quality, isLast);
          mProducerListener.onProducerFinishWithFailure(
              mProducerContext.getId(), PRODUCER_NAME, e, extraMap);
          handleError(e);
          return;
        }
        Map<String, String> extraMap = getExtraMap(queueTime, quality, isLast);
        mProducerListener.onProducerFinishWithSuccess(
            mProducerContext.getId(), PRODUCER_NAME, extraMap);
        handleResult(decodedImage, isLast);
      } finally {
        CloseableReference.closeSafely(bytesRef);
      }
    }
 @Override
 protected int getIntermediateImageEndOffset(
     CloseableReference<PooledByteBuffer> imageBytesRef) {
   return imageBytesRef.get().size();
 }