diff options
author | Ray Chen <raychen@google.com> | 2012-05-02 15:31:38 +0800 |
---|---|---|
committer | Ray Chen <raychen@google.com> | 2012-05-02 15:31:38 +0800 |
commit | 98db32decd9cbc4d3405f9c75f3a43a0e74f873f (patch) | |
tree | 6c7ab7593353cf9cd7db37b725bf1d48a72e702d /src | |
parent | 348988dc1934981a96018006b4af6c38f33cf26e (diff) | |
download | android_packages_apps_Snap-98db32decd9cbc4d3405f9c75f3a43a0e74f873f.tar.gz android_packages_apps_Snap-98db32decd9cbc4d3405f9c75f3a43a0e74f873f.tar.bz2 android_packages_apps_Snap-98db32decd9cbc4d3405f9c75f3a43a0e74f873f.zip |
Fix 6341866 ANR in com.google.android.gallery3d due to com.android.gallery3d.ui.TileImageViewAdapter.setScreenNail
RegionDecoder is run in a lower priority thread but it uses the same lock as setScreenNail while decoding, so a priority inversion causes this ANR.
The change tries to separate the lock so setScreenNail doesn't have to wait on the decoding process so the ANR could be avoided.
Change-Id: I02cc26fa0535adaa57cdcf94b819970e179311d1
b:6341866
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/gallery3d/ui/TileImageViewAdapter.java | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/com/android/gallery3d/ui/TileImageViewAdapter.java b/src/com/android/gallery3d/ui/TileImageViewAdapter.java index f4c6e658a..0400de6f3 100644 --- a/src/com/android/gallery3d/ui/TileImageViewAdapter.java +++ b/src/com/android/gallery3d/ui/TileImageViewAdapter.java @@ -100,10 +100,8 @@ public class TileImageViewAdapter implements TileImageView.Model { } @Override - public synchronized Bitmap getTile(int level, int x, int y, int tileSize, + public Bitmap getTile(int level, int x, int y, int tileSize, int borderSize) { - if (mRegionDecoder == null) return null; - // wantRegion is the rectangle on the original image we want. askRegion // is the rectangle on the original image that we will ask from // mRegionDecoder. Both are in the coordinates of the original image, @@ -115,8 +113,14 @@ public class TileImageViewAdapter implements TileImageView.Model { wantRegion.set(x - b, y - b, x + (tileSize << level) + b, y + (tileSize << level) + b); - // askRegion is the intersection of wantRegion and the original image. - askRegion.set(0, 0, mImageWidth, mImageHeight); + BitmapRegionDecoder regionDecoder = null; + synchronized (this) { + regionDecoder = mRegionDecoder; + if (regionDecoder == null) return null; + // askRegion is the intersection of wantRegion and the original image. + askRegion.set(0, 0, mImageWidth, mImageHeight); + } + Utils.assertTrue(askRegion.intersect(wantRegion)); BitmapFactory.Options options = new BitmapFactory.Options(); @@ -127,8 +131,8 @@ public class TileImageViewAdapter implements TileImageView.Model { Bitmap bitmap; // In CropImage, we may call the decodeRegion() concurrently. - synchronized (mRegionDecoder) { - bitmap = mRegionDecoder.decodeRegion(askRegion, options); + synchronized (regionDecoder) { + bitmap = regionDecoder.decodeRegion(askRegion, options); } if (bitmap == null) { |