summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLikai Ding <likaid@codeaurora.org>2016-06-03 11:52:57 +0800
committerLikai Ding <likaid@codeaurora.org>2016-06-06 09:26:10 +0800
commit77504adebce4b8bb8233eefbede7a3d2bfafd0a0 (patch)
tree88d547ed0b3ec2fa1a59a507a1285d82d279887d
parentd1208622bd805d170e25e6f5e9f66b3bca28abdd (diff)
downloadandroid_packages_apps_Gallery2-77504adebce4b8bb8233eefbede7a3d2bfafd0a0.tar.gz
android_packages_apps_Gallery2-77504adebce4b8bb8233eefbede7a3d2bfafd0a0.tar.bz2
android_packages_apps_Gallery2-77504adebce4b8bb8233eefbede7a3d2bfafd0a0.zip
Gallery: don't use tile for small thumbnails
A thumbnail on an FHD screen is ~380px while tile size is 256px. It's quite inefficient to upload a thumbnail in 4 such tiles. As devices today can upload bigger textures in less time, tiling is no longer needed for small thumbnails. CRs-Fixed: 1024519 Change-Id: I95f9a5f1c695b7d7f1401b3a294848d46f1c3545
-rw-r--r--src/com/android/gallery3d/glrenderer/TiledTexture.java48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/com/android/gallery3d/glrenderer/TiledTexture.java b/src/com/android/gallery3d/glrenderer/TiledTexture.java
index bd93d3acc..ca26dde2b 100644
--- a/src/com/android/gallery3d/glrenderer/TiledTexture.java
+++ b/src/com/android/gallery3d/glrenderer/TiledTexture.java
@@ -36,14 +36,13 @@ import java.util.ArrayList;
// upload the whole bitmap but we reduce the time of uploading each tile
// so it make the animation more smooth and prevents jank.
public class TiledTexture implements Texture {
+ private static final int TILE_THRESHOLD = 512;
+
private static final int CONTENT_SIZE = 254;
private static final int BORDER_SIZE = 1;
private static final int TILE_SIZE = CONTENT_SIZE + 2 * BORDER_SIZE;
private static final int INIT_CAPACITY = 8;
- private static Tile sFreeTileHead = null;
- private static final Object sFreeTileLock = new Object();
-
private static Bitmap sUploadBitmap;
private static Canvas sCanvas;
private static Paint sBitmapPaint;
@@ -109,9 +108,9 @@ public class TiledTexture implements Texture {
public int offsetX;
public int offsetY;
public Bitmap bitmap;
- public Tile nextFreeTile;
public int contentWidth;
public int contentHeight;
+ private boolean raw;
@Override
public void setSize(int width, int height) {
@@ -121,10 +120,13 @@ public class TiledTexture implements Texture {
mHeight = height + 2 * BORDER_SIZE;
mTextureWidth = TILE_SIZE;
mTextureHeight = TILE_SIZE;
+ raw = false;
}
@Override
protected Bitmap onGetBitmap() {
+ if (raw) return bitmap;
+
// make a local copy of the reference to the bitmap,
// since it might be null'd in a different thread. b/8694871
Bitmap localBitmapRef = bitmap;
@@ -151,24 +153,13 @@ public class TiledTexture implements Texture {
protected void onFreeBitmap(Bitmap bitmap) {
// do nothing
}
- }
-
- private static void freeTile(Tile tile) {
- tile.invalidateContent();
- tile.bitmap = null;
- synchronized (sFreeTileLock) {
- tile.nextFreeTile = sFreeTileHead;
- sFreeTileHead = tile;
- }
- }
- private static Tile obtainTile() {
- synchronized (sFreeTileLock) {
- Tile result = sFreeTileHead;
- if (result == null) return new Tile();
- sFreeTileHead = result.nextFreeTile;
- result.nextFreeTile = null;
- return result;
+ public void setAsRaw(Bitmap bitmap) {
+ this.bitmap = bitmap;
+ offsetX = offsetY = 0;
+ contentWidth = mWidth = mTextureWidth = bitmap.getWidth();
+ contentHeight = mHeight = mTextureHeight = bitmap.getHeight();
+ raw = true;
}
}
@@ -197,11 +188,19 @@ public class TiledTexture implements Texture {
public TiledTexture(Bitmap bitmap) {
mWidth = bitmap.getWidth();
mHeight = bitmap.getHeight();
+
+ if (mWidth < TILE_THRESHOLD && mHeight < TILE_THRESHOLD) {
+ Tile tile = new Tile();
+ tile.setAsRaw(bitmap);
+ mTiles = new Tile[] { tile };
+ return;
+ }
+
ArrayList<Tile> list = new ArrayList<>();
for (int x = 0, w = mWidth; x < w; x += CONTENT_SIZE) {
for (int y = 0, h = mHeight; y < h; y += CONTENT_SIZE) {
- Tile tile = obtainTile();
+ Tile tile = new Tile();
tile.offsetX = x;
tile.offsetY = y;
tile.bitmap = bitmap;
@@ -221,8 +220,9 @@ public class TiledTexture implements Texture {
// Can be called in UI thread.
public void recycle() {
synchronized (mTiles) {
- for (Tile mTile : mTiles) {
- freeTile(mTile);
+ for (Tile tile : mTiles) {
+ tile.invalidateContent();
+ tile.bitmap = null;
}
}
}