Пример #1
0
 /// <summary>
 /// Instantiates the <see cref="LocalContentUriThumbnailFetchProducer"/>.
 /// </summary>
 public LocalContentUriThumbnailFetchProducer(
     IExecutorService executor,
     IPooledByteBufferFactory pooledByteBufferFactory) : base(
         executor,
         pooledByteBufferFactory)
 {
 }
 /// <summary>
 /// Instantiates the <see cref="LocalExifThumbnailProducer"/>.
 /// </summary>
 public LocalExifThumbnailProducer(
     IExecutorService executor,
     IPooledByteBufferFactory pooledByteBufferFactory)
 {
     _executor = executor;
     _pooledByteBufferFactory = pooledByteBufferFactory;
 }
Пример #3
0
 /// <summary>
 /// Instantiates the <see cref="FutureAccessListFetchProducer"/>.
 /// </summary>
 public FutureAccessListFetchProducer(
     IExecutorService executor,
     IPooledByteBufferFactory pooledByteBufferFactory) : base(
         executor,
         pooledByteBufferFactory)
 {
 }
 /// <summary>
 /// Instantiates the <see cref="LocalFetchProducer"/>.
 /// </summary>
 protected LocalFetchProducer(
     IExecutorService executor,
     IPooledByteBufferFactory pooledByteBufferFactory)
 {
     _executor = executor;
     _pooledByteBufferFactory = pooledByteBufferFactory;
 }
 /// <summary>
 /// Instantiates the <see cref="LocalAssetFetchProducer"/>.
 /// </summary>
 public LocalAssetFetchProducer(
     IExecutorService executor,
     IPooledByteBufferFactory pooledByteBufferFactory) : base(
         executor,
         pooledByteBufferFactory)
 {
 }
 /// <summary>
 /// Instantiates the <see cref="WebpTranscodeProducer"/>.
 /// </summary>
 public WebpTranscodeProducer(
     IExecutorService executor,
     IPooledByteBufferFactory pooledByteBufferFactory,
     IProducer <EncodedImage> inputProducer)
 {
     _executor = Preconditions.CheckNotNull(executor);
     _pooledByteBufferFactory = Preconditions.CheckNotNull(pooledByteBufferFactory);
     _inputProducer           = Preconditions.CheckNotNull(inputProducer);
 }
 /// <summary>
 /// Instantiates the <see cref="NetworkFetchProducer"/>.
 /// </summary>
 public NetworkFetchProducer(
     IPooledByteBufferFactory pooledByteBufferFactory,
     IByteArrayPool byteArrayPool,
     INetworkFetcher <FetchState> networkFetcher)
 {
     _pooledByteBufferFactory = pooledByteBufferFactory;
     _byteArrayPool           = byteArrayPool;
     _networkFetcher          = networkFetcher;
 }
Пример #8
0
        public void Initialize()
        {
            // Initializes the IFileCache
            _fileCacheFactory = new DiskStorageCacheFactory(new DynamicDefaultDiskStorageFactory());
            _fileCache        = _fileCacheFactory.Get(DiskCacheConfig.NewBuilder().Build());

            // Initializes the IPooledByteBufferFactory and PooledByteStreams
            _poolFactory       = new PoolFactory(PoolConfig.NewBuilder().Build());
            _byteBufferFactory = _poolFactory.PooledByteBufferFactory;
            _pooledByteStreams = _poolFactory.PooledByteStreams;

            // Initializes the IPooledByteBuffer from an image
            var file = StorageFile.GetFileFromApplicationUriAsync(
                new Uri("ms-appx:///Assets/SplashScreen.scale-200.png")).GetAwaiter().GetResult();

            using (var stream = file.OpenReadAsync().GetAwaiter().GetResult())
            {
                _pooledByteBuffer = _byteBufferFactory.NewByteBuffer(
                    ByteStreams.ToByteArray(stream.AsStream()));
            }

            _closeableReference = CloseableReference <IPooledByteBuffer> .of(_pooledByteBuffer);

            _encodedImage           = new EncodedImage(_closeableReference);
            _stagingArea            = StagingArea.Instance;
            _imageCacheStatsTracker = NoOpImageCacheStatsTracker.Instance;

            // Initializes the cache keys
            IList <ICacheKey> keys = new List <ICacheKey>();

            keys.Add(new SimpleCacheKey("http://test.uri"));
            keys.Add(new SimpleCacheKey("http://tyrone.uri"));
            keys.Add(new SimpleCacheKey("http://ian.uri"));
            _cacheKey = new MultiCacheKey(keys);

            // Initializes the executors
            _isCancelled           = new AtomicBoolean(false);
            _readPriorityExecutor  = Executors.NewFixedThreadPool(1);
            _writePriorityExecutor = Executors.NewFixedThreadPool(1);

            // Initializes the disk cache
            _bufferedDiskCache = new BufferedDiskCache(
                _fileCache,
                _byteBufferFactory,
                _pooledByteStreams,
                _readPriorityExecutor,
                _writePriorityExecutor,
                _imageCacheStatsTracker);
        }
Пример #9
0
 /// <summary>
 /// Instantiates the <see cref="BufferedDiskCache"/>.
 /// </summary>
 public BufferedDiskCache(
     IFileCache fileCache,
     IPooledByteBufferFactory pooledByteBufferFactory,
     PooledByteStreams pooledByteStreams,
     IExecutorService readExecutor,
     IExecutorService writeExecutor,
     IImageCacheStatsTracker imageCacheStatsTracker)
 {
     _fileCache = fileCache;
     _pooledByteBufferFactory = pooledByteBufferFactory;
     _pooledByteStreams       = pooledByteStreams;
     _readExecutor            = readExecutor;
     _writeExecutor           = writeExecutor;
     _imageCacheStatsTracker  = imageCacheStatsTracker;
     _stagingArea             = StagingArea.Instance;
 }
 /// <summary>
 /// Instantiates the <see cref="BufferedDiskCache"/>.
 /// </summary>
 public BufferedDiskCache(
     IFileCache fileCache,
     IPooledByteBufferFactory pooledByteBufferFactory,
     PooledByteStreams pooledByteStreams,
     IExecutorService readExecutor,
     IExecutorService writeExecutor,
     IImageCacheStatsTracker imageCacheStatsTracker)
 {
     _fileCache = fileCache;
     _pooledByteBufferFactory = pooledByteBufferFactory;
     _pooledByteStreams       = pooledByteStreams;
     _readExecutor            = readExecutor;
     _writeExecutor           = writeExecutor;
     _imageCacheStatsTracker  = imageCacheStatsTracker;
     _stagingArea             = StagingArea.Instance;
     _writeToDiskCacheTasks   = new ConcurrentDictionary <ICacheKey, Task>();
 }
Пример #11
0
        /// <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;
        }
Пример #12
0
        public void Initialize()
        {
            _testExecutor            = Executors.NewFixedThreadPool(MAX_DEGREE_OF_PARALLELISM);
            _poolFactory             = new PoolFactory(PoolConfig.NewBuilder().Build());
            _pooledByteBufferFactory = _poolFactory.PooledByteBufferFactory;
            _byteArrayPool           = _poolFactory.SmallByteArrayPool;
            _producerListener        = new ProducerListenerImpl(
                (_, __) => { },
                (requestId, producerName, eventName) =>
            {
                if (eventName.Equals(NetworkFetchProducer.INTERMEDIATE_RESULT_PRODUCER_EVENT))
                {
                    ++_intermediateResultProducerEventCalls;
                }
            },
                (_, __, ___) =>
            {
                ++_onProducerFinishWithSuccessFuncCalls;
            },
                (requestId, producerName, error, extraMap) =>
            {
                _internalRequestId    = requestId;
                _internalProducerName = producerName;
                _internalError        = error;
                _internalExtraMap     = extraMap;
                ++_onProducerFinishWithFailureFuncCalls;
            },
                (_, __, ___) =>
            {
                ++_onProducerFinishWithCancellationFuncCalls;
            },
                (_) =>
            {
                return(false);
            });

            _consumer = new BaseConsumerImpl <EncodedImage>(
                (_, isLast) =>
            {
                ++_onNewResultImplCalls;

                if (isLast)
                {
                    _completion.Set();
                }
            },
                (_) =>
            {
                _completion.Set();
            },
                () =>
            {
                _completion.Set();
            },
                (_) => { });

            _networkFetchProducer = new NetworkFetchProducer(
                _pooledByteBufferFactory,
                _byteArrayPool,
                _networkFetcher);

            _completion = new ManualResetEvent(false);
        }
Пример #13
0
 /// <summary>
 /// Instantiates the <see cref="DataFetchProducer"/>.
 /// </summary>
 public DataFetchProducer(
     IPooledByteBufferFactory pooledByteBufferFactory) : base(
         CallerThreadExecutor.Instance,
         pooledByteBufferFactory)
 {
 }