Skip to content
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

Merged
merged 1 commit into from
Nov 24, 2015

Conversation

mullender
Copy link

… Android

@googlebot
Copy link

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. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@mullender
Copy link
Author

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) {
Copy link
Author

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

Copy link
Collaborator

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.

Copy link
Author

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.

@TWiStErRob
Copy link
Collaborator

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.

@googlebot
Copy link

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.

@mullender
Copy link
Author

@TWiStErRob @sjudd
I agree with both your comments and made the patch work only for the specific device that consistently has the issue.
I measured the perf impact of adding the lock, it is significant. #738 (comment)

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 {
Copy link
Collaborator

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.

Copy link
Author

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

@mullender mullender force-pushed the glide-issue-738 branch 3 times, most recently from 2fa00cf to 787954f Compare November 20, 2015 23:30
@mullender
Copy link
Author

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();
Copy link
Collaborator

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.

@TWiStErRob
Copy link
Collaborator

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.
@mullender
Copy link
Author

@TWiStErRob good nitpicks ;)
I updated the PR.

@sjudd
Copy link
Collaborator

sjudd commented Nov 24, 2015

LGTM, thanks for tracking this down and fixing it!

sjudd added a commit that referenced this pull request Nov 24, 2015
fix for issue #738 Some images simply do not download (Black image) -…
@sjudd sjudd merged commit ff7850c into bumptech:master Nov 24, 2015
@TWiStErRob TWiStErRob added this to the 4.0 milestone Nov 24, 2015
sjudd added a commit to sjudd/glide that referenced this pull request Dec 2, 2015
*** 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
sjudd added a commit to sjudd/glide that referenced this pull request Dec 2, 2015
*** 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants