示例#1
0
        /// <summary>
        /// Instantiates the <see cref="ProducerSequenceFactory"/>.
        /// </summary>
        public ProducerSequenceFactory(
            ProducerFactory producerFactory,
            INetworkFetcher <FetchState> networkFetcher,
            bool resizeAndRotateEnabledForNetwork,
            bool downsampleEnabled,
            bool webpSupportEnabled,
            ThreadHandoffProducerQueue threadHandoffProducerQueue,
            int throttlingMaxSimultaneousRequests,
            FlexByteArrayPool flexByteArrayPool)
        {
            _producerFactory = producerFactory;
            _networkFetcher  = networkFetcher;
            _resizeAndRotateEnabledForNetwork = resizeAndRotateEnabledForNetwork;
            _downsampleEnabled      = downsampleEnabled;
            _webpSupportEnabled     = webpSupportEnabled;
            _postprocessorSequences = new Dictionary <
                IProducer <CloseableReference <CloseableImage> >,
                IProducer <CloseableReference <CloseableImage> > >();

            _closeableImagePrefetchSequences = new Dictionary <
                IProducer <CloseableReference <CloseableImage> >,
                IProducer <object> >();

            _threadHandoffProducerQueue        = threadHandoffProducerQueue;
            _throttlingMaxSimultaneousRequests = throttlingMaxSimultaneousRequests;
            _flexByteArrayPool = flexByteArrayPool;
        }
示例#2
0
        private ProducerFactory GetProducerFactory()
        {
            if (_producerFactory == null)
            {
                _producerFactory =
                    new ProducerFactory(
                        _config.PoolFactory.SmallByteArrayPool,
                        GetImageDecoder(),
                        _config.ProgressiveJpegConfig,
                        _config.IsDownsampleEnabled,
                        _config.IsResizeAndRotateEnabledForNetwork,
                        _config.ExecutorSupplier,
                        _config.PoolFactory.PooledByteBufferFactory,
                        GetBitmapMemoryCache(),
                        GetEncodedMemoryCache(),
                        GetMainBufferedDiskCache(),
                        GetSmallImageBufferedDiskCache(),
                        _config.CacheKeyFactory,
                        GetPlatformBitmapFactory(),
                        _config.PoolFactory.FlexByteArrayPool,
                        _config.Experiments.ForceSmallCacheThresholdBytes);
            }

            return(_producerFactory);
        }
示例#3
0
        /// <summary>
        /// swallow-result -> background-thread hand-off -> multiplex ->
        /// encoded cache -> disk cache -> (webp transcode) -> network fetch.
        /// </summary>
        private IProducer <object> GetNetworkFetchToEncodedMemoryPrefetchSequence()
        {
            lock (_gate)
            {
                if (_networkFetchToEncodedMemoryPrefetchSequence == null)
                {
                    _networkFetchToEncodedMemoryPrefetchSequence =
                        ProducerFactory.NewSwallowResultProducer(
                            GetBackgroundNetworkFetchToEncodedMemorySequence());
                }

                return(_networkFetchToEncodedMemoryPrefetchSequence);
            }
        }
示例#4
0
        /// <summary>
        /// swallow result producer -> inputProducer
        /// </summary>
        private IProducer <object> GetDecodedImagePrefetchSequence(

            IProducer <CloseableReference <CloseableImage> > inputProducer)
        {
            lock (_gate)
            {
                if (!_closeableImagePrefetchSequences.ContainsKey(inputProducer))
                {
                    SwallowResultProducer <CloseableReference <CloseableImage> > swallowResultProducer =
                        ProducerFactory.NewSwallowResultProducer(inputProducer);

                    _closeableImagePrefetchSequences.Add(inputProducer, swallowResultProducer);
                }

                var producer = default(IProducer <object>);
                _closeableImagePrefetchSequences.TryGetValue(inputProducer, out producer);
                return(producer);
            }
        }
示例#5
0
        /// <summary>
        /// bitmap cache get ->
        /// background thread hand-off -> bitmap cache -> decode ->
        /// resize and rotate -> (webp transcode) -> data fetch.
        /// </summary>
        private IProducer <CloseableReference <CloseableImage> > GetDataFetchSequence()
        {
            lock (_gate)
            {
                if (_dataFetchSequence == null)
                {
                    IProducer <EncodedImage> inputProducer = _producerFactory.NewDataFetchProducer();
                    inputProducer = ProducerFactory.NewAddImageTransformMetaDataProducer(inputProducer);
                    if (!_downsampleEnabled)
                    {
                        inputProducer = _producerFactory.NewResizeAndRotateProducer(inputProducer);
                    }

                    _dataFetchSequence = NewBitmapCacheGetToDecodeSequence(inputProducer);
                }

                return(_dataFetchSequence);
            }
        }
示例#6
0
        /// <summary>
        /// Branch on separate images
        ///   -> thumbnail resize and rotate -> thumbnail producers as provided
        ///   -> local image resize and rotate -> add meta data producer
        /// </summary>
        /// <param name="inputProducer">
        /// Producer providing the input to add meta data producer.
        /// </param>
        /// <param name="thumbnailProducers">
        /// The thumbnail producers from which to request the image before
        /// falling back to the full image producer sequence.
        /// </param>
        /// <returns>Local transformations sequence.</returns>
        private IProducer <EncodedImage> NewLocalTransformationsSequence(
            IProducer <EncodedImage> inputProducer,
            IThumbnailProducer <EncodedImage>[] thumbnailProducers)
        {
            IProducer <EncodedImage> localImageProducer =
                ProducerFactory.NewAddImageTransformMetaDataProducer(inputProducer);

            if (!_downsampleEnabled)
            {
                localImageProducer = _producerFactory.NewResizeAndRotateProducer(localImageProducer);
            }

            ThrottlingProducer <EncodedImage> localImageThrottlingProducer =
                _producerFactory.NewThrottlingProducer(
                    _throttlingMaxSimultaneousRequests,
                    localImageProducer);

            return(ProducerFactory.NewBranchOnSeparateImagesProducer(
                       NewLocalThumbnailProducer(thumbnailProducers),
                       localImageThrottlingProducer));
        }
示例#7
0
        /// <summary>
        /// multiplex -> encoded cache -> disk cache -> (webp transcode) ->
        /// network fetch.
        /// </summary>
        private IProducer <EncodedImage> GetCommonNetworkFetchToEncodedMemorySequence()
        {
            lock (_gate)
            {
                if (_commonNetworkFetchToEncodedMemorySequence == null)
                {
                    IProducer <EncodedImage> inputProducer =
                        NewEncodedCacheMultiplexToTranscodeSequence(
                            _producerFactory.NewNetworkFetchProducer(_networkFetcher));

                    _commonNetworkFetchToEncodedMemorySequence =
                        ProducerFactory.NewAddImageTransformMetaDataProducer(inputProducer);

                    if (_resizeAndRotateEnabledForNetwork && !_downsampleEnabled)
                    {
                        _commonNetworkFetchToEncodedMemorySequence =
                            _producerFactory.NewResizeAndRotateProducer(
                                _commonNetworkFetchToEncodedMemorySequence);
                    }
                }

                return(_commonNetworkFetchToEncodedMemorySequence);
            }
        }