/**
* Acquire a read lock to prevent decoding overlapping with recycling, then check the pool still
* exists and acquire a decoder to load the requested region. There is no check whether the pool
* currently has decoders, because it's guaranteed to have one decoder after {@link #init(Context, Uri)}
* is called and be null once {@link #recycle()} is called. In practice the view can't call this
* method until after {@link #init(Context, Uri)}, so there will be no blocking on an empty pool.
*/
@Override
public Bitmap decodeRegion(Rect sRect, int sampleSize) {
debug("Decode region " + sRect + " on thread " + Thread.currentThread().getName());
if (sRect.width() < imageDimensions.x || sRect.height() < imageDimensions.y) {
lazyInit();
}
decoderLock.readLock().lock();
try {
if (decoderPool != null) {
BitmapRegionDecoder decoder = decoderPool.acquire();
try {
// Decoder can't be null or recycled in practice
if (decoder != null && !decoder.isRecycled()) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = sampleSize;
options.inPreferredConfig = bitmapConfig;
Bitmap bitmap = decoder.decodeRegion(sRect, options);
if (bitmap == null) {
throw new RuntimeException("Skia image decoder returned null bitmap - image format may not be supported");
}
return bitmap;
}
} finally {
if (decoder != null) {
decoderPool.release(decoder);
}
}
}
throw new IllegalStateException("Cannot decode region after decoder has been recycled");
} finally {
decoderLock.readLock().unlock();
}
}
SkiaPooledImageRegionDecoder.java 文件源码
java
阅读 28
收藏 0
点赞 0
评论 0
项目:garras
作者:
评论列表
文章目录