use of com.bumptech.glide.load.Key in project Rocket by mozilla-tw.
the class MultiModelLoader method buildLoadData.
@Override
public LoadData<Data> buildLoadData(Model model, int width, int height, Options options) {
Key sourceKey = null;
int size = modelLoaders.size();
List<DataFetcher<Data>> fetchers = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
ModelLoader<Model, Data> modelLoader = modelLoaders.get(i);
if (modelLoader.handles(model)) {
LoadData<Data> loadData = modelLoader.buildLoadData(model, width, height, options);
if (loadData != null) {
sourceKey = loadData.sourceKey;
fetchers.add(loadData.fetcher);
}
}
}
return !fetchers.isEmpty() ? new LoadData<>(sourceKey, new MultiFetcher<>(fetchers, exceptionListPool)) : null;
}
use of com.bumptech.glide.load.Key in project Rocket by mozilla-tw.
the class ResourceCacheGenerator method startNext.
@Override
public boolean startNext() {
List<Key> sourceIds = helper.getCacheKeys();
if (sourceIds.isEmpty()) {
return false;
}
List<Class<?>> resourceClasses = helper.getRegisteredResourceClasses();
while (modelLoaders == null || !hasNextModelLoader()) {
resourceClassIndex++;
if (resourceClassIndex >= resourceClasses.size()) {
sourceIdIndex++;
if (sourceIdIndex >= sourceIds.size()) {
return false;
}
resourceClassIndex = 0;
}
Key sourceId = sourceIds.get(sourceIdIndex);
Class<?> resourceClass = resourceClasses.get(resourceClassIndex);
Transformation<?> transformation = helper.getTransformation(resourceClass);
currentKey = new ResourceCacheKey(sourceId, helper.getSignature(), helper.getWidth(), helper.getHeight(), transformation, resourceClass, helper.getOptions());
cacheFile = helper.getDiskCache().get(currentKey);
if (cacheFile != null) {
this.sourceKey = sourceId;
modelLoaders = helper.getModelLoaders(cacheFile);
modelLoaderIndex = 0;
}
}
loadData = null;
boolean started = false;
while (!started && hasNextModelLoader()) {
ModelLoader<File, ?> modelLoader = modelLoaders.get(modelLoaderIndex++);
loadData = modelLoader.buildLoadData(cacheFile, helper.getWidth(), helper.getHeight(), helper.getOptions());
if (loadData != null && helper.hasLoadPath(loadData.fetcher.getDataClass())) {
started = true;
loadData.fetcher.loadData(helper.getPriority(), this);
}
}
return started;
}
use of com.bumptech.glide.load.Key in project glide by bumptech.
the class DecodeJob method onResourceDecoded.
@Synthetic
@NonNull
<Z> Resource<Z> onResourceDecoded(DataSource dataSource, @NonNull Resource<Z> decoded) {
@SuppressWarnings("unchecked") Class<Z> resourceSubClass = (Class<Z>) decoded.get().getClass();
Transformation<Z> appliedTransformation = null;
Resource<Z> transformed = decoded;
if (dataSource != DataSource.RESOURCE_DISK_CACHE) {
appliedTransformation = decodeHelper.getTransformation(resourceSubClass);
transformed = appliedTransformation.transform(glideContext, decoded, width, height);
}
// TODO: Make this the responsibility of the Transformation.
if (!decoded.equals(transformed)) {
decoded.recycle();
}
final EncodeStrategy encodeStrategy;
final ResourceEncoder<Z> encoder;
if (decodeHelper.isResourceEncoderAvailable(transformed)) {
encoder = decodeHelper.getResultEncoder(transformed);
encodeStrategy = encoder.getEncodeStrategy(options);
} else {
encoder = null;
encodeStrategy = EncodeStrategy.NONE;
}
Resource<Z> result = transformed;
boolean isFromAlternateCacheKey = !decodeHelper.isSourceKey(currentSourceKey);
if (diskCacheStrategy.isResourceCacheable(isFromAlternateCacheKey, dataSource, encodeStrategy)) {
if (encoder == null) {
throw new Registry.NoResultEncoderAvailableException(transformed.get().getClass());
}
final Key key;
switch(encodeStrategy) {
case SOURCE:
key = new DataCacheKey(currentSourceKey, signature);
break;
case TRANSFORMED:
key = new ResourceCacheKey(decodeHelper.getArrayPool(), currentSourceKey, signature, width, height, appliedTransformation, resourceSubClass, options);
break;
default:
throw new IllegalArgumentException("Unknown strategy: " + encodeStrategy);
}
LockedResource<Z> lockedResult = LockedResource.obtain(transformed);
deferredEncodeManager.init(key, encoder, lockedResult);
result = lockedResult;
}
return result;
}
use of com.bumptech.glide.load.Key in project glide by bumptech.
the class BitmapPreFillRunner method allocate.
/**
* Attempts to allocate {@link android.graphics.Bitmap}s and returns {@code true} if there are
* more {@link android.graphics.Bitmap}s to allocate and {@code false} otherwise.
*/
@VisibleForTesting
boolean allocate() {
long start = clock.now();
while (!toPrefill.isEmpty() && !isGcDetected(start)) {
PreFillType toAllocate = toPrefill.remove();
final Bitmap bitmap;
if (!seenTypes.contains(toAllocate)) {
seenTypes.add(toAllocate);
bitmap = bitmapPool.getDirty(toAllocate.getWidth(), toAllocate.getHeight(), toAllocate.getConfig());
} else {
bitmap = Bitmap.createBitmap(toAllocate.getWidth(), toAllocate.getHeight(), toAllocate.getConfig());
}
// Order matters here! If the Bitmap is too large or the BitmapPool is too full, it may be
// recycled after the call to bitmapPool#put below.
int bitmapSize = Util.getBitmapByteSize(bitmap);
// not empty so that we use all available space.
if (getFreeMemoryCacheBytes() >= bitmapSize) {
// We could probably make UniqueKey just always return false from equals,
// but the allocation of the Key is not nearly as expensive as the allocation of the Bitmap,
// so it's probably not worth it.
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") Key uniqueKey = new UniqueKey();
memoryCache.put(uniqueKey, BitmapResource.obtain(bitmap, bitmapPool));
} else {
bitmapPool.put(bitmap);
}
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "allocated [" + toAllocate.getWidth() + "x" + toAllocate.getHeight() + "] " + toAllocate.getConfig() + " size: " + bitmapSize);
}
}
return !isCancelled && !toPrefill.isEmpty();
}
use of com.bumptech.glide.load.Key in project glide by bumptech.
the class RecyclerAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ListViewHolder viewHolder, int position) {
MediaStoreData current = data.get(position);
Key signature = new MediaStoreSignature(current.mimeType, current.dateModified, current.orientation);
requestBuilder.clone().signature(signature).load(current.uri).into(viewHolder.image);
}
Aggregations