Skip to content

Commit

Permalink
Add new SF mbp fallback reasons
Browse files Browse the repository at this point in the history
Reviewed By: malmeida

Differential Revision: D64730635

fbshipit-source-id: 9753100d8015abaee44ad5afcffd75f3d0957af3
  • Loading branch information
Artem Kholodnyi authored and facebook-github-bot committed Oct 24, 2024
1 parent 23a16df commit f29925c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,15 @@ interface UriModifierInterface {

data class Unmodified(val reason: String, override val bestAllowlistedSize: Int?) :
ModificationResult("Unmodified(reason='$reason'")

data class FallbackToMbpMemoryCache(val isBestSize: String) :
ModificationResult("FallbackToMbpMemoryCache($isBestSize") {
override val bestAllowlistedSize: Int? = null
}

data class FallbackToMbpDiskCache(val isBestSize: Boolean) :
ModificationResult("FallbackToMbpDiskCache(isBestSize=$isBestSize") {
override val bestAllowlistedSize: Int? = null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import androidx.core.util.ObjectsCompat
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat
import com.facebook.common.callercontext.ContextChain
import com.facebook.datasource.DataSource
import com.facebook.fresco.middleware.HasExtraData
import com.facebook.fresco.ui.common.OnFadeListener
import com.facebook.fresco.urimod.UriModifierInterface.ModificationResult
import com.facebook.fresco.vito.core.FrescoDrawableInterface
import com.facebook.fresco.vito.core.VitoImageRequest
import com.facebook.fresco.vito.listener.ImageListener
Expand Down Expand Up @@ -351,6 +353,7 @@ object FrescoVitoImage2Spec {
@Prop(optional = true) callerContext: Any?,
@Prop(optional = true) logWithHighSamplingRate: Boolean?,
@Prop(optional = true) prefetchRequestListener: RequestListener?,
@CachedValue requestCachedValue: VitoImageRequest?,
@FromPrepare forceKeepOriginalSize: Boolean
) {
val imageOptions = ensureImageOptions(imageOptions)
Expand All @@ -364,7 +367,7 @@ object FrescoVitoImage2Spec {
}
val viewportRect = Rect(0, 0, width - paddingX, height - paddingY)
viewportDimensions.set(viewportRect)
if (experimentalDynamicSizeVito2() && !forceKeepOriginalSize) {
if (experimentalDynamicSizeVito2()) {
val vitoImageRequest =
createVitoImageRequest(
c,
Expand All @@ -376,19 +379,31 @@ object FrescoVitoImage2Spec {
logWithHighSamplingRate,
viewportRect,
false)
requestFromBoundsDefined.set(vitoImageRequest)

val config = FrescoVitoProvider.getConfig().prefetchConfig
if (shouldPrefetchInBoundsDefinedForDynamicSize(prefetch)) {
prefetchDataSourceFromBoundsDefined.set(
FrescoVitoProvider.getPrefetcher()
.prefetch(
config.prefetchTargetOnBoundsDefined(),
vitoImageRequest,
callerContext,
contextChain,
prefetchRequestListener,
"FrescoVitoImage2Spec_OnBoundsDefined"))

if (!forceKeepOriginalSize) {
requestFromBoundsDefined.set(vitoImageRequest)

val config = FrescoVitoProvider.getConfig().prefetchConfig
if (shouldPrefetchInBoundsDefinedForDynamicSize(prefetch)) {
prefetchDataSourceFromBoundsDefined.set(
FrescoVitoProvider.getPrefetcher()
.prefetch(
config.prefetchTargetOnBoundsDefined(),
vitoImageRequest,
callerContext,
contextChain,
prefetchRequestListener,
"FrescoVitoImage2Spec_OnBoundsDefined"))
}
} else {
// Force keep original size so we will not use the OnBoundsDefined URL
// Compare vitoImageRequest to requestCachedValue to see if original URL was the best URL
val isBestSize =
vitoImageRequest.finalImageRequest?.sourceUri ==
requestCachedValue?.finalImageRequest?.sourceUri
requestCachedValue?.putExtra(
HasExtraData.KEY_MODIFIED_URL,
ModificationResult.FallbackToMbpDiskCache(isBestSize).toString())
}
}
}
Expand Down

0 comments on commit f29925c

Please sign in to comment.