您的位置:首页 > 其它

Glide源码阅读(一 补充) Glide单例初始化做的事

2018-03-06 20:17 330 查看
GlideBuilder中

 RequestManager中有持有Glide的对象,在创建RequestManager时就有初始化Glide对象Glide createGlide() {
if (sourceService == null) {//图片下载线程池
final int cores = Math.max(1, Runtime.getRuntime().availableProcessors());
sourceService = new FifoPriorityThreadPoolExecutor(cores);
}
if (diskCacheService == null) {//磁盘缓存线程池
diskCacheService = new FifoPriorityThreadPoolExecutor(1);
}
MemorySizeCalculator calculator = new MemorySizeCalculator(context);
if (bitmapPool == null) {//图片对象池
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
int size = calculator.getBitmapPoolSize();
bitmapPool = new LruBitmapPool(size);
} else {
bitmapPool = new BitmapPoolAdapter();
}
}
if (memoryCache == null) {//内存缓存
memoryCache = new LruResourceCache(calculator.getMemoryCacheSize());
}
if (diskCacheFactory == null) {//磁盘缓存
diskCacheFactory = new InternalCacheDiskCacheFactory(context);
}
if (engine == null) {//类似controller,缓存、执行下载等模块在engine中做逻辑判断,选择调用不同模块功能
engine = new Engine(memoryCache, diskCacheFactory, diskCacheService, sourceService);
}
if (decodeFormat == null) {//解码格式
decodeFormat = DecodeFormat.DEFAULT;
}
return new Glide(engine, memoryCache, bitmapPool, context, decodeFormat);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Glide