/// <summary> /// Returns the encoded <see cref="CountingMemoryCache{K, V}"/>. /// </summary> public static CountingMemoryCache <ICacheKey, IPooledByteBuffer> Get( ISupplier <MemoryCacheParams> encodedMemoryCacheParamsSupplier, IMemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory) { IValueDescriptor <IPooledByteBuffer> valueDescriptor = new ValueDescriptorImpl <IPooledByteBuffer>( (value) => { return(value.Size); }); ICacheTrimStrategy trimStrategy = new NativeMemoryCacheTrimStrategy(); CountingMemoryCache <ICacheKey, IPooledByteBuffer> countingCache = new CountingMemoryCache <ICacheKey, IPooledByteBuffer>( valueDescriptor, trimStrategy, encodedMemoryCacheParamsSupplier, platformBitmapFactory, false); memoryTrimmableRegistry.RegisterMemoryTrimmable(countingCache); return(countingCache); }
/// <summary> /// Instantiates the bitmap counting memory cache. /// </summary> public static CountingMemoryCache <ICacheKey, CloseableImage> Get( ISupplier <MemoryCacheParams> bitmapMemoryCacheParamsSupplier, IMemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory, bool isExternalCreatedBitmapLogEnabled) { IValueDescriptor <CloseableImage> valueDescriptor = new ValueDescriptorImpl <CloseableImage>( (value) => { return(value.SizeInBytes); }); ICacheTrimStrategy trimStrategy = new BitmapMemoryCacheTrimStrategy(); CountingMemoryCache <ICacheKey, CloseableImage> countingCache = new CountingMemoryCache <ICacheKey, CloseableImage>( valueDescriptor, trimStrategy, bitmapMemoryCacheParamsSupplier, platformBitmapFactory, isExternalCreatedBitmapLogEnabled); memoryTrimmableRegistry.RegisterMemoryTrimmable(countingCache); return(countingCache); }
/// <summary> /// Gets the animated factory. /// </summary> public static IAnimatedFactory GetAnimatedFactory( PlatformBitmapFactory platformBitmapFactory, IExecutorSupplier executorSupplier) { // TODO: Adding animated factory return(default(IAnimatedFactory)); }
private ImagePipelineConfig(Builder builder) { _animatedImageFactory = builder.AnimatedImageFactory; _bitmapMemoryCacheParamsSupplier = builder.BitmapMemoryCacheParamsSupplier ?? new DefaultBitmapMemoryCacheParamsSupplier(); _bitmapConfig = builder.BitmapConfig == default(BitmapPixelFormat) ? BitmapPixelFormat.Bgra8 : builder.BitmapConfig; _cacheKeyFactory = builder.CacheKeyFactory ?? DefaultCacheKeyFactory.Instance; _decodeMemoryFileEnabled = builder.IsDecodeMemoryFileEnabled; _fileCacheFactory = builder.FileCacheFactory ?? new DiskStorageCacheFactory(new DynamicDefaultDiskStorageFactory()); _downsampleEnabled = builder.IsDownsampleEnabled; _encodedMemoryCacheParamsSupplier = builder.EncodedMemoryCacheParamsSupplier ?? new DefaultEncodedMemoryCacheParamsSupplier(); _imageCacheStatsTracker = builder.ImageCacheStatsTracker ?? NoOpImageCacheStatsTracker.Instance; _imageDecoder = builder.ImageDecoder; _isPrefetchEnabledSupplier = builder.IsPrefetchEnabledSupplier ?? new SupplierImpl <bool>( () => { return(true); }); _mainDiskCacheConfig = builder.MainDiskCacheConfig ?? GetDefaultMainDiskCacheConfig(); _memoryTrimmableRegistry = builder.MemoryTrimmableRegistry ?? NoOpMemoryTrimmableRegistry.Instance; _networkFetcher = builder.NetworkFetcher ?? new HttpUrlConnectionNetworkFetcher(); _platformBitmapFactory = builder.PlatformBitmapFactory; _poolFactory = builder.PoolFactory ?? new PoolFactory(PoolConfig.NewBuilder().Build()); _progressiveJpegConfig = builder.ProgressiveJpegConfig == default(IProgressiveJpegConfig) ? new SimpleProgressiveJpegConfig() : builder.ProgressiveJpegConfig; _requestListeners = builder.RequestListeners ?? new HashSet <IRequestListener>(); _resizeAndRotateEnabledForNetwork = builder.ResizeAndRotateEnabledForNetwork; _smallImageDiskCacheConfig = builder.SmallImageDiskCacheConfig ?? _mainDiskCacheConfig; // Below this comment can't be built in alphabetical order, because of dependencies int numCpuBoundThreads = _poolFactory.FlexByteArrayPoolMaxNumThreads; _executorSupplier = builder.ExecutorSupplier ?? new DefaultExecutorSupplier(numCpuBoundThreads); _imagePipelineExperiments = builder.Experiment.Build(); }
/// <summary> /// Gets the platform bitmap factory. /// </summary> public PlatformBitmapFactory GetPlatformBitmapFactory() { if (_platformBitmapFactory == null) { _platformBitmapFactory = BuildPlatformBitmapFactory( _config.PoolFactory, GetPlatformDecoder()); } return(_platformBitmapFactory); }
/// <summary> /// Instantiates the <see cref="PostprocessorProducer"/>. /// </summary> public PostprocessorProducer( IProducer <CloseableReference <CloseableImage> > inputProducer, PlatformBitmapFactory platformBitmapFactory, FlexByteArrayPool flexByteArrayPool, IExecutorService executor) { _inputProducer = Preconditions.CheckNotNull(inputProducer); _bitmapFactory = platformBitmapFactory; _flexByteArrayPool = flexByteArrayPool; _executor = Preconditions.CheckNotNull(executor); }
/// <summary> /// Instantiates the <see cref="CountingMemoryCache{K, V}"/>. /// </summary> public CountingMemoryCache( IValueDescriptor <V> valueDescriptor, ICacheTrimStrategy cacheTrimStrategy, ISupplier <MemoryCacheParams> memoryCacheParamsSupplier, PlatformBitmapFactory platformBitmapFactory, bool isExternalCreatedBitmapLogEnabled) { _valueDescriptor = valueDescriptor; _exclusiveEntries = new CountingLruMap <K, Entry>(WrapValueDescriptor(valueDescriptor)); _cachedEntries = new CountingLruMap <K, Entry>(WrapValueDescriptor(valueDescriptor)); _cacheTrimStrategy = cacheTrimStrategy; _memoryCacheParamsSupplier = memoryCacheParamsSupplier; _memoryCacheParams = _memoryCacheParamsSupplier.Get(); _lastCacheParamsCheck = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if (isExternalCreatedBitmapLogEnabled) { platformBitmapFactory.SetCreationListener( new BitmapCreationObserverImpl((b, o) => _otherEntries.Add(b, o))); } }
/// <summary> /// Clients should override this method only if the post-processed /// bitmap has to be of a different size than the source bitmap. /// If the post-processed bitmap is of the same size, clients should /// override one of the other two methods. /// /// <para />The source bitmap must not be modified as it may be shared /// by the other clients. The implementation must create a new bitmap /// that is safe to be modified and return a reference to it. /// Clients should use <code>bitmapFactory</code> to create a new bitmap. /// </summary> /// <param name="sourceBitmap">The source bitmap.</param> /// <param name="bitmapFactory"> /// The factory to create a destination bitmap. /// </param> /// <param name="flexByteArrayPool"> /// The memory pool used for post process. /// </param> /// <returns> /// A reference to the newly created bitmap. /// </returns> public CloseableReference <SoftwareBitmap> Process( SoftwareBitmap sourceBitmap, PlatformBitmapFactory bitmapFactory, FlexByteArrayPool flexByteArrayPool) { CloseableReference <SoftwareBitmap> destBitmapRef = bitmapFactory.CreateBitmapInternal( sourceBitmap.PixelWidth, sourceBitmap.PixelHeight, sourceBitmap.BitmapPixelFormat); try { Process(destBitmapRef.Get(), sourceBitmap, flexByteArrayPool); return(CloseableReference <SoftwareBitmap> .CloneOrNull(destBitmapRef)); } finally { CloseableReference <SoftwareBitmap> .CloseSafely(destBitmapRef); } }
/// <summary> /// Instantiates the <see cref="ProducerFactory"/> /// </summary> /// <param name="byteArrayPool"> /// The IByteArrayPool used by DecodeProducer. /// </param> /// <param name="imageDecoder"> /// The image decoder. /// </param> /// <param name="progressiveJpegConfig"> /// The progressive Jpeg configuration. /// </param> /// <param name="downsampleEnabled"> /// Enabling downsample. /// </param> /// <param name="resizeAndRotateEnabledForNetwork"> /// Enabling resize and rotate. /// </param> /// <param name="executorSupplier"> /// The supplier for tasks. /// </param> /// <param name="pooledByteBufferFactory"> /// The factory that allocates IPooledByteBuffer memory. /// </param> /// <param name="bitmapMemoryCache"> /// The memory cache for CloseableImage. /// </param> /// <param name="encodedMemoryCache"> /// The memory cache for IPooledByteBuffer. /// </param> /// <param name="defaultBufferedDiskCache"> /// The default buffered disk cache. /// </param> /// <param name="smallImageBufferedDiskCache"> /// The buffered disk cache used for small images. /// </param> /// <param name="cacheKeyFactory"> /// The factory that creates cache keys for the pipeline. /// </param> /// <param name="platformBitmapFactory"> /// The bitmap factory used for post process. /// </param> /// <param name="flexByteArrayPool"> /// The memory pool used for post process. /// </param> /// <param name="forceSmallCacheThresholdBytes"> /// The threshold set for using the small buffered disk cache. /// </param> public ProducerFactory( IByteArrayPool byteArrayPool, ImageDecoder imageDecoder, IProgressiveJpegConfig progressiveJpegConfig, bool downsampleEnabled, bool resizeAndRotateEnabledForNetwork, IExecutorSupplier executorSupplier, IPooledByteBufferFactory pooledByteBufferFactory, IMemoryCache <ICacheKey, CloseableImage> bitmapMemoryCache, IMemoryCache <ICacheKey, IPooledByteBuffer> encodedMemoryCache, BufferedDiskCache defaultBufferedDiskCache, BufferedDiskCache smallImageBufferedDiskCache, ICacheKeyFactory cacheKeyFactory, PlatformBitmapFactory platformBitmapFactory, FlexByteArrayPool flexByteArrayPool, int forceSmallCacheThresholdBytes) { _forceSmallCacheThresholdBytes = forceSmallCacheThresholdBytes; _byteArrayPool = byteArrayPool; _imageDecoder = imageDecoder; _progressiveJpegConfig = progressiveJpegConfig; _downsampleEnabled = downsampleEnabled; _resizeAndRotateEnabledForNetwork = resizeAndRotateEnabledForNetwork; _executorSupplier = executorSupplier; _pooledByteBufferFactory = pooledByteBufferFactory; _bitmapMemoryCache = bitmapMemoryCache; _encodedMemoryCache = encodedMemoryCache; _defaultBufferedDiskCache = defaultBufferedDiskCache; _smallImageBufferedDiskCache = smallImageBufferedDiskCache; _cacheKeyFactory = cacheKeyFactory; _platformBitmapFactory = platformBitmapFactory; _flexByteArrayPool = flexByteArrayPool; }
/// <summary> /// Sets the platform bitmap factory. /// </summary> public Builder SetPlatformBitmapFactory(PlatformBitmapFactory platformBitmapFactory) { PlatformBitmapFactory = platformBitmapFactory; return(this); }