Exemplo n.º 1
0
            private void SubmitPostprocessing()
            {
                _parent._executor.Execute(() =>
                {
                    CloseableReference <CloseableImage> closeableImageRef;
                    bool isLast;
                    lock (_gate)
                    {
                        // instead of cloning and closing the reference, we do a more
                        // efficient move.
                        closeableImageRef = _sourceImageRef;
                        isLast            = _isLast;
                        _sourceImageRef   = null;
                        _isDirty          = false;
                    }

                    if (CloseableReference <CloseableImage> .IsValid(closeableImageRef))
                    {
                        try
                        {
                            DoPostprocessing(closeableImageRef, isLast);
                        }
                        finally
                        {
                            CloseableReference <CloseableImage> .CloseSafely(closeableImageRef);
                        }
                    }

                    ClearRunningAndStartIfDirty();
                });
            }
Exemplo n.º 2
0
 /// <summary>
 /// Ensure that the current stream is valid, that is underlying
 /// closeable reference is not null and is valid.
 /// </summary>
 /// <exception cref="InvalidStreamException">
 /// If the stream is invalid.
 /// </exception>
 private void EnsureValid()
 {
     if (!CloseableReference <NativeMemoryChunk> .IsValid(_bufRef))
     {
         throw new InvalidStreamException();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Instantiates the <see cref="EncodedImage"/> with provided params
        /// </summary>
        public EncodedImage(CloseableReference <IPooledByteBuffer> pooledByteBufferRef)
        {
            Preconditions.CheckArgument(
                CloseableReference <IPooledByteBuffer> .IsValid(pooledByteBufferRef));

            _pooledByteBufferRef = pooledByteBufferRef.Clone();
            _inputStreamSupplier = null;
        }
Exemplo n.º 4
0
            private bool SetRunningIfDirtyAndNotRunning()
            {
                lock (_gate)
                {
                    if (!_isClosed && _isDirty && !_isPostProcessingRunning &&
                        CloseableReference <CloseableImage> .IsValid(_sourceImageRef))
                    {
                        _isPostProcessingRunning = true;
                        return(true);
                    }

                    return(false);
                }
            }
Exemplo n.º 5
0
            protected override void OnNewResultImpl(
                CloseableReference <CloseableImage> newResult, bool isLast)
            {
                if (!CloseableReference <CloseableImage> .IsValid(newResult))
                {
                    // try to propagate if the last result is invalid
                    if (isLast)
                    {
                        MaybeNotifyOnNewResult(null, true);
                    }

                    // ignore if invalid
                    return;
                }

                UpdateSourceImageRef(newResult, isLast);
            }
        /// <summary>
        /// Returns whether the image is stored in the bitmap memory cache.
        /// </summary>
        /// <param name="imageRequest">
        /// The imageRequest for the image to be looked up.
        /// </param>
        /// <returns>
        /// true if the image was found in the bitmap memory cache,
        /// false otherwise.
        /// </returns>
        public bool IsInBitmapMemoryCache(ImageRequest imageRequest)
        {
            if (imageRequest == null)
            {
                return(false);
            }

            ICacheKey cacheKey = _cacheKeyFactory.GetBitmapCacheKey(imageRequest, null);
            CloseableReference <CloseableImage> reference = _bitmapMemoryCache.Get(cacheKey);

            try
            {
                return(CloseableReference <CloseableImage> .IsValid(reference));
            }
            finally
            {
                CloseableReference <CloseableImage> .CloseSafely(reference);
            }
        }
Exemplo n.º 7
0
            private void DoPostprocessing(
                CloseableReference <CloseableImage> sourceImageRef,
                bool isLast)
            {
                Preconditions.CheckArgument(CloseableReference <CloseableImage> .IsValid(sourceImageRef));
                if (!ShouldPostprocess(sourceImageRef.Get()))
                {
                    MaybeNotifyOnNewResult(sourceImageRef, isLast);
                    return;
                }

                _listener.OnProducerStart(_requestId, NAME);
                CloseableReference <CloseableImage> destImageRef = null;

                try
                {
                    try
                    {
                        destImageRef = PostprocessInternal(sourceImageRef.Get());
                    }
                    catch (Exception e)
                    {
                        _listener.OnProducerFinishWithFailure(
                            _requestId, NAME, e, GetExtraMap(_listener, _requestId, _postprocessor));

                        MaybeNotifyOnFailure(e);
                        return;
                    }

                    _listener.OnProducerFinishWithSuccess(
                        _requestId, NAME, GetExtraMap(_listener, _requestId, _postprocessor));

                    MaybeNotifyOnNewResult(destImageRef, isLast);
                }
                finally
                {
                    CloseableReference <CloseableImage> .CloseSafely(destImageRef);
                }
            }
Exemplo n.º 8
0
 public void TestRemoveWithBadRef()
 {
     Assert.IsFalse(_stagingArea.Remove(_cacheKey, _secondEncodedImage));
     Assert.IsTrue(CloseableReference <IPooledByteBuffer> .IsValid(_closeableReference));
     Assert.IsTrue(CloseableReference <IPooledByteBuffer> .IsValid(_closeableReference2));
 }