From 82d95838d891057b56fd43780e2424e04f1e291b Mon Sep 17 00:00:00 2001 From: Pin Ting Date: Thu, 4 Oct 2012 16:54:50 +0800 Subject: Accelerate PNG image rendering. Bug:7137662 Change-Id: I050a228a6c8031c6a2d068eb4ba1b39be86e9f4a --- src/com/android/gallery3d/ui/TileImageView.java | 22 ++++++++++++++++------ .../android/gallery3d/ui/TileImageViewAdapter.java | 1 - src/com/android/gallery3d/util/GalleryUtils.java | 8 ++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/com/android/gallery3d/ui/TileImageView.java b/src/com/android/gallery3d/ui/TileImageView.java index 9eb4f4787..5ce06bec4 100644 --- a/src/com/android/gallery3d/ui/TileImageView.java +++ b/src/com/android/gallery3d/ui/TileImageView.java @@ -29,6 +29,7 @@ import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.BitmapPool; import com.android.gallery3d.data.DecodeUtils; import com.android.gallery3d.util.Future; +import com.android.gallery3d.util.GalleryUtils; import com.android.gallery3d.util.ThreadPool; import com.android.gallery3d.util.ThreadPool.CancelListener; import com.android.gallery3d.util.ThreadPool.JobContext; @@ -43,15 +44,12 @@ public class TileImageView extends GLView { // TILE_SIZE must be 2^N - 2. We put one pixel border in each side of the // texture to avoid seams between tiles. - private static final int TILE_SIZE = 254; + private static int TILE_SIZE; private static final int TILE_BORDER = 1; - private static final int BITMAP_SIZE = TILE_SIZE + TILE_BORDER * 2; + private static int BITMAP_SIZE; private static final int UPLOAD_LIMIT = 1; - private static final BitmapPool sTilePool = - ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER - ? new BitmapPool(BITMAP_SIZE, BITMAP_SIZE, 128) - : null; + private static BitmapPool sTilePool; /* * This is the tile state in the CPU side. @@ -152,6 +150,18 @@ public class TileImageView extends GLView { public TileImageView(GalleryContext context) { mThreadPool = context.getThreadPool(); mTileDecoder = mThreadPool.submit(new TileDecoder()); + if (TILE_SIZE == 0) { + if (GalleryUtils.isHighResolution(context.getAndroidContext())) { + TILE_SIZE = 510 ; + } else { + TILE_SIZE = 254; + } + BITMAP_SIZE = TILE_SIZE + TILE_BORDER * 2; + sTilePool = + ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER + ? new BitmapPool(BITMAP_SIZE, BITMAP_SIZE, 128) + : null; + } } public void setModel(Model model) { diff --git a/src/com/android/gallery3d/ui/TileImageViewAdapter.java b/src/com/android/gallery3d/ui/TileImageViewAdapter.java index a14df754a..08d337921 100644 --- a/src/com/android/gallery3d/ui/TileImageViewAdapter.java +++ b/src/com/android/gallery3d/ui/TileImageViewAdapter.java @@ -112,7 +112,6 @@ public class TileImageViewAdapter implements TileImageView.Model { @Override public Bitmap getTile(int level, int x, int y, int tileSize, int borderSize, BitmapPool pool) { - if (!ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER) { return getTileWithoutReusingBitmap(level, x, y, tileSize, borderSize); } diff --git a/src/com/android/gallery3d/util/GalleryUtils.java b/src/com/android/gallery3d/util/GalleryUtils.java index a3eccb89b..efa06149f 100644 --- a/src/com/android/gallery3d/util/GalleryUtils.java +++ b/src/com/android/gallery3d/util/GalleryUtils.java @@ -87,6 +87,14 @@ public class GalleryUtils { R.color.bitmap_screennail_placeholder)); } + public static boolean isHighResolution(Context context) { + DisplayMetrics metrics = new DisplayMetrics(); + WindowManager wm = (WindowManager) + context.getSystemService(Context.WINDOW_SERVICE); + wm.getDefaultDisplay().getMetrics(metrics); + return metrics.heightPixels > 2048 || metrics.widthPixels > 2048; + } + public static float[] intColorToFloatARGBArray(int from) { return new float[] { Color.alpha(from) / 255f, -- cgit v1.2.3