Skip to content

Commit

Permalink
Move ImagePerfState and ImagePerfData to ui-common target
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik

Differential Revision: D43398660

fbshipit-source-id: 2160becc874fcd6231ef44630f2fbdf5ab108440
  • Loading branch information
steelrooter authored and facebook-github-bot committed Feb 23, 2023
1 parent ee34e5e commit ac00658
Show file tree
Hide file tree
Showing 28 changed files with 244 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.facebook.common.internal.Preconditions;
import com.facebook.common.internal.Supplier;
import com.facebook.common.internal.Suppliers;
import com.facebook.drawee.backends.pipeline.info.ImagePerfDataListener;
import com.facebook.fresco.ui.common.ImagePerfDataListener;
import com.facebook.imagepipeline.drawable.DrawableFactory;
import com.facebook.infer.annotation.Nullsafe;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.facebook.drawee.backends.pipeline.info.ImageOriginListener;
import com.facebook.drawee.backends.pipeline.info.ImageOriginRequestListener;
import com.facebook.drawee.backends.pipeline.info.ImageOriginUtils;
import com.facebook.drawee.backends.pipeline.info.ImagePerfDataListener;
import com.facebook.drawee.backends.pipeline.info.ImagePerfMonitor;
import com.facebook.drawee.components.DeferredReleaser;
import com.facebook.drawee.controller.AbstractDraweeController;
Expand All @@ -40,6 +39,7 @@
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.interfaces.DraweeHierarchy;
import com.facebook.drawee.interfaces.SettableDraweeHierarchy;
import com.facebook.fresco.ui.common.ImagePerfDataListener;
import com.facebook.fresco.ui.common.MultiUriHelper;
import com.facebook.imagepipeline.cache.MemoryCache;
import com.facebook.imagepipeline.drawable.DrawableFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import com.facebook.common.references.CloseableReference;
import com.facebook.datasource.DataSource;
import com.facebook.drawee.backends.pipeline.info.ImageOriginListener;
import com.facebook.drawee.backends.pipeline.info.ImagePerfDataListener;
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
import com.facebook.drawee.controller.ControllerListener;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.fresco.ui.common.ControllerListener2;
import com.facebook.fresco.ui.common.ImagePerfDataListener;
import com.facebook.imagepipeline.cache.CacheKeyFactory;
import com.facebook.imagepipeline.common.RotationOptions;
import com.facebook.imagepipeline.core.ImagePipeline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import android.content.Context;
import com.facebook.common.executors.UiThreadImmediateExecutorService;
import com.facebook.common.internal.Supplier;
import com.facebook.drawee.backends.pipeline.info.ImagePerfDataListener;
import com.facebook.drawee.components.DeferredReleaser;
import com.facebook.drawee.controller.ControllerListener;
import com.facebook.fresco.ui.common.ControllerListener2;
import com.facebook.fresco.ui.common.ImagePerfDataListener;
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.core.ImagePipelineFactory;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

package com.facebook.drawee.backends.pipeline.info;

import com.facebook.fresco.ui.common.ImageLoadStatus;
import com.facebook.fresco.ui.common.ImagePerfData;
import com.facebook.fresco.ui.common.ImagePerfDataListener;
import com.facebook.fresco.ui.common.VisibilityState;
import com.facebook.infer.annotation.Nullsafe;
import java.util.Collection;

Expand All @@ -21,15 +25,15 @@ public ForwardingImagePerfDataListener(Collection<ImagePerfDataListener> listene

@Override
public void onImageLoadStatusUpdated(
ImagePerfData imagePerfData, @ImageLoadStatus int imageLoadStatus) {
ImagePerfData imagePerfData, ImageLoadStatus imageLoadStatus) {
for (ImagePerfDataListener listener : mListeners) {
listener.onImageLoadStatusUpdated(imagePerfData, imageLoadStatus);
}
}

@Override
public void onImageVisibilityUpdated(
ImagePerfData imagePerfData, @VisibilityState int visibilityState) {
ImagePerfData imagePerfData, VisibilityState visibilityState) {
for (ImagePerfDataListener listener : mListeners) {
listener.onImageVisibilityUpdated(imagePerfData, visibilityState);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.facebook.drawee.backends.pipeline.info;

import com.facebook.fresco.ui.common.ImagePerfData;
import com.facebook.imagepipeline.producers.BitmapMemoryCacheGetProducer;
import com.facebook.imagepipeline.producers.BitmapMemoryCacheProducer;
import com.facebook.imagepipeline.producers.DataFetchProducer;
Expand Down Expand Up @@ -80,5 +81,17 @@ public static String toString(@ImageOrigin int imageOrigin) {
}
}

public static @ImageOrigin int getImageOriginFromImagePerfData(ImagePerfData imagePerfData) {
Object originFromPipelineExtras = imagePerfData.getPipelineExtra(ImagePerfExtra.IMAGE_ORIGIN);
final int imageOrigin;
if (originFromPipelineExtras == null) {
imageOrigin = ImageOrigin.UNKNOWN;
} else {
imageOrigin = (int) originFromPipelineExtras;
}

return imageOrigin;
}

private ImageOriginUtils() {}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.drawee.backends.pipeline.info

object ImagePerfExtra {
const val IMAGE_ORIGIN = "IMAGE_ORIGIN"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
import com.facebook.drawee.backends.pipeline.info.internal.ImagePerfImageOriginListener;
import com.facebook.drawee.backends.pipeline.info.internal.ImagePerfRequestListener;
import com.facebook.drawee.interfaces.DraweeHierarchy;
import com.facebook.fresco.ui.common.ImageLoadStatus;
import com.facebook.fresco.ui.common.ImagePerfData;
import com.facebook.fresco.ui.common.ImagePerfDataListener;
import com.facebook.fresco.ui.common.ImagePerfNotifier;
import com.facebook.fresco.ui.common.ImagePerfState;
import com.facebook.fresco.ui.common.VisibilityState;
import com.facebook.imagepipeline.listener.ForwardingRequestListener;
import com.facebook.infer.annotation.Nullsafe;
import java.util.List;
Expand Down Expand Up @@ -100,7 +106,7 @@ public void clearImagePerfDataListeners() {
}

@Override
public void notifyStatusUpdated(ImagePerfState state, @ImageLoadStatus int imageLoadStatus) {
public void notifyStatusUpdated(ImagePerfState state, ImageLoadStatus imageLoadStatus) {
state.setImageLoadStatus(imageLoadStatus);
if (!mEnabled || mImagePerfDataListeners == null || mImagePerfDataListeners.isEmpty()) {
return;
Expand All @@ -116,7 +122,7 @@ public void notifyStatusUpdated(ImagePerfState state, @ImageLoadStatus int image

@Override
public void notifyListenersOfVisibilityStateUpdate(
ImagePerfState state, @VisibilityState int visibilityState) {
ImagePerfState state, VisibilityState visibilityState) {
if (!mEnabled || mImagePerfDataListeners == null || mImagePerfDataListeners.isEmpty()) {
return;
}
Expand Down Expand Up @@ -146,7 +152,7 @@ private void setupListeners() {
mImagePerfRequestListener = new ImagePerfRequestListener(mMonotonicClock, mImagePerfState);
}
if (mImageOriginListener == null) {
mImageOriginListener = new ImagePerfImageOriginListener(mImagePerfState, this);
mImageOriginListener = new ImagePerfImageOriginListener(mImagePerfState);
}
if (mImageOriginRequestListener == null) {
mImageOriginRequestListener =
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import android.graphics.drawable.Animatable;
import androidx.annotation.VisibleForTesting;
import com.facebook.common.time.MonotonicClock;
import com.facebook.drawee.backends.pipeline.info.ImageLoadStatus;
import com.facebook.drawee.backends.pipeline.info.ImagePerfMonitor;
import com.facebook.drawee.backends.pipeline.info.ImagePerfState;
import com.facebook.drawee.backends.pipeline.info.VisibilityState;
import com.facebook.drawee.controller.BaseControllerListener;
import com.facebook.fresco.ui.common.DimensionsInfo;
import com.facebook.fresco.ui.common.ImageLoadStatus;
import com.facebook.fresco.ui.common.ImagePerfState;
import com.facebook.fresco.ui.common.OnDrawControllerListener;
import com.facebook.fresco.ui.common.VisibilityState;
import com.facebook.imagepipeline.image.ImageInfo;
import com.facebook.infer.annotation.Nullsafe;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void onRelease(String id) {
super.onRelease(id);
final long now = mClock.now();

int lastImageLoadStatus = mImagePerfState.getImageLoadStatus();
ImageLoadStatus lastImageLoadStatus = mImagePerfState.getImageLoadStatus();
if (lastImageLoadStatus != ImageLoadStatus.SUCCESS
&& lastImageLoadStatus != ImageLoadStatus.ERROR
&& lastImageLoadStatus != ImageLoadStatus.DRAW) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import com.facebook.common.internal.Preconditions;
import com.facebook.common.internal.Supplier;
import com.facebook.common.time.MonotonicClock;
import com.facebook.drawee.backends.pipeline.info.ImageLoadStatus;
import com.facebook.drawee.backends.pipeline.info.ImagePerfNotifier;
import com.facebook.drawee.backends.pipeline.info.ImagePerfState;
import com.facebook.drawee.backends.pipeline.info.VisibilityState;
import com.facebook.fresco.ui.common.BaseControllerListener2;
import com.facebook.fresco.ui.common.ControllerListener2;
import com.facebook.fresco.ui.common.DimensionsInfo;
import com.facebook.fresco.ui.common.ImageLoadStatus;
import com.facebook.fresco.ui.common.ImagePerfNotifier;
import com.facebook.fresco.ui.common.ImagePerfState;
import com.facebook.fresco.ui.common.OnDrawControllerListener;
import com.facebook.fresco.ui.common.VisibilityState;
import com.facebook.imagepipeline.image.ImageInfo;
import com.facebook.infer.annotation.Nullsafe;
import java.io.Closeable;
Expand Down Expand Up @@ -58,10 +58,18 @@ public void handleMessage(@NonNull Message msg) {
ImagePerfState state = (ImagePerfState) Preconditions.checkNotNull(msg.obj);
switch (msg.what) {
case WHAT_STATUS:
mNotifier.notifyStatusUpdated(state, msg.arg1);
ImageLoadStatus imageLoadStatusFromVal = ImageLoadStatus.Companion.fromInt(msg.arg1);
if (imageLoadStatusFromVal == null) {
throw new IllegalArgumentException("Invalid ImageLoadStatus value: " + msg.arg1);
}
mNotifier.notifyStatusUpdated(state, imageLoadStatusFromVal);
break;
case WHAT_VISIBILITY:
mNotifier.notifyListenersOfVisibilityStateUpdate(state, msg.arg1);
VisibilityState visibilityStateFromVal = VisibilityState.Companion.fromInt(msg.arg1);
if (visibilityStateFromVal == null) {
throw new IllegalArgumentException("Invalid VisibilityState value: " + msg.arg1);
}
mNotifier.notifyListenersOfVisibilityStateUpdate(state, visibilityStateFromVal);
break;
}
}
Expand Down Expand Up @@ -156,7 +164,7 @@ public void onRelease(String id, @Nullable ControllerListener2.Extras extras) {
state.setExtraData(extras);
state.setControllerId(id);

int lastImageLoadStatus = state.getImageLoadStatus();
ImageLoadStatus lastImageLoadStatus = state.getImageLoadStatus();
if (lastImageLoadStatus != ImageLoadStatus.SUCCESS
&& lastImageLoadStatus != ImageLoadStatus.ERROR
&& lastImageLoadStatus != ImageLoadStatus.DRAW) {
Expand Down Expand Up @@ -203,23 +211,23 @@ private void reportViewInvisible(ImagePerfState state, long time) {
updateVisibility(state, VisibilityState.INVISIBLE);
}

private void updateStatus(ImagePerfState state, @ImageLoadStatus int imageLoadStatus) {
private void updateStatus(ImagePerfState state, ImageLoadStatus imageLoadStatus) {
if (shouldDispatchAsync()) {
Message msg = Preconditions.checkNotNull(sHandler).obtainMessage();
msg.what = WHAT_STATUS;
msg.arg1 = imageLoadStatus;
msg.arg1 = imageLoadStatus.getValue();
msg.obj = state;
sHandler.sendMessage(msg);
} else {
mImagePerfNotifier.notifyStatusUpdated(state, imageLoadStatus);
}
}

private void updateVisibility(ImagePerfState state, @VisibilityState int visibilityState) {
private void updateVisibility(ImagePerfState state, VisibilityState visibilityState) {
if (shouldDispatchAsync()) {
Message msg = Preconditions.checkNotNull(sHandler).obtainMessage();
msg.what = WHAT_VISIBILITY;
msg.arg1 = visibilityState;
msg.arg1 = visibilityState.getValue();
msg.obj = state;
sHandler.sendMessage(msg);
} else {
Expand Down
Loading

0 comments on commit ac00658

Please sign in to comment.