<p dir="auto"><strong>Glide Version/Integration library (if any)</strong>: 3.6.0-SNAPSHOT<br>
<strong>Device/Android Version</strong>: S4/4.4<br>
<strong>Issue details/Repro steps</strong>: <code class="notranslate">ImageVideoModelLoader</code> acquires both <code class="notranslate">InputStream</code> and <code class="notranslate">ParcelFileDescriptor</code> for almost everything:</p>
<ul dir="auto">
<li><code class="notranslate">load(R.raw.svg)</code>:<br>
android.resource://net.twisterrob.app/raw/svg</li>
<li><code class="notranslate">load(ContentUris.withAppendedId(ITEM_URI, id).toString()):</code><br>
content://net.twisterrob.app/item/1579</li>
<li><code class="notranslate">load(new File(new File(context.getFilesDir(), "images"), "item.jpg").toString())</code>:<br>
file:///data/data/net.twisterrob.app/files/images/item.jpg</li>
</ul>
<p dir="auto">The realization that this happens came when I was profiling an activity startup and saw that there are two 800ms database accesses happening in the background. The 800ms was my bad (missing DB indices), but at least it was clearly visible:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/2906988/7202595/2bb05508-e514-11e4-8b41-0a72a52d8785.png"><img src="https://cloud.githubusercontent.com/assets/2906988/7202595/2bb05508-e514-11e4-8b41-0a72a52d8785.png" alt="image" style="max-width: 100%;"></a><br>
I'm transitioning to a <code class="notranslate">ContentProvider</code> to give access to the images with <code class="notranslate">openFile</code>, so the above image displays how <code class="notranslate">content://net.twisterrob.app/item/1579</code> looks like when handed to Glide. I was able to reduce the time required to query the PFD/IS but some may not be that lucky (web backend). Doubling the load time seems unnecessary and as you can see the image could have been already read if just queried once.<br>
The case with <code class="notranslate">R.raw.svg</code> is even worse since the IS is already ready and trying to fetch a PFD fails all the time, because of a limitation on raw resources (only aapt uncompressed one can give a PFD).</p>
<p dir="auto">Why is it needed to acquire the <code class="notranslate">ParcelFileDescriptor</code> when you already have an <code class="notranslate">InputStream</code>?<br>
Is there an easy way to avoid going through <code class="notranslate">ImageVideoModelLoader</code>?<br>
Is there a way for to always use only one or the other? (I guess with some .decoder magic).</p>
<p dir="auto">It should instead let ImageVideoWrapper lazily open these resources when necessary.</p>