Skip to content

Commit

Permalink
Add new lightweight debug overlay for Vito v2
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D51305440

fbshipit-source-id: 8a97d8c013435b3bdacd54ea6fbf8bd2a36b595c
  • Loading branch information
oprisnik authored and facebook-github-bot committed Nov 22, 2023
1 parent 2f90c1e commit f528f6b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ import kotlin.math.min
open class DebugOverlayDrawable
@JvmOverloads
constructor(
private val identifier: String = "",
val identifier: String = "",
private val identifierColor: Int = 0xFF00FF00.toInt(),
) : Drawable() {

@ColorInt var backgroundColor: Int = Color.TRANSPARENT
var textGravity: Int = Gravity.TOP

var drawIdentifier: Boolean = true

// Internal helpers
private val debugData = LinkedHashMap<String, Pair<String, Int>>()
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
Expand Down Expand Up @@ -93,7 +95,9 @@ constructor(
// Reset the text position
currentTextXPx = startTextXPx
currentTextYPx = startTextYPx
addDebugText(canvas, "Vito", identifier, identifierColor)
if (drawIdentifier) {
addDebugText(canvas, "Vito", identifier, identifierColor)
}
for ((key, value) in debugData) {
addDebugText(canvas, key, value.first, value.second)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void update(FrescoDrawable2 drawable, @Nullable ControllerListener2.Extra
DebugOverlayDrawable overlay = extractOrCreate(drawable);
overlay.reset();
setData(overlay, drawable, extras);
overlay.invalidateSelf();
}

protected abstract void setData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,24 @@
@Nullsafe(Nullsafe.Mode.STRICT)
public class DefaultDebugOverlayFactory2 extends BaseDebugOverlayFactory2 {

private boolean mShowExtendedInformation;

public DefaultDebugOverlayFactory2(Supplier<Boolean> debugOverlayEnabled) {
this(true, debugOverlayEnabled);
}

public DefaultDebugOverlayFactory2(
boolean showExtendedInformation, Supplier<Boolean> debugOverlayEnabled) {
super(debugOverlayEnabled);
mShowExtendedInformation = showExtendedInformation;
}

public void setShowExtendedInformation(boolean showExtendedInformation) {
mShowExtendedInformation = showExtendedInformation;
}

public boolean getShowExtendedInformation() {
return mShowExtendedInformation;
}

@Override
Expand All @@ -37,18 +53,22 @@ protected void setData(
setImageOriginData(overlay, extras);
}

private static void setBasicData(DebugOverlayDrawable overlay, FrescoDrawableInterface drawable) {
overlay.addDebugData("ID", VitoUtils.getStringId(drawable.getImageId()));
private void setBasicData(DebugOverlayDrawable overlay, FrescoDrawableInterface drawable) {
overlay.setDrawIdentifier(mShowExtendedInformation);
String tag = mShowExtendedInformation ? "ID" : overlay.getIdentifier();
overlay.addDebugData(tag, VitoUtils.getStringId(drawable.getImageId()));
if (drawable instanceof FrescoDrawable2) {
FrescoDrawable2 abstractDrawable = (FrescoDrawable2) drawable;
Rect bounds = abstractDrawable.getBounds();
overlay.addDebugData("D", formatDimensions(bounds.width(), bounds.height()));
overlay.addDebugData("DAR", String.valueOf(bounds.width() / (float) bounds.height()));
if (mShowExtendedInformation) {
overlay.addDebugData("DAR", String.valueOf(bounds.width() / (float) bounds.height()));
}
overlay.addDebugData(
"I",
formatDimensions(
abstractDrawable.getActualImageWidthPx(), abstractDrawable.getActualImageHeightPx()));
if (abstractDrawable.getActualImageHeightPx() > 0) {
if (mShowExtendedInformation && abstractDrawable.getActualImageHeightPx() > 0) {
overlay.addDebugData(
"IAR",
String.valueOf(
Expand All @@ -58,7 +78,7 @@ private static void setBasicData(DebugOverlayDrawable overlay, FrescoDrawableInt
}
}

private static void setImageOriginData(
private void setImageOriginData(
DebugOverlayDrawable overlay, @Nullable ControllerListener2.Extras extras) {
String origin = "unknown";
String originSubcategory = "unknown";
Expand All @@ -74,14 +94,21 @@ private static void setImageOriginData(
originSubcategory = String.valueOf(originExtras.get("origin_sub"));
}
}
overlay.addDebugData(
"origin", origin, DebugOverlayImageOriginColor.getImageOriginColor(origin));
overlay.addDebugData("origin_sub", originSubcategory, Color.GRAY);
if (mShowExtendedInformation) {
overlay.addDebugData(
"origin", origin, DebugOverlayImageOriginColor.getImageOriginColor(origin));
overlay.addDebugData("origin_sub", originSubcategory, Color.GRAY);
} else {
overlay.addDebugData(
"o",
origin + " | " + originSubcategory,
DebugOverlayImageOriginColor.getImageOriginColor(origin));
}
}

private static void setImageRequestData(
private void setImageRequestData(
DebugOverlayDrawable overlay, @Nullable VitoImageRequest imageRequest) {
if (imageRequest == null) {
if (imageRequest == null || !mShowExtendedInformation) {
return;
}
overlay.addDebugData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import com.facebook.fresco.vito.core.impl.BaseVitoImagePerfListener
import com.facebook.fresco.vito.core.impl.DefaultImageDecodeOptionsProviderImpl
import com.facebook.fresco.vito.core.impl.ImagePipelineUtilsImpl
import com.facebook.fresco.vito.core.impl.ImagePipelineUtilsImpl.CircularBitmapRounding
import com.facebook.fresco.vito.core.impl.debug.DefaultDebugOverlayFactory2
import com.facebook.fresco.vito.core.impl.debug.NoOpDebugOverlayFactory2
import com.facebook.fresco.vito.nativecode.NativeCircularBitmapRounding
import com.facebook.fresco.vito.provider.FrescoVitoProvider
import com.facebook.fresco.vito.provider.impl.DefaultFrescoVitoProvider
Expand Down Expand Up @@ -50,12 +52,13 @@ class FrescoVito {
imagePipeline: ImagePipeline? = null,
lightweightBackgroundThreadExecutor: Executor? = null,
uiThreadExecutor: Executor? = null,
debugOverlayEnabledSupplier: Supplier<Boolean?>? = null,
debugOverlayEnabledSupplier: Supplier<Boolean>? = null,
useNativeCode: Supplier<Boolean> = Suppliers.BOOLEAN_TRUE,
vitoConfig: FrescoVitoConfig = DefaultFrescoVitoConfig(),
callerContextVerifier: CallerContextVerifier = NoOpCallerContextVerifier,
vitoImagePerfListener: VitoImagePerfListener = BaseVitoImagePerfListener(),
imagePerfListenerSupplier: Supplier<ControllerListener2<ImageInfo>>? = null,
showExtendedDebugOverlayInformation: Boolean = true
) {
if (isInitialized) {
return
Expand All @@ -72,9 +75,11 @@ class FrescoVito {
createImagePipelineUtils(useNativeCode),
lightweightBackgroundThreadExecutor,
uiThreadExecutor,
debugOverlayEnabledSupplier,
callerContextVerifier,
vitoImagePerfListener,
debugOverlayEnabledSupplier?.let {
DefaultDebugOverlayFactory2(showExtendedDebugOverlayInformation, it)
} ?: NoOpDebugOverlayFactory2(),
imagePerfListenerSupplier))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.facebook.fresco.vito.core.impl.FrescoController2Impl
import com.facebook.fresco.vito.core.impl.FrescoVitoPrefetcherImpl
import com.facebook.fresco.vito.core.impl.HierarcherImpl
import com.facebook.fresco.vito.core.impl.VitoImagePipelineImpl
import com.facebook.fresco.vito.core.impl.debug.DefaultDebugOverlayFactory2
import com.facebook.fresco.vito.core.impl.debug.DebugOverlayFactory2
import com.facebook.fresco.vito.core.impl.debug.NoOpDebugOverlayFactory2
import com.facebook.fresco.vito.drawable.ArrayVitoDrawableFactory
import com.facebook.fresco.vito.drawable.BitmapDrawableFactory
Expand All @@ -39,9 +39,9 @@ class DefaultFrescoVitoProvider(
imagePipelineUtils: ImagePipelineUtils,
lightweightBackgroundThreadExecutor: Executor,
uiThreadExecutor: Executor,
debugOverlayEnabledSupplier: Supplier<Boolean?>?,
callerContextVerifier: CallerContextVerifier,
vitoImagePerfListener: VitoImagePerfListener,
debugOverlayFactory: DebugOverlayFactory2 = NoOpDebugOverlayFactory2(),
imagePerfListenerSupplier: Supplier<ControllerListener2<ImageInfo>>? = null,
) : FrescoVitoProvider.Implementation {

Expand All @@ -67,8 +67,7 @@ class DefaultFrescoVitoProvider(
uiThreadExecutor,
vitoImagePipeline,
null,
debugOverlayEnabledSupplier?.let { DefaultDebugOverlayFactory2(it) }
?: NoOpDebugOverlayFactory2(),
debugOverlayFactory,
imagePerfListenerSupplier,
vitoImagePerfListener)
}
Expand Down

0 comments on commit f528f6b

Please sign in to comment.