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);
}
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);
}
相关文章推荐
- Tomcat源码阅读之初始化Server组件
- Spring源码阅读(一):IOC容器的初始化
- chromium源码阅读--Browser进程初始化
- SDL源码阅读笔记(2) video dirver的初始化及选择
- prometheus源码阅读 - 配置初始化与重加载
- Spring 源码阅读五 IOC容器初始化之bean定义载入
- Memcached源码阅读之资源初始化
- CI框架源码阅读---------系统初始化文件
- SDL源码阅读笔记(2) video dirver的初始化及选择
- tomcat源码阅读笔记二——初始化过程(上)
- 1、Tomcat源码阅读之初始化流程梳理
- Spring 源码阅读 BeanFactory(三) 对象的初始化 singleton 草稿
- Nginx 源码阅读笔记5 初始化 cycle
- Redis源码阅读(三)集群-连接初始化
- Memcached源码阅读之初始化参数解析
- vector源码阅读笔记(初始化)
- [置顶] Elastic-Job-Lite 源码阅读 ---- 任务初始化
- Glide源码阅读一
- Tomcat源码阅读(一)初始化
- [置顶] nginx源码阅读(二).初始化:main函数及ngx_init_cycle函数