多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > Fresco源碼解析 - 創建一個ImagePipeline(一)

Fresco源碼解析 - 創建一個ImagePipeline(一)

來源:程序員人生   發布時間:2015-05-06 08:52:13 閱讀次數:5826次

在Fresco源碼解析 - 初始化進程分析章節中,我們分析了Fresco的初始化進程,兩個initialize方法中都用到了 ImagePipelineFactory類。

ImagePipelineFactory.initialize(context);會創建1個所有參數都使用默許值的ImagePipelineConfig來初始化ImagePipeline

ImagePipelineFactory.initialize(imagePipelineConfig)會首先用 imagePipelineConfig創建1個ImagePipelineFactory的實例 - sInstance

sInstance = new ImagePipelineFactory(imagePipelineConfig);

然后,初始化Drawee時,在PipelineDraweeControllerBuilderSupplier的構造方法中通過 ImagePipelineFactory.getInstance()獲得這個實例。

Fresco.java

private static void initializeDrawee(Context context) { sDraweeControllerBuilderSupplier = new PipelineDraweeControllerBuilderSupplier(context); SimpleDraweeView.initialize(sDraweeControllerBuilderSupplier); }

PipelineDraweeControllerBuilderSupplier.java

public PipelineDraweeControllerBuilderSupplier(Context context) { this(context, ImagePipelineFactory.getInstance()); } public PipelineDraweeControllerBuilderSupplier( Context context, ImagePipelineFactory imagePipelineFactory) { this(context, imagePipelineFactory, null); }

PipelineDraweeControllerBuilderSupplier還有1個構造方法,就是 this(context, imagePipelineFactory, null)調用的構造方法。

public PipelineDraweeControllerBuilderSupplier( Context context, ImagePipelineFactory imagePipelineFactory, Set<ControllerListener> boundControllerListeners) { mContext = context; mImagePipeline = imagePipelineFactory.getImagePipeline(); mPipelineDraweeControllerFactory = new PipelineDraweeControllerFactory( context.getResources(), DeferredReleaser.getInstance(), imagePipelineFactory.getAnimatedDrawableFactory(), UiThreadImmediateExecutorService.getInstance()); mBoundControllerListeners = boundControllerListeners; }

其中,mImagePipeline = imagePipelineFactory.getImagePipeline()用于獲得ImagePipeline的實例。

ImagePipelineFactory.java

public ImagePipeline getImagePipeline() { if (mImagePipeline == null) { mImagePipeline = new ImagePipeline( getProducerSequenceFactory(), mConfig.getRequestListeners(), mConfig.getIsPrefetchEnabledSupplier(), getBitmapMemoryCache(), getEncodedMemoryCache(), mConfig.getCacheKeyFactory()); } return mImagePipeline; }

可以看出mImagePipeline是1個單例,構造ImagePipeline時用到的mConfig就是本片最開始講到的 ImagePipelineConfig imagePipelineConfig

經過這個進程,1個ImagePipeline就被創建好了,下面我們具體解析1下ImagePipeline的每一個參數。


由于ImagePipelineFactoryImagePipelineConfig來創建1個ImagePipeline,我們首先分析1下ImagePipelineConfig的源碼。

public class ImagePipelineConfig { private final Supplier<MemoryCacheParams> mBitmapMemoryCacheParamsSupplier; private final CacheKeyFactory mCacheKeyFactory; private final Context mContext; private final Supplier<MemoryCacheParams> mEncodedMemoryCacheParamsSupplier; private final ExecutorSupplier mExecutorSupplier; private final ImageCacheStatsTracker mImageCacheStatsTracker; private final AnimatedDrawableUtil mAnimatedDrawableUtil; private final AnimatedImageFactory mAnimatedImageFactory; private final ImageDecoder mImageDecoder; private final Supplier<Boolean> mIsPrefetchEnabledSupplier; private final DiskCacheConfig mMainDiskCacheConfig; private final MemoryTrimmableRegistry mMemoryTrimmableRegistry; private final NetworkFetcher mNetworkFetcher; private final PoolFactory mPoolFactory; private final ProgressiveJpegConfig mProgressiveJpegConfig; private final Set<RequestListener> mRequestListeners; private final boolean mResizeAndRotateEnabledForNetwork; private final DiskCacheConfig mSmallImageDiskCacheConfig; private final PlatformBitmapFactory mPlatformBitmapFactory; // other methods }

上圖可以看出,獲得圖象的第1站是Memeory Cache,然后是Disk Cache,最后是Network,而MemoryDisk都是緩存在本地的數據,MemoryCacheParams就用于表示它們的緩存策略。

MemoryCacheParams.java

/** * Pass arguments to control the cache's behavior in the constructor. * * @param maxCacheSize The maximum size of the cache, in bytes. * @param maxCacheEntries The maximum number of items that can live in the cache. * @param maxEvictionQueueSize The eviction queue is an area of memory that stores items ready * for eviction but have not yet been deleted. This is the maximum * size of that queue in bytes. * @param maxEvictionQueueEntries The maximum number of entries in the eviction queue. * @param maxCacheEntrySize The maximum size of a single cache entry. */ public MemoryCacheParams( int maxCacheSize, int maxCacheEntries, int maxEvictionQueueSize, int maxEvictionQueueEntries, int maxCacheEntrySize) { this.maxCacheSize = maxCacheSize; this.maxCacheEntries = maxCacheEntries; this.maxEvictionQueueSize = maxEvictionQueueSize; this.maxEvictionQueueEntries = maxEvictionQueueEntries; this.maxCacheEntrySize = maxCacheEntrySize; }

關于每一個參數的作用,注釋已寫得很清楚,不再贅述。


CacheKeyFactory會為ImageRequest創建1個索引 - CacheKey

/** * Factory methods for creating cache keys for the pipeline. */ public interface CacheKeyFactory { /** * @return {@link CacheKey} for doing bitmap cache lookups in the pipeline. */ public CacheKey getBitmapCacheKey(ImageRequest request); /** * @return {@link CacheKey} for doing encoded image lookups in the pipeline. */ public CacheKey getEncodedCacheKey(ImageRequest request); /** * @return a {@link String} that unambiguously indicates the source of the image. */ public Uri getCacheKeySourceUri(Uri sourceUri); }

ExecutorSupplier會根據ImagePipeline的使用處景獲得不同的Executor

public interface ExecutorSupplier { /** Executor used to do all disk reads, whether for disk cache or local files. */ Executor forLocalStorageRead(); /** Executor used to do all disk writes, whether for disk cache or local files. */ Executor forLocalStorageWrite(); /** Executor used for all decodes. */ Executor forDecode(); /** Executor used for all image transformations, such as transcoding, resizing, and rotating. */ Executor forTransform(); /** Executor used for background operations, such as postprocessing. */ Executor forBackground(); }

ImageCacheStatsTracker 作為 Cache 埋點工具,可以統計Cache的各種操作數據。

public interface ImageCacheStatsTracker { /** Called whenever decoded images are put into the bitmap cache. */ public void onBitmapCachePut(); /** Called on a bitmap cache hit. */ public void onBitmapCacheHit(); /** Called on a bitmap cache miss. */ public void onBitmapCacheMiss(); /** Called whenever encoded images are put into the encoded memory cache. */ public void onMemoryCachePut(); /** Called on an encoded memory cache hit. */ public void onMemoryCacheHit(); /** Called on an encoded memory cache hit. */ public void onMemoryCacheMiss(); /** * Called on an staging area hit. * * <p>The staging area stores encoded images. It gets the images before they are written * to disk cache. */ public void onStagingAreaHit(); /** Called on a staging area miss hit. */ public void onStagingAreaMiss(); /** Called on a disk cache hit. */ public void onDiskCacheHit(); /** Called on a disk cache miss. */ public void onDiskCacheMiss(); /** Called if an exception is thrown on a disk cache read. */ public void onDiskCacheGetFail(); /** * Registers a bitmap cache with this tracker. * * <p>Use this method if you need access to the cache itself to compile your stats. */ public void registerBitmapMemoryCache(CountingMemoryCache<?, ?> bitmapMemoryCache); /** * Registers an encoded memory cache with this tracker. * * <p>Use this method if you need access to the cache itself to compile your stats. */ public void registerEncodedMemoryCache(CountingMemoryCache<?, ?> encodedMemoryCache); }

剩下的幾個參數與Drawable關聯比較大,我們下1篇再分析。

めっちゃ眠くて、寢て行っちゃうから、じゃね

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 小说区 综合区 首页 | 亚洲成人在线网站 | 亚洲在线天堂 | 综合久久久久久久 | 亚洲69av | 国产h视频在线观看网站免费 | 亚洲在线视频网站 | 欧美精品久久久久久久影视 | 亚洲欧美日韩国产综合高清 | 久久国产精品免费一区二区三区 | 欧美成人免费全部观看天天性色 | 综合激情区视频一区视频二区 | 91麻豆精品国产综合久久久 | 国产成人欧美一区二区三区的 | 亚洲欧美综合图片 | 在线黄色免费网站 | 亚洲精品视频免费 | 欧美孕妇xxxx做受欧美 | 欧美综合图区亚欧综合图区 | 在线视频亚洲欧美 | 91探花国产综合在线精品 | 另类zoofilia杂交videos | 国产午夜精品不卡视频 | 欧美人与牲动交xxxx小说 | 17videosex性欧美 | 波多野结衣中出在线 | 国产性一交一乱一伦一色一情 | 日韩精品一区二区三区乱码 | 一级女人毛片人一女人 | 亚洲自拍偷拍网 | 男女免费爽爽爽在线视频 | 欧美一区二区久久精品 | 欧美好色 | 中国美女一级看片 | www.av在线.com| 亚洲精品成人a在线观看 | 日本成a人免费视频 | 性做久久久久免费看 | 亚洲国产欧美国产第一区二区三区 | 中文字幕免费在线观看 | 中文字幕精品一区 |