summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ui/TileImageView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/ui/TileImageView.java')
-rw-r--r--src/com/android/gallery3d/ui/TileImageView.java83
1 files changed, 44 insertions, 39 deletions
diff --git a/src/com/android/gallery3d/ui/TileImageView.java b/src/com/android/gallery3d/ui/TileImageView.java
index 8f26981fe..f1c31e49d 100644
--- a/src/com/android/gallery3d/ui/TileImageView.java
+++ b/src/com/android/gallery3d/ui/TileImageView.java
@@ -16,20 +16,24 @@
package com.android.gallery3d.ui;
+import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
+import android.support.v4.util.LongSparseArray;
+import android.util.DisplayMetrics;
import android.util.FloatMath;
+import android.view.WindowManager;
import com.android.gallery3d.app.GalleryContext;
import com.android.gallery3d.common.ApiHelper;
-import com.android.gallery3d.common.LongSparseArray;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.BitmapPool;
import com.android.gallery3d.data.DecodeUtils;
+import com.android.gallery3d.glrenderer.GLCanvas;
+import com.android.gallery3d.glrenderer.UploadedTexture;
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;
@@ -41,14 +45,11 @@ public class TileImageView extends GLView {
@SuppressWarnings("unused")
private static final String TAG = "TileImageView";
-
- // 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 int TILE_SIZE;
- private static final int TILE_BORDER = 1;
- private static int BITMAP_SIZE;
private static final int UPLOAD_LIMIT = 1;
+ // TILE_SIZE must be 2^N
+ private static int sTileSize;
+
private static BitmapPool sTilePool;
/*
@@ -76,7 +77,7 @@ public class TileImageView extends GLView {
private static final int STATE_RECYCLING = 0x20;
private static final int STATE_RECYCLED = 0x40;
- private Model mModel;
+ private TileSource mModel;
private ScreenNail mScreenNail;
protected int mLevelCount; // cache the value of mScaledBitmaps.length
@@ -125,7 +126,7 @@ public class TileImageView extends GLView {
private final ThreadPool mThreadPool;
private boolean mBackgroundTileUploaded;
- public static interface Model {
+ public static interface TileSource {
public int getLevelCount();
public ScreenNail getScreenNail();
public int getImageWidth();
@@ -133,8 +134,7 @@ public class TileImageView extends GLView {
// The tile returned by this method can be specified this way: Assuming
// the image size is (width, height), first take the intersection of (0,
- // 0) - (width, height) and (x, y) - (x + tileSize, y + tileSize). Then
- // extend this intersection region by borderSize pixels on each side. If
+ // 0) - (width, height) and (x, y) - (x + tileSize, y + tileSize). If
// in extending the region, we found some part of the region are outside
// the image, those pixels are filled with black.
//
@@ -144,27 +144,34 @@ public class TileImageView extends GLView {
//
// The method would be called in another thread.
public Bitmap getTile(int level, int x, int y, int tileSize,
- int borderSize, BitmapPool pool);
+ BitmapPool pool);
+ }
+
+ 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 TileImageView(GalleryContext context) {
mThreadPool = context.getThreadPool();
mTileDecoder = mThreadPool.submit(new TileDecoder());
- if (TILE_SIZE == 0) {
- if (GalleryUtils.isHighResolution(context.getAndroidContext())) {
- TILE_SIZE = 510 ;
+ if (sTileSize == 0) {
+ if (isHighResolution(context.getAndroidContext())) {
+ sTileSize = 512 ;
} else {
- TILE_SIZE = 254;
+ sTileSize = 256;
}
- BITMAP_SIZE = TILE_SIZE + TILE_BORDER * 2;
sTilePool =
ApiHelper.HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER
- ? new BitmapPool(BITMAP_SIZE, BITMAP_SIZE, 128)
+ ? new BitmapPool(sTileSize, sTileSize, 128)
: null;
}
}
- public void setModel(Model model) {
+ public void setModel(TileSource model) {
mModel = model;
if (model != null) notifyModelInvalidated();
}
@@ -266,7 +273,7 @@ public class TileImageView extends GLView {
}
for (int i = fromLevel; i < endLevel; ++i) {
- int size = TILE_SIZE << i;
+ int size = sTileSize << i;
Rect r = range[i - fromLevel];
for (int y = r.top, bottom = r.bottom; y < bottom; y += size) {
for (int x = r.left, right = r.right; x < right; x += size) {
@@ -320,7 +327,7 @@ public class TileImageView extends GLView {
int bottom = (int) FloatMath.ceil(top + height / scale);
// align the rectangle to tile boundary
- int size = TILE_SIZE << level;
+ int size = sTileSize << level;
left = Math.max(0, size * (left / size));
top = Math.max(0, size * (top / size));
right = Math.min(mImageWidth, right);
@@ -431,7 +438,7 @@ public class TileImageView extends GLView {
mScreenNail.noDraw();
}
- int size = (TILE_SIZE << level);
+ int size = (sTileSize << level);
float length = size * mScale;
Rect r = mTileRange;
@@ -594,7 +601,7 @@ public class TileImageView extends GLView {
RectF source = mSourceRect;
RectF target = mTargetRect;
target.set(x, y, x + length, y + length);
- source.set(0, 0, TILE_SIZE, TILE_SIZE);
+ source.set(0, 0, sTileSize, sTileSize);
Tile tile = getTile(tx, ty, level);
if (tile != null) {
@@ -614,7 +621,7 @@ public class TileImageView extends GLView {
if (drawTile(tile, canvas, source, target)) return;
}
if (mScreenNail != null) {
- int size = TILE_SIZE << level;
+ int size = sTileSize << level;
float scaleX = (float) mScreenNail.getWidth() / mImageWidth;
float scaleY = (float) mScreenNail.getHeight() / mImageHeight;
source.set(tx * scaleX, ty * scaleY, (tx + size) * scaleX,
@@ -627,8 +634,6 @@ public class TileImageView extends GLView {
Tile tile, GLCanvas canvas, RectF source, RectF target) {
while (true) {
if (tile.isContentValid()) {
- // offset source rectangle for the texture border.
- source.offset(TILE_BORDER, TILE_BORDER);
canvas.drawTexture(tile, source, target);
return true;
}
@@ -640,15 +645,15 @@ public class TileImageView extends GLView {
source.left /= 2f;
source.right /= 2f;
} else {
- source.left = (TILE_SIZE + source.left) / 2f;
- source.right = (TILE_SIZE + source.right) / 2f;
+ source.left = (sTileSize + source.left) / 2f;
+ source.right = (sTileSize + source.right) / 2f;
}
if (tile.mY == parent.mY) {
source.top /= 2f;
source.bottom /= 2f;
} else {
- source.top = (TILE_SIZE + source.top) / 2f;
- source.bottom = (TILE_SIZE + source.bottom) / 2f;
+ source.top = (sTileSize + source.top) / 2f;
+ source.bottom = (sTileSize + source.bottom) / 2f;
}
tile = parent;
}
@@ -678,7 +683,7 @@ public class TileImageView extends GLView {
// by (1 << mTilelevel) from a region in the original image.
try {
mDecodedTile = DecodeUtils.ensureGLCompatibleBitmap(mModel.getTile(
- mTileLevel, mX, mY, TILE_SIZE, TILE_BORDER, sTilePool));
+ mTileLevel, mX, mY, sTileSize, sTilePool));
} catch (Throwable t) {
Log.w(TAG, "fail to decode tile", t);
}
@@ -691,9 +696,9 @@ public class TileImageView extends GLView {
// We need to override the width and height, so that we won't
// draw beyond the boundaries.
- int rightEdge = ((mImageWidth - mX) >> mTileLevel) + TILE_BORDER;
- int bottomEdge = ((mImageHeight - mY) >> mTileLevel) + TILE_BORDER;
- setSize(Math.min(BITMAP_SIZE, rightEdge), Math.min(BITMAP_SIZE, bottomEdge));
+ int rightEdge = ((mImageWidth - mX) >> mTileLevel);
+ int bottomEdge = ((mImageHeight - mY) >> mTileLevel);
+ setSize(Math.min(sTileSize, rightEdge), Math.min(sTileSize, bottomEdge));
Bitmap bitmap = mDecodedTile;
mDecodedTile = null;
@@ -707,12 +712,12 @@ public class TileImageView extends GLView {
// boundary).
@Override
public int getTextureWidth() {
- return TILE_SIZE + TILE_BORDER * 2;
+ return sTileSize;
}
@Override
public int getTextureHeight() {
- return TILE_SIZE + TILE_BORDER * 2;
+ return sTileSize;
}
public void update(int x, int y, int level) {
@@ -724,7 +729,7 @@ public class TileImageView extends GLView {
public Tile getParentTile() {
if (mTileLevel + 1 == mLevelCount) return null;
- int size = TILE_SIZE << (mTileLevel + 1);
+ int size = sTileSize << (mTileLevel + 1);
int x = size * (mX / size);
int y = size * (mY / size);
return getTile(x, y, mTileLevel + 1);
@@ -733,7 +738,7 @@ public class TileImageView extends GLView {
@Override
public String toString() {
return String.format("tile(%s, %s, %s / %s)",
- mX / TILE_SIZE, mY / TILE_SIZE, mLevel, mLevelCount);
+ mX / sTileSize, mY / sTileSize, mLevel, mLevelCount);
}
}