Fresco source code parsing, fresco source code

Source: Internet
Author: User

Fresco source code parsing, fresco source code

In the Fresco source code parsing-initialization process analysis chapter, we analyzed the Fresco initialization process, twoinitializeMethods are usedImagePipelineFactoryClass.

ImagePipelineFactory.initialize(context);CreatesImagePipelineConfigTo initializeImagePipeline.

ImagePipelineFactory.initialize(imagePipelineConfig)Will be used firstimagePipelineConfigCreateImagePipelineFactoryInstance-sInstance.

sInstance = new ImagePipelineFactory(imagePipelineConfig);

Then, initializeDraweeInPipelineDraweeControllerBuilderSupplierIn the constructorImagePipelineFactory.getInstance()Obtain this instance.

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);}

PipelineDraweeControllerBuilderSupplierAnother constructor isthis(context, imagePipelineFactory, null)The constructor.

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;}

Where,mImagePipeline = imagePipelineFactory.getImagePipeline()Used to obtainImagePipeline.

ImagePipelineFactory. java

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

We can see thatmImagePipelineIs a Singleton, constructedImagePipelineUsed inmConfigThis is what we first talked about in this film.ImagePipelineConfig imagePipelineConfig.

After this processImagePipelineIt will be created. Let's analyze it in detail.ImagePipeline.

BecauseImagePipelineFactoryUseImagePipelineConfigCreateImagePipelineFirst, let's analyzeImagePipelineConfigSource code.

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}

We can see that the first stop to get an image isMemeory CacheAnd thenDisk CacheAnd finallyNetwork, AndMemoryAndDiskAll data is cached locally,MemoryCacheParamsIt is used to indicate their cache policies.

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;  }

The comment on the role of each parameter is clearly written and will not be repeated.

CacheKeyFactoryWill beImageRequestCreate an index-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);}

ExecutorSupplierAccordingImagePipelineTo obtain differentExecutor.

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();}

ImageCacheStatsTrackerAsCacheTracking tool, which can be used for statisticsCacheOperation data.

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);}

The remaining parameters andDrawableThe Association is relatively large. We will analyze it later.

Even when you have been sleeping or sleeping, even when you have been sleeping, or even when you have been sleeping.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.