-
- All Implemented Interfaces:
-
com.pdfview.subsamplincscaleimageview.decoder.ImageRegionDecoder
public class SkiaPooledImageRegionDecoder implements ImageRegionDecoder
An implementation of ImageRegionDecoder using a pool of BitmapRegionDecoders, to provide true parallel loading of tiles. This is only effective if parallel loading has been enabled in the view by calling setExecutor with a multi-threaded Executor instance.
One decoder is initialised when the class is initialised. This is enough to decode base layer tiles. Additional decoders are initialised when a subregion of the image is first requested, which indicates interaction with the view. Creation of additional encoders stops when allowAdditionalDecoder returns false. The default implementation takes into account the file size, number of CPU cores, low memory status and a hard limit of 4. Extend this class to customise this.
WARNING: This class is highly experimental and not proven to be stable on a wide range of devices. You are advised to test it thoroughly on all available devices, and code your app to use SkiaImageRegionDecoder on old or low powered devices you could not test.
-
-
Field Summary
Fields Modifier and Type Field Description private static booleandebug
-
Constructor Summary
Constructors Constructor Description SkiaPooledImageRegionDecoder()SkiaPooledImageRegionDecoder(Bitmap.Config bitmapConfig)
-
Method Summary
Modifier and Type Method Description static voidsetDebug(boolean debug)Controls logging of debug messages. Pointinit(Context context, @NonNull() Uri uri)Initialises the decoder pool. BitmapdecodeRegion(@NonNull() Rect sRect, int sampleSize)Acquire a read lock to prevent decoding overlapping with recycling, then check the pool stillexists and acquire a decoder to load the requested region. synchronized booleanisReady()Holding a read lock to avoid returning true while the pool is being recycled, this returnstrue if the pool has at least one decoder available. synchronized voidrecycle()Wait until all read locks held by decodeRegion are released, then recycleand destroy the pool. -
-
Constructor Detail
-
SkiaPooledImageRegionDecoder
SkiaPooledImageRegionDecoder()
-
SkiaPooledImageRegionDecoder
SkiaPooledImageRegionDecoder(Bitmap.Config bitmapConfig)
-
-
Method Detail
-
setDebug
static void setDebug(boolean debug)
Controls logging of debug messages. All instances are affected.
- Parameters:
debug- true to enable debug logging, false to disable.
-
init
@NonNull() Point init(Context context, @NonNull() Uri uri)
Initialises the decoder pool. This method creates one decoder on the current thread and usesit to decode the bounds, then spawns an independent thread to populate the pool with anadditional three decoders. The thread will abort if recycle is called.
-
decodeRegion
@NonNull() Bitmap decodeRegion(@NonNull() Rect sRect, int sampleSize)
Acquire a read lock to prevent decoding overlapping with recycling, then check the pool stillexists and acquire a decoder to load the requested region. There is no check whether the poolcurrently has decoders, because it's guaranteed to have one decoder after init is called and be null once recycle is called. In practice the view can't call thismethod until after init, so there will be no blocking on an empty pool.
-
isReady
synchronized boolean isReady()
Holding a read lock to avoid returning true while the pool is being recycled, this returnstrue if the pool has at least one decoder available.
-
recycle
synchronized void recycle()
Wait until all read locks held by decodeRegion are released, then recycleand destroy the pool. Elsewhere, when a read lock is acquired, we must check the pool is not null.
-
-
-
-