当前位置: 首页>>代码示例>>Java>>正文


Java CloseableReference.isValid方法代码示例

本文整理汇总了Java中com.facebook.common.references.CloseableReference.isValid方法的典型用法代码示例。如果您正苦于以下问题:Java CloseableReference.isValid方法的具体用法?Java CloseableReference.isValid怎么用?Java CloseableReference.isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.facebook.common.references.CloseableReference的用法示例。


在下文中一共展示了CloseableReference.isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renderFrameAndCache

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private boolean renderFrameAndCache(
    int frameNumber,
    CloseableReference<Bitmap> bitmapReference,
    @BitmapAnimationBackend.FrameType int frameType) {
  // Check if the bitmap is valid
  if (!CloseableReference.isValid(bitmapReference)) {
    return false;
  }
  // Try to render the frame
  if (!mBitmapFrameRenderer.renderFrame(frameNumber, bitmapReference.get())) {
    return false;
  }
  FLog.v(TAG, "Frame %d ready.", mFrameNumber);
  // Cache the frame
  synchronized (mPendingFrameDecodeJobs) {
    mBitmapFrameCache.onFramePrepared(mFrameNumber, bitmapReference, frameType);
  }
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:DefaultBitmapFramePreparer.java

示例2: convertToBitmapReferenceAndClose

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Converts the given image reference to a bitmap reference
 * and closes the original image reference.
 *
 * @param closeableImage the image to convert. It will be closed afterwards and will be invalid
 * @return the closeable bitmap reference to be used
 */
@VisibleForTesting
@Nullable
static CloseableReference<Bitmap> convertToBitmapReferenceAndClose(
    final @Nullable CloseableReference<CloseableImage> closeableImage) {
  try {
    if (CloseableReference.isValid(closeableImage) &&
        closeableImage.get() instanceof CloseableStaticBitmap) {

      CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) closeableImage.get();
      if (closeableStaticBitmap != null) {
        // We return a clone of the underlying bitmap reference that has to be manually closed
        // and then close the passed CloseableStaticBitmap in order to preserve correct
        // cache size calculations.
        return closeableStaticBitmap.cloneUnderlyingBitmapReference();
      }
    }
    // Not a bitmap reference, so we return null
    return null;
  } finally {
    CloseableReference.closeSafely(closeableImage);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:FrescoFrameCache.java

示例3: renderFrameInBitmap

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Try to render the frame to the given target bitmap. If the rendering fails, the target bitmap
 * reference will be closed and false is returned. If rendering succeeds, the target bitmap
 * reference can be drawn and has to be manually closed after drawing has been completed.
 *
 * @param frameNumber the frame number to render
 * @param targetBitmap the target bitmap
 * @return true if rendering successful
 */
private boolean renderFrameInBitmap(
    int frameNumber,
    @Nullable CloseableReference<Bitmap> targetBitmap) {
  if (!CloseableReference.isValid(targetBitmap)) {
    return false;
  }
  // Render the image
  boolean frameRendered =
      mBitmapFrameRenderer.renderFrame(frameNumber, targetBitmap.get());
  if (!frameRendered) {
    CloseableReference.closeSafely(targetBitmap);
  }
  return frameRendered;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:BitmapAnimationBackend.java

示例4: drawBitmapAndCache

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Helper method that draws the given bitmap on the canvas respecting the bounds (if set).
 *
 * If rendering was successful, it notifies the cache that the frame has been rendered with the
 * given bitmap. In addition, it will notify the {@link FrameListener} if set.
 *
 * @param frameNumber the current frame number passed to the cache
 * @param bitmapReference the bitmap to draw
 * @param canvas the canvas to draw an
 * @param frameType the {@link FrameType} to be rendered
 * @return true if the bitmap has been drawn
 */
private boolean drawBitmapAndCache(
    int frameNumber,
    @Nullable CloseableReference<Bitmap> bitmapReference,
    Canvas canvas,
    @FrameType int frameType) {
  if (!CloseableReference.isValid(bitmapReference)) {
    return false;
  }
  if (mBounds == null) {
    canvas.drawBitmap(bitmapReference.get(), 0f, 0f, mPaint);
  } else {
    canvas.drawBitmap(bitmapReference.get(), null, mBounds, mPaint);
  }

  // Notify the cache that a frame has been rendered.
  // We should not cache fallback frames since they do not represent the actual frame.
  if (frameType != FRAME_TYPE_FALLBACK) {
    mBitmapFrameCache.onFrameRendered(
        frameNumber,
        bitmapReference,
        frameType);
  }

  if (mFrameListener != null) {
    mFrameListener.onFrameDrawn(this, frameNumber, frameType);
  }
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:BitmapAnimationBackend.java

示例5: onFramePrepared

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
public synchronized void onFramePrepared(
    int frameNumber,
    CloseableReference<Bitmap> bitmapReference,
    @BitmapAnimationBackend.FrameType int frameType) {
  Preconditions.checkNotNull(bitmapReference);
  CloseableReference<CloseableImage> closableReference = null;
  try {
    closableReference = createImageReference(bitmapReference);
    if (closableReference == null) {
      return;
    }
    CloseableReference<CloseableImage> newReference =
        mAnimatedFrameCache.cache(frameNumber, closableReference);
    if (CloseableReference.isValid(newReference)) {
      CloseableReference<CloseableImage> oldReference = mPreparedPendingFrames.get(frameNumber);
      CloseableReference.closeSafely(oldReference);
      // For performance reasons, we don't clone the reference and close the original one
      // but cache the reference directly.
      mPreparedPendingFrames.put(frameNumber, newReference);
      FLog.v(
          TAG,
          "cachePreparedFrame(%d) cached. Pending frames: %s",
          frameNumber,
          mPreparedPendingFrames);
    }
  } finally {
    CloseableReference.closeSafely(closableReference);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:FrescoFrameCache.java

示例6: getBitmapSizeBytes

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private static int getBitmapSizeBytes(
    @Nullable CloseableReference<CloseableImage> imageReference) {
  if (!CloseableReference.isValid(imageReference)) {
    return 0;
  }
  return getBitmapSizeBytes(imageReference.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:FrescoFrameCache.java

示例7: onNewResultImpl

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
protected void onNewResultImpl(
    CloseableReference<CloseableImage> newResult,
    @Status int status) {
  if (!CloseableReference.isValid(newResult)) {
    // try to propagate if the last result is invalid
    if (isLast(status)) {
      maybeNotifyOnNewResult(null, status);
    }
    // ignore if invalid
    return;
  }
  updateSourceImageRef(newResult, status);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:PostprocessorProducer.java

示例8: setRunningIfDirtyAndNotRunning

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private synchronized boolean setRunningIfDirtyAndNotRunning() {
  if (!mIsClosed && mIsDirty && !mIsPostProcessingRunning &&
      CloseableReference.isValid(mSourceImageRef)) {
    mIsPostProcessingRunning = true;
    return true;
  }
  return false;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:PostprocessorProducer.java

示例9: internalPrepareBitmap

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
private void internalPrepareBitmap(CloseableReference<CloseableImage> newResult) {
  if (newResult == null || !newResult.isValid()) {
    return;
  }

  final CloseableImage closeableImage = newResult.get();
  if (closeableImage == null || closeableImage.isClosed()) {
    return;
  }

  if (closeableImage instanceof CloseableStaticBitmap) {
    final CloseableStaticBitmap staticBitmap = (CloseableStaticBitmap) closeableImage;
    final Bitmap bitmap = staticBitmap.getUnderlyingBitmap();
    if (bitmap == null) {
      return;
    }

    final int bitmapByteCount = bitmap.getRowBytes() * bitmap.getHeight();
    if (bitmapByteCount < mMinBitmapSizeBytes) {
      return;
    }
    if (bitmapByteCount > mMaxBitmapSizeBytes) {
      return;
    }

    bitmap.prepareToDraw();
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:BitmapPrepareProducer.java

示例10: isInBitmapMemoryCache

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Returns whether the image is stored in the bitmap memory cache.
 *
 * @param imageRequest the imageRequest for the image to be looked up.
 * @return true if the image was found in the bitmap memory cache, false otherwise.
 */
public boolean isInBitmapMemoryCache(final ImageRequest imageRequest) {
  if (imageRequest == null) {
    return false;
  }
  final CacheKey cacheKey = mCacheKeyFactory.getBitmapCacheKey(imageRequest, null);
  CloseableReference<CloseableImage> ref = mBitmapMemoryCache.get(cacheKey);
  try {
    return CloseableReference.isValid(ref);
  } finally {
    CloseableReference.closeSafely(ref);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:ImagePipeline.java

示例11: contains

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
public synchronized boolean contains(int frameNumber) {
  return frameNumber == mLastFrameNumber && CloseableReference.isValid(mLastBitmapReference);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:KeepLastFrameCache.java

示例12: isClosed

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Check if this bytebuffer is already closed
 * @return true if this bytebuffer is closed.
 */
@Override
public synchronized boolean isClosed() {
  return !CloseableReference.isValid(mBufRef);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:NativePooledByteBuffer.java

示例13: ensureValid

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Ensure that the current stream is valid, that is underlying closeable reference is not null
 * and is valid
 * @throws InvalidStreamException if the stream is invalid
 */
private void ensureValid() {
  if (!CloseableReference.isValid(mBufRef)) {
    throw new InvalidStreamException();
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:NativePooledByteBufferOutputStream.java

示例14: contains

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
@Override
public synchronized boolean contains(int frameNumber) {
  return CloseableReference.isValid(mBitmapSparseArray.get(frameNumber));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:5,代码来源:NaiveCacheAllFramesCachingBackend.java

示例15: isValid

import com.facebook.common.references.CloseableReference; //导入方法依赖的package包/类
/**
 * Returns true if the internal buffer reference is valid or the InputStream Supplier is not null,
 * false otherwise.
 */
public synchronized boolean isValid() {
  return CloseableReference.isValid(mPooledByteBufferRef) || mInputStreamSupplier != null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:EncodedImage.java


注:本文中的com.facebook.common.references.CloseableReference.isValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。