private <Data, TResource, Transcode> List<DecodePath<Data, TResource, Transcode>> getDecodePaths( Class<Data> dataClass, Class<TResource> resourceClass, Class<Transcode> transcodeClass) { List<DecodePath<Data, TResource, Transcode>> decodePaths = new ArrayList<>(); List<Class<TResource>> registeredResourceClasses = decoderRegistry.getResourceClasses(dataClass, resourceClass); for (Class<TResource> registeredResourceClass : registeredResourceClasses) { List<Class<Transcode>> registeredTranscodeClasses = transcoderRegistry.getTranscodeClasses(registeredResourceClass, transcodeClass); for (Class<Transcode> registeredTranscodeClass : registeredTranscodeClasses) { List<ResourceDecoder<Data, TResource>> decoders = decoderRegistry.getDecoders(dataClass, registeredResourceClass); ResourceTranscoder<TResource, Transcode> transcoder = transcoderRegistry.get(registeredResourceClass, registeredTranscodeClass); decodePaths.add(new DecodePath<>(dataClass, registeredResourceClass, registeredTranscodeClass, decoders, transcoder, exceptionListPool)); } } return decodePaths; }
@SuppressWarnings("unchecked") public synchronized <T, R> List<ResourceDecoder<T, R>> getDecoders(Class<T> dataClass, Class<R> resourceClass) { List<ResourceDecoder<T, R>> result = new ArrayList<>(); for (String bucket : bucketPriorityList) { List<Entry<?, ?>> entries = decoders.get(bucket); if (entries == null) { continue; } for (Entry<?, ?> entry : entries) { if (entry.handles(dataClass, resourceClass)) { result.add((ResourceDecoder<T, R>) entry.decoder); } } } // TODO: cache result list. return result; }
private <Data, TResource, Transcode> List<DecodePath<Data, TResource, Transcode>> getDecodePaths( Class<Data> dataClass, Class<TResource> resourceClass, Class<Transcode> transcodeClass) { List<DecodePath<Data, TResource, Transcode>> decodePaths = new ArrayList<>(); List<Class<TResource>> registeredResourceClasses = decoderRegistry.getResourceClasses(dataClass, resourceClass); for (Class<TResource> registeredResourceClass : registeredResourceClasses) { List<Class<Transcode>> registeredTranscodeClasses = transcoderRegistry.getTranscodeClasses(registeredResourceClass, transcodeClass); for (Class<Transcode> registeredTranscodeClass : registeredTranscodeClasses) { List<ResourceDecoder<Data, TResource>> decoders = decoderRegistry.getDecoders(dataClass, registeredResourceClass); ResourceTranscoder<TResource, Transcode> transcoder = transcoderRegistry.get(registeredResourceClass, registeredTranscodeClass); decodePaths.add(new DecodePath<>(dataClass, registeredResourceClass, registeredTranscodeClass, decoders, transcoder, throwableListPool)); } } return decodePaths; }
@Override public void onSizeReady(int width, int height) { if (isCancelled) { return; } width = Math.round(sizeMultiplier * width); height = Math.round(sizeMultiplier * height); ResourceDecoder<InputStream, Z> cacheDecoder = loadProvider.getCacheDecoder(); ResourceDecoder<T, Z> decoder = loadProvider.getSourceDecoder(); ResourceEncoder <Z> encoder = loadProvider.getEncoder(); ResourceTranscoder<Z, R> transcoder = loadProvider.getTranscoder(); ModelLoader<A, T> modelLoader = loadProvider.getModelLoader(); final String id = modelLoader.getId(model); final DataFetcher<T> dataFetcher = modelLoader.getResourceFetcher(model, width, height); loadedFromMemoryCache = true; loadStatus = engine.load(id, width, height, cacheDecoder, dataFetcher, decoder, transformation, encoder, transcoder, priority, isMemoryCacheable, this); loadedFromMemoryCache = resource != null; }
public DecodePath(Class<DataType> dataClass, Class<ResourceType> resourceClass, Class<Transcode> transcodeClass, List<? extends ResourceDecoder<DataType, ResourceType>> decoders, ResourceTranscoder<ResourceType, Transcode> transcoder, Pool<List<Exception>> listPool) { this.dataClass = dataClass; this.decoders = decoders; this.transcoder = transcoder; this.listPool = listPool; failureMessage = "Failed DecodePath{" + dataClass.getSimpleName() + "->" + resourceClass.getSimpleName() + "->" + transcodeClass.getSimpleName() + "}"; }
private Resource<ResourceType> decodeResourceWithList(DataRewinder<DataType> rewinder, int width, int height, Options options, List<Exception> exceptions) throws GlideException { Resource<ResourceType> result = null; for (int i = 0, size = decoders.size(); i < size; i++) { ResourceDecoder<DataType, ResourceType> decoder = decoders.get(i); try { DataType data = rewinder.rewindAndGet(); if (decoder.handles(data, options)) { data = rewinder.rewindAndGet(); result = decoder.decode(data, width, height, options); } } catch (IOException e) { if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Failed to decode data for " + decoder, e); } exceptions.add(e); } if (result != null) { break; } } if (result == null) { throw new GlideException(failureMessage, new ArrayList<>(exceptions)); } return result; }
@SuppressWarnings("unchecked") public synchronized <T, R> List<ResourceDecoder<T, R>> getDecoders(Class<T> dataClass, Class<R> resourceClass) { List<ResourceDecoder<T, R>> result = new ArrayList<>(); for (Entry<?, ?> entry : decoders) { if (entry.handles(dataClass, resourceClass)) { result.add((ResourceDecoder<T, R>) entry.decoder); } } // TODO: cache result list. return result; }
public DecodePath(Class<DataType> dataClass, Class<ResourceType> resourceClass, Class<Transcode> transcodeClass, List<? extends ResourceDecoder<DataType, ResourceType>> decoders, ResourceTranscoder<ResourceType, Transcode> transcoder, Pool<List<Throwable>> listPool) { this.dataClass = dataClass; this.decoders = decoders; this.transcoder = transcoder; this.listPool = listPool; failureMessage = "Failed DecodePath{" + dataClass.getSimpleName() + "->" + resourceClass.getSimpleName() + "->" + transcodeClass.getSimpleName() + "}"; }
private Resource<ResourceType> decodeResourceWithList(DataRewinder<DataType> rewinder, int width, int height, Options options, List<Throwable> exceptions) throws GlideException { Resource<ResourceType> result = null; for (int i = 0, size = decoders.size(); i < size; i++) { ResourceDecoder<DataType, ResourceType> decoder = decoders.get(i); try { DataType data = rewinder.rewindAndGet(); if (decoder.handles(data, options)) { data = rewinder.rewindAndGet(); result = decoder.decode(data, width, height, options); } // Some decoders throw unexpectedly. If they do, we shouldn't fail the entire load path, but // instead log and continue. See #2406 for an example. } catch (IOException | RuntimeException | OutOfMemoryError e) { if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Failed to decode data for " + decoder, e); } exceptions.add(e); } if (result != null) { break; } } if (result == null) { throw new GlideException(failureMessage, new ArrayList<>(exceptions)); } return result; }
ImageWrapperResourceDecoder(ResourceDecoder<ImageVideoWrapper, Bitmap> bitmapDecoder, ResourceDecoder<InputStream, GifDrawable> gifDecoder, BitmapPool bitmapPool, ImageTypeParser parser, BufferedStreamFactory streamFactory) { this.bitmapDecoder = bitmapDecoder; this.gifDecoder = gifDecoder; this.bitmapPool = bitmapPool; this.parser = parser; this.streamFactory = streamFactory; }
public PaletteBitmapDecoder( BitmapPool bitmapPool, ResourceDecoder<InputStream, Bitmap> bitmapDecoder, ResourceDecoder<InputStream, Palette> paletteDecoder) { this.bitmapPool = bitmapPool; this.paletteDecoder = paletteDecoder; this.bitmapDecoder = bitmapDecoder; }
public SourceResourceRunner(Key key, int width, int height, DataFetcher<T> dataFetcher, ResourceDecoder<T, Z> decoder, Transformation<Z> transformation, ResourceEncoder<Z> encoder, ResourceTranscoder<Z, R> transcoder, DiskCache diskCache, Priority priority, ResourceCallback cb) { this.key = key; this.width = width; this.height = height; this.fetcher = dataFetcher; this.decoder = decoder; this.transformation = transformation; this.encoder = encoder; this.transcoder = transcoder; this.diskCache = diskCache; this.priority = priority; this.cb = cb; }
public EngineKey(String id, int width, int height, ResourceDecoder cacheDecoder, ResourceDecoder decoder, Transformation transformation, ResourceEncoder encoder, ResourceTranscoder transcoder) { this.id = id; this.width = width; this.height = height; this.cacheDecoder = cacheDecoder; this.decoder = decoder; this.transformation = transformation; this.encoder = encoder; this.transcoder = transcoder; }
public ResourceRunner(Key key, int width, int height, DiskCache diskCache, ResourceDecoder<InputStream, Z> cacheDecoder, ResourceTranscoder<Z, R> transcoder, SourceResourceRunner sourceRunner, ExecutorService executorService, Handler bgHandler, EngineJob job) { this.key = key; this.width = width; this.height = height; this.diskCache = diskCache; this.cacheDecoder = cacheDecoder; this.transcoder = transcoder; this.sourceRunner = sourceRunner; this.executorService = executorService; this.bgHandler = bgHandler; this.job = job; }
/** * * @param id A unique id for the model, dimensions, cache decoder, decoder, and encoder * @param cacheDecoder * @param fetcher * @param decoder * @param encoder * @param transcoder * @param priority * @param <T> The type of data the resource will be decoded from. * @param <Z> The type of the resource that will be decoded. * @param <R> The type of the resource that will be transcoded from the decoded resource. */ public <T, Z, R> LoadStatus load(String id, int width, int height, ResourceDecoder<InputStream, Z> cacheDecoder, DataFetcher<T> fetcher, ResourceDecoder<T, Z> decoder, Transformation<Z> transformation, ResourceEncoder<Z> encoder, ResourceTranscoder<Z, R> transcoder, Priority priority, boolean isMemoryCacheable, ResourceCallback cb) { Key key = keyFactory.buildKey(id, width, height, cacheDecoder, decoder, transformation, encoder, transcoder); Resource cached = cache.get(key); if (cached != null) { cached.acquire(1); cb.onResourceReady(cached); return null; } ResourceRunner current = runners.get(key); if (current != null) { EngineJob job = current.getJob(); job.addCallback(cb); return new LoadStatus(cb, job); } ResourceRunner<Z, R> runner = factory.build(key, width, height, cacheDecoder, fetcher, decoder, transformation, encoder, transcoder, priority, isMemoryCacheable, this); runner.getJob().addCallback(cb); runners.put(key, runner); runner.queue(); return new LoadStatus(cb, runner.getJob()); }
@Override public <T, Z, R> ResourceRunner<Z, R> build(Key key, int width, int height, ResourceDecoder<InputStream, Z> cacheDecoder, DataFetcher<T> fetcher, ResourceDecoder<T, Z> decoder, Transformation<Z> transformation, ResourceEncoder<Z> encoder, ResourceTranscoder<Z, R> transcoder, Priority priority, boolean isMemoryCacheable, EngineJobListener listener) { EngineJob engineJob = new EngineJob(key, memoryCache, mainHandler, isMemoryCacheable, listener); SourceResourceRunner<T, Z, R> sourceRunner = new SourceResourceRunner<T, Z, R>(key, width, height, fetcher, decoder, transformation, encoder, transcoder, diskCache, priority, engineJob); return new ResourceRunner<Z, R>(key, width, height, diskCache, cacheDecoder, transcoder, sourceRunner, service, bgHandler, engineJob); }
@Override public ResourceDecoder<InputStream, Z> getCacheDecoder() { if (cacheDecoder != null) { return cacheDecoder; } else { return parent.getCacheDecoder(); } }
@Override public ResourceDecoder<T, Z> getSourceDecoder() { if (sourceDecoder != null) { return sourceDecoder; } else { return parent.getSourceDecoder(); } }