Skip to content

Commit

Permalink
Add a disallowHardwareConfig method to RequestOptions.
Browse files Browse the repository at this point in the history
It's easier to just call a method than it is to set a component specific
option and it looks like disabling hardware configs is going to be
relatively common.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167035799
  • Loading branch information
sjudd committed Aug 31, 2017
1 parent 0a44cf6 commit 0241df5
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,27 @@ public RequestOptions format(@NonNull DecodeFormat format) {
return set(Downsampler.DECODE_FORMAT, Preconditions.checkNotNull(format));
}

/**
* Disables the use of {@link android.graphics.Bitmap.Config#HARDWARE} in {@link Downsampler} to
* avoid errors caused by inspecting Bitmap pixels, drawing with hardware support disabled,
* drawing to {@link android.graphics.Canvas}s backed by {@link Bitmap}s etc.
*
* <p>It's almost never safe to set {@link Downsampler#ALLOW_HARDWARE_CONFIG} to {@code true} so
* we only provide a way to disable hardware configs entirely. If no option is set for
* {@link Downsampler#ALLOW_HARDWARE_CONFIG}, Glide will set the value per request based on
* whether or not a {@link Transformation} is applied and if one is, the type of
* {@link Transformation} applied. Built in transformations like {@link FitCenter} and
* {@link com.bumptech.glide.load.resource.bitmap.DownsampleStrategy.CenterOutside} can safely use
* {@link android.graphics.Bitmap.Config#HARDWARE} because they can be entirely replaced by
* scaling within {@link Downsampler}. {@link Transformation}s like {@link #circleCrop()} that
* can't be replicated by {@link Downsampler} cannot use {@link Bitmap.Config#HARDWARE} because
* {@link android.graphics.Bitmap.Config#HARDWARE} cannot be drawn to
* {@link android.graphics.Canvas}s, which is required by most {@link Transformation}s.
*/
public RequestOptions disallowHardwareConfig() {
return set(Downsampler.ALLOW_HARDWARE_CONFIG, false);
}

/**
* Sets the {@link DownsampleStrategy} to use when decoding {@link Bitmap Bitmaps} using
* {@link Downsampler}.
Expand Down

0 comments on commit 0241df5

Please sign in to comment.