-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix for issue #738 Some images simply do not download (Black image) -… #758
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
fix for #738 |
@@ -248,17 +248,6 @@ static void calculateScaling(DownsampleStrategy downsampleStrategy, int degreesT | |||
float adjustedScaleFactor = powerOfTwoSampleSize * exactScaleFactor; | |||
|
|||
options.inSampleSize = powerOfTwoSampleSize; | |||
// Density scaling is only supported if inBitmap is null prior to KitKat. Avoid setting | |||
// densities here so we calculate the final Bitmap size correctly. | |||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first part of the fix, it seems that the values here are part of the problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to be more specific. What does this fix? On what device(s)?
This is a substantial decrease in performance. If it fixes specific issues on specific devices, only disable it in those particular cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
I was making this PR late last night, usually not the best time :)
Afterwards I was thinking about how this could be related to the issue. My current thought is that there is a bug in the OS code of the MotoX 5.1: bitmap scaling is not thread safe.
When you specify the inDensity and inTargetDensity it will also trigger the same non-thread-safe code path.
I will validate this hunch by applying the same lock on this operation as is applied to the drawBitmap operation.
That looks like quite a significant change, I'll let @sjudd handle this one. My view is that one it's not worth removing all that logic because it doesn't work on one or two phones out of thousands, I'd rather create an exception for those with some device detection. |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
@TWiStErRob @sjudd But I think the perf impact is a good trade-off for this device, weighed against not being able to see the images at all. |
* types of devices the lock is always available and therefore does not impact performance The | ||
* actual lock logic is delegated to {@see ReentrantLock} | ||
*/ | ||
final class BitmapDrawLock implements Lock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about?
final class BitmapDrawLock {
// only enable the lock for Moto X 2nd gen on android 5.1
private static final Lock INSTANCE =
"XT1097".equals(Build.MODEL) && Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1
? new ReentrantLock()
: new NoLock();
private BitmapDrawLock() {
// static utility class
}
public static Lock getInstance() {
return INSTANCE;
}
}
public class NoLock implements Lock {
@Override public void lock() {
// do nothing
}
@Override public void lockInterruptibly() throws InterruptedException {
// do nothing
}
@Override public boolean tryLock() {
return true;
}
@Override public boolean tryLock(long time, @NotNull TimeUnit unit) throws InterruptedException {
return true;
}
@Override public void unlock() {
// do nothing
}
@NotNull @Override public Condition newCondition() {
throw new UnsupportedOperationException("Should not be called");
}
}
That single INSTANCE field + getInstance can be even moved to some other class, like TransformationUtils
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your proposal fits better with the existing code in the project
2fa00cf
to
787954f
Compare
Cleaned up the PR and implemented according to your suggestion @TWiStErRob |
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); | ||
canvas.drawRoundRect(rect, roundingRadius, roundingRadius, paint); | ||
clear(canvas); | ||
TransformationUtils.getBitmapDrawableLock().lock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just nitpick: direct access vs get instance in the same class. I would prefer direct access where it's defined, like in applyMatrix, and getter outside the class.
Thank you, man! |
…on (affects only Moto X 2nd gen on api 22) this addresses a threading bug on this specific device, the bug manifests itself by displaying black images instead of resized images.
787954f
to
59f3d9c
Compare
@TWiStErRob good nitpicks ;) |
LGTM, thanks for tracking this down and fixing it! |
fix for issue #738 Some images simply do not download (Black image) -…
*** Reason for rollback *** Broke Street View *** Original change description *** MOE automated commit. Merge pull request bumptech#762 from vanniktech/master_clean_upload_script Clean upload script up ------------- Merge pull request bumptech#727 from josemontiel/master Implemented CENTER_INSIDE support ------------- Update Downsampler names. ------------- Merge pull request bumptech#758 from mullender/glide-issue-738 fix for issue bumptech#738 Some images simply do not download (Black image) -… ------------- Created by MOE: https://github.com/google/moe *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=108724201
*** Reason for rollback *** Rollforward with compatibility for apps targeting API 21 *** Original change description *** Automated g4 rollback of changelist 108709885. *** Reason for rollback *** Broke Street View *** Original change description *** MOE automated commit. Merge pull request bumptech#762 from vanniktech/master_clean_upload_script Clean upload script up ------------- Merge pull request bumptech#727 from josemontiel/master Implemented CENTER_INSIDE support ------------- Update Downsampler names. ------------- Merge pull request bumptech#758 from mullender/glide-issue-738 fix for issue bumptech#738 Some images simply do no... *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=108748541
… Android