Skip to content

Commit

Permalink
Add support for data URIs in [Part 2]
Browse files Browse the repository at this point in the history
  • Loading branch information
tyronen committed May 14, 2015
1 parent d614d3a commit 388c8c2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fbcore/src/main/java/com/facebook/common/util/UriUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class UriUtil {
*/
public static final String LOCAL_RESOURCE_SCHEME = "res";

/** Data scheme for URIs */
public static final String DATA_SCHEME = "data";

/**
* /**
* Check if uri represents network resource
Expand Down Expand Up @@ -97,6 +100,11 @@ public static boolean isLocalResourceUri(@Nullable Uri uri) {
return LOCAL_RESOURCE_SCHEME.equals(scheme);
}

/** Check if the uri is a data uri */
public static boolean isDataUri(@Nullable Uri uri) {
return DATA_SCHEME.equals(getSchemeOrNull(uri));
}

/**
* @param uri uri to extract scheme from, possibly null
* @return null if uri is null, result of uri.getScheme() otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.facebook.imagepipeline.producers.BitmapMemoryCacheKeyMultiplexProducer;
import com.facebook.imagepipeline.producers.BitmapMemoryCacheProducer;
import com.facebook.imagepipeline.producers.BranchOnSeparateImagesProducer;
import com.facebook.imagepipeline.producers.DataFetchProducer;
import com.facebook.imagepipeline.producers.DecodeProducer;
import com.facebook.imagepipeline.producers.DiskCacheProducer;
import com.facebook.imagepipeline.producers.EncodedCacheKeyMultiplexProducer;
Expand Down Expand Up @@ -139,6 +140,10 @@ public static BranchOnSeparateImagesProducer newBranchOnSeparateImagesProducer(
return new BranchOnSeparateImagesProducer(nextProducer1, nextProducer2);
}

public DataFetchProducer newDataFetchProducer() {
return new DataFetchProducer(mExecutorSupplier.forBackground(), mPooledByteBufferFactory);
}

public DecodeProducer newDecodeProducer(
Producer<CloseableReference<PooledByteBuffer>> nextProducer) {
return new DecodeProducer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.facebook.imagepipeline.producers.BitmapMemoryCacheKeyMultiplexProducer;
import com.facebook.imagepipeline.producers.BitmapMemoryCacheProducer;
import com.facebook.imagepipeline.producers.BranchOnSeparateImagesProducer;
import com.facebook.imagepipeline.producers.DataFetchProducer;
import com.facebook.imagepipeline.producers.DecodeProducer;
import com.facebook.imagepipeline.producers.EncodedMemoryCacheProducer;
import com.facebook.imagepipeline.producers.ImageTransformMetaData;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class ProducerSequenceFactory {
@VisibleForTesting Producer<CloseableReference<CloseableImage>> mLocalContentUriFetchSequence;
@VisibleForTesting Producer<CloseableReference<CloseableImage>> mLocalResourceFetchSequence;
@VisibleForTesting Producer<CloseableReference<CloseableImage>> mLocalAssetFetchSequence;
@VisibleForTesting Producer<CloseableReference<CloseableImage>> mDataFetchSequence;
@VisibleForTesting Map<
Producer<CloseableReference<CloseableImage>>,
Producer<CloseableReference<CloseableImage>>>
Expand Down Expand Up @@ -164,6 +166,8 @@ private Producer<CloseableReference<CloseableImage>> getBasicDecodedImageSequenc
return getLocalAssetFetchSequence();
} else if (UriUtil.isLocalResourceUri(uri)) {
return getLocalResourceFetchSequence();
} else if (UriUtil.isDataUri(uri)) {
return getDataFetchSequence();
} else {
String uriString = uri.toString();
if (uriString.length() > 30) {
Expand Down Expand Up @@ -320,6 +324,19 @@ private synchronized Producer<CloseableReference<CloseableImage>> getLocalAssetF
return mLocalAssetFetchSequence;
}

/**
* bitmap cache get ->
* background thread hand-off -> multiplex -> bitmap cache -> decode ->
*/
private synchronized Producer<CloseableReference<CloseableImage>> getDataFetchSequence() {
if (mDataFetchSequence == null) {
DataFetchProducer dataFetchProducer =
mProducerFactory.newDataFetchProducer();
mDataFetchSequence = newBitmapCacheGetToDecodeSequence(dataFetchProducer);
}
return mDataFetchSequence;
}

/**
* Creates a new fetch sequence that just needs the source producer.
* @param nextProducer the source producer
Expand Down

0 comments on commit 388c8c2

Please sign in to comment.