Skip to content

Commit

Permalink
Add option to set minimum hardware Bitmap dimension in Glide.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 260752977
  • Loading branch information
sjudd authored and glide-copybara-robot committed Jul 30, 2019
1 parent 4de2cda commit 0ac450c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
3 changes: 2 additions & 1 deletion library/src/main/java/com/bumptech/glide/Glide.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ private static void throwIncorrectGlideModule(Exception e) {
@NonNull List<RequestListener<Object>> defaultRequestListeners,
boolean isLoggingRequestOriginsEnabled,
boolean isImageDecoderEnabledForBitmaps,
int hardwareBitmapFdLimit) {
int hardwareBitmapFdLimit,
int minHardwareDimension) {
this.engine = engine;
this.bitmapPool = bitmapPool;
this.arrayPool = arrayPool;
Expand Down
4 changes: 3 additions & 1 deletion library/src/main/java/com/bumptech/glide/GlideBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public RequestOptions build() {
private boolean isImageDecoderEnabledForBitmaps;

private int hardwareBitmapFdLimit = HardwareConfigState.DEFAULT_MAXIMUM_FDS_FOR_HARDWARE_CONFIGS;
private int minHardwareDimension = HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION;

/**
* Sets the {@link com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool} implementation to use
Expand Down Expand Up @@ -578,6 +579,7 @@ Glide build(@NonNull Context context) {
defaultRequestListeners,
isLoggingRequestOriginsEnabled,
isImageDecoderEnabledForBitmaps,
hardwareBitmapFdLimit);
hardwareBitmapFdLimit,
minHardwareDimension);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class HardwareConfigState {
*
* @see #FD_SIZE_LIST
*/
@VisibleForTesting static final int MIN_HARDWARE_DIMENSION = 128;
public static final int DEFAULT_MIN_HARDWARE_DIMENSION = 128;

/**
* Allows us to check to make sure we're not exceeding the FD limit for a process with hardware
Expand Down Expand Up @@ -58,6 +58,7 @@ public final class HardwareConfigState {
public static final int DEFAULT_MAXIMUM_FDS_FOR_HARDWARE_CONFIGS = 700;

private static volatile int fdSizeLimit = DEFAULT_MAXIMUM_FDS_FOR_HARDWARE_CONFIGS;
private static volatile int minHardwareDimension = DEFAULT_MIN_HARDWARE_DIMENSION;

private static volatile HardwareConfigState instance;

Expand Down Expand Up @@ -98,8 +99,8 @@ public boolean isHardwareConfigAllowed(
return false;
}

return targetWidth >= MIN_HARDWARE_DIMENSION
&& targetHeight >= MIN_HARDWARE_DIMENSION
return targetWidth >= minHardwareDimension
&& targetHeight >= minHardwareDimension
// Make sure to call isFdSizeBelowHardwareLimit last because it has side affects.
&& isFdSizeBelowHardwareLimit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class HardwareConfigStateTest {
BitmapFactory.Options options = new BitmapFactory.Options();
boolean result =
state.setHardwareConfigIfAllowed(
/*targetWidth=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetWidth=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
options,
/*isHardwareConfigAllowed=*/ true,
/*isExifOrientationRequired=*/ false);
Expand All @@ -45,8 +45,8 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinWidth_returnsFalse_does

boolean result =
state.setHardwareConfigIfAllowed(
/*targetWidth=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION - 1,
/*targetHeight=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetWidth=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION - 1,
/*targetHeight=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
options,
/*isHardwareConfigAllowed=*/ true,
/*isExifOrientationRequired=*/ false);
Expand All @@ -66,8 +66,8 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinHeight_returnsFalse_doe

boolean result =
state.setHardwareConfigIfAllowed(
/*targetWidth=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION - 1,
/*targetWidth=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION - 1,
options,
/*isHardwareConfigAllowed=*/ true,
/*isExifOrientationRequired=*/ false);
Expand All @@ -88,8 +88,8 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinHeight_returnsFalse_doe

boolean result =
state.setHardwareConfigIfAllowed(
/*targetWidth=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetWidth=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
options,
/*isHardwareConfigAllowed=*/ false,
/*isExifOrientationRequired=*/ false);
Expand All @@ -110,8 +110,8 @@ public void setHardwareConfigIfAllowed_withSmallerThanMinHeight_returnsFalse_doe

boolean result =
state.setHardwareConfigIfAllowed(
/*targetWidth=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetWidth=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
options,
/*isHardwareConfigAllowed=*/ true,
/*isExifOrientationRequired=*/ true);
Expand All @@ -131,8 +131,8 @@ public void setHardwareConfigIfAllowed_withOsLessThanO_returnsFalse_doesNotSetVa

boolean result =
state.setHardwareConfigIfAllowed(
/*targetWidth=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetWidth=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
options,
/*isHardwareConfigAllowed=*/ true,
/*isExifOrientationRequired=*/ false);
Expand All @@ -158,8 +158,8 @@ public void setHardwareConfigIfAllowed_withOsLessThanO_returnsFalse_doesNotSetVa

boolean result =
state.setHardwareConfigIfAllowed(
/*targetWidth=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetWidth=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
options,
/*isHardwareConfigAllowed=*/ true,
/*isExifOrientationRequired=*/ false);
Expand All @@ -185,8 +185,8 @@ public void setHardwareConfigIfAllowed_withDisallowedSamsungDevices_OMR1_returns

boolean result =
state.setHardwareConfigIfAllowed(
/*targetWidth=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetWidth=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
options,
/*isHardwareConfigAllowed=*/ true,
/*isExifOrientationRequired=*/ false);
Expand All @@ -212,8 +212,8 @@ public void setHardwareConfigIfAllowed_withShortEmptyOrNullModelNames_returnsTru

boolean result =
state.setHardwareConfigIfAllowed(
/*targetWidth=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.MIN_HARDWARE_DIMENSION,
/*targetWidth=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
/*targetHeight=*/ HardwareConfigState.DEFAULT_MIN_HARDWARE_DIMENSION,
options,
/*isHardwareConfigAllowed=*/ true,
/*isExifOrientationRequired=*/ false);
Expand Down

0 comments on commit 0ac450c

Please sign in to comment.